source: dev/BasicCompiler_Common/TypeDef.cpp@ 113

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

TypeDef、Declareの名前空間対応を行った。
TypeDef、Declareをローカル領域で使用した際、エラーを表示するようにした。

File size: 5.1 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 string &typeName ) const{
60 int max = (int)(*this).size();
61 for( int i=0; i<max; i++ ){
62 if( (*this)[i].IsEqualSymbol( typeName ) ){
63 return i;
64 }
65 }
66 return -1;
67}
68
69void TypeDefCollection::Add( const NamespaceScopes &namespaceScopes, const string &expression, int nowLine ){
70 int i;
71 char temporary[VN_SIZE];
72
73 for(i=0;;i++){
74 if(expression[i]=='='||expression[i]=='\0'){
75 temporary[i]=0;
76 break;
77 }
78 temporary[i]=expression[i];
79 }
80
81 if(expression[i]!='='){
82 SetError(10,"TypeDef",nowLine);
83 return;
84 }
85
86 const char *pTemp=expression.c_str()+i+1;
87
88 //識別文字のエラーチェック(新しい型)
89 i=0;
90 for(;;i++){
91 if(temporary[i]=='\0') break;
92 if(!IsVariableChar(temporary[i])){
93 SetError(10,"TypeDef",nowLine);
94 return;
95 }
96 }
97
98 //識別文字のエラーチェック(コピー元の型)
99 if(pTemp[0]=='*'&&pTemp[1]==1&&(pTemp[2]==ESC_FUNCTION||pTemp[2]==ESC_SUB)){
100 //関数ポインタ
101 if(pTemp[3]!='('){
102 SetError(10,"TypeDef",nowLine);
103 return;
104 }
105 }
106 else{
107 i=0;
108 while(pTemp[i]=='*') i++;
109 for(;;i++){
110 if(pTemp[i]=='\0') break;
111 if(!IsVariableChar(pTemp[i])){
112 SetError(10,"TypeDef",nowLine);
113 return;
114 }
115 }
116 }
117
118 //識別子が重複している場合はエラーにする
119 if(lstrcmp(temporary,pTemp)==0){
120 SetError(1,NULL,nowLine);
121 return;
122 }
123
124
125
126 //////////////////////////
127 // TypeDef情報を追加
128 //////////////////////////
129
130 //エラー用
131 extern int cp;
132 cp = nowLine;
133
134 Add( namespaceScopes, temporary, pTemp );
135}
136
137void TypeDefCollection::Init(){
138 // 初期化
139 clear();
140
141 // 名前空間管理
142 NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
143 namespaceScopes.clear();
144
145 // Importsされた名前空間の管理
146 NamespaceScopesCollection &importedNamespaces = Smoothie::Meta::importedNamespaces;
147 importedNamespaces.clear();
148
149 int i=-1, i2;
150 char temporary[VN_SIZE];
151 while(1){
152 extern char *basbuf;
153
154 i++;
155
156 if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
157 for(i+=2,i2=0;;i2++,i++){
158 if( IsCommandDelimitation( basbuf[i] ) ){
159 temporary[i2]=0;
160 break;
161 }
162 temporary[i2]=basbuf[i];
163 }
164 namespaceScopes.push_back( temporary );
165
166 continue;
167 }
168 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
169 if( namespaceScopes.size() <= 0 ){
170 SetError(12, "End Namespace", i );
171 }
172 else{
173 namespaceScopes.pop_back();
174 }
175
176 i += 2;
177 continue;
178 }
179 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){
180 for(i+=2,i2=0;;i2++,i++){
181 if( IsCommandDelimitation( basbuf[i] ) ){
182 temporary[i2]=0;
183 break;
184 }
185 temporary[i2]=basbuf[i];
186 }
187 importedNamespaces.Imports( temporary );
188
189 continue;
190 }
191 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
192 importedNamespaces.clear();
193 continue;
194 }
195
196 if( basbuf[i]==1 ){
197 char temporary[VN_SIZE];
198 if(basbuf[i+1]==ESC_TYPEDEF){
199 int i2 = 0;
200 for(i+=2;;i2++,i++){
201 if(basbuf[i]=='\n'){
202 temporary[i2]=0;
203 break;
204 }
205 temporary[i2]=basbuf[i];
206 if(basbuf[i]=='\0') break;
207 }
208 Add( namespaceScopes, temporary, i );
209
210 continue;
211 }
212 else if( basbuf[i+1] == ESC_CONST && basbuf[i+2] == 1 && basbuf[i+3] == ESC_ENUM ){
213 int i2 = 0;
214 for(i+=4;;i2++,i++){
215 if(!IsVariableChar(basbuf[i])){
216 temporary[i2]=0;
217 break;
218 }
219 temporary[i2]=basbuf[i];
220 if(basbuf[i]=='\0') break;
221 }
222 Add( namespaceScopes, temporary, "Long" );
223 }
224 }
225
226 //次の行
227 for(;;i++){
228 if(IsCommandDelimitation(basbuf[i])) break;
229 }
230 if(basbuf[i]=='\0') break;
231 }
232}
Note: See TracBrowser for help on using the repository browser.