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

Last change on this file since 523 was 523, checked in by dai_9181, 15 years ago

ヘッダファイルを整理中

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