source: dev/trunk/ab5.0/abdev/ab_common/include/Lexical/Variable.h@ 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: 5.2 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(Variable&& var);
67 Variable( const Variable &var );
68 Variable();
69 Variable& operator =(Variable&& y);
70 Variable& operator =(Variable const& y)
71 {
72 return *this = std::move(Variable(y));
73 }
74
75 void SetArray( const Subscripts &subscripts ){
76 isArray = true;
77 this->subscripts = subscripts;
78 }
79
80 const Type &GetType() const
81 {
82 return type;
83 }
84 void ConstOff(){
85 isConst = false;
86 }
87 void ConstOn(){
88 isConst = true;
89 }
90 bool IsConst() const
91 {
92 return isConst;
93 }
94 bool IsRef() const
95 {
96 return isRef;
97 }
98 bool IsArray()const
99 {
100 return isArray;
101 }
102 const Subscripts &GetSubscripts() const
103 {
104 return subscripts;
105 }
106
107 void ThisIsByValStructParameter(){
108 isParameter = true;
109 }
110 bool IsByValStructParameter() const
111 {
112 return isParameter;
113 }
114 bool HasInitData() const
115 {
116 return hasInitData;
117 }
118
119
120 int GetMemorySize() const
121 {
122 if( isRef || isParameter ){
123 return PTR_SIZE;
124 }
125
126 int size = type.GetSize();
127
128 if( isArray ){
129 int num = 1;
130 for( int i=0; i<(int)subscripts.size(); i++){
131 num *= subscripts[i]+1;
132 }
133 size *= num;
134 }
135
136 if( size % PTR_SIZE ){
137 size += PTR_SIZE-(size%PTR_SIZE);
138 }
139
140 return size;
141 }
142
143 int GetOffsetAddress() const
144 {
145 return offset;
146 }
147 void SetOffsetAddress( int offset )
148 {
149 this->offset = offset;
150 }
151
152 const std::string &GetParamStrForConstructor() const
153 {
154 return paramStrForConstructor;
155 }
156
157 //レキシカルスコープ用
158 int GetScopeStartAddress() const
159 {
160 return scopeStartAddress;
161 }
162 void SetScopeStartAddress( int scopeStartAddress )
163 {
164 this->scopeStartAddress = scopeStartAddress;
165 }
166 int GetScopeEndAddress() const
167 {
168 return scopeEndAddress;
169 }
170 void SetScopeEndAddress( int scopeEndAddress )
171 {
172 this->scopeEndAddress = scopeEndAddress;
173 }
174 int GetScopeLevel() const
175 {
176 return scopeLevel;
177 }
178 void SetScopeLevel( int scopeLevel )
179 {
180 this->scopeLevel = scopeLevel;
181 }
182
183 virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
184
185
186 bool isLiving;
187 int source_code_address;
188
189
190 static int GetSubScriptCounts( const Subscripts &subscripts ){
191 // 配列の要素数を取得
192 int i,i2;
193 for(i=0,i2=1;i<(int)subscripts.size();i++){
194 i2 *= subscripts[i]+1;
195 }
196 return i2;
197 }
198};
199
200class Variables : public std::vector<Variable *>
201{
202protected:
203 int allSize;
204
205 // XMLシリアライズ用
206private:
207 friend class boost::serialization::access;
208 template<class Archive> void serialize(Archive& ar, const unsigned int version)
209 {
210 trace_for_serialize( "serializing - Variables" );
211
212 ar & boost::serialization::make_nvp("vector_Variable", boost::serialization::base_object<vector<Variable *>>(*this));
213 }
214
215public:
216 Variables()
217 : allSize( 0 )
218 {
219 }
220 ~Variables(){
221 Clear();
222 }
223
224 void Clear(){
225 for( int i=0; i<(int)this->size(); i++ ){
226 delete (*this)[i];
227 }
228
229 allSize = 0;
230 clear();
231 }
232 void PullOutAll()
233 {
234 clear();
235 }
236
237 int GetAllSize() const
238 {
239 return allSize;
240 }
241
242 bool DuplicateCheck( const Symbol &symbol, int nowScopeLevel ) const;
243
244 const Variable *BackSearch( const Symbol &symbol, int nowScopeLevel ) const;
245 const Variable *Find( const Symbol &symbol )const;
246};
247
248class GlobalVars : public Variables
249{
250public:
251 Jenga::Common::Binary initAreaBuffer;
252
253 // XMLシリアライズ用
254private:
255 friend class boost::serialization::access;
256 template<class Archive> void serialize(Archive& ar, const unsigned int version)
257 {
258 trace_for_serialize( "serializing - GlobalVars" );
259
260 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Variables );
261 ar & BOOST_SERIALIZATION_NVP( initAreaBuffer );
262 }
263public:
264 GlobalVars()
265 {
266 }
267 ~GlobalVars()
268 {
269 }
270
271 void Add( Variable *pVar, bool isResetOffsetAddress = true );
272};
Note: See TracBrowser for help on using the repository browser.