source: dev/trunk/ab5.0/abdev/ab_common/include/Lexical/Variable.h@ 682

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

値渡しの構造体パラメータが正常に引き渡されない不具合を修正。

File size: 5.3 KB
Line 
1#pragma once
2
3class Variable
4 : public RelationalObjectModuleItem
5{
6 Type type;
7 bool isConst;
8 bool isRef;
9 bool isArray;
10 Subscripts subscripts;
11
12 bool isParameter;
13 bool hasInitData;
14
15 //コンストラクタ用パラメータ
16 std::string paramStrForConstructor;
17
18
19 /* --- オフセット ---
20 ※グローバル変数で初期バッファがない場合は最上位ビットに1がセットされ、
21 初期バッファの有無が識別される。
22 (その後、スケジュール実行により、実際の配置に並び替えられる)*/
23 int offset;
24
25
26 //レキシカルスコープ用
27 int scopeStartAddress;
28 int scopeEndAddress;
29 int scopeLevel;
30
31
32 // XMLシリアライズ用
33private:
34 friend class boost::serialization::access;
35 template<class Archive> void serialize(Archive& ar, const unsigned int version)
36 {
37 trace_for_serialize( "serializing - Variable" );
38
39 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( RelationalObjectModuleItem );
40
41 if( ActiveBasic::Common::Environment::IsRemoveExternal() )
42 {
43 if( this->IsExternal() )
44 {
45 this->NeedResolve();
46 return;
47 }
48 }
49
50 ar & BOOST_SERIALIZATION_NVP( type );
51 ar & BOOST_SERIALIZATION_NVP( isConst );
52 ar & BOOST_SERIALIZATION_NVP( isRef );
53 ar & BOOST_SERIALIZATION_NVP( isArray );
54 ar & BOOST_SERIALIZATION_NVP( subscripts );
55 ar & BOOST_SERIALIZATION_NVP( isParameter );
56 ar & BOOST_SERIALIZATION_NVP( hasInitData );
57 ar & BOOST_SERIALIZATION_NVP( paramStrForConstructor );
58 ar & BOOST_SERIALIZATION_NVP( offset );
59 ar & BOOST_SERIALIZATION_NVP( scopeStartAddress );
60 ar & BOOST_SERIALIZATION_NVP( scopeEndAddress );
61 ar & BOOST_SERIALIZATION_NVP( scopeLevel );
62 }
63
64public:
65 Variable( const Symbol &symbol, const Type &type, bool isConst, bool isRef, const std::string &paramStrForConstructor, bool hasInitData );
66 Variable( const Variable &var );
67 Variable();
68
69 void SetArray( const Subscripts &subscripts ){
70 isArray = true;
71 this->subscripts = subscripts;
72 }
73
74 const Type &GetType() const
75 {
76 return type;
77 }
78 void ConstOff(){
79 isConst = false;
80 }
81 void ConstOn(){
82 isConst = true;
83 }
84 bool IsConst() const
85 {
86 return isConst;
87 }
88 bool IsRef() const
89 {
90 return isRef;
91 }
92 bool IsArray()const
93 {
94 return isArray;
95 }
96 const Subscripts &GetSubscripts() const
97 {
98 return subscripts;
99 }
100
101 void ThisIsByValStructParameter(){
102 isParameter = true;
103 }
104 bool IsByValStructParameter() const
105 {
106 return isParameter;
107 }
108 bool HasInitData() const
109 {
110 return hasInitData;
111 }
112
113
114 int GetMemorySize() const
115 {
116 if( isRef || isParameter ){
117 return PTR_SIZE;
118 }
119
120 int size = type.GetSize();
121
122 if( isArray ){
123 int num = 1;
124 for( int i=0; i<(int)subscripts.size(); i++){
125 num *= subscripts[i]+1;
126 }
127 size *= num;
128 }
129
130 if( size % PTR_SIZE ){
131 size += PTR_SIZE-(size%PTR_SIZE);
132 }
133
134 return size;
135 }
136
137 int GetOffsetAddress() const
138 {
139 return offset;
140 }
141 void SetOffsetAddress( int offset )
142 {
143 this->offset = offset;
144 }
145
146 const std::string &GetParamStrForConstructor() const
147 {
148 return paramStrForConstructor;
149 }
150
151 //レキシカルスコープ用
152 int GetScopeStartAddress() const
153 {
154 return scopeStartAddress;
155 }
156 void SetScopeStartAddress( int scopeStartAddress )
157 {
158 this->scopeStartAddress = scopeStartAddress;
159 }
160 int GetScopeEndAddress() const
161 {
162 return scopeEndAddress;
163 }
164 void SetScopeEndAddress( int scopeEndAddress )
165 {
166 this->scopeEndAddress = scopeEndAddress;
167 }
168 int GetScopeLevel() const
169 {
170 return scopeLevel;
171 }
172 void SetScopeLevel( int scopeLevel )
173 {
174 this->scopeLevel = scopeLevel;
175 }
176
177 virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
178
179
180 bool isLiving;
181 int source_code_address;
182
183
184 static int GetSubScriptCounts( const Subscripts &subscripts ){
185 // 配列の要素数を取得
186 int i,i2;
187 for(i=0,i2=1;i<(int)subscripts.size();i++){
188 i2 *= subscripts[i]+1;
189 }
190 return i2;
191 }
192};
193
194class Variables : public std::vector<Variable *>
195{
196protected:
197 int allSize;
198
199 // XMLシリアライズ用
200private:
201 friend class boost::serialization::access;
202 template<class Archive> void serialize(Archive& ar, const unsigned int version)
203 {
204 trace_for_serialize( "serializing - Variables" );
205
206 ar & boost::serialization::make_nvp("vector_Variable", boost::serialization::base_object<vector<Variable *>>(*this));
207 }
208
209public:
210 Variables()
211 : allSize( 0 )
212 {
213 }
214 ~Variables(){
215 Clear();
216 }
217
218 void Clear(){
219 for( int i=0; i<(int)this->size(); i++ ){
220 delete (*this)[i];
221 }
222
223 allSize = 0;
224 clear();
225 }
226 void PullOutAll()
227 {
228 clear();
229 }
230
231 int GetAllSize() const
232 {
233 return allSize;
234 }
235
236 bool DuplicateCheck( const Symbol &symbol, int nowScopeLevel ) const;
237
238 const Variable *BackSearch( const Symbol &symbol, int nowScopeLevel ) const;
239 const Variable *Find( const Symbol &symbol )const;
240};
241
242class GlobalVars : public Variables
243{
244public:
245 Jenga::Common::Binary initAreaBuffer;
246
247 // XMLシリアライズ用
248private:
249 friend class boost::serialization::access;
250 template<class Archive> void serialize(Archive& ar, const unsigned int version)
251 {
252 trace_for_serialize( "serializing - GlobalVars" );
253
254 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Variables );
255 ar & BOOST_SERIALIZATION_NVP( initAreaBuffer );
256 }
257public:
258 GlobalVars()
259 {
260 }
261 ~GlobalVars()
262 {
263 }
264
265 void Add( Variable *pVar, bool isResetOffsetAddress = true );
266};
Note: See TracBrowser for help on using the repository browser.