source: dev/BasicCompiler_Common/TypeDef.cpp@ 114

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

CClassクラスのインスタンスを全面的にconstにした。
TypeDefされたクラスの静的メソッドを呼び出せるようにした。(静的メンバへの対応はまだ)

File size: 5.5 KB
Line 
1#include "common.h"
2
3
4TypeDef::TypeDef( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName )
5 : namespaceScopes( namespaceScopes )
6 , name( name )
7 , baseName( baseName )
8{
9 if( !Type::StringToType( baseName, baseType ) ){
10 SetError(3, baseName, cp );
11 return;
12 }
13}
14TypeDef::~TypeDef(){
15}
16
17bool TypeDef::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
18{
19 if( GetName() != name ){
20 return false;
21 }
22 return NamespaceScopes::IsSameArea( this->namespaceScopes, namespaceScopes );
23}
24bool TypeDef::IsEqualSymbol( const string &fullName ) const
25{
26 char AreaName[VN_SIZE] = ""; //オブジェクト変数
27 char NestName[VN_SIZE] = ""; //入れ子メンバ
28 bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName );
29
30 if( IsEqualSymbol( NamespaceScopes( AreaName ), NestName ) ){
31 return true;
32 }
33
34 if( isNest ){
35 // 静的メンバを考慮
36
37 char AreaName2[VN_SIZE] = ""; //オブジェクト変数
38 char NestName2[VN_SIZE] = ""; //入れ子メンバ
39 bool isNest = SplitMemberName( AreaName, AreaName2, NestName2 );
40 lstrcat( NestName2, "." );
41 lstrcat( NestName2, NestName );
42
43 return IsEqualSymbol( NamespaceScopes( AreaName2 ), NestName2 );
44 }
45
46 return false;
47}
48
49
50
51TypeDefCollection::TypeDefCollection(){
52}
53TypeDefCollection::~TypeDefCollection(){
54}
55void TypeDefCollection::Add( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName ){
56 TypeDef typeDef( namespaceScopes, name, baseName );
57 this->push_back( typeDef );
58}
59int TypeDefCollection::GetIndex( const NamespaceScopes &namespaceScopes, const string &name ) const{
60 int max = (int)(*this).size();
61 for( int i=0; i<max; i++ ){
62 if( (*this)[i].IsEqualSymbol( namespaceScopes, name ) ){
63 return i;
64 }
65 }
66 return -1;
67}
68int TypeDefCollection::GetIndex( const string &fullName ) const{
69 char AreaName[VN_SIZE] = ""; //オブジェクト変数
70 char NestName[VN_SIZE] = ""; //入れ子メンバ
71 bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName );
72
73 return GetIndex( NamespaceScopes( AreaName ), NestName );
74}
75
76void TypeDefCollection::Add( const NamespaceScopes &namespaceScopes, const string &expression, int nowLine ){
77 int i;
78 char temporary[VN_SIZE];
79
80 for(i=0;;i++){
81 if(expression[i]=='='||expression[i]=='\0'){
82 temporary[i]=0;
83 break;
84 }
85 temporary[i]=expression[i];
86 }
87
88 if(expression[i]!='='){
89 SetError(10,"TypeDef",nowLine);
90 return;
91 }
92
93 const char *pTemp=expression.c_str()+i+1;
94
95 //識別文字のエラーチェック(新しい型)
96 i=0;
97 for(;;i++){
98 if(temporary[i]=='\0') break;
99 if(!IsVariableChar(temporary[i])){
100 SetError(10,"TypeDef",nowLine);
101 return;
102 }
103 }
104
105 //識別文字のエラーチェック(コピー元の型)
106 if(pTemp[0]=='*'&&pTemp[1]==1&&(pTemp[2]==ESC_FUNCTION||pTemp[2]==ESC_SUB)){
107 //関数ポインタ
108 if(pTemp[3]!='('){
109 SetError(10,"TypeDef",nowLine);
110 return;
111 }
112 }
113 else{
114 i=0;
115 while(pTemp[i]=='*') i++;
116 for(;;i++){
117 if(pTemp[i]=='\0') break;
118 if(!IsVariableChar(pTemp[i])){
119 SetError(10,"TypeDef",nowLine);
120 return;
121 }
122 }
123 }
124
125 //識別子が重複している場合はエラーにする
126 if(lstrcmp(temporary,pTemp)==0){
127 SetError(1,NULL,nowLine);
128 return;
129 }
130
131
132
133 //////////////////////////
134 // TypeDef情報を追加
135 //////////////////////////
136
137 //エラー用
138 extern int cp;
139 cp = nowLine;
140
141 Add( namespaceScopes, temporary, pTemp );
142}
143
144void TypeDefCollection::Init(){
145 // 初期化
146 clear();
147
148 // 名前空間管理
149 NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
150 namespaceScopes.clear();
151
152 // Importsされた名前空間の管理
153 NamespaceScopesCollection &importedNamespaces = Smoothie::Meta::importedNamespaces;
154 importedNamespaces.clear();
155
156 int i=-1, i2;
157 char temporary[VN_SIZE];
158 while(1){
159 extern char *basbuf;
160
161 i++;
162
163 if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
164 for(i+=2,i2=0;;i2++,i++){
165 if( IsCommandDelimitation( basbuf[i] ) ){
166 temporary[i2]=0;
167 break;
168 }
169 temporary[i2]=basbuf[i];
170 }
171 namespaceScopes.push_back( temporary );
172
173 continue;
174 }
175 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
176 if( namespaceScopes.size() <= 0 ){
177 SetError(12, "End Namespace", i );
178 }
179 else{
180 namespaceScopes.pop_back();
181 }
182
183 i += 2;
184 continue;
185 }
186 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){
187 for(i+=2,i2=0;;i2++,i++){
188 if( IsCommandDelimitation( basbuf[i] ) ){
189 temporary[i2]=0;
190 break;
191 }
192 temporary[i2]=basbuf[i];
193 }
194 importedNamespaces.Imports( temporary );
195
196 continue;
197 }
198 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
199 importedNamespaces.clear();
200 continue;
201 }
202
203 if( basbuf[i]==1 ){
204 char temporary[VN_SIZE];
205 if(basbuf[i+1]==ESC_TYPEDEF){
206 int i2 = 0;
207 for(i+=2;;i2++,i++){
208 if(basbuf[i]=='\n'){
209 temporary[i2]=0;
210 break;
211 }
212 temporary[i2]=basbuf[i];
213 if(basbuf[i]=='\0') break;
214 }
215 Add( namespaceScopes, temporary, i );
216
217 continue;
218 }
219 else if( basbuf[i+1] == ESC_CONST && basbuf[i+2] == 1 && basbuf[i+3] == ESC_ENUM ){
220 int i2 = 0;
221 for(i+=4;;i2++,i++){
222 if(!IsVariableChar(basbuf[i])){
223 temporary[i2]=0;
224 break;
225 }
226 temporary[i2]=basbuf[i];
227 if(basbuf[i]=='\0') break;
228 }
229 Add( namespaceScopes, temporary, "Long" );
230 }
231 }
232
233 //次の行
234 for(;;i++){
235 if(IsCommandDelimitation(basbuf[i])) break;
236 }
237 if(basbuf[i]=='\0') break;
238 }
239}
Note: See TracBrowser for help on using the repository browser.