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

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