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

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