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