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

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

ObjectModuleに関連するクラス一式をab_commonプロジェクトに移動した。

File size: 3.2 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 : Symbol( 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 NamespaceScopes &namespaceScopes, const std::string &name, const Type &type, bool isConst, bool isRef, const std::string &paramStrForConstructor, bool hasInitData )
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}
25Variable::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}
37Variable::Variable()
38{
39}
40
41
42bool Variables::DuplicateCheck( const Symbol &symbol, int nowScopeLevel ) const
43{
44 //レキシカルスコープを考慮して重複判定
45 for( int i=(int)this->size()-1; i>=0 ; i-- ){
46 const Variable *pVar = (*this)[i];
47 if( pVar->isLiving //現在のスコープで有効なもの
48 && pVar->GetScopeLevel() == nowScopeLevel //現在のスコープと同一レベル
49 )
50 {
51 if( pVar->IsEqualSymbol( symbol ) ){
52 return true;
53 }
54 }
55 }
56 return false;
57}
58
59const Variable *Variables::BackSearch( const Symbol &symbol, int nowScopeLevel ) const
60{
61 //レキシカルスコープを考慮してバックサーチ
62 for( int i=(int)this->size()-1; i>=0 ; i-- ){
63 const Variable *pVar = (*this)[i];
64 if( pVar->isLiving //現在のスコープで有効なもの
65 && pVar->GetScopeLevel() <= nowScopeLevel //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)
66 ){
67 if( pVar->IsEqualSymbol( symbol ) ){
68 return pVar;
69 }
70 }
71 }
72 return NULL;
73}
74
75const 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}
86
87void GlobalVars::Add( Variable *pVar, bool isResetOffsetAddress )
88{
89 int alignment = 0;
90 if( pVar->GetType().IsStruct() ){
91 alignment = pVar->GetType().GetClass().GetFixedAlignment();
92 }
93
94 if( pVar->HasInitData() ){
95 //初期バッファがあるとき
96
97 if( isResetOffsetAddress )
98 {
99 if( alignment ){
100 if( initAreaBuffer.GetSize() % alignment ){
101 initAreaBuffer.Resize( initAreaBuffer.GetSize() + ( alignment - (initAreaBuffer.GetSize() % alignment) ) );
102 }
103 }
104
105 pVar->SetOffsetAddress( initAreaBuffer.GetSize() );
106
107 initAreaBuffer.Resize( initAreaBuffer.GetSize() + pVar->GetMemorySize() );
108 }
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}
Note: See TracBrowser for help on using the repository browser.