Changeset 75 in dev for BasicCompiler64
- Timestamp:
- Mar 20, 2007, 4:36:16 AM (18 years ago)
- Location:
- BasicCompiler64
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler64/BasicCompiler.vcproj
r71 r75 22 22 UseOfMFC="0" 23 23 ATLMinimizesCRunTimeLibraryUsage="false" 24 CharacterSet=" 0"24 CharacterSet="2" 25 25 > 26 26 <Tool … … 52 52 MinimalRebuild="true" 53 53 BasicRuntimeChecks="0" 54 RuntimeLibrary=" 3"54 RuntimeLibrary="1" 55 55 UsePrecompiledHeader="0" 56 56 PrecompiledHeaderFile=".\Debug/BasicCompiler.pch" … … 125 125 UseOfMFC="0" 126 126 ATLMinimizesCRunTimeLibraryUsage="false" 127 CharacterSet=" 0"127 CharacterSet="2" 128 128 > 129 129 <Tool … … 322 322 UseOfMFC="0" 323 323 ATLMinimizesCRunTimeLibraryUsage="false" 324 CharacterSet=" 0"324 CharacterSet="2" 325 325 > 326 326 <Tool … … 473 473 > 474 474 <File 475 RelativePath="..\BasicCompiler_Common\Parameter.h" 476 > 477 </File> 478 <File 479 RelativePath="..\BasicCompiler_Common\Procedure.h" 480 > 481 </File> 482 <File 475 483 RelativePath="..\BasicCompiler_Common\Type.h" 484 > 485 </File> 486 <File 487 RelativePath="..\BasicCompiler_Common\Variable.h" 476 488 > 477 489 </File> … … 1522 1534 > 1523 1535 <File 1524 RelativePath="..\BasicCompiler_Common\Variable .cpp"1525 > 1526 </File> 1527 <File 1528 RelativePath="..\BasicCompiler_Common\Variable .h"1536 RelativePath="..\BasicCompiler_Common\VariableOpe.cpp" 1537 > 1538 </File> 1539 <File 1540 RelativePath="..\BasicCompiler_Common\VariableOpe.h" 1529 1541 > 1530 1542 </File> … … 1545 1557 Name="Procedure" 1546 1558 > 1547 <File1548 RelativePath="..\BasicCompiler_Common\Parameter.h"1549 >1550 </File>1551 1559 <File 1552 1560 RelativePath="..\BasicCompiler_Common\ParamImpl.cpp" … … 1563 1571 > 1564 1572 <File 1573 RelativePath="..\BasicCompiler_Common\Procedure.cpp" 1574 > 1575 </File> 1576 <File 1565 1577 RelativePath="..\BasicCompiler_Common\Type.cpp" 1578 > 1579 </File> 1580 <File 1581 RelativePath="..\BasicCompiler_Common\Variable.cpp" 1566 1582 > 1567 1583 </File> -
BasicCompiler64/CParameter.cpp
r73 r75 2 2 #include "opcode.h" 3 3 4 int ParamImpl::NewTempParameters( const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum ){ 4 int ParamImpl::NewTempParameters( const string &procName, const Parameters ¶ms, int SecondParmNum ){ 5 if( SecondParmNum == -1 ) SecondParmNum = (int)params.size(); 6 5 7 /////////////////////////////////////////////////////// 6 8 // 一時オブジェクトをあらかじめスタックに積んでおく … … 12 14 13 15 BOOL bEllipse; 14 if(p i_num){15 if(p pi[pi_num-1].type==DEF_ELLIPSE) bEllipse=1;16 if(params.size()){ 17 if(params[params.size()-1]->GetBasicType()==DEF_ELLIPSE) bEllipse=1; 16 18 else bEllipse=0; 17 19 } … … 21 23 useTempParameters[i2] = false; 22 24 23 if(bEllipse&&i2<= pi_num-2) bEllipse=0;24 25 if(i2==0 &&ppi[i2].name){26 if( lstrcmp(ppi[i2].name,"_System_LocalThis")==0){25 if(bEllipse&&i2<=(int)params.size()-2) bEllipse=0; 26 27 if(i2==0){ 28 if( params[i2]->GetVarName() == "_System_LocalThis" ){ 27 29 //オブジェクトメンバの第一パラメータのThisポインタ 28 30 continue; 29 31 } 30 32 } 31 if( (i2==0||i2==1)&&ppi[i2].name){32 if( lstrcmp(ppi[i2].name,FuncName)==0){33 if( i2==0||i2==1 ){ 34 if( params[i2]->GetVarName() == procName ){ 33 35 //オブジェクトメンバの第一または第二パラメータの戻り値用オブジェクト 34 36 continue; … … 36 38 } 37 39 38 T YPEINFO DummyTypeInfo;40 Type dummyType; 39 41 BOOL bByVal; 40 42 if(bEllipse){ 41 DummyTypeInfo.type=NumOpe_GetType(Parms[i2],NULL,&DummyTypeInfo.u.lpIndex);43 NumOpe_GetType( Parms[i2], Type(), dummyType ); 42 44 bByVal=1; 43 45 } 44 46 else{ 45 DummyTypeInfo.type=ppi[i2].type; 46 DummyTypeInfo.u.lpIndex=ppi[i2].u.index; 47 bByVal=ppi[i2].bByVal; 47 dummyType = *params[i2]; 48 bByVal = ( params[i2]->IsRef() == false ) ? TRUE:FALSE; 48 49 } 49 50 … … 56 57 } 57 58 58 LONG_PTR lpVarIndex; 59 if( GetVarType( Parms[i2], &lpVarIndex, FALSE ) == -1 ){ 59 if( !GetVarType( Parms[i2], Type(), FALSE ) ){ 60 60 //変数ではないとき 61 61 int reg = REG_RAX; 62 int type = NumOpe( ®, Parms[i2], DummyTypeInfo.type, DummyTypeInfo.u.lpIndex, &lpVarIndex ); 63 64 if( type != DEF_STRUCT ){ 62 Type calcType; 63 NumOpe( ®, Parms[i2], dummyType, calcType ); 64 65 if( !calcType.IsStruct() ){ 65 66 //一時参照を作成 66 67 pobj_sf->push( reg ); … … 76 77 77 78 bool result = CheckDifferentType( 78 DummyTypeInfo.type, 79 DummyTypeInfo.u.lpIndex, 80 type, 81 lpVarIndex, 82 FuncName, 79 dummyType, 80 calcType, 81 procName.c_str(), 83 82 i2); 84 83 … … 87 86 useTempObject = true; 88 87 89 types[i2].type = type; 90 types[i2].u.lpIndex = lpVarIndex; 88 types[i2] = calcType; 91 89 } 92 90 } … … 104 102 for(int i2=ParmsNum-1;i2>=0;i2--){ 105 103 if( useTempParameters[i2] ){ 106 if( types[i2]. type == DEF_STRUCT){104 if( types[i2].IsStruct() ){ 107 105 // 構造体の一時メモリ 108 106 … … 112 110 113 111 //call free 114 extern SubInfo*pSub_free;112 extern UserProc *pSub_free; 115 113 op_call(pSub_free); 116 114 } … … 123 121 } 124 122 125 void ParamImpl::SetStructParameter( int reg,CClass *pobj_Class,LPSTR Parameter){123 void ParamImpl::SetStructParameter( int reg, const Type &baseType, const char *expression ){ 126 124 ////////////////////////////////////////////////////// 127 125 ///// レジスタ資源のバックアップ … … 129 127 ////////////////////////////////////////////////////// 130 128 131 int object_size = pobj_Class->GetSize();129 int object_size = baseType.GetClass().GetSize(); 132 130 133 131 //mov rcx,object_size … … 135 133 136 134 //call calloc 137 extern SubInfo*pSub_calloc;135 extern UserProc *pSub_calloc; 138 136 op_call(pSub_calloc); 139 137 … … 144 142 pobj_sf->push(REG_R11); 145 143 146 TYPEINFO BaseType={DEF_STRUCT,(LONG_PTR)pobj_Class}; 147 TYPEINFO CalcType; 148 CalcType.type=NumOpe_GetType(Parameter,&BaseType,&CalcType.u.lpIndex); 149 150 /* 151 TODO: 消す 152 if( pobj_Class->GetCopyConstructorMethod() 153 && CalcType.type==DEF_OBJECT&&CalcType.u.pobj_Class==pobj_Class){ 154 //////////////////////////////////// 155 // コピーコンストラクタを呼び出す 156 //////////////////////////////////// 157 158 BOOL bUseHeap; 159 int temp_reg=REG_RDX; 160 CalcType.type=NumOpe(&temp_reg,Parameter,DEF_OBJECT,(LONG_PTR)pobj_Class,&CalcType.u.lpIndex,&bUseHeap); 161 162 if(bUseHeap){ 163 //mov r14,rdx 164 op_mov_RR(REG_R14,REG_RDX); 165 } 166 167 //mov r11,qword ptr[rsp+offset] ※スタックフレームを利用 168 pobj_sf->ref(REG_R11); 169 170 //mov rcx,this 171 op_mov_RR(REG_RCX,REG_R11); 172 173 //call constructor 174 op_call(pobj_Class->GetCopyConstructorMethod()->psi); 175 176 177 if(bUseHeap){ 178 FreeTempObject(REG_R14,pobj_Class); 179 } 180 } 181 else{ 182 if( pobj_Class->GetConstructorMethod() ){ 183 //////////////////////////////// 184 // コンストラクタを呼び出す 185 //////////////////////////////// 186 187 //mov rcx,this 188 op_mov_RR(REG_RCX,REG_R11); 189 190 //call constructor 191 op_call(pobj_Class->GetConstructorMethod()->psi); 192 } 193 */ 194 195 196 BOOL bUseHeap; 197 int temp_reg=REG_RAX; 198 CalcType.type=NumOpe(&temp_reg,Parameter,DEF_STRUCT,(LONG_PTR)pobj_Class,&CalcType.u.lpIndex,&bUseHeap); 199 200 201 //mov r11,qword ptr[rsp+offset] ※スタックフレームを利用 202 pobj_sf->ref(REG_R11); 203 204 205 RELATIVE_VAR RelativeVar; 206 RelativeVar.bOffsetOffset=0; 207 RelativeVar.offset=0; 208 RelativeVar.dwKind=VAR_DIRECTMEM; 209 210 SetStructVariableFromRax((LONG_PTR)pobj_Class,CalcType.type,CalcType.u.lpIndex,&RelativeVar,bUseHeap); 211 212 //} 144 145 Type calcType; 146 BOOL bUseHeap; 147 int temp_reg=REG_RAX; 148 NumOpe( &temp_reg, 149 expression, 150 baseType, 151 calcType, 152 &bUseHeap ); 153 154 155 //mov r11,qword ptr[rsp+offset] ※スタックフレームを利用 156 pobj_sf->ref(REG_R11); 157 158 159 RELATIVE_VAR RelativeVar; 160 RelativeVar.bOffsetOffset=0; 161 RelativeVar.offset=0; 162 RelativeVar.dwKind=VAR_DIRECTMEM; 163 164 SetStructVariableFromRax( 165 baseType, 166 calcType, 167 &RelativeVar,bUseHeap); 168 213 169 214 170 //mov r11,qword ptr[rsp+offset] ※スタックフレームを利用 … … 225 181 226 182 227 void ParamImpl::SetParameter(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum){ 183 void ParamImpl::SetParameter( const string &procName, const Parameters ¶ms, int SecondParmNum ){ 184 if( SecondParmNum == -1 ) SecondParmNum = (int)params.size(); 185 228 186 /////////////////////////////////////////////////////////// 229 187 // パラメータをレジスタ及びスタックフレームにセット … … 232 190 233 191 BOOL bEllipse; 234 if( pi_num){235 if(p pi[pi_num-1].type==DEF_ELLIPSE) bEllipse=1;192 if( params.size() ){ 193 if(params[params.size()-1]->GetBasicType()==DEF_ELLIPSE) bEllipse=1; 236 194 else bEllipse=0; 237 195 } … … 240 198 BOOL bHas_System_LocalThis=0; 241 199 if(ParmsNum>=1){ 242 if( lstrcmp(ppi[0].name,"_System_LocalThis")==0)200 if( params[0]->GetVarName() == "_System_LocalThis" ){ 243 201 bHas_System_LocalThis=1; 202 } 244 203 } 245 204 246 205 //戻り値用の変数名を取得 247 const char *lpszVarNameToReturn = ( FuncName[0]==1&&FuncName[1]==ESC_OPERATOR)?"_System_ReturnValue":FuncName;206 const char *lpszVarNameToReturn = (procName[0]==1&&procName[1]==ESC_OPERATOR)?"_System_ReturnValue":procName.c_str(); 248 207 249 208 //パラメータをレジスタとスタックに格納 250 int CalcType;251 LONG_PTR lpCalcIndex;252 BOOL bCalcUseHeap;253 209 int ParmSize=0; 254 210 int reg,temp_reg; 255 211 RELATIVE_VAR RelativeVar; 256 212 for(i2=ParmsNum-1;i2>=0;i2--){ 257 if(bEllipse&&i2<= pi_num-2) bEllipse=0;258 259 if(i2==0 &&ppi[i2].name){260 if( lstrcmp(ppi[i2].name,"_System_LocalThis")==0){213 if(bEllipse&&i2<=(int)params.size()-2) bEllipse=0; 214 215 if(i2==0){ 216 if( params[i2]->GetVarName() == "_System_LocalThis" ){ 261 217 //オブジェクトメンバの第一パラメータのThisポインタ 262 218 continue; 263 219 } 264 220 } 265 if( (i2==0||i2==1)&&ppi[i2].name){266 if( lstrcmp(ppi[i2].name,lpszVarNameToReturn)==0){221 if(i2==0||i2==1){ 222 if( params[i2]->GetVarName() == lpszVarNameToReturn ){ 267 223 //オブジェクトメンバの第一または第二パラメータの戻り値用オブジェクト 268 224 continue; … … 270 226 } 271 227 272 T YPEINFO DummyTypeInfo;228 Type dummyType; 273 229 BOOL bByVal; 274 230 if(bEllipse){ 275 DummyTypeInfo.type=NumOpe_GetType(Parms[i2],NULL,&DummyTypeInfo.u.lpIndex);231 NumOpe_GetType( Parms[i2], Type(), dummyType ); 276 232 bByVal=1; 277 233 } 278 234 else{ 279 DummyTypeInfo.type=ppi[i2].type; 280 DummyTypeInfo.u.lpIndex=ppi[i2].u.index; 281 bByVal=ppi[i2].bByVal; 235 dummyType = *params[i2]; 236 bByVal = ( params[i2]->IsRef() == false ) ? TRUE:FALSE; 282 237 } 283 238 284 239 int xmm_temp_sw=0; 285 if( IsRealNumberType(DummyTypeInfo.type)&&bByVal){240 if(dummyType.IsReal()&&bByVal){ 286 241 //実数型 287 242 if(i2==0) reg=REG_XMM0; … … 308 263 if(Parms[i2][0]==1&&Parms[i2][1]==ESC_BYVAL){ 309 264 char temp2[255]; 310 sprintf(temp2,"%s関数の第%dパラメータ", FuncName,i2+1);265 sprintf(temp2,"%s関数の第%dパラメータ",procName,i2+1); 311 266 SetError(19,temp2,cp); 312 267 continue; 313 268 } 314 269 315 if( DummyTypeInfo.type==DEF_STRUCT){316 SetStructParameter( reg,DummyTypeInfo.u.pobj_Class,Parms[i2]);270 if( dummyType.IsStruct() ){ 271 SetStructParameter( reg, dummyType, Parms[i2] ); 317 272 goto next; 318 273 } … … 321 276 322 277 extern LONG_PTR ProcPtr_BaseIndex; 323 LONG_PTR back_ProcPtr_BaseIndex; 324 back_ProcPtr_BaseIndex=ProcPtr_BaseIndex; 325 if(DummyTypeInfo.type==DEF_PTR_PROC) ProcPtr_BaseIndex=DummyTypeInfo.u.lpIndex; 326 else ProcPtr_BaseIndex=-1; 327 328 CalcType=NumOpe(&temp_reg,Parms[i2],DummyTypeInfo.type,DummyTypeInfo.u.lpIndex,&lpCalcIndex,&bCalcUseHeap); 278 LONG_PTR back_ProcPtr_BaseIndex = ProcPtr_BaseIndex; 279 if( dummyType.IsProcPtr() ){ 280 ProcPtr_BaseIndex = dummyType.GetIndex(); 281 } 282 else{ 283 ProcPtr_BaseIndex=-1; 284 } 285 286 BOOL bCalcUseHeap; 287 Type calcType; 288 if( !NumOpe( &temp_reg, Parms[i2], dummyType, calcType, &bCalcUseHeap ) ){ 289 break; 290 } 329 291 330 292 ProcPtr_BaseIndex=back_ProcPtr_BaseIndex; 331 293 332 if(CalcType==-1) break; 333 334 if(CalcType==DEF_OBJECT){ 335 if( DummyTypeInfo.type != DEF_OBJECT 294 if( calcType.IsObject() ){ 295 if( !dummyType.IsObject() 336 296 || 337 DummyTypeInfo.type == DEF_OBJECT&&338 ! DummyTypeInfo.u.pobj_Class->IsEqualsOrSubClass( (CClass *)lpCalcIndex) ){297 dummyType.IsObject() && 298 !dummyType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) ){ 339 299 //キャスト演算子のオーバーロードに対応する 340 CallCastOperatorProc( reg,CalcType,lpCalcIndex,bCalcUseHeap,DummyTypeInfo.type,DummyTypeInfo.u.lpIndex);300 CallCastOperatorProc( reg, calcType, bCalcUseHeap,dummyType ); 341 301 } 342 302 } … … 344 304 345 305 if(bEllipse){ 346 if( IsRealNumberType(CalcType)){306 if( calcType.IsReal() ){ 347 307 //整数レジスタへコピー 348 308 //※cdeclの拡張パラメータは実数の場合も汎用レジスタで引渡し … … 358 318 } 359 319 } 360 else if( IsWholeNumberType(CalcType)){320 else if( calcType.IsWhole() ){ 361 321 //整数型の場合は、64ビットへ拡張する 362 ExtendTypeTo64( CalcType,temp_reg);322 ExtendTypeTo64( calcType.GetBasicType(), temp_reg ); 363 323 } 364 324 } … … 369 329 else i3=i2; 370 330 CheckDifferentType( 371 DummyTypeInfo.type, 372 DummyTypeInfo.u.lpIndex, 373 CalcType, 374 lpCalcIndex, 375 FuncName, 331 dummyType, 332 calcType, 333 procName.c_str(), 376 334 i3); 377 335 378 379 if(DummyTypeInfo.type==DEF_DOUBLE){ 336 if( dummyType.IsDouble() ){ 380 337 //Double型へ変換 381 ChangeTypeToXmm_Double( CalcType,reg,temp_reg);382 } 383 else if( DummyTypeInfo.type==DEF_SINGLE){338 ChangeTypeToXmm_Double(calcType.GetBasicType(),reg,temp_reg); 339 } 340 else if( dummyType.IsSingle() ){ 384 341 //Single型へ変換 385 ChangeTypeToXmm_Single( CalcType,reg,temp_reg);386 } 387 else if( IsWholeNumberType(DummyTypeInfo.type)){342 ChangeTypeToXmm_Single(calcType.GetBasicType(),reg,temp_reg); 343 } 344 else if( dummyType.IsWhole() ){ 388 345 //実数型 → 整数型 389 ChangeTypeToWhole( CalcType,DummyTypeInfo.type,reg,temp_reg);346 ChangeTypeToWhole(calcType.GetBasicType(),dummyType.GetBasicType(),reg,temp_reg); 390 347 } 391 348 } … … 397 354 398 355 temp_reg=reg; 399 CalcType=NumOpe(&temp_reg,Parms[i2]+2,0,0,&lpCalcIndex); 400 if(CalcType==-1) break; 401 402 int ptr_type; 403 ptr_type=GetPtrType(DummyTypeInfo.type,DummyTypeInfo.u.lpIndex); 356 Type calcType; 357 if( !NumOpe(&temp_reg, Parms[i2]+2, dummyType, calcType) ){ 358 break; 359 } 360 361 dummyType.PtrLevelUp(); 404 362 405 363 //型チェック … … 407 365 else i3=i2; 408 366 CheckDifferentType( 409 ptr_type, 410 DummyTypeInfo.u.lpIndex, 411 CalcType, 412 lpCalcIndex, 413 FuncName, 367 dummyType, 368 calcType, 369 procName.c_str(), 414 370 i3); 415 371 416 if( IsRealNumberType(CalcType)){372 if( calcType.IsReal() ){ 417 373 //実数型 → 整数型 418 ChangeTypeToWhole( CalcType,DEF_QWORD,reg,temp_reg);374 ChangeTypeToWhole( calcType.GetBasicType(), DEF_QWORD,reg,temp_reg); 419 375 } 420 376 } … … 428 384 else{ 429 385 //変数のアドレスを取得 430 int VarType; 431 LONG_PTR lpVarIndex; 386 Type varType; 432 387 if(GetVarOffset( 433 388 false, 434 389 false, 435 390 Parms[i2], 436 &VarType,437 391 &RelativeVar, 438 &lpVarIndex)){439 440 if( DummyTypeInfo.type!=DEF_ANY){392 varType)){ 393 394 if( !dummyType.IsAny() ){ 441 395 //型チェックを行う 442 if( DummyTypeInfo.type==VarType){443 if( DummyTypeInfo.type==DEF_OBJECT){444 if( ! DummyTypeInfo.u.pobj_Class->IsEqualsOrSubClass( (CClass *)lpVarIndex) ){396 if( dummyType.GetBasicType() == varType.GetBasicType() ){ 397 if( dummyType.IsObject() ){ 398 if( !dummyType.GetClass().IsEqualsOrSubClass( &varType.GetClass() ) ){ 445 399 SetError(11,Parms[i2],cp); 446 400 } 447 401 } 448 else if( DummyTypeInfo.type==DEF_STRUCT){449 if( ! DummyTypeInfo.u.pobj_Class->IsEquals( (CClass *)lpVarIndex) ){402 else if( dummyType.IsStruct() ){ 403 if( !dummyType.GetClass().IsEquals( &varType.GetClass() ) ){ 450 404 SetError(11,Parms[i2],cp); 451 405 } 452 406 } 453 407 } 454 else if((VarType&FLAG_PTR)&&((VarType^FLAG_PTR)==DummyTypeInfo.type)){ 408 else if( (varType.GetBasicType()&FLAG_PTR) 409 &&((varType.GetBasicType()^FLAG_PTR)==dummyType.GetBasicType())){ 455 410 //仮引数がポインタ参照で、実引数が配列の先頭ポインタのとき 456 411 } … … 494 449 495 450 //パラメータが収まるだけのスタックフレームを確保 496 pobj_sf->parameter_allocate( pi_num*sizeof(_int64)+ sizeof(_int64)/*ret用*/ );451 pobj_sf->parameter_allocate((int)params.size()*sizeof(_int64)+ sizeof(_int64)/*ret用*/ ); 497 452 } 498 453 void ParamImpl::BackupParameter(int pi_num){ -
BasicCompiler64/Compile_Calc.cpp
r64 r75 84 84 } 85 85 86 LONG_PTR lp; 87 if(GetVarType(variable,&lp,0)!=-1){ 86 if(GetVarType(variable,Type(),0)){ 88 87 //変数リストに該当したとき 89 88 SetError(1,NULL,cp); … … 129 128 130 129 char ObjName[VN_SIZE],array_element[VN_SIZE]; 131 CClass *pobj_c;132 130 GetArrayElement(variable,ObjName,array_element); 133 131 if(array_element[0]){ 134 i2=GetVarType(ObjName,(LONG_PTR *)&pobj_c,0);135 if( i2==DEF_OBJECT){132 Type varType; 133 if( GetVarType(ObjName,varType,0) && varType.IsObject() ){ 136 134 char temporary[VN_SIZE]; 137 135 sprintf(temporary,"%s.%c%c%c",ObjName,1,ESC_OPERATOR,CALC_ARRAY_SET); … … 141 139 142 140 int idProc; 143 void *p Info;144 idProc=GetProc(temporary, &pInfo);141 void *pProc; 142 idProc=GetProc(temporary,(void **)&pProc); 145 143 if(idProc){ 146 CallProc(idProc,p Info,temporary,temp2,NULL);144 CallProc(idProc,pProc,temporary,temp2,Type()); 147 145 return; 148 146 } … … 161 159 //////////////////////////////////////// 162 160 163 int VarType,CalcType; 164 LONG_PTR lpVarIndex,lpCalcIndex; 165 BOOL bCalcUseHeap; 161 Type varType; 166 162 167 163 //型を識別 168 VarType=GetVarType(variable,&lpVarIndex,0); 169 if(VarType==-1){ 164 if( !GetVarType(variable,varType,false) ){ 170 165 171 166 // プロパティ用のメソッドを呼び出す 172 if(!CallPropertyMethod( variable,Command+i+1,NULL)){167 if(!CallPropertyMethod( variable, Command+i+1, Type() )){ 173 168 //エラーを表示 174 GetVarType(variable, &lpVarIndex,1);169 GetVarType(variable,varType,true); 175 170 } 176 171 … … 179 174 180 175 extern LONG_PTR ProcPtr_BaseIndex; 181 if( VarType==DEF_PTR_PROC) ProcPtr_BaseIndex=lpVarIndex;176 if(varType.IsProcPtr()) ProcPtr_BaseIndex=varType.GetIndex(); 182 177 else ProcPtr_BaseIndex=-1; 183 178 184 179 //NumOpe...(rax、またはxmm0に答えが格納される) 185 180 int reg=REG_RAX; 186 CalcType=NumOpe(®,Command+i+1,VarType,lpVarIndex,&lpCalcIndex,&bCalcUseHeap); 187 188 if(reg!=REG_RAX&&IsWholeNumberType(CalcType)){ 181 BOOL bCalcUseHeap; 182 Type calcType; 183 if( !NumOpe(®,Command+i+1,varType,calcType,&bCalcUseHeap) ){ 184 return; 185 } 186 187 if(reg!=REG_RAX&&calcType.IsWhole()|| 188 varType.IsNull()||calcType.IsNull()){ 189 189 SetError(300,NULL,cp); 190 190 } 191 192 if(VarType==-1||CalcType==-1) return;193 191 194 192 //結果を格納しているレジスタをブロッキング … … 199 197 if(!GetVarOffsetReadWrite( 200 198 variable, 201 &VarType,202 199 &VarRelativeVar, 203 &lpVarIndex, 204 NULL)) return; 200 varType)) return; 205 201 206 202 //レジスタのブロッキングを解除 207 203 pobj_BlockReg->clear(); 208 204 209 if( VarType&FLAG_PTR){205 if(varType.GetBasicType()&FLAG_PTR){ 210 206 SetError(14,variable,cp); 211 207 return; 212 208 } 213 209 214 if( VarType==DEF_STRUCT){210 if( varType.IsStruct() ){ 215 211 //構造体インスタンスへの代入 216 SetStructVariableFromRax( lpVarIndex,CalcType,lpCalcIndex,&VarRelativeVar,bCalcUseHeap);217 return; 218 } 219 220 if( CalcType==DEF_OBJECT && (CalcType!=VarType || lpCalcIndex!=lpVarIndex) ){212 SetStructVariableFromRax(varType,calcType,&VarRelativeVar,bCalcUseHeap); 213 return; 214 } 215 216 if( calcType.IsObject() && !calcType.Equals( varType ) ){ 221 217 //キャスト演算子のオーバーロードに対応する 222 CallCastOperatorProc(REG_RAX, CalcType,lpCalcIndex,bCalcUseHeap,VarType,lpVarIndex);218 CallCastOperatorProc(REG_RAX,calcType,bCalcUseHeap,varType); 223 219 } 224 220 … … 228 224 ///////////////////////////////// 229 225 230 CheckDifferentType( VarType,lpVarIndex,CalcType,lpCalcIndex,0,0);226 CheckDifferentType(varType,calcType,0,0); 231 227 232 228 … … 234 230 // rax(実数はxmm0)の内容を変数にコピー 235 231 ///////////////////////////////////////////////// 236 SetVariableFromRax( VarType,CalcType,&VarRelativeVar);232 SetVariableFromRax(varType.GetBasicType(),calcType.GetBasicType(),&VarRelativeVar); 237 233 } 238 239 // TODO: 消す240 /*241 void SetRefVariable( const char *varname, const char *expression ){242 ////////////////////////////////////////243 // 変数のタイプ型を識別して、演算を行う244 ////////////////////////////////////////245 246 int VarType,CalcType;247 LONG_PTR lpVarIndex,lpCalcIndex;248 BOOL bCalcUseHeap;249 250 //型を識別251 VarType=GetVarType(varname,&lpVarIndex,0);252 if(VarType==-1){253 SetError(300,NULL,cp);254 return;255 }256 257 extern LONG_PTR ProcPtr_BaseIndex;258 if(VarType==DEF_PTR_PROC) ProcPtr_BaseIndex=lpVarIndex;259 else ProcPtr_BaseIndex=-1;260 261 //NumOpe...(rax、またはxmm0に答えが格納される)262 int reg=REG_RAX;263 CalcType=NumOpe(®,expression,VarType,lpVarIndex,&lpCalcIndex,&bCalcUseHeap);264 265 //結果を格納しているレジスタをブロッキング266 pobj_BlockReg->lock(reg);267 268 if(VarType==-1||CalcType==-1) return;269 270 //変数アドレスを取得271 RELATIVE_VAR VarRelativeVar;272 if(!GetVarOffsetReadWrite(273 varname,274 &VarType,275 &VarRelativeVar,276 &lpVarIndex)) return;277 278 //レジスタのブロッキングを解除279 pobj_BlockReg->clear();280 281 if(VarType&FLAG_PTR){282 SetError(14,varname,cp);283 return;284 }285 286 if( VarType == DEF_OBJECT287 && (VarRelativeVar.dwKind == VAR_REFLOCAL || VarRelativeVar.dwKind == VAR_REFGLOBAL ) ){288 // 参照型オブジェクトへの代入(初期化)はポインタ変数と同様の処理に値する289 PTR_LEVEL_UP( VarType );290 291 if( VarRelativeVar.dwKind == VAR_REFGLOBAL ){292 VarRelativeVar.dwKind = VAR_GLOBAL;293 }294 else if( VarRelativeVar.dwKind == VAR_REFLOCAL ){295 VarRelativeVar.dwKind = VAR_LOCAL;296 }297 298 if( CalcType == DEF_OBJECT ){299 //右辺値が実体オブジェクトのときは、参照をコピー300 PTR_LEVEL_UP( CalcType );301 }302 }303 else{304 SetError(300,NULL,cp);305 }306 307 308 /////////////////////////////////309 // 右辺、左辺の型チェックを行う310 /////////////////////////////////311 312 CheckDifferentType(VarType,lpVarIndex,CalcType,lpCalcIndex,0,0);313 314 315 /////////////////////////////////////////////////316 // rax(実数はxmm0)の内容を変数にコピー317 /////////////////////////////////////////////////318 SetVariableFromRax(VarType,CalcType,&VarRelativeVar);319 }320 */ -
BasicCompiler64/Compile_CallProc.cpp
r73 r75 8 8 void Call_DebugSys_SaveContext(){ 9 9 //call _System_GetEip 10 extern SubInfo*pSub_System_GetEip;10 extern UserProc *pSub_System_GetEip; 11 11 op_call(pSub_System_GetEip); 12 12 … … 18 18 19 19 //call _DebugSys_SaveContext 20 extern SubInfo*pSub_DebugSys_SaveContext;20 extern UserProc *pSub_DebugSys_SaveContext; 21 21 op_call(pSub_DebugSys_SaveContext); 22 22 } … … 32 32 33 33 34 int Opcode_CallProcPtr(char *variable,char *Parameter,PROCPTRINFO *pi,LONG_PTR *plpIndex){ 35 extern HANDLE hHeap; 36 int i; 37 34 bool Opcode_CallProcPtr( const char *variable, const char *lpszParms,ProcPointer *pProcPointer){ 38 35 39 36 extern BOOL bDebugCompile; … … 49 46 //パラメータオブジェクトを生成 50 47 ParamImpl *pobj_parameter=0; 51 pobj_parameter=new ParamImpl( Parameter);48 pobj_parameter=new ParamImpl(lpszParms); 52 49 53 50 //エラーチェック 54 if( !pobj_parameter->ErrorCheck(variable,p i->pParmInfo,pi->ParmNum,pi->ParmNum) ){51 if( !pobj_parameter->ErrorCheck(variable,pProcPointer->Params() ) ){ 55 52 //パラメータにエラーがあるときは処理を終える 56 return pi->ReturnType;53 return false; 57 54 } 58 55 59 56 //スタックフレームに存在する既存のパラメータをバックアップ 60 pobj_parameter->BackupParameter( pi->ParmNum);57 pobj_parameter->BackupParameter( (int)pProcPointer->Params().size() ); 61 58 62 59 //一時オブジェクトを生成 63 pobj_parameter->NewTempParameters( variable,p i->pParmInfo,pi->ParmNum,pi->ParmNum);60 pobj_parameter->NewTempParameters( variable,pProcPointer->Params() ); 64 61 65 62 //レジスタ、スタックフレームにセット 66 pobj_parameter->SetParameter(variable,p i->pParmInfo,pi->ParmNum,pi->ParmNum);63 pobj_parameter->SetParameter(variable,pProcPointer->Params() ); 67 64 68 65 69 66 70 67 RELATIVE_VAR RelativeVar; 71 LONG_PTR lp; 72 GetVarOffsetReadOnly(variable,&i,&RelativeVar,&lp); 68 GetVarOffsetReadOnly(variable,&RelativeVar,Type()); 73 69 SetVarPtrToReg(REG_RAX,&RelativeVar); 74 70 … … 88 84 89 85 //スタックフレームに存在する既存のパラメータを復元 90 pobj_parameter->RestoreParameter( pi->ParmNum);86 pobj_parameter->RestoreParameter( (int)pProcPointer->Params().size() ); 91 87 92 88 //パラメータオブジェクトを破棄 93 89 delete pobj_parameter; 94 90 95 return pi->ReturnType;91 return true; 96 92 } 97 93 98 void Opcode_CallProc(const char *Parameter,SubInfo *psi,DWORD dwFlags,char *ObjectName,int RefType){94 bool Opcode_CallProc(const char *Parameter,UserProc *pUserProc,DWORD dwFlags,const char *ObjectName,int RefType){ 99 95 int i2; 100 96 101 if( psi->dwType==SUBTYPE_MACRO){102 if( lstrcmpi(psi->name,"Print")==0){97 if( pUserProc->IsMacro() ){ 98 if( lstrcmpi( pUserProc->GetName().c_str(), "Print" ) == 0 ){ 103 99 Opcode_Print(Parameter,0); 104 return ;105 } 106 if( lstrcmpi(psi->name,"Input")==0){100 return true; 101 } 102 if( lstrcmpi( pUserProc->GetName().c_str(), "Input" ) == 0 ){ 107 103 Opcode_Input(Parameter); 108 return ;109 } 110 if( lstrcmpi(psi->name,"Write")==0){104 return true; 105 } 106 if( lstrcmpi( pUserProc->GetName().c_str(), "Write" ) == 0 ){ 111 107 Opcode_Print(Parameter,1); 112 return ;113 } 114 } 115 116 p si->bUse=1;108 return true; 109 } 110 } 111 112 pUserProc->Using(); 117 113 118 114 bool isStatic = false; 119 CClass *pobj_c = NULL;115 const CClass *pobj_c = NULL; 120 116 CMethod *pMethod = NULL; 121 if( psi->pobj_ParentClass){117 if( pUserProc->GetParentClassPtr() ){ 122 118 //クラスのメンバ関数を呼び出す場合はアクセスチェックを行う 123 119 if(ObjectName[0]){ … … 128 124 else{ 129 125 //"->"によってオブジェクトを指定する通常のメンバ関数呼び出し 130 int type = GetVarType(ObjectName,(LONG_PTR *)&pobj_c,0); 131 if(!(NATURAL_TYPE(type)==DEF_OBJECT)){ 126 Type varType; 127 GetVarType( ObjectName, varType, false ); 128 pobj_c = &varType.GetClass(); 129 if( NATURAL_TYPE( varType.GetBasicType() ) != DEF_OBJECT ){ 132 130 pobj_c=pobj_DBClass->check(ObjectName); 133 131 if( pobj_c ){ … … 143 141 if(dwFlags&PROCFLAG_NEW){ 144 142 //New演算子によるコンストラクタ呼び出し 145 pobj_c=p si->pobj_ParentClass;143 pobj_c=pUserProc->GetParentClassPtr(); 146 144 } 147 145 else{ … … 156 154 ///////////////////////////////// 157 155 pMethod = NULL; 158 if( ! isStatic ) pMethod = pobj_c->GetMethodInfo( p si);156 if( ! isStatic ) pMethod = pobj_c->GetMethodInfo( pUserProc ); 159 157 if( ! pMethod ){ 160 158 //動的メソッドが取得できなかったときは静的メソッドを当たる 161 pMethod = pobj_c->GetStaticMethodInfo( p si);159 pMethod = pobj_c->GetStaticMethodInfo( pUserProc ); 162 160 if( !pMethod ){ 163 161 SetError(300,NULL,cp); 164 return ;162 return false; 165 163 } 166 164 … … 180 178 //同一クラスオブジェクトの場合はプライベートアクセスを容認する 181 179 if(dwAccess==ACCESS_NON){ 182 SetError(109,p si->name,cp);183 return ;180 SetError(109,pUserProc->GetName(),cp); 181 return false; 184 182 } 185 183 } … … 187 185 if(dwAccess==ACCESS_PRIVATE|| 188 186 dwAccess==ACCESS_NON){ 189 SetError(109,p si->name,cp);190 return ;187 SetError(109,pUserProc->GetName(),cp); 188 return false; 191 189 } 192 190 if(dwAccess==ACCESS_PROTECTED){ 193 SetError(110,p si->name,cp);194 return ;191 SetError(110,pUserProc->GetName(),cp); 192 return false; 195 193 } 196 194 } … … 199 197 //クラス内部からの呼び出し(継承によるACCESS_NONのみをエラーとする) 200 198 if(dwAccess==ACCESS_NON){ 201 SetError(109,p si->name,cp);202 return ;199 SetError(109,pUserProc->GetName(),cp); 200 return false; 203 201 } 204 202 } … … 211 209 212 210 char temporary[VN_SIZE]={0}; 213 if( p si->pobj_ParentClass&& isStatic == false ){211 if( pUserProc->GetParentClassPtr() && isStatic == false ){ 214 212 //_System_LocalThis(第一パラメータ)のダミーを作成 215 213 lstrcpy(temporary,"0,"); … … 234 232 235 233 //エラーチェック 236 if( !pobj_parameter->ErrorCheck(p si->name,psi->realParams,psi->SecondParmNum) ){234 if( !pobj_parameter->ErrorCheck(pUserProc->GetName(),pUserProc->RealParams(),pUserProc->GetSecondParmNum() ) ){ 237 235 //パラメータにエラーがあるときは処理を終える 238 return ;239 } 240 241 if(p si->dwType==SUBTYPE_MACRO){236 return false; 237 } 238 239 if(pUserProc->IsMacro()){ 242 240 //マクロ関数の場合は、パラメータ省略を考慮する 243 pobj_parameter->MacroParameterSupport( psi->realParams);241 pobj_parameter->MacroParameterSupport( pUserProc->RealParams() ); 244 242 } 245 243 246 244 //スタックフレームに存在する既存のパラメータをバックアップ 247 pobj_parameter->BackupParameter( psi->RealParmNum);245 pobj_parameter->BackupParameter( (int)pUserProc->RealParams().size() ); 248 246 249 247 //一時オブジェクトを生成 250 pobj_parameter->NewTempParameters( p si->name,psi->realParams,psi->RealSecondParmNum);248 pobj_parameter->NewTempParameters( pUserProc->GetName(),pUserProc->RealParams(),pUserProc->GetRealSecondParmNum() ); 251 249 252 250 //レジスタ、スタックフレームにセット 253 pobj_parameter->SetParameter(p si->name,psi->realParams,psi->RealSecondParmNum);254 255 if(p si->ReturnType==DEF_STRUCT && psi->isReturnRef == false){251 pobj_parameter->SetParameter(pUserProc->GetName(),pUserProc->RealParams(),pUserProc->GetRealSecondParmNum() ); 252 253 if(pUserProc->ReturnType().IsStruct() ){ 256 254 ////////////////////////////////////////////////////// 257 255 // 戻り値に構造体インスタンスを持つ場合 … … 265 263 ////////////////////////////////////////////////////// 266 264 267 int object_size = p si->u.Return_pobj_c->GetSize();265 int object_size = pUserProc->ReturnType().GetClass().GetSize(); 268 266 269 267 //mov rcx,object_size … … 271 269 272 270 //call calloc 273 extern SubInfo*pSub_calloc;271 extern UserProc *pSub_calloc; 274 272 op_call(pSub_calloc); 275 273 … … 282 280 }//////////////////////////////////////////// 283 281 284 if( p si->pobj_ParentClass&& isStatic == false ){282 if( pUserProc->GetParentClassPtr() && isStatic == false ){ 285 283 //mov rdx,r13 286 284 op_mov_RR(REG_RDX,REG_R13); … … 293 291 294 292 295 if( p si->pobj_ParentClass&& isStatic == false ){293 if( pUserProc->GetParentClassPtr() && isStatic == false ){ 296 294 /////////////////////////////// 297 295 // メンバ関数の場合 … … 305 303 if( pMethod->isConst ){ 306 304 //Constアクセスが可能なメソッドの場合 307 if( !GetVarOffsetReadOnly( ObjectName, &i2, &RelativeVar, 0 ) ) return; 305 if( !GetVarOffsetReadOnly( ObjectName, &RelativeVar, Type() ) ){ 306 return false; 307 } 308 308 } 309 309 else{ 310 310 //Constアクセスが不可能なメソッドの場合 311 if( !GetVarOffsetReadWrite( ObjectName, &i2, &RelativeVar, 0 ) ) return; 311 if( !GetVarOffsetReadWrite( ObjectName, &RelativeVar, Type() ) ){ 312 return false; 313 } 312 314 } 313 315 … … 334 336 } 335 337 336 if( psi->bVirtual){338 if( pUserProc->IsVirtual() ){ 337 339 //仮想関数(オブジェクトメソッド)呼び出し 338 340 //pObj->func_table->func1 … … 343 345 op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,0,MOD_BASE); 344 346 345 i2 = pobj_c->GetFuncNumInVtbl( p si);347 i2 = pobj_c->GetFuncNumInVtbl( pUserProc ); 346 348 347 349 //call qword ptr[r11+func_index] … … 364 366 365 367 //call ProcAddr 366 op_call(p si);368 op_call(pUserProc); 367 369 } 368 370 369 371 /* 64コンパイラでは不要 370 if(p di->bCdecl){372 if(pDllProc->bCdecl){ 371 373 //add esp,ParmSize 372 374 }*/ … … 380 382 381 383 //スタックフレームに存在する既存のパラメータを復元 382 pobj_parameter->RestoreParameter( psi->RealParmNum);384 pobj_parameter->RestoreParameter( (int)pUserProc->RealParams().size() ); 383 385 384 386 //パラメータオブジェクトを破棄 385 387 delete pobj_parameter; 388 389 return true; 386 390 } 387 391 388 int Opcode_CallDllProc(char *Parameter,DECLAREINFO *pdi,LONG_PTR *plpIndex){ 389 char *temporary; 390 391 temporary=(char *)HeapAlloc(hHeap,0,lstrlen(Parameter)+1); 392 bool Opcode_CallDllProc( const char *lpszParms, DllProc *pDllProc ){ 392 393 393 394 extern BOOL bDebugCompile; 394 395 extern BOOL bDebugSupportProc; 395 if(bDebugCompile&&bDebugSupportProc==0&& lstrcmp(pdi->name,"DebugBreak")!=0)396 if(bDebugCompile&&bDebugSupportProc==0&& pDllProc->GetName() != "DebugBreak" ){ 396 397 Call_DebugSys_SaveContext(); 397 398 } 398 399 399 400 … … 404 405 //パラメータオブジェクトを生成 405 406 ParamImpl *pobj_parameter=0; 406 pobj_parameter=new ParamImpl( Parameter);407 pobj_parameter=new ParamImpl(lpszParms); 407 408 408 409 //エラーチェック 409 if( !pobj_parameter->ErrorCheck( pdi->name,pdi->pParmInfo,pdi->ParmNum,pdi->ParmNum) ){410 if( !pobj_parameter->ErrorCheck( pDllProc->GetName(), pDllProc->Params() ) ){ 410 411 //パラメータにエラーがあるときは処理を終える 411 return pdi->ReturnType;412 return false; 412 413 } 413 414 414 415 //スタックフレームに存在する既存のパラメータをバックアップ 415 pobj_parameter->BackupParameter( pdi->ParmNum);416 pobj_parameter->BackupParameter( (int)pDllProc->Params().size() ); 416 417 417 418 //一時オブジェクトを生成 418 pobj_parameter->NewTempParameters( p di->name,pdi->pParmInfo,pdi->ParmNum,pdi->ParmNum);419 pobj_parameter->NewTempParameters( pDllProc->GetName(), pDllProc->Params() ); 419 420 420 421 //レジスタ、スタックフレームにセット 421 pobj_parameter->SetParameter(p di->name,pdi->pParmInfo,pdi->ParmNum,pdi->ParmNum);422 pobj_parameter->SetParameter(pDllProc->GetName(), pDllProc->Params() ); 422 423 423 424 … … 429 430 430 431 //call dword ptr[ImportTable] 431 op_call( p di);432 op_call( pDllProc ); 432 433 433 434 /* 64コンパイラでは不要 434 if(p di->bCdecl){435 if(pDllProc->bCdecl){ 435 436 //add esp,ParmSize 436 437 }*/ … … 440 441 441 442 //スタックフレームに存在する既存のパラメータを復元 442 pobj_parameter->RestoreParameter( pdi->ParmNum);443 pobj_parameter->RestoreParameter( (int)pDllProc->Params().size() ); 443 444 444 445 //パラメータオブジェクトを破棄 445 446 delete pobj_parameter; 446 447 447 if(plpIndex) *plpIndex=pdi->u.ReturnIndex; 448 449 HeapDefaultFree(temporary); 450 451 return pdi->ReturnType; 448 return true; 452 449 } -
BasicCompiler64/Compile_Func.cpp
r73 r75 40 40 } 41 41 void Opcode_Func_Len( const char *Parameter ){ 42 int type,TypeSize;43 LONG_PTR lpIndex;44 42 BOOL bArrayHead; 45 46 type=GetVarType(Parameter,&lpIndex,0);47 43 48 44 const char *tempParm=Parameter; 49 45 char temporary[VN_SIZE]; 50 46 char temp2[32]; 51 if(type==-1){ 47 Type type; 48 if( !GetVarType(Parameter,type,0) ){ 52 49 sprintf(temporary,"_System_DummyStr2=%s",Parameter); 53 50 OpcodeCalc(temporary); … … 57 54 58 55 extern CClass *pobj_StringClass; 59 type=DEF_OBJECT; 60 lpIndex=(LONG_PTR)pobj_StringClass; 61 } 62 63 TYPEINFO TypeInfo={type,lpIndex}; 64 if(IsStringObjectType(TypeInfo)){ 56 type.SetType( DEF_OBJECT, pobj_StringClass ); 57 } 58 59 if( type.IsStringObject() ){ 65 60 //Stringオブジェクトの場合 66 61 sprintf(temporary,"%s.Length",tempParm); 67 62 68 63 int reg=REG_RAX; 69 NumOpe(®,temporary, 0,0,NULL,NULL);64 NumOpe(®,temporary,Type(),Type(),NULL); 70 65 return; 71 66 } … … 74 69 int SubScripts[MAX_ARRAYDIM]; 75 70 RELATIVE_VAR RelativeVar; 76 if(!GetVarOffsetReadOnly(tempParm,& type,&RelativeVar,&lpIndex,SubScripts)) return;77 78 79 if(type &FLAG_PTR){80 type &=~FLAG_PTR;71 if(!GetVarOffsetReadOnly(tempParm,&RelativeVar,type,SubScripts)) return; 72 73 74 if(type.GetBasicType()&FLAG_PTR){ 75 type.SetBasicType( type.GetBasicType() & ( ~FLAG_PTR ) ); 81 76 82 77 bArrayHead=1; … … 84 79 else bArrayHead=0; 85 80 86 TypeSize=GetTypeSize(type,lpIndex);87 88 if(bArrayHead) TypeSize*=JumpSubScripts(SubScripts);81 int typeSize = type.GetSize(); 82 83 if(bArrayHead) typeSize*=JumpSubScripts(SubScripts); 89 84 90 85 //mov rax,TypeSize 91 op_mov_RV(sizeof(_int64),REG_RAX, TypeSize);86 op_mov_RV(sizeof(_int64),REG_RAX,typeSize); 92 87 93 88 return; … … 95 90 void Opcode_Func_AddressOf( const char *name ){ 96 91 extern int cp; 97 SubInfo *psi;92 UserProc *pUserProc; 98 93 99 94 extern LONG_PTR ProcPtr_BaseIndex; … … 101 96 //左辺の型にのっとり、オーバーロードを解決 102 97 103 std::vector< SubInfo*> subs;98 std::vector<UserProc *> subs; 104 99 GetOverloadSubHash( name, subs ); 105 100 if( subs.size() == 0 ){ … … 109 104 110 105 //オーバーロードを解決 111 extern P ROCPTRINFO *pProcPtrInfo;112 p si=OverloadSolution(name,subs,pProcPtrInfo[ProcPtr_BaseIndex].pParmInfo,pProcPtrInfo[ProcPtr_BaseIndex].ParmNum,NULL);113 114 if(!p si){106 extern ProcPointer **ppProcPointer; 107 pUserProc=OverloadSolution(name,subs,ppProcPointer[ProcPtr_BaseIndex]->Params(), Type() ); 108 109 if(!pUserProc){ 115 110 SetError(27,name,cp); 116 111 return; … … 118 113 } 119 114 else{ 120 p si=GetSubHash(name);121 if(!p si){115 pUserProc=GetSubHash(name); 116 if(!pUserProc){ 122 117 SetError(27,name,cp); 123 118 return; … … 125 120 } 126 121 127 128 if(psi->bVirtual){ 122 if( pUserProc->IsVirtual() ){ 129 123 /////////////////////////////// 130 124 // 仮想関数の場合 … … 142 136 else{ 143 137 RELATIVE_VAR RelativeVar; 144 inttype;145 if(!GetVarOffsetReadOnly(ObjectName,& type,&RelativeVar,(LONG_PTR *)&pobj_c)) return;138 Type type; 139 if(!GetVarOffsetReadOnly(ObjectName,&RelativeVar,type)) return; 146 140 SetVarPtrToReg(REG_RCX,&RelativeVar); 147 141 148 142 //参照タイプが整合しているかをチェック 149 if(type !=RefType) SetError(104,ObjectName,cp);150 151 if(type ==DEF_PTR_OBJECT){143 if(type.GetBasicType()!=RefType) SetError(104,ObjectName,cp); 144 145 if(type.IsObjectPtr()){ 152 146 //mov rcx,qword ptr[rcx] 153 147 op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,0,MOD_BASE); … … 172 166 op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,0,MOD_BASE); 173 167 174 int i2 = pobj_c->GetFuncNumInVtbl( p si);168 int i2 = pobj_c->GetFuncNumInVtbl( pUserProc ); 175 169 176 170 //mov rax,qword ptr[r11+func_index] … … 188 182 op_mov_RV(sizeof(_int64),REG_RAX,0); 189 183 obp-=sizeof(long); 190 pobj_SubAddrSchedule->add(p si,0);184 pobj_SubAddrSchedule->add(pUserProc,0); 191 185 obp+=sizeof(long); 192 186 } 193 187 194 p si->bUse=1;188 pUserProc->Using(); 195 189 } 196 190 void Opcode_Func_SizeOf( const char *Parameter ){ … … 210 204 op_mov_RV(sizeof(_int64),REG_RAX,size); 211 205 } 212 void Opcode_Func_VarPtr( const char *Parameter, TYPEINFO &ReturnTypeInfo ){ 206 void Opcode_Func_VarPtr( const char *Parameter, Type &resultType, bool isCallOn ){ 207 if( isCallOn == false ){ 208 // 戻り値の型を取得するだけ 209 210 //変数のアドレスを取得 211 if(!GetVarType( Parameter, resultType, true )) return; 212 213 resultType.PtrLevelUp(); 214 215 return; 216 } 217 213 218 RELATIVE_VAR RelativeVar; 214 219 215 220 //変数のアドレスを取得 216 if(!GetVarOffsetReadOnly( Parameter, &Re turnTypeInfo.type, &RelativeVar, &ReturnTypeInfo.u.lpIndex)) return;217 218 int beforeType = ReturnTypeInfo.type;219 220 PTR_LEVEL_UP( ReturnTypeInfo.type);221 if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return; 222 223 int beforeType = resultType.GetBasicType(); 224 225 resultType.PtrLevelUp(); 221 226 222 227 SetVarPtrToReg(REG_RAX,&RelativeVar); … … 230 235 } 231 236 void Opcode_Func_GetPtrData( const char *Parameter, const int type ){ 232 int i2;233 234 237 int reg=REG_RAX; 235 i2=NumOpe(®,Parameter,0,0,0); 236 if(!IsWholeNumberType(i2)){ 237 extern int cp; 238 Type tempType; 239 if( !NumOpe(®,Parameter,Type(),tempType) ){ 240 return; 241 } 242 if(!tempType.IsWhole()){ 238 243 SetError(11,Parameter,cp); 239 244 return; … … 254 259 } 255 260 256 void Opcode_CallFunc( const char *Parameter, const int FuncNum, TYPEINFO &ReturnTypeInfo){261 bool Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &resultType, bool isCallOn ){ 257 262 switch(FuncNum){ 258 263 case FUNC_LEN: 259 Opcode_Func_Len(Parameter);260 ReturnTypeInfo.type = DEF_LONG;264 if( isCallOn ) Opcode_Func_Len(Parameter); 265 resultType.SetBasicType( DEF_LONG ); 261 266 break; 262 267 case FUNC_ADDRESSOF: 263 Opcode_Func_AddressOf(Parameter);264 ReturnTypeInfo.type = DEF_PTR_VOID;268 if( isCallOn ) Opcode_Func_AddressOf(Parameter); 269 resultType.SetBasicType( DEF_PTR_VOID ); 265 270 break; 266 271 case FUNC_SIZEOF: 267 Opcode_Func_SizeOf(Parameter);268 ReturnTypeInfo.type = DEF_LONG;272 if( isCallOn ) Opcode_Func_SizeOf(Parameter); 273 resultType.SetBasicType( DEF_LONG ); 269 274 break; 270 275 case FUNC_VARPTR: 271 Opcode_Func_VarPtr( Parameter, ReturnTypeInfo);276 Opcode_Func_VarPtr( Parameter, resultType, isCallOn ); 272 277 break; 273 278 274 279 case FUNC_GETDOUBLE: 275 Opcode_Func_GetPtrData(Parameter,DEF_DOUBLE);276 ReturnTypeInfo.type = DEF_DOUBLE;280 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DOUBLE); 281 resultType.SetBasicType( DEF_DOUBLE ); 277 282 break; 278 283 case FUNC_GETSINGLE: 279 Opcode_Func_GetPtrData(Parameter,DEF_SINGLE);280 ReturnTypeInfo.type = DEF_SINGLE;284 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_SINGLE); 285 resultType.SetBasicType( DEF_SINGLE ); 281 286 break; 282 287 case FUNC_GETQWORD: 283 Opcode_Func_GetPtrData(Parameter,DEF_QWORD);284 ReturnTypeInfo.type = DEF_QWORD;288 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_QWORD); 289 resultType.SetBasicType( DEF_QWORD ); 285 290 break; 286 291 case FUNC_GETDWORD: 287 Opcode_Func_GetPtrData(Parameter,DEF_DWORD);288 ReturnTypeInfo.type = DEF_DWORD;292 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DWORD); 293 resultType.SetBasicType( DEF_DWORD ); 289 294 break; 290 295 case FUNC_GETWORD: 291 Opcode_Func_GetPtrData(Parameter,DEF_WORD);292 ReturnTypeInfo.type = DEF_WORD;296 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_WORD); 297 resultType.SetBasicType( DEF_WORD ); 293 298 break; 294 299 case FUNC_GETBYTE: 295 Opcode_Func_GetPtrData(Parameter,DEF_BYTE); 296 ReturnTypeInfo.type = DEF_BYTE; 297 break; 298 } 299 } 300 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_BYTE); 301 resultType.SetBasicType( DEF_BYTE ); 302 break; 303 default: 304 return false; 305 } 306 return true; 307 } -
BasicCompiler64/Compile_Object.cpp
r73 r75 2 2 #include "opcode.h" 3 3 4 void _call_constructor( CClass *pobj_c,const char *CreateParameter,int ObjectSize,BOOL bSomeObjects){4 void _call_constructor( const CClass *pobj_c,const char *CreateParameter,int ObjectSize,BOOL bSomeObjects){ 5 5 //////////////////////////// 6 6 // コンストラクタの呼び出し … … 32 32 //////////////////////// 33 33 34 std::vector< SubInfo*> subs;34 std::vector<UserProc *> subs; 35 35 pobj_c->EnumMethod( pobj_c->name, subs ); 36 36 37 SubInfo *psi;37 UserProc *pUserProc; 38 38 if( subs.size() > 0 ){ 39 39 //オーバーロードを解決 40 p si=OverloadSolutionWithStrParam(pobj_c->name,41 subs,CreateParameter,"" ,NULL);42 43 if(!p si) return;40 pUserProc=OverloadSolutionWithStrParam(pobj_c->name, 41 subs,CreateParameter,""); 42 43 if(!pUserProc) return; 44 44 } 45 45 46 46 //コンストラクタを呼び出す 47 47 Opcode_CallProc(CreateParameter, 48 p si,48 pUserProc, 49 49 PROCFLAG_NEW,"",0); 50 50 … … 73 73 } 74 74 } 75 void Operator_New( CClass &classObj, const char *objectSizeStr, const char *parameter, const TYPEINFO &baseTypeInfo){75 void Operator_New( const CClass &classObj, const char *objectSizeStr, const char *parameter, const Type &baseType ){ 76 76 int typeSize = classObj.GetSize(); 77 77 … … 86 86 87 87 int reg=REG_RAX; 88 int type = NumOpe(®,objectSizeStr,0,0,0); 89 if(!IsWholeNumberType(type)) SetError(49,NULL,cp); 88 Type tempType; 89 NumOpe(®,objectSizeStr,Type(),tempType); 90 if( !tempType.IsWhole() ) SetError(49,NULL,cp); 90 91 91 92 //※添え字上限値であることを考慮 … … 117 118 } 118 119 119 if( baseTypeInfo.type == DEF_OBJECT ){ 120 //DeleteはGCで処理 120 if( baseType.IsObject() ){ 121 // オブジェクト インスタンス 122 // ※DeleteはGCで処理 121 123 122 124 //call _System_GC_malloc_ForObject 123 extern SubInfo*pSub_System_GC_malloc_ForObject;125 extern UserProc *pSub_System_GC_malloc_ForObject; 124 126 op_call(pSub_System_GC_malloc_ForObject); 125 127 } 126 128 else{ 127 //明示的なDeleteが必要 129 // オブジェクトポインタ 130 // ※明示的なDeleteが必要 128 131 129 132 //call _System_GC_malloc_ForObjectPtr 130 extern SubInfo*pSub_System_GC_malloc_ForObjectPtr;133 extern UserProc *pSub_System_GC_malloc_ForObjectPtr; 131 134 op_call(pSub_System_GC_malloc_ForObjectPtr); 132 135 } … … 162 165 op_mov_RV(sizeof(_int64),REG_RCX,0); 163 166 obp-=sizeof(long); 164 pobj_SubAddrSchedule->add(method->p si,0);165 method->p si->bUse=1;167 pobj_SubAddrSchedule->add(method->pUserProc,0); 168 method->pUserProc->Using(); 166 169 obp+=sizeof(long); 167 170 … … 190 193 pobj_sf->pop(REG_RAX); 191 194 } 192 int Operator_New(const char *Parameter,LONG_PTR *plpIndex,const TYPEINFO &baseTypeInfo ){193 char TypeName[VN_SIZE],CreateParameter[VN_SIZE],objectSizeStr[VN_SIZE];194 int i,i2;195 196 i=0;197 198 if(Parameter[0]=='['){199 i=GetStringInBracket(objectSizeStr,Parameter);200 201 SlideString(objectSizeStr+1,-1);202 objectSizeStr[i-2]=0;203 }204 else objectSizeStr[0]=0;205 206 for(i2=0;;i++,i2++){207 if(Parameter[i]=='('){208 TypeName[i2]=0;209 210 //コンストラクタに渡すパラメータを取得211 i2=GetStringInPare(CreateParameter,Parameter+i);212 RemoveStringPare(CreateParameter);213 i+=i2;214 if(Parameter[i]!='\0'){215 SetError(42,NULL,cp);216 return 0;217 }218 break;219 }220 TypeName[i2]=Parameter[i];221 if(Parameter[i]=='\0'){222 CreateParameter[0]=0;223 break;224 }225 }226 227 int type;228 type=GetTypeFixed(TypeName,plpIndex);229 if(type==-1){230 SetError(3,TypeName,cp);231 return 0;232 }233 234 if(type!=DEF_OBJECT){235 ////////////////////////236 // 通常のデータ型の場合237 ////////////////////////238 239 SetError(121,NULL,cp);240 return 0;241 }242 243 CClass *pobj_c;244 pobj_c=(CClass *)*plpIndex;245 246 Operator_New( *pobj_c, objectSizeStr, CreateParameter, baseTypeInfo );247 248 if( baseTypeInfo.type == DEF_OBJECT ){249 return DEF_OBJECT;250 }251 return DEF_PTR_OBJECT;252 }253 254 195 void OpcodeDelete(const char *Parameter, bool isSweeping){ 255 int type;256 257 196 int reg=REG_RAX; 258 type=NumOpe(®,Parameter,0,0,0); 259 if(type==-1) return; 260 if(!(type==DEF_PTR_OBJECT||type==DEF_PTR_VOID)) SetError(122,NULL,cp); 197 Type tempType; 198 if( !NumOpe(®,Parameter,Type(),tempType) ){ 199 return; 200 } 201 if(!( tempType.IsObjectPtr() || tempType.IsVoidPtr() )) SetError(122,NULL,cp); 261 202 262 203 //sub rax,PTR_SIZE*3 … … 328 269 if( isSweeping ){ 329 270 //call _System_GC_free_for_SweepingDelete 330 extern SubInfo*pSub_System_GC_free_for_SweepingDelete;271 extern UserProc *pSub_System_GC_free_for_SweepingDelete; 331 272 op_call(pSub_System_GC_free_for_SweepingDelete); 332 273 } 333 274 else{ 334 275 //call free 335 extern SubInfo*pSub_free;276 extern UserProc *pSub_free; 336 277 op_call(pSub_free); 337 278 } -
BasicCompiler64/Compile_ProcOp.cpp
r73 r75 2 2 #include "Opcode.h" 3 3 4 void SystemProc( char *name){4 void SystemProc( const char *name ){ 5 5 if(lstrcmp(name,"_System_GetEip")==0){ 6 6 //mov rax,qword ptr[rsp] … … 22 22 } 23 23 24 extern BOOL bCompilingGlobal; 25 BOOL bBackCompilingGlobal; 26 bBackCompilingGlobal=bCompilingGlobal; 27 bCompilingGlobal=1; 24 UserProc *pBackUserProc; 25 pBackUserProc = &UserProc::CompilingUserProc(); 26 UserProc::CompileStartForGlobalArea(); 28 27 29 28 int BackCp; … … 56 55 *((long *)(OpBuffer+StackFrameSchedule))=pobj_sf->GetFrameSize(); 57 56 58 bCompilingGlobal=bBackCompilingGlobal;57 UserProc::CompileStartForUserProc( pBackUserProc ); 59 58 cp=BackCp; 60 59 … … 70 69 StackFrameSchedule=obp-sizeof(long); 71 70 72 extern int MaxGlobalVarNum; 73 extern VARIABLE *GlobalVar; 74 int i; 75 for(i=0;i<MaxGlobalVarNum;i++){ 76 if(memicmp(GlobalVar[i].name,"Static%",7)==0){ 71 foreach( Variable *pVar, globalVars ){ 72 if(memicmp(pVar->GetName().c_str(),"Static%",7)==0){ 77 73 //コンストラクタ呼び出し 78 if( GlobalVar[i].type==DEF_OBJECT){74 if( pVar->IsObject() ){ 79 75 80 76 //エラー用 81 cp=GlobalVar[i].source_code_address; 82 83 TYPEINFO TypeInfo; 84 TypeInfo.type=GlobalVar[i].type; 85 TypeInfo.u.lpIndex=GlobalVar[i].u.index; 77 cp=pVar->source_code_address; 78 86 79 CallConstructor( 87 GlobalVar[i].name,88 GlobalVar[i].SubScripts,89 TypeInfo,90 GlobalVar[i].ConstractParameter);80 pVar->GetName().c_str(), 81 pVar->GetSubScriptsPtr(), 82 *pVar, 83 pVar->paramStrForConstructor.c_str()); 91 84 } 92 85 } … … 107 100 108 101 109 extern BOOL bCompilingGlobal; 110 BOOL bBackCompilingGlobal; 111 bBackCompilingGlobal=bCompilingGlobal; 112 bCompilingGlobal=1; 102 UserProc *pBackUserProc; 103 pBackUserProc = &UserProc::CompilingUserProc(); 104 UserProc::CompileStartForGlobalArea(); 113 105 114 106 obj_LexScopes.CallDestructorsOfScopeEnd(); 115 107 116 bCompilingGlobal=bBackCompilingGlobal;108 UserProc::CompileStartForUserProc( pBackUserProc ); 117 109 118 110 … … 204 196 } 205 197 } 206 void CompileBufferInProcedure( SubInfo *psi){198 void CompileBufferInProcedure(UserProc *pUserProc){ 207 199 extern char *basbuf; 208 200 extern HANDLE hHeap; 209 extern SubInfo**ppSubHash;201 extern UserProc **ppSubHash; 210 202 extern BOOL bDebugCompile; 211 int i3,i4, VarSize,BufferSize;203 int i3,i4,BufferSize; 212 204 char temporary[VN_SIZE]; 213 205 214 206 BufferSize=128; 215 207 216 if(psi->bUse==0||psi->bCompile) return; 217 218 219 psi->bCompile=1; 208 if( pUserProc->IsUsing() == false || pUserProc->IsCompiled() ) return; 209 210 pUserProc->CompleteCompile(); 220 211 221 212 extern BOOL bSystemProc; 222 if(memcmp(p si->name,"_System_",8)==0) bSystemProc=1;213 if(memcmp(pUserProc->GetName().c_str(),"_System_",8)==0) bSystemProc=1; 223 214 else bSystemProc=0; 224 215 225 216 extern BOOL bDebugSupportProc; 226 if(memcmp(p si->name,"_DebugSys_",10)==0){217 if(memcmp(pUserProc->GetName().c_str(),"_DebugSys_",10)==0){ 227 218 if(!bDebugCompile){ 228 psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1); 229 psi->VarNum=0; 219 pUserProc->localVars.clear(); 230 220 return; 231 221 } … … 234 224 else bDebugSupportProc=0; 235 225 236 p si->CompileAddress=obp;237 238 if(p si->bSystem){226 pUserProc->beginOpAddress=obp; 227 228 if(pUserProc->IsSystem()){ 239 229 //////////////////// 240 230 // 特殊関数 … … 250 240 pobj_sf=new CStackFrame(); 251 241 252 SystemProc(p si->name);242 SystemProc(pUserProc->GetName().c_str()); 253 243 254 244 //スタックフレーム管理用オブジェクトを破棄 … … 256 246 pobj_sf=0; 257 247 258 psi->EndOpAddr=obp; 259 psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1); 260 psi->VarNum=0; 248 pUserProc->endOpAddress=obp; 249 pUserProc->localVars.clear(); 261 250 return; 262 251 } 263 252 264 cp=p si->address;253 cp=pUserProc->GetCodePos(); 265 254 for(;;cp++){ 266 255 if(IsCommandDelimitation(basbuf[cp])) break; … … 303 292 304 293 //ローカル変数に関する情報 305 extern VARIABLE *LocalVar;306 extern int MaxLocalVarNum;307 294 extern int AllLocalVarSize; 308 LocalVar=(VARIABLE *)HeapAlloc(hHeap,0,sizeof(VARIABLE));309 MaxLocalVarNum=0;310 295 AllLocalVarSize=0; 296 pUserProc->localVars.clear(); 311 297 312 298 //ローカル変数アドレススケジュール … … 324 310 ///////////////////////////////////// 325 311 326 for(i3=psi->RealParmNum-1;i3>=0;i3--){ 327 //変数データを追加 328 LocalVar=(VARIABLE *)HeapReAlloc(hHeap,0,LocalVar,(MaxLocalVarNum+1)*sizeof(VARIABLE)); 329 330 lstrcpy(LocalVar[MaxLocalVarNum].name,psi->realParams[i3].GetVarName.c_str()); 331 332 // TODO: パラメータのConst定義の指定が未完成 333 LocalVar[MaxLocalVarNum].bConst=false; 334 335 LocalVar[MaxLocalVarNum].bArray=psi->realParams[i3].IsArray()?TRUE:FALSE; 336 memcpy(LocalVar[MaxLocalVarNum].SubScripts,psi->realParams[i3].GetSubScriptsPtr(),MAX_ARRAYDIM*sizeof(int)); 337 338 LocalVar[MaxLocalVarNum].type=psi->realParams[i3].GetBasicType(); 339 if(LocalVar[MaxLocalVarNum].type==DEF_OBJECT 340 ||LocalVar[MaxLocalVarNum].type==DEF_STRUCT){ 341 if(psi->bExport) 342 SetError(24,NULL,cp); 343 } 344 345 LocalVar[MaxLocalVarNum].u.index=psi->realParams[i3].GetIndex(); 346 347 if(psi->realParams[i3].IsRef() == false&&psi->realParams[i3].IsStruct()){ 312 //パラメータ用の変数データを考慮 313 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){ 314 Parameter ¶m = *pUserProc->RealParams()[i3]; 315 316 Variable *pVar = new Variable( param.GetVarName(), param, false, param.IsRef() ); 317 318 if( param.IsArray() ){ 319 pVar->SetArray( param.GetSubScriptsPtr() ); 320 } 321 322 int varSize; 323 if( param.IsRef() == false && param.IsStruct() ){ 348 324 //構造体のByValパラメータ 349 LocalVar[MaxLocalVarNum].fRef=REF_PARAMETER | OBJECT_PARAMETER;350 VarSize=PTR_SIZE;325 pVar->ThisIsParameter(); 326 varSize=PTR_SIZE; 351 327 } 352 328 else{ 353 if(psi->realParams[i3].IsRef() == false&&psi->realParams[i3].IsArray()){ 354 LocalVar[MaxLocalVarNum].fRef=0; 355 VarSize=GetTypeSize(LocalVar[MaxLocalVarNum].type,LocalVar[MaxLocalVarNum].u.index); 356 if(VarSize%PTR_SIZE) VarSize+=PTR_SIZE-(VarSize%PTR_SIZE); 329 if( param.IsArray() == false ){ 330 varSize = pVar->GetMemorySize(); 357 331 } 358 332 else{ 359 LocalVar[MaxLocalVarNum].fRef=REF_PARAMETER; 360 VarSize=PTR_SIZE; 361 } 362 } 363 AllLocalVarSize+=VarSize; 364 LocalVar[MaxLocalVarNum].offset=AllLocalVarSize; 333 varSize=PTR_SIZE; 334 } 335 } 336 AllLocalVarSize+=varSize; 337 pVar->offset=AllLocalVarSize; 365 338 366 339 //レキシカルスコープ情報 367 LocalVar[MaxLocalVarNum].ScopeLevel=obj_LexScopes.GetNowLevel();368 LocalVar[MaxLocalVarNum].ScopeStartAddress=obj_LexScopes.GetStartAddress();369 LocalVar[MaxLocalVarNum].bLiving=TRUE;370 371 MaxLocalVarNum++;340 pVar->ScopeLevel=obj_LexScopes.GetNowLevel(); 341 pVar->ScopeStartAddress=obj_LexScopes.GetStartAddress(); 342 pVar->bLiving=TRUE; 343 344 pUserProc->localVars.push_back( pVar ); 372 345 } 373 346 … … 377 350 378 351 //コンパイル中の関数が属するクラス 379 pobj_CompilingClass=p si->pobj_ParentClass;380 352 pobj_CompilingClass=pUserProc->GetParentClassPtr(); 353 381 354 //コンパイルスタートをクラス管理クラスに追加 382 pobj_DBClass->StartCompile( p si);355 pobj_DBClass->StartCompile( pUserProc ); 383 356 384 357 //コンパイル中の関数 385 extern SubInfo *pCompilingSubInfo; 386 pCompilingSubInfo=psi; 358 UserProc::CompileStartForUserProc( pUserProc ); 387 359 388 360 //スタックフレーム管理用クラスを初期化 … … 394 366 // ここからコード生成 395 367 396 for(i3=psi->RealParmNum-1;i3>=0;i3--){ 368 for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){ 369 Parameter ¶m = *pUserProc->RealParams()[i3]; 397 370 if(i3==3){ 398 if(p si->realParams[i3].IsReal()&&psi->realParams[i3].IsRef() == false){371 if(param.IsReal()&¶m.IsRef() == false){ 399 372 //movsd qword ptr[rsp+0x20],xmm3 400 373 op_movsd_MR(REG_XMM3,REG_RSP,0x20,MOD_BASE_DISP32); … … 406 379 } 407 380 if(i3==2){ 408 if(p si->realParams[i3].IsReal()&&psi->realParams[i3].IsRef() == false){381 if(param.IsReal()&¶m.IsRef() == false){ 409 382 //movsd qword ptr[rsp+0x18],xmm2 410 383 op_movsd_MR(REG_XMM2,REG_RSP,0x18,MOD_BASE_DISP32); … … 416 389 } 417 390 if(i3==1){ 418 if(p si->realParams[i3].IsReal()&&psi->realParams[i3].IsRef() == false){391 if(param.IsReal()&¶m.IsRef() == false){ 419 392 //movsd qword ptr[rsp+0x10],xmm1 420 393 op_movsd_MR(REG_XMM1,REG_RSP,0x10,MOD_BASE_DISP32); … … 426 399 } 427 400 if(i3==0){ 428 if(p si->realParams[i3].IsReal()&&psi->realParams[i3].IsRef() == false){401 if(param.IsReal()&¶m.IsRef() == false){ 429 402 //movsd qword ptr[rsp+0x8],xmm0 430 403 op_movsd_MR(REG_XMM0,REG_RSP,0x8,MOD_BASE_DISP32); … … 458 431 BaseLocalVar=AllLocalVarSize; 459 432 460 if( psi->ReturnType!=DEF_NON){433 if( !pUserProc->ReturnType().IsNull() ){ 461 434 //戻り値が存在するとき 462 435 463 char *temp; 464 if(psi->name[0]==1&&psi->name[1]==ESC_OPERATOR) temp="_System_ReturnValue"; 465 else temp=psi->name; 466 467 if(psi->ReturnType==DEF_STRUCT && psi->isReturnRef == false){ 436 const char *temp = pUserProc->GetName().c_str(); 437 if( temp[0]==1&&temp[1]==ESC_OPERATOR ){ 438 temp = "_System_ReturnValue"; 439 } 440 441 if( pUserProc->ReturnType().IsStruct() ){ 468 442 //戻り値用の構造体(値型)はパラメータで引き渡される 469 443 } 470 444 else{ 471 445 //戻り値用の変数の定義 472 if( psi->isReturnRef ){ 473 sprintf(temporary,"%c%c",1,ESC_BYREF); 474 } 475 else temporary[0]=0; 476 477 sprintf(temporary+lstrlen(temporary),"%s%c%c",temp,1,ESC_AS); 478 GetTypeName(psi->ReturnType,psi->u.ReturnIndex,temporary+lstrlen(temporary)); 446 sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, pUserProc->ReturnType().ToString().c_str() ); 479 447 480 448 OpcodeDim(temporary,0); … … 497 465 498 466 //call _DebugSys_StartProc 499 extern SubInfo*pSub_DebugSys_StartProc;467 extern UserProc *pSub_DebugSys_StartProc; 500 468 op_call(pSub_DebugSys_StartProc); 501 469 } 502 470 503 471 if(pobj_CompilingClass){ 504 if( lstrcmp(psi->name,pobj_CompilingClass->name)==0){472 if( pUserProc->GetName() == pobj_CompilingClass->name ){ 505 473 //////////////////////////////////// 506 474 // コンストラクタをコンパイルするとき … … 550 518 551 519 Opcode_CallProc(temporary, 552 pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->p si,520 pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc, 553 521 0, 554 522 "", … … 558 526 //基底クラスのコンストラクタを暗黙的に呼び出す 559 527 Opcode_CallProc("", 560 pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->p si,528 pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc, 561 529 0, 562 530 "", … … 568 536 for(i3=0;i3<pobj_CompilingClass->iMemberNum;i3++){ 569 537 CMember *pMember = pobj_CompilingClass->ppobj_Member[i3]; 570 if(pMember-> TypeInfo.type==DEF_OBJECT){538 if(pMember->IsObject()){ 571 539 // オブジェクトメンバを発見したとき 572 540 … … 574 542 pMember->name, 575 543 1, ESC_NEW, 576 pMember-> TypeInfo.u.pobj_Class->name );544 pMember->GetClass().name ); 577 545 OpcodeCalc( temporary ); 578 546 } … … 598 566 } 599 567 } 600 else if( psi->name[0]=='~'){568 else if( pUserProc->IsDestructor() ){ 601 569 //デストラクタをコンパイルしたとき 602 570 … … 609 577 ////////////////////////////////////////// 610 578 ////// プロシージャ内をコンパイル //////// 611 if(psi->dwType==SUBTYPE_SUB) CompileBuffer(ESC_ENDSUB,0); 612 else if(psi->dwType==SUBTYPE_FUNCTION) CompileBuffer(ESC_ENDFUNCTION,0); 613 else if(psi->dwType==SUBTYPE_MACRO) CompileBuffer(ESC_ENDMACRO,0); 579 if(pUserProc->IsMacro()) CompileBuffer(ESC_ENDMACRO,0); 580 else{ 581 if(pUserProc->IsSub()) CompileBuffer(ESC_ENDSUB,0); 582 else if(pUserProc->IsFunction()) CompileBuffer(ESC_ENDFUNCTION,0); 583 } 614 584 ////////////////////////////////////////// 615 585 ////////////////////////////////////////// … … 623 593 pobj_CompilingClass->NotifyFinishConstructorCompile(); 624 594 } 625 else if( psi->name[0]=='~'){595 else if( pUserProc->IsDestructor() ){ 626 596 //////////////////////////////////// 627 597 //デストラクタをコンパイルしたとき … … 638 608 if( method ){ 639 609 Opcode_CallProc("", 640 method->p si,610 method->pUserProc, 641 611 0, 642 612 "", … … 659 629 int offset = pobj_CompilingClass->GetMemberOffset( pMember->name, NULL ); 660 630 661 if(pMember-> TypeInfo.type==DEF_OBJECT){662 CMethod *method = pMember-> TypeInfo.u.pobj_Class->GetDestructorMethod();631 if(pMember->IsObject()){ 632 CMethod *method = pMember->GetClass().GetDestructorMethod(); 663 633 if( method ){ 664 634 for(i4=MemberObjectNum-1;i4>=0;i4--){ … … 670 640 671 641 //call destructor 672 op_call(method->p si);642 op_call(method->pUserProc); 673 643 } 674 644 } … … 705 675 HeapDefaultFree(WithInfo.pWithCp); 706 676 707 //重複エラー情報管理のメモリを解放708 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);709 HeapDefaultFree(SynonymErrorWords);710 711 677 //ローカルオブジェクト(レキシカルスコープレベル=0)の解放処理 712 678 obj_LexScopes.CallDestructorsOfScopeEnd(); … … 720 686 if(bDebugCompile&&bDebugSupportProc==0){ 721 687 //call _DebugSys_EndProc 722 extern SubInfo*pSub_DebugSys_EndProc;688 extern UserProc *pSub_DebugSys_EndProc; 723 689 op_call(pSub_DebugSys_EndProc); 724 690 } 725 691 726 if( psi->ReturnType!=DEF_NON){692 if( !pUserProc->ReturnType().IsNull() ){ 727 693 ////////////////////////////////// 728 694 // 戻り値をraxまたはxmm0に設定 … … 730 696 731 697 RELATIVE_VAR RelativeVar; 732 LONG_PTR lpIndex; 733 734 char *temp; 735 if(psi->name[0]==1&&psi->name[1]==ESC_OPERATOR) 698 699 const char *temp = pUserProc->GetName().c_str(); 700 if( temp[0]==1 && temp[1]==ESC_OPERATOR ){ 736 701 temp="_System_ReturnValue"; 737 else temp=psi->name;738 GetVarOffsetReadWrite(temp,& i3,&RelativeVar,&lpIndex);739 740 i3=p si->ReturnType;702 } 703 GetVarOffsetReadWrite(temp,&RelativeVar,Type()); 704 705 i3=pUserProc->ReturnType().GetBasicType(); 741 706 742 707 if(i3==DEF_OBJECT || i3==DEF_STRUCT){ … … 772 737 } 773 738 HeapDefaultFree(pLocalVarAddrSchedule); 774 for (i3=0;i3<MaxLocalVarNum;i3++){739 foreach( Variable *pVar, pUserProc->localVars ){ 775 740 //後にデバッグで利用する 776 LocalVar[i3].offset=AllLocalVarSize+pobj_sf->GetFrameSize()-LocalVar[i3].offset;741 pVar->offset = AllLocalVarSize + pobj_sf->GetFrameSize() - pVar->offset; 777 742 } 778 743 … … 812 777 813 778 814 psi->EndOpAddr=obp; 815 psi->pVar=LocalVar; 816 psi->VarNum=MaxLocalVarNum; 817 818 //ローカル変数のネーム情報は後に解放する 779 pUserProc->endOpAddress=obp; 780 781 782 //重複エラー情報管理のメモリを解放 783 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]); 784 HeapDefaultFree(SynonymErrorWords); 819 785 } 820 786 void CompileLocal(){ 821 extern SubInfo**ppSubHash;787 extern UserProc **ppSubHash; 822 788 int i2; 823 SubInfo *psi;789 UserProc *pUserProc; 824 790 825 791 extern BOOL bDll; 826 792 if(bDll){ 827 793 //DLLの場合はグローバル変数を初期化するための関数を一番初めにコンパイルする 828 p si=GetSubHash("_System_InitDllGlobalVariables");829 if(p si){830 CompileBufferInProcedure(p si);794 pUserProc=GetSubHash("_System_InitDllGlobalVariables"); 795 if(pUserProc){ 796 CompileBufferInProcedure(pUserProc); 831 797 } 832 798 else SetError(300,NULL,cp); … … 835 801 //_System_InitStaticLocalVariablesは一番最後にコンパイル 836 802 //※一般関数内の静的変数オブジェクトをすべて収集しなければならない 837 extern SubInfo*pSub_System_InitStaticLocalVariables;838 pSub_System_InitStaticLocalVariables-> bCompile=1;803 extern UserProc *pSub_System_InitStaticLocalVariables; 804 pSub_System_InitStaticLocalVariables->CompleteCompile(); 839 805 840 806 //_System_Call_Destructor_of_GlobalObjectは一番最後にコンパイル 841 extern SubInfo*pSub_System_Call_Destructor_of_GlobalObject;842 pSub_System_Call_Destructor_of_GlobalObject-> bCompile=1;807 extern UserProc *pSub_System_Call_Destructor_of_GlobalObject; 808 pSub_System_Call_Destructor_of_GlobalObject->CompleteCompile(); 843 809 844 810 Repeat: 845 811 for(i2=0;i2<MAX_HASH;i2++){ 846 p si=ppSubHash[i2];847 while(p si){848 CompileBufferInProcedure(p si);849 p si=psi->pNextData;812 pUserProc=ppSubHash[i2]; 813 while(pUserProc){ 814 CompileBufferInProcedure(pUserProc); 815 pUserProc=pUserProc->pNextData; 850 816 } 851 817 } … … 853 819 //プロシージャコンパイルによって、プロシージャコンパイルが必要になる場合 854 820 for(i2=0;i2<MAX_HASH;i2++){ 855 p si=ppSubHash[i2];856 while(p si){857 if( psi->bUse&&psi->bCompile==0&&psi->bVirtual==0){821 pUserProc=ppSubHash[i2]; 822 while(pUserProc){ 823 if( pUserProc->IsUsing() && pUserProc->IsCompiled() == false ){ 858 824 goto Repeat; 859 825 } 860 826 861 p si=psi->pNextData;827 pUserProc=pUserProc->pNextData; 862 828 } 863 829 } 864 830 865 831 //_System_InitStaticLocalVariablesは一番最後にコンパイル 866 pSub_System_InitStaticLocalVariables-> bCompile=0;832 pSub_System_InitStaticLocalVariables->KillCompileStatus(); 867 833 CompileBufferInProcedure(pSub_System_InitStaticLocalVariables); 868 834 869 835 //_System_Call_Destructor_of_GlobalObjectは一番最後にコンパイル 870 pSub_System_Call_Destructor_of_GlobalObject-> bCompile=0;836 pSub_System_Call_Destructor_of_GlobalObject->KillCompileStatus(); 871 837 CompileBufferInProcedure(pSub_System_Call_Destructor_of_GlobalObject); 872 838 } -
BasicCompiler64/Compile_Set_Var.cpp
r73 r75 7 7 } 8 8 9 void SetStructVariableFromRax( LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,RELATIVE_VAR *pRelativeVar,BOOL bUseHeap){9 void SetStructVariableFromRax( const Type &varType, const Type &calcType, RELATIVE_VAR *pRelativeVar,BOOL bUseHeap){ 10 10 int RightTermReg; 11 11 pobj_reg=new CRegister(REG_RCX); … … 17 17 18 18 //右辺 19 if( IsRealNumberType(CalcType)){19 if( calcType.IsReal() ){ 20 20 RightTermReg=pobj_reg->LockXmmReg(); 21 21 22 if( CalcType==DEF_DOUBLE){22 if( calcType.IsDouble() ){ 23 23 //movlsd RightTermReg,xmm0 24 24 op_movsd_RR(RightTermReg,REG_XMM0); 25 25 } 26 else if( CalcType==DEF_SINGLE){26 else if( calcType.IsSingle() ){ 27 27 //movlss RightTermReg,xmm0 28 28 op_movss_RR(RightTermReg,REG_XMM0); … … 62 62 */ 63 63 //右辺用レジスタを解除 64 if( IsRealNumberType(CalcType)) pobj_reg->UnlockXmmReg();64 if( calcType.IsReal() ) pobj_reg->UnlockXmmReg(); 65 65 else pobj_reg->UnlockReg(); 66 66 … … 73 73 74 74 75 if( CalcType == DEF_STRUCT ){ 76 CClass *pVarClass = (CClass *)lpVarIndex; 77 CClass *pCalcClass = (CClass *)lpCalcIndex; 78 79 if( pVarClass->IsEquals( pCalcClass ) ){ //等しい 75 if( calcType.IsStruct() ){ 76 if( varType.GetClass().IsEquals( &calcType.GetClass() ) ){ //等しい 80 77 81 78 //双方のオブジェクト型が一致、または派生・継承関係にあるとき … … 88 85 op_mov_RR(REG_RDI,VarReg); 89 86 90 CClass *pClass = (CClass *)lpVarIndex; 91 int object_size = pClass->GetSize(); 87 int object_size = varType.GetClass().GetSize(); 92 88 93 89 //mov rcx,object_size … … 107 103 108 104 //call free 109 extern SubInfo*pSub_free;105 extern UserProc *pSub_free; 110 106 op_call(pSub_free); 111 107 } -
BasicCompiler64/Compile_Statement.cpp
r73 r75 5 5 int i,i2; 6 6 char buffer[8192]; 7 SubInfo *psi;7 UserProc *pUserProc; 8 8 9 9 for(i=0;;i++){ … … 41 41 ////////////////////////////// 42 42 43 p si=GetSubHash(Command);43 pUserProc=GetSubHash(Command); 44 44 45 45 //GetSubHash内でエラー提示が行われた場合 46 if(p si==(SubInfo*)-1) return;47 48 if(p si==0){46 if(pUserProc==(UserProc *)-1) return; 47 48 if(pUserProc==0){ 49 49 char temporary[VN_SIZE]; 50 50 lstrcpy(temporary,Command); 51 51 52 52 CharUpper(temporary); 53 p si=GetSubHash(temporary);53 pUserProc=GetSubHash(temporary); 54 54 55 55 //GetSubHash内でエラー提示が行われた場合 56 if(p si==(SubInfo*)-1) return;57 } 58 59 if(p si){60 if( psi->dwType!=SUBTYPE_MACRO) SetError(10,Command,cp);61 62 Opcode_CallProc("",p si,0,"",0);56 if(pUserProc==(UserProc *)-1) return; 57 } 58 59 if(pUserProc){ 60 if( !pUserProc->IsMacro() ) SetError(10,Command,cp); 61 62 Opcode_CallProc("",pUserProc,0,"",0); 63 63 64 64 return; … … 72 72 73 73 int idProc; 74 void *p Info;75 idProc=GetProc(buffer, &pInfo);74 void *pProc; 75 idProc=GetProc(buffer,(void **)&pProc); 76 76 77 77 int i4; … … 91 91 //////////////// 92 92 93 LONG_PTR lp;94 i2=CallProc(idProc,pInfo,buffer,temp2,&lp);93 Type resultType; 94 CallProc(idProc,pProc,buffer,temp2,resultType); 95 95 96 96 … … 99 99 ///////////////////// 100 100 101 if( i2==DEF_STRUCT){101 if( resultType.IsStruct() ){ 102 102 //mov r14,rax 103 103 op_mov_RR(REG_R14,REG_RAX); 104 104 105 FreeTempObject(REG_R14, (CClass *)lp);105 FreeTempObject(REG_R14,&resultType.GetClass()); 106 106 } 107 107 return; … … 116 116 117 117 void Judgment(char *buffer){ 118 int reg=REG_RAX,type; 119 type=NumOpe(®,buffer,0,0,0); 118 int reg=REG_RAX; 119 Type resultType; 120 if( !NumOpe(®,buffer,Type(),resultType) ){ 121 return; 122 } 120 123 121 124 int offset; 122 125 123 if( type==DEF_DOUBLE){126 if(resultType.IsDouble()){ 124 127 double dbl=0; 125 128 offset=dataTable.Add( dbl ); … … 135 138 obp+=sizeof(long); 136 139 } 137 else if( type==DEF_SINGLE){140 else if(resultType.IsSingle()){ 138 141 float flt=0; 139 142 offset=dataTable.Add( flt ); … … 152 155 153 156 //cmp rax,0 154 op_cmp_value( GetTypeSize(type,-1),REG_RAX,0);157 op_cmp_value(resultType.GetSize(),REG_RAX,0); 155 158 } 156 159 } … … 340 343 void OpcodeFor(char *Parameter){ 341 344 extern HANDLE hHeap; 345 Type resultType; 342 346 int i,i2,i3; 343 347 char temporary[VN_SIZE],variable[VN_SIZE],JudgeNum[VN_SIZE],StepNum[VN_SIZE]; … … 400 404 sprintf(temporary,"(%s)>=0",StepNum); 401 405 402 int reg ,type;406 int reg; 403 407 reg=REG_RAX; 404 type=NumOpe(®,temporary,0,0,0); 408 if( !NumOpe(®,temporary,Type(),resultType) ){ 409 return; 410 } 405 411 406 412 //cmp rax,0 407 op_cmp_value( GetTypeSize(type,-1),REG_RAX,0);413 op_cmp_value(resultType.GetSize(),REG_RAX,0); 408 414 409 415 //je [カウンタ減少の場合の判定] … … 417 423 418 424 reg=REG_RAX; 419 type=NumOpe(®,temporary,0,0,0);425 NumOpe(®,temporary,Type(),Type()); 420 426 421 427 //jmp [カウンタ減少の場合の判定を飛び越す] … … 430 436 431 437 reg=REG_RAX; 432 type=NumOpe(®,temporary,0,0,0);438 NumOpe(®,temporary,Type(),resultType); 433 439 434 440 *((long *)(OpBuffer+i3))=obp-(i3+sizeof(long)); //jmpジャンプ先のオフセット値 435 441 436 442 //cmp rax,0 437 op_cmp_value( GetTypeSize(type,-1),REG_RAX,0);443 op_cmp_value(resultType.GetSize(),REG_RAX,0); 438 444 439 445 ErrorStep: … … 583 589 extern HANDLE hHeap; 584 590 585 extern BOOL bCompilingGlobal; 586 if(bCompilingGlobal){ 591 if( UserProc::IsGlobalAreaCompiling() ){ 587 592 SetError(12,"Exit Sub/Function",cp); 588 593 return; … … 611 616 CaseScheduleNum++; 612 617 } 613 void OpcodeSelect( char *Parameter){618 void OpcodeSelect( const char *lpszParms ){ 614 619 extern DWORD *pCaseSchedule; 615 620 extern int CaseScheduleNum; … … 631 636 NowCaseSchedule=0; 632 637 633 int reg1=REG_RAX,type1; 634 LONG_PTR lpIndex; 635 type1=NumOpe(®1,Parameter,0,0,&lpIndex); 636 637 if(type1==DEF_DOUBLE){ 638 int reg1=REG_RAX; 639 Type type1; 640 if( !NumOpe(®1,lpszParms,Type(), type1 ) ){ 641 return; 642 } 643 644 if(type1.IsDouble()){ 638 645 //movsd qword ptr[rsp+offset],xmm_reg ※スタックフレームを利用 639 646 pobj_sf->push(reg1,sizeof(double)); 640 647 } 641 else if(type1 ==DEF_SINGLE){648 else if(type1.IsSingle()){ 642 649 //movss dword ptr[rsp+offset],xmm_reg ※スタックフレームを利用 643 650 pobj_sf->push(reg1,sizeof(float)); 644 651 } 645 652 else{ 646 ExtendTypeTo64(type1 ,reg1);653 ExtendTypeTo64(type1.GetBasicType(),reg1); 647 654 648 655 //mov qword ptr[rsp+offset],reg ※スタックフレームを利用 … … 712 719 cp=NowCaseCp; 713 720 714 int reg2=REG_RDX,type2; 715 LONG_PTR lpIndex2; 716 type2=NumOpe(®2,temporary,type1,lpIndex,&lpIndex2); 721 int reg2=REG_RDX; 722 Type type2; 723 if( !NumOpe(®2,temporary,type1,type2) ){ 724 return; 725 } 717 726 718 727 cp=i2; 719 728 720 if(type1==DEF_OBJECT){ 721 CClass *pobj_c; 722 pobj_c=(CClass *)lpIndex; 723 724 std::vector<SubInfo *> subs; 725 pobj_c->EnumMethod( CALC_EQUAL, subs ); 729 if(type1.IsObject()){ 730 std::vector<UserProc *> subs; 731 type1.GetClass().EnumMethod( CALC_EQUAL, subs ); 726 732 if( subs.size() == 0 ){ 727 733 return; 728 734 } 729 735 730 PARAMETER_INFO *ppi = (PARAMETER_INFO *)HeapAlloc(hHeap,0,sizeof(PARAMETER_INFO)*3); 731 int iParmNum=0; 732 ppi[iParmNum].bArray=0; 733 ppi[iParmNum].bByVal=0; 734 ppi[iParmNum].name=0; 735 ppi[iParmNum].type=type2; 736 ppi[iParmNum].u.index=lpIndex2; 737 ppi[iParmNum].SubScripts[0]=-1; 738 iParmNum++; 736 Parameters params; 737 params.push_back( new Parameter( "", Type( type2 ) ) ); 739 738 740 739 //オーバーロードを解決 741 SubInfo *psi; 742 psi=OverloadSolution("==",subs,ppi,iParmNum,NULL); 743 HeapDefaultFree(ppi); 744 745 if(!psi){ 740 UserProc *pUserProc; 741 pUserProc=OverloadSolution("==",subs, params, NULL); 742 743 delete params[0]; 744 745 if(!pUserProc){ 746 746 //エラー 747 747 return; … … 759 759 760 760 //call operator_proc ※ ==演算子 761 op_call(p si);761 op_call(pUserProc); 762 762 763 763 //test rax,rax … … 769 769 } 770 770 else{ 771 if(type1 ==DEF_DOUBLE){771 if(type1.IsDouble()){ 772 772 int xmm_reg; 773 773 if(IsXmmReg(reg2)) xmm_reg=reg2; 774 774 else xmm_reg=REG_XMM5; 775 ChangeTypeToXmm_Double(type2 ,xmm_reg,reg2);775 ChangeTypeToXmm_Double(type2.GetBasicType(),xmm_reg,reg2); 776 776 777 777 //movsd xmm4,qword ptr[rsp+offset] ※スタックフレームから参照 … … 781 781 op_comisd(xmm_reg,REG_XMM4); 782 782 } 783 else if(type1 ==DEF_SINGLE){783 else if(type1.IsSingle()){ 784 784 int xmm_reg; 785 785 if(IsXmmReg(reg2)) xmm_reg=reg2; 786 786 else xmm_reg=REG_XMM5; 787 ChangeTypeToXmm_Single(type2 ,xmm_reg,reg2);787 ChangeTypeToXmm_Single(type2.GetBasicType(),xmm_reg,reg2); 788 788 789 789 //movss xmm4,dword ptr[rsp+offset] ※スタックフレームから参照 … … 796 796 //その他整数型 797 797 798 i2=NeutralizationType(type1 ,-1,type2,-1);798 i2=NeutralizationType(type1.GetBasicType(),-1,type2.GetBasicType(),-1); 799 799 800 800 //mov r14,qword ptr[rsp+offset] ※スタックフレームから参照 … … 883 883 884 884 //call _System_GetEip 885 extern SubInfo*pSub_System_GetEip;885 extern UserProc *pSub_System_GetEip; 886 886 op_call(pSub_System_GetEip); 887 887 … … 938 938 } 939 939 void OpcodeReturn(char *Parameter){ 940 extern BOOL bCompilingGlobal; 941 if(bCompilingGlobal){ 940 if( UserProc::IsGlobalAreaCompiling() ){ 942 941 SetError(62,NULL,cp); 943 942 } … … 945 944 //戻り値をセット 946 945 if(Parameter[0]){ 947 extern SubInfo *pCompilingSubInfo; 948 char *temp; 949 if(pCompilingSubInfo->name[0]==1&&pCompilingSubInfo->name[1]==ESC_OPERATOR) 950 temp="_System_ReturnValue"; 951 else temp=pCompilingSubInfo->name; 952 953 /* 954 TODO: 消す 955 if( pCompilingSubInfo->isReturnRef ){ 956 //参照型 957 SetRefVariable( temp, Parameter ); 946 UserProc &proc = UserProc::CompilingUserProc(); 947 948 const char *temp = "_System_ReturnValue"; 949 if(proc.GetName()[0]==1&&proc.GetName()[1]==ESC_OPERATOR) 950 { 958 951 } 959 952 else{ 960 //値型*/ 961 char temporary[VN_SIZE]; 962 sprintf(temporary,"%s=%s",temp,Parameter); 963 OpcodeCalc(temporary); 964 //} 953 temp=proc.GetName().c_str(); 954 } 955 956 char temporary[VN_SIZE]; 957 sprintf(temporary,"%s=%s",temp,Parameter); 958 OpcodeCalc(temporary); 965 959 } 966 960 … … 972 966 void Opcode_Input(const char *Parameter){ 973 967 extern int cp; 974 int i2,i3,i4,i5 ,type;968 int i2,i3,i4,i5; 975 969 BOOL bFile; 976 970 char temporary[VN_SIZE],temp2[VN_SIZE],buffer[VN_SIZE]; … … 1054 1048 } 1055 1049 1056 LONG_PTR lpIndex; 1057 type = GetVarType(temporary, &lpIndex, 1); 1050 Type varType; 1051 if( !GetVarType(temporary, varType, 1) ){ 1052 return; 1053 } 1058 1054 1059 1055 sprintf(temp2,"_System_InputDataPtr[%d]=VarPtr(%s)",i4,temporary); 1060 1056 OpcodeCalc(temp2); 1061 1057 1062 if(type==DEF_LONG) type=DEF_DWORD; 1063 else if(type==DEF_INTEGER) type=DEF_WORD; 1064 else if(type==DEF_OBJECT){ 1065 CClass *pobj_Class=(CClass *)lpIndex; 1066 if(lstrcmp(pobj_Class->name,"String")==0) type=DEF_STRING; 1067 } 1068 sprintf(temp2,"_System_InputDataType[%d]=%d",i4,type); 1058 if(varType.IsLong()) varType.SetBasicType( DEF_DWORD ); 1059 else if(varType.IsInteger()) varType.SetBasicType( DEF_WORD ); 1060 else if(varType.IsObject()){ 1061 varType.SetBasicType( DEF_OBJECT ); 1062 if( varType.IsStringObject() ){ 1063 varType.SetBasicType( DEF_STRING ); 1064 } 1065 } 1066 sprintf(temp2,"_System_InputDataType[%d]=%d",i4,varType.GetBasicType()); 1069 1067 OpcodeCalc(temp2); 1070 1068 … … 1075 1073 OpcodeCalc(temp2); 1076 1074 1077 SubInfo *psi;1078 if(bFile) p si=GetSubHash("INPUT_FromFile");1079 else p si=GetSubHash("INPUT_FromPrompt");1080 if(!p si){1075 UserProc *pUserProc; 1076 if(bFile) pUserProc=GetSubHash("INPUT_FromFile"); 1077 else pUserProc=GetSubHash("INPUT_FromPrompt"); 1078 if(!pUserProc){ 1081 1079 SetError(3,"Input",cp); 1082 1080 return; 1083 1081 } 1084 Opcode_CallProc(buffer,p si,0,"",0);1082 Opcode_CallProc(buffer,pUserProc,0,"",0); 1085 1083 } 1086 1084 void Opcode_PrintUsing(const char *Parameter,char *buffer,BOOL bFile){ … … 1177 1175 OpcodeCalc(temp2); 1178 1176 1179 SubInfo *psi;1180 if(bFile) p si=GetSubHash("PRINTUSING_ToFile");1181 else p si=GetSubHash("PRINTUSING_ToPrompt");1182 if(!p si){1177 UserProc *pUserProc; 1178 if(bFile) pUserProc=GetSubHash("PRINTUSING_ToFile"); 1179 else pUserProc=GetSubHash("PRINTUSING_ToPrompt"); 1180 if(!pUserProc){ 1183 1181 SetError(3,"Print",cp); 1184 1182 return; 1185 1183 } 1186 Opcode_CallProc(buffer,p si,0,"",0);1184 Opcode_CallProc(buffer,pUserProc,0,"",0); 1187 1185 } 1188 1186 void Opcode_Print(const char *Parameter,BOOL bWrite){ … … 1281 1279 if(sw) lstrcat(buffer,"+Ex\"\\r\\n\""); 1282 1280 1283 SubInfo *psi;1284 if(bFile) p si=GetSubHash("PRINT_ToFile");1285 else p si=GetSubHash("PRINT_ToPrompt");1286 if(!p si){1281 UserProc *pUserProc; 1282 if(bFile) pUserProc=GetSubHash("PRINT_ToFile"); 1283 else pUserProc=GetSubHash("PRINT_ToPrompt"); 1284 if(!pUserProc){ 1287 1285 SetError(3,"Print",cp); 1288 1286 return; 1289 1287 } 1290 Opcode_CallProc(buffer,p si,0,"",0);1288 Opcode_CallProc(buffer,pUserProc,0,"",0); 1291 1289 } 1292 1290 … … 1299 1297 1300 1298 void OpcodeSetPtrData(char *Parameter,int type){ 1301 int i ,i2;1299 int i; 1302 1300 char temporary[VN_SIZE]; 1303 1301 … … 1321 1319 1322 1320 int reg_ptr=REG_RAX; 1323 i2=NumOpe(®_ptr,temporary,0,0,0); 1324 if(!IsWholeNumberType(i2)){ 1321 Type resultType; 1322 if( !NumOpe(®_ptr,temporary,Type(),resultType) ){ 1323 return; 1324 } 1325 if(!resultType.IsWhole()){ 1325 1326 SetError(11,Parameter,cp); 1326 1327 return; … … 1338 1339 1339 1340 int temp_reg=REG_NON; 1340 i2=NumOpe(&temp_reg,temporary,0,0,0); 1341 if( !NumOpe(&temp_reg,temporary,Type(),resultType) ){ 1342 return; 1343 } 1341 1344 1342 1345 //レジスタのブロッキングを解除 … … 1344 1347 1345 1348 if(type==DEF_DOUBLE){ 1346 ChangeTypeToXmm_Double( i2,REG_XMM0,temp_reg);1349 ChangeTypeToXmm_Double(resultType.GetBasicType(),REG_XMM0,temp_reg); 1347 1350 1348 1351 //movsd qword ptr[reg_ptr],xmm0 … … 1350 1353 } 1351 1354 else if(type==DEF_SINGLE){ 1352 ChangeTypeToXmm_Single( i2,REG_XMM0,temp_reg);1355 ChangeTypeToXmm_Single(resultType.GetBasicType(),REG_XMM0,temp_reg); 1353 1356 1354 1357 //movss dword ptr[reg_ptr],xmm0 … … 1356 1359 } 1357 1360 else{ 1358 ChangeTypeToWhole( i2,type,REG_RCX,temp_reg);1361 ChangeTypeToWhole(resultType.GetBasicType(),type,REG_RCX,temp_reg); 1359 1362 1360 1363 //mov ptr[reg_ptr],rcx -
BasicCompiler64/Compile_Var.cpp
r73 r75 3 3 4 4 //変数 5 V ARIABLE *GlobalVar;5 Variables globalVars; 6 6 int MaxGlobalVarNum; 7 7 int AllGlobalVarSize; 8 8 int AllInitGlobalVarSize; 9 VARIABLE *LocalVar; 9 10 10 int MaxLocalVarNum; 11 11 int AllLocalVarSize; 12 12 13 13 14 void SetRelativeOffset(int *pType,LONG_PTR lpIndex,RELATIVE_VAR *pRelativeVar,char *lpPtrOffset){ 15 int i2; 16 17 14 void SetRelativeOffset( Type &resultType, RELATIVE_VAR *pRelativeVar,const char *lpPtrOffset){ 18 15 ///////////////////////////////////////////// 19 16 // 先頭ポインタをr12に取得してメモリへ退避 … … 31 28 32 29 int reg=REG_NON; 33 i2=NumOpe(®,lpPtrOffset,0,0,0); 34 if(!IsWholeNumberType(i2)) SetError(46,NULL,cp); 35 ExtendTypeTo64(i2,reg); 30 Type type; 31 NumOpe( ®, lpPtrOffset, Type(), type ); 32 if( !type.IsWhole() ){ 33 SetError(46,NULL,cp); 34 } 35 ExtendTypeTo64(type.GetBasicType(),reg); 36 36 37 37 if(reg==REG_R14){ … … 40 40 } 41 41 42 if( PTR_LEVEL(*pType)){43 *pType = PTR_LEVEL_DOWN( *pType);44 45 i 2=GetTypeSize(*pType,lpIndex);46 if( i2>=2){42 if( resultType.PtrLevel() ){ 43 resultType.PtrLevelDown(); 44 45 int typeSize = resultType.GetSize(); 46 if(typeSize>=2){ 47 47 //imul reg,i2 48 op_imul_RV(sizeof(_int64),reg, i2);48 op_imul_RV(sizeof(_int64),reg,typeSize); 49 49 } 50 50 } … … 80 80 } 81 81 } 82 BOOL GetArrayOffset(int *SubScripts,char *array,int type,LONG_PTR lpIndex){82 bool GetArrayOffset(const int *SubScripts,char *array, const Type &type){ 83 83 extern HANDLE hHeap; 84 int i,i2,i3,i4 ,TypeSize;84 int i,i2,i3,i4; 85 85 char temporary[VN_SIZE],*pParm[MAX_PARMS]; 86 86 … … 101 101 if(SubScripts[i3]==-1){ 102 102 for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]); 103 return 0;103 return false; 104 104 } 105 105 … … 114 114 if(SubScripts[i3]!=-1){ 115 115 for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]); 116 return 0;116 return false; 117 117 } 118 118 break; … … 136 136 137 137 int reg=REG_NON; 138 T YPEINFO TypeInfo;138 Type type; 139 139 BOOL bUseHeap; 140 TypeInfo.type=NumOpe(®,pParm[i],DEF_LONG,-1,&TypeInfo.u.lpIndex,&bUseHeap);141 if( TypeInfo.type==DEF_OBJECT){140 NumOpe( ®, pParm[i], Type( DEF_LONG ), type, &bUseHeap ); 141 if( type.IsObject() ){ 142 142 //キャスト演算子のオーバーロードに対応する 143 143 CallCastOperatorProc(reg, 144 TypeInfo.type,TypeInfo.u.lpIndex, 145 bUseHeap,DEF_LONG,-1); 146 TypeInfo.type=DEF_LONG; 147 } 148 149 if(!IsWholeNumberType(TypeInfo.type)) SetError(46,NULL,cp); 150 ExtendTypeTo64(TypeInfo.type,reg); 144 type, 145 bUseHeap, Type(DEF_LONG) ); 146 type.SetBasicType( DEF_LONG ); 147 } 148 149 if( !type.IsWhole() ){ 150 SetError(46,NULL,cp); 151 } 152 ExtendTypeTo64( type.GetBasicType(), reg ); 151 153 152 154 if(reg==REG_R14){ … … 168 170 HeapDefaultFree(pParm[i]); 169 171 } 170 171 TypeSize=GetTypeSize(type,lpIndex);172 172 173 173 //imul r12,TypeSize … … 175 175 OpBuffer[obp++]=(char)0x69; 176 176 OpBuffer[obp++]=(char)0xE4; 177 *((long *)(OpBuffer+obp))= TypeSize;177 *((long *)(OpBuffer+obp))=type.GetSize(); 178 178 obp+=sizeof(long); 179 179 … … 186 186 OpBuffer[obp++]=(char)0xDC; 187 187 188 return 1;188 return true; 189 189 } 190 BOOL GetMemberOffset(bool isErrorEnabled, bool isWriteAccess, CClass *pobj_c, char *member, int *pType, RELATIVE_VAR *pRelativeVar, LONG_PTR *plpNestIndex, BOOL bPrivateAccess){190 bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const CClass &objClass, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess){ 191 191 int i; 192 192 … … 202 202 CClass::RefType refType; 203 203 lstrcpy(VarName,member); 204 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return 0;204 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return false; 205 205 206 206 … … 209 209 //////////////////////////// 210 210 211 int offset = pobj_c->GetMemberOffset( VarName, &i );212 if(i== pobj_c->iMemberNum){211 int offset = objClass.GetMemberOffset( VarName, &i ); 212 if(i==objClass.iMemberNum){ 213 213 if(isErrorEnabled) SetError(103,VarName,cp); 214 return 0;215 } 216 217 CMember *pMember= pobj_c->ppobj_Member[i];214 return false; 215 } 216 217 CMember *pMember=objClass.ppobj_Member[i]; 218 218 219 219 220 220 //アクセシビリティをチェック 221 if( pobj_c==pobj_CompilingClass){221 if(&objClass==pobj_CompilingClass){ 222 222 //同一クラスオブジェクトの場合はプライベートアクセスを容認する 223 223 if(pMember->dwAccess==ACCESS_NON){ 224 224 if(isErrorEnabled) SetError(107,VarName,cp); 225 return 0;225 return false; 226 226 } 227 227 } … … 230 230 pMember->dwAccess==ACCESS_NON){ 231 231 if(isErrorEnabled) SetError(107,VarName,cp); 232 return 0;232 return false; 233 233 } 234 234 else if(bPrivateAccess==0&&pMember->dwAccess==ACCESS_PROTECTED){ 235 235 if(isErrorEnabled) SetError(108,VarName,cp); 236 return 0;236 return false; 237 237 } 238 238 } … … 242 242 if( pMember->IsConst() && //定数メンバである 243 243 isWriteAccess && //書き込みアクセスを要求されている 244 pobj_c->IsCompilingConstructor() == false //コンストラクタ コンパイル中を除く244 objClass.IsCompilingConstructor() == false //コンストラクタ コンパイル中を除く 245 245 ){ 246 246 //Const定義の変数に書き込みアクセスをしようとした場合 … … 248 248 } 249 249 250 *pType=pMember->TypeInfo.type; 251 *plpNestIndex=pMember->TypeInfo.u.lpIndex; 250 resultType = *pMember; 252 251 253 252 //ポインタ変数の場合 254 if( IsPtrType(*pType)){253 if( resultType.IsPointer() ){ 255 254 if(pMember->SubScripts[0]==-1){ 256 255 lstrcpy(lpPtrOffset,array); … … 261 260 if(lpPtrOffset[0]){ 262 261 if(isErrorEnabled) SetError(16,member,cp); 263 return 0;262 return false; 264 263 } 265 264 } … … 276 275 if(array[0]){ 277 276 //配列オフセット 278 if(!GetArrayOffset(pMember->SubScripts,array,*p Type,pMember->TypeInfo.u.lpIndex)){277 if(!GetArrayOffset(pMember->SubScripts,array,*pMember)){ 279 278 if(isErrorEnabled) SetError(14,member,cp); 280 279 } 281 280 } 282 281 else if(pMember->SubScripts[0]!=-1){ 283 *pType|=FLAG_PTR;282 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 284 283 } 285 284 … … 287 286 //入れ子構造の場合 288 287 289 if( *pType==DEF_OBJECT || *pType==DEF_STRUCT){288 if( resultType.IsObject() || resultType.IsStruct() ){ 290 289 if( refType != CClass::Dot ){ 291 290 if(isErrorEnabled) SetError(104,member,cp); 292 return 0;293 } 294 295 if( *pType==DEF_OBJECT){291 return false; 292 } 293 294 if( resultType.IsObject() ){ 296 295 // 参照内容へのポインタを抽出 297 296 SetRelativeOffset( *pRelativeVar ); 298 297 } 299 298 } 300 else if( *pType==DEF_PTR_OBJECT||*pType==DEF_PTR_STRUCT){299 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){ 301 300 //構造体ポインタ型メンバ変数 302 301 303 302 if(lpPtrOffset[0]){ 304 303 //pObj[n].member 305 if( ( *pType==DEF_PTR_OBJECT||*pType==DEF_PTR_STRUCT )&& refType != CClass::Dot ){ 306 if(isErrorEnabled) SetError(104,member,cp); 307 return 0; 304 if( ( resultType.IsObjectPtr() || resultType.IsStructPtr() ) 305 && refType != CClass::Dot ){ 306 if(isErrorEnabled) SetError(104,member,cp); 307 return false; 308 308 } 309 309 310 310 //直接参照に切り替え 311 SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);311 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 312 312 pRelativeVar->dwKind=VAR_DIRECTMEM; 313 313 … … 316 316 else{ 317 317 //pObj->member 318 if( ( *pType==DEF_PTR_OBJECT||*pType==DEF_PTR_STRUCT )&& refType != CClass::Pointer ){ 319 if(isErrorEnabled) SetError(104,member,cp); 320 return 0; 318 if( (resultType.IsObjectPtr() || resultType.IsStructPtr() ) 319 && refType != CClass::Pointer ){ 320 if(isErrorEnabled) SetError(104,member,cp); 321 return false; 321 322 } 322 323 … … 324 325 } 325 326 } 326 else if(*pType==MAKE_PTR_TYPE(DEF_OBJECT,2) || *pType==MAKE_PTR_TYPE(DEF_STRUCT,2)){ 327 else if( resultType.GetBasicType() == MAKE_PTR_TYPE(DEF_OBJECT,2) 328 || resultType.GetBasicType() == MAKE_PTR_TYPE(DEF_STRUCT,2)){ 327 329 //構造体ポインタのポインタ型メンバ変数 328 330 … … 331 333 if( refType != CClass::Pointer ){ 332 334 if(isErrorEnabled) SetError(104,member,cp); 333 return 0;335 return false; 334 336 } 335 337 336 338 //直接参照に切り替え 337 SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);339 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 338 340 pRelativeVar->dwKind=VAR_DIRECTMEM; 339 341 … … 345 347 else{ 346 348 if(isErrorEnabled) SetError(104,member,cp); 347 return 0;348 } 349 } 350 351 if(! GetMemberOffset(349 return false; 350 } 351 } 352 353 if(!_member_offset( 352 354 isErrorEnabled, 353 355 isWriteAccess, 354 pMember-> TypeInfo.u.pobj_Class,356 pMember->GetClass(), 355 357 NestMember, 356 pType,357 358 pRelativeVar, 358 plpNestIndex,359 0)) return 0;359 resultType, 360 0)) return false; 360 361 } 361 362 362 363 if(lpPtrOffset[0]){ 363 SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);364 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 364 365 pRelativeVar->dwKind=VAR_DIRECTMEM; 365 366 } 366 367 367 return 1;368 return true; 368 369 } 369 370 void GetWithName(char *buffer){ … … 380 381 //自身のオブジェクトのThisポインタをregにコピー 381 382 382 extern VARIABLE *LocalVar;383 383 RELATIVE_VAR RelativeVar; 384 384 RelativeVar.dwKind=VAR_LOCAL; … … 388 388 SetReg_WholeVariable(DEF_PTR_VOID,&RelativeVar,reg); 389 389 } 390 BOOL GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){ 391 extern BOOL bCompilingGlobal; 390 bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType,int *pss){ 392 391 int i; 393 LONG_PTR lpIndex;394 392 char variable[VN_SIZE],member[VN_SIZE],VarName[VN_SIZE],array[VN_SIZE],lpPtrOffset[VN_SIZE]; 395 393 … … 406 404 407 405 void *pInfo; 408 int idProc=GetProc(VarName, &pInfo);406 int idProc=GetProc(VarName,(void **)&pInfo); 409 407 410 408 if(idProc){ 411 409 pRelativeVar->dwKind=VAR_DIRECTMEM; 410 411 Type type; 412 412 413 413 ////////////////////////////////////////////////////// … … 420 420 //////////////// 421 421 422 *pType=CallProc(idProc,pInfo,VarName,array,&lpIndex);422 CallProc(idProc,pInfo,VarName,array,type); 423 423 424 424 //戻り値をr11にコピー … … 430 430 }//////////////////////////////////////////// 431 431 432 LONG_PTR lp2; 433 if(!GetMemberOffset( 432 if(!_member_offset( 434 433 isErrorEnabled, 435 434 isWriteAccess, 436 (CClass *)lpIndex, 437 member,pType,pRelativeVar,&lp2,0)) return 0; 438 if(plpIndex) *plpIndex=lp2; 439 440 return 1; 435 type.GetClass(), 436 member,pRelativeVar,resultType,0)) return false; 437 438 return true; 441 439 } 442 440 } … … 447 445 GetVarFormatString(VarName,array,lpPtrOffset,member,refType); 448 446 449 int *pSubScripts;447 const int *pSubScripts; 450 448 bool bConst = false; 451 449 452 450 453 if( bCompilingGlobal==0){451 if( UserProc::IsLocalAreaCompiling() ){ 454 452 ////////////////// 455 453 // ローカル変数 456 454 ////////////////// 457 455 458 for(i=MaxLocalVarNum-1;i>=0;i--){ //レキシカルスコープを考慮してバックサーチ 459 if( LocalVar[i].bLiving //現在のスコープで有効なもの 460 && LocalVar[i].ScopeLevel <= obj_LexScopes.GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮) 461 ){ 462 if(lstrcmp(VarName,LocalVar[i].name)==0) break; 463 } 464 } 465 if(i>=0){ 456 const Variable *pVar = UserProc::CompilingUserProc().localVars.BackSearch( VarName ); 457 if( pVar ){ 466 458 //ポインタ変数の場合 467 if( IsPtrType(LocalVar[i].type)){468 if( LocalVar[i].SubScripts[0]==-1){459 if( pVar->IsPointer() ){ 460 if( !pVar->IsArray() ){ 469 461 lstrcpy(lpPtrOffset,array); 470 462 array[0]=0; … … 475 467 SetError(16,variable,cp); 476 468 pRelativeVar->dwKind=NON_VAR; 477 return 0;469 return false; 478 470 } 479 471 } 480 472 481 pRelativeVar->offset=- LocalVar[i].offset;473 pRelativeVar->offset=-pVar->offset; 482 474 pRelativeVar->bOffsetOffset=0; 483 if( LocalVar[i].fRef){475 if( pVar->IsRef() ){ 484 476 // 参照型 485 477 pRelativeVar->dwKind = VAR_REFLOCAL; 486 478 } 487 479 else pRelativeVar->dwKind=VAR_LOCAL; 488 *pType=LocalVar[i].type; 489 lpIndex=LocalVar[i].u.index; 490 if(plpIndex) *plpIndex=lpIndex; 491 pSubScripts=LocalVar[i].SubScripts; 492 bConst = LocalVar[i].bConst; 480 resultType = *pVar; 481 pSubScripts=pVar->GetSubScriptsPtr(); 482 bConst = pVar->IsConst(); 493 483 494 484 goto ok; … … 506 496 SetThisPtrToReg(REG_R11); 507 497 508 *pType=DEF_OBJECT;509 498 pRelativeVar->dwKind=VAR_DIRECTMEM; 510 499 511 if(plpIndex) *plpIndex=(LONG_PTR)pobj_CompilingClass;512 return 1;500 resultType.SetType( DEF_OBJECT, pobj_CompilingClass ); 501 return true; 513 502 } 514 503 … … 542 531 543 532 pRelativeVar->dwKind=VAR_DIRECTMEM; 544 if(! GetMemberOffset(533 if(!_member_offset( 545 534 isErrorEnabled, 546 535 isWriteAccess, 547 pobj_CompilingClass,536 *pobj_CompilingClass, 548 537 variable, 549 pType,550 538 pRelativeVar, 551 &lpIndex,1)) return 0; 552 if(plpIndex) *plpIndex=lpIndex; 553 return 1; 539 resultType,1)) return false; 540 return true; 554 541 } 555 542 556 543 NonClassMember: 557 544 558 ////////////////////////// 559 // 静的ローカル変数 560 // ※"Static.Object.Method.Variable" 561 ////////////////////////// 562 563 char temporary[VN_SIZE]; 564 extern SubInfo *pCompilingSubInfo; 565 if(pCompilingSubInfo){ 566 GetNowStaticVarFullName(VarName,temporary); 567 568 for(i=0;i<MaxGlobalVarNum;i++){ 569 if(lstrcmp(temporary,GlobalVar[i].name)==0) break; 570 } 571 if(i!=MaxGlobalVarNum){ 545 { 546 const Variable *pVar; 547 548 ////////////////////////// 549 // 静的ローカル変数 550 // ※"Static.Object.Method.Variable" 551 ////////////////////////// 552 553 char temporary[VN_SIZE]; 554 if( UserProc::IsLocalAreaCompiling() ){ 555 GetNowStaticVarFullName(VarName,temporary); 556 557 pVar = globalVars.Find( temporary ); 558 if( pVar ){ 559 goto GlobalOk; 560 } 561 } 562 563 564 ////////////////////////// 565 // クラスの静的メンバ 566 ////////////////////////// 567 568 if(member[0]){ 569 lstrcpy(temporary,member); 570 571 char tempMember[VN_SIZE]; 572 char tempArray[VN_SIZE]; 573 { 574 CClass::RefType refType; 575 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember, refType ); 576 } 577 578 char temp2[VN_SIZE]; 579 sprintf(temp2,"%s.%s",VarName,temporary); 580 pVar = globalVars.Find( temp2 ); 581 if( pVar ){ 582 lstrcpy(member,tempMember); 583 lstrcpy(array,tempArray); 584 goto GlobalOk; 585 } 586 } 587 588 if(pobj_CompilingClass){ 589 //自身のクラスから静的メンバを参照する場合 590 char temp2[VN_SIZE]; 591 sprintf(temp2,"%s.%s",pobj_CompilingClass->name,VarName); 592 pVar = globalVars.Find( temp2 ); 593 if( pVar ){ 594 goto GlobalOk; 595 } 596 } 597 598 ///////////////////// 599 // グローバル変数 600 ///////////////////// 601 602 pVar = globalVars.BackSearch( VarName ); 603 if( pVar ){ 572 604 goto GlobalOk; 573 605 } 574 } 575 576 577 ////////////////////////// 578 // クラスの静的メンバ 579 ////////////////////////// 580 581 if(member[0]){ 582 lstrcpy(temporary,member); 583 584 char tempMember[VN_SIZE]; 585 char tempArray[VN_SIZE]; 586 { 587 CClass::RefType refType; 588 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember, refType ); 589 } 590 591 char temp2[VN_SIZE]; 592 sprintf(temp2,"%s.%s",VarName,temporary); 593 for(i=0;i<MaxGlobalVarNum;i++){ 594 if(lstrcmp(temp2,GlobalVar[i].name)==0) break; 595 } 596 597 if(i!=MaxGlobalVarNum){ 598 lstrcpy(member,tempMember); 599 lstrcpy(array,tempArray); 600 goto GlobalOk; 601 } 602 } 603 604 if(pobj_CompilingClass){ 605 //自身のクラスから静的メンバを参照する場合 606 char temp2[VN_SIZE]; 607 sprintf(temp2,"%s.%s",pobj_CompilingClass->name,VarName); 608 for(i=0;i<MaxGlobalVarNum;i++){ 609 if(lstrcmp(temp2,GlobalVar[i].name)==0) break; 610 } 611 612 if(i!=MaxGlobalVarNum){ 613 goto GlobalOk; 614 } 615 } 616 617 ///////////////////// 618 // グローバル変数 619 ///////////////////// 620 621 for(i=MaxGlobalVarNum-1;i>=0;i--){ //レキシカルスコープを考慮してバックサーチ 622 if( GlobalVar[i].bLiving //現在のスコープで有効なもの 623 && GlobalVar[i].ScopeLevel <= obj_LexScopes.GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮) 624 ){ 625 if(lstrcmp(VarName,GlobalVar[i].name)==0) break; 626 } 627 } 628 if(i>=0){ 629 goto GlobalOk; 630 } 631 632 if(isErrorEnabled) SetError(3,variable,cp); 633 pRelativeVar->dwKind=NON_VAR; 634 return 0; 606 607 if(isErrorEnabled) SetError(3,variable,cp); 608 pRelativeVar->dwKind=NON_VAR; 609 return false; 635 610 636 611 637 612 638 613 GlobalOk: 639 //ポインタ変数の場合 640 if(IsPtrType(GlobalVar[i].type)){ 641 if(GlobalVar[i].SubScripts[0]==-1){ 642 lstrcpy(lpPtrOffset,array); 643 array[0]=0; 644 } 645 } 646 else{ 647 if(lpPtrOffset[0]){ 648 SetError(16,variable,cp); 649 pRelativeVar->dwKind=NON_VAR; 650 return 0; 651 } 652 } 653 654 pRelativeVar->offset=GlobalVar[i].offset; 655 pRelativeVar->bOffsetOffset=0; 656 if(GlobalVar[i].fRef){ 657 // 参照型 658 pRelativeVar->dwKind = VAR_REFGLOBAL; 659 } 660 else pRelativeVar->dwKind=VAR_GLOBAL; 661 *pType=GlobalVar[i].type; 662 lpIndex=GlobalVar[i].u.index; 663 if(plpIndex) *plpIndex=lpIndex; 664 pSubScripts=GlobalVar[i].SubScripts; 665 bConst = GlobalVar[i].bConst; 614 //ポインタ変数の場合 615 if( pVar->IsPointer() ){ 616 if( !pVar->IsArray() ){ 617 lstrcpy(lpPtrOffset,array); 618 array[0]=0; 619 } 620 } 621 else{ 622 if(lpPtrOffset[0]){ 623 SetError(16,variable,cp); 624 pRelativeVar->dwKind=NON_VAR; 625 return false; 626 } 627 } 628 629 pRelativeVar->offset=pVar->offset; 630 pRelativeVar->bOffsetOffset=0; 631 if( pVar->IsRef() ){ 632 // 参照型 633 pRelativeVar->dwKind = VAR_REFGLOBAL; 634 } 635 else pRelativeVar->dwKind=VAR_GLOBAL; 636 resultType = *pVar; 637 pSubScripts=pVar->GetSubScriptsPtr(); 638 bConst = pVar->IsConst(); 639 } 666 640 667 641 … … 671 645 if( bConst && isWriteAccess ){ 672 646 //Const定義の変数に書き込みアクセスをしようとした場合 673 if( *pType == DEF_OBJECT){647 if( resultType.IsObject() ){ 674 648 //オブジェクト定数 675 649 SetError(130, VarName, cp ); … … 683 657 if(array[0]==0&&pSubScripts[0]!=-1){ 684 658 //配列の先頭ポインタを示す場合 685 *pType|=FLAG_PTR;659 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 686 660 if(pss) memcpy(pss,pSubScripts,MAX_ARRAYDIM); 687 return 1;661 return true; 688 662 } 689 663 … … 696 670 } 697 671 if(array[0]){ 698 if(!GetArrayOffset(pSubScripts,array, *pType,lpIndex)){672 if(!GetArrayOffset(pSubScripts,array,resultType)){ 699 673 SetError(14,variable,cp); 700 674 pRelativeVar->dwKind=NON_VAR; 701 return 0;675 return false; 702 676 } 703 677 } 704 678 if(member[0]){ 705 if( *pType==DEF_OBJECT || *pType==DEF_STRUCT){679 if( resultType.IsObject() || resultType.IsStruct() ){ 706 680 //実態オブジェクトのメンバを参照(obj.member) 707 681 if( refType != CClass::Dot ){ 708 682 SetError(104,VarName,cp); 709 683 pRelativeVar->dwKind=NON_VAR; 710 return 0;711 } 712 713 if( *pType==DEF_OBJECT){684 return false; 685 } 686 687 if( resultType.IsObject() ){ 714 688 // 参照内容へのポインタを抽出 715 689 SetRelativeOffset( *pRelativeVar ); 716 690 } 717 691 } 718 else if( *pType==DEF_PTR_OBJECT || *pType==DEF_PTR_STRUCT){692 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){ 719 693 //ポインタオブジェクトが示すメンバを参照 720 694 if(lpPtrOffset[0]){ … … 723 697 SetError(104,VarName,cp); 724 698 pRelativeVar->dwKind=NON_VAR; 725 return 0;699 return false; 726 700 } 727 SetRelativeOffset( pType,lpIndex,pRelativeVar,lpPtrOffset);701 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 728 702 pRelativeVar->dwKind=VAR_DIRECTMEM; 729 703 } … … 733 707 SetError(104,VarName,cp); 734 708 pRelativeVar->dwKind=NON_VAR; 735 return 0;709 return false; 736 710 } 737 711 … … 743 717 } 744 718 } 745 else if( *pType==MAKE_PTR_TYPE(DEF_OBJECT,2) || *pType==MAKE_PTR_TYPE(DEF_STRUCT,2)){719 else if( resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_OBJECT,2) || resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_STRUCT,2)){ 746 720 //ポインタオブジェクトが示すメンバを参照 747 721 if(lpPtrOffset[0]){ … … 750 724 SetError(104,VarName,cp); 751 725 pRelativeVar->dwKind=NON_VAR; 752 return 0;726 return false; 753 727 } 754 728 755 SetRelativeOffset( pType,lpIndex,pRelativeVar,lpPtrOffset);729 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 756 730 pRelativeVar->dwKind=VAR_DIRECTMEM; 757 731 … … 765 739 SetError(104,VarName,cp); 766 740 pRelativeVar->dwKind=NON_VAR; 767 return 0;741 return false; 768 742 } 769 743 } … … 771 745 SetError(102,VarName,cp); 772 746 pRelativeVar->dwKind=NON_VAR; 773 return 0; 774 } 775 776 LONG_PTR lp2; 777 if(!GetMemberOffset( 747 return false; 748 } 749 750 if(!_member_offset( 778 751 isErrorEnabled, 779 752 isWriteAccess, 780 (CClass *)lpIndex, 781 member,pType,pRelativeVar,&lp2,0)) return 0; 782 if(plpIndex) *plpIndex=lp2; 783 784 return 1; 753 resultType.GetClass(), 754 member,pRelativeVar,resultType,0)) return false; 755 756 return true; 785 757 } 786 758 787 759 if(lpPtrOffset[0]){ 788 SetRelativeOffset( pType,lpIndex,pRelativeVar,lpPtrOffset);760 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 789 761 pRelativeVar->dwKind=VAR_DIRECTMEM; 790 762 } 791 763 792 return 1;764 return true; 793 765 } 794 766 795 BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf){767 bool SetInitGlobalData(int offset,const Type &type,const int *SubScripts,char *InitBuf){ 796 768 extern BYTE *initGlobalBuf; 797 int i,i2,i3 ,TypeSize;769 int i,i2,i3; 798 770 char temporary[VN_SIZE]; 799 771 … … 802 774 InitBuf[lstrlen(InitBuf)-1]=0; 803 775 804 TypeSize=GetTypeSize(type,lpIndex);776 int typeSize = type.GetSize(); 805 777 806 778 if(SubScripts[0]!=-1){ 807 TypeSize*=JumpSubScripts(SubScripts+1);779 typeSize*=JumpSubScripts(SubScripts+1); 808 780 i=0; 809 781 i2=0; … … 815 787 i=GetOneParameter(InitBuf,i,temporary); 816 788 if(!SetInitGlobalData( 817 offset+i2* TypeSize,789 offset+i2*typeSize, 818 790 type, 819 lpIndex,820 791 SubScripts+1, 821 temporary)) return 0;792 temporary)) return false; 822 793 i2++; 823 794 if(InitBuf[i]=='\0') break; 824 795 } 825 return -1; 826 } 827 828 if(type==DEF_STRUCT){ 829 CClass *pobj_c; 830 pobj_c=(CClass *)lpIndex; 831 832 for(i=0,i2=0;i2<pobj_c->iMemberNum;i2++){ 796 return true; 797 } 798 799 if(type.IsStruct()){ 800 const CClass &objClass = type.GetClass(); 801 802 for(i=0,i2=0;i2<objClass.iMemberNum;i2++){ 833 803 i=GetOneParameter(InitBuf,i,temporary); 834 804 835 i3= pobj_c->GetMemberOffset( pobj_c->ppobj_Member[i2]->name, NULL );805 i3=objClass.GetMemberOffset( objClass.ppobj_Member[i2]->name, NULL ); 836 806 837 807 if(!SetInitGlobalData(offset+i3, 838 pobj_c->ppobj_Member[i2]->TypeInfo.type, 839 pobj_c->ppobj_Member[i2]->TypeInfo.u.lpIndex, 840 pobj_c->ppobj_Member[i2]->SubScripts, 841 temporary)) return 0; 808 *objClass.ppobj_Member[i2], 809 objClass.ppobj_Member[i2]->SubScripts, 810 temporary)) return false; 842 811 843 812 if(InitBuf[i]=='\0') break; 844 813 } 845 if(i2+1!= pobj_c->iMemberNum){814 if(i2+1!=objClass.iMemberNum){ 846 815 SetError(41,0,cp); 847 return 0;848 } 849 return 1;816 return false; 817 } 818 return true; 850 819 } 851 820 852 821 SetError(41,0,cp); 853 return 0;822 return false; 854 823 } 855 824 … … 859 828 /////////////////////////////////////// 860 829 861 if( type == DEF_OBJECT || type == DEF_STRUCT){830 if( type.IsObject() || type.IsStruct() ){ 862 831 //オブジェクトまたは構造体の場合はありえない 863 832 SetError(300,NULL,cp); 864 return 0;833 return false; 865 834 } 866 835 867 836 if(SubScripts[0]!=-1){ 868 837 SetError(41,0,cp); 869 return 0;838 return false; 870 839 } 871 840 872 841 double dbl; 873 842 _int64 i64data; 874 int CalcType; 875 LONG_PTR lpCalcIndex; 876 877 CalcType=StaticCalculation(false, InitBuf,type,&i64data,&lpCalcIndex); 878 if(!CalcType){ 843 Type calcType; 844 845 if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){ 879 846 //動的データだった場合 880 return 0;881 } 882 if( IsRealNumberType(CalcType)){847 return false; 848 } 849 if( calcType.IsReal() ){ 883 850 memcpy(&dbl,&i64data,sizeof(double)); 884 851 i64data=(_int64)dbl; … … 889 856 CheckDifferentType( 890 857 type, 891 lpIndex, 892 CalcType, 893 lpCalcIndex, 858 calcType, 894 859 0,0); 895 860 896 if( type==DEF_DOUBLE)861 if( type.IsDouble() ){ 897 862 *(double *)(initGlobalBuf+offset)=(double)dbl; 898 else if(type==DEF_SINGLE) 899 *(float *)(initGlobalBuf+offset)=(float)dbl; 900 else if(type==DEF_INT64||type==DEF_QWORD||IsPtrType(type)){ 901 if(type==typeOfPtrChar&&lpCalcIndex==LITERAL_STRING){ 863 } 864 else if( type.IsSingle() ){ 865 *(float *)(initGlobalBuf+offset)=(float)dbl; 866 } 867 else if( type.Is64() || type.IsPointer() ){ 868 if(type.GetBasicType()==typeOfPtrChar && type.GetIndex()==LITERAL_STRING){ 902 869 //文字列定数のとき 903 870 … … 923 890 } 924 891 } 925 else if( type==DEF_LONG||type==DEF_DWORD)892 else if( type.IsDWord() || type.IsLong() ){ 926 893 *(DWORD *)(initGlobalBuf+offset)=(DWORD)i64data; 927 else if(type==DEF_INTEGER||type==DEF_WORD || (isUnicode&&type==DEF_CHAR)) 894 } 895 else if( type.IsWord() || type.IsInteger() ){ 928 896 *(WORD *)(initGlobalBuf+offset)=(WORD)i64data; 929 else if(type==DEF_SBYTE||type==DEF_BYTE||type==DEF_BOOLEAN || (isUnicode==false&&type==DEF_CHAR)) 897 } 898 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){ 930 899 *(BYTE *)(initGlobalBuf+offset)=(BYTE)i64data; 931 932 return 1; 900 } 901 902 return true; 933 903 } 934 BOOL InitLocalVar(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf){935 int i,i2,i3 ,TypeSize;904 bool InitLocalVar(int offset,const Type &type,const int *SubScripts,char *InitBuf){ 905 int i,i2,i3; 936 906 char temporary[VN_SIZE]; 937 907 … … 940 910 InitBuf[lstrlen(InitBuf)-1]=0; 941 911 942 TypeSize=GetTypeSize(type,lpIndex);912 int typeSize = type.GetSize(); 943 913 944 914 if(SubScripts[0]!=-1){ 945 TypeSize*=JumpSubScripts(SubScripts+1);915 typeSize*=JumpSubScripts(SubScripts+1); 946 916 i=0; 947 917 i2=0; … … 949 919 if(SubScripts[0]<i2){ 950 920 SetError(41,0,cp); 951 return 0;921 return false; 952 922 } 953 923 i=GetOneParameter(InitBuf,i,temporary); 954 924 if(!InitLocalVar( 955 offset+i2* TypeSize,925 offset+i2*typeSize, 956 926 type, 957 lpIndex,958 927 SubScripts+1, 959 temporary)) return 0;928 temporary)) return false; 960 929 i2++; 961 930 if(InitBuf[i]=='\0') break; 962 931 } 963 return -1; 964 } 965 966 if(type==DEF_STRUCT){ 967 CClass *pobj_c; 968 pobj_c=(CClass *)lpIndex; 969 970 for(i=0,i2=0;i2<pobj_c->iMemberNum;i2++){ 932 return true; 933 } 934 935 if(type.IsStruct()){ 936 const CClass &objClass = type.GetClass(); 937 938 for(i=0,i2=0;i2<objClass.iMemberNum;i2++){ 971 939 i=GetOneParameter(InitBuf,i,temporary); 972 940 973 i3= pobj_c->GetMemberOffset( pobj_c->ppobj_Member[i2]->name, NULL );941 i3=objClass.GetMemberOffset( objClass.ppobj_Member[i2]->name, NULL ); 974 942 975 943 if(!InitLocalVar(offset+i3, 976 pobj_c->ppobj_Member[i2]->TypeInfo.type, 977 pobj_c->ppobj_Member[i2]->TypeInfo.u.lpIndex, 978 pobj_c->ppobj_Member[i2]->SubScripts, 979 temporary)) return 0; 944 *objClass.ppobj_Member[i2], 945 objClass.ppobj_Member[i2]->SubScripts, 946 temporary)) return false; 980 947 981 948 if(InitBuf[i]=='\0') break; 982 949 } 983 if(i2+1!= pobj_c->iMemberNum){950 if(i2+1!=objClass.iMemberNum){ 984 951 SetError(41,0,cp); 985 952 return 0; 986 953 } 987 return 1;954 return true; 988 955 } 989 956 990 957 SetError(41,0,cp); 991 return 0;958 return false; 992 959 } 993 960 … … 999 966 if(SubScripts[0]!=-1){ 1000 967 SetError(41,0,cp); 1001 return 0;968 return false; 1002 969 } 1003 970 1004 971 double dbl; 1005 972 _int64 i64data; 1006 int CalcType; 1007 LONG_PTR lpCalcIndex; 1008 CalcType=StaticCalculation(false, InitBuf,type,&i64data,&lpCalcIndex); 1009 if(!CalcType){ 973 Type calcType; 974 975 if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){ 1010 976 //動的データだった場合 1011 return 0;1012 } 1013 if( IsRealNumberType(CalcType)){977 return false; 978 } 979 if( calcType.IsReal() ){ 1014 980 memcpy(&dbl,&i64data,sizeof(double)); 1015 981 i64data=(_int64)dbl; … … 1020 986 CheckDifferentType( 1021 987 type, 1022 lpIndex, 1023 CalcType, 1024 lpCalcIndex, 988 calcType, 1025 989 0,0); 1026 990 1027 if( type==DEF_DOUBLE){991 if( type.IsDouble() ){ 1028 992 memcpy(&i64data,&dbl,sizeof(double)); 1029 993 … … 1037 1001 obp+=sizeof(long); 1038 1002 } 1039 else if( type==DEF_SINGLE){1003 else if( type.IsSingle() ){ 1040 1004 float flt; 1041 1005 flt=(float)dbl; … … 1047 1011 obp+=sizeof(long)+sizeof(long); 1048 1012 } 1049 else if( type==DEF_INT64||type==DEF_QWORD||IsPtrType(type)){1050 if(type ==typeOfPtrChar&&lpCalcIndex==LITERAL_STRING){1013 else if( type.Is64() || type.IsPointer() ){ 1014 if(type.GetBasicType()==typeOfPtrChar && type.GetIndex()==LITERAL_STRING){ 1051 1015 //文字列定数のとき 1052 1016 … … 1088 1052 } 1089 1053 } 1090 else if( type==DEF_LONG||type==DEF_DWORD){1054 else if( type.IsDWord() || type.IsLong() ){ 1091 1055 //mov dword ptr[rsp+offset],value 1092 1056 op_mov_MV(sizeof(long),REG_RSP,offset,USE_OFFSET,(int)i64data); … … 1095 1059 obp+=sizeof(long)+sizeof(long); 1096 1060 } 1097 else if( type==DEF_INTEGER||type==DEF_WORD || (isUnicode&&type==DEF_CHAR)){1061 else if( type.IsWord() || type.IsInteger() ){ 1098 1062 //mov word ptr[rsp+offset],value 1099 1063 op_mov_MV(sizeof(short),REG_RSP,offset,USE_OFFSET,(int)i64data); … … 1102 1066 obp+=sizeof(long)+sizeof(short); 1103 1067 } 1104 else if( type==DEF_SBYTE||type==DEF_BYTE||type==DEF_BOOLEAN || (isUnicode==false&&type==DEF_CHAR)){1068 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){ 1105 1069 //mov byte ptr[rsp+offset],value 1106 1070 op_mov_MV(sizeof(char),REG_RSP,offset,USE_OFFSET,(int)i64data); … … 1109 1073 obp+=sizeof(long)+sizeof(char); 1110 1074 } 1111 return 1;1075 return true; 1112 1076 } 1113 1077 1114 void dim(bool isRef, char *VarName,int *SubScripts,TYPEINFO &TypeInfo,int TypeSize,char *InitBuf,char *ConstractParameter,DWORD dwFlags){ 1115 extern BOOL bCompilingGlobal; 1116 if(bCompilingGlobal){ 1078 void dim(bool isRef, char *VarName,int *SubScripts,Type &type,char *InitBuf,char *ConstractParameter,DWORD dwFlags){ 1079 if( UserProc::IsGlobalAreaCompiling() ){ 1117 1080 ///////////////////////// 1118 1081 // グローバル変数 1119 1082 ///////////////////////// 1120 1083 1121 AddGlobalVariable(isRef,VarName,SubScripts, &TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags);1084 AddGlobalVariable(isRef,VarName,SubScripts,type,InitBuf,ConstractParameter,dwFlags); 1122 1085 } 1123 1086 else{ … … 1126 1089 ///////////////// 1127 1090 1128 int i2,i3; 1129 1130 for(i2=0;i2<MaxLocalVarNum;i2++){ 1131 if(LocalVar[i2].bLiving&&obj_LexScopes.GetNowLevel()==LocalVar[i2].ScopeLevel){ 1132 if(lstrcmp(LocalVar[i2].name,VarName)==0){ 1133 //2重定義のエラー 1134 SetError(15,VarName,cp); 1135 return; 1136 } 1137 } 1138 } 1139 1140 LocalVar=(VARIABLE *)HeapReAlloc(hHeap,0,LocalVar,(MaxLocalVarNum+1)*sizeof(VARIABLE)); 1141 VARIABLE *pVar = &LocalVar[MaxLocalVarNum]; 1142 MaxLocalVarNum++; 1143 1144 if( isRef ){ 1145 //参照型 1146 pVar->fRef = REF_VARIABLE; 1147 TypeSize = PTR_SIZE; 1148 } 1149 else pVar->fRef=0; 1150 1151 for(i2=1,i3=0;i3<255;i3++){ 1152 //配列要素数 1153 pVar->SubScripts[i3]=SubScripts[i3]; 1154 1155 if(SubScripts[i3]==-1) break; 1156 i2*=SubScripts[i3]+1; 1157 } 1158 int VarSize=TypeSize*i2; 1159 if(VarSize%8) VarSize+=8-(VarSize%8); 1160 1161 //変数データを追加 1162 lstrcpy(pVar->name,VarName); 1163 if(dwFlags & DIMFLAG_CONST) pVar->bConst = true; 1164 else pVar->bConst = false; 1165 if(SubScripts[0]==-1) pVar->bArray=0; 1166 else pVar->bArray=1; 1167 pVar->type=TypeInfo.type; 1168 pVar->u.index=TypeInfo.u.lpIndex; 1091 if( UserProc::CompilingUserProc().localVars.DuplicateCheck( VarName ) ){ 1092 //2重定義のエラー 1093 SetError(15,VarName,cp); 1094 return; 1095 } 1096 1097 bool isConst = ( dwFlags & DIMFLAG_CONST ) ? true:false; 1098 1099 Variable *pVar = new Variable( VarName, type, isConst, isRef ); 1100 1101 if( SubScripts[0] != -1 ){ 1102 //配列あり 1103 pVar->SetArray( SubScripts ); 1104 } 1105 1106 //コンストラクタ用パラメータ 1107 pVar->paramStrForConstructor = ConstractParameter; 1108 1109 //レキシカルスコープ 1110 pVar->ScopeLevel=obj_LexScopes.GetNowLevel(); 1111 pVar->ScopeStartAddress=obj_LexScopes.GetStartAddress(); 1112 pVar->bLiving=TRUE; 1113 1114 //エラー用 1115 pVar->source_code_address=cp; 1116 1117 // 変数を追加 1118 UserProc::CompilingUserProc().localVars.push_back( pVar ); 1169 1119 1170 1120 //アラインメントを考慮 1171 if( pVar-> type==DEF_STRUCT){1172 int alignment = pVar-> u.pobj_c->iAlign;1121 if( pVar->IsStruct() ){ 1122 int alignment = pVar->GetClass().iAlign; 1173 1123 if( alignment ){ 1174 1124 if( AllLocalVarSize % alignment ){ … … 1178 1128 } 1179 1129 1180 AllLocalVarSize +=VarSize;1181 pVar->offset =AllLocalVarSize;1130 AllLocalVarSize += pVar->GetMemorySize(); 1131 pVar->offset = AllLocalVarSize; 1182 1132 1183 1133 //レキシカルスコープ … … 1188 1138 if(InitBuf[0]){ 1189 1139 //初期代入時のみ、書き込みアクセスを許可する 1190 bool bConstBack = pVar->bConst; 1191 pVar->bConst = false; 1140 if( isConst ){ 1141 pVar->ConstOff(); 1142 } 1192 1143 1193 1144 int result = 0; 1194 if( pVar->type != DEF_OBJECT){1145 if( !pVar->IsObject() ){ 1195 1146 result = InitLocalVar(-pVar->offset, 1196 pVar->type, 1197 pVar->u.index, 1198 pVar->SubScripts, 1147 *pVar, 1148 pVar->GetSubScriptsPtr(), 1199 1149 InitBuf); 1200 1150 } … … 1207 1157 } 1208 1158 1209 pVar->bConst = bConstBack; 1159 if( isConst ){ 1160 pVar->ConstOn(); 1161 } 1210 1162 } 1211 1163 else{ … … 1216 1168 1217 1169 //mov rdx, VarSize 1218 op_mov_RV( sizeof(_int64), REG_RDX, VarSize);1170 op_mov_RV( sizeof(_int64), REG_RDX, pVar->GetMemorySize() ); 1219 1171 1220 1172 //mov rcx, rsp … … 1228 1180 1229 1181 //call FillMemory 1230 D ECLAREINFO *pdi;1231 p di=GetDeclareHash("FillMemory");1232 op_call( p di);1182 DllProc *pDllProc; 1183 pDllProc=GetDeclareHash("FillMemory"); 1184 op_call( pDllProc ); 1233 1185 } 1234 1186 } 1235 1187 1236 1188 //コンストラクタ呼び出し 1237 if( TypeInfo.type==DEF_OBJECT&&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&&InitBuf[0]=='\0'){1189 if( type.IsObject() &&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&&InitBuf[0]=='\0'){ 1238 1190 char objectSize[255]; 1239 1191 if( SubScripts[0] == -1 ){ … … 1246 1198 sprintf( objectSize, "%d", SubScripts[0] ); 1247 1199 } 1248 Operator_New( *TypeInfo.u.pobj_Class, objectSize, ConstractParameter, TypeInfo ); 1249 1250 int type; 1251 LONG_PTR lpIndex; 1200 Operator_New( type.GetClass(), objectSize, ConstractParameter, type ); 1201 1202 Type tempType; 1252 1203 RELATIVE_VAR RelativeVar; 1253 GetVarOffset( true, false, VarName, & type, &RelativeVar, &lpIndex);1204 GetVarOffset( true, false, VarName, &RelativeVar, tempType ); 1254 1205 if( RelativeVar.dwKind == VAR_DIRECTMEM ){ 1255 1206 SetError(); … … 1258 1209 } 1259 1210 1260 if( TypeInfo.type==DEF_OBJECT){1261 if( TypeInfo.u.pobj_Class->IsAbstract()){1211 if( type.IsObject() ){ 1212 if( type.GetClass().IsAbstract() ){ 1262 1213 //抽象クラスだったとき 1263 SetError(125, TypeInfo.u.pobj_Class->name,cp);1214 SetError(125,type.GetClass().name,cp); 1264 1215 } 1265 1216 } 1266 1217 } 1267 void dim(char *Parameter,DWORD dwFlags){1268 extern BOOL bCompilingGlobal;1269 extern HANDLE hHeap;1270 int i2;1271 char VarName[VN_SIZE];1272 1273 //参照型かどうか1274 bool isRef = false;1275 1276 i2 = 0;1277 1278 if( Parameter[i2] == 1 && Parameter[i2+1] == ESC_BYREF ){1279 //参照型1280 isRef = true;1281 Parameter += 2;1282 }1283 1284 if(dwFlags & DIMFLAG_CONST){1285 1286 //////////////////////////////////1287 // 定数変数の場合を考慮1288 //////////////////////////////////1289 for(;;i2++){1290 if(Parameter[i2] == '=' ||1291 Parameter[i2] == 1 && Parameter[i2] == ESC_AS ||1292 Parameter[i2] =='('){1293 VarName[i2] = 0;1294 break;1295 }1296 VarName[i2] = Parameter[i2];1297 }1298 1299 //定数と2重定義されていないる場合は抜け出す1300 if(CDBConst::obj.GetType(VarName)){1301 return;1302 }1303 1304 //定数マクロとして定義されている場合は抜け出す1305 if(GetConstHash(VarName)){1306 return;1307 }1308 }1309 1310 1311 //構文を解析1312 int SubScripts[MAX_ARRAYDIM];1313 TYPEINFO TypeInfo;1314 char InitBuf[8192];1315 char ConstractParameter[VN_SIZE];1316 if(!GetDimentionFormat(Parameter, isRef , VarName,SubScripts,&TypeInfo,InitBuf,ConstractParameter))1317 return;1318 1319 1320 //定数と2重定義されていないかを調べる1321 if(CDBConst::obj.GetType(VarName)){1322 SetError(15,VarName,cp);1323 return;1324 }1325 1326 //定数マクロとして定義されている場合1327 if(GetConstHash(VarName)){1328 SetError(15,VarName,cp);1329 return;1330 }1331 1332 1333 //タイプサイズを取得1334 int TypeSize;1335 TypeSize=GetTypeSize(TypeInfo.type,TypeInfo.u.lpIndex);1336 1337 extern BOOL bCompilingGlobal;1338 if(dwFlags&DIMFLAG_STATIC){1339 if(bCompilingGlobal){1340 SetError(60,NULL,cp);1341 return;1342 }1343 1344 /////////////////////1345 // Static変数1346 // ※"Static.Object.Method.Variable"1347 /////////////////////1348 1349 char temporary[VN_SIZE];1350 GetNowStaticVarFullName(VarName,temporary);1351 1352 dim( isRef,temporary,SubScripts,TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags );1353 1354 /*1355 Note: 静的変数のコンストラクタ呼び出しは1356 _System_InitStaticLocalVariables関数内で一括して行う1357 */1358 }1359 else{1360 dim( isRef,VarName,SubScripts,TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags );1361 }1362 }1363 void OpcodeDim(char *Parameter,DWORD dwFlags){1364 int i,i2,i3,IsStr=0;1365 char temporary[8192];1366 1367 for(i=0,i2=0;;i++,i2++){1368 if(Parameter[i]=='\"') IsStr^=1;1369 if(Parameter[i]=='('&&IsStr==0){1370 i3=GetStringInPare(temporary+i2,Parameter+i);1371 i+=i3-1;1372 i2+=i3-1;1373 continue;1374 }1375 if(Parameter[i]=='['&&IsStr==0){1376 i3=GetStringInBracket(temporary+i2,Parameter+i);1377 i+=i3-1;1378 i2+=i3-1;1379 continue;1380 }1381 if((Parameter[i]==','&&IsStr==0)||1382 Parameter[i]=='\0'){1383 temporary[i2]=0;1384 1385 dim(temporary,dwFlags);1386 1387 if(Parameter[i]=='\0') break;1388 i2=-1;1389 continue;1390 }1391 temporary[i2]=Parameter[i];1392 }1393 }1394 1395 1218 void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar){ 1396 1219 if(!IsGeneralReg(reg)) SetError(300,NULL,cp); -
BasicCompiler64/MakePeHdr.cpp
r73 r75 6 6 // 特殊関数の構造体ポインタ 7 7 //////////////////////////// 8 SubInfo 8 UserProc 9 9 *pSub_System_StartupProgram, 10 10 *pSub_DebugSys_StartProc, … … 136 136 137 137 //関数ポインタ情報を初期化 138 extern P ROCPTRINFO *pProcPtrInfo;138 extern ProcPointer **ppProcPointer; 139 139 extern int ProcPtrInfoNum; 140 p ProcPtrInfo=(PROCPTRINFO*)HeapAlloc(hHeap,0,1);140 ppProcPointer=(ProcPointer **)HeapAlloc(hHeap,0,1); 141 141 ProcPtrInfoNum=0; 142 142 … … 170 170 171 171 if(pSub_System_StartupProgram=GetSubHash("_System_StartupProgram",1)) 172 pSub_System_StartupProgram-> bUse=1;172 pSub_System_StartupProgram->Using(); 173 173 174 174 if(pSub_DebugSys_StartProc=GetSubHash("_DebugSys_StartProc",1)) 175 pSub_DebugSys_StartProc-> bUse=1;175 pSub_DebugSys_StartProc->Using(); 176 176 177 177 if(pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc",1)) 178 pSub_DebugSys_EndProc-> bUse=1;178 pSub_DebugSys_EndProc->Using(); 179 179 180 180 if(pSub_DebugSys_SaveContext=GetSubHash("_DebugSys_SaveContext",1)) 181 pSub_DebugSys_SaveContext-> bUse=1;181 pSub_DebugSys_SaveContext->Using(); 182 182 183 183 if(pSub_System_GetEip=GetSubHash("_System_GetEip",1)){ 184 pSub_System_GetEip-> bUse=1;185 pSub_System_GetEip-> bSystem=1;184 pSub_System_GetEip->Using(); 185 pSub_System_GetEip->ThisIsSystemProc(); 186 186 } 187 187 188 188 if(pSub_System_InitDllGlobalVariables=GetSubHash("_System_InitDllGlobalVariables",1)){ 189 pSub_System_InitDllGlobalVariables-> bUse=1;190 pSub_System_InitDllGlobalVariables-> bSystem=1;189 pSub_System_InitDllGlobalVariables->Using(); 190 pSub_System_InitDllGlobalVariables->ThisIsSystemProc(); 191 191 } 192 192 193 193 if(pSub_System_InitStaticLocalVariables=GetSubHash("_System_InitStaticLocalVariables",1)){ 194 pSub_System_InitStaticLocalVariables-> bUse=1;195 pSub_System_InitStaticLocalVariables-> bSystem=1;194 pSub_System_InitStaticLocalVariables->Using(); 195 pSub_System_InitStaticLocalVariables->ThisIsSystemProc(); 196 196 } 197 197 198 198 if(pSub_System_Call_Destructor_of_GlobalObject=GetSubHash("_System_Call_Destructor_of_GlobalObject",1)){ 199 pSub_System_Call_Destructor_of_GlobalObject-> bUse=1;200 pSub_System_Call_Destructor_of_GlobalObject-> bSystem=1;199 pSub_System_Call_Destructor_of_GlobalObject->Using(); 200 pSub_System_Call_Destructor_of_GlobalObject->ThisIsSystemProc(); 201 201 } 202 202 203 203 if(pSub_System_GetSp=GetSubHash("_System_GetSp",1)){ 204 pSub_System_GetSp-> bUse=1;205 pSub_System_GetSp-> bSystem=1;204 pSub_System_GetSp->Using(); 205 pSub_System_GetSp->ThisIsSystemProc(); 206 206 } 207 207 208 208 if(pSub_pow=GetSubHash("pow",1)) 209 pSub_pow-> bUse=1;209 pSub_pow->Using(); 210 210 211 211 if(pSub_calloc=GetSubHash("calloc",1)) 212 pSub_calloc-> bUse=1;212 pSub_calloc->Using(); 213 213 214 214 if(pSub_realloc=GetSubHash("realloc",1)) 215 pSub_realloc-> bUse=1;215 pSub_realloc->Using(); 216 216 217 217 if(pSub_free=GetSubHash("free",1)) 218 pSub_free-> bUse=1;218 pSub_free->Using(); 219 219 220 220 if( pSub_System_GC_malloc_ForObject = GetSubHash( "_System_GC_malloc_ForObject",1 ) ) 221 pSub_System_GC_malloc_ForObject-> bUse = 1;221 pSub_System_GC_malloc_ForObject->Using(); 222 222 223 223 if( pSub_System_GC_malloc_ForObjectPtr = GetSubHash( "_System_GC_malloc_ForObjectPtr",1 ) ) 224 pSub_System_GC_malloc_ForObjectPtr-> bUse = 1;224 pSub_System_GC_malloc_ForObjectPtr->Using(); 225 225 226 226 if( pSub_System_GC_free_for_SweepingDelete = GetSubHash( "_System_GC_free_for_SweepingDelete",1 ) ) 227 pSub_System_GC_free_for_SweepingDelete-> bUse = 1;227 pSub_System_GC_free_for_SweepingDelete->Using(); 228 228 229 229 … … 271 271 272 272 cp=-1; 273 extern BOOL bCompilingGlobal; 274 bCompilingGlobal=1; 273 UserProc::CompileStartForGlobalArea(); 275 274 276 275 if(!bDll){ … … 352 351 353 352 //call _System_Call_Destructor_of_GlobalObject 354 extern SubInfo*pSub_System_Call_Destructor_of_GlobalObject;353 extern UserProc *pSub_System_Call_Destructor_of_GlobalObject; 355 354 op_call(pSub_System_Call_Destructor_of_GlobalObject); 356 355 … … 405 404 ///////////////////// 406 405 407 bCompilingGlobal=0;408 409 406 //プロシージャをコンパイル開始 410 407 cp=0; … … 429 426 //////////////////////////////// 430 427 for(i=0;i<MAX_HASH;i++){ 431 extern DECLAREINFO **ppDeclareHash; 432 DECLAREINFO *pdi; 433 pdi=ppDeclareHash[i]; 434 while(pdi){ 435 if(pdi->bUse==0){ 436 pdi=pdi->pNextData; 428 extern DllProc **ppDeclareHash; 429 const DllProc *pDllProc = ppDeclareHash[i]; 430 while(pDllProc){ 431 if( !pDllProc->IsUsing() ){ 432 pDllProc=pDllProc->pNextData; 437 433 continue; 438 434 } … … 440 436 //エラーチェック 441 437 HINSTANCE hLib; 442 hLib=LoadLibrary( pdi->file);438 hLib=LoadLibrary( pDllProc->GetDllFileName().c_str() ); 443 439 if(!hLib){ 444 440 extern char OutputFileName[MAX_PATH]; … … 446 442 _splitpath(OutputFileName,temp2,temp3,NULL,NULL); 447 443 lstrcat(temp2,temp3); 448 lstrcpy(temp3,p di->file);444 lstrcpy(temp3,pDllProc->GetDllFileName().c_str()); 449 445 GetFullPath(temp3,temp2); 450 446 hLib=LoadLibrary(temp3); 451 447 452 448 if(!hLib){ 453 SetError(-106,p di->file,pdi->pos);449 SetError(-106,pDllProc->GetDllFileName().c_str(),pDllProc->GetCodePos()); 454 450 } 455 451 } 456 452 457 453 if(hLib){ 458 if(!GetProcAddress(hLib,p di->alias)){454 if(!GetProcAddress(hLib,pDllProc->GetAlias().c_str())){ 459 455 FreeLibrary(hLib); 460 SetError(-107,p di->alias,pdi->pos);456 SetError(-107,pDllProc->GetAlias(),pDllProc->GetCodePos()); 461 457 } 462 458 FreeLibrary(hLib); 463 459 } 464 460 465 p di=pdi->pNextData;461 pDllProc=pDllProc->pNextData; 466 462 } 467 463 } … … 500 496 ExportNamesLength=lstrlen(lpExportNames)+1; 501 497 502 extern SubInfo**ppSubHash;503 SubInfo *psi,*psi2;498 extern UserProc **ppSubHash; 499 UserProc *pUserProc,*psi2; 504 500 while(1){ 505 501 //辞書順にサーチ 506 502 temporary[0]=0; 507 503 for(i=0,psi2=0;i<MAX_HASH;i++){ 508 p si=ppSubHash[i];509 while(p si){510 if(p si->bExport){504 pUserProc=ppSubHash[i]; 505 while(pUserProc){ 506 if(pUserProc->IsExport()){ 511 507 if(temporary[0]=='\0'){ 512 lstrcpy(temporary,p si->name);513 psi2=p si;508 lstrcpy(temporary,pUserProc->GetName().c_str()); 509 psi2=pUserProc; 514 510 } 515 511 else{ 516 512 i3=lstrlen(temporary); 517 i4= lstrlen(psi->name);513 i4=(int)pUserProc->GetName().size(); 518 514 if(i3<i4) i3=i4; 519 if(memcmp(temporary,p si->name,i3)>0){520 lstrcpy(temporary,p si->name);521 psi2=p si;515 if(memcmp(temporary,pUserProc->GetName().c_str(),i3)>0){ 516 lstrcpy(temporary,pUserProc->GetName().c_str()); 517 psi2=pUserProc; 522 518 } 523 519 } 524 520 } 525 p si=psi->pNextData;521 pUserProc=pUserProc->pNextData; 526 522 } 527 523 } 528 524 if(psi2==0) break; 529 psi=psi2; 530 531 psi->bExport=0; 532 533 if(lstrcmpi(psi->name,"DllMain")==0) 534 DllMain_EntryPoint=psi->CompileAddress; 525 pUserProc=psi2; 526 527 pUserProc->ExportOff(); 528 529 if( pUserProc->GetName() == "DllMain" ){ 530 DllMain_EntryPoint=pUserProc->beginOpAddress; 531 } 535 532 536 533 lpdwExportAddressTable=(DWORD *)HeapReAlloc(hHeap,0,lpdwExportAddressTable,(ExportNum+1)*sizeof(DWORD)); 537 lpdwExportAddressTable[ExportNum]=p si->CompileAddress;534 lpdwExportAddressTable[ExportNum]=pUserProc->beginOpAddress; 538 535 539 536 lpdwExportNamePointerTable=(DWORD *)HeapReAlloc(hHeap,0,lpdwExportNamePointerTable,(ExportNum+1)*sizeof(DWORD)); … … 543 540 lpwExportOrdinalTable[ExportNum]=ExportNum; 544 541 545 lstrcpy(lpExportNames+ExportNamesLength,p si->name);542 lstrcpy(lpExportNames+ExportNamesLength,pUserProc->GetName().c_str()); 546 543 ExportNamesLength+=lstrlen(lpExportNames+ExportNamesLength)+1; 547 544 … … 576 573 //インポートDLL情報 577 574 ///////////////////// 578 extern D ECLAREINFO**ppDeclareHash;579 D ECLAREINFO *pdi;575 extern DllProc **ppDeclareHash; 576 DllProc *pDllProc; 580 577 char **ppDllNames; 581 578 int ImportDllNum; … … 613 610 ImportDllNum=0; 614 611 for(i=0;i<MAX_HASH;i++){ 615 pdi=ppDeclareHash[i]; 616 while(pdi){ 617 if(pdi->dwType==DECLARE_STATIC|| 618 pdi->bUse==0){ 619 pdi=pdi->pNextData; 612 const DllProc *pDllProc=ppDeclareHash[i]; 613 while(pDllProc){ 614 if( !pDllProc->IsUsing() ){ 615 pDllProc=pDllProc->pNextData; 620 616 continue; 621 617 } 622 618 623 if( lstrlen(pdi->file)>16){619 if( pDllProc->GetDllFileName().size() > 16 ){ 624 620 SetError(7,NULL,cp); 625 621 break; 626 622 } 627 623 for(i2=0;i2<ImportDllNum;i2++){ 628 if(lstrcmp(ppDllNames[i2],pdi->file)==0) break; 624 if( pDllProc->GetDllFileName() == ppDllNames[i2] ){ 625 break; 626 } 629 627 } 630 628 if(i2==ImportDllNum){ 631 629 ppDllNames=(char **)HeapReAlloc(hHeap,0,ppDllNames,(ImportDllNum+1)*sizeof(char **)); 632 630 ppDllNames[ImportDllNum]=(char *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,16); 633 lstrcpy(ppDllNames[ImportDllNum],p di->file);631 lstrcpy(ppDllNames[ImportDllNum],pDllProc->GetDllFileName().c_str()); 634 632 ImportDllNum++; 635 633 } 636 634 637 p di=pdi->pNextData;635 pDllProc=pDllProc->pNextData; 638 636 } 639 637 } … … 651 649 pImportDescriptor[i].Name=i*0x10; //※すぐ下で再計算 652 650 for(i2=0;i2<MAX_HASH;i2++){ 653 pdi=ppDeclareHash[i2]; 654 while(pdi){ 655 if(pdi->dwType==DECLARE_STATIC|| 656 pdi->bUse==0){ 657 pdi=pdi->pNextData; 651 pDllProc=ppDeclareHash[i2]; 652 while(pDllProc){ 653 if( !pDllProc->IsUsing() ){ 654 pDllProc=pDllProc->pNextData; 658 655 continue; 659 656 } 660 657 661 if( lstrcmp(ppDllNames[i],pdi->file)==0){658 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 662 659 //ルックアップデータのサイズを追加 663 660 LookupSize+=sizeof(_int64); 664 661 } 665 662 666 p di=pdi->pNextData;663 pDllProc=pDllProc->pNextData; 667 664 } 668 665 } … … 691 688 for(i=0,i5=0;i<ImportDllNum;i++){ 692 689 for(i2=0;i2<MAX_HASH;i2++){ 693 pdi=ppDeclareHash[i2]; 694 while(pdi){ 695 if(pdi->dwType==DECLARE_STATIC|| 696 pdi->bUse==0){ 697 pdi=pdi->pNextData; 690 pDllProc=ppDeclareHash[i2]; 691 while(pDllProc){ 692 if( !pDllProc->IsUsing() ){ 693 pDllProc=pDllProc->pNextData; 698 694 continue; 699 695 } 700 696 701 if( lstrcmp(ppDllNames[i],pdi->file)==0){697 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 702 698 //ルックアップの位置をセット(後にインポート アドレス テーブルにセットしなおされる) 703 p di->LookupAddress=i5*sizeof(_int64);699 pDllProc->SetLookupAddress( i5*sizeof(_int64) ); 704 700 705 701 //ルックアップ テーブルの値をセット … … 714 710 pHintTable[HintSize++]=0; 715 711 pHintTable[HintSize++]=0; 716 lstrcpy(pHintTable+HintSize,p di->alias);717 i4= lstrlen(pdi->alias);712 lstrcpy(pHintTable+HintSize,pDllProc->GetAlias().c_str()); 713 i4=(int)pDllProc->GetAlias().size(); 718 714 HintSize+=i4+1; 719 715 if(i4%2==0) pHintTable[HintSize++]=0; … … 725 721 } 726 722 727 p di=pdi->pNextData;723 pDllProc=pDllProc->pNextData; 728 724 } 729 725 } … … 742 738 //グローバル変数情報を扱う構造体も初期バッファの有無による配置を行う 743 739 //(デバッグ情報で利用される) 744 extern int MaxGlobalVarNum;745 extern VARIABLE *GlobalVar;746 740 extern int AllInitGlobalVarSize; 747 for (i=0;i<MaxGlobalVarNum;i++){748 if( GlobalVar[i].offset&0x80000000){749 GlobalVar[i].offset=(GlobalVar[i].offset&0x7FFFFFFF)+AllInitGlobalVarSize;741 foreach( Variable *pVar, globalVars ){ 742 if(pVar->offset&0x80000000){ 743 pVar->offset=(pVar->offset&0x7FFFFFFF)+AllInitGlobalVarSize; 750 744 } 751 745 } … … 997 991 998 992 for(i2=0;i2<MAX_HASH;i2++){ 999 pdi=ppDeclareHash[i2];1000 while(p di){1001 if( pdi->bUse==0){1002 p di=pdi->pNextData;993 const DllProc *pDllProc=ppDeclareHash[i2]; 994 while(pDllProc){ 995 if( !pDllProc->IsUsing() ){ 996 pDllProc=pDllProc->pNextData; 1003 997 continue; 1004 998 } 1005 999 1006 if( lstrcmp(ppDllNames[i],pdi->file)==0){1000 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 1007 1001 //ルックアップ テーブル 1008 1002 pLookupTable[i5++]+=MemPos_ImportSection; 1009 1003 } 1010 1004 1011 p di=pdi->pNextData;1005 pDllProc=pDllProc->pNextData; 1012 1006 } 1013 1007 } … … 1033 1027 // ※x86はRVAからのオフセット。x64はRPI(実行中アドレス)からのオフセット 1034 1028 for(i=0;i<pobj_ImportAddrSchedule->num;i++){ 1035 D ECLAREINFO *pdi;1036 p di=pobj_ImportAddrSchedule->ppdi[i];1029 DllProc *pDllProc; 1030 pDllProc=pobj_ImportAddrSchedule->ppdi[i]; 1037 1031 *((long *)(OpBuffer+pobj_ImportAddrSchedule->pObpValues[i]))= 1038 1032 MemPos_ImportSection+ 1039 p di->LookupAddress1033 pDllProc->GetLookupAddress() 1040 1034 -(MemPos_CodeSection+pobj_ImportAddrSchedule->pObpValues[i]+sizeof(long)); 1041 1035 } … … 1046 1040 // プロシージャポインタスケジュール 1047 1041 for(i=0;i<pobj_SubAddrSchedule->num;i++){ 1048 if(pobj_SubAddrSchedule->ppsi[i]-> CompileAddress==01049 &&pobj_SubAddrSchedule->ppsi[i]-> EndOpAddr==0){1042 if(pobj_SubAddrSchedule->ppsi[i]->beginOpAddress==0 1043 &&pobj_SubAddrSchedule->ppsi[i]->endOpAddress==0){ 1050 1044 SetError(300,NULL,-1); 1051 1045 } … … 1053 1047 if(pobj_SubAddrSchedule->pbCall[i]){ 1054 1048 *((long *)(OpBuffer+pobj_SubAddrSchedule->pObpValues[i]))= 1055 pobj_SubAddrSchedule->ppsi[i]-> CompileAddress-(pobj_SubAddrSchedule->pObpValues[i]+sizeof(long));1049 pobj_SubAddrSchedule->ppsi[i]->beginOpAddress-(pobj_SubAddrSchedule->pObpValues[i]+sizeof(long)); 1056 1050 } 1057 1051 else{ 1058 1052 *((long *)(OpBuffer+pobj_SubAddrSchedule->pObpValues[i]))= 1059 pobj_SubAddrSchedule->ppsi[i]-> CompileAddress+ImageBase+MemPos_CodeSection;1053 pobj_SubAddrSchedule->ppsi[i]->beginOpAddress+ImageBase+MemPos_CodeSection; 1060 1054 } 1061 1055 } … … 1098 1092 //グローバル変数情報を扱う構造体も初期バッファの有無による配置を行う 1099 1093 //(デバッグ情報で利用される) 1100 extern int MaxGlobalVarNum; 1101 extern VARIABLE *GlobalVar; 1102 for(i=0;i<MaxGlobalVarNum;i++){ 1103 if(GlobalVar[i].offset&0x80000000){ 1104 GlobalVar[i].offset=(GlobalVar[i].offset&0x7FFFFFFF)+AllInitGlobalVarSize; 1094 foreach( Variable *pVar, globalVars ){ 1095 if(pVar->offset&0x80000000){ 1096 pVar->offset=(pVar->offset&0x7FFFFFFF)+AllInitGlobalVarSize; 1105 1097 } 1106 1098 } -
BasicCompiler64/NumOpe.cpp
r69 r75 19 19 20 20 extern CClass *pobj_StringClass; 21 TYPEINFO baseTypeInfo = { DEF_OBJECT, (LONG_PTR)pobj_StringClass }; 22 Operator_New( *pobj_StringClass, "", parameter, baseTypeInfo ); 21 Operator_New( *pobj_StringClass, "", parameter, Type( DEF_OBJECT, *pobj_StringClass ) ); 23 22 24 23 free( parameter ); … … 70 69 } 71 70 72 int NumOpe(int *pReg,const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap){ 73 extern HANDLE hHeap; 71 void ExtendRegToBigType( int reg, int bigBasicType, int baseBasicType ){ 72 switch( Type::GetBasicSize( bigBasicType ) ){ 73 case sizeof(_int64): 74 ExtendTypeTo64(baseBasicType,reg); 75 break; 76 case sizeof(long): 77 ExtendTypeTo32(baseBasicType,reg); 78 break; 79 case sizeof(short): 80 ExtendTypeTo16(baseBasicType,reg); 81 break; 82 } 83 } 84 85 bool NumOpe( int *pReg, 86 const char *expression, 87 const Type &baseType, 88 Type &resultType, 89 BOOL *pbUseHeap ){ 90 74 91 int i,i2,i3,i4; 75 92 char temporary[1024],temp2[1024],temp3[1024]; 76 93 77 if( Command[0]=='\0'){94 if(expression[0]=='\0'){ 78 95 SetError(1,NULL,cp); 79 return 0;80 } 81 82 if( Command[0]==1&& Command[1]==ESC_NEW ){96 return false; 97 } 98 99 if(expression[0]==1&& expression[1]==ESC_NEW ){ 83 100 //New演算子(オブジェクト生成) 84 TYPEINFO baseTypeInfo = { BaseType, lpBaseIndex }; 85 int resultType = Operator_New(Command+2,plpIndex, baseTypeInfo ); 101 102 if( !Operator_New( expression+2, baseType, resultType ) ){ 103 return false; 104 } 86 105 87 106 //mov reg,rax 88 107 op_mov_RR( *pReg, REG_RAX ); 89 108 90 return resultType;109 return true; 91 110 } 92 111 … … 100 119 long stack[255]; 101 120 int pnum; 102 if(!GetNumOpeElements( Command,&pnum,values,calc,stack)){121 if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){ 103 122 for(i=0;i<pnum;i++){ 104 123 if(values[i]) HeapDefaultFree(values[i]); … … 156 175 double dbl; 157 176 int sp; 158 int type [255];177 int type_stack[255]; 159 178 LONG_PTR index_stack[255]; 160 179 BOOL bUseHeap[255]; … … 167 186 168 187 if(idCalc){ 169 if(type [sp-2]==DEF_OBJECT){188 if(type_stack[sp-2]==DEF_OBJECT){ 170 189 //オーバーロードされたオペレータを呼び出す 171 TYPEINFO BaseTypeInfo={BaseType,lpBaseIndex}; 172 i2=CallOperatorProc(idCalc,&BaseTypeInfo,type,index_stack,bUseHeap,sp); 190 i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,bUseHeap,sp); 173 191 if(i2==0){ 174 192 if(idCalc==CALC_EQUAL) lstrcpy(temp2,"=="); … … 183 201 } 184 202 185 if(!CheckCalcType(idCalc,type ,sp)) goto error;203 if(!CheckCalcType(idCalc,type_stack,sp)) goto error; 186 204 } 187 205 … … 209 227 StrLiteral: 210 228 211 if(BaseType==DEF_OBJECT){ 212 CClass *pobj_Class; 213 pobj_Class=(CClass *)lpBaseIndex; 214 TYPEINFO BaseTypeInfo = {BaseType,lpBaseIndex}; 215 if(IsStringObjectType(BaseTypeInfo)){ 229 if( baseType.IsObject() ){ 230 if( baseType.IsStringObject() ){ 216 231 //要求タイプがStringのとき 217 232 … … 220 235 221 236 extern CClass *pobj_StringClass; 222 type [sp]=DEF_OBJECT;237 type_stack[sp]=DEF_OBJECT; 223 238 index_stack[sp]=(LONG_PTR)pobj_StringClass; 224 239 bLiteralCalculation=0; … … 232 247 } 233 248 234 type [sp]=typeOfPtrChar;249 type_stack[sp]=typeOfPtrChar; 235 250 bLiteralCalculation=0; 236 251 … … 277 292 int idProc; 278 293 void *pInfo; 279 idProc=GetProc(temporary,&pInfo); 280 294 idProc=GetProc(temporary,(void **)&pInfo); 295 296 Type resultType; 281 297 if(idProc){ 282 298 //閉じカッコ")"に続く文字がNULLでないとき … … 302 318 //////////////// 303 319 304 i2=CallProc(idProc,pInfo,temporary,temp2,&index_stack[sp]);305 if( i2==-1){320 CallProc(idProc,pInfo,temporary,temp2,resultType); 321 if(resultType.IsNull()){ 306 322 //戻り値が存在しないとき 307 323 for(i2=2;;i2++){ … … 325 341 326 342 //大きな型への暗黙の変換 327 type[sp]=AutoBigCast(BaseType,i2); 343 type_stack[sp]=AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType()); 344 index_stack[sp] = resultType.GetIndex(); 328 345 bLiteralCalculation=0; 329 346 330 SetUseRegFromRax(i2,UseReg,XmmReg); 331 332 if(IsRealNumberType(i2)) bXmm=1; 347 if( type_stack[sp] != resultType.GetBasicType() ){ 348 // 大きな型へ変換された場合 349 // ※レジスタの値をキャストする 350 ExtendRegToBigType( REG_RAX, type_stack[sp], resultType.GetBasicType() ); 351 } 352 353 SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg); 354 355 if(resultType.IsReal()) bXmm=1; 333 356 else bXmm=0; 334 357 … … 342 365 else pobj_reg->LockReg(); 343 366 344 if( i2==DEF_STRUCT){367 if(resultType.IsStruct()){ 345 368 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 346 369 //※後にfreeする必要あり … … 360 383 361 384 //マクロ関数の場合 362 i2=NumOpe(&UseReg,temp3,0,0,&index_stack[sp]);363 364 if(!IS_LITERAL( index_stack[sp])){385 NumOpe(&UseReg,temp3,Type(),resultType); 386 387 if(!IS_LITERAL(resultType.GetIndex())){ 365 388 //リテラル値ではなかったとき 366 389 bLiteralCalculation=0; 367 390 } 368 391 369 type[sp]=i2; 370 371 if(IsRealNumberType(i2)) pobj_reg->LockXmmReg(); 392 type_stack[sp] = resultType.GetBasicType(); 393 index_stack[sp] = resultType.GetIndex(); 394 395 if(resultType.IsReal()) pobj_reg->LockXmmReg(); 372 396 else pobj_reg->LockReg(); 373 397 … … 381 405 //インデクサ(getアクセサ) 382 406 char variable[VN_SIZE],array_element[VN_SIZE]; 383 CClass *pobj_c;384 407 GetArrayElement(term,variable,array_element); 385 408 if(array_element[0]){ 386 i2=GetVarType(variable,(LONG_PTR *)&pobj_c,0);387 if(i2==DEF_OBJECT){388 TYPEINFO RetTypeInfo;389 CallIndexerGetterProc(UseReg, pobj_c,variable,array_element,RetTypeInfo);390 type [sp]=RetTypeInfo.type;391 index_stack[sp]= RetTypeInfo.u.lpIndex;409 Type resultType; 410 GetVarType(variable,resultType,0); 411 if( resultType.IsObject() ){ 412 CallIndexerGetterProc(UseReg,&resultType.GetClass(),variable,array_element,resultType); 413 type_stack[sp]=resultType.GetBasicType(); 414 index_stack[sp]=resultType.GetIndex(); 392 415 bLiteralCalculation=0; 393 416 394 if( IsRealNumberType(RetTypeInfo.type)) pobj_reg->LockXmmReg();417 if(resultType.IsReal()) pobj_reg->LockXmmReg(); 395 418 else pobj_reg->LockReg(); 396 419 sp++; … … 402 425 // Nothing 403 426 if( lstrcmp( term, "Nothing" ) == 0 ){ 404 type [sp] = DEF_OBJECT;405 if( BaseType == DEF_OBJECT){406 index_stack[sp] = lpBaseIndex;427 type_stack[sp] = DEF_OBJECT; 428 if( baseType.IsObject() ){ 429 index_stack[sp] = baseType.GetIndex(); 407 430 } 408 431 else{ … … 427 450 428 451 RELATIVE_VAR RelativeVar; 452 Type varType; 429 453 if(GetVarOffset( 430 454 false, //エラー表示あり 431 455 false, //読み込み専用 432 456 term, 433 & i2,&RelativeVar,&index_stack[sp])){457 &RelativeVar,varType)){ 434 458 ////////// 435 459 // 変数 … … 437 461 438 462 //大きな型への暗黙の変換 439 type[sp]=AutoBigCast(BaseType,i2); 463 type_stack[sp]=AutoBigCast(baseType.GetBasicType(),varType.GetBasicType()); 464 index_stack[sp] = varType.GetIndex(); 440 465 bLiteralCalculation=0; 441 466 442 if(type[sp]!=i2){ 443 //大きな型へ変換された場合(レジスタを0に初期化する) 444 445 //xor reg,reg 446 op_zero_reg(UseReg); 447 } 448 449 if(i2&FLAG_PTR){ 467 if(varType.GetBasicType()&FLAG_PTR){ 450 468 //配列ポインタ 451 type [sp]=GetPtrType(i2^FLAG_PTR,index_stack[sp]);469 type_stack[sp]=GetPtrType(varType.GetBasicType()^FLAG_PTR); 452 470 453 471 SetVarPtrToReg(UseReg,&RelativeVar); 454 472 } 455 else if( IsRealNumberType(i2)){473 else if(varType.IsReal()){ 456 474 //実数型 457 475 bXmm=1; 458 476 459 if( i2==DEF_DOUBLE)477 if( varType.IsDouble() ) 460 478 SetXmmReg_DoubleVariable(&RelativeVar,XmmReg); 461 if( i2==DEF_SINGLE)479 if( varType.IsSingle() ) 462 480 SetXmmReg_SingleVariable(&RelativeVar,XmmReg); 463 481 } 464 else if( IsWholeNumberType(i2) || i2==DEF_OBJECT){482 else if( varType.IsWhole() || varType.IsObject()){ 465 483 //整数型 466 SetReg_WholeVariable( i2,&RelativeVar,UseReg);467 } 468 else if( i2==DEF_STRUCT){484 SetReg_WholeVariable(varType.GetBasicType(),&RelativeVar,UseReg); 485 } 486 else if( varType.IsStruct() ){ 469 487 //構造体ポインタをUseRegへ格納(構造体は値型) 470 488 SetVarPtrToReg(UseReg,&RelativeVar); 471 489 } 472 490 else SetError(11,term,cp); 491 492 if( type_stack[sp] != varType.GetBasicType() ){ 493 // 大きな型へ変換された場合 494 // ※レジスタの値をキャストする 495 ExtendRegToBigType( UseReg, type_stack[sp], varType.GetBasicType() ); 496 } 473 497 474 498 if(bXmm==0&&UseReg==REG_R14){ … … 477 501 } 478 502 if(bXmm&&XmmReg==REG_XMM4){ 479 if( i2==DEF_DOUBLE){503 if(varType.IsDouble()){ 480 504 //movsd qword ptr[rsp+offset],xmm4 ※スタックフレームを利用 481 505 pobj_sf->push(REG_XMM4,sizeof(double)); 482 506 } 483 if( i2==DEF_SINGLE){507 if(varType.IsSingle()){ 484 508 //movss dword ptr[rsp+offset],xmm4 ※スタックフレームを利用 485 509 pobj_sf->push(REG_XMM4,sizeof(float)); … … 500 524 i3 = CDBConst::obj.GetType(term); 501 525 if(i3){ 502 type [sp] = i3;526 type_stack[sp] = i3; 503 527 if(IsRealNumberType(i3)){ 504 528 //実数 … … 536 560 i3=GetTypeFixed(term,&lp); 537 561 if(i3!=-1){ 538 type [sp]=i3|FLAG_CAST;562 type_stack[sp]=i3|FLAG_CAST; 539 563 index_stack[sp]=lp; 540 564 sp++; … … 559 583 ////////////////////////////////////////////////////// 560 584 561 T YPEINFO RetTypeInfo;562 CallPropertyMethod(term,NULL, &RetTypeInfo);585 Type resultType; 586 CallPropertyMethod(term,NULL,resultType); 563 587 564 588 //大きな型への暗黙の変換 565 type[sp]=AutoBigCast(BaseType,RetTypeInfo.type); 566 567 index_stack[sp]=RetTypeInfo.u.lpIndex; 589 type_stack[sp]=AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType()); 590 index_stack[sp]=resultType.GetIndex(); 568 591 bLiteralCalculation=0; 569 592 570 SetUseRegFromRax(RetTypeInfo.type,UseReg,XmmReg); 571 572 if(IsRealNumberType(type[sp])) bXmm=1; 593 if( type_stack[sp] != resultType.GetBasicType() ){ 594 // 大きな型へ変換された場合 595 // ※レジスタの値をキャストする 596 ExtendRegToBigType( REG_RAX, type_stack[sp], resultType.GetBasicType() ); 597 } 598 599 SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg); 600 601 if(IsRealNumberType(type_stack[sp])) bXmm=1; 573 602 else bXmm=0; 574 603 … … 578 607 }//////////////////////////////////////////// 579 608 580 if(type [sp]==DEF_STRUCT){609 if(type_stack[sp]==DEF_STRUCT){ 581 610 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 582 611 //※後にfreeする必要あり … … 595 624 bError=1; 596 625 SetError(3,term,cp); 597 type [sp]=DEF_DOUBLE;626 type_stack[sp]=DEF_DOUBLE; 598 627 } 599 628 else{ 600 629 //リテラル値 601 type [sp]=GetLiteralValue(term,&i64data,BaseType);630 type_stack[sp]=GetLiteralValue(term,&i64data,baseType.GetBasicType()); 602 631 Literal: 603 if(type [sp]==DEF_DOUBLE){632 if(type_stack[sp]==DEF_DOUBLE){ 604 633 //64ビット浮動小数型 605 634 bXmm=1; … … 627 656 } 628 657 } 629 else if(type [sp]==DEF_SINGLE){658 else if(type_stack[sp]==DEF_SINGLE){ 630 659 //32ビット浮動小数型 631 660 bXmm=1; … … 680 709 case CALC_OR: 681 710 case CALC_AND: 682 if(!CalcTwoTerm_Logical(idCalc,type ,index_stack,&sp)) goto error;711 if(!CalcTwoTerm_Logical(idCalc,type_stack,index_stack,&sp)) goto error; 683 712 break; 684 713 case CALC_NOT: 685 714 //value[sp-1]=Not value[sp-1] 686 715 //NOT演算子 687 if(!Calc_Not(type ,sp)) goto error;716 if(!Calc_Not(type_stack,sp)) goto error; 688 717 break; 689 718 … … 695 724 case CALC_NOTEQUAL: //value[sp-2] <> value[sp-1] 696 725 case CALC_EQUAL: //value[sp-2] = value[sp-1] 697 if(!CalcTwoTerm_Relational(idCalc,type ,index_stack,&sp)) goto error;726 if(!CalcTwoTerm_Relational(idCalc,type_stack,index_stack,&sp)) goto error; 698 727 break; 699 728 … … 701 730 case CALC_SHL: //value[sp-2] << value[sp-1] 702 731 case CALC_SHR: //value[sp-2] >> value[sp-1] 703 if(!Calc_Shift(idCalc,type ,&sp)) goto error;732 if(!Calc_Shift(idCalc,type_stack,&sp)) goto error; 704 733 break; 705 734 … … 708 737 case CALC_SUBTRACTION: 709 738 case CALC_PRODUCT: 710 if(!CalcTwoTerm_Arithmetic(idCalc,type ,index_stack,&sp)) goto error;739 if(!CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp)) goto error; 711 740 break; 712 741 case CALC_MOD: 713 742 //value[sp-2]%=value[sp-1] 714 743 //剰余演算 715 if(!Calc_Mod(type ,index_stack,&sp)) goto error;744 if(!Calc_Mod(type_stack,index_stack,&sp)) goto error; 716 745 break; 717 746 case CALC_QUOTIENT: 718 747 //value[sp-2]/=value[sp-1]; 719 748 //除算 720 if(!Calc_Divide(type ,&sp,BaseType)) goto error;749 if(!Calc_Divide(type_stack,&sp,baseType.GetBasicType())) goto error; 721 750 break; 722 751 case CALC_INTQUOTIENT: 723 752 //value[sp-2]/=value[sp-1] 724 753 //整数除算 725 if(!Calc_IntDivide(type ,index_stack,&sp)) goto error;754 if(!Calc_IntDivide(type_stack,index_stack,&sp)) goto error; 726 755 break; 727 756 case CALC_MINUSMARK: 728 757 //value[sp-1]=-value[sp-1] 729 758 //符号反転 730 if(!Calc_MinusMark(type ,sp)) goto error;759 if(!Calc_MinusMark(type_stack,sp)) goto error; 731 760 break; 732 761 case CALC_POWER: 733 762 //べき乗演算(浮動小数点演算のみ) 734 if(!Calc_Power(type ,&sp)) goto error;763 if(!Calc_Power(type_stack,&sp)) goto error; 735 764 break; 736 765 case CALC_AS: 737 766 //キャスト 738 if(!Calc_Cast(type ,index_stack,&sp)) goto error;767 if(!Calc_Cast(type_stack,index_stack,&sp)) goto error; 739 768 break; 740 769 case CALC_BYVAL: 741 770 //ポインタ型→参照型 742 if( PTR_LEVEL( type [sp-1] ) <= 0 ){771 if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){ 743 772 //ポインタ型ではないとき 744 773 SetError( 3, NULL, cp ); … … 746 775 } 747 776 748 type [sp-1] = PTR_LEVEL_DOWN( type[sp-1] );777 type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] ); 749 778 750 779 break; … … 765 794 if(bLiteralCalculation){ 766 795 //右辺値が数値の定数式の場合 767 LONG_PTR lpClassIndex;768 i2=StaticCalculation(true, Command,BaseType,&i64data,&lpClassIndex);796 Type resultType; 797 StaticCalculation(true, expression,baseType.GetBasicType(),&i64data,resultType); 769 798 770 799 obp=BeforeObp; … … 775 804 *pobj_reg=objReg_Backup; 776 805 777 if( IsRealNumberType(i2)){778 if( IsRealNumberType(BaseType)) i2=BaseType;806 if(resultType.IsReal()){ 807 if(baseType.IsReal()) resultType=baseType; 779 808 780 809 XmmReg=pobj_reg->LockXmmReg(); 781 810 782 if( i2==DEF_DOUBLE){811 if(resultType.IsDouble()){ 783 812 i3 = dataTable.Add( i64data ); 784 813 … … 793 822 obp+=sizeof(long); 794 823 } 795 if( i2==DEF_SINGLE){824 if(resultType.IsSingle()){ 796 825 memcpy(&dbl,&i64data,sizeof(_int64)); 797 826 … … 815 844 } 816 845 else{ 817 if(! Is64Type(i2)){846 if(!resultType.Is64()){ 818 847 //整数(符号有り/無し) 819 848 820 849 i3=(long)i64data; 821 850 822 if( GetTypeSize(i2,-1)==sizeof(char)) i3=i3&0x000000FF;823 if( GetTypeSize(i2,-1)==sizeof(short)) i3=i3&0x0000FFFF;851 if(resultType.GetBasicSize()==sizeof(char)) i3=i3&0x000000FF; 852 if(resultType.GetBasicSize()==sizeof(short)) i3=i3&0x0000FFFF; 824 853 825 854 i64data=(_int64)i3; … … 832 861 } 833 862 834 type [0]=i2;835 index_stack[0]= lpClassIndex;863 type_stack[0]=resultType.GetBasicType(); 864 index_stack[0]=resultType.GetIndex(); 836 865 } 837 866 else{ … … 840 869 } 841 870 842 if(plpIndex) *plpIndex=index_stack[0];843 871 if(pbUseHeap) *pbUseHeap=bUseHeap[0]; 844 872 845 if(IsRealNumberType(type [0]))873 if(IsRealNumberType(type_stack[0])) 846 874 *pReg=pobj_reg->UnlockXmmReg(); 847 875 else … … 858 886 } 859 887 860 int RetType; 861 RetType=type[0]; 888 resultType.SetType( type_stack[0], index_stack[0] ); 889 890 bool isSuccessful = true; 862 891 goto finish; 863 892 … … 878 907 } 879 908 880 RetType=-1;909 isSuccessful = false; 881 910 goto finish; 882 911 … … 893 922 delete pobj_BackReloc; 894 923 895 return RetType;924 return isSuccessful; 896 925 } -
BasicCompiler64/NumOpe_Arithmetic.cpp
r73 r75 559 559 560 560 //call pow 561 extern SubInfo*pSub_pow;561 extern UserProc *pSub_pow; 562 562 op_call(pSub_pow); 563 563 -
BasicCompiler64/Opcode.h
r73 r75 251 251 252 252 //NumOpe.cpp 253 int NumOpe(int *pReg,const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap=0); 253 bool NumOpe( int *pReg, 254 const char *Command, 255 const Type &baseType, 256 Type &resultType, 257 BOOL *pbUseHeap = NULL ); 254 258 255 259 //NumOpe_Arithmetic.cpp … … 286 290 //Compile_Set_Var.cpp 287 291 BOOL IsUse_r11(RELATIVE_VAR *pRelativeVar); 288 void SetStructVariableFromRax( LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,RELATIVE_VAR *pRelativeVar,BOOL bUseHeap);292 void SetStructVariableFromRax( const Type &varType, const Type &calcType, RELATIVE_VAR *pRelativeVar,BOOL bUseHeap); 289 293 void SetRealVariable(int VarType, int CalcType, RELATIVE_VAR *pRelativeVar); 290 294 void SetBooleanVariable(int type,RELATIVE_VAR *pRelative); … … 307 311 308 312 //Compile_Object.cpp 309 void Operator_New( CClass &classObj, const char *objectSizeStr, const char *parameter,const TYPEINFO &baseTypeInfo ); 310 int Operator_New(const char *Parameter,LONG_PTR *plpIndex,const TYPEINFO &baseTypeInfo ); 313 void Operator_New( const CClass &classObj, const char *objectSizeStr, const char *parameter,const Type &baseTypeInfo ); 311 314 void OpcodeDelete(const char *Parameter, bool isSweeping); 312 315 … … 314 317 void GetWithName(char *buffer); 315 318 void SetThisPtrToReg(int reg); 316 BOOL GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);317 BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf);319 bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType,int *pss = NULL); 320 bool SetInitGlobalData(int offset,const Type &type,const int *SubScripts,char *InitBuf); 318 321 #define DIMFLAG_INITDEBUGVAR 0x01 319 322 #define DIMFLAG_NONCALL_CONSTRACTOR 0x02 320 323 #define DIMFLAG_STATIC 0x04 321 324 #define DIMFLAG_CONST 0x08 322 void dim(bool isRef, char *VarName,int *SubScripts,TYPEINFO &TypeInfo,int TypeSize,char *InitBuf,char *ConstractParameter,DWORD dwFlags); 323 void OpcodeDim(char *Parameter,DWORD dwFlag); 325 void dim(bool isRef, char *VarName,int *SubScripts,Type &type,char *InitBuf,char *ConstractParameter,DWORD dwFlags); 324 326 void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar); 325 327 … … 333 335 class ParamImpl{ 334 336 char *Parms[255]; 335 TYPEINFO types[255];337 vector<Type> types; 336 338 int ParmsNum; 337 339 338 T YPEINFO ReturnTypeInfo;340 Type returnType; 339 341 340 342 //一時オブジェクト管理用 … … 345 347 public: 346 348 ParamImpl(const char *buffer); 347 ParamImpl(const P ARAMETER_INFO *pParamInfo, const int ParmNum);349 ParamImpl(const Parameters ¶ms); 348 350 ~ParamImpl(); 349 void SetReturnType( TYPEINFO *pTypeInfo);351 void SetReturnType( const Type &returnType ); 350 352 351 353 private: 352 BOOL _overload_check( Parameters ¶ms, TYPEINFO *pReturnTypeInfo,int overload_level);353 SubInfo *OverloadSolutionWithReturnType( const char *name, std::vector<SubInfo*> &subs );354 bool _overload_check( int level, const Parameters ¶ms, const Type &returnType ); 355 UserProc *OverloadSolutionWithReturnType( const char *name, std::vector<UserProc *> &subs ); 354 356 public: 355 SubInfo *OverloadSolution( const char *name, std::vector<SubInfo *> &subs ); 356 357 BOOL ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum); 358 void MacroParameterSupport(PARAMETER_INFO *ppi); 359 void SetStructParameter(int reg,CClass *pobj_Class,LPSTR Parameter); 357 UserProc *OverloadSolution( const char *name, std::vector<UserProc *> &subs ); 358 359 bool ErrorCheck( const string &procName, const Parameters ¶ms, int SecondParmNum = -1 ); 360 void MacroParameterSupport( const Parameters ¶ms ); 361 void SetStructParameter( int reg, const Type &baseType, const char *expression ); 362 void SetParameter( const string &procName, const Parameters ¶ms, int SecondParmNum = -1 ); 360 363 361 364 //一時オブジェクトパラメータの生成と破棄 362 int NewTempParameters( const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);365 int NewTempParameters( const string &procName, const Parameters ¶ms, int SecondParmNum = -1 ); 363 366 void DeleteTempParameters(); 364 365 void SetParameter(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);366 367 367 368 void BackupParameter(int pi_num); … … 384 385 void AddLocalVarAddrSchedule(); 385 386 #define PROCFLAG_NEW 1 386 int Opcode_CallProcPtr(char *variable,char *Parameter,PROCPTRINFO *pi,LONG_PTR *plpIndex);387 void Opcode_CallProc(const char *Parameter,SubInfo *psi,DWORD dwFlags,char *ObjectName,int RefType);388 int Opcode_CallDllProc(char *Parameter,DECLAREINFO *pdi,LONG_PTR *plpIndex);387 bool Opcode_CallProcPtr(const char *variable, const char *lpszParms,ProcPointer *pProcPointer); 388 bool Opcode_CallProc(const char *Parameter,UserProc *pUserProc,DWORD dwFlags,const char *ObjectName,int RefType); 389 bool Opcode_CallDllProc( const char *lpszParms,DllProc *pDllProc); 389 390 390 391 //Compile_ProcOp.cpp … … 394 395 int GetFunctionType(int FuncNum); 395 396 int GetFunctionFromName(char *FuncName); 396 void Opcode_CallFunc( const char *Parameter, const int FuncNum, TYPEINFO &ReturnTypeInfo);397 bool Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &ReturnTypeInfo, bool isCallOn = true ); 397 398 398 399 //OperatorProc.cpp 399 void FreeTempObject(int reg, CClass *pobj_c);400 int CallOperatorProc(int idCalc, TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);401 void CallCastOperatorProc(int reg, int &CalcType,LONG_PTR &lpCalcIndex,BOOL bCalcUseHeap,int ToType,LONG_PTR lpToIndex);402 void CallIndexerGetterProc(int reg, CClass *pobj_Class,char *ObjectName,char *Parameter,TYPEINFO &RetTypeInfo);400 void FreeTempObject(int reg,const CClass *pobj_c); 401 int CallOperatorProc(int idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp); 402 void CallCastOperatorProc(int reg,Type &calcType,BOOL bCalcUseHeap,const Type &toType); 403 void CallIndexerGetterProc(int reg,const CClass *pobj_Class,char *ObjectName,char *Parameter,Type &resultType); 403 404 404 405 //Compile_Statement.cpp … … 411 412 void OpcodeContinue(void); 412 413 void OpcodeExitSub(void); 413 void OpcodeSelect( char *Parameter);414 void OpcodeSelect( const char *Parameter ); 414 415 void OpcodeCase(char *Parameter); 415 416 void OpcodeGosub(char *Parameter); … … 512 513 void op_fld_ptr_esp(int type); 513 514 void op_zero_reg(int reg); 514 void op_call( SubInfo *psi);515 void op_call( D ECLAREINFO *pdi);515 void op_call( UserProc *pUserProc ); 516 void op_call( DllProc *pDllProc ); -
BasicCompiler64/OperatorProc.cpp
r73 r75 2 2 #include "Opcode.h" 3 3 4 void FreeTempObject(int reg, CClass *pobj_c){4 void FreeTempObject(int reg,const CClass *pobj_c){ 5 5 if(!IsSafeReg(reg)) SetError(300,NULL,cp); 6 6 … … 16 16 17 17 //call DestructorProcAddr 18 op_call( method->p si);18 op_call( method->pUserProc ); 19 19 } 20 20 … … 23 23 24 24 //call free 25 extern SubInfo*pSub_free;25 extern UserProc *pSub_free; 26 26 op_call(pSub_free); 27 27 } 28 28 29 int CallOperatorProc(int idCalc, TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp){29 int CallOperatorProc(int idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp){ 30 30 //オーバーロードされたオペレータ関数を呼び出す 31 31 CClass *pobj_c; 32 32 pobj_c=(CClass *)index_stack[sp-2]; 33 33 34 std::vector< SubInfo*> subs;34 std::vector<UserProc *> subs; 35 35 pobj_c->EnumMethod( idCalc, subs ); 36 36 if( subs.size() == 0 ){ … … 45 45 46 46 int i; 47 BOOL bReturnTypeIsObject=1;48 TYPEINFO ReturnType={DEF_OBJECT,subs[0]->u.ReturnIndex};49 for(i=0;i<subs.size();i++){50 if(subs[i]->ReturnType!=DEF_OBJECT)51 bReturnTypeIsObject=0;52 }53 54 if(bReturnTypeIsObject==0){55 if(pBaseTypeInfo){56 if(pBaseTypeInfo->type==DEF_OBJECT){57 ReturnType.u.lpIndex=pBaseTypeInfo->u.lpIndex;58 }59 }60 }61 62 47 63 48 … … 66 51 ///////////////////////////////////////////// 67 52 68 PARAMETER_INFO *ppi = (PARAMETER_INFO *)HeapAlloc(hHeap,0,sizeof(PARAMETER_INFO)*3); 69 int iParmNum=0; 70 71 if(bTwoTerm){ 72 ppi[iParmNum].bArray=0; 73 ppi[iParmNum].bByVal=0; 74 ppi[iParmNum].name=0; 75 ppi[iParmNum].type=type[sp-1]; 76 ppi[iParmNum].u.index=index_stack[sp-1]; 77 ppi[iParmNum].SubScripts[0]=-1; 78 iParmNum++; 79 } 80 53 Parameters params; 54 55 if(bTwoTerm){ 56 params.push_back( new Parameter( "", Type( type_stack[sp-1], index_stack[sp-1] ) ) ); 57 } 81 58 82 59 //オーバーロードを解決 … … 84 61 if(idCalc==CALC_EQUAL) lstrcpy(temporary,"=="); 85 62 else GetCalcName(idCalc,temporary); 86 SubInfo *psi;87 psi=OverloadSolution(temporary,subs,ppi,iParmNum,pBaseTypeInfo); 88 89 90 if(!psi){91 HeapDefaultFree(ppi);63 UserProc *pUserProc = OverloadSolution( temporary, subs, params, baseType ); 64 65 if(!pUserProc){ 66 if(bTwoTerm){ 67 delete params[0]; 68 } 92 69 return -1; 93 70 } 94 71 else{ 95 72 //オーバーロードされていないが、パラメータ個数が一致しないとき 96 if(iParmNum!=psi->params.size()){ 97 HeapDefaultFree(ppi); 73 if(params.size()!=pUserProc->Params().size()){ 74 if(bTwoTerm){ 75 delete params[0]; 76 } 98 77 return -1; 99 78 } 100 79 } 101 80 102 for(i=0;i< iParmNum;i++){81 for(i=0;i<(int)params.size();i++){ 103 82 CheckDifferentType( 104 p si->params[i]->GetBasicType(),105 p si->params[i]->GetIndex(),106 p pi[i].type,107 p pi[i].u.index,83 pUserProc->Params()[i]->GetBasicType(), 84 pUserProc->Params()[i]->GetIndex(), 85 params[i]->GetBasicType(), 86 params[i]->GetIndex(), 108 87 "", 109 88 i); 110 89 } 111 90 112 HeapDefaultFree(ppi); 113 114 if(bTwoTerm){ 115 if( psi->realParams[1]->IsStruct() && psi->realParams[1]->IsRef() == false ){ 91 if(bTwoTerm){ 92 delete params[0]; 93 } 94 95 int right_side_size = GetTypeSize(type_stack[sp-1],index_stack[sp-1]); 96 97 if(bTwoTerm){ 98 if( pUserProc->RealParams()[1]->IsStruct() &&pUserProc->RealParams()[1]->IsRef() == false ){ 116 99 //一時オブジェクトはメソッド内で破棄される 117 100 bUseHeap[sp-1]=0; … … 119 102 } 120 103 121 if(psi->ReturnType==DEF_STRUCT){ 104 105 if( pUserProc->ReturnType().IsStruct() ){ 122 106 ////////////////////////////////////////////////////// 123 107 // 戻り値に構造体インスタンスを持つ場合 … … 131 115 ////////////////////////////////////////////////////// 132 116 133 int object_size = p si->u.Return_pobj_c->GetSize();117 int object_size = pUserProc->ReturnType().GetClass().GetSize(); 134 118 135 119 //mov rcx,object_size … … 137 121 138 122 //call calloc 139 extern SubInfo*pSub_calloc;123 extern UserProc *pSub_calloc; 140 124 op_call(pSub_calloc); 141 125 … … 152 136 if(bTwoTerm){ 153 137 //右の項(実数の場合が未完成) 154 SetOneTermToReg_Whole64Calc(type [sp-1],®2);138 SetOneTermToReg_Whole64Calc(type_stack[sp-1],®2); 155 139 pobj_reg->UnlockReg(); 156 if( !p si->realParams[1]->IsRef() == false ){140 if( !pUserProc->RealParams()[1]->IsRef() == false ){ 157 141 //一時参照を作成 158 142 pobj_sf->push( reg2 ); … … 190 174 191 175 if(bTwoTerm){ 192 if( psi->ReturnType==DEF_STRUCT){176 if( pUserProc->ReturnType().IsStruct() ){ 193 177 //mov r8,reg2 194 178 op_mov_RR(REG_R8,reg2); … … 200 184 } 201 185 202 if( psi->ReturnType==DEF_STRUCT){186 if( pUserProc->ReturnType().IsStruct() ){ 203 187 //mov rdx,r13 204 188 op_mov_RR(REG_RDX,REG_R13); … … 209 193 210 194 //call operator_proc 211 op_call(p si);212 213 if( psi->ReturnType!=DEF_NON){195 op_call(pUserProc); 196 197 if( !pUserProc->ReturnType().IsNull() ){ 214 198 //戻り値を一時的に退避 215 199 … … 253 237 254 238 if(bTwoTerm){ 255 if( !p si->realParams[1]->IsRef() == false ){239 if( !pUserProc->RealParams()[1]->IsRef() == false ){ 256 240 //一時参照を破棄 257 241 pobj_sf->pop(); … … 259 243 } 260 244 261 if( psi->ReturnType!=DEF_NON){245 if( !pUserProc->ReturnType().IsNull() ){ 262 246 //戻り値をreg1にセット 263 247 reg1=pobj_reg->LockReg(); … … 268 252 269 253 sp--; 270 type [sp-1]=psi->ReturnType;271 index_stack[sp-1]=p si->u.ReturnIndex;272 273 if( psi->ReturnType==DEF_STRUCT){254 type_stack[sp-1]=pUserProc->ReturnType().GetBasicType(); 255 index_stack[sp-1]=pUserProc->ReturnType().GetIndex(); 256 257 if( pUserProc->ReturnType().IsStruct() ){ 274 258 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 275 259 //※後にfreeする必要あり … … 281 265 } 282 266 283 void CallCastOperatorProc(int reg, int &CalcType,LONG_PTR &lpCalcIndex,BOOL bCalcUseHeap,int ToType,LONG_PTR lpToIndex){284 int type [10];267 void CallCastOperatorProc(int reg,Type &calcType,BOOL bCalcUseHeap,const Type &toType){ 268 int type_stack[10]; 285 269 LONG_PTR index_stack[10]; 286 270 BOOL array_bUseHeap[10]; … … 304 288 305 289 //左辺 306 type [0]=CalcType;307 index_stack[0]= lpCalcIndex;290 type_stack[0]=calcType.GetBasicType(); 291 index_stack[0]=calcType.GetIndex(); 308 292 array_bUseHeap[0]=0; 309 type [1]=ToType;310 index_stack[1]= lpToIndex;293 type_stack[1]=toType.GetBasicType(); 294 index_stack[1]=toType.GetIndex(); 311 295 array_bUseHeap[1]=0; 312 296 313 TYPEINFO BaseTypeInfo={ToType,lpToIndex}; 314 315 iRet=CallOperatorProc(CALC_AS,&BaseTypeInfo,type,index_stack,array_bUseHeap,sp); 297 iRet=CallOperatorProc(CALC_AS,toType,type_stack,index_stack,array_bUseHeap,sp); 316 298 317 299 pobj_reg->UnlockReg(); … … 325 307 if(iRet==1){ 326 308 //成功したとき 327 CalcType=type[0]; 328 lpCalcIndex=index_stack[0]; 309 calcType.SetType( type_stack[0], index_stack[0] ); 329 310 return; 330 311 } … … 339 320 340 321 //インデクサ(getter)を呼び出す 341 void CallIndexerGetterProc(int reg, CClass *pobj_Class,char *ObjectName,char *Parameter,TYPEINFO &RetTypeInfo){342 343 std::vector< SubInfo*> subs;322 void CallIndexerGetterProc(int reg,const CClass *pobj_Class,char *ObjectName,char *Parameter,Type &resultType ){ 323 324 std::vector<UserProc *> subs; 344 325 pobj_Class->EnumMethod( CALC_ARRAY_GET, subs ); 345 326 if( subs.size() == 0 ){ … … 353 334 354 335 Opcode_CallProc(Parameter,subs[0],0,ObjectName,DEF_OBJECT); 355 RetTypeInfo.type = subs[0]->ReturnType; 356 RetTypeInfo.u.lpIndex = subs[0]->u.ReturnIndex; 336 resultType = subs[0]->ReturnType(); 357 337 358 338 //mov reg,rax -
BasicCompiler64/WatchList.cpp
r73 r75 5 5 #include "../BasicCompiler_Common/debug.h" 6 6 7 int Debugging_GetArray( int *SubScripts,char *array,int type,LONG_PTR lpIndex,LONG_PTR *plpOffset);7 int Debugging_GetArray( const int *SubScripts,char *array,const Type &type,LONG_PTR *plpOffset); 8 8 9 9 ULONG_PTR Debugging_GetVarPtr(RELATIVE_VAR *pRelativeVar){ … … 61 61 } 62 62 63 BOOL Debugging_SetRelativeOffset(int *pType,LONG_PTR lpIndex,RELATIVE_VAR *pRelativeVar,char *lpPtrOffset){63 bool Debugging_SetRelativeOffset( Type &type,RELATIVE_VAR *pRelativeVar,char *lpPtrOffset){ 64 64 int array_num; 65 65 66 66 _int64 i64data; 67 i nt type;68 type=StaticCalculation(true, lpPtrOffset,0,&i64data,0,1);69 if(!type) return 0;70 if( IsRealNumberType(type)){67 if( !StaticCalculation( true, lpPtrOffset, 0, &i64data, Type(), 1 ) ){ 68 return false; 69 } 70 if( type.IsReal() ){ 71 71 double dbl; 72 72 memcpy(&dbl,&i64data,sizeof(double)); … … 76 76 array_num=(int)i64data; 77 77 78 if( PTR_LEVEL(*pType)){79 *pType=MAKE_PTR_TYPE(NATURAL_TYPE(*pType),PTR_LEVEL(*pType)-1);80 array_num *= GetTypeSize(*pType,-1);78 if( type.PtrLevel() ){ 79 type.PtrLevelDown(); 80 array_num *= type.GetSize(); 81 81 } 82 82 else{ 83 83 //エラー 84 return 0;84 return false; 85 85 } 86 86 … … 89 89 SIZE_T stAccBytes; 90 90 lpData=Debugging_GetVarPtr(pRelativeVar); 91 if(!ReadProcessMemory(hDebugProcess,(void *)lpData,&pRelativeVar->offset,sizeof(LONG_PTR),&stAccBytes)) return 0; 91 if(!ReadProcessMemory(hDebugProcess,(void *)lpData,&pRelativeVar->offset,sizeof(LONG_PTR),&stAccBytes)){ 92 return false; 93 } 92 94 pRelativeVar->dwKind=VAR_DIRECTMEM; 93 95 94 96 pRelativeVar->offset+=array_num; 95 return 1;97 return true; 96 98 } 97 99 98 BOOL Debugging_GetMember(CClass *pobj_c,char *member,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpNestIndex,BOOL bPrivateAccess){100 int Debugging_GetMember( const CClass &objClass,char *member,RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess){ 99 101 int i,i2; 100 102 … … 117 119 //////////////////////////// 118 120 119 int offset = pobj_c->GetMemberOffset( VarName, &i );120 if(i== pobj_c->iMemberNum) return 0;121 int offset = objClass.GetMemberOffset( VarName, &i ); 122 if(i==objClass.iMemberNum) return 0; 121 123 122 124 123 125 //アクセシビリティをチェック 124 if((bPrivateAccess==0&& pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)||125 pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){126 if((bPrivateAccess==0&&objClass.ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)|| 127 objClass.ppobj_Member[i]->dwAccess==ACCESS_NON){ 126 128 return 0; 127 129 } 128 else if(bPrivateAccess==0&& pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PROTECTED)130 else if(bPrivateAccess==0&&objClass.ppobj_Member[i]->dwAccess==ACCESS_PROTECTED) 129 131 return 0; 130 132 131 *pType=pobj_c->ppobj_Member[i]->TypeInfo.type; 132 *plpNestIndex=pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex; 133 resultType = *objClass.ppobj_Member[i]; 133 134 134 135 //ポインタ変数の場合 135 if( IsPtrType(*pType)){136 if( pobj_c->ppobj_Member[i]->SubScripts[0]==-1){136 if( resultType.IsPointer() ){ 137 if(objClass.ppobj_Member[i]->SubScripts[0]==-1){ 137 138 lstrcpy(lpPtrOffset,array); 138 139 array[0]=0; … … 148 149 //配列オフセット 149 150 i2=Debugging_GetArray( 150 pobj_c->ppobj_Member[i]->SubScripts,151 objClass.ppobj_Member[i]->SubScripts, 151 152 array, 152 *pType, 153 pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex, 153 resultType, 154 154 &pRelativeVar->offset); 155 155 if(i2==0){ … … 162 162 } 163 163 } 164 else if( pobj_c->ppobj_Member[i]->SubScripts[0]!=-1){165 *pType|=FLAG_PTR;164 else if(objClass.ppobj_Member[i]->SubScripts[0]!=-1){ 165 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 166 166 } 167 167 … … 169 169 //入れ子構造の場合 170 170 171 if( *pType==DEF_OBJECT || *pType==DEF_STRUCT){171 if( resultType.IsObject() || resultType.IsStruct() ){ 172 172 if( refType != CClass::Dot ) return 0; 173 173 174 if( *pType==DEF_OBJECT){174 if( resultType.IsObject() ){ 175 175 extern HANDLE hDebugProcess; 176 176 LONG_PTR lpData; … … 181 181 } 182 182 } 183 else if( *pType==DEF_PTR_OBJECT || *pType==DEF_PTR_STRUCT){183 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){ 184 184 //構造体ポインタ型メンバ変数 185 185 … … 188 188 189 189 //直接参照に切り替え 190 Debugging_SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);190 Debugging_SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 191 191 192 192 lpPtrOffset[0]=0; … … 204 204 } 205 205 206 i2=Debugging_GetMember( pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class,206 i2=Debugging_GetMember(objClass.ppobj_Member[i]->GetClass(), 207 207 NestMember, 208 pType,209 208 pRelativeVar, 210 plpNestIndex,209 resultType, 211 210 0); 212 211 if(i2==0){ … … 221 220 222 221 if(lpPtrOffset[0]){ 223 Debugging_SetRelativeOffset( pType,*plpNestIndex,pRelativeVar,lpPtrOffset);222 Debugging_SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 224 223 } 225 224 226 225 return 1; 227 226 } 228 int Debugging_GetArray( int *SubScripts,char *array,int type,LONG_PTR lpIndex,LONG_PTR *plpOffset){227 int Debugging_GetArray( const int *SubScripts,char *array,const Type &type,LONG_PTR *plpOffset){ 229 228 extern HANDLE hHeap; 230 int i,i2,i3,i4,i5,array_offset ,TypeSize;229 int i,i2,i3,i4,i5,array_offset; 231 230 char temporary[VN_SIZE],*pParm[MAX_PARMS]; 232 231 … … 275 274 for(i=i3-1;i>=0;i--){ 276 275 _int64 i64data; 277 i2=StaticCalculation(true, pParm[i],0,&i64data,0,1); 278 if(i2==0){ 276 Type resultType; 277 bool isMemoryAccessError; 278 if( !StaticCalculation(true, pParm[i],0,&i64data,resultType,1, &isMemoryAccessError ) ){ 279 279 //式エラー 280 280 return 0; 281 281 } 282 if(i 2==-1){282 if(isMemoryAccessError){ 283 283 //アクセスエラー 284 284 return -1; 285 285 } 286 286 287 if( IsRealNumberType(i2)){287 if(resultType.IsReal()){ 288 288 double dbl; 289 289 memcpy(&dbl,&i64data,sizeof(double)); … … 299 299 } 300 300 301 TypeSize=GetTypeSize(type,lpIndex); 302 303 array_offset*=TypeSize; 301 array_offset *= type.GetSize(); 304 302 305 303 *plpOffset+=array_offset; … … 308 306 } 309 307 ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip){ 310 int i; 311 SubInfo *psi; 312 313 //ripからプロシージャを取得 314 psi=GetSubFromObp(obp_Rip); 315 316 for(i=0;i<psi->VarNum;i++){ 317 if(lstrcmp(psi->pVar[i].name,"_System_LocalThis")==0) break; 318 } 319 if(i==psi->VarNum) return 0; 320 321 return psi->pVar[i].offset; 308 UserProc *pUserProc = GetSubFromObp(obp_Rip); 309 310 foreach( Variable *pVar, pUserProc->localVars ){ 311 if( pVar->GetName() == "_System_LocalThis" ){ 312 return pVar->offset; 313 } 314 } 315 return 0; 322 316 } 323 int Debugging_GetVarOffset( char *variable,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){317 int Debugging_GetVarOffset( char *variable,RELATIVE_VAR *pRelativeVar, Type &resultType, int *pss){ 324 318 extern HANDLE hDebugProcess; 325 319 int i,i2,i3; … … 332 326 GetVarFormatString(VarName,array,lpPtrOffset,member,refType); 333 327 334 LONG_PTR lpIndex; 335 int *pSubScripts; 336 BOOL bArray; 328 const int *pSubScripts; 329 bool isArray; 337 330 338 331 … … 340 333 // ローカル変数 341 334 ///////////////// 342 extern VARIABLE *LocalVar; 343 extern int MaxLocalVarNum; 344 for(i=0;i<MaxLocalVarNum;i++){ 345 if(lstrcmp(VarName,LocalVar[i].name)==0) break; 346 } 347 if(i!=MaxLocalVarNum){ 335 const Variable *pVar = UserProc::CompilingUserProc().localVars.Find( VarName ); 336 if( pVar ){ 348 337 //ポインタ変数の場合 349 if( IsPtrType(LocalVar[i].type)){350 if( !LocalVar[i].bArray){338 if( pVar->IsPointer() ){ 339 if( !pVar->IsArray() ){ 351 340 lstrcpy(lpPtrOffset,array); 352 341 array[0]=0; … … 357 346 } 358 347 359 pRelativeVar->offset=LocalVar[i].offset; 360 if(LocalVar[i].fRef) pRelativeVar->dwKind=VAR_REFLOCAL; 361 else pRelativeVar->dwKind=VAR_LOCAL; 362 *pType=LocalVar[i].type; 363 lpIndex=LocalVar[i].u.index; 364 *plpIndex=lpIndex; 365 bArray=LocalVar[i].bArray; 366 pSubScripts=LocalVar[i].SubScripts; 348 pRelativeVar->offset = pVar->offset; 349 if( pVar->IsRef() ){ 350 pRelativeVar->dwKind=VAR_REFLOCAL; 351 } 352 else{ 353 pRelativeVar->dwKind=VAR_LOCAL; 354 } 355 resultType = *pVar; 356 isArray = pVar->IsArray(); 357 pSubScripts = pVar->GetSubScriptsPtr(); 367 358 } 368 359 else{ … … 406 397 pRelativeVar->dwKind=VAR_DIRECTMEM; 407 398 408 LONG_PTR lp2; 409 i3=Debugging_GetMember(pobj_CompilingClass,variable,pType,pRelativeVar,&lp2,1); 399 i3=Debugging_GetMember(*pobj_CompilingClass,variable,pRelativeVar,resultType,1); 410 400 if(i3==0){ 411 401 //式エラー … … 417 407 } 418 408 419 *plpIndex=lp2;420 409 return 1; 421 410 } … … 426 415 // グローバル変数 427 416 /////////////////// 428 extern VARIABLE *GlobalVar; 429 extern int MaxGlobalVarNum; 430 431 for(i=0;i<MaxGlobalVarNum;i++){ 432 if(lstrcmp(VarName,GlobalVar[i].name)==0) break; 433 } 434 if(i==MaxGlobalVarNum){ 417 418 const Variable *pVar = globalVars.Find( VarName ); 419 if( !pVar ){ 435 420 //一致しないとき 436 421 return 0; … … 438 423 439 424 //ポインタ変数の場合 440 if( IsPtrType(GlobalVar[i].type)){441 if( !GlobalVar[i].bArray){425 if( pVar->IsPointer() ){ 426 if( !pVar->IsArray() ){ 442 427 lstrcpy(lpPtrOffset,array); 443 428 array[0]=0; … … 448 433 } 449 434 450 pRelativeVar->offset= GlobalVar[i].offset;451 if( GlobalVar[i].fRef) pRelativeVar->dwKind=VAR_REFGLOBAL;435 pRelativeVar->offset=pVar->offset; 436 if(pVar->IsRef()) pRelativeVar->dwKind=VAR_REFGLOBAL; 452 437 else pRelativeVar->dwKind=VAR_GLOBAL; 453 *pType=GlobalVar[i].type; 454 lpIndex=GlobalVar[i].u.index; 455 *plpIndex=lpIndex; 456 bArray=GlobalVar[i].bArray; 457 pSubScripts=GlobalVar[i].SubScripts; 458 } 459 460 461 if(array[0]==0&&bArray){ 438 resultType = *pVar; 439 isArray = pVar->IsArray(); 440 pSubScripts=pVar->GetSubScriptsPtr(); 441 } 442 443 444 if(array[0]==0&&isArray){ 462 445 //配列の先頭ポインタを示す場合 463 *pType|=FLAG_PTR;464 if(pss) memcpy(pss,pSubScripts,MAX_ARRAYDIM );446 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 447 if(pss) memcpy(pss,pSubScripts,MAX_ARRAYDIM*sizeof(int)); 465 448 return 1; 466 449 } 467 450 468 451 if(array[0]){ 469 i3=Debugging_GetArray(pSubScripts,array, *pType,lpIndex,&pRelativeVar->offset);452 i3=Debugging_GetArray(pSubScripts,array,resultType,&pRelativeVar->offset); 470 453 if(i3==0){ 471 454 //式エラー … … 478 461 } 479 462 if(member[0]){ 480 if( *pType==DEF_OBJECT || *pType==DEF_STRUCT){463 if( resultType.IsObject() || resultType.IsStruct() ){ 481 464 //実態オブジェクトのメンバを参照(obj.member) 482 465 if( refType != CClass::Dot ){ … … 484 467 } 485 468 486 LONG_PTR lp2; 487 i3=Debugging_GetMember((CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0); 469 i3=Debugging_GetMember(resultType.GetClass(),member,pRelativeVar,resultType,0); 488 470 if(i3==0){ 489 471 //式エラー … … 494 476 return -1; 495 477 } 496 497 *plpIndex=lp2; 498 } 499 else if(*pType==DEF_PTR_OBJECT || *pType==DEF_PTR_STRUCT){ 478 } 479 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){ 500 480 //ポインタオブジェクトが示すメンバを参照 501 481 if(lpPtrOffset[0]){ 502 482 //pObj[n].member 503 483 if( refType != CClass::Dot ) return 0; 504 Debugging_SetRelativeOffset(pType,lpIndex,pRelativeVar,lpPtrOffset); 505 506 LONG_PTR lp2; 507 i3=Debugging_GetMember((CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0); 484 Debugging_SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset); 485 486 i3=Debugging_GetMember(resultType.GetClass(),member,pRelativeVar,resultType,0); 508 487 if(i3==0){ 509 488 //式エラー … … 514 493 return -1; 515 494 } 516 517 *plpIndex=lp2;518 495 } 519 496 else{ … … 527 504 pRelativeVar->offset=lpData; 528 505 529 LONG_PTR lp2; 530 i3=Debugging_GetMember((CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0); 506 i3=Debugging_GetMember(resultType.GetClass(),member,pRelativeVar,resultType,0); 531 507 if(i3==0){ 532 508 //式エラー … … 537 513 return -1; 538 514 } 539 540 *plpIndex=lp2;541 515 } 542 516 } … … 548 522 549 523 if(lpPtrOffset[0]){ 550 if(!Debugging_SetRelativeOffset( pType,lpIndex,pRelativeVar,lpPtrOffset)) return 0;524 if(!Debugging_SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset)) return 0; 551 525 } 552 526 -
BasicCompiler64/amd64_main.cpp
r73 r75 1791 1791 ///////////////////////////// 1792 1792 1793 void op_call( SubInfo *psi){1793 void op_call( UserProc *pUserProc ){ 1794 1794 OpBuffer[obp++] = (char)0xE8; 1795 pobj_SubAddrSchedule->add( p si, 1 );1796 p si->bUse = 1;1795 pobj_SubAddrSchedule->add( pUserProc, 1 ); 1796 pUserProc->Using(); 1797 1797 obp += sizeof(long); 1798 1798 } 1799 void op_call( D ECLAREINFO *pdi){1799 void op_call( DllProc *pDllProc ){ 1800 1800 OpBuffer[obp++] = (char)0xFF; 1801 1801 OpBuffer[obp++] = (char)0x15; 1802 pobj_ImportAddrSchedule->add(p di);1802 pobj_ImportAddrSchedule->add(pDllProc); 1803 1803 obp += sizeof(long); 1804 1804 1805 p di->bUse=1;1806 } 1805 pDllProc->Using(); 1806 } -
BasicCompiler64/increment.cpp
r11 r75 3 3 4 4 void IncDec(int idCalc, char *lpszLeft, char *lpszRight){ 5 int VarType;6 LONG_PTR lpVarIndex;7 RELATIVE_VAR VarRelativeVar;8 9 5 10 6 /////////////////////////// … … 12 8 /////////////////////////// 13 9 10 RELATIVE_VAR VarRelativeVar; 11 Type varType; 14 12 if(!GetVarOffsetReadWrite( 15 13 lpszLeft, 16 &VarType,17 14 &VarRelativeVar, 18 &lpVarIndex)) return;15 varType)) return; 19 16 20 17 //変数オフセットを一時退避 … … 30 27 31 28 int reg; 32 if( VarType==DEF_DOUBLE){29 if( varType.IsDouble() ){ 33 30 reg=REG_XMM0; 34 31 SetXmmReg_DoubleVariable(&VarRelativeVar,reg); 35 32 } 36 else if( VarType==DEF_SINGLE){33 else if( varType.IsSingle() ){ 37 34 reg=REG_XMM0; 38 35 SetXmmReg_SingleVariable(&VarRelativeVar,reg); … … 40 37 else{ 41 38 reg=REG_RAX; 42 SetReg_WholeVariable( VarType,&VarRelativeVar,reg);39 SetReg_WholeVariable(varType.GetBasicType(),&VarRelativeVar,reg); 43 40 } 44 41 45 42 46 if( IsWholeNumberType(VarType)&&lstrcmp(lpszRight,"1")==0&&43 if(varType.IsWhole()&&lstrcmp(lpszRight,"1")==0&& 47 44 (idCalc==CALC_ADDITION||idCalc==CALC_SUBTRACTION)){ 48 45 if(idCalc==CALC_ADDITION){ … … 60 57 61 58 //右辺を計算 62 int CalcType; 63 LONG_PTR lpCalcIndex; 59 Type calcType; 64 60 if(reg==REG_RAX) reg=REG_RCX; 65 61 else reg=REG_RAX; 66 CalcType=NumOpe(®,lpszRight,VarType,lpVarIndex,&lpCalcIndex);62 NumOpe(®,lpszRight,varType,calcType); 67 63 68 64 //レジスタのブロッキングを解除 … … 70 66 71 67 72 if( IsPtrType(VarType)&&IsWholeNumberType(CalcType)&&(!IsPtrType(CalcType))){68 if(varType.IsPointer()&&calcType.IsWhole()&&(!calcType.IsPointer())){ 73 69 //左辺がポインタ型、右辺が整数型の場合は、エラーをださないようにする 74 CalcType=VarType; 75 lpCalcIndex=lpVarIndex; 70 calcType = varType; 76 71 } 77 72 … … 81 76 ///////////////////////////////// 82 77 83 CheckDifferentType( VarType,lpVarIndex,CalcType,lpCalcIndex,0,0);78 CheckDifferentType(varType,calcType,0,0); 84 79 85 80 … … 88 83 89 84 //左辺用レジスタ 90 if( IsRealNumberType(VarType))85 if(varType.IsReal()) 91 86 pobj_reg->LockXmmReg(); 92 87 else … … 94 89 95 90 //右辺値レジスタ 96 if( VarType==DEF_DOUBLE)97 ChangeTypeToXmm_Double( CalcType,91 if(varType.IsDouble()) 92 ChangeTypeToXmm_Double(calcType.GetBasicType(), 98 93 pobj_reg->LockXmmReg(), 99 94 pobj_reg->GetNextReg()); 100 else if( VarType==DEF_SINGLE)101 ChangeTypeToXmm_Single( CalcType,95 else if(varType.IsSingle()) 96 ChangeTypeToXmm_Single(calcType.GetBasicType(), 102 97 pobj_reg->LockXmmReg(), 103 98 pobj_reg->GetNextReg()); 104 99 else 105 ChangeTypeToWhole( CalcType,VarType,100 ChangeTypeToWhole(calcType.GetBasicType(),varType.GetBasicType(), 106 101 pobj_reg->LockReg(), 107 102 pobj_reg->GetNextXmmReg()); 108 103 109 int type [255],sp;104 int type_stack[255],sp; 110 105 LONG_PTR index_stack[255]; 111 type [0]=VarType;112 type [1]=VarType;113 index_stack[0]= lpVarIndex;114 index_stack[1]= lpVarIndex;106 type_stack[0]=varType.GetBasicType(); 107 type_stack[1]=varType.GetBasicType(); 108 index_stack[0]=varType.GetIndex(); 109 index_stack[1]=varType.GetIndex(); 115 110 sp=2; 116 111 … … 119 114 case CALC_OR: 120 115 case CALC_AND: 121 CalcTwoTerm_Logical(idCalc,type ,index_stack,&sp);116 CalcTwoTerm_Logical(idCalc,type_stack,index_stack,&sp); 122 117 break; 123 118 case CALC_SHL: 124 119 case CALC_SHR: 125 Calc_Shift(idCalc,type ,&sp);120 Calc_Shift(idCalc,type_stack,&sp); 126 121 break; 127 122 case CALC_ADDITION: 128 123 case CALC_SUBTRACTION: 129 124 case CALC_PRODUCT: 130 CalcTwoTerm_Arithmetic(idCalc,type ,index_stack,&sp);125 CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp); 131 126 break; 132 127 case CALC_MOD: 133 Calc_Mod(type ,index_stack,&sp);128 Calc_Mod(type_stack,index_stack,&sp); 134 129 break; 135 130 case CALC_QUOTIENT: 136 Calc_Divide(type ,&sp,VarType);131 Calc_Divide(type_stack,&sp,varType.GetBasicType()); 137 132 break; 138 133 case CALC_INTQUOTIENT: 139 Calc_IntDivide(type ,index_stack,&sp);134 Calc_IntDivide(type_stack,index_stack,&sp); 140 135 break; 141 136 case CALC_POWER: 142 Calc_Power(type ,&sp);137 Calc_Power(type_stack,&sp); 143 138 break; 144 139 } … … 160 155 } 161 156 162 SetVariableFromRax( VarType,VarType,&VarRelativeVar);157 SetVariableFromRax(varType.GetBasicType(),varType.GetBasicType(),&VarRelativeVar); 163 158 } -
BasicCompiler64/varlist.cpp
r73 r75 7 7 HWND hVarTree_Global,hVarTree_Local,hVarTree_This; 8 8 9 int VarList_Array(HWND hVarTree,HTREEITEM hParent,LONG_PTR offset, int type,int *SubScripts,LONG_PTR lpIndex);10 void VarList_Member(HWND hVarTree,HTREEITEM hParent,LONG_PTR pTopOffset, CClass *pobj_c,BOOL bPtr);11 void VarList_Insert(HWND hVarTree,TV_INSERTSTRUCT *lptv,c har *VarName,int type,LONG_PTR offset,LONG_PTR lpIndex){9 int VarList_Array(HWND hVarTree,HTREEITEM hParent,LONG_PTR offset,const Type &type,const int *SubScripts); 10 void VarList_Member(HWND hVarTree,HTREEITEM hParent,LONG_PTR pTopOffset,const CClass &objClass,BOOL bPtr); 11 void VarList_Insert(HWND hVarTree,TV_INSERTSTRUCT *lptv,const char *VarName,const Type &type,LONG_PTR offset){ 12 12 extern HANDLE hDebugProcess; 13 13 int i2; … … 22 22 _int64 i64data; 23 23 24 if( type==DEF_OBJECT||type==DEF_STRUCT){25 if( type ==DEF_OBJECT){24 if( type.IsObject() || type.IsStruct() ){ 25 if( type.IsObject() ){ 26 26 // 参照型ということを考慮する 27 27 ReadProcessMemory(hDebugProcess,(void *)offset,&pData,sizeof(void *),&stAccBytes); … … 34 34 hParent=TreeView_InsertItem(hVarTree,lptv); 35 35 36 VarList_Member(hVarTree,hParent,offset, (CClass *)lpIndex,0);36 VarList_Member(hVarTree,hParent,offset,type.GetClass(),0); 37 37 return; 38 38 } 39 if(type==DEF_PTR_OBJECT||type==DEF_PTR_STRUCT){39 else if( type.IsObjectPtr() || type.IsStructPtr() ){ 40 40 i2=ReadProcessMemory(hDebugProcess,(void *)offset,&pData,sizeof(void *),&stAccBytes); 41 41 … … 45 45 hParent=TreeView_InsertItem(hVarTree,lptv); 46 46 47 if(i2) VarList_Member(hVarTree,hParent,pData, (CClass *)lpIndex,1);47 if(i2) VarList_Member(hVarTree,hParent,pData,type.GetClass(),1); 48 48 return; 49 49 } 50 50 else{ 51 if(type ==MAKE_PTR_TYPE(DEF_SBYTE,1)||type==MAKE_PTR_TYPE(DEF_BYTE,1)){51 if(type.GetBasicType()==MAKE_PTR_TYPE(DEF_SBYTE,1)||type.GetBasicType()==MAKE_PTR_TYPE(DEF_BYTE,1)){ 52 52 if(ReadProcessMemory(hDebugProcess,(void *)offset,&pData,sizeof(void *),&stAccBytes)){ 53 53 for(i2=0;;i2++){ … … 67 67 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 68 68 } 69 else if(type ==DEF_DOUBLE){69 else if(type.IsDouble()){ 70 70 if(ReadProcessMemory(hDebugProcess,(void *)offset,&dbl,sizeof(double),&stAccBytes)){ 71 71 sprintf(lptv->item.pszText,"%s %.15g",VarName,dbl); … … 73 73 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 74 74 } 75 else if(type ==DEF_SINGLE){75 else if(type.IsSingle()){ 76 76 if(ReadProcessMemory(hDebugProcess,(void *)offset,&flt,sizeof(float),&stAccBytes)){ 77 77 sprintf(lptv->item.pszText,"%s %.6g",VarName,flt); … … 79 79 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 80 80 } 81 else if(type ==DEF_INT64){81 else if(type.IsInt64()){ 82 82 _int64 i64data; 83 83 if(ReadProcessMemory(hDebugProcess,(void *)offset,&i64data,sizeof(_int64),&stAccBytes)){ … … 89 89 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 90 90 } 91 else if(type ==DEF_QWORD||IsPtrType(type)){91 else if(type.IsQWord()||type.IsPointer()){ 92 92 if(ReadProcessMemory(hDebugProcess,(void *)offset,&i64data,sizeof(_int64),&stAccBytes)){ 93 93 _ui64toa(i64data,temporary,10); … … 98 98 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 99 99 } 100 else if(type ==DEF_LONG){100 else if(type.IsLong()){ 101 101 if(ReadProcessMemory(hDebugProcess,(void *)offset,&i64data,sizeof(_int64),&stAccBytes)){ 102 102 sprintf(lptv->item.pszText,"%s %d(&H%X)",VarName,i64data,i64data); … … 104 104 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 105 105 } 106 else if(type ==DEF_DWORD){106 else if(type.IsDWord()){ 107 107 if(ReadProcessMemory(hDebugProcess,(void *)offset,&i64data,sizeof(_int64),&stAccBytes)){ 108 108 sprintf(lptv->item.pszText,"%s %u(&H%X)",VarName,i64data,i64data); … … 110 110 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 111 111 } 112 else if(type ==DEF_INTEGER || (isUnicode&&type==DEF_CHAR)){112 else if(type.IsInteger()){ 113 113 if(ReadProcessMemory(hDebugProcess,(void *)offset,&wData,sizeof(WORD),&stAccBytes)){ 114 114 sprintf(lptv->item.pszText,"%s %d(&H%X)",VarName,(short)wData,(short)wData); … … 116 116 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 117 117 } 118 else if(type ==DEF_WORD){118 else if(type.IsWord()){ 119 119 if(ReadProcessMemory(hDebugProcess,(void *)offset,&wData,sizeof(WORD),&stAccBytes)){ 120 120 sprintf(lptv->item.pszText,"%s %u(&H%X)",VarName,wData,wData); … … 122 122 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 123 123 } 124 else if(type ==DEF_SBYTE || (isUnicode==false&&type==DEF_CHAR)){124 else if(type.IsSByte()){ 125 125 if(ReadProcessMemory(hDebugProcess,(void *)offset,&byteData,sizeof(BYTE),&stAccBytes)){ 126 126 temporary[0]=byteData; … … 130 130 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 131 131 } 132 else if(type ==DEF_BYTE){132 else if(type.IsByte()){ 133 133 if(ReadProcessMemory(hDebugProcess,(void *)offset,&byteData,sizeof(BYTE),&stAccBytes)){ 134 134 temporary[0]=byteData; … … 138 138 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 139 139 } 140 else if(type ==DEF_BOOLEAN){140 else if(type.IsBoolean()){ 141 141 if(ReadProcessMemory(hDebugProcess,(void *)offset,&byteData,sizeof(BYTE),&stAccBytes)){ 142 142 if( byteData ) lstrcpy( temporary, "True" ); … … 152 152 TreeView_InsertItem(hVarTree,lptv); 153 153 } 154 void VarList_Member(HWND hVarTree,HTREEITEM hParent,LONG_PTR pTopOffset, CClass *pobj_c,BOOL bPtr){154 void VarList_Member(HWND hVarTree,HTREEITEM hParent,LONG_PTR pTopOffset,const CClass &objClass,BOOL bPtr){ 155 155 int i,i2; 156 156 char VarData[VN_SIZE],VarName[VN_SIZE]; … … 163 163 tv.item.pszText=VarData; 164 164 165 for(i=0;i< pobj_c->iMemberNum;i++){165 for(i=0;i<objClass.iMemberNum;i++){ 166 166 if(bPtr){ 167 167 lstrcpy(VarName,"->"); 168 lstrcat(VarName, pobj_c->ppobj_Member[i]->name);168 lstrcat(VarName,objClass.ppobj_Member[i]->name); 169 169 } 170 170 else{ 171 171 lstrcpy(VarName,"."); 172 lstrcat(VarName, pobj_c->ppobj_Member[i]->name);172 lstrcat(VarName,objClass.ppobj_Member[i]->name); 173 173 } 174 174 175 175 LONG_PTR offset; 176 offset= pobj_c->GetMemberOffset( pobj_c->ppobj_Member[i]->name, &i2 );177 178 if( pobj_c->ppobj_Member[i]->SubScripts[0]!=-1){176 offset=objClass.GetMemberOffset( objClass.ppobj_Member[i]->name, &i2 ); 177 178 if(objClass.ppobj_Member[i]->SubScripts[0]!=-1){ 179 179 //構造体内の配列 180 180 sprintf(VarData,"%s %s(&H%X)",VarName,STRING_ARRAY,pTopOffset+offset); … … 185 185 i2=VarList_Array(hVarTree,hParent, 186 186 pTopOffset+offset, 187 pobj_c->ppobj_Member[i]->TypeInfo.type, 188 pobj_c->ppobj_Member[i]->SubScripts, 189 pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex); 187 *objClass.ppobj_Member[i], 188 objClass.ppobj_Member[i]->SubScripts); 190 189 } 191 190 else{ … … 194 193 &tv, 195 194 VarName, 196 pobj_c->ppobj_Member[i]->TypeInfo.type, 197 pTopOffset+offset, 198 pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex); 199 } 200 } 201 } 202 int VarList_Array(HWND hVarTree,HTREEITEM hParent,LONG_PTR offset,int type,int *SubScripts,LONG_PTR lpIndex){ 203 int i,i2,i3,ElementNum,MemCounter,UseCount[255],TypeSize; 195 *objClass.ppobj_Member[i], 196 pTopOffset+offset); 197 } 198 } 199 } 200 int VarList_Array(HWND hVarTree,HTREEITEM hParent,LONG_PTR offset,const Type &type,const int *SubScripts ){ 201 int i,i2,i3,ElementNum,MemCounter,UseCount[255]; 204 202 char temporary[VN_SIZE],temp2[DIGIT_SIZE]; 205 203 … … 210 208 tv.hParent=hParent; 211 209 tv.item.pszText=temporary; 212 213 TypeSize=GetTypeSize(type,lpIndex);214 210 215 211 for(i=0;i<255;i++){ … … 240 236 241 237 VarList_Insert(hVarTree,&tv,temporary,type, 242 offset+MemCounter*TypeSize, 243 lpIndex); 238 offset+MemCounter*type.GetSize()); 244 239 } 245 240 … … 254 249 void RefreshGlobalVar(void){ 255 250 extern DWORD ImageBase; 256 int i;257 251 char temporary[VN_SIZE]; 258 252 TV_INSERTSTRUCT tv; … … 269 263 extern HANDLE hDebugProcess; 270 264 extern int MemPos_RWSection; 271 extern int MaxGlobalVarNum; 272 extern VARIABLE *GlobalVar; 273 274 for(i=0;i<MaxGlobalVarNum;i++){ 275 VARIABLE *pVar=&GlobalVar[i]; 265 266 foreach( Variable *pVar, globalVars ){ 276 267 277 268 //スコープ外の場合は無視 … … 289 280 290 281 if(!pobj_nv->bShow_DefaultSystem_Var){ 291 if(memcmp(pVar-> name,"_System_",8)==0||292 memcmp(pVar-> name,"_DebugSys_",10)==0||293 memcmp(pVar-> name,"_PromptSys_",11)==0) continue;282 if(memcmp(pVar->GetName().c_str(),"_System_",8)==0|| 283 memcmp(pVar->GetName().c_str(),"_DebugSys_",10)==0|| 284 memcmp(pVar->GetName().c_str(),"_PromptSys_",11)==0) continue; 294 285 } 295 286 if(!pobj_nv->bShow_Rad_Var){ 296 if(memcmp(pVar-> name,"_RadSys_",8)==0) continue;287 if(memcmp(pVar->GetName().c_str(),"_RadSys_",8)==0) continue; 297 288 } 298 289 if(!pobj_nv->bShow_GUID_Var){ 299 if(memcmp(pVar-> name,"GUID_",5)==0||300 memcmp(pVar-> name,"IID_",4)==0||301 memcmp(pVar-> name,"CLSID_",6)==0) continue;290 if(memcmp(pVar->GetName().c_str(),"GUID_",5)==0|| 291 memcmp(pVar->GetName().c_str(),"IID_",4)==0|| 292 memcmp(pVar->GetName().c_str(),"CLSID_",6)==0) continue; 302 293 } 303 294 304 295 //静的メンバ 305 if(strstr(pVar-> name,".")) continue;306 307 if(pVar-> bArray){296 if(strstr(pVar->GetName().c_str(),".")) continue; 297 298 if(pVar->IsArray()){ 308 299 sprintf(temporary,"%s %s(&H%X)", 309 pVar-> name,300 pVar->GetName().c_str(), 310 301 STRING_ARRAY, 311 302 ImageBase+MemPos_RWSection+pVar->offset); … … 316 307 VarList_Array(hVarTree_Global,hParent, 317 308 (LONG_PTR)(ImageBase+MemPos_RWSection+pVar->offset), 318 pVar->type, 319 pVar->SubScripts, 320 pVar->u.index); 309 *pVar, 310 pVar->GetSubScriptsPtr()); 321 311 } 322 312 else{ 323 313 VarList_Insert(hVarTree_Global, 324 314 &tv, 325 pVar->name, 326 pVar->type, 327 (LONG_PTR)(ImageBase+MemPos_RWSection+pVar->offset), 328 pVar->u.index); 315 pVar->GetName().c_str(), 316 *pVar, 317 (LONG_PTR)(ImageBase+MemPos_RWSection+pVar->offset)); 329 318 } 330 319 } … … 354 343 if(pobj_dti->lplpSpBase[i2]==0) return; 355 344 356 extern SubInfo**ppSubHash;357 SubInfo *psi;345 extern UserProc **ppSubHash; 346 UserProc *pUserProc; 358 347 for(i3=0,sw=0;i3<MAX_HASH;i3++){ 359 p si=ppSubHash[i3];360 while(p si){361 if(rva_to_real(p si->CompileAddress) <= pobj_dti->lplpObp[i2] &&362 pobj_dti->lplpObp[i2] < rva_to_real(p si->EndOpAddr)){348 pUserProc=ppSubHash[i3]; 349 while(pUserProc){ 350 if(rva_to_real(pUserProc->beginOpAddress) <= pobj_dti->lplpObp[i2] && 351 pobj_dti->lplpObp[i2] < rva_to_real(pUserProc->endOpAddress)){ 363 352 sw=1; 364 353 break; 365 354 } 366 355 367 p si=psi->pNextData;356 pUserProc=pUserProc->pNextData; 368 357 } 369 358 if(sw) break; 370 359 } 371 if(!psi) return; 372 373 for(i=0;i<psi->VarNum;i++){ 374 VARIABLE *pVar=&psi->pVar[i]; 360 if(!pUserProc) return; 361 362 foreach( Variable *pVar, UserProc::CompilingUserProc().localVars ){ 375 363 376 364 //スコープ外の場合は無視 … … 386 374 } 387 375 388 if(pVar-> bArray){376 if(pVar->IsArray()){ 389 377 sprintf(temporary,"%s %s(&H%X)", 390 pVar-> name,378 pVar->GetName().c_str(), 391 379 STRING_ARRAY, 392 380 pobj_dti->lplpSpBase[i2]+pVar->offset); … … 397 385 VarList_Array(hVarTree_Local,hParent, 398 386 pobj_dti->lplpSpBase[i2]+pVar->offset, 399 pVar->type, 400 pVar->SubScripts, 401 pVar->u.index); 387 *pVar, 388 pVar->GetSubScriptsPtr()); 402 389 } 403 390 else{ 404 391 offset=pobj_dti->lplpSpBase[i2]+pVar->offset; 405 if(pVar-> fRef){392 if(pVar->IsRef()){ 406 393 ReadProcessMemory(hDebugProcess,(void *)offset,&lpData,sizeof(LONG_PTR),&stAccBytes); 407 394 offset=lpData; 408 395 } 409 396 VarList_Insert(hVarTree_Local,&tv, 410 pVar->name, 411 pVar->type, 412 offset, 413 pVar->u.index); 397 pVar->GetName().c_str(), 398 *pVar, 399 offset); 414 400 } 415 401 } … … 422 408 423 409 TreeView_DeleteAllItems(hVarTree_This); 424 if(!p si->pobj_ParentClass) return;410 if(!pUserProc->GetParentClassPtr()) return; 425 411 426 412 //Thisポインタを取得 427 413 LONG_PTR pThis; 428 for(i=0;i<psi->VarNum;i++){429 if(lstrcmp(psi->pVar[i].name,"_System_LocalThis")==0) break;430 }431 if(i==psi->VarNum) return;432 lpData=pobj_dti->lplpSpBase[i2]+p si->pVar[i].offset;414 const Variable *pVar = UserProc::CompilingUserProc().localVars.Find( "_System_LocalThis" ); 415 if( !pVar ){ 416 return; 417 } 418 lpData=pobj_dti->lplpSpBase[i2]+pVar->offset; 433 419 ReadProcessMemory(hDebugProcess,(void *)lpData,&pThis,sizeof(LONG_PTR),&stAccBytes); 434 420 435 for(i=0;i<p si->pobj_ParentClass->iMemberNum;i++){436 offset=p si->pobj_ParentClass->GetMemberOffset( psi->pobj_ParentClass->ppobj_Member[i]->name,&i2);437 438 if(p si->pobj_ParentClass->ppobj_Member[i]->SubScripts[0]!=-1){421 for(i=0;i<pUserProc->GetParentClassPtr()->iMemberNum;i++){ 422 offset=pUserProc->GetParentClassPtr()->GetMemberOffset( pUserProc->GetParentClassPtr()->ppobj_Member[i]->name,&i2); 423 424 if(pUserProc->GetParentClassPtr()->ppobj_Member[i]->SubScripts[0]!=-1){ 439 425 //配列 440 426 sprintf(temporary,"%s %s(&H%X)", 441 p si->pobj_ParentClass->ppobj_Member[i]->name,427 pUserProc->GetParentClassPtr()->ppobj_Member[i]->name, 442 428 STRING_ARRAY, 443 429 (DWORD64)offset); … … 448 434 VarList_Array(hVarTree_This,hParent, 449 435 pThis+offset, 450 psi->pobj_ParentClass->ppobj_Member[i]->TypeInfo.type, 451 psi->pobj_ParentClass->ppobj_Member[i]->SubScripts, 452 psi->pobj_ParentClass->ppobj_Member[i]->TypeInfo.u.lpIndex); 436 *pUserProc->GetParentClassPtr()->ppobj_Member[i], 437 pUserProc->GetParentClassPtr()->ppobj_Member[i]->SubScripts); 453 438 } 454 439 else{ 455 440 VarList_Insert(hVarTree_This,&tv, 456 psi->pobj_ParentClass->ppobj_Member[i]->name, 457 psi->pobj_ParentClass->ppobj_Member[i]->TypeInfo.type, 458 pThis+offset, 459 psi->pobj_ParentClass->ppobj_Member[i]->TypeInfo.u.lpIndex); 441 pUserProc->GetParentClassPtr()->ppobj_Member[i]->name, 442 *pUserProc->GetParentClassPtr()->ppobj_Member[i], 443 pThis+offset); 460 444 } 461 445 } … … 489 473 490 474 void SetCalcToWatchList(HWND hListView,int iItem,char *buffer){ 491 int i;492 475 char temporary[255],temp2[255]; 493 476 … … 498 481 499 482 //カッコを相互チェック 500 if(!CheckParenthesis2(buffer)){ 501 ListView_SetItemText(hListView,iItem,1,"式の解析に失敗"); 483 if(!CheckParenthesis2(buffer)){ListView_SetItemText(hListView,iItem,1,"式の解析に失敗"); 502 484 return; 503 485 } … … 505 487 double dbl; 506 488 _int64 i64data; 507 i=StaticCalculation(true, buffer,0,&i64data,0,1); 508 if(IsRealNumberType(i)){ 509 memcpy(&dbl,&i64data,sizeof(double)); 510 } 511 512 if(i==0){ 489 Type resultType; 490 bool isMemoryAccessError; 491 if( !StaticCalculation(true, buffer,0,&i64data,resultType,1,&isMemoryAccessError) ){ 513 492 ListView_SetItemText(hListView,iItem,1,"式の解析に失敗"); 514 493 } 515 else if(i ==-1){494 else if(isMemoryAccessError){ 516 495 ListView_SetItemText(hListView,iItem,1,"アクセスできません"); 517 496 } 518 497 else{ 519 if(IsRealNumberType(i)) 498 if(resultType.IsReal()){ 499 memcpy(&dbl,&i64data,sizeof(double)); 520 500 sprintf(temporary,"%.15g (&H%08X)",dbl,(int)dbl); 521 else if(Is64Type(i)){ 501 } 502 else if(resultType.Is64()){ 522 503 _i64toa(i64data,temporary,10); 523 504 _i64toa(i64data,temp2,16); … … 586 567 587 568 //プロシージャ コンボボックス 588 extern SubInfo**ppSubHash;589 SubInfo *psi;569 extern UserProc **ppSubHash; 570 UserProc *pUserProc; 590 571 int sw; 591 572 SendMessage(hProcCombo,CB_RESETCONTENT,0,0); 592 573 for(i2=pobj_dti->iProcLevel;i2>=0;i2--){ 593 574 for(i3=0,sw=0;i3<MAX_HASH;i3++){ 594 p si=ppSubHash[i3];595 while(p si){596 if(rva_to_real(p si->CompileAddress) <= pobj_dti->lplpObp[i2] &&597 pobj_dti->lplpObp[i2] < rva_to_real(p si->EndOpAddr)){598 lstrcpy(temporary,psi->name);599 sw=1;600 break;575 pUserProc=ppSubHash[i3]; 576 while(pUserProc){ 577 if(rva_to_real(pUserProc->beginOpAddress) <= pobj_dti->lplpObp[i2] && 578 pobj_dti->lplpObp[i2] < rva_to_real(pUserProc->endOpAddress)){ 579 lstrcpy(temporary,pUserProc->GetName().c_str()); 580 sw=1; 581 break; 601 582 } 602 p si=psi->pNextData;583 pUserProc=pUserProc->pNextData; 603 584 } 604 585 if(sw) break; 605 586 } 606 if(!p si){587 if(!pUserProc){ 607 588 if(i2==0){ 608 589 lstrcpy(temporary,"Global"); … … 699 680 /////////////////////////////////////////////// 700 681 701 extern VARIABLE *LocalVar;702 extern int MaxLocalVarNum;703 682 int sw; 704 705 MaxLocalVarNum=0;706 683 707 684 i2=(int)SendDlgItemMessage(hDebugWnd,IDC_PROCCOMBO,CB_GETCURSEL,0,0); … … 709 686 710 687 if(pobj_dti->lplpSpBase[i2]){ 711 extern SubInfo**ppSubHash;712 SubInfo *psi;688 extern UserProc **ppSubHash; 689 UserProc *pUserProc; 713 690 for(i3=0,sw=0;i3<MAX_HASH;i3++){ 714 p si=ppSubHash[i3];715 while(p si){716 if(rva_to_real(p si->CompileAddress) <= pobj_dti->lplpObp[i2] &&717 pobj_dti->lplpObp[i2] < rva_to_real(p si->EndOpAddr)){691 pUserProc=ppSubHash[i3]; 692 while(pUserProc){ 693 if(rva_to_real(pUserProc->beginOpAddress) <= pobj_dti->lplpObp[i2] && 694 pobj_dti->lplpObp[i2] < rva_to_real(pUserProc->endOpAddress)){ 718 695 sw=1; 719 696 break; 720 697 } 721 698 722 p si=psi->pNextData;699 pUserProc=pUserProc->pNextData; 723 700 } 724 701 if(sw) break; … … 726 703 727 704 728 if(psi){ 729 LocalVar=psi->pVar; 730 MaxLocalVarNum=psi->VarNum; 731 732 pobj_CompilingClass=psi->pobj_ParentClass; 705 if(pUserProc){ 706 pobj_CompilingClass=pUserProc->GetParentClassPtr(); 707 UserProc::CompileStartForUserProc( pUserProc ); 733 708 } 734 709 }
Note:
See TracChangeset
for help on using the changeset viewer.