1 | #include "common.h"
|
---|
2 |
|
---|
3 |
|
---|
4 | TypeDef::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 | }
|
---|
14 | TypeDef::~TypeDef(){
|
---|
15 | }
|
---|
16 |
|
---|
17 | bool 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 | }
|
---|
24 | bool 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 |
|
---|
51 | TypeDefCollection::TypeDefCollection(){
|
---|
52 | }
|
---|
53 | TypeDefCollection::~TypeDefCollection(){
|
---|
54 | }
|
---|
55 | void TypeDefCollection::Add( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName ){
|
---|
56 | TypeDef typeDef( namespaceScopes, name, baseName );
|
---|
57 | this->push_back( typeDef );
|
---|
58 | }
|
---|
59 | int 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 | }
|
---|
68 | int 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 |
|
---|
76 | void 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 |
|
---|
144 | void TypeDefCollection::Init(){
|
---|
145 | // 初期化
|
---|
146 | clear();
|
---|
147 |
|
---|
148 | // 名前空間管理
|
---|
149 | NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
|
---|
150 | namespaceScopes.clear();
|
---|
151 |
|
---|
152 | // Importsされた名前空間の管理
|
---|
153 | NamespaceScopesCollection &importedNamespaces = Smoothie::Temp::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 | if( !importedNamespaces.Imports( temporary ) )
|
---|
195 | {
|
---|
196 | SetError(64,temporary,cp );
|
---|
197 | }
|
---|
198 |
|
---|
199 | continue;
|
---|
200 | }
|
---|
201 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
|
---|
202 | importedNamespaces.clear();
|
---|
203 | continue;
|
---|
204 | }
|
---|
205 |
|
---|
206 | if( basbuf[i]==1 ){
|
---|
207 | char temporary[VN_SIZE];
|
---|
208 | if(basbuf[i+1]==ESC_TYPEDEF){
|
---|
209 | int i2 = 0;
|
---|
210 | for(i+=2;;i2++,i++){
|
---|
211 | if(basbuf[i]=='\n'){
|
---|
212 | temporary[i2]=0;
|
---|
213 | break;
|
---|
214 | }
|
---|
215 | temporary[i2]=basbuf[i];
|
---|
216 | if(basbuf[i]=='\0') break;
|
---|
217 | }
|
---|
218 | Add( namespaceScopes, temporary, i );
|
---|
219 |
|
---|
220 | continue;
|
---|
221 | }
|
---|
222 | else if( basbuf[i+1] == ESC_CONST && basbuf[i+2] == 1 && basbuf[i+3] == ESC_ENUM ){
|
---|
223 | int i2 = 0;
|
---|
224 | for(i+=4;;i2++,i++){
|
---|
225 | if(!IsVariableChar(basbuf[i])){
|
---|
226 | temporary[i2]=0;
|
---|
227 | break;
|
---|
228 | }
|
---|
229 | temporary[i2]=basbuf[i];
|
---|
230 | if(basbuf[i]=='\0') break;
|
---|
231 | }
|
---|
232 | Add( namespaceScopes, temporary, "Long" );
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | //次の行
|
---|
237 | for(;;i++){
|
---|
238 | if(IsCommandDelimitation(basbuf[i])) break;
|
---|
239 | }
|
---|
240 | if(basbuf[i]=='\0') break;
|
---|
241 | }
|
---|
242 | }
|
---|