[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[580] | 3 | Variable::Variable( const Symbol &symbol, const Type &type, bool isConst, bool isRef, const std::string ¶mStrForConstructor, bool hasInitData )
|
---|
[637] | 4 | : RelationalObjectModuleItem( symbol )
|
---|
[511] | 5 | , type( type )
|
---|
| 6 | , isConst( isConst )
|
---|
| 7 | , isRef( isRef )
|
---|
| 8 | , isArray( false )
|
---|
| 9 | , isParameter( false)
|
---|
| 10 | , paramStrForConstructor( paramStrForConstructor )
|
---|
| 11 | , hasInitData( hasInitData )
|
---|
[206] | 12 | {
|
---|
[511] | 13 | }
|
---|
| 14 | Variable::Variable( const Variable &var )
|
---|
[637] | 15 | : RelationalObjectModuleItem( var )
|
---|
[511] | 16 | , type( var.type )
|
---|
| 17 | , isConst( var.isConst )
|
---|
| 18 | , isRef( var.isRef )
|
---|
| 19 | , isArray( var.isArray )
|
---|
| 20 | , subscripts( var.subscripts )
|
---|
| 21 | , isParameter( false )
|
---|
| 22 | , paramStrForConstructor( var.paramStrForConstructor )
|
---|
| 23 | , hasInitData( var.hasInitData )
|
---|
| 24 | {
|
---|
| 25 | }
|
---|
| 26 | Variable::Variable()
|
---|
| 27 | {
|
---|
| 28 | }
|
---|
[206] | 29 |
|
---|
[640] | 30 | bool Variable::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
|
---|
[637] | 31 | {
|
---|
[640] | 32 | this->type.Resolve( resolver, resolveErrors );
|
---|
[637] | 33 | return true;
|
---|
| 34 | }
|
---|
[206] | 35 |
|
---|
[637] | 36 |
|
---|
[570] | 37 | bool Variables::DuplicateCheck( const Symbol &symbol, int nowScopeLevel ) const
|
---|
[206] | 38 | {
|
---|
| 39 | //レキシカルスコープを考慮して重複判定
|
---|
| 40 | for( int i=(int)this->size()-1; i>=0 ; i-- ){
|
---|
[288] | 41 | const Variable *pVar = (*this)[i];
|
---|
[570] | 42 | if( pVar->isLiving //現在のスコープで有効なもの
|
---|
| 43 | && pVar->GetScopeLevel() == nowScopeLevel //現在のスコープと同一レベル
|
---|
[248] | 44 | )
|
---|
| 45 | {
|
---|
[288] | 46 | if( pVar->IsEqualSymbol( symbol ) ){
|
---|
[248] | 47 | return true;
|
---|
| 48 | }
|
---|
[206] | 49 | }
|
---|
| 50 | }
|
---|
| 51 | return false;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[570] | 54 | const Variable *Variables::BackSearch( const Symbol &symbol, int nowScopeLevel ) const
|
---|
[206] | 55 | {
|
---|
| 56 | //レキシカルスコープを考慮してバックサーチ
|
---|
| 57 | for( int i=(int)this->size()-1; i>=0 ; i-- ){
|
---|
[288] | 58 | const Variable *pVar = (*this)[i];
|
---|
[570] | 59 | if( pVar->isLiving //現在のスコープで有効なもの
|
---|
| 60 | && pVar->GetScopeLevel() <= nowScopeLevel //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)
|
---|
[206] | 61 | ){
|
---|
[288] | 62 | if( pVar->IsEqualSymbol( symbol ) ){
|
---|
| 63 | return pVar;
|
---|
[206] | 64 | }
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | return NULL;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | const Variable *Variables::Find( const Symbol &symbol )const
|
---|
| 71 | {
|
---|
| 72 | int max = (int)this->size();
|
---|
| 73 | for( int i=0; i<max; i++ ){
|
---|
| 74 | Variable *pVar = (*this)[i];
|
---|
| 75 | if( pVar->IsEqualSymbol( symbol ) ){
|
---|
| 76 | return pVar;
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | return NULL;
|
---|
| 80 | }
|
---|
[273] | 81 |
|
---|
[288] | 82 | void GlobalVars::Add( Variable *pVar, bool isResetOffsetAddress )
|
---|
[273] | 83 | {
|
---|
| 84 | int alignment = 0;
|
---|
| 85 | if( pVar->GetType().IsStruct() ){
|
---|
| 86 | alignment = pVar->GetType().GetClass().GetFixedAlignment();
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[275] | 89 | if( pVar->HasInitData() ){
|
---|
[273] | 90 | //初期バッファがあるとき
|
---|
| 91 |
|
---|
[288] | 92 | if( isResetOffsetAddress )
|
---|
| 93 | {
|
---|
| 94 | if( alignment ){
|
---|
| 95 | if( initAreaBuffer.GetSize() % alignment ){
|
---|
| 96 | initAreaBuffer.Resize( initAreaBuffer.GetSize() + ( alignment - (initAreaBuffer.GetSize() % alignment) ) );
|
---|
| 97 | }
|
---|
[273] | 98 | }
|
---|
| 99 |
|
---|
[288] | 100 | pVar->SetOffsetAddress( initAreaBuffer.GetSize() );
|
---|
| 101 |
|
---|
| 102 | initAreaBuffer.Resize( initAreaBuffer.GetSize() + pVar->GetMemorySize() );
|
---|
[287] | 103 | }
|
---|
[273] | 104 | }
|
---|
| 105 | else{
|
---|
| 106 | //初期バッファがないとき
|
---|
| 107 |
|
---|
| 108 | if( alignment ){
|
---|
| 109 | if( allSize % alignment ){
|
---|
| 110 | allSize += alignment - (allSize % alignment);
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | pVar->SetOffsetAddress( allSize | 0x80000000 );
|
---|
| 115 | allSize += pVar->GetMemorySize();
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | push_back( pVar );
|
---|
| 119 | }
|
---|