| 1 | #include "stdafx.h" | 
|---|
| 2 |  | 
|---|
| 3 | #include <Compiler.h> | 
|---|
| 4 | #include <Variable.h> | 
|---|
| 5 |  | 
|---|
| 6 | /* | 
|---|
| 7 | TODO: 消す | 
|---|
| 8 | bool Variable::IsEqualSymbol( const Symbol &symbol, bool isSupportStaticMember ) const | 
|---|
| 9 | { | 
|---|
| 10 | if( GetName() == symbol.GetName() | 
|---|
| 11 | && compiler.GetNamespaceSupporter().IsSameAreaNamespace( this->GetNamespaceScopes(), symbol.GetNamespaceScopes() ) ) | 
|---|
| 12 | { | 
|---|
| 13 | return true; | 
|---|
| 14 | } | 
|---|
| 15 |  | 
|---|
| 16 | if( isSupportStaticMember && symbol.GetNamespaceScopes().size() >= 1 ) | 
|---|
| 17 | { | 
|---|
| 18 | // 静的メンバを考慮 | 
|---|
| 19 | NamespaceScopes namespaceScopes( symbol.GetNamespaceScopes() ); | 
|---|
| 20 | string name = namespaceScopes[namespaceScopes.size()-1] + "." + symbol.GetName(); | 
|---|
| 21 | namespaceScopes.pop_back(); | 
|---|
| 22 |  | 
|---|
| 23 | return IsEqualSymbol( Symbol( namespaceScopes, name ), false ); | 
|---|
| 24 | } | 
|---|
| 25 | return false; | 
|---|
| 26 | }*/ | 
|---|
| 27 |  | 
|---|
| 28 |  | 
|---|
| 29 | bool Variables::DuplicateCheck( const Symbol &symbol ) const | 
|---|
| 30 | { | 
|---|
| 31 | //レキシカルスコープを考慮して重複判定 | 
|---|
| 32 | for( int i=(int)this->size()-1; i>=0 ; i-- ){ | 
|---|
| 33 | const Variable *pVar = (*this)[i]; | 
|---|
| 34 | if( pVar->isLiving                                          //現在のスコープで有効なもの | 
|---|
| 35 | && pVar->GetScopeLevel() == compiler.codeGenerator.lexicalScopes.GetNowLevel()  //現在のスコープと同一レベル | 
|---|
| 36 | ) | 
|---|
| 37 | { | 
|---|
| 38 | if( pVar->IsEqualSymbol( symbol ) ){ | 
|---|
| 39 | return true; | 
|---|
| 40 | } | 
|---|
| 41 | } | 
|---|
| 42 | } | 
|---|
| 43 | return false; | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | const Variable *Variables::BackSearch( const Symbol &symbol ) const | 
|---|
| 47 | { | 
|---|
| 48 | //レキシカルスコープを考慮してバックサーチ | 
|---|
| 49 | for( int i=(int)this->size()-1; i>=0 ; i-- ){ | 
|---|
| 50 | const Variable *pVar = (*this)[i]; | 
|---|
| 51 | if( pVar->isLiving                                          //現在のスコープで有効なもの | 
|---|
| 52 | && pVar->GetScopeLevel() <= compiler.codeGenerator.lexicalScopes.GetNowLevel()  //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮) | 
|---|
| 53 | ){ | 
|---|
| 54 | if( pVar->IsEqualSymbol( symbol ) ){ | 
|---|
| 55 | return pVar; | 
|---|
| 56 | } | 
|---|
| 57 | } | 
|---|
| 58 | } | 
|---|
| 59 | return NULL; | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | const Variable *Variables::Find( const Symbol &symbol )const | 
|---|
| 63 | { | 
|---|
| 64 | int max = (int)this->size(); | 
|---|
| 65 | for( int i=0; i<max; i++ ){ | 
|---|
| 66 | Variable *pVar = (*this)[i]; | 
|---|
| 67 | if( pVar->IsEqualSymbol( symbol ) ){ | 
|---|
| 68 | return pVar; | 
|---|
| 69 | } | 
|---|
| 70 | } | 
|---|
| 71 | return NULL; | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | void GlobalVars::Add( Variable *pVar, bool isResetOffsetAddress ) | 
|---|
| 75 | { | 
|---|
| 76 | int alignment = 0; | 
|---|
| 77 | if( pVar->GetType().IsStruct() ){ | 
|---|
| 78 | alignment = pVar->GetType().GetClass().GetFixedAlignment(); | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | if( pVar->HasInitData() ){ | 
|---|
| 82 | //初期バッファがあるとき | 
|---|
| 83 |  | 
|---|
| 84 | if( isResetOffsetAddress ) | 
|---|
| 85 | { | 
|---|
| 86 | if( alignment ){ | 
|---|
| 87 | if( initAreaBuffer.GetSize() % alignment ){ | 
|---|
| 88 | initAreaBuffer.Resize( initAreaBuffer.GetSize() + ( alignment - (initAreaBuffer.GetSize() % alignment) ) ); | 
|---|
| 89 | } | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 | pVar->SetOffsetAddress( initAreaBuffer.GetSize() ); | 
|---|
| 93 |  | 
|---|
| 94 | initAreaBuffer.Resize( initAreaBuffer.GetSize() + pVar->GetMemorySize() ); | 
|---|
| 95 | } | 
|---|
| 96 | } | 
|---|
| 97 | else{ | 
|---|
| 98 | //初期バッファがないとき | 
|---|
| 99 |  | 
|---|
| 100 | if( alignment ){ | 
|---|
| 101 | if( allSize % alignment ){ | 
|---|
| 102 | allSize += alignment - (allSize % alignment); | 
|---|
| 103 | } | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | pVar->SetOffsetAddress( allSize | 0x80000000 ); | 
|---|
| 107 | allSize += pVar->GetMemorySize(); | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | push_back( pVar ); | 
|---|
| 111 | } | 
|---|