source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/include/Variable.h@ 523

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

ヘッダファイルを整理中

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