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