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