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

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

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

File size: 3.0 KB
Line 
1#include "stdafx.h"
2
3Variable::Variable( const Symbol &symbol, const Type &type, bool isConst, bool isRef, const std::string &paramStrForConstructor, bool hasInitData )
4 : RelationalObjectModuleItem( symbol )
5 , type( type )
6 , isConst( isConst )
7 , isRef( isRef )
8 , isArray( false )
9 , isParameter( false)
10 , paramStrForConstructor( paramStrForConstructor )
11 , hasInitData( hasInitData )
12{
13}
14Variable::Variable( const Variable &var )
15 : RelationalObjectModuleItem( var )
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}
29
30bool Variable::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
31{
32 this->type.Resolve( resolver, resolveErrors );
33 return true;
34}
35
36
37bool Variables::DuplicateCheck( const Symbol &symbol, int nowScopeLevel ) const
38{
39 //レキシカルスコープを考慮して重複判定
40 for( int i=(int)this->size()-1; i>=0 ; i-- ){
41 const Variable *pVar = (*this)[i];
42 if( pVar->isLiving //現在のスコープで有効なもの
43 && pVar->GetScopeLevel() == nowScopeLevel //現在のスコープと同一レベル
44 )
45 {
46 if( pVar->IsEqualSymbol( symbol ) ){
47 return true;
48 }
49 }
50 }
51 return false;
52}
53
54const Variable *Variables::BackSearch( const Symbol &symbol, int nowScopeLevel ) const
55{
56 //レキシカルスコープを考慮してバックサーチ
57 for( int i=(int)this->size()-1; i>=0 ; i-- ){
58 const Variable *pVar = (*this)[i];
59 if( pVar->isLiving //現在のスコープで有効なもの
60 && pVar->GetScopeLevel() <= nowScopeLevel //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)
61 ){
62 if( pVar->IsEqualSymbol( symbol ) ){
63 return pVar;
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}
81
82void GlobalVars::Add( Variable *pVar, bool isResetOffsetAddress )
83{
84 int alignment = 0;
85 if( pVar->GetType().IsStruct() ){
86 alignment = pVar->GetType().GetClass().GetFixedAlignment();
87 }
88
89 if( pVar->HasInitData() ){
90 //初期バッファがあるとき
91
92 if( isResetOffsetAddress )
93 {
94 if( alignment ){
95 if( initAreaBuffer.GetSize() % alignment ){
96 initAreaBuffer.Resize( initAreaBuffer.GetSize() + ( alignment - (initAreaBuffer.GetSize() % alignment) ) );
97 }
98 }
99
100 pVar->SetOffsetAddress( initAreaBuffer.GetSize() );
101
102 initAreaBuffer.Resize( initAreaBuffer.GetSize() + pVar->GetMemorySize() );
103 }
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.