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
RevLine 
[78]1#include "common.h"
[4]2
3
[113]4TypeDef::TypeDef( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName )
5 : namespaceScopes( namespaceScopes )
6 , name( name )
7 , baseName( baseName )
[78]8{
9 if( !Type::StringToType( baseName, baseType ) ){
10 SetError(3, baseName, cp );
11 return;
12 }
[4]13}
[78]14TypeDef::~TypeDef(){
[4]15}
16
[113]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 );
[4]29
[113]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
[78]51TypeDefCollection::TypeDefCollection(){
[4]52}
[78]53TypeDefCollection::~TypeDefCollection(){
[4]54}
[113]55void TypeDefCollection::Add( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName ){
56 TypeDef typeDef( namespaceScopes, name, baseName );
[78]57 this->push_back( typeDef );
[4]58}
[114]59int TypeDefCollection::GetIndex( const NamespaceScopes &namespaceScopes, const string &name ) const{
[79]60 int max = (int)(*this).size();
[78]61 for( int i=0; i<max; i++ ){
[114]62 if( (*this)[i].IsEqualSymbol( namespaceScopes, name ) ){
[4]63 return i;
64 }
65 }
66 return -1;
67}
[114]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 );
[4]72
[114]73 return GetIndex( NamespaceScopes( AreaName ), NestName );
74}
75
[113]76void TypeDefCollection::Add( const NamespaceScopes &namespaceScopes, const string &expression, int nowLine ){
[4]77 int i;
[78]78 char temporary[VN_SIZE];
[4]79
80 for(i=0;;i++){
[78]81 if(expression[i]=='='||expression[i]=='\0'){
[4]82 temporary[i]=0;
83 break;
84 }
[78]85 temporary[i]=expression[i];
[4]86 }
87
[78]88 if(expression[i]!='='){
89 SetError(10,"TypeDef",nowLine);
[4]90 return;
91 }
92
[78]93 const char *pTemp=expression.c_str()+i+1;
[4]94
95 //識別文字のエラーチェック(新しい型)
96 i=0;
97 for(;;i++){
98 if(temporary[i]=='\0') break;
99 if(!IsVariableChar(temporary[i])){
[78]100 SetError(10,"TypeDef",nowLine);
[4]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]!='('){
[78]109 SetError(10,"TypeDef",nowLine);
[4]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])){
[78]119 SetError(10,"TypeDef",nowLine);
[4]120 return;
121 }
122 }
123 }
124
125 //識別子が重複している場合はエラーにする
126 if(lstrcmp(temporary,pTemp)==0){
[78]127 SetError(1,NULL,nowLine);
[4]128 return;
129 }
130
131
132
133 //////////////////////////
134 // TypeDef情報を追加
135 //////////////////////////
[78]136
137 //エラー用
138 extern int cp;
139 cp = nowLine;
140
[113]141 Add( namespaceScopes, temporary, pTemp );
[4]142}
[78]143
144void TypeDefCollection::Init(){
145 // 初期化
146 clear();
147
[113]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];
[78]158 while(1){
[113]159 extern char *basbuf;
160
[78]161 i++;
162
[113]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
[78]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 }
[113]215 Add( namespaceScopes, temporary, i );
[78]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 }
[113]229 Add( namespaceScopes, temporary, "Long" );
[78]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.