Changeset 50 in dev for BasicCompiler64
- Timestamp:
- Feb 10, 2007, 5:44:58 PM (18 years ago)
- Location:
- BasicCompiler64
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler64/BasicCompiler.vcproj
r44 r50 48 48 Name="VCCLCompilerTool" 49 49 Optimization="0" 50 AdditionalIncludeDirectories="..\cpplibs\boost" 50 51 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;JPN;_AMD64_;_WIN64" 51 52 MinimalRebuild="true" … … 1378 1379 > 1379 1380 </File> 1380 <File1381 RelativePath="..\BasicCompiler_Common\Subroutine.cpp"1382 >1383 </File>1384 1381 <Filter 1385 1382 Name="Intermediate" … … 1539 1536 <File 1540 1537 RelativePath="..\BasicCompiler_Common\NativeCode.h" 1538 > 1539 </File> 1540 </Filter> 1541 <Filter 1542 Name="Procedure" 1543 > 1544 <File 1545 RelativePath="..\BasicCompiler_Common\Parameter.cpp" 1546 > 1547 </File> 1548 <File 1549 RelativePath="..\BasicCompiler_Common\Subroutine.cpp" 1541 1550 > 1542 1551 </File> -
BasicCompiler64/CParameter.cpp
r47 r50 1 1 #include "../BasicCompiler_Common/common.h" 2 2 #include "opcode.h" 3 4 CParameter::CParameter(char *buffer){5 ///////////////////////////6 // パラメータ文字列を整理7 ///////////////////////////8 9 extern HANDLE hHeap;10 int i,i2,i3;11 char temporary[VN_SIZE];12 13 i=0;14 ParmsNum=0;15 while(1){16 if(buffer[i]=='\0') break;17 18 for(i2=0;;i2++,i++){19 if(buffer[i]=='\"'){20 temporary[i2]=buffer[i];21 for(i++,i2++;;i++,i2++){22 temporary[i2]=buffer[i];23 if(buffer[i]=='\"') break;24 }25 continue;26 }27 28 if(buffer[i]=='('){29 i3=GetStringInPare(temporary+i2,buffer+i);30 i2+=i3-1;31 i+=i3-1;32 continue;33 }34 if(buffer[i]=='['){35 i3=GetStringInBracket(temporary+i2,buffer+i);36 i2+=i3-1;37 i+=i3-1;38 continue;39 }40 41 if(buffer[i]==','||buffer[i]=='\0'){42 temporary[i2]=0;43 break;44 }45 temporary[i2]=buffer[i];46 }47 48 Parms[ParmsNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);49 lstrcpy(Parms[ParmsNum],temporary);50 ParmsNum++;51 52 if(buffer[i]==',') i++;53 }54 55 ReturnTypeInfo.type=0;56 ReturnTypeInfo.u.lpIndex=0;57 }58 CParameter::CParameter(PARAMETER_INFO *pParamInfo,int ParmNum){59 int i;60 for(i=0;i<ParmNum;i++){61 Parms[i]=0;62 types[i].type=pParamInfo[i].type;63 types[i].u.lpIndex=pParamInfo[i].u.index;64 }65 this->ParmsNum=ParmNum;66 67 ReturnTypeInfo.type=0;68 ReturnTypeInfo.u.lpIndex=0;69 }70 CParameter::~CParameter(){71 int i2;72 73 //パラメータ文字列を解放74 for(i2=0;i2<ParmsNum;i2++){75 if(Parms[i2]==(char *)-1) continue;76 77 if(Parms[i2]) HeapDefaultFree(Parms[i2]);78 }79 }80 81 void CParameter::SetReturnType(TYPEINFO *pTypeInfo){82 ReturnTypeInfo=*pTypeInfo;83 }84 85 BOOL CParameter::_overload_check(PARAMETER_INFO *ppi,int pi_num,TYPEINFO *pReturnTypeInfo,int overload_level){86 //パラメータを識別してオーバーロードを解決87 88 //パラメータの個数が不一致の場合89 if(pi_num!=ParmsNum) return 0;90 91 int i,type;92 LONG_PTR lpIndex;93 for(i=0;i<pi_num;i++){94 if(Parms[i]){95 TYPEINFO BaseType={ppi[i].type,ppi[i].u.index};96 type=NumOpe_GetType(Parms[i],&BaseType,&lpIndex);97 }98 else{99 type=types[i].type;100 lpIndex=types[i].u.lpIndex;101 }102 103 if(type!=ppi[i].type){104 if(overload_level==OVERLOAD_LEVEL1){105 return 0;106 }107 else if(overload_level==OVERLOAD_LEVEL2){108 if(!(109 IsWholeNumberType(type)&&IsWholeNumberType(ppi[i].type)||110 IsRealNumberType(type)&&IsRealNumberType(ppi[i].type)111 )) return 0;112 }113 else if(overload_level==OVERLOAD_LEVEL3){114 if(type==DEF_OBJECT||ppi[i].type==DEF_OBJECT) return 0;115 }116 }117 else{118 if(NATURAL_TYPE(type)==DEF_OBJECT){119 if(lpIndex!=ppi[i].u.index) return 0;120 }121 }122 }123 124 if(pReturnTypeInfo){125 //戻り値も比較対象にする126 if(ReturnTypeInfo.type==pReturnTypeInfo->type){127 if(NATURAL_TYPE(ReturnTypeInfo.type)==DEF_OBJECT){128 if(ReturnTypeInfo.u.lpIndex != pReturnTypeInfo->u.lpIndex) return 0;129 }130 }131 else return 0;132 }133 134 return 1;135 }136 SUBINFO *CParameter::OverloadSolutionWithReturnType(const char *name,SUBINFO **ppsi,int num){137 int i,sw=0;138 SUBINFO *psi;139 psi=0;140 for(i=0;i<num;i++){141 psi=ppsi[i];142 143 TYPEINFO ReturnTypeInfo;144 ReturnTypeInfo.type=psi->ReturnType;145 ReturnTypeInfo.u.lpIndex=psi->u.ReturnIndex;146 147 //エラーチェック148 if(_overload_check(psi->pParmInfo,psi->ParmNum,&ReturnTypeInfo,OVERLOAD_LEVEL1)){149 if(sw){150 SetError(52,name,cp);151 return 0;152 }153 sw=1;154 break;155 }156 }157 158 if(!sw){159 for(i=0;i<num;i++){160 psi=ppsi[i];161 162 TYPEINFO ReturnTypeInfo;163 ReturnTypeInfo.type=psi->ReturnType;164 ReturnTypeInfo.u.lpIndex=psi->u.ReturnIndex;165 166 //エラーチェック167 if(_overload_check(psi->pParmInfo,psi->ParmNum,&ReturnTypeInfo,OVERLOAD_LEVEL2)){168 if(sw){169 SetError(52,name,cp);170 return 0;171 }172 sw=1;173 break;174 }175 }176 }177 178 if(!sw){179 for(i=0;i<num;i++){180 psi=ppsi[i];181 182 TYPEINFO ReturnTypeInfo;183 ReturnTypeInfo.type=psi->ReturnType;184 ReturnTypeInfo.u.lpIndex=psi->u.ReturnIndex;185 186 //エラーチェック187 if(_overload_check(psi->pParmInfo,psi->ParmNum,&ReturnTypeInfo,OVERLOAD_LEVEL3)){188 if(sw){189 SetError(52,name,cp);190 return 0;191 }192 sw=1;193 break;194 }195 }196 }197 198 if(!sw){199 SetError(52,name,cp);200 return 0;201 }202 203 return psi;204 }205 206 SUBINFO *CParameter::OverloadSolution(const char *name,SUBINFO **ppsi,int num){207 int i,sw=0;208 SUBINFO *psi;209 psi=0;210 for(i=0;i<num;i++){211 psi=ppsi[i];212 213 //エラーチェック214 if(_overload_check(psi->pParmInfo,psi->ParmNum,NULL,OVERLOAD_LEVEL1)){215 if(sw){216 return OverloadSolutionWithReturnType(name,ppsi,num);217 }218 sw=1;219 break;220 }221 }222 223 if(!sw){224 for(i=0;i<num;i++){225 psi=ppsi[i];226 227 //エラーチェック228 if(_overload_check(psi->pParmInfo,psi->ParmNum,NULL,OVERLOAD_LEVEL2)){229 if(sw){230 return OverloadSolutionWithReturnType(name,ppsi,num);231 }232 sw=1;233 break;234 }235 }236 }237 238 if(!sw){239 for(i=0;i<num;i++){240 psi=ppsi[i];241 242 //エラーチェック243 if(_overload_check(psi->pParmInfo,psi->ParmNum,NULL,OVERLOAD_LEVEL3)){244 if(sw){245 return OverloadSolutionWithReturnType(name,ppsi,num);246 }247 sw=1;248 break;249 }250 }251 }252 253 if(!sw){254 SUBINFO *temp_psi;255 for(i=0;i<num;i++){256 temp_psi=ppsi[i];257 258 //エラーチェック259 if(temp_psi->ParmNum==this->ParmsNum){260 if(sw){261 sw=0;262 break;263 }264 sw=1;265 266 psi=temp_psi;267 }268 }269 }270 271 if(!sw){272 SetError(52,name,cp);273 return 0;274 }275 276 return psi;277 }278 279 BOOL CParameter::ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum){280 if(ParmsNum>pi_num){281 if(ppi[pi_num-1].type!=DEF_ELLIPSE){282 //パラメータが多すぎるとき283 SetError(10,FuncName,cp);284 return 0;285 }286 }287 else if(ParmsNum<pi_num){288 if(ParmsNum<SecondParmNum){289 if(ppi[ParmsNum].type==DEF_ELLIPSE){290 return 1;291 }292 293 //パラメータが少なすぎるとき294 SetError(10,FuncName,cp);295 return 0;296 }297 298 //省略パラメータに "0" を指定する299 for(;ParmsNum < pi_num;ParmsNum++){300 extern HANDLE hHeap;301 char temporary[64];302 if(ppi[ParmsNum].bByVal) lstrcpy(temporary,"0");303 else sprintf(temporary,"%c%c0",1,ESC_BYVAL);304 Parms[ParmsNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);305 lstrcpy(Parms[ParmsNum],temporary);306 }307 }308 309 return 1;310 }311 void CParameter::MacroParameterSupport(PARAMETER_INFO *ppi){312 int i;313 for(i=0;i<ParmsNum;i++){314 if(Parms[i][0]=='\0'){315 extern HANDLE hHeap;316 char temporary[64];317 if(ppi[i].bByVal) lstrcpy(temporary,"0");318 else sprintf(temporary,"%c%c0",1,ESC_BYVAL);319 HeapDefaultFree(Parms[i]);320 Parms[i]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);321 lstrcpy(Parms[i],temporary);322 }323 }324 }325 3 326 4 void CParameter::NewTempParameters( const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum ){ -
BasicCompiler64/Compile_CallProc.cpp
r47 r50 29 29 pLocalVarAddrSchedule[LocalVarAddrScheduleNum]=obp; 30 30 LocalVarAddrScheduleNum++; 31 }32 33 int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex){34 int ret_type;35 36 if(idProc==PROC_DEFAULT){37 /////////////////////38 // ユーザー定義関数39 /////////////////////40 41 SUBINFO *psi;42 psi=(SUBINFO *)pInfo;43 44 //GetSubHash内でエラー提示が行われた場合45 if(psi==(SUBINFO *)-1) return -1;46 47 48 //オブジェクト名を取得49 char ObjectName[VN_SIZE];50 int RefType;51 SplitObjectName(name,ObjectName,&RefType);52 53 54 ////////////////////////55 // オーバーロードを解決56 ////////////////////////57 58 SUBINFO **ppsi;59 int num;60 ppsi=GetOverloadSubHash(name,&num);61 if(num){62 //オーバーロードを解決63 psi=OverloadSolutionWithStrParam(name,ppsi,num,Parameter,ObjectName,NULL);64 HeapDefaultFree(ppsi);65 66 if(!psi) return 0;67 }68 69 70 Opcode_CallProc(Parameter,psi,0,ObjectName,RefType);71 if( plpRetIndex ){72 *plpRetIndex = psi->u.ReturnIndex;73 }74 return psi->ReturnType;75 }76 else if(idProc==PROC_DLL){77 /////////////////////////78 // DLL関数79 /////////////////////////80 DECLAREINFO *pdi;81 pdi=(DECLAREINFO *)pInfo;82 83 ret_type=Opcode_CallDllProc(Parameter,pdi,plpRetIndex);84 }85 else if(idProc==PROC_BUILTIN){86 /////////////////////////87 // 組み込み関数88 /////////////////////////89 int FuncId;90 FuncId=(int)(_int64)pInfo;91 92 TYPEINFO ReturnTypeInfo = { DEF_LONG, NULL };93 Opcode_CallFunc( Parameter, FuncId, ReturnTypeInfo );94 if( plpRetIndex ){95 *plpRetIndex = ReturnTypeInfo.u.lpIndex;96 }97 return ReturnTypeInfo.type;98 }99 else if(idProc==PROC_PTR){100 /////////////////101 // 関数ポインタ102 /////////////////103 104 LONG_PTR lpIndex;105 GetVarType(name,&lpIndex,0);106 107 extern PROCPTRINFO *pProcPtrInfo;108 ret_type=Opcode_CallProcPtr(name,Parameter,&pProcPtrInfo[lpIndex],plpRetIndex);109 }110 111 return ret_type;112 }113 114 BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo){115 //プロパティ用のメソッドを呼び出す116 117 //配列要素を取得118 char VarName[VN_SIZE],ArrayElements[VN_SIZE];119 GetArrayElement(variable,VarName,ArrayElements);120 121 //オブジェクト名を取得122 char ObjectName[VN_SIZE];123 int RefType;124 SplitObjectName(VarName,ObjectName,&RefType);125 126 //オーバーロード用の関数リストを作成127 SUBINFO **ppsi;128 int num;129 ppsi=GetOverloadSubHash(VarName,&num);130 if(num==0){131 return 0;132 }133 134 //パラメータを整備135 char *Parameter;136 Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(RightSide)+32);137 lstrcpy(Parameter,ArrayElements);138 if(RightSide){139 if(Parameter[0]&&RightSide[0]) lstrcat(Parameter,",");140 lstrcat(Parameter,RightSide);141 }142 143 //オーバーロードを解決144 SUBINFO *psi;145 psi=OverloadSolutionWithStrParam(VarName,ppsi,num,Parameter,ObjectName,NULL);146 HeapDefaultFree(ppsi);147 148 if(psi){149 //呼び出し150 Opcode_CallProc(Parameter,psi,0,ObjectName,RefType);151 152 if( pRetTypeInfo ){153 pRetTypeInfo->type = psi->ReturnType;154 pRetTypeInfo->u.lpIndex = psi->u.ReturnIndex;155 }156 }157 158 HeapDefaultFree(Parameter);159 160 return 1;161 31 } 162 32 -
BasicCompiler64/Compile_Func.cpp
r46 r50 101 101 //左辺の型にのっとり、オーバーロードを解決 102 102 103 SUBINFO **ppsi; 104 int num; 105 ppsi=GetOverloadSubHash( name, &num ); 106 if(!num){ 107 HeapDefaultFree(ppsi); 108 103 std::vector<SUBINFO *> subs; 104 GetOverloadSubHash( name, subs ); 105 if( subs.size() == 0 ){ 109 106 SetError(27,name,cp); 110 107 return; … … 113 110 //オーバーロードを解決 114 111 extern PROCPTRINFO *pProcPtrInfo; 115 psi=OverloadSolution(name,ppsi,num,pProcPtrInfo[ProcPtr_BaseIndex].pParmInfo,pProcPtrInfo[ProcPtr_BaseIndex].ParmNum,NULL); 116 HeapDefaultFree(ppsi); 112 psi=OverloadSolution(name,subs,pProcPtrInfo[ProcPtr_BaseIndex].pParmInfo,pProcPtrInfo[ProcPtr_BaseIndex].ParmNum,NULL); 117 113 118 114 if(!psi){ -
BasicCompiler64/Compile_Object.cpp
r31 r50 2 2 #include "opcode.h" 3 3 4 void CallConstructor(CClass *pobj_c,char *CreateParameter,int ObjectSize,BOOL bSomeObjects){4 void _call_constructor(CClass *pobj_c,char *CreateParameter,int ObjectSize,BOOL bSomeObjects){ 5 5 //////////////////////////// 6 6 // コンストラクタの呼び出し … … 32 32 //////////////////////// 33 33 34 SUBINFO **ppsi; 34 std::vector<SUBINFO *> subs; 35 pobj_c->EnumMethod( pobj_c->name, subs ); 36 35 37 SUBINFO *psi; 36 int num; 37 ppsi=GetOverloadObjectSubHash(pobj_c->name,pobj_c,&num); 38 if(num){ 38 if( subs.size() > 0 ){ 39 39 //オーバーロードを解決 40 40 psi=OverloadSolutionWithStrParam(pobj_c->name, 41 ppsi,num,CreateParameter,"",NULL); 42 HeapDefaultFree(ppsi); 41 subs,CreateParameter,"",NULL); 43 42 44 43 if(!psi) return; … … 227 226 //////////////////////////// 228 227 229 CallConstructor(pobj_c,CreateParameter,TypeSize,bSomeObjects);228 _call_constructor(pobj_c,CreateParameter,TypeSize,bSomeObjects); 230 229 231 230 -
BasicCompiler64/Compile_ProcOp.cpp
r44 r50 84 84 TypeInfo.type=GlobalVar[i].type; 85 85 TypeInfo.u.lpIndex=GlobalVar[i].u.index; 86 CallConstr actor(86 CallConstructor( 87 87 GlobalVar[i].name, 88 88 GlobalVar[i].SubScripts, -
BasicCompiler64/Compile_Statement.cpp
r48 r50 725 725 pobj_c=(CClass *)lpIndex; 726 726 727 SUBINFO **ppsi; 728 int num; 729 ppsi=pobj_c->GetOperatorSubInfo(CALC_EQUAL,num); 730 if(num==0){ 731 HeapDefaultFree(ppsi); 732 727 std::vector<SUBINFO *> subs; 728 pobj_c->EnumMethod( CALC_EQUAL, subs ); 729 if( subs.size() == 0 ){ 733 730 return; 734 731 } … … 746 743 //オーバーロードを解決 747 744 SUBINFO *psi; 748 psi=OverloadSolution("==",ppsi,num,ppi,iParmNum,NULL); 749 HeapDefaultFree(ppsi); 745 psi=OverloadSolution("==",subs,ppi,iParmNum,NULL); 750 746 HeapDefaultFree(ppi); 751 747 -
BasicCompiler64/Compile_Var.cpp
r49 r50 1300 1300 //コンストラクタ呼び出し 1301 1301 if(TypeInfo.type==DEF_OBJECT&&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&& isRef == false ){ 1302 CallConstr actor(VarName,SubScripts,TypeInfo,ConstractParameter);1302 CallConstructor(VarName,SubScripts,TypeInfo,ConstractParameter); 1303 1303 } 1304 1304 } -
BasicCompiler64/Opcode.h
r49 r50 341 341 342 342 public: 343 CParameter(c har *buffer);344 CParameter( PARAMETER_INFO *pParamInfo,int ParmNum);343 CParameter(const char *buffer); 344 CParameter(const PARAMETER_INFO *pParamInfo, const int ParmNum); 345 345 ~CParameter(); 346 346 void SetReturnType(TYPEINFO *pTypeInfo); … … 348 348 private: 349 349 BOOL _overload_check(PARAMETER_INFO *ppi,int pi_num,TYPEINFO *pReturnTypeInfo,int overload_level); 350 SUBINFO *OverloadSolutionWithReturnType( const char *name,SUBINFO **ppsi,int num);350 SUBINFO *OverloadSolutionWithReturnType( const char *name, std::vector<SUBINFO *> &subs ); 351 351 public: 352 SUBINFO *OverloadSolution( const char *name,SUBINFO **ppsi,int num);352 SUBINFO *OverloadSolution( const char *name, std::vector<SUBINFO *> &subs ); 353 353 354 354 BOOL ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum); … … 380 380 //Compile_CallProc.cpp 381 381 void AddLocalVarAddrSchedule(); 382 int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex);383 BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo);384 382 #define PROCFLAG_NEW 1 385 383 int Opcode_CallProcPtr(char *variable,char *Parameter,PROCPTRINFO *pi,LONG_PTR *plpIndex); -
BasicCompiler64/OperatorProc.cpp
r38 r50 31 31 pobj_c=(CClass *)index_stack[sp-2]; 32 32 33 SUBINFO **ppsi; 34 int num; 35 ppsi=pobj_c->GetOperatorSubInfo(idCalc,num); 36 if(num==0){ 37 HeapDefaultFree(ppsi); 38 33 std::vector<SUBINFO *> subs; 34 pobj_c->EnumMethod( idCalc, subs ); 35 if( subs.size() == 0 ){ 39 36 return 0; 40 37 } … … 48 45 int i; 49 46 BOOL bReturnTypeIsObject=1; 50 TYPEINFO ReturnType={DEF_OBJECT, ppsi[0]->u.ReturnIndex};51 for(i=0;i< num;i++){52 if( ppsi[i]->ReturnType!=DEF_OBJECT)47 TYPEINFO ReturnType={DEF_OBJECT,subs[0]->u.ReturnIndex}; 48 for(i=0;i<subs.size();i++){ 49 if(subs[i]->ReturnType!=DEF_OBJECT) 53 50 bReturnTypeIsObject=0; 54 51 } … … 88 85 else GetCalcName(idCalc,temporary); 89 86 SUBINFO *psi; 90 psi=OverloadSolution(temporary, ppsi,num,ppi,iParmNum,pBaseTypeInfo);91 HeapDefaultFree(ppsi); 87 psi=OverloadSolution(temporary,subs,ppi,iParmNum,pBaseTypeInfo); 88 92 89 93 90 if(!psi){ … … 438 435 //インデクサ(getter)を呼び出す 439 436 void CallIndexerGetterProc(int reg,CClass *pobj_Class,char *ObjectName,char *Parameter,TYPEINFO &RetTypeInfo){ 440 SUBINFO **ppsi; 441 int num; 442 ppsi=pobj_Class->GetOperatorSubInfo(CALC_ARRAY_GET,num); 443 if(num==0){ 444 HeapDefaultFree(ppsi); 445 437 438 std::vector<SUBINFO *> subs; 439 pobj_Class->EnumMethod( CALC_ARRAY_GET, subs ); 440 if( subs.size() == 0 ){ 446 441 return; 447 442 } … … 452 447 ////////////////////////////////////////////////////// 453 448 454 Opcode_CallProc(Parameter, ppsi[0],0,ObjectName,DEF_OBJECT);455 RetTypeInfo.type = ppsi[0]->ReturnType;456 RetTypeInfo.u.lpIndex = ppsi[0]->u.ReturnIndex;449 Opcode_CallProc(Parameter,subs[0],0,ObjectName,DEF_OBJECT); 450 RetTypeInfo.type = subs[0]->ReturnType; 451 RetTypeInfo.u.lpIndex = subs[0]->u.ReturnIndex; 457 452 458 453 //mov reg,rax … … 464 459 }//////////////////////////////////////////// 465 460 466 HeapDefaultFree(ppsi);467 461 }
Note:
See TracChangeset
for help on using the changeset viewer.