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