source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/TypeDef.cpp@ 465

Last change on this file since 465 was 465, checked in by dai_9181, 16 years ago

Messenger/ErrorMessengerクラスを導入。SetError関数によるエラー生成を廃止した。

File size: 5.8 KB
Line 
1#include "stdafx.h"
2
3#include <TypeDef.h>
4#include <Compiler.h>
5#include <NamespaceSupporter.h>
6
7TypeDef::TypeDef( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName, int nowLine )
8 : Symbol( namespaceScopes, name )
9 , baseName( baseName )
10{
11 if( !compiler.StringToType( baseName, baseType ) ){
12 compiler.errorMessenger.Output(3, baseName, nowLine );
13 return;
14 }
15}
16/*
17bool TypeDef::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
18{
19 if( GetName() != name ){
20 return false;
21 }
22 return compiler.GetNamespaceSupporter().IsSameAreaNamespace( 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, int nowLine ){
56 TypeDef typeDef( namespaceScopes, name, baseName, nowLine );
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 compiler.errorMessenger.Output(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], true) ) ){
100 compiler.errorMessenger.Output(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 compiler.errorMessenger.Output(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], true) ) )
119 {
120 compiler.errorMessenger.Output(10,"TypeDef",nowLine);
121 return;
122 }
123 }
124 }
125
126 //識別子が重複している場合はエラーにする
127 if(lstrcmp(temporary,pTemp)==0){
128 compiler.errorMessenger.Output(1,NULL,nowLine);
129 return;
130 }
131
132
133
134 //////////////////////////
135 // TypeDef情報を追加
136 //////////////////////////
137
138 Add( namespaceScopes, temporary, pTemp, nowLine );
139}
140
141void TypeDefCollection::CollectTypeDefs(){
142
143 // 名前空間管理
144 NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
145 namespaceScopes.clear();
146
147 // Importsされた名前空間の管理
148 NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
149 importedNamespaces.clear();
150
151 int i=-1, i2;
152 char temporary[VN_SIZE];
153 while(1){
154 extern char *basbuf;
155
156 i++;
157
158 if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
159 for(i+=2,i2=0;;i2++,i++){
160 if( IsCommandDelimitation( basbuf[i] ) ){
161 temporary[i2]=0;
162 break;
163 }
164 temporary[i2]=basbuf[i];
165 }
166 namespaceScopes.push_back( temporary );
167
168 continue;
169 }
170 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
171 if( namespaceScopes.size() <= 0 ){
172 compiler.errorMessenger.Output(12, "End Namespace", i );
173 }
174 else{
175 namespaceScopes.pop_back();
176 }
177
178 i += 2;
179 continue;
180 }
181 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){
182 for(i+=2,i2=0;;i2++,i++){
183 if( IsCommandDelimitation( basbuf[i] ) ){
184 temporary[i2]=0;
185 break;
186 }
187 temporary[i2]=basbuf[i];
188 }
189 if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
190 {
191 compiler.errorMessenger.Output(64,temporary,i );
192 }
193
194 continue;
195 }
196 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
197 importedNamespaces.clear();
198 continue;
199 }
200
201 if( basbuf[i]==1 ){
202 char temporary[VN_SIZE];
203 if(basbuf[i+1]==ESC_TYPEDEF){
204 int i2 = 0;
205 for(i+=2;;i2++,i++){
206 if(basbuf[i]=='\n'){
207 temporary[i2]=0;
208 break;
209 }
210 temporary[i2]=basbuf[i];
211 if(basbuf[i]=='\0') break;
212 }
213 Add( namespaceScopes, temporary, i );
214
215 continue;
216 }
217 else if( basbuf[i+1] == ESC_CONST && basbuf[i+2] == 1 && basbuf[i+3] == ESC_ENUM ){
218 int i2 = 0;
219 for(i+=4;;i2++,i++){
220 if(!IsVariableChar(basbuf[i])){
221 temporary[i2]=0;
222 break;
223 }
224 temporary[i2]=basbuf[i];
225 if(basbuf[i]=='\0') break;
226 }
227 Add( namespaceScopes, temporary, "Long", i );
228 }
229 }
230
231 //次の行
232 for(;;i++){
233 if(IsCommandDelimitation(basbuf[i])) break;
234 }
235 if(basbuf[i]=='\0') break;
236 }
237}
Note: See TracBrowser for help on using the repository browser.