Changeset 40 in dev for BasicCompiler32
- Timestamp:
- Jan 28, 2007, 3:48:22 AM (18 years ago)
- Location:
- BasicCompiler32
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler32/Compile_Calc.cpp
r36 r40 600 600 } 601 601 } 602 603 void SetRefVariable( const char *varname, const char *expression ){ 604 //////////////////////////////////////// 605 // 変数のタイプ型を識別して、演算を行う 606 //////////////////////////////////////// 607 608 int VarType,CalcType; 609 LONG_PTR lpVarIndex,lpCalcIndex; 610 RELATIVE_VAR VarRelativeVar; 611 BOOL bCalcUseHeap; 612 613 //型を識別 614 VarType=GetVarType(varname,&lpVarIndex,0); 615 if(VarType==-1){ 616 SetError(300,NULL,cp); 617 return; 618 } 619 620 extern LONG_PTR ProcPtr_BaseIndex; 621 if(VarType==DEF_PTR_PROC) ProcPtr_BaseIndex=lpVarIndex; 622 else ProcPtr_BaseIndex=-1; 623 624 if(VarType==DEF_OBJECT){ 625 //代入演算のオーバーロード オペレータに備える 626 627 //変数アドレスを取得 628 if(!GetVarOffsetReadWrite( 629 varname, 630 &VarType, 631 &VarRelativeVar, 632 &lpVarIndex)) return; 633 634 SetVarPtrToEax(&VarRelativeVar); 635 636 //push eax 637 op_push(REG_EAX); 638 } 639 640 641 //NumOpe...(スタックに答えが格納される) 642 CalcType=NumOpe(expression,VarType,lpVarIndex,&lpCalcIndex,&bCalcUseHeap); 643 if(VarType==-1||CalcType==-1) return; 644 645 //変数アドレスを取得 646 if(!GetVarOffsetReadWrite( 647 varname, 648 &VarType, 649 &VarRelativeVar, 650 &lpVarIndex)) return; 651 652 if(VarType&FLAG_PTR){ 653 SetError(14,varname,cp); 654 return; 655 } 656 657 658 if( VarType == DEF_OBJECT && VarRelativeVar.dwKind == VAR_REFLOCAL ){ 659 // 参照型オブジェクトへの代入(初期化)はポインタ変数と同様の処理に値する 660 VarType = PTR_LEVEL_UP( VarType ); 661 662 VarRelativeVar.dwKind = VAR_LOCAL; 663 664 if( CalcType == DEF_OBJECT ){ 665 //右辺値が実体オブジェクトのときは、参照をコピー 666 CalcType = PTR_LEVEL_UP( DEF_OBJECT ); 667 } 668 } 669 else{ 670 SetError(300,NULL,cp); 671 } 672 673 674 ///////////////////////////////// 675 // 右辺、左辺の型チェックを行う 676 ///////////////////////////////// 677 678 CheckDifferentType(VarType,lpVarIndex,CalcType,lpCalcIndex,0,0); 679 680 681 ///////////////////////////////////////////////// 682 // スタックの内容を変数にコピーするコードを抽出 683 ///////////////////////////////////////////////// 684 685 if(VarType==DEF_BOOLEAN){ 686 //bool 687 SetBooleanVariable(CalcType,&VarRelativeVar); 688 } 689 else if(VarType==DEF_CHAR||VarType==DEF_BYTE){ 690 //8ビット整数型変数へスタックの内容を格納する 691 Set8Variable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 692 } 693 else if(VarType==DEF_INTEGER||VarType==DEF_WORD){ 694 //16ビット整数型変数へスタックの内容を格納する 695 Set16Variable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 696 } 697 else if(VarType==DEF_LONG||VarType==DEF_DWORD||IsPtrType(VarType)){ 698 //32ビット整数型変数へスタックの内容を格納する 699 if(VarType==DEF_LONG) 700 SetLongVariable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 701 else 702 SetDWordVariable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 703 } 704 else if(VarType==DEF_INT64||VarType==DEF_QWORD){ 705 //64ビット整数型変数へスタックの内容を格納する 706 SetInt64Variable(CalcType,&VarRelativeVar); 707 } 708 else if(VarType==DEF_DOUBLE){ 709 //Double型変数へスタックの内容を格納する 710 SetDoubleVariable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 711 } 712 else if(VarType==DEF_SINGLE){ 713 //Single型変数へスタックの内容を格納する 714 SetSingleVariable(CalcType,VarRelativeVar.dwKind,VarRelativeVar.offset,VarRelativeVar.bOffsetOffset); 715 } 716 } -
BasicCompiler32/Compile_CallProc.cpp
r31 r40 337 337 } 338 338 339 if(psi->ReturnType==DEF_OBJECT ){339 if(psi->ReturnType==DEF_OBJECT && psi->isReturnRef == false ){ 340 340 //_System_ReturnObject(第一または第二パラメータのダミーを作成) 341 341 sprintf(temporary+lstrlen(temporary),"%c%c0,",1,ESC_BYVAL); … … 375 375 376 376 377 378 if(psi->ReturnType==DEF_OBJECT){ 377 if(psi->ReturnType==DEF_OBJECT && psi->isReturnRef == false){ 379 378 ////////////////////////////////////////////////////// 380 379 // 戻り値にオブジェクト インスタンスを持つ場合 -
BasicCompiler32/Compile_Object.cpp
r31 r40 75 75 } 76 76 } 77 int Operator_New(c har *Parameter,LONG_PTR *plpIndex){77 int Operator_New(const char *Parameter,LONG_PTR *plpIndex){ 78 78 char TypeName[VN_SIZE],CreateParameter[VN_SIZE],ObjectSize[VN_SIZE]; 79 79 int i,i2; -
BasicCompiler32/Compile_ProcOp.cpp
r36 r40 374 374 else temp=psi->name; 375 375 376 if(psi->ReturnType==DEF_OBJECT ){376 if(psi->ReturnType==DEF_OBJECT && psi->isReturnRef == false){ 377 377 //戻り値用オブジェクトのコンストラクタを呼び出す 378 378 if(psi->u.Return_pobj_c->ConstructorMemberSubIndex!=-1){ … … 383 383 else{ 384 384 //戻り値用の変数の定義 385 sprintf(temporary,"%s%c%c",temp,1,ESC_AS); 385 if( psi->isReturnRef ){ 386 sprintf(temporary,"%c%c",1,ESC_BYREF); 387 } 388 else temporary[0]=0; 389 390 sprintf(temporary+lstrlen(temporary),"%s%c%c",temp,1,ESC_AS); 386 391 GetTypeName(psi->ReturnType,psi->u.ReturnIndex,temporary+lstrlen(temporary)); 392 387 393 OpcodeDim(temporary,0); 388 394 } … … 514 520 else offset=0; 515 521 for(i3=0;i3<pobj_CompilingClass->iMemberNum;i3++){ 516 offset=GetSizeOfClassMember(pobj_CompilingClass,pobj_CompilingClass->ppobj_Member[i3]->name,NULL); 517 518 if(pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.type==DEF_OBJECT){ 519 if(pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->ConstructorMemberSubIndex!=-1){ 520 i5=pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->ConstructorMemberSubIndex; 521 if(pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->ppobj_Method[i5]->psi->RealParmNum==1){ //Thisポインタを第一引数に持ち合わせるため、引数なしの場合はこの値が1になる 522 CMember *pMember = pobj_CompilingClass->ppobj_Member[i3]; 523 524 offset=GetSizeOfClassMember(pobj_CompilingClass,pMember->name,NULL); 525 526 if(pMember->TypeInfo.type==DEF_OBJECT){ 527 if(pMember->TypeInfo.u.pobj_Class->ConstructorMemberSubIndex!=-1){ 528 i5=pMember->TypeInfo.u.pobj_Class->ConstructorMemberSubIndex; 529 if(pMember->TypeInfo.u.pobj_Class->ppobj_Method[i5]->psi->RealParmNum==1){ //Thisポインタを第一引数に持ち合わせるため、引数なしの場合はこの値が1になる 522 530 523 531 MemberTypeSize= 524 GetTypeSize(p obj_CompilingClass->ppobj_Member[i3]->TypeInfo.type,525 p obj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.lpIndex);532 GetTypeSize(pMember->TypeInfo.type, 533 pMember->TypeInfo.u.lpIndex); 526 534 527 535 MemberObjectNum= 528 JumpSubScripts(p obj_CompilingClass->ppobj_Member[i3]->SubScripts);536 JumpSubScripts(pMember->SubScripts); 529 537 530 538 for(i4=0;i4<MemberObjectNum;i4++){ … … 542 550 543 551 //call constructor 544 op_call(p obj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->ppobj_Method[i5]->psi);552 op_call(pMember->TypeInfo.u.pobj_Class->ppobj_Method[i5]->psi); 545 553 } 546 554 } … … 624 632 offset=GetTypeSize(DEF_OBJECT,(LONG_PTR)pobj_CompilingClass); 625 633 for(i3=pobj_CompilingClass->iMemberNum-1;i3>=0;i3--){ 634 CMember *pMember = pobj_CompilingClass->ppobj_Member[i3]; 635 626 636 MemberTypeSize= 627 GetTypeSize(p obj_CompilingClass->ppobj_Member[i3]->TypeInfo.type,628 p obj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.lpIndex);637 GetTypeSize(pMember->TypeInfo.type, 638 pMember->TypeInfo.u.lpIndex); 629 639 630 640 MemberObjectNum= 631 JumpSubScripts(p obj_CompilingClass->ppobj_Member[i3]->SubScripts);641 JumpSubScripts(pMember->SubScripts); 632 642 633 643 offset-=MemberTypeSize*MemberObjectNum; 634 644 635 if(p obj_CompilingClass->ppobj_Member[i3]->TypeInfo.type==DEF_OBJECT){636 if(p obj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->DestructorMemberSubIndex!=-1){645 if(pMember->TypeInfo.type==DEF_OBJECT){ 646 if(pMember->TypeInfo.u.pobj_Class->DestructorMemberSubIndex!=-1){ 637 647 for(i4=MemberObjectNum-1;i4>=0;i4--){ 638 648 //Thisポインタをecxにコピー … … 649 659 650 660 //call destructor 651 i5=p obj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->DestructorMemberSubIndex;652 op_call(p obj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->ppobj_Method[i5]->psi);661 i5=pMember->TypeInfo.u.pobj_Class->DestructorMemberSubIndex; 662 op_call(pMember->TypeInfo.u.pobj_Class->ppobj_Method[i5]->psi); 653 663 } 654 664 } -
BasicCompiler32/Compile_Statement.cpp
r36 r40 1359 1359 else temp=pCompilingSubInfo->name; 1360 1360 1361 char temporary[VN_SIZE]; 1362 sprintf(temporary,"%s=%s",temp,Parameter); 1363 OpcodeCalc(temporary); 1361 if( pCompilingSubInfo->isReturnRef ){ 1362 //参照型 1363 SetRefVariable( temp, Parameter ); 1364 } 1365 else{ 1366 //値型 1367 char temporary[VN_SIZE]; 1368 sprintf(temporary,"%s=%s",temp,Parameter); 1369 OpcodeCalc(temporary); 1370 } 1364 1371 } 1365 1372 -
BasicCompiler32/Compile_Var.cpp
r36 r40 179 179 } 180 180 181 CMember *pMember=pobj_c->ppobj_Member[i]; 182 181 183 //アクセシビリティをチェック 182 184 if(pobj_c==pobj_CompilingClass){ 183 185 //同一クラスオブジェクトの場合はプライベートアクセスを容認する 184 if(p obj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){186 if(pMember->dwAccess==ACCESS_NON){ 185 187 if(isErrorEnabled) SetError(107,VarName,cp); 186 188 return 0; … … 188 190 } 189 191 else{ 190 if((bPrivateAccess==0&&p obj_c->ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)||191 p obj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){192 if((bPrivateAccess==0&&pMember->dwAccess==ACCESS_PRIVATE)|| 193 pMember->dwAccess==ACCESS_NON){ 192 194 if(isErrorEnabled) SetError(107,VarName,cp); 193 195 return 0; 194 196 } 195 else if(bPrivateAccess==0&&p obj_c->ppobj_Member[i]->dwAccess==ACCESS_PROTECTED){197 else if(bPrivateAccess==0&&pMember->dwAccess==ACCESS_PROTECTED){ 196 198 if(isErrorEnabled) SetError(108,VarName,cp); 197 199 return 0; … … 201 203 //Const定義の場合は書き込みアクセスを制限する 202 204 //※コンストラクタをコンパイル中の場合は例外的に許可する 203 if( p obj_c->ppobj_Member[i]->IsConst() && //定数メンバである205 if( pMember->IsConst() && //定数メンバである 204 206 isWriteAccess && //書き込みアクセスを要求されている 205 207 pobj_c->IsCompilingConstructor() == false //コンストラクタ コンパイル中を除く … … 209 211 } 210 212 211 *pType=p obj_c->ppobj_Member[i]->TypeInfo.type;212 *plpNestIndex=p obj_c->ppobj_Member[i]->TypeInfo.u.lpIndex;213 *pType=pMember->TypeInfo.type; 214 *plpNestIndex=pMember->TypeInfo.u.lpIndex; 213 215 214 216 //ポインタ変数の場合 215 217 if(IsPtrType(*pType)){ 216 if(p obj_c->ppobj_Member[i]->SubScripts[0]==-1){218 if(pMember->SubScripts[0]==-1){ 217 219 lstrcpy(lpPtrOffset,array); 218 220 array[0]=0; … … 236 238 if(array[0]){ 237 239 //配列オフセット 238 if(!GetArrayOffset(p obj_c->ppobj_Member[i]->SubScripts,array,*pType,pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex))240 if(!GetArrayOffset(pMember->SubScripts,array,*pType,pMember->TypeInfo.u.lpIndex)) 239 241 if(isErrorEnabled) SetError(14,member,cp); 240 242 } 241 else if(p obj_c->ppobj_Member[i]->SubScripts[0]!=-1){243 else if(pMember->SubScripts[0]!=-1){ 242 244 *pType|=FLAG_PTR; 243 245 } … … 320 322 isErrorEnabled, 321 323 isWriteAccess, 322 p obj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class,324 pMember->TypeInfo.u.pobj_Class, 323 325 NestMember, 324 326 pType, … … 357 359 } 358 360 359 BOOL GetVarOffset(bool isErrorEnabled, bool isWriteAccess, c har *NameBuffer, int *pType, RELATIVE_VAR *pRelativeVar, LONG_PTR *plpIndex, int *pss){361 BOOL GetVarOffset(bool isErrorEnabled, bool isWriteAccess, const char *NameBuffer, int *pType, RELATIVE_VAR *pRelativeVar, LONG_PTR *plpIndex, int *pss){ 360 362 extern BOOL bCompilingGlobal; 361 363 int i,RefType; … … 907 909 /////////////////////////////////////// 908 910 909 if( type == DEF_OBJECT){910 //オブジェクトの場合はありえない911 SetError(300,NULL,cp);912 return 0;913 }914 915 911 if(SubScripts[0]!=-1){ 916 912 SetError(41,0,cp); … … 1064 1060 } 1065 1061 1066 void dim(char *Parameter,DWORD dwFlag ){1062 void dim(char *Parameter,DWORD dwFlags){ 1067 1063 extern BOOL bCompilingGlobal; 1068 1064 extern HANDLE hHeap; … … 1071 1067 1072 1068 1073 if(dwFlag & DIMFLAG_CONST){ 1069 //参照型かどうか 1070 bool isRef = false; 1071 1072 i2 = 0; 1073 1074 if( Parameter[i2] == 1 && Parameter[i2+1] == ESC_BYREF ){ 1075 //参照型 1076 isRef = true; 1077 Parameter += 2; 1078 } 1079 1080 1081 if(dwFlags & DIMFLAG_CONST){ 1074 1082 ////////////////////////////////// 1075 1083 // 定数変数の場合を考慮 1076 1084 ////////////////////////////////// 1077 for( i2=0;;i2++){1085 for(;;i2++){ 1078 1086 if(Parameter[i2] == '=' || 1079 1087 Parameter[i2] == 1 && Parameter[i2] == ESC_AS || … … 1102 1110 char InitBuf[8192]; 1103 1111 char ConstractParameter[VN_SIZE]; 1104 if(!GetDimentionFormat(Parameter, VarName,SubScripts,&TypeInfo,InitBuf,ConstractParameter))1112 if(!GetDimentionFormat(Parameter, isRef, VarName,SubScripts,&TypeInfo,InitBuf,ConstractParameter)) 1105 1113 return; 1106 1114 … … 1123 1131 TypeSize=GetTypeSize(TypeInfo.type,TypeInfo.u.lpIndex); 1124 1132 1125 if(dwFlag &DIMFLAG_STATIC){1133 if(dwFlags&DIMFLAG_STATIC){ 1126 1134 if(bCompilingGlobal){ 1127 1135 SetError(60,NULL,cp); … … 1137 1145 GetNowStaticVarFullName(VarName,temporary); 1138 1146 1139 AddGlobalVariable(temporary,SubScripts,&TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlag );1147 AddGlobalVariable(temporary,SubScripts,&TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags); 1140 1148 1141 1149 /* … … 1150 1158 ///////////////////////// 1151 1159 1152 AddGlobalVariable(VarName,SubScripts,&TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlag );1160 AddGlobalVariable(VarName,SubScripts,&TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags); 1153 1161 } 1154 1162 else{ … … 1168 1176 1169 1177 LocalVar=(VARIABLE *)HeapReAlloc(hHeap,0,LocalVar,(MaxLocalVarNum+1)*sizeof(VARIABLE)); 1178 VARIABLE *pVar = &LocalVar[MaxLocalVarNum]; 1179 MaxLocalVarNum++; 1180 1181 if( isRef ){ 1182 //参照型 1183 pVar->fRef = REF_VARIABLE; 1184 TypeSize = PTR_SIZE; 1185 } 1186 else pVar->fRef=0; 1170 1187 1171 1188 for(i2=1,i3=0;i3<255;i3++){ 1172 1189 //配列要素数 1173 LocalVar[MaxLocalVarNum].SubScripts[i3]=SubScripts[i3];1190 pVar->SubScripts[i3]=SubScripts[i3]; 1174 1191 1175 1192 if(SubScripts[i3]==-1) break; … … 1179 1196 if(VarSize%4) VarSize+=4-(VarSize%4); 1180 1197 1181 VARIABLE *pVar = &LocalVar[MaxLocalVarNum];1182 1183 MaxLocalVarNum++;1184 1185 1198 //変数データを追加 1186 1199 lstrcpy(pVar->name,VarName); 1187 pVar->fRef=0; 1188 if(dwFlag & DIMFLAG_CONST) pVar->bConst = true; 1200 if(dwFlags & DIMFLAG_CONST) pVar->bConst = true; 1189 1201 else pVar->bConst = false; 1190 1202 if(SubScripts[0]==-1) pVar->bArray=0; … … 1212 1224 1213 1225 if(!result){ 1214 //動的な式だった場合は代入演算を行う 1215 char temporary[8192]; 1216 sprintf(temporary,"%s=%s",VarName,InitBuf); 1217 OpcodeCalc(temporary); 1226 if( isRef ){ 1227 SetRefVariable( VarName, InitBuf ); 1228 } 1229 else{ 1230 char temporary[8192]; 1231 sprintf(temporary,"%s=%s",VarName,InitBuf); 1232 OpcodeCalc(temporary); 1233 } 1218 1234 } 1219 1235 … … 1252 1268 1253 1269 //コンストラクタ呼び出し 1254 if(TypeInfo.type==DEF_OBJECT&&(dwFlag &DIMFLAG_NONCALL_CONSTRACTOR)==0){1270 if(TypeInfo.type==DEF_OBJECT&&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&& isRef == false ){ 1255 1271 CallConstractor(VarName,SubScripts,TypeInfo,ConstractParameter); 1256 1272 } … … 1264 1280 } 1265 1281 } 1266 void OpcodeDim(char *Parameter,DWORD dwFlag ){1282 void OpcodeDim(char *Parameter,DWORD dwFlags){ 1267 1283 int i,i2,i3,IsStr=0; 1268 1284 char temporary[8192]; … … 1286 1302 temporary[i2]=0; 1287 1303 1288 dim(temporary,dwFlag );1304 dim(temporary,dwFlags); 1289 1305 1290 1306 if(Parameter[i]=='\0') break; -
BasicCompiler32/NumOpe.cpp
r38 r40 113 113 114 114 115 int NumOpe(c har *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap){115 int NumOpe(const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap){ 116 116 extern HANDLE hHeap; 117 117 int i,i2,i3,i4; -
BasicCompiler32/Opcode.h
r38 r40 95 95 void ChangeTypeToByte(int OldType); 96 96 void OpcodeCalc(char *Command); 97 void SetRefVariable( const char *varname, const char *expression ); 97 98 98 99 //NumOpe.cpp 99 100 void PushReturnValue(int type); 100 int NumOpe(c har *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap=0);101 int NumOpe(const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap=0); 101 102 102 103 //NumOpe_Arithmetic.cpp … … 167 168 168 169 //Compile_Object.cpp 169 int Operator_New(c har *Parameter,LONG_PTR *plpIndex);170 int Operator_New(const char *Parameter,LONG_PTR *plpIndex); 170 171 void OpcodeDelete(char *Parameter); 171 172 … … 173 174 void GetWithName(char *buffer); 174 175 void SetThisPtrToReg(int reg); 175 BOOL GetVarOffset(bool isErrorEnabled,bool isWriteAccess,c har *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);176 BOOL GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0); 176 177 BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf); 177 178 #define DIMFLAG_INITDEBUGVAR 1
Note:
See TracChangeset
for help on using the changeset viewer.