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