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