#include "stdafx.h" Variable::Variable( const Symbol &symbol, const Type &type, bool isConst, bool isRef, const std::string ¶mStrForConstructor, bool hasInitData ) : RelationalObjectModuleItem( symbol ) , type( type ) , isConst( isConst ) , isRef( isRef ) , isArray( false ) , isParameter( false) , paramStrForConstructor( paramStrForConstructor ) , hasInitData( hasInitData ) { } Variable::Variable( const Variable &var ) : RelationalObjectModuleItem( var ) , type( var.type ) , isConst( var.isConst ) , isRef( var.isRef ) , isArray( var.isArray ) , subscripts( var.subscripts ) , isParameter( false ) , paramStrForConstructor( var.paramStrForConstructor ) , hasInitData( var.hasInitData ) { } Variable::Variable() { } bool Variable::Resolve( const ObjectModule &resolver ) { this->type.Resolve( resolver ); return true; } bool Variables::DuplicateCheck( const Symbol &symbol, int nowScopeLevel ) const { //レキシカルスコープを考慮して重複判定 for( int i=(int)this->size()-1; i>=0 ; i-- ){ const Variable *pVar = (*this)[i]; if( pVar->isLiving //現在のスコープで有効なもの && pVar->GetScopeLevel() == nowScopeLevel //現在のスコープと同一レベル ) { if( pVar->IsEqualSymbol( symbol ) ){ return true; } } } return false; } const Variable *Variables::BackSearch( const Symbol &symbol, int nowScopeLevel ) const { //レキシカルスコープを考慮してバックサーチ for( int i=(int)this->size()-1; i>=0 ; i-- ){ const Variable *pVar = (*this)[i]; if( pVar->isLiving //現在のスコープで有効なもの && pVar->GetScopeLevel() <= nowScopeLevel //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮) ){ if( pVar->IsEqualSymbol( symbol ) ){ return pVar; } } } return NULL; } const Variable *Variables::Find( const Symbol &symbol )const { int max = (int)this->size(); for( int i=0; iIsEqualSymbol( symbol ) ){ return pVar; } } return NULL; } void GlobalVars::Add( Variable *pVar, bool isResetOffsetAddress ) { int alignment = 0; if( pVar->GetType().IsStruct() ){ alignment = pVar->GetType().GetClass().GetFixedAlignment(); } if( pVar->HasInitData() ){ //初期バッファがあるとき if( isResetOffsetAddress ) { if( alignment ){ if( initAreaBuffer.GetSize() % alignment ){ initAreaBuffer.Resize( initAreaBuffer.GetSize() + ( alignment - (initAreaBuffer.GetSize() % alignment) ) ); } } pVar->SetOffsetAddress( initAreaBuffer.GetSize() ); initAreaBuffer.Resize( initAreaBuffer.GetSize() + pVar->GetMemorySize() ); } } else{ //初期バッファがないとき if( alignment ){ if( allSize % alignment ){ allSize += alignment - (allSize % alignment); } } pVar->SetOffsetAddress( allSize | 0x80000000 ); allSize += pVar->GetMemorySize(); } push_back( pVar ); }