source: dev/branches/egtra/ab5.0/abdev/ab_common/src/Lexical/Variable.cpp@ 816

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

ab_commonにおいて、各クラスのコピー禁止を明確化、ならびにコピー可能なものにムーブコンストラクタ・ムーブ代入演算子を追加

File size: 3.8 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}
[816]14
[511]15Variable::Variable( const Variable &var )
[637]16 : RelationalObjectModuleItem( var )
[511]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}
[816]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
[511]41Variable::Variable()
42{
43}
[206]44
[816]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
[640]59bool Variable::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
[637]60{
[640]61 this->type.Resolve( resolver, resolveErrors );
[637]62 return true;
63}
[206]64
[637]65
[570]66bool Variables::DuplicateCheck( const Symbol &symbol, int nowScopeLevel ) const
[206]67{
68 //レキシカルスコープを考慮して重複判定
69 for( int i=(int)this->size()-1; i>=0 ; i-- ){
[288]70 const Variable *pVar = (*this)[i];
[570]71 if( pVar->isLiving //現在のスコープで有効なもの
72 && pVar->GetScopeLevel() == nowScopeLevel //現在のスコープと同一レベル
[248]73 )
74 {
[288]75 if( pVar->IsEqualSymbol( symbol ) ){
[248]76 return true;
77 }
[206]78 }
79 }
80 return false;
81}
82
[570]83const Variable *Variables::BackSearch( const Symbol &symbol, int nowScopeLevel ) const
[206]84{
85 //レキシカルスコープを考慮してバックサーチ
86 for( int i=(int)this->size()-1; i>=0 ; i-- ){
[288]87 const Variable *pVar = (*this)[i];
[570]88 if( pVar->isLiving //現在のスコープで有効なもの
89 && pVar->GetScopeLevel() <= nowScopeLevel //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)
[206]90 ){
[288]91 if( pVar->IsEqualSymbol( symbol ) ){
92 return pVar;
[206]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}
[273]110
[288]111void GlobalVars::Add( Variable *pVar, bool isResetOffsetAddress )
[273]112{
113 int alignment = 0;
114 if( pVar->GetType().IsStruct() ){
115 alignment = pVar->GetType().GetClass().GetFixedAlignment();
116 }
117
[275]118 if( pVar->HasInitData() ){
[273]119 //初期バッファがあるとき
120
[288]121 if( isResetOffsetAddress )
122 {
123 if( alignment ){
124 if( initAreaBuffer.GetSize() % alignment ){
125 initAreaBuffer.Resize( initAreaBuffer.GetSize() + ( alignment - (initAreaBuffer.GetSize() % alignment) ) );
126 }
[273]127 }
128
[288]129 pVar->SetOffsetAddress( initAreaBuffer.GetSize() );
130
131 initAreaBuffer.Resize( initAreaBuffer.GetSize() + pVar->GetMemorySize() );
[287]132 }
[273]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.