source: dev/trunk/ab5.0/abdev/ab_common/src/Lexical/Variable.cpp@ 639

Last change on this file since 639 was 639, checked in by dai_9181, 16 years ago

静的リンクリンカの依存関係解決モジュールを製作中

File size: 2.9 KB
RevLine 
[206]1#include "stdafx.h"
2
[580]3Variable::Variable( const Symbol &symbol, const Type &type, bool isConst, bool isRef, const std::string &paramStrForConstructor, 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}
14Variable::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}
26Variable::Variable()
27{
28}
[206]29
[639]30bool Variable::Resolve( const ObjectModule &resolver )
[637]31{
[639]32 this->type.Resolve( resolver );
[637]33 return true;
34}
[206]35
[637]36
[570]37bool 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]54const 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
70const 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]82void 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}
Note: See TracBrowser for help on using the repository browser.