Changeset 64 in dev for BasicCompiler_Common/Variable.cpp
- Timestamp:
- Mar 8, 2007, 2:49:34 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/Variable.cpp
r63 r64 157 157 else if(IsPtrType(type)) return PTR_SIZE; 158 158 159 else if( type==DEF_OBJECT){159 else if( type == DEF_STRUCT ){ 160 160 CClass *pobj_c; 161 161 pobj_c=(CClass *)lpIndex; 162 if(!pobj_c) return 0; 162 if(!pobj_c){ 163 SetError(300,NULL,cp); 164 return 0; 165 } 166 163 167 return pobj_c->GetSize(); 168 } 169 170 else if(type==DEF_OBJECT){ 171 return PTR_SIZE; 164 172 } 165 173 else{ … … 232 240 if(pobj_c){ 233 241 *lpNum=(LONG_PTR)pobj_c; 234 return DEF_OBJECT; 242 243 if( pobj_c->IsStructure() ){ 244 return DEF_STRUCT; 245 } 246 else{ 247 return DEF_OBJECT; 248 } 235 249 } 236 250 … … 282 296 283 297 //オブジェクト 284 else if(type==DEF_OBJECT ){298 else if(type==DEF_OBJECT || type==DEF_STRUCT){ 285 299 if(lpIndex==0) lstrcpy(name,"non"); 286 300 else{ … … 296 310 else{ 297 311 extern PROCPTRINFO *pProcPtrInfo; 298 if(pProcPtrInfo[lpIndex].ReturnType== -1)312 if(pProcPtrInfo[lpIndex].ReturnType==DEF_NON) 299 313 lstrcpy(name,"*Sub"); 300 314 else lstrcpy(name,"*Function"); … … 316 330 } 317 331 318 bool FormatUseProcReturnObject( const char *term, char *procName, char *parameter, int &RefType, char *member ){332 bool FormatUseProcReturnObject( const char *term, char *procName, char *parameter, CClass::RefType &refType, char *member ){ 319 333 int p1 = 0, p2 = 0; 320 334 … … 323 337 if( term[i] == '[' ){ 324 338 i = JumpStringInBracket( term, i + 1 ); 339 if( term[i] == '\0' ) break; 325 340 continue; 326 341 } … … 328 343 int temp_p = i; 329 344 i = JumpStringInPare( term, i + 1 ) + 1; 345 if( term[i] == '\0' ) break; 330 346 if( term[i] == '.' 331 347 || term[i] == 1 && term[i] == ESC_PSMEM ){ … … 348 364 //参照タイプ 349 365 if( term[p2] == '.' ){ 350 RefType = DEF_OBJECT;366 refType = CClass::Dot; 351 367 } 352 368 else{ 353 RefType = DEF_PTR_OBJECT;369 refType = CClass::Pointer; 354 370 p2++; 355 371 } … … 361 377 } 362 378 363 BOOL GetVarFormatString(char *buffer,char *array,char *array2,char *NestMember, int *pRefType){379 BOOL GetVarFormatString(char *buffer,char *array,char *array2,char *NestMember,CClass::RefType &refType){ 364 380 extern int cp; 365 381 int i,i2,i3; … … 369 385 array2[0]=0; 370 386 NestMember[0]=0; 371 *pRefType=0;372 387 for(i=0;;i++){ 373 388 if(buffer[i]=='\"'){ … … 428 443 if(buffer[i]=='.'){ 429 444 lstrcpy(NestMember,buffer+i+1); 430 *pRefType=DEF_OBJECT;445 refType = CClass::Dot; 431 446 buffer[i]=0; 432 447 break; … … 434 449 if(buffer[i]==1&&buffer[i+1]==ESC_PSMEM){ 435 450 lstrcpy(NestMember,buffer+i+2); 436 *pRefType=DEF_PTR_OBJECT;451 refType = CClass::Pointer; 437 452 buffer[i]=0; 438 453 break; … … 614 629 char lpPtrOffset[VN_SIZE]; //第2次配列 615 630 char NestMember[VN_SIZE]; //入れ子メンバ 616 int object_type; //"."参照のときは0、"->"参照のときは1631 CClass::RefType refType = CClass::Non; 617 632 lstrcpy(VarName,member); 618 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember, &object_type)) return 0;633 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return 0; 619 634 620 635 for(i=0;i<pobj_c->iMemberNum;i++){ … … 664 679 } 665 680 666 if( object_type){681 if( refType != CClass::Non ){ 667 682 //入れ子構造の場合 668 683 … … 704 719 705 720 706 int RefType;707 if( FormatUseProcReturnObject( variable, VarName, array, RefType, member ) ){721 CClass::RefType refType; 722 if( FormatUseProcReturnObject( variable, VarName, array, refType, member ) ){ 708 723 // 戻り値オブジェクトのメンバを直接参照しているとき 709 724 //例: func().member … … 723 738 724 739 lstrcpy(VarName,variable); 725 GetVarFormatString(VarName,array,lpPtrOffset,member, &RefType);740 GetVarFormatString(VarName,array,lpPtrOffset,member,refType); 726 741 727 742 int *pSubScripts; … … 825 840 char tempMember[VN_SIZE]; 826 841 char tempArray[VN_SIZE]; 827 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember,&i); 842 { 843 CClass::RefType refType; 844 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember,refType); 845 } 828 846 829 847 char temp2[VN_SIZE]; … … 897 915 898 916 if(member[0]){ 899 if(NATURAL_TYPE(type)==DEF_OBJECT) 900 return GetMemberType((CClass *)lpIndex,member,plpIndex,0,bError); 917 if( NATURAL_TYPE(type)==DEF_OBJECT 918 || NATURAL_TYPE(type)==DEF_STRUCT){ 919 return GetMemberType((CClass *)lpIndex,member,plpIndex,0,bError); 920 } 901 921 } 902 922 … … 921 941 } 922 942 923 BOOL GetVarOffsetReadOnly(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss ){943 BOOL GetVarOffsetReadOnly(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss ){ 924 944 //読み取り専用で変数へアクセス 925 945 return GetVarOffset( … … 932 952 pss); 933 953 } 934 BOOL GetVarOffsetReadWrite(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss ){954 BOOL GetVarOffsetReadWrite(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss ){ 935 955 //読み書き両用で変数へアクセス 936 956 return GetVarOffset( … … 1095 1115 } 1096 1116 1117 /* 1118 TODO: 消す 1097 1119 if( pTypeInfo->type == DEF_OBJECT && InitBuf[0] != '\0' && InitBuf[0] != '[' && isRef == false ){ 1098 1120 if( pTypeInfo->u.pobj_Class->GetCopyConstructorMethod() ){ … … 1101 1123 InitBuf[0] = 0; 1102 1124 } 1103 } 1125 }*/ 1104 1126 1105 1127 GetArrange(variable,VarName,SubScripts); … … 1191 1213 lstrcpy(pVar->ConstractParameter,ConstractParameter); 1192 1214 1193 if(InitBuf[0]||dwFlag==DIMFLAG_INITDEBUGVAR){1194 //初期バッファがあるとき1195 pVar->offset=AllInitGlobalVarSize;1196 AllInitGlobalVarSize+=VarSize;1197 }1198 else{1199 //初期バッファがないとき1200 pVar->offset=AllGlobalVarSize | 0x80000000;1201 AllGlobalVarSize+=VarSize;1202 }1203 1204 1215 //レキシカルスコープ 1205 1216 pVar->ScopeLevel=obj_LexScopes.GetNowLevel(); … … 1210 1221 pVar->source_code_address=cp; 1211 1222 1212 //初期バッファにデータをセット 1213 extern BYTE *initGlobalBuf; 1214 initGlobalBuf=(BYTE *)HeapReAlloc(hHeap, 1215 HEAP_ZERO_MEMORY, 1216 initGlobalBuf, 1217 AllInitGlobalVarSize); 1223 //アラインメントを考慮 1224 int alignment = 0; 1225 if( pVar->type==DEF_STRUCT ){ 1226 alignment = pVar->u.pobj_c->iAlign; 1227 } 1228 1229 if(InitBuf[0]||dwFlag==DIMFLAG_INITDEBUGVAR){ 1230 //初期バッファがあるとき 1231 1232 if( alignment ){ 1233 if( AllInitGlobalVarSize % alignment ){ 1234 AllInitGlobalVarSize += alignment - (AllInitGlobalVarSize % alignment); 1235 } 1236 } 1237 1238 pVar->offset=AllInitGlobalVarSize; 1239 AllInitGlobalVarSize+=VarSize; 1240 } 1241 else{ 1242 //初期バッファがないとき 1243 1244 if( alignment ){ 1245 if( AllGlobalVarSize % alignment ){ 1246 AllGlobalVarSize += alignment - (AllGlobalVarSize % alignment); 1247 } 1248 } 1249 1250 pVar->offset=AllGlobalVarSize | 0x80000000; 1251 AllGlobalVarSize+=VarSize; 1252 } 1253 1218 1254 if(InitBuf[0]){ 1219 i f( pVar->type == DEF_OBJECT && InitBuf[0] != '[' ){1220 //単発式が初期値のオブジェクトの場合1221 //初期 値をコピーコンストラクタに渡す1222 1223 i f( isRef ){1224 SetRefVariable( name, InitBuf );1225 }1226 }1227 else{ 1228 intresult = SetInitGlobalData(pVar->offset,1255 int result = 0; 1256 if( pVar->type != DEF_OBJECT ){ 1257 //初期バッファにデータをセット 1258 extern BYTE *initGlobalBuf; 1259 initGlobalBuf=(BYTE *)HeapReAlloc(hHeap, 1260 HEAP_ZERO_MEMORY, 1261 initGlobalBuf, 1262 AllInitGlobalVarSize); 1263 1264 result = SetInitGlobalData(pVar->offset, 1229 1265 pVar->type, 1230 1266 pVar->u.index, 1231 1267 pVar->SubScripts, 1232 1268 InitBuf); 1233 1234 if(!result){ 1235 //動的な式だった場合は代入演算を行う1236 1237 //初期代入時のみ、書き込みアクセスを許可する 1238 bool bConstBack = pVar->bConst;1239 pVar->bConst = false;1240 1241 //代入 1242 char temporary[8192];1243 sprintf(temporary,"%s=%s",name,InitBuf);1244 OpcodeCalc(temporary);1245 1246 //アクセス制限を元に戻す 1247 pVar->bConst = bConstBack;1248 }1269 } 1270 1271 if(!result){ 1272 //動的な式だった場合は代入演算を行う 1273 1274 //初期代入時のみ、書き込みアクセスを許可する 1275 bool bConstBack = pVar->bConst; 1276 pVar->bConst = false; 1277 1278 //代入 1279 char temporary[8192]; 1280 sprintf(temporary,"%s=%s",name,InitBuf); 1281 OpcodeCalc(temporary); 1282 1283 //アクセス制限を元に戻す 1284 pVar->bConst = bConstBack; 1249 1285 } 1250 1286 } … … 1260 1296 1261 1297 /* 1298 TODO: 消す 1262 1299 if(pTypeInfo->type==DEF_OBJECT){ 1263 1300 //利用対象のクラスコンストラクタ、デストラクタに使用チェックをつける
Note:
See TracChangeset
for help on using the changeset viewer.