source: dev/trunk/jenga/include/smoothie/Variable.h@ 203

Last change on this file since 203 was 203, checked in by dai_9181, 17 years ago

jengaライブラリに一通りserializeメソッドを仕込んだ

File size: 3.9 KB
Line 
1#pragma once
2
3#include "Type.h"
4#include "Symbol.h"
5
6class Variable : public Type
7{
8 NamespaceScopes namespaceScopes;
9 string name;
10 bool isConst;
11 bool isRef;
12 bool isArray;
13 int subScripts[MAX_ARRAYDIM];
14
15 bool isParameter;
16
17 // XMLシリアライズ用
18 // TODO: xml実装(publicなクラスが残っている)
19private:
20 friend class boost::serialization::access;
21 template<class Archive> void serialize(Archive& ar, const unsigned int version)
22 {
23 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Type );
24 ar & BOOST_SERIALIZATION_NVP( namespaceScopes );
25 ar & BOOST_SERIALIZATION_NVP( name );
26 ar & BOOST_SERIALIZATION_NVP( isConst );
27 ar & BOOST_SERIALIZATION_NVP( isRef );
28 ar & BOOST_SERIALIZATION_NVP( isArray );
29 ar & BOOST_SERIALIZATION_NVP( subScripts );
30 ar & BOOST_SERIALIZATION_NVP( isParameter );
31 }
32
33public:
34 Variable( const string &name, const Type &type, bool isConst = false, bool isRef = false )
35 : Type( type )
36 , name( name )
37 , isConst( isConst )
38 , isRef( isRef )
39 , isArray( false )
40 , isParameter( false)
41 {
42 subScripts[0] = -1;
43 }
44 Variable( const NamespaceScopes &namespaceScopes, const string &name, const Type &type, bool isConst = false, bool isRef = false )
45 : namespaceScopes( namespaceScopes )
46 , Type( type )
47 , name( name )
48 , isConst( isConst )
49 , isRef( isRef )
50 , isArray( false )
51 , isParameter( false)
52 {
53 subScripts[0] = -1;
54 }
55 Variable( const Variable &var )
56 : Type( var )
57 , name( var.name )
58 , isConst( var.isConst )
59 , isRef( var.isRef )
60 , isArray( false )
61 , isParameter( false )
62 {
63 subScripts[0] = -1;
64 if( var.isArray ){
65 SetArray( var.subScripts );
66 }
67 }
68 ~Variable(){}
69
70 const NamespaceScopes &GetNamespaceScopes() const
71 {
72 return namespaceScopes;
73 }
74
75 void SetArray( const int *pSubScripts ){
76 isArray = true;
77 memcpy( this->subScripts, pSubScripts, sizeof(int) * MAX_ARRAYDIM );
78 }
79
80 const string &GetName() const
81 {
82 return name;
83 }
84
85 virtual bool IsEqualSymbol( const Symbol &symbol, bool isSupportStaticMember = true ) const = 0;
86
87 void ConstOff(){
88 isConst = false;
89 }
90 void ConstOn(){
91 isConst = true;
92 }
93 bool IsConst() const
94 {
95 return isConst;
96 }
97 bool IsRef() const
98 {
99 return isRef;
100 }
101 bool IsArray()const
102 {
103 return isArray;
104 }
105 const int *GetSubScriptsPtr() const
106 {
107 return subScripts;
108 }
109
110 void ThisIsParameter(){
111 isParameter = true;
112 }
113 bool IsParameter() const
114 {
115 return isParameter;
116 }
117
118
119 int GetMemorySize() const
120 {
121 if( isRef || isParameter ){
122 return PTR_SIZE;
123 }
124
125 int size = Type::GetSize();
126
127 if( isArray ){
128 int num = 1;
129 for( int i=0; i<MAX_ARRAYDIM; i++){
130 if(subScripts[i]==-1) break;
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
144 /* --- オフセット ---
145
146 ※グローバル変数で初期バッファがない場合は最上位ビットに1がセットされ、
147 初期バッファの有無が識別される。
148 (その後、スケジュール実行により、実際の配置に並び替えられる)*/
149 int offset;
150
151 //コンストラクタ用パラメータ
152 string paramStrForConstructor;
153
154 //レキシカルスコープ用
155 int ScopeStartAddress;
156 int ScopeEndAddress;
157 int ScopeLevel;
158 BOOL bLiving;
159
160
161 int source_code_address;
162
163
164 static int GetSubScriptCounts(const int *ss){
165 // 配列の要素数を取得
166 int i,i2;
167 for(i=0,i2=1;i<255;i++){
168 if(ss[i]==-1) break;
169 i2*=ss[i]+1;
170 }
171 return i2;
172 }
173};
174
175class Variables : public vector<Variable *>
176{
177public:
178 Variables(){}
179 ~Variables(){
180 clear();
181 }
182
183 void clear(){
184 for( int i=0; i<(int)this->size(); i++ ){
185 delete (*this)[i];
186 }
187
188 vector<Variable *>::clear();
189 }
190
191 bool DuplicateCheck( const Symbol &symbol ) const;
192
193 const Variable *BackSearch( const Symbol &symbol ) const;
194
195 const Variable *Find( const Symbol &symbol )const;
196};
197
198extern Variables globalVars;
Note: See TracBrowser for help on using the repository browser.