| 1 | #include "stdafx.h"
|
|---|
| 2 |
|
|---|
| 3 | #include "Opcode.h"
|
|---|
| 4 |
|
|---|
| 5 | //変数
|
|---|
| 6 | // TODO: xml未完成
|
|---|
| 7 | int AllLocalVarSize;
|
|---|
| 8 |
|
|---|
| 9 | using namespace ActiveBasic::Compiler;
|
|---|
| 10 |
|
|---|
| 11 | void SetRelativeOffset( Type &resultType, RELATIVE_VAR *pRelativeVar,const char *lpPtrOffset){
|
|---|
| 12 | PushLongVariable(pRelativeVar);
|
|---|
| 13 |
|
|---|
| 14 | Type type;
|
|---|
| 15 | NumOpe( lpPtrOffset, Type(), type );
|
|---|
| 16 | ChangeTypeToLong( type.GetBasicType() );
|
|---|
| 17 |
|
|---|
| 18 | //pop ebx
|
|---|
| 19 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 20 |
|
|---|
| 21 | if( resultType.PtrLevel() ){
|
|---|
| 22 | resultType.PtrLevelDown();
|
|---|
| 23 |
|
|---|
| 24 | int typeSize = resultType.GetSize();
|
|---|
| 25 | if(typeSize>=2){
|
|---|
| 26 | //imul ebx,i2
|
|---|
| 27 | compiler.codeGenerator.op_imul_RV( REG_EBX, typeSize );
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
| 30 | else{
|
|---|
| 31 | //エラー
|
|---|
| 32 | compiler.errorMessenger.Output(1,NULL,cp);
|
|---|
| 33 | return;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | //pop ecx
|
|---|
| 37 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 38 |
|
|---|
| 39 | //add ecx,ebx
|
|---|
| 40 | compiler.codeGenerator.op_add_RR( REG_ECX, REG_EBX );
|
|---|
| 41 | }
|
|---|
| 42 | void SetRelativeOffset( RELATIVE_VAR &relativeVar ){
|
|---|
| 43 | if(relativeVar.dwKind==VAR_DIRECTMEM){
|
|---|
| 44 | //mov ecx,dword ptr[ecx]
|
|---|
| 45 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_ECX, 0, MOD_BASE );
|
|---|
| 46 | }
|
|---|
| 47 | else{
|
|---|
| 48 | //直接参照に切り替え
|
|---|
| 49 | SetVarPtrToEax(&relativeVar);
|
|---|
| 50 | relativeVar.dwKind=VAR_DIRECTMEM;
|
|---|
| 51 |
|
|---|
| 52 | //mov ecx,dword ptr[eax]
|
|---|
| 53 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_EAX, 0, MOD_BASE );
|
|---|
| 54 | }
|
|---|
| 55 | }
|
|---|
| 56 | bool GetArrayOffset(const Subscripts &subscripts,char *array, const Type &type){
|
|---|
| 57 | extern HANDLE hHeap;
|
|---|
| 58 | int i,i2,i3,i4;
|
|---|
| 59 | char temporary[VN_SIZE],*pParm[MAX_PARMS];
|
|---|
| 60 |
|
|---|
| 61 | for(i=0,i2=0,i3=0;;i++,i2++){
|
|---|
| 62 | if(array[i]=='('){
|
|---|
| 63 | i4=GetStringInPare(temporary+i2,array+i);
|
|---|
| 64 | i+=i4-1;
|
|---|
| 65 | i2+=i4-1;
|
|---|
| 66 | continue;
|
|---|
| 67 | }
|
|---|
| 68 | if(array[i]=='['){
|
|---|
| 69 | i4=GetStringInBracket(temporary+i2,array+i);
|
|---|
| 70 | i+=i4-1;
|
|---|
| 71 | i2+=i4-1;
|
|---|
| 72 | continue;
|
|---|
| 73 | }
|
|---|
| 74 | if(array[i]==','||array[i]=='\0'){
|
|---|
| 75 | if( i3 >= (int)subscripts.size() )
|
|---|
| 76 | {
|
|---|
| 77 | for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]);
|
|---|
| 78 | return 0;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | temporary[i2]=0;
|
|---|
| 82 |
|
|---|
| 83 | pParm[i3]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
|
|---|
| 84 | lstrcpy(pParm[i3],temporary);
|
|---|
| 85 |
|
|---|
| 86 | i3++;
|
|---|
| 87 |
|
|---|
| 88 | if(array[i]=='\0'){
|
|---|
| 89 | if( i3 < (int)subscripts.size() )
|
|---|
| 90 | {
|
|---|
| 91 | for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]);
|
|---|
| 92 | return 0;
|
|---|
| 93 | }
|
|---|
| 94 | break;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | i2=-1;
|
|---|
| 98 | continue;
|
|---|
| 99 | }
|
|---|
| 100 | temporary[i2]=array[i];
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | //push ecx
|
|---|
| 104 | compiler.codeGenerator.op_push(REG_ECX);
|
|---|
| 105 |
|
|---|
| 106 | //push 0
|
|---|
| 107 | compiler.codeGenerator.op_push_V(0);
|
|---|
| 108 |
|
|---|
| 109 | for(i=i3-1;i>=0;i--){
|
|---|
| 110 | Type tempType;
|
|---|
| 111 | bool isNeedHeapFreeStructure;
|
|---|
| 112 | NumOpe( pParm[i], Type( DEF_LONG ), tempType, &isNeedHeapFreeStructure );
|
|---|
| 113 | if( tempType.IsObject() )
|
|---|
| 114 | {
|
|---|
| 115 | //キャスト演算子のオーバーロードに対応する
|
|---|
| 116 | CallCastOperatorProc(
|
|---|
| 117 | tempType,
|
|---|
| 118 | isNeedHeapFreeStructure, Type(DEF_LONG) );
|
|---|
| 119 | tempType.SetBasicType( DEF_LONG );
|
|---|
| 120 | }
|
|---|
| 121 | ChangeTypeToLong( tempType.GetBasicType() );
|
|---|
| 122 |
|
|---|
| 123 | //pop eax
|
|---|
| 124 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 125 |
|
|---|
| 126 | for( i2=i+1, i4=1; i2<i3; i2++ )
|
|---|
| 127 | {
|
|---|
| 128 | i4*=subscripts[i2]+1;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | //imul eax,i4
|
|---|
| 132 | compiler.codeGenerator.op_imul_RV( REG_EAX, i4 );
|
|---|
| 133 |
|
|---|
| 134 | //add dword ptr[esp],eax
|
|---|
| 135 | compiler.codeGenerator.PutOld(
|
|---|
| 136 | (char)0x01,
|
|---|
| 137 | (char)0x04,
|
|---|
| 138 | (char)0x24
|
|---|
| 139 | );
|
|---|
| 140 |
|
|---|
| 141 | HeapDefaultFree(pParm[i]);
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | //pop eax
|
|---|
| 145 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 146 |
|
|---|
| 147 | //imul eax,TypeSize
|
|---|
| 148 | compiler.codeGenerator.op_imul_RV( REG_EAX, type.GetSize() );
|
|---|
| 149 |
|
|---|
| 150 | //pop ecx
|
|---|
| 151 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 152 |
|
|---|
| 153 | //add ecx,eax
|
|---|
| 154 | compiler.codeGenerator.op_add_RR( REG_ECX, REG_EAX );
|
|---|
| 155 |
|
|---|
| 156 | return 1;
|
|---|
| 157 | }
|
|---|
| 158 | bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const Type &classType, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess)
|
|---|
| 159 | {
|
|---|
| 160 | const CClass &objClass = classType.GetClass();
|
|---|
| 161 |
|
|---|
| 162 | //////////////////////////////////////
|
|---|
| 163 | // クラス、配列の構成要素を解析する
|
|---|
| 164 | //////////////////////////////////////
|
|---|
| 165 |
|
|---|
| 166 | char VarName[VN_SIZE]; //変数名
|
|---|
| 167 | char array[VN_SIZE]; //第1次配列
|
|---|
| 168 | char lpPtrOffset[VN_SIZE]; //第2次配列
|
|---|
| 169 | char NestMember[VN_SIZE]; //入れ子メンバ
|
|---|
| 170 | ReferenceKind refType;
|
|---|
| 171 | lstrcpy(VarName,member);
|
|---|
| 172 | if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return false;
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 | ////////////////////////////
|
|---|
| 176 | // メンバオフセットを取得
|
|---|
| 177 | ////////////////////////////
|
|---|
| 178 |
|
|---|
| 179 | const Member *pMember = objClass.FindDynamicMember( VarName );
|
|---|
| 180 | if( !pMember )
|
|---|
| 181 | {
|
|---|
| 182 | if(isErrorEnabled) compiler.errorMessenger.Output(103,VarName,cp);
|
|---|
| 183 | return false;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | int offset = objClass.GetMemberOffset( VarName );
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 | //アクセシビリティをチェック
|
|---|
| 190 | if( compiler.IsCompilingClass() && &objClass == &compiler.GetCompilingClass() ){
|
|---|
| 191 | //同一クラスオブジェクトの場合はプライベートアクセスを容認する
|
|---|
| 192 | if(pMember->IsNoneAccess()){
|
|---|
| 193 | if(isErrorEnabled) compiler.errorMessenger.Output(107,VarName,cp);
|
|---|
| 194 | return false;
|
|---|
| 195 | }
|
|---|
| 196 | }
|
|---|
| 197 | else{
|
|---|
| 198 | if((bPrivateAccess==0&&pMember->IsPrivate())||
|
|---|
| 199 | pMember->IsNoneAccess()){
|
|---|
| 200 | if(isErrorEnabled) compiler.errorMessenger.Output(107,VarName,cp);
|
|---|
| 201 | return false;
|
|---|
| 202 | }
|
|---|
| 203 | else if(bPrivateAccess==0&&pMember->IsProtected()){
|
|---|
| 204 | if(isErrorEnabled) compiler.errorMessenger.Output(108,VarName,cp);
|
|---|
| 205 | return false;
|
|---|
| 206 | }
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | //Const定義の場合は書き込みアクセスを制限する
|
|---|
| 210 | //※コンストラクタをコンパイル中の場合は例外的に許可する
|
|---|
| 211 | if( pMember->IsConst() && //定数メンバである
|
|---|
| 212 | isWriteAccess && //書き込みアクセスを要求されている
|
|---|
| 213 | objClass.IsCompilingConstructor() == false //コンストラクタ コンパイル中を除く
|
|---|
| 214 | ){
|
|---|
| 215 | //Const定義の変数に書き込みアクセスをしようとした場合
|
|---|
| 216 | compiler.errorMessenger.Output(61,VarName,cp);
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | resultType = pMember->GetType();
|
|---|
| 220 |
|
|---|
| 221 | // 型パラメータを解決
|
|---|
| 222 | ResolveFormalGenericTypeParameter( resultType, classType );
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 | //ポインタ変数の場合
|
|---|
| 226 | if( resultType.IsPointer() ){
|
|---|
| 227 | if( pMember->GetSubscripts().size() == 0 ){
|
|---|
| 228 | lstrcpy(lpPtrOffset,array);
|
|---|
| 229 | array[0]=0;
|
|---|
| 230 | }
|
|---|
| 231 | }
|
|---|
| 232 | else{
|
|---|
| 233 | if(lpPtrOffset[0]){
|
|---|
| 234 | if(isErrorEnabled) compiler.errorMessenger.Output(16,member,cp);
|
|---|
| 235 | return false;
|
|---|
| 236 | }
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | if(offset){
|
|---|
| 240 | //add ecx,offset
|
|---|
| 241 | compiler.codeGenerator.op_add_RV( REG_ECX, offset );
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | if(array[0]){
|
|---|
| 245 | //配列オフセット
|
|---|
| 246 | if(!GetArrayOffset(pMember->GetSubscripts(),array,pMember->GetType())){
|
|---|
| 247 | if(isErrorEnabled) compiler.errorMessenger.Output(14,member,cp);
|
|---|
| 248 | return false;
|
|---|
| 249 | }
|
|---|
| 250 | }
|
|---|
| 251 | else if( pMember->GetSubscripts().size() > 0 ){
|
|---|
| 252 | resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR );
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | if(NestMember[0]){
|
|---|
| 256 | //入れ子構造の場合
|
|---|
| 257 |
|
|---|
| 258 | if( resultType.IsObject() || resultType.IsStruct() ){
|
|---|
| 259 | if( refType != RefDot ){
|
|---|
| 260 | if(isErrorEnabled) compiler.errorMessenger.Output(104,member,cp);
|
|---|
| 261 | return false;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | if( resultType.IsObject() ){
|
|---|
| 265 | // 参照内容へのポインタを抽出
|
|---|
| 266 | SetRelativeOffset( *pRelativeVar );
|
|---|
| 267 | }
|
|---|
| 268 | }
|
|---|
| 269 | else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){
|
|---|
| 270 | //構造体ポインタ型メンバ変数
|
|---|
| 271 |
|
|---|
| 272 | if(lpPtrOffset[0]){
|
|---|
| 273 | //pObj[n].member
|
|---|
| 274 | if( ( resultType.IsObjectPtr() || resultType.IsStructPtr() )
|
|---|
| 275 | && refType != RefDot ){
|
|---|
| 276 | if(isErrorEnabled) compiler.errorMessenger.Output(104,member,cp);
|
|---|
| 277 | return false;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | //直接参照に切り替え
|
|---|
| 281 | SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
|
|---|
| 282 | pRelativeVar->dwKind=VAR_DIRECTMEM;
|
|---|
| 283 |
|
|---|
| 284 | lpPtrOffset[0]=0;
|
|---|
| 285 | }
|
|---|
| 286 | else{
|
|---|
| 287 | //pObj->member
|
|---|
| 288 | if( ( resultType.IsObjectPtr() || resultType.IsStructPtr() )
|
|---|
| 289 | && refType != RefPointer ){
|
|---|
| 290 | if(isErrorEnabled) compiler.errorMessenger.Output(104,member,cp);
|
|---|
| 291 | return false;
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | SetRelativeOffset( *pRelativeVar );
|
|---|
| 295 | }
|
|---|
| 296 | }
|
|---|
| 297 | else if( resultType.GetBasicType() == MAKE_PTR_TYPE(DEF_OBJECT,2)
|
|---|
| 298 | || resultType.GetBasicType() == MAKE_PTR_TYPE(DEF_STRUCT,2)){
|
|---|
| 299 | //構造体ポインタのポインタ型メンバ変数
|
|---|
| 300 |
|
|---|
| 301 | if(lpPtrOffset[0]){
|
|---|
| 302 | //ppObj[n]->member
|
|---|
| 303 | if( refType != RefPointer ){
|
|---|
| 304 | if(isErrorEnabled) compiler.errorMessenger.Output(104,member,cp);
|
|---|
| 305 | return false;
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | //直接参照に切り替え
|
|---|
| 309 | SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
|
|---|
| 310 | pRelativeVar->dwKind=VAR_DIRECTMEM;
|
|---|
| 311 |
|
|---|
| 312 | lpPtrOffset[0]=0;
|
|---|
| 313 |
|
|---|
| 314 | //mov ecx,dword ptr[ecx]
|
|---|
| 315 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_ECX, 0, MOD_BASE );
|
|---|
| 316 | }
|
|---|
| 317 | else{
|
|---|
| 318 | if(isErrorEnabled) compiler.errorMessenger.Output(104,member,cp);
|
|---|
| 319 | return false;
|
|---|
| 320 | }
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | if(!_member_offset(
|
|---|
| 324 | isErrorEnabled,
|
|---|
| 325 | isWriteAccess,
|
|---|
| 326 | pMember->GetType(),
|
|---|
| 327 | NestMember,
|
|---|
| 328 | pRelativeVar,
|
|---|
| 329 | resultType,
|
|---|
| 330 | 0)) return false;
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | if(lpPtrOffset[0]){
|
|---|
| 334 | SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
|
|---|
| 335 | pRelativeVar->dwKind=VAR_DIRECTMEM;
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | return true;
|
|---|
| 339 | }
|
|---|
| 340 |
|
|---|
| 341 | int LocalVar_ThisPtrOffset;
|
|---|
| 342 | void SetThisPtrToReg(int reg){
|
|---|
| 343 | //自身のオブジェクトのThisポインタをregにコピー
|
|---|
| 344 |
|
|---|
| 345 | RELATIVE_VAR RelativeVar;
|
|---|
| 346 | RelativeVar.dwKind=VAR_LOCAL;
|
|---|
| 347 | RelativeVar.bOffsetOffset=0;
|
|---|
| 348 | RelativeVar.offset=-LocalVar_ThisPtrOffset;
|
|---|
| 349 |
|
|---|
| 350 | SetReg_WholeVariable(Type(DEF_PTR_VOID),&RelativeVar,reg);
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts ){
|
|---|
| 354 | char variable[VN_SIZE];
|
|---|
| 355 |
|
|---|
| 356 | if(NameBuffer[0]=='.'){
|
|---|
| 357 | GetWithName(variable);
|
|---|
| 358 | lstrcat(variable,NameBuffer);
|
|---|
| 359 | }
|
|---|
| 360 | else lstrcpy(variable,NameBuffer);
|
|---|
| 361 |
|
|---|
| 362 | // 名前空間を分離
|
|---|
| 363 | char namespaceStr[VN_SIZE]="", simpleName[VN_SIZE];
|
|---|
| 364 | compiler.GetObjectModule().meta.GetNamespaces().SplitNamespace( variable, namespaceStr, simpleName );
|
|---|
| 365 |
|
|---|
| 366 | // 先頭オブジェクトまたはクラス名と入れ子メンバに分割
|
|---|
| 367 | ReferenceKind refType;
|
|---|
| 368 | char member[VN_SIZE],array[VN_SIZE],lpPtrOffset[VN_SIZE];
|
|---|
| 369 | GetVarFormatString(simpleName,array,lpPtrOffset,member,refType);
|
|---|
| 370 |
|
|---|
| 371 | // 名前空間を分離していた場合は結合
|
|---|
| 372 | char VarName[VN_SIZE];
|
|---|
| 373 | if( namespaceStr[0] ){
|
|---|
| 374 | sprintf( VarName, "%s.%s", namespaceStr, simpleName );
|
|---|
| 375 | }
|
|---|
| 376 | else{
|
|---|
| 377 | lstrcpy( VarName, simpleName );
|
|---|
| 378 | }
|
|---|
| 379 |
|
|---|
| 380 | const Subscripts *pSubscripts;
|
|---|
| 381 | bool bConst = false;
|
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 | if( compiler.IsLocalAreaCompiling() ){
|
|---|
| 385 | //////////////////
|
|---|
| 386 | // ローカル変数
|
|---|
| 387 | //////////////////
|
|---|
| 388 |
|
|---|
| 389 | const Variable *pVar = compiler.GetCompilingUserProc().GetLocalVars().BackSearch(
|
|---|
| 390 | LexicalAnalyzer::FullNameToSymbol( VarName ),
|
|---|
| 391 | compiler.codeGenerator.lexicalScopes.GetNowLevel()
|
|---|
| 392 | );
|
|---|
| 393 | if( pVar ){
|
|---|
| 394 | //ポインタ変数の場合
|
|---|
| 395 | if( pVar->GetType().IsPointer() ){
|
|---|
| 396 | if( !pVar->IsArray() ){
|
|---|
| 397 | lstrcpy(lpPtrOffset,array);
|
|---|
| 398 | array[0]=0;
|
|---|
| 399 | }
|
|---|
| 400 | }
|
|---|
| 401 | else{
|
|---|
| 402 | if(lpPtrOffset[0]){
|
|---|
| 403 | compiler.errorMessenger.Output(16,variable,cp);
|
|---|
| 404 | pRelativeVar->dwKind=NON_VAR;
|
|---|
| 405 | return false;
|
|---|
| 406 | }
|
|---|
| 407 | }
|
|---|
| 408 |
|
|---|
| 409 | pRelativeVar->offset=-pVar->GetOffsetAddress();
|
|---|
| 410 | pRelativeVar->bOffsetOffset=0;
|
|---|
| 411 | if( pVar->IsRef() ){
|
|---|
| 412 | // 参照型
|
|---|
| 413 | pRelativeVar->dwKind = VAR_REFLOCAL;
|
|---|
| 414 | }
|
|---|
| 415 | else pRelativeVar->dwKind=VAR_LOCAL;
|
|---|
| 416 | resultType = pVar->GetType();
|
|---|
| 417 | pSubscripts = &pVar->GetSubscripts();
|
|---|
| 418 | bConst = pVar->IsConst();
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 | /////////////////////////////////////////////////////////
|
|---|
| 422 | // ☆★☆ ジェネリクスサポート ☆★☆
|
|---|
| 423 |
|
|---|
| 424 | if( resultType.IsTypeParameter() )
|
|---|
| 425 | {
|
|---|
| 426 | // 型パラメータだったとき
|
|---|
| 427 |
|
|---|
| 428 | int ptrLevel = PTR_LEVEL( resultType.GetBasicType() );
|
|---|
| 429 |
|
|---|
| 430 | // 制約クラス(指定されていないときはObjectクラス)にセットする
|
|---|
| 431 | resultType.SetBasicType( DEF_OBJECT );
|
|---|
| 432 |
|
|---|
| 433 | for( int i=0; i<ptrLevel; i++ )
|
|---|
| 434 | {
|
|---|
| 435 | resultType.PtrLevelUp();
|
|---|
| 436 | }
|
|---|
| 437 | }
|
|---|
| 438 |
|
|---|
| 439 | //
|
|---|
| 440 | /////////////////////////////////////////////////////////
|
|---|
| 441 |
|
|---|
| 442 | goto ok;
|
|---|
| 443 | }
|
|---|
| 444 | }
|
|---|
| 445 |
|
|---|
| 446 | if( compiler.IsCompilingClass() ){
|
|---|
| 447 | //////////////////////
|
|---|
| 448 | // クラスメンバの参照
|
|---|
| 449 | //////////////////////
|
|---|
| 450 |
|
|---|
| 451 | if(lstrcmpi(variable,"This")==0){
|
|---|
| 452 | //Thisオブジェクト
|
|---|
| 453 |
|
|---|
| 454 | //Thisポインタをecxにコピー
|
|---|
| 455 | SetThisPtrToReg(REG_ECX);
|
|---|
| 456 |
|
|---|
| 457 | pRelativeVar->dwKind=VAR_DIRECTMEM;
|
|---|
| 458 |
|
|---|
| 459 | resultType.SetType( DEF_OBJECT, &compiler.GetCompilingClass() );
|
|---|
| 460 | return true;
|
|---|
| 461 | }
|
|---|
| 462 |
|
|---|
| 463 | if(memicmp(variable,"This.",5)==0){
|
|---|
| 464 | //Thisオブジェクトのメンバを参照するとき
|
|---|
| 465 | SlideString(variable+5,-5);
|
|---|
| 466 | lstrcpy(VarName,variable);
|
|---|
| 467 | }
|
|---|
| 468 | else{
|
|---|
| 469 | //クラス内の動的メンバを参照するとき(通常)
|
|---|
| 470 |
|
|---|
| 471 | if( !compiler.GetCompilingClass().HasDynamicMember( VarName ) )
|
|---|
| 472 | {
|
|---|
| 473 | goto NonClassMember;
|
|---|
| 474 | }
|
|---|
| 475 | }
|
|---|
| 476 |
|
|---|
| 477 | //Const修飾子のメソッド内でメンバ書き込みアクセスが発生したとき
|
|---|
| 478 | //(コンストラクタ、デストラクタ内を除く)
|
|---|
| 479 | const CMethod *pMethod = &compiler.GetCompilingUserProc().GetMethod();
|
|---|
| 480 | if( isWriteAccess &&
|
|---|
| 481 | pMethod->IsConst() &&
|
|---|
| 482 | compiler.GetCompilingClass().IsCompilingConstructor() == false &&
|
|---|
| 483 | compiler.GetCompilingClass().IsCompilingDestructor() == false
|
|---|
| 484 | ){
|
|---|
| 485 | compiler.errorMessenger.Output(131, NULL, cp );
|
|---|
| 486 | }
|
|---|
| 487 |
|
|---|
| 488 | /////////////////////////////
|
|---|
| 489 | // thisポインタをecxにセット
|
|---|
| 490 |
|
|---|
| 491 | //Thisポインタをecxにコピー
|
|---|
| 492 | SetThisPtrToReg(REG_ECX);
|
|---|
| 493 |
|
|---|
| 494 | pRelativeVar->dwKind=VAR_DIRECTMEM;
|
|---|
| 495 | if(!_member_offset(
|
|---|
| 496 | isErrorEnabled,
|
|---|
| 497 | isWriteAccess,
|
|---|
| 498 | Type( DEF_OBJECT, compiler.GetCompilingClass() ),
|
|---|
| 499 | variable,
|
|---|
| 500 | pRelativeVar,
|
|---|
| 501 | resultType,1)) return false;
|
|---|
| 502 | return true;
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 | NonClassMember:
|
|---|
| 506 |
|
|---|
| 507 | {
|
|---|
| 508 | const Variable *pVar;
|
|---|
| 509 |
|
|---|
| 510 | //////////////////////////
|
|---|
| 511 | // 静的ローカル変数
|
|---|
| 512 | // ※"Static.Object.Method.Variable"
|
|---|
| 513 | //////////////////////////
|
|---|
| 514 |
|
|---|
| 515 | char temporary[VN_SIZE];
|
|---|
| 516 | if( compiler.IsLocalAreaCompiling() ){
|
|---|
| 517 | GetNowStaticVarFullName(VarName,temporary);
|
|---|
| 518 |
|
|---|
| 519 | pVar = compiler.GetObjectModule().meta.GetGlobalVars().Find( LexicalAnalyzer::FullNameToSymbol( temporary ) );
|
|---|
| 520 | if( pVar ){
|
|---|
| 521 | goto GlobalOk;
|
|---|
| 522 | }
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 | //////////////////////////
|
|---|
| 527 | // クラスの静的メンバ
|
|---|
| 528 | //////////////////////////
|
|---|
| 529 |
|
|---|
| 530 | if(member[0]){
|
|---|
| 531 | lstrcpy(temporary,member);
|
|---|
| 532 |
|
|---|
| 533 | // TODO: 名前空間を考慮したコードになっていない
|
|---|
| 534 |
|
|---|
| 535 | char tempMember[VN_SIZE];
|
|---|
| 536 | char tempArray[VN_SIZE];
|
|---|
| 537 | {
|
|---|
| 538 | ReferenceKind refType;
|
|---|
| 539 | GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember, refType );
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 | const TypeDef *pTypeDef = compiler.GetObjectModule().meta.GetTypeDefs().Find(
|
|---|
| 543 | LexicalAnalyzer::FullNameToSymbol( VarName )
|
|---|
| 544 | );
|
|---|
| 545 | if( pTypeDef )
|
|---|
| 546 | {
|
|---|
| 547 | // TypeDef後の型名だったとき
|
|---|
| 548 | lstrcpy( VarName, pTypeDef->GetBaseName().c_str() );
|
|---|
| 549 | }
|
|---|
| 550 |
|
|---|
| 551 | char temp2[VN_SIZE];
|
|---|
| 552 | sprintf(temp2,"%s.%s",VarName,temporary);
|
|---|
| 553 | pVar = compiler.GetObjectModule().meta.GetGlobalVars().Find( LexicalAnalyzer::FullNameToSymbol( temp2 ) );
|
|---|
| 554 | if( pVar ){
|
|---|
| 555 | lstrcpy(member,tempMember);
|
|---|
| 556 | lstrcpy(array,tempArray);
|
|---|
| 557 | goto GlobalOk;
|
|---|
| 558 | }
|
|---|
| 559 | }
|
|---|
| 560 |
|
|---|
| 561 | if( compiler.IsCompilingClass() ){
|
|---|
| 562 | //自身のクラスから静的メンバを参照する場合
|
|---|
| 563 | char temp2[VN_SIZE];
|
|---|
| 564 | sprintf(temp2,"%s.%s",compiler.GetCompilingClass().GetName().c_str(),VarName);
|
|---|
| 565 | pVar = compiler.GetObjectModule().meta.GetGlobalVars().Find( LexicalAnalyzer::FullNameToSymbol( temp2 ) );
|
|---|
| 566 | if( pVar ){
|
|---|
| 567 | goto GlobalOk;
|
|---|
| 568 | }
|
|---|
| 569 | }
|
|---|
| 570 |
|
|---|
| 571 | /////////////////////
|
|---|
| 572 | // グローバル変数
|
|---|
| 573 | /////////////////////
|
|---|
| 574 |
|
|---|
| 575 | pVar = compiler.GetObjectModule().meta.GetGlobalVars().BackSearch(
|
|---|
| 576 | LexicalAnalyzer::FullNameToSymbol( VarName ),
|
|---|
| 577 | compiler.codeGenerator.lexicalScopes.GetNowLevel()
|
|---|
| 578 | );
|
|---|
| 579 | if( pVar ){
|
|---|
| 580 | goto GlobalOk;
|
|---|
| 581 | }
|
|---|
| 582 |
|
|---|
| 583 | if(isErrorEnabled) compiler.errorMessenger.Output(3,variable,cp);
|
|---|
| 584 | pRelativeVar->dwKind=NON_VAR;
|
|---|
| 585 | return false;
|
|---|
| 586 |
|
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 | GlobalOk:
|
|---|
| 590 | //ポインタ変数の場合
|
|---|
| 591 | if( pVar->GetType().IsPointer() ){
|
|---|
| 592 | if( !pVar->IsArray() ){
|
|---|
| 593 | lstrcpy(lpPtrOffset,array);
|
|---|
| 594 | array[0]=0;
|
|---|
| 595 | }
|
|---|
| 596 | }
|
|---|
| 597 | else{
|
|---|
| 598 | if(lpPtrOffset[0]){
|
|---|
| 599 | compiler.errorMessenger.Output(16,variable,cp);
|
|---|
| 600 | pRelativeVar->dwKind=NON_VAR;
|
|---|
| 601 | return false;
|
|---|
| 602 | }
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | pRelativeVar->offset=pVar->GetOffsetAddress();
|
|---|
| 606 | pRelativeVar->bOffsetOffset=0;
|
|---|
| 607 | if( pVar->IsRef() ){
|
|---|
| 608 | // 参照型
|
|---|
| 609 | pRelativeVar->dwKind = VAR_REFGLOBAL;
|
|---|
| 610 | }
|
|---|
| 611 | else pRelativeVar->dwKind=VAR_GLOBAL;
|
|---|
| 612 | resultType = pVar->GetType();
|
|---|
| 613 | pSubscripts=&pVar->GetSubscripts();
|
|---|
| 614 | bConst = pVar->IsConst();
|
|---|
| 615 | }
|
|---|
| 616 |
|
|---|
| 617 |
|
|---|
| 618 |
|
|---|
| 619 | ok:
|
|---|
| 620 |
|
|---|
| 621 | if( bConst && isWriteAccess ){
|
|---|
| 622 | //Const定義の変数に書き込みアクセスをしようとした場合
|
|---|
| 623 | if( resultType.IsObject() ){
|
|---|
| 624 | //オブジェクト定数
|
|---|
| 625 | compiler.errorMessenger.Output(130, VarName, cp );
|
|---|
| 626 | }
|
|---|
| 627 | else{
|
|---|
| 628 | //一般のConst変数
|
|---|
| 629 | compiler.errorMessenger.Output(61,VarName,cp);
|
|---|
| 630 | }
|
|---|
| 631 | }
|
|---|
| 632 |
|
|---|
| 633 | if( array[0] == 0 && pSubscripts->size() > 0 ){
|
|---|
| 634 | //配列の先頭ポインタを示す場合
|
|---|
| 635 | resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR );
|
|---|
| 636 |
|
|---|
| 637 | if( pResultSubscripts )
|
|---|
| 638 | {
|
|---|
| 639 | (*pResultSubscripts) = *pSubscripts;
|
|---|
| 640 | }
|
|---|
| 641 | return true;
|
|---|
| 642 | }
|
|---|
| 643 |
|
|---|
| 644 | if(array[0]||member[0]){
|
|---|
| 645 | //xor ecx,ecx(ecxを0に初期化する)
|
|---|
| 646 | //※ecxは変数ベースアドレスからの相対オフセットを示す
|
|---|
| 647 | compiler.codeGenerator.op_zero_reg(REG_ECX);
|
|---|
| 648 |
|
|---|
| 649 | pRelativeVar->bOffsetOffset=1;
|
|---|
| 650 | }
|
|---|
| 651 | if(array[0]){
|
|---|
| 652 | if(!GetArrayOffset(*pSubscripts,array,resultType)){
|
|---|
| 653 | compiler.errorMessenger.Output(14,variable,cp);
|
|---|
| 654 | pRelativeVar->dwKind=NON_VAR;
|
|---|
| 655 | return false;
|
|---|
| 656 | }
|
|---|
| 657 | }
|
|---|
| 658 | if(member[0]){
|
|---|
| 659 | if( resultType.IsObject() || resultType.IsStruct() ){
|
|---|
| 660 | //実態オブジェクトのメンバを参照(obj.member)
|
|---|
| 661 | if( refType != RefDot ){
|
|---|
| 662 | compiler.errorMessenger.Output(104,VarName,cp);
|
|---|
| 663 | pRelativeVar->dwKind=NON_VAR;
|
|---|
| 664 | return false;
|
|---|
| 665 | }
|
|---|
| 666 |
|
|---|
| 667 | if( resultType.IsObject() ){
|
|---|
| 668 | // 参照内容へのポインタを抽出
|
|---|
| 669 | SetRelativeOffset( *pRelativeVar );
|
|---|
| 670 | }
|
|---|
| 671 | }
|
|---|
| 672 | else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){
|
|---|
| 673 | //ポインタオブジェクトが示すメンバを参照
|
|---|
| 674 | if(lpPtrOffset[0]){
|
|---|
| 675 | //pObj[n].member
|
|---|
| 676 | if( refType != RefDot ){
|
|---|
| 677 | compiler.errorMessenger.Output(104,VarName,cp);
|
|---|
| 678 | pRelativeVar->dwKind=NON_VAR;
|
|---|
| 679 | return false;
|
|---|
| 680 | }
|
|---|
| 681 | SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
|
|---|
| 682 | pRelativeVar->dwKind=VAR_DIRECTMEM;
|
|---|
| 683 | }
|
|---|
| 684 | else{
|
|---|
| 685 | //pObj->member
|
|---|
| 686 | if( refType != RefPointer ){
|
|---|
| 687 | compiler.errorMessenger.Output(104,VarName,cp);
|
|---|
| 688 | pRelativeVar->dwKind=NON_VAR;
|
|---|
| 689 | return false;
|
|---|
| 690 | }
|
|---|
| 691 |
|
|---|
| 692 | SetVarPtrToEax(pRelativeVar);
|
|---|
| 693 | pRelativeVar->dwKind=VAR_DIRECTMEM;
|
|---|
| 694 |
|
|---|
| 695 | //mov ecx,dword ptr[eax]
|
|---|
| 696 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_EAX, 0, MOD_BASE );
|
|---|
| 697 | }
|
|---|
| 698 | }
|
|---|
| 699 | else if( resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_OBJECT,2) || resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_STRUCT,2)){
|
|---|
| 700 | //ポインタオブジェクトが示すメンバを参照
|
|---|
| 701 | if(lpPtrOffset[0]){
|
|---|
| 702 | //ppObj[n]->member
|
|---|
| 703 | if( refType != RefPointer ){
|
|---|
| 704 | compiler.errorMessenger.Output(104,VarName,cp);
|
|---|
| 705 | pRelativeVar->dwKind=NON_VAR;
|
|---|
| 706 | return false;
|
|---|
| 707 | }
|
|---|
| 708 |
|
|---|
| 709 | SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
|
|---|
| 710 | pRelativeVar->dwKind=VAR_DIRECTMEM;
|
|---|
| 711 |
|
|---|
| 712 |
|
|---|
| 713 | SetVarPtrToEax(pRelativeVar);
|
|---|
| 714 |
|
|---|
| 715 | //mov ecx,dword ptr[eax]
|
|---|
| 716 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_EAX, 0, MOD_BASE );
|
|---|
| 717 | }
|
|---|
| 718 | else{
|
|---|
| 719 | compiler.errorMessenger.Output(104,VarName,cp);
|
|---|
| 720 | pRelativeVar->dwKind=NON_VAR;
|
|---|
| 721 | return false;
|
|---|
| 722 | }
|
|---|
| 723 | }
|
|---|
| 724 | else{
|
|---|
| 725 | compiler.errorMessenger.Output(102,VarName,cp);
|
|---|
| 726 | pRelativeVar->dwKind=NON_VAR;
|
|---|
| 727 | return false;
|
|---|
| 728 | }
|
|---|
| 729 |
|
|---|
| 730 | Type classType( resultType );
|
|---|
| 731 |
|
|---|
| 732 | if(!_member_offset(
|
|---|
| 733 | isErrorEnabled,
|
|---|
| 734 | isWriteAccess,
|
|---|
| 735 | classType,
|
|---|
| 736 | member,pRelativeVar,resultType,0)) return false;
|
|---|
| 737 |
|
|---|
| 738 | return true;
|
|---|
| 739 | }
|
|---|
| 740 |
|
|---|
| 741 | if(lpPtrOffset[0]){
|
|---|
| 742 | SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
|
|---|
| 743 | pRelativeVar->dwKind=VAR_DIRECTMEM;
|
|---|
| 744 | }
|
|---|
| 745 |
|
|---|
| 746 | return true;
|
|---|
| 747 | }
|
|---|
| 748 |
|
|---|
| 749 | bool SetInitGlobalData(int offset,const Type &type,const Subscripts &subscripts,const char *lpszInitBuf){
|
|---|
| 750 | int i2,i3;
|
|---|
| 751 | char temporary[VN_SIZE];
|
|---|
| 752 | char InitBuf[VN_SIZE];
|
|---|
| 753 | lstrcpy( InitBuf, lpszInitBuf );
|
|---|
| 754 |
|
|---|
| 755 | if(InitBuf[0]=='['){
|
|---|
| 756 | SlideString(InitBuf+1,-1);
|
|---|
| 757 | InitBuf[lstrlen(InitBuf)-1]=0;
|
|---|
| 758 |
|
|---|
| 759 | int typeSize = type.GetSize();
|
|---|
| 760 |
|
|---|
| 761 | if( subscripts.size() > 0 ){
|
|---|
| 762 | Subscripts nestSubscripts;
|
|---|
| 763 | for( int i=1; i<(int)subscripts.size(); i++ )
|
|---|
| 764 | {
|
|---|
| 765 | nestSubscripts.push_back( subscripts[i] );
|
|---|
| 766 | }
|
|---|
| 767 |
|
|---|
| 768 | typeSize*=JumpSubScripts( nestSubscripts );
|
|---|
| 769 | {
|
|---|
| 770 | int i=0;
|
|---|
| 771 | i2=0;
|
|---|
| 772 | while(1){
|
|---|
| 773 | if( subscripts[0] < i2 ){
|
|---|
| 774 | compiler.errorMessenger.Output(41,0,cp);
|
|---|
| 775 | return 0;
|
|---|
| 776 | }
|
|---|
| 777 | i=GetOneParameter(InitBuf,i,temporary);
|
|---|
| 778 | if(!SetInitGlobalData(
|
|---|
| 779 | offset+i2*typeSize,
|
|---|
| 780 | type,
|
|---|
| 781 | nestSubscripts,
|
|---|
| 782 | temporary)) return false;
|
|---|
| 783 | i2++;
|
|---|
| 784 | if(InitBuf[i]=='\0') break;
|
|---|
| 785 | }
|
|---|
| 786 | }
|
|---|
| 787 | return true;
|
|---|
| 788 | }
|
|---|
| 789 |
|
|---|
| 790 | if(type.IsStruct()){
|
|---|
| 791 | const CClass &objClass = type.GetClass();
|
|---|
| 792 |
|
|---|
| 793 | int i = 0;
|
|---|
| 794 | BOOST_FOREACH( Member *pMember, objClass.GetDynamicMembers() ){
|
|---|
| 795 | if(InitBuf[i]=='\0'){
|
|---|
| 796 | compiler.errorMessenger.Output(41,0,cp);
|
|---|
| 797 | return false;
|
|---|
| 798 | }
|
|---|
| 799 |
|
|---|
| 800 | i=GetOneParameter(InitBuf,i,temporary);
|
|---|
| 801 |
|
|---|
| 802 | i3=objClass.GetMemberOffset( pMember->GetName().c_str() );
|
|---|
| 803 |
|
|---|
| 804 | if(!SetInitGlobalData(offset+i3,
|
|---|
| 805 | pMember->GetType(),
|
|---|
| 806 | pMember->GetSubscripts(),
|
|---|
| 807 | temporary)) return false;
|
|---|
| 808 | }
|
|---|
| 809 | return true;
|
|---|
| 810 | }
|
|---|
| 811 |
|
|---|
| 812 | compiler.errorMessenger.Output(41,0,cp);
|
|---|
| 813 | return false;
|
|---|
| 814 | }
|
|---|
| 815 |
|
|---|
| 816 |
|
|---|
| 817 | ///////////////////////////////////////
|
|---|
| 818 | // 単発式([]で囲まれていない)
|
|---|
| 819 | ///////////////////////////////////////
|
|---|
| 820 |
|
|---|
| 821 | if( subscripts.size() > 0 ){
|
|---|
| 822 | compiler.errorMessenger.Output(41,0,cp);
|
|---|
| 823 | return false;
|
|---|
| 824 | }
|
|---|
| 825 |
|
|---|
| 826 | double dbl;
|
|---|
| 827 | _int64 i64data;
|
|---|
| 828 | Type calcType;
|
|---|
| 829 |
|
|---|
| 830 | if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){
|
|---|
| 831 | //動的データだった場合
|
|---|
| 832 | return false;
|
|---|
| 833 | }
|
|---|
| 834 | if( calcType.IsReal() ){
|
|---|
| 835 | memcpy(&dbl,&i64data,sizeof(double));
|
|---|
| 836 | i64data=(_int64)dbl;
|
|---|
| 837 | }
|
|---|
| 838 | else dbl=(double)i64data;
|
|---|
| 839 |
|
|---|
| 840 | //型チェック
|
|---|
| 841 | CheckDifferentType(
|
|---|
| 842 | type,
|
|---|
| 843 | calcType,
|
|---|
| 844 | 0,0);
|
|---|
| 845 |
|
|---|
| 846 | if( type.IsDouble() ){
|
|---|
| 847 | compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
|
|---|
| 848 | offset,
|
|---|
| 849 | (const char *)&dbl,
|
|---|
| 850 | sizeof(double)
|
|---|
| 851 | );
|
|---|
| 852 | }
|
|---|
| 853 | else if( type.IsSingle() ){
|
|---|
| 854 | float flt = (float)dbl;
|
|---|
| 855 | compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
|
|---|
| 856 | offset,
|
|---|
| 857 | (const char *)&flt,
|
|---|
| 858 | sizeof(float)
|
|---|
| 859 | );
|
|---|
| 860 | }
|
|---|
| 861 | else if( type.Is64() ){
|
|---|
| 862 | compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
|
|---|
| 863 | offset,
|
|---|
| 864 | (const char *)&i64data,
|
|---|
| 865 | sizeof(_int64)
|
|---|
| 866 | );
|
|---|
| 867 | }
|
|---|
| 868 | else if( type.IsLong() || type.IsDWord() || type.IsPointer() ){
|
|---|
| 869 | if( type.GetBasicType() == typeOfPtrChar && calcType.GetIndex() == LITERAL_STRING )
|
|---|
| 870 | {
|
|---|
| 871 | //文字列定数のとき
|
|---|
| 872 |
|
|---|
| 873 | char *temp;
|
|---|
| 874 | temp=(char *)i64data;
|
|---|
| 875 | if( compiler.IsUnicode() )
|
|---|
| 876 | {
|
|---|
| 877 | i2 = compiler.GetObjectModule().dataTable.AddWString( Jenga::Common::ToWString( temp ) );
|
|---|
| 878 | }
|
|---|
| 879 | else
|
|---|
| 880 | {
|
|---|
| 881 | i2 = compiler.GetObjectModule().dataTable.AddString( temp );
|
|---|
| 882 | }
|
|---|
| 883 | HeapDefaultFree(temp);
|
|---|
| 884 |
|
|---|
| 885 | //mov eax,DataPos
|
|---|
| 886 | compiler.codeGenerator.op_mov_RV( REG_EAX, i2, Schedule::DataTable );
|
|---|
| 887 |
|
|---|
| 888 | //mov dword ptr[offset],eax
|
|---|
| 889 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, 0, offset, MOD_DISP32, Schedule::GlobalVar );
|
|---|
| 890 | }
|
|---|
| 891 | else{
|
|---|
| 892 | long l = (long)i64data;
|
|---|
| 893 | compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
|
|---|
| 894 | offset,
|
|---|
| 895 | (const char *)&l,
|
|---|
| 896 | sizeof(long)
|
|---|
| 897 | );
|
|---|
| 898 | }
|
|---|
| 899 | }
|
|---|
| 900 | else if( type.IsWord() || type.IsInteger() ){
|
|---|
| 901 | short s = (short)i64data;
|
|---|
| 902 | compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
|
|---|
| 903 | offset,
|
|---|
| 904 | (const char *)&s,
|
|---|
| 905 | sizeof(short)
|
|---|
| 906 | );
|
|---|
| 907 | }
|
|---|
| 908 | else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){
|
|---|
| 909 | char c = (char)i64data;
|
|---|
| 910 | compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
|
|---|
| 911 | offset,
|
|---|
| 912 | (const char *)&c,
|
|---|
| 913 | sizeof(char)
|
|---|
| 914 | );
|
|---|
| 915 | }
|
|---|
| 916 |
|
|---|
| 917 | return true;
|
|---|
| 918 | }
|
|---|
| 919 | bool InitLocalVar(int offset,const Type &type,const Subscripts &subscripts,const char *lpszInitBuf){
|
|---|
| 920 | int i2,i3;
|
|---|
| 921 | char temporary[VN_SIZE];
|
|---|
| 922 | char InitBuf[VN_SIZE];
|
|---|
| 923 | lstrcpy( InitBuf, lpszInitBuf );
|
|---|
| 924 |
|
|---|
| 925 | if(InitBuf[0]=='['){
|
|---|
| 926 | SlideString(InitBuf+1,-1);
|
|---|
| 927 | InitBuf[lstrlen(InitBuf)-1]=0;
|
|---|
| 928 |
|
|---|
| 929 | int typeSize = type.GetSize();
|
|---|
| 930 |
|
|---|
| 931 | if( subscripts.size() > 0 ){
|
|---|
| 932 | Subscripts nestSubscripts;
|
|---|
| 933 | for( int i=1; i<(int)subscripts.size(); i++ )
|
|---|
| 934 | {
|
|---|
| 935 | nestSubscripts.push_back( subscripts[i] );
|
|---|
| 936 | }
|
|---|
| 937 |
|
|---|
| 938 | typeSize*=JumpSubScripts( nestSubscripts );
|
|---|
| 939 | {
|
|---|
| 940 | int i=0;
|
|---|
| 941 | i2=0;
|
|---|
| 942 | while(1){
|
|---|
| 943 | if( subscripts[0] < i2 ){
|
|---|
| 944 | compiler.errorMessenger.Output(41,0,cp);
|
|---|
| 945 | return 0;
|
|---|
| 946 | }
|
|---|
| 947 | i=GetOneParameter(InitBuf,i,temporary);
|
|---|
| 948 | if(!InitLocalVar(
|
|---|
| 949 | offset+i2*typeSize,
|
|---|
| 950 | type,
|
|---|
| 951 | nestSubscripts,
|
|---|
| 952 | temporary)) return false;
|
|---|
| 953 | i2++;
|
|---|
| 954 | if(InitBuf[i]=='\0') break;
|
|---|
| 955 | }
|
|---|
| 956 | }
|
|---|
| 957 | return true;
|
|---|
| 958 | }
|
|---|
| 959 |
|
|---|
| 960 | if(type.IsStruct()){
|
|---|
| 961 | const CClass &objClass = type.GetClass();
|
|---|
| 962 |
|
|---|
| 963 | int i = 0;
|
|---|
| 964 | BOOST_FOREACH( Member *pMember, objClass.GetDynamicMembers() ){
|
|---|
| 965 | if(InitBuf[i]=='\0'){
|
|---|
| 966 | compiler.errorMessenger.Output(41,0,cp);
|
|---|
| 967 | return false;
|
|---|
| 968 | }
|
|---|
| 969 |
|
|---|
| 970 | i=GetOneParameter(InitBuf,i,temporary);
|
|---|
| 971 |
|
|---|
| 972 | i3=objClass.GetMemberOffset( pMember->GetName().c_str() );
|
|---|
| 973 |
|
|---|
| 974 | if(!InitLocalVar(offset+i3,
|
|---|
| 975 | pMember->GetType(),
|
|---|
| 976 | pMember->GetSubscripts(),
|
|---|
| 977 | temporary)) return false;
|
|---|
| 978 |
|
|---|
| 979 | if(InitBuf[i]=='\0') break;
|
|---|
| 980 | }
|
|---|
| 981 | return true;
|
|---|
| 982 | }
|
|---|
| 983 |
|
|---|
| 984 | compiler.errorMessenger.Output(41,0,cp);
|
|---|
| 985 | return false;
|
|---|
| 986 | }
|
|---|
| 987 |
|
|---|
| 988 |
|
|---|
| 989 | ///////////////////////////////////////
|
|---|
| 990 | // 単発式([]で囲まれていない)
|
|---|
| 991 | ///////////////////////////////////////
|
|---|
| 992 |
|
|---|
| 993 | if( subscripts.size() > 0 ){
|
|---|
| 994 | compiler.errorMessenger.Output(41,0,cp);
|
|---|
| 995 | return false;
|
|---|
| 996 | }
|
|---|
| 997 |
|
|---|
| 998 | double dbl;
|
|---|
| 999 | _int64 i64data;
|
|---|
| 1000 | Type calcType;
|
|---|
| 1001 |
|
|---|
| 1002 | if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){
|
|---|
| 1003 | //動的データだった場合
|
|---|
| 1004 | return false;
|
|---|
| 1005 | }
|
|---|
| 1006 | if( calcType.IsReal() ){
|
|---|
| 1007 | memcpy(&dbl,&i64data,sizeof(double));
|
|---|
| 1008 | i64data=(_int64)dbl;
|
|---|
| 1009 | }
|
|---|
| 1010 | else dbl=(double)i64data;
|
|---|
| 1011 |
|
|---|
| 1012 | //型チェック
|
|---|
| 1013 | CheckDifferentType(
|
|---|
| 1014 | type,
|
|---|
| 1015 | calcType,
|
|---|
| 1016 | 0,0);
|
|---|
| 1017 |
|
|---|
| 1018 | if( type.IsDouble() ){
|
|---|
| 1019 | //mov eax,HILONG(dbl)
|
|---|
| 1020 | compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(((char *)(&dbl))+4) );
|
|---|
| 1021 |
|
|---|
| 1022 | //mov dword ptr[ebp+offset+sizeof(long)],eax
|
|---|
| 1023 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1024 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset+sizeof(long), MOD_BASE_DISP32, Schedule::None, true )
|
|---|
| 1025 | );
|
|---|
| 1026 |
|
|---|
| 1027 | //mov eax,LOLONG(dbl)
|
|---|
| 1028 | compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(&dbl) );
|
|---|
| 1029 |
|
|---|
| 1030 | //mov dword ptr[ebp+offset],eax
|
|---|
| 1031 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1032 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset, MOD_BASE_DISP32, Schedule::None, true )
|
|---|
| 1033 | );
|
|---|
| 1034 | }
|
|---|
| 1035 | else if( type.IsSingle() ){
|
|---|
| 1036 | float flt;
|
|---|
| 1037 | flt=(float)dbl;
|
|---|
| 1038 |
|
|---|
| 1039 | //mov eax,InitValue
|
|---|
| 1040 | compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)&flt );
|
|---|
| 1041 |
|
|---|
| 1042 | //mov dword ptr[ebp+offset],eax
|
|---|
| 1043 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1044 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset, MOD_BASE_DISP32, Schedule::None, true )
|
|---|
| 1045 | );
|
|---|
| 1046 | }
|
|---|
| 1047 | else if( type.Is64() ){
|
|---|
| 1048 | //mov eax,HILONG(i64data)
|
|---|
| 1049 | compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(((char *)(&i64data))+4) );
|
|---|
| 1050 |
|
|---|
| 1051 | //mov dword ptr[ebp+offset+sizeof(long)],eax
|
|---|
| 1052 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1053 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset+sizeof(long), MOD_BASE_DISP32, Schedule::None, true )
|
|---|
| 1054 | );
|
|---|
| 1055 |
|
|---|
| 1056 | //mov eax,LOLONG(i64data)
|
|---|
| 1057 | compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(&i64data) );
|
|---|
| 1058 |
|
|---|
| 1059 | //mov dword ptr[ebp+offset],eax
|
|---|
| 1060 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1061 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset, MOD_BASE_DISP32, Schedule::None, true )
|
|---|
| 1062 | );
|
|---|
| 1063 | }
|
|---|
| 1064 | else if( type.IsDWord() || type.IsLong() || type.IsPointer() ){
|
|---|
| 1065 | if( type.GetBasicType() == typeOfPtrChar && calcType.GetIndex() == LITERAL_STRING )
|
|---|
| 1066 | {
|
|---|
| 1067 | //文字列定数のとき
|
|---|
| 1068 |
|
|---|
| 1069 | char *temp;
|
|---|
| 1070 | temp=(char *)i64data;
|
|---|
| 1071 | if( compiler.IsUnicode() )
|
|---|
| 1072 | {
|
|---|
| 1073 | i2 = compiler.GetObjectModule().dataTable.AddWString( Jenga::Common::ToWString( temp ) );
|
|---|
| 1074 | }
|
|---|
| 1075 | else
|
|---|
| 1076 | {
|
|---|
| 1077 | i2 = compiler.GetObjectModule().dataTable.AddString( temp );
|
|---|
| 1078 | }
|
|---|
| 1079 | HeapDefaultFree(temp);
|
|---|
| 1080 |
|
|---|
| 1081 | //mov eax,DataPos
|
|---|
| 1082 | compiler.codeGenerator.op_mov_RV( REG_EAX, i2, Schedule::DataTable );
|
|---|
| 1083 | }
|
|---|
| 1084 | else{
|
|---|
| 1085 | //mov eax,InitValue
|
|---|
| 1086 | compiler.codeGenerator.op_mov_RV( REG_EAX, (long)i64data );
|
|---|
| 1087 | }
|
|---|
| 1088 |
|
|---|
| 1089 | //mov dword ptr[ebp+offset],eax
|
|---|
| 1090 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1091 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset, MOD_BASE_DISP32, Schedule::None, true )
|
|---|
| 1092 | );
|
|---|
| 1093 | }
|
|---|
| 1094 | else if( type.IsWord() || type.IsInteger() ){
|
|---|
| 1095 | //mov word ptr[ebp+offset],InitValue
|
|---|
| 1096 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1097 | compiler.codeGenerator.op_mov_MV( sizeof(short), REG_EBP, offset, Schedule::None, true, (long)i64data )
|
|---|
| 1098 | );
|
|---|
| 1099 | }
|
|---|
| 1100 | else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){
|
|---|
| 1101 | //mov byte ptr[ebp+offset],InitValue
|
|---|
| 1102 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1103 | compiler.codeGenerator.op_mov_MV( sizeof(char), REG_EBP, offset, Schedule::None, true, (long)i64data )
|
|---|
| 1104 | );
|
|---|
| 1105 | }
|
|---|
| 1106 |
|
|---|
| 1107 | return true;
|
|---|
| 1108 | }
|
|---|
| 1109 |
|
|---|
| 1110 | void dim( char *VarName, const Subscripts &subscripts, const Type &type,const char *InitBuf,const char *ConstractParameter,DWORD dwFlags){
|
|---|
| 1111 | if( compiler.IsGlobalAreaCompiling() ){
|
|---|
| 1112 | /////////////////////////
|
|---|
| 1113 | // グローバル変数
|
|---|
| 1114 | /////////////////////////
|
|---|
| 1115 |
|
|---|
| 1116 | AddGlobalVariable(VarName,subscripts,type,InitBuf,ConstractParameter,dwFlags);
|
|---|
| 1117 | }
|
|---|
| 1118 | else{
|
|---|
| 1119 | /////////////////
|
|---|
| 1120 | // ローカル変数
|
|---|
| 1121 | /////////////////
|
|---|
| 1122 |
|
|---|
| 1123 | if( compiler.GetCompilingUserProc().GetLocalVars().DuplicateCheck( LexicalAnalyzer::FullNameToSymbol( VarName ), compiler.codeGenerator.lexicalScopes.GetNowLevel() ) ){
|
|---|
| 1124 | //2重定義のエラー
|
|---|
| 1125 | compiler.errorMessenger.Output(15,VarName,cp);
|
|---|
| 1126 | return;
|
|---|
| 1127 | }
|
|---|
| 1128 |
|
|---|
| 1129 | bool isConst = ( dwFlags & DIMFLAG_CONST ) ? true:false;
|
|---|
| 1130 |
|
|---|
| 1131 | Variable *pVar = new Variable(
|
|---|
| 1132 | ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( VarName ),
|
|---|
| 1133 | type,
|
|---|
| 1134 | isConst,
|
|---|
| 1135 | false,
|
|---|
| 1136 | ConstractParameter,
|
|---|
| 1137 | false
|
|---|
| 1138 | );
|
|---|
| 1139 |
|
|---|
| 1140 | if( subscripts.size() > 0 ){
|
|---|
| 1141 | //配列あり
|
|---|
| 1142 | pVar->SetArray( subscripts );
|
|---|
| 1143 | }
|
|---|
| 1144 |
|
|---|
| 1145 | //レキシカルスコープ
|
|---|
| 1146 | pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
|
|---|
| 1147 | pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
|
|---|
| 1148 | pVar->isLiving = true;
|
|---|
| 1149 |
|
|---|
| 1150 | //エラー用
|
|---|
| 1151 | pVar->source_code_address=cp;
|
|---|
| 1152 |
|
|---|
| 1153 | // 変数を追加
|
|---|
| 1154 | compiler.GetCompilingUserProc().GetLocalVars().push_back( pVar );
|
|---|
| 1155 |
|
|---|
| 1156 | //アラインメントを考慮
|
|---|
| 1157 | if( pVar->GetType().IsStruct() ){
|
|---|
| 1158 | int alignment = pVar->GetType().GetClass().GetFixedAlignment();
|
|---|
| 1159 |
|
|---|
| 1160 | if( alignment ){
|
|---|
| 1161 | if( AllLocalVarSize % alignment ){
|
|---|
| 1162 | AllLocalVarSize += alignment - (AllLocalVarSize % alignment);
|
|---|
| 1163 | }
|
|---|
| 1164 | }
|
|---|
| 1165 |
|
|---|
| 1166 | if( alignment == PTR_SIZE*2 ){
|
|---|
| 1167 | // ポインタに要するサイズよりも一回り大きなアラインメントが指定されているとき
|
|---|
| 1168 | // (例:CONTEXT構造体など)
|
|---|
| 1169 | // 呼び出し側のオフセットズレを考慮する
|
|---|
| 1170 |
|
|---|
| 1171 | if( 0 == ( compiler.GetCompilingUserProc().RealParams().GetMemorySize() + PTR_SIZE /* ret分 */ ) % alignment ){
|
|---|
| 1172 | AllLocalVarSize += PTR_SIZE;
|
|---|
| 1173 | }
|
|---|
| 1174 | }
|
|---|
| 1175 | }
|
|---|
| 1176 |
|
|---|
| 1177 | AllLocalVarSize += pVar->GetMemorySize();
|
|---|
| 1178 | pVar->SetOffsetAddress( AllLocalVarSize );
|
|---|
| 1179 |
|
|---|
| 1180 | //レキシカルスコープ
|
|---|
| 1181 | pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
|
|---|
| 1182 | pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
|
|---|
| 1183 | pVar->isLiving = true;
|
|---|
| 1184 |
|
|---|
| 1185 | if(InitBuf[0]){
|
|---|
| 1186 | //初期代入時のみ、書き込みアクセスを許可する
|
|---|
| 1187 | if( isConst ){
|
|---|
| 1188 | pVar->ConstOff();
|
|---|
| 1189 | }
|
|---|
| 1190 |
|
|---|
| 1191 | int result = 0;
|
|---|
| 1192 | if( !pVar->GetType().IsObject() ){
|
|---|
| 1193 | result = InitLocalVar(-pVar->GetOffsetAddress(),
|
|---|
| 1194 | pVar->GetType(),
|
|---|
| 1195 | pVar->GetSubscripts(),
|
|---|
| 1196 | InitBuf);
|
|---|
| 1197 | }
|
|---|
| 1198 |
|
|---|
| 1199 | if(!result){
|
|---|
| 1200 | //動的な式だった場合は代入演算を行う
|
|---|
| 1201 | char temporary[8192];
|
|---|
| 1202 | sprintf(temporary,"%s=%s",VarName,InitBuf);
|
|---|
| 1203 | OpcodeCalc(temporary);
|
|---|
| 1204 | }
|
|---|
| 1205 |
|
|---|
| 1206 | if( isConst ){
|
|---|
| 1207 | pVar->ConstOn();
|
|---|
| 1208 | }
|
|---|
| 1209 | }
|
|---|
| 1210 | else{
|
|---|
| 1211 | //push 0
|
|---|
| 1212 | compiler.codeGenerator.op_push_V(0);
|
|---|
| 1213 |
|
|---|
| 1214 | //push VarSize
|
|---|
| 1215 | compiler.codeGenerator.op_push_V( pVar->GetMemorySize() );
|
|---|
| 1216 |
|
|---|
| 1217 | //mov eax,ebp
|
|---|
| 1218 | compiler.codeGenerator.op_mov_RR( REG_EAX, REG_EBP );
|
|---|
| 1219 |
|
|---|
| 1220 | //add eax,offset
|
|---|
| 1221 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1222 | compiler.codeGenerator.op_add_RV( REG_EAX, -pVar->GetOffsetAddress(), Schedule::None, true )
|
|---|
| 1223 | );
|
|---|
| 1224 |
|
|---|
| 1225 | //push eax
|
|---|
| 1226 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 1227 |
|
|---|
| 1228 | //call FillMemory
|
|---|
| 1229 | compiler.codeGenerator.op_call( GetDeclareHash("FillMemory") );
|
|---|
| 1230 | }
|
|---|
| 1231 | }
|
|---|
| 1232 |
|
|---|
| 1233 | //New呼び出し
|
|---|
| 1234 | if( type.IsObject()
|
|---|
| 1235 | && !type.IsInterface() && !type.IsComInterface()
|
|---|
| 1236 | &&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0
|
|---|
| 1237 | &&InitBuf[0]=='\0')
|
|---|
| 1238 | {
|
|---|
| 1239 | char objectSize[255];
|
|---|
| 1240 | if( subscripts.size() == 0 ){
|
|---|
| 1241 | objectSize[0] = 0;
|
|---|
| 1242 | }
|
|---|
| 1243 | else{
|
|---|
| 1244 | if( subscripts.size() > 1 ){
|
|---|
| 1245 | compiler.errorMessenger.Output(300,NULL,cp);
|
|---|
| 1246 | }
|
|---|
| 1247 | sprintf( objectSize, "%d", subscripts[0] );
|
|---|
| 1248 | }
|
|---|
| 1249 | Operator_New( type.GetClass(), objectSize, ConstractParameter, type );
|
|---|
| 1250 |
|
|---|
| 1251 | //pop eax
|
|---|
| 1252 | compiler.codeGenerator.op_pop( REG_EAX );
|
|---|
| 1253 |
|
|---|
| 1254 | RELATIVE_VAR RelativeVar;
|
|---|
| 1255 | GetVarOffset( true, false, VarName, &RelativeVar, Type() );
|
|---|
| 1256 | if( RelativeVar.dwKind == VAR_DIRECTMEM ){
|
|---|
| 1257 | compiler.errorMessenger.OutputFatalError();
|
|---|
| 1258 | }
|
|---|
| 1259 | SetVariableFromEax( Type( DEF_OBJECT, *compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr() ), DEF_OBJECT, &RelativeVar );
|
|---|
| 1260 | }
|
|---|
| 1261 | }
|
|---|
| 1262 |
|
|---|
| 1263 | void SetVarPtrToEax(RELATIVE_VAR *pRelativeVar){
|
|---|
| 1264 | if(pRelativeVar->dwKind==VAR_GLOBAL){
|
|---|
| 1265 | if(pRelativeVar->bOffsetOffset){
|
|---|
| 1266 | //lea eax,dword ptr[ecx+offset]
|
|---|
| 1267 | compiler.codeGenerator.op_lea_RM( REG_EAX, REG_ECX, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::GlobalVar );
|
|---|
| 1268 | }
|
|---|
| 1269 | else{
|
|---|
| 1270 | //mov eax,offset
|
|---|
| 1271 | compiler.codeGenerator.op_mov_RV( REG_EAX, pRelativeVar->offset, Schedule::GlobalVar );
|
|---|
| 1272 | }
|
|---|
| 1273 | }
|
|---|
| 1274 | else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
|
|---|
| 1275 | if(pRelativeVar->bOffsetOffset){
|
|---|
| 1276 | //mov eax,ecx
|
|---|
| 1277 | compiler.codeGenerator.op_mov_RR( REG_EAX, REG_ECX );
|
|---|
| 1278 |
|
|---|
| 1279 | //add eax,dword ptr[offset]
|
|---|
| 1280 | compiler.codeGenerator.op_add_RM( sizeof(long), REG_EAX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32, Schedule::GlobalVar );
|
|---|
| 1281 | }
|
|---|
| 1282 | else{
|
|---|
| 1283 | //mov eax,dword ptr[offset]
|
|---|
| 1284 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32, Schedule::GlobalVar );
|
|---|
| 1285 | }
|
|---|
| 1286 | }
|
|---|
| 1287 | else if(pRelativeVar->dwKind==VAR_LOCAL){
|
|---|
| 1288 | if(pRelativeVar->bOffsetOffset){
|
|---|
| 1289 | //add ecx,offset
|
|---|
| 1290 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1291 | compiler.codeGenerator.op_add_RV( REG_ECX, pRelativeVar->offset, Schedule::None, true )
|
|---|
| 1292 | );
|
|---|
| 1293 |
|
|---|
| 1294 | //lea eax,dword ptr[ebp+ecx]
|
|---|
| 1295 | compiler.codeGenerator.PutOld(
|
|---|
| 1296 | (char)0x8D,
|
|---|
| 1297 | (char)0x44,
|
|---|
| 1298 | (char)0x0D,
|
|---|
| 1299 | (char)0x00
|
|---|
| 1300 | );
|
|---|
| 1301 | }
|
|---|
| 1302 | else{
|
|---|
| 1303 | //lea eax,dword ptr[ecx+offset]
|
|---|
| 1304 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1305 | compiler.codeGenerator.op_lea_RM( REG_EAX, REG_EBP, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
|
|---|
| 1306 | );
|
|---|
| 1307 | }
|
|---|
| 1308 | }
|
|---|
| 1309 | else if(pRelativeVar->dwKind==VAR_REFLOCAL){
|
|---|
| 1310 | if(pRelativeVar->bOffsetOffset){
|
|---|
| 1311 | //mov eax,ecx
|
|---|
| 1312 | compiler.codeGenerator.op_mov_RR( REG_EAX, REG_ECX );
|
|---|
| 1313 |
|
|---|
| 1314 | //add eax,dword ptr[ebp+offset]
|
|---|
| 1315 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1316 | compiler.codeGenerator.op_add_RM( sizeof(long), REG_EAX, REG_EBP, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
|
|---|
| 1317 | );
|
|---|
| 1318 | }
|
|---|
| 1319 | else{
|
|---|
| 1320 | //mov eax,dword ptr[ebp+offset]
|
|---|
| 1321 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
|---|
| 1322 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EBP, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
|
|---|
| 1323 | );
|
|---|
| 1324 | }
|
|---|
| 1325 | }
|
|---|
| 1326 | else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
|
|---|
| 1327 | //mov eax,ecx
|
|---|
| 1328 | compiler.codeGenerator.op_mov_RR( REG_EAX, REG_ECX );
|
|---|
| 1329 | }
|
|---|
| 1330 | }
|
|---|
| 1331 | void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar)
|
|---|
| 1332 | {
|
|---|
| 1333 | if( reg != REG_EAX ){
|
|---|
| 1334 | compiler.errorMessenger.OutputFatalError();
|
|---|
| 1335 | //TODO: 未完成
|
|---|
| 1336 | }
|
|---|
| 1337 | SetVarPtrToEax( pRelativeVar );
|
|---|
| 1338 | }
|
|---|
| 1339 |
|
|---|
| 1340 | bool Compile_AddGlobalRootsForGc()
|
|---|
| 1341 | {
|
|---|
| 1342 | const UserProc *pUserProc_AddGlobalRootPtr = GetClassMethod( "_System_CGarbageCollection", "AddGlobalRootPtr" );
|
|---|
| 1343 | if( !pUserProc_AddGlobalRootPtr )
|
|---|
| 1344 | {
|
|---|
| 1345 | compiler.errorMessenger.Output(3, "_System_CGarbageCollection.AddGlobalRootPtr", -1 );
|
|---|
| 1346 | return false;
|
|---|
| 1347 | }
|
|---|
| 1348 |
|
|---|
| 1349 | BOOST_FOREACH( const Variable *pVar, compiler.GetObjectModule().meta.GetGlobalVars() ){
|
|---|
| 1350 | if( pVar->GetType().IsObject() || pVar->GetType().IsPointer() || pVar->GetType().IsStruct() ){
|
|---|
| 1351 | // オブジェクトまたはポインタだったとき
|
|---|
| 1352 | // ※構造体も含む(暫定対応)
|
|---|
| 1353 |
|
|---|
| 1354 | // 変数領域に要するLONG_PTR単位の個数を引き渡す
|
|---|
| 1355 | compiler.codeGenerator.op_push_V( pVar->GetMemorySize()/PTR_SIZE );
|
|---|
| 1356 |
|
|---|
| 1357 |
|
|---|
| 1358 | /////////////////////////////
|
|---|
| 1359 | // ルートポインタを引き渡す
|
|---|
| 1360 |
|
|---|
| 1361 | //mov eax,offset
|
|---|
| 1362 | compiler.codeGenerator.op_mov_RV(REG_EAX,(int)pVar->GetOffsetAddress(), Schedule::GlobalVar );
|
|---|
| 1363 |
|
|---|
| 1364 | //push eax
|
|---|
| 1365 | compiler.codeGenerator.op_push( REG_EAX );
|
|---|
| 1366 |
|
|---|
| 1367 | //
|
|---|
| 1368 | /////////////////////////////
|
|---|
| 1369 |
|
|---|
| 1370 |
|
|---|
| 1371 | /////////////////////////////
|
|---|
| 1372 | // Thisポインタを引き渡す
|
|---|
| 1373 |
|
|---|
| 1374 | SetThisPtrToReg(REG_EAX);
|
|---|
| 1375 |
|
|---|
| 1376 | //push eax
|
|---|
| 1377 | compiler.codeGenerator.op_push( REG_EAX );
|
|---|
| 1378 |
|
|---|
| 1379 | //
|
|---|
| 1380 | /////////////////////////////
|
|---|
| 1381 |
|
|---|
| 1382 |
|
|---|
| 1383 | // call AddGlobalRootPtr
|
|---|
| 1384 | compiler.codeGenerator.op_call( pUserProc_AddGlobalRootPtr );
|
|---|
| 1385 | }
|
|---|
| 1386 | }
|
|---|
| 1387 |
|
|---|
| 1388 | return true;
|
|---|
| 1389 | }
|
|---|