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

Last change on this file since 829 was 829, checked in by イグトランス (egtra), 12 years ago

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain; charset=Shift_JIS
File size: 3.7 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}
14
15Variable::Variable( const Variable &var )
16 : RelationalObjectModuleItem( var )
17 , type( var.type )
18 , isConst( var.isConst )
19 , isRef( var.isRef )
20 , isArray( var.isArray )
21 , subscripts( var.subscripts )
22 , isParameter( false )
23 , paramStrForConstructor( var.paramStrForConstructor )
24 , hasInitData( var.hasInitData )
25{
26}
27
28Variable::Variable(Variable&& var)
29 : RelationalObjectModuleItem(std::move(var))
30 , type(std::move(var.type))
31 , isConst(std::move(var.isConst))
32 , isRef(std::move(var.isRef))
33 , isArray(std::move(var.isArray))
34 , subscripts(std::move(var.subscripts))
35 , isParameter(std::move(var.isParameter))
36 , paramStrForConstructor(std::move(var.paramStrForConstructor))
37 , hasInitData(std::move(var.hasInitData))
38{
39}
40
41Variable::Variable()
42{
43}
44
45Variable& Variable::operator =(Variable&& var)
46{
47 RelationalObjectModuleItem::operator =(std::move(var));
48 type = std::move(var.type);
49 isConst = std::move(var.isConst);
50 isRef = std::move(var.isRef);
51 isArray = std::move(var.isArray);
52 subscripts = std::move(var.subscripts);
53 isParameter = std::move(var.isParameter);
54 paramStrForConstructor = std::move(var.paramStrForConstructor);
55 hasInitData = std::move(var.hasInitData);
56 return *this;
57}
58
59bool Variable::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
60{
61 this->type.Resolve( resolver, resolveErrors );
62 return true;
63}
64
65
66bool Variables::DuplicateCheck( const Symbol &symbol, int nowScopeLevel ) const
67{
68 //レキシカルスコープを考慮して重複判定
69 for( int i=(int)this->size()-1; i>=0 ; i-- ){
70 const Variable *pVar = (*this)[i];
71 if( pVar->isLiving //現在のスコープで有効なもの
72 && pVar->GetScopeLevel() == nowScopeLevel //現在のスコープと同一レベル
73 )
74 {
75 if( pVar->IsEqualSymbol( symbol ) ){
76 return true;
77 }
78 }
79 }
80 return false;
81}
82
83const Variable *Variables::BackSearch( const Symbol &symbol, int nowScopeLevel ) const
84{
85 //レキシカルスコープを考慮してバックサーチ
86 for( int i=(int)this->size()-1; i>=0 ; i-- ){
87 const Variable *pVar = (*this)[i];
88 if( pVar->isLiving //現在のスコープで有効なもの
89 && pVar->GetScopeLevel() <= nowScopeLevel //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)
90 ){
91 if( pVar->IsEqualSymbol( symbol ) ){
92 return pVar;
93 }
94 }
95 }
96 return NULL;
97}
98
99const Variable *Variables::Find( const Symbol &symbol )const
100{
101 int max = (int)this->size();
102 for( int i=0; i<max; i++ ){
103 Variable *pVar = (*this)[i];
104 if( pVar->IsEqualSymbol( symbol ) ){
105 return pVar;
106 }
107 }
108 return NULL;
109}
110
111void GlobalVars::Add( Variable *pVar, bool isResetOffsetAddress )
112{
113 int alignment = 0;
114 if( pVar->GetType().IsStruct() ){
115 alignment = pVar->GetType().GetClass().GetFixedAlignment();
116 }
117
118 if( pVar->HasInitData() ){
119 //初期バッファがあるとき
120
121 if( isResetOffsetAddress )
122 {
123 if( alignment ){
124 if( initAreaBuffer.GetSize() % alignment ){
125 initAreaBuffer.Resize( initAreaBuffer.GetSize() + ( alignment - (initAreaBuffer.GetSize() % alignment) ) );
126 }
127 }
128
129 pVar->SetOffsetAddress( initAreaBuffer.GetSize() );
130
131 initAreaBuffer.Resize( initAreaBuffer.GetSize() + pVar->GetMemorySize() );
132 }
133 }
134 else{
135 //初期バッファがないとき
136
137 if( alignment ){
138 if( allSize % alignment ){
139 allSize += alignment - (allSize % alignment);
140 }
141 }
142
143 pVar->SetOffsetAddress( allSize | 0x80000000 );
144 allSize += pVar->GetMemorySize();
145 }
146
147 push_back( pVar );
148}
Note: See TracBrowser for help on using the repository browser.