1 | #include "stdafx.h"
|
---|
2 |
|
---|
3 | #include <Source.h>
|
---|
4 | #include <Class.h>
|
---|
5 | #include <Compiler.h>
|
---|
6 |
|
---|
7 | #include "../common.h"
|
---|
8 | #ifdef _AMD64_
|
---|
9 | #include "../../compiler_x64/opcode.h"
|
---|
10 | #else
|
---|
11 | #include "../../compiler_x86/opcode.h"
|
---|
12 | #endif
|
---|
13 |
|
---|
14 |
|
---|
15 | class CLoopRefCheck{
|
---|
16 | char **names;
|
---|
17 | int num;
|
---|
18 | void init(){
|
---|
19 | int i;
|
---|
20 | for(i=0;i<num;i++){
|
---|
21 | free(names[i]);
|
---|
22 | }
|
---|
23 | free(names);
|
---|
24 | }
|
---|
25 | public:
|
---|
26 | CLoopRefCheck()
|
---|
27 | {
|
---|
28 | names=(char **)malloc(1);
|
---|
29 | num=0;
|
---|
30 | }
|
---|
31 | ~CLoopRefCheck()
|
---|
32 | {
|
---|
33 | init();
|
---|
34 | }
|
---|
35 | void add(const char *lpszInheritsClass)
|
---|
36 | {
|
---|
37 | names=(char **)realloc(names,(num+1)*sizeof(char *));
|
---|
38 | names[num]=(char *)malloc(lstrlen(lpszInheritsClass)+1);
|
---|
39 | lstrcpy(names[num],lpszInheritsClass);
|
---|
40 | num++;
|
---|
41 | }
|
---|
42 | void del(const char *lpszInheritsClass)
|
---|
43 | {
|
---|
44 | int i;
|
---|
45 | for(i=0;i<num;i++){
|
---|
46 | if(lstrcmp(names[i],lpszInheritsClass)==0){
|
---|
47 | free(names[i]);
|
---|
48 | break;
|
---|
49 | }
|
---|
50 | }
|
---|
51 | if(i!=num){
|
---|
52 | num--;
|
---|
53 | for(;i<num;i++){
|
---|
54 | names[i]=names[i+1];
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|
58 | BOOL check(const CClass &inheritsClass) const
|
---|
59 | {
|
---|
60 | //ループ継承チェック
|
---|
61 | int i;
|
---|
62 | for(i=0;i<num;i++){
|
---|
63 | if( inheritsClass.GetName() == names[i] ){
|
---|
64 | return 1;
|
---|
65 | }
|
---|
66 | }
|
---|
67 | return 0;
|
---|
68 | }
|
---|
69 | };
|
---|
70 | CLoopRefCheck *pobj_LoopRefCheck;
|
---|
71 |
|
---|
72 |
|
---|
73 | void Classes::CollectClassesForNameOnly( const BasicSource &source )
|
---|
74 | {
|
---|
75 | int i, i2;
|
---|
76 | char temporary[VN_SIZE];
|
---|
77 |
|
---|
78 | // 名前空間管理
|
---|
79 | NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
|
---|
80 | namespaceScopes.clear();
|
---|
81 |
|
---|
82 | // Importsされた名前空間の管理
|
---|
83 | NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
|
---|
84 | importedNamespaces.clear();
|
---|
85 |
|
---|
86 | for(i=0;;i++){
|
---|
87 | if(source[i]=='\0') break;
|
---|
88 |
|
---|
89 | if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
|
---|
90 | for(i+=2,i2=0;;i2++,i++){
|
---|
91 | if( IsCommandDelimitation( source[i] ) ){
|
---|
92 | temporary[i2]=0;
|
---|
93 | break;
|
---|
94 | }
|
---|
95 | temporary[i2]=source[i];
|
---|
96 | }
|
---|
97 | namespaceScopes.push_back( temporary );
|
---|
98 |
|
---|
99 | continue;
|
---|
100 | }
|
---|
101 | else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
|
---|
102 | if( namespaceScopes.size() <= 0 ){
|
---|
103 | compiler.errorMessenger.Output(12, "End Namespace", i );
|
---|
104 | }
|
---|
105 | else{
|
---|
106 | namespaceScopes.pop_back();
|
---|
107 | }
|
---|
108 |
|
---|
109 | i += 2;
|
---|
110 | continue;
|
---|
111 | }
|
---|
112 | else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
|
---|
113 | for(i+=2,i2=0;;i2++,i++){
|
---|
114 | if( IsCommandDelimitation( source[i] ) ){
|
---|
115 | temporary[i2]=0;
|
---|
116 | break;
|
---|
117 | }
|
---|
118 | temporary[i2]=source[i];
|
---|
119 | }
|
---|
120 | if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
|
---|
121 | {
|
---|
122 | compiler.errorMessenger.Output(64,temporary,i );
|
---|
123 | }
|
---|
124 |
|
---|
125 | continue;
|
---|
126 | }
|
---|
127 | else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
|
---|
128 | importedNamespaces.clear();
|
---|
129 | continue;
|
---|
130 | }
|
---|
131 |
|
---|
132 | if(source[i]==1&&(
|
---|
133 | source[i+1]==ESC_CLASS||
|
---|
134 | source[i+1]==ESC_TYPE||
|
---|
135 | source[i+1]==ESC_INTERFACE
|
---|
136 | ))
|
---|
137 | {
|
---|
138 | int nowLine = i;
|
---|
139 | i += 2;
|
---|
140 |
|
---|
141 | Type blittableType;
|
---|
142 | if(memicmp(source.GetBuffer()+i,"Align(",6)==0){
|
---|
143 | //アラインメント修飾子
|
---|
144 | i+=6;
|
---|
145 | i=JumpStringInPare(source.GetBuffer(),i)+1;
|
---|
146 | }
|
---|
147 | else if( memicmp( source.GetBuffer() + i, "Blittable(", 10 ) == 0 ){
|
---|
148 | // Blittable修飾子
|
---|
149 | i+=10;
|
---|
150 | i+=GetStringInPare_RemovePare(temporary,source.GetBuffer()+i)+1;
|
---|
151 | compiler.StringToType( temporary, blittableType );
|
---|
152 | }
|
---|
153 |
|
---|
154 | bool isEnum = false;
|
---|
155 | bool isDelegate = false;
|
---|
156 | if( source[i] == 1 && source[i+1] == ESC_ENUM ){
|
---|
157 | // 列挙型の場合
|
---|
158 | isEnum = true;
|
---|
159 |
|
---|
160 | i += 2;
|
---|
161 | }
|
---|
162 | else if( source[i] == 1 && source[i+1] == ESC_DELEGATE )
|
---|
163 | {
|
---|
164 | // デリゲートの場合
|
---|
165 | isDelegate = true;
|
---|
166 |
|
---|
167 | i += 2;
|
---|
168 | }
|
---|
169 |
|
---|
170 | for(i2=0;;i++,i2++){
|
---|
171 | if(!IsVariableChar(source[i])){
|
---|
172 | temporary[i2]=0;
|
---|
173 | break;
|
---|
174 | }
|
---|
175 | temporary[i2]=source[i];
|
---|
176 | }
|
---|
177 |
|
---|
178 | //クラスを追加
|
---|
179 | CClass *pClass = this->Add(namespaceScopes, importedNamespaces, temporary,nowLine);
|
---|
180 | if( pClass ){
|
---|
181 | if( source[nowLine+1] == ESC_CLASS ){
|
---|
182 | if( isEnum )
|
---|
183 | {
|
---|
184 | pClass->SetClassType( CClass::Enum );
|
---|
185 | }
|
---|
186 | else if( isDelegate )
|
---|
187 | {
|
---|
188 | pClass->SetClassType( CClass::Delegate );
|
---|
189 | }
|
---|
190 | else{
|
---|
191 | pClass->SetClassType( CClass::Class );
|
---|
192 | }
|
---|
193 | }
|
---|
194 | else if( source[nowLine+1] == ESC_INTERFACE ){
|
---|
195 | pClass->SetClassType( CClass::Interface );
|
---|
196 | }
|
---|
197 | else{
|
---|
198 | pClass->SetClassType( CClass::Structure );
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | // Blittable型の場合
|
---|
203 | if( !blittableType.IsNull() ){
|
---|
204 | pClass->SetBlittableType( blittableType );
|
---|
205 |
|
---|
206 | // Blittable型として登録
|
---|
207 | compiler.GetObjectModule().meta.GetBlittableTypes().push_back( BlittableType( blittableType, pClass ) );
|
---|
208 | }
|
---|
209 | }
|
---|
210 | }
|
---|
211 | }
|
---|
212 |
|
---|
213 | bool Classes::MemberVar_LoopRefCheck(const CClass &objClass){
|
---|
214 | if( objClass.HasSuperClass() )
|
---|
215 | {
|
---|
216 | // 基底クラスをチェック
|
---|
217 | if( MemberVar_LoopRefCheck( objClass.GetSuperClass() ) == false )
|
---|
218 | {
|
---|
219 | return false;
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|
223 | bool result = true;
|
---|
224 | BOOST_FOREACH( CMember *pMember, objClass.GetDynamicMembers() ){
|
---|
225 | if(pMember->GetType().IsStruct()){
|
---|
226 | //循環参照でないかをチェック
|
---|
227 | if(pobj_LoopRefCheck->check(pMember->GetType().GetClass())){
|
---|
228 | extern int cp;
|
---|
229 | compiler.errorMessenger.Output(124,pMember->GetType().GetClass().GetName(),cp);
|
---|
230 | return false;
|
---|
231 | }
|
---|
232 |
|
---|
233 | pobj_LoopRefCheck->add(objClass.GetName().c_str());
|
---|
234 |
|
---|
235 | bool tempResult = MemberVar_LoopRefCheck(pMember->GetType().GetClass());
|
---|
236 | if( result )
|
---|
237 | {
|
---|
238 | result = tempResult;
|
---|
239 | }
|
---|
240 |
|
---|
241 | pobj_LoopRefCheck->del(objClass.GetName().c_str());
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | return result;
|
---|
246 | }
|
---|
247 |
|
---|
248 | void Classes::GetClass_recur(const char *lpszInheritsClass){
|
---|
249 | extern char *basbuf;
|
---|
250 | int i,i2,i3,sub_address,top_pos;
|
---|
251 | char temporary[8192];
|
---|
252 |
|
---|
253 | // 名前空間管理
|
---|
254 | NamespaceScopes backupNamespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
|
---|
255 | NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
|
---|
256 | namespaceScopes.clear();
|
---|
257 |
|
---|
258 | // Importsされた名前空間の管理
|
---|
259 | NamespaceScopesCollection backupImportedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
|
---|
260 | compiler.GetNamespaceSupporter().GetImportedNamespaces().clear();
|
---|
261 |
|
---|
262 | // 呼び出し元でコンパイル中のクラスポインタをバックアップ
|
---|
263 | const CClass *pBackCompilingClass = compiler.pCompilingClass;
|
---|
264 |
|
---|
265 | for(i=0;;i++){
|
---|
266 | if(basbuf[i]=='\0') break;
|
---|
267 |
|
---|
268 |
|
---|
269 | // 名前空間
|
---|
270 | if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
|
---|
271 | for(i+=2,i2=0;;i2++,i++){
|
---|
272 | if( IsCommandDelimitation( basbuf[i] ) ){
|
---|
273 | temporary[i2]=0;
|
---|
274 | break;
|
---|
275 | }
|
---|
276 | temporary[i2]=basbuf[i];
|
---|
277 | }
|
---|
278 | namespaceScopes.push_back( temporary );
|
---|
279 |
|
---|
280 | continue;
|
---|
281 | }
|
---|
282 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
|
---|
283 | if( namespaceScopes.size() <= 0 ){
|
---|
284 | compiler.errorMessenger.Output(12, "End Namespace", i );
|
---|
285 | }
|
---|
286 | else{
|
---|
287 | namespaceScopes.pop_back();
|
---|
288 | }
|
---|
289 |
|
---|
290 | i += 2;
|
---|
291 | continue;
|
---|
292 | }
|
---|
293 |
|
---|
294 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){
|
---|
295 | for(i+=2,i2=0;;i2++,i++){
|
---|
296 | if( IsCommandDelimitation( basbuf[i] ) ){
|
---|
297 | temporary[i2]=0;
|
---|
298 | break;
|
---|
299 | }
|
---|
300 | temporary[i2]=basbuf[i];
|
---|
301 | }
|
---|
302 | if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
|
---|
303 | {
|
---|
304 | compiler.errorMessenger.Output(64,temporary,i );
|
---|
305 | }
|
---|
306 |
|
---|
307 | continue;
|
---|
308 | }
|
---|
309 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
|
---|
310 | compiler.GetNamespaceSupporter().GetImportedNamespaces().clear();
|
---|
311 | continue;
|
---|
312 | }
|
---|
313 |
|
---|
314 |
|
---|
315 |
|
---|
316 | if(basbuf[i]==1&&basbuf[i+1]==ESC_INTERFACE){
|
---|
317 | //////////////////////////
|
---|
318 | // インターフェイス
|
---|
319 | //////////////////////////
|
---|
320 |
|
---|
321 | top_pos=i;
|
---|
322 |
|
---|
323 | i+=2;
|
---|
324 |
|
---|
325 | //インターフェイス名を取得
|
---|
326 | GetCommandToken( temporary, basbuf, i );
|
---|
327 |
|
---|
328 | char className[VN_SIZE];
|
---|
329 | Jenga::Common::Strings typeParameters;
|
---|
330 | Jenga::Common::Strings typeParameterBaseClassNames;
|
---|
331 | SplitGenericClassInstance( temporary, className, typeParameters, true, &typeParameterBaseClassNames );
|
---|
332 |
|
---|
333 | CClass *pobj_c = const_cast<CClass *>( this->Find(namespaceScopes, className) );
|
---|
334 | if(!pobj_c) continue;
|
---|
335 |
|
---|
336 | compiler.pCompilingClass = pobj_c;
|
---|
337 |
|
---|
338 | if(lpszInheritsClass){
|
---|
339 | if(lstrcmp(lpszInheritsClass,pobj_c->GetName().c_str())!=0){
|
---|
340 | //継承先先読み用
|
---|
341 | continue;
|
---|
342 | }
|
---|
343 | }
|
---|
344 |
|
---|
345 | if(pobj_c->IsReady()){
|
---|
346 | //既に先読みされているとき
|
---|
347 | continue;
|
---|
348 | }
|
---|
349 |
|
---|
350 | /////////////////////////////////////////////////////////
|
---|
351 | // ☆★☆ ジェネリクスサポート ☆★☆
|
---|
352 | for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ )
|
---|
353 | {
|
---|
354 | Type baseType( DEF_OBJECT, *GetObjectClassPtr() );
|
---|
355 | if( typeParameterBaseClassNames[i2].size() )
|
---|
356 | {
|
---|
357 | if( !compiler.StringToType( typeParameterBaseClassNames[i2], baseType ) )
|
---|
358 | {
|
---|
359 | compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
|
---|
360 | }
|
---|
361 | else if( !baseType.IsObject() )
|
---|
362 | {
|
---|
363 | compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
|
---|
364 | }
|
---|
365 | }
|
---|
366 |
|
---|
367 | pobj_c->AddFormalGenericType( GenericType( typeParameters[i2], baseType ) );
|
---|
368 | }
|
---|
369 | /////////////////////////////////////////////////////////
|
---|
370 |
|
---|
371 | pobj_c->Readed();
|
---|
372 |
|
---|
373 | pobj_c->SetConstructorMemberSubIndex( -1 );
|
---|
374 | pobj_c->SetDestructorMemberSubIndex( -1 );
|
---|
375 |
|
---|
376 | if( memcmp( basbuf+i+1, "__COM", 5 ) == 0 && IsCommandDelimitation( basbuf[i+1+5] ) )
|
---|
377 | {
|
---|
378 | // COMインターフェイス
|
---|
379 | pobj_c->SetClassType( CClass::ComInterface );
|
---|
380 |
|
---|
381 | i += 6;
|
---|
382 | }
|
---|
383 |
|
---|
384 | if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS){
|
---|
385 | //継承を行う場合
|
---|
386 | for(i+=3,i2=0;;i++,i2++){
|
---|
387 | if(IsCommandDelimitation(basbuf[i])){
|
---|
388 | temporary[i2]=0;
|
---|
389 | break;
|
---|
390 | }
|
---|
391 | temporary[i2]=basbuf[i];
|
---|
392 | }
|
---|
393 |
|
---|
394 | if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
|
---|
395 | compiler.errorMessenger.Output(105,temporary,i);
|
---|
396 | goto Interface_InheritsError;
|
---|
397 | }
|
---|
398 |
|
---|
399 | //継承元クラスを取得
|
---|
400 | const Classes &classes = *this;
|
---|
401 | const CClass *pInheritsClass = classes.Find(temporary);
|
---|
402 | if( !pInheritsClass ){
|
---|
403 | compiler.errorMessenger.Output(106,temporary,i);
|
---|
404 | goto Interface_InheritsError;
|
---|
405 | }
|
---|
406 |
|
---|
407 | //継承させる
|
---|
408 | if( !pobj_c->InheritsClass( *pInheritsClass, Types(), i ) ){
|
---|
409 | goto Interface_InheritsError;
|
---|
410 | }
|
---|
411 | }
|
---|
412 | else{
|
---|
413 | //継承無し
|
---|
414 | if( &pobj_c->GetSuperClass() || pobj_c->GetVtblNum() )
|
---|
415 | {
|
---|
416 | // TODO: ここに来ないことが実証できたらこの分岐は消す
|
---|
417 | Jenga::Throw( "GetClass_recur内の例外" );
|
---|
418 | }
|
---|
419 | }
|
---|
420 | Interface_InheritsError:
|
---|
421 |
|
---|
422 | //メンバ変数、関数を取得
|
---|
423 | while(1){
|
---|
424 | i++;
|
---|
425 |
|
---|
426 | //エラー
|
---|
427 | if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE||basbuf[i+1]==ESC_INTERFACE)){
|
---|
428 | compiler.errorMessenger.Output(22,"Interface",i);
|
---|
429 | i--;
|
---|
430 | break;
|
---|
431 | }
|
---|
432 |
|
---|
433 | if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
|
---|
434 | compiler.errorMessenger.Output(111,NULL,i);
|
---|
435 | break;
|
---|
436 | }
|
---|
437 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPLEMENTS )
|
---|
438 | {
|
---|
439 | compiler.errorMessenger.Output(137, NULL, i );
|
---|
440 | break;
|
---|
441 | }
|
---|
442 |
|
---|
443 | sub_address=i;
|
---|
444 |
|
---|
445 | for(i2=0;;i++,i2++){
|
---|
446 | if(IsCommandDelimitation(basbuf[i])){
|
---|
447 | temporary[i2]=0;
|
---|
448 | break;
|
---|
449 | }
|
---|
450 | temporary[i2]=basbuf[i];
|
---|
451 | }
|
---|
452 | if(temporary[0]=='\0'){
|
---|
453 | if(basbuf[i]=='\0'){
|
---|
454 | i--;
|
---|
455 | compiler.errorMessenger.Output(22,"Interface",top_pos);
|
---|
456 | break;
|
---|
457 | }
|
---|
458 | continue;
|
---|
459 | }
|
---|
460 |
|
---|
461 | //End Interface記述の場合
|
---|
462 | if(temporary[0]==1&&temporary[1]==ESC_ENDINTERFACE) break;
|
---|
463 |
|
---|
464 | if(!(temporary[0]==1&&(
|
---|
465 | temporary[1]==ESC_SUB||temporary[1]==ESC_FUNCTION
|
---|
466 | ))){
|
---|
467 | compiler.errorMessenger.Output(1,NULL,i);
|
---|
468 | break;
|
---|
469 | }
|
---|
470 |
|
---|
471 | //メンバ関数を追加
|
---|
472 | pobj_c->AddMethod(pobj_c,
|
---|
473 | Prototype::Public, //Publicアクセス権
|
---|
474 | 0, // bStatic
|
---|
475 | false, // isConst
|
---|
476 | true, // isAbstract
|
---|
477 | true, // isVirtual
|
---|
478 | false, // isOverride
|
---|
479 | false, // isAutoGeneration
|
---|
480 | temporary,
|
---|
481 | sub_address
|
---|
482 | );
|
---|
483 | }
|
---|
484 | }
|
---|
485 |
|
---|
486 | if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
|
---|
487 | //////////////////////////
|
---|
488 | // クラス
|
---|
489 | //////////////////////////
|
---|
490 |
|
---|
491 | top_pos=i;
|
---|
492 |
|
---|
493 | const DWORD dwClassType=basbuf[i+1];
|
---|
494 |
|
---|
495 | i+=2;
|
---|
496 |
|
---|
497 | int iAlign=0;
|
---|
498 | if(memicmp(basbuf+i,"Align(",6)==0){
|
---|
499 | //アラインメント修飾子
|
---|
500 | i+=6;
|
---|
501 | i+=GetStringInPare_RemovePare(temporary,basbuf+i)+1;
|
---|
502 | iAlign=atoi(temporary);
|
---|
503 |
|
---|
504 | if( dwClassType != ESC_TYPE )
|
---|
505 | {
|
---|
506 | compiler.errorMessenger.Output(140,NULL,i);
|
---|
507 | }
|
---|
508 |
|
---|
509 | if(!(iAlign==1||iAlign==2||iAlign==4||iAlign==8||iAlign==16))
|
---|
510 | compiler.errorMessenger.Output(51,NULL,i);
|
---|
511 | }
|
---|
512 | else if( memicmp( basbuf + i, "Blittable(", 10 ) == 0 ){
|
---|
513 | // Blittable修飾子
|
---|
514 | i+=10;
|
---|
515 | i=JumpStringInPare(basbuf,i)+1;
|
---|
516 |
|
---|
517 | if( dwClassType != ESC_CLASS )
|
---|
518 | {
|
---|
519 | compiler.errorMessenger.Output(141,NULL,i);
|
---|
520 | }
|
---|
521 | }
|
---|
522 |
|
---|
523 | if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENUM )
|
---|
524 | {
|
---|
525 | // 列挙型の場合
|
---|
526 | i += 2;
|
---|
527 | }
|
---|
528 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_DELEGATE )
|
---|
529 | {
|
---|
530 | // デリゲートの場合
|
---|
531 | i += 2;
|
---|
532 | }
|
---|
533 |
|
---|
534 | //クラス名を取得
|
---|
535 | GetCommandToken( temporary, basbuf, i );
|
---|
536 |
|
---|
537 | char className[VN_SIZE];
|
---|
538 | Jenga::Common::Strings typeParameters;
|
---|
539 | Jenga::Common::Strings typeParameterBaseClassNames;
|
---|
540 | SplitGenericClassInstance( temporary, className, typeParameters, true, &typeParameterBaseClassNames );
|
---|
541 |
|
---|
542 | CClass *pobj_c = const_cast<CClass *>( this->Find(namespaceScopes, className) );
|
---|
543 | if(!pobj_c) continue;
|
---|
544 |
|
---|
545 | compiler.pCompilingClass = pobj_c;
|
---|
546 |
|
---|
547 | if(lpszInheritsClass){
|
---|
548 | if( pobj_c->GetName() != lpszInheritsClass ){
|
---|
549 | //継承先先読み用
|
---|
550 | continue;
|
---|
551 | }
|
---|
552 | }
|
---|
553 |
|
---|
554 | if(pobj_c->IsReady()){
|
---|
555 | //既に先読みされているとき
|
---|
556 | continue;
|
---|
557 | }
|
---|
558 |
|
---|
559 |
|
---|
560 | /////////////////////////////////////////////////////////
|
---|
561 | // ☆★☆ ジェネリクスサポート ☆★☆
|
---|
562 | for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ )
|
---|
563 | {
|
---|
564 | Type baseType( DEF_OBJECT, *GetObjectClassPtr() );
|
---|
565 | if( typeParameterBaseClassNames[i2].size() )
|
---|
566 | {
|
---|
567 | if( !compiler.StringToType( typeParameterBaseClassNames[i2], baseType ) )
|
---|
568 | {
|
---|
569 | compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
|
---|
570 | }
|
---|
571 | else if( !baseType.IsObject() )
|
---|
572 | {
|
---|
573 | compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
|
---|
574 | }
|
---|
575 | }
|
---|
576 |
|
---|
577 | pobj_c->AddFormalGenericType( GenericType( typeParameters[i2], baseType ) );
|
---|
578 | }
|
---|
579 | /////////////////////////////////////////////////////////
|
---|
580 |
|
---|
581 |
|
---|
582 | pobj_c->SetFixedAlignment( iAlign );
|
---|
583 |
|
---|
584 | pobj_c->Readed();
|
---|
585 |
|
---|
586 | pobj_c->SetConstructorMemberSubIndex( -1 );
|
---|
587 | pobj_c->SetDestructorMemberSubIndex( -1 );
|
---|
588 |
|
---|
589 | //アクセス制限の初期値をセット
|
---|
590 | Prototype::Accessibility accessibility;
|
---|
591 | if(dwClassType==ESC_CLASS){
|
---|
592 | accessibility = Prototype::Private;
|
---|
593 | }
|
---|
594 | else{
|
---|
595 | accessibility = Prototype::Public;
|
---|
596 | }
|
---|
597 |
|
---|
598 | if( pobj_c->GetName() == "Object"
|
---|
599 | || dwClassType == ESC_TYPE )
|
---|
600 | {
|
---|
601 | // 何も継承しない
|
---|
602 |
|
---|
603 | if( &pobj_c->GetSuperClass() || pobj_c->GetVtblNum() )
|
---|
604 | {
|
---|
605 | // TODO: ここに来ないことが実証できたらこの分岐は消す
|
---|
606 | Jenga::Throw( "GetClass_recur内の例外" );
|
---|
607 | }
|
---|
608 | }
|
---|
609 | else{
|
---|
610 | if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS)
|
---|
611 | {
|
---|
612 | // クラス継承先が指定されているとき
|
---|
613 | i += 3;
|
---|
614 | GetCommandToken( temporary, basbuf, i );
|
---|
615 |
|
---|
616 | if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
|
---|
617 | compiler.errorMessenger.Output(105,temporary,i);
|
---|
618 | goto InheritsError;
|
---|
619 | }
|
---|
620 | }
|
---|
621 | else
|
---|
622 | {
|
---|
623 | // 何の指定もないときはObjectクラスを継承する
|
---|
624 | lstrcpy( temporary, "Object" );
|
---|
625 | }
|
---|
626 | pobj_c->Inherits( temporary, i );
|
---|
627 |
|
---|
628 | if( basbuf[i+1] == 1 && basbuf[i+2] == ESC_IMPLEMENTS )
|
---|
629 | {
|
---|
630 | // インターフェイス実装を行う場合
|
---|
631 | i += 3;
|
---|
632 | GetCommandToken( temporary, basbuf, i );
|
---|
633 |
|
---|
634 | pobj_c->Implements( temporary, i );
|
---|
635 | }
|
---|
636 | }
|
---|
637 | InheritsError:
|
---|
638 |
|
---|
639 | //メンバとメソッドを取得
|
---|
640 | while(1){
|
---|
641 | i++;
|
---|
642 |
|
---|
643 | //エラー
|
---|
644 | if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
|
---|
645 | compiler.errorMessenger.Output(22,"Class",i);
|
---|
646 | i--;
|
---|
647 | break;
|
---|
648 | }
|
---|
649 |
|
---|
650 | if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
|
---|
651 | compiler.errorMessenger.Output(111,NULL,i);
|
---|
652 | break;
|
---|
653 | }
|
---|
654 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPLEMENTS )
|
---|
655 | {
|
---|
656 | compiler.errorMessenger.Output(137, NULL, i );
|
---|
657 | break;
|
---|
658 | }
|
---|
659 |
|
---|
660 | //Static修飾子
|
---|
661 | BOOL bStatic;
|
---|
662 | if(basbuf[i]==1&&basbuf[i+1]==ESC_STATIC){
|
---|
663 | bStatic=1;
|
---|
664 | i+=2;
|
---|
665 | }
|
---|
666 | else bStatic=0;
|
---|
667 |
|
---|
668 | //Const修飾子
|
---|
669 | bool isConst = false;
|
---|
670 | if( basbuf[i] == 1 && basbuf[i + 1] == ESC_CONST ){
|
---|
671 | isConst = true;
|
---|
672 | i += 2;
|
---|
673 | }
|
---|
674 |
|
---|
675 | if(basbuf[i]==1&&(
|
---|
676 | basbuf[i+1]==ESC_ABSTRACT||basbuf[i+1]==ESC_VIRTUAL||basbuf[i+1]==ESC_OVERRIDE||
|
---|
677 | basbuf[i+1]==ESC_SUB||basbuf[i+1]==ESC_FUNCTION
|
---|
678 | )){
|
---|
679 | i3=basbuf[i+1];
|
---|
680 | sub_address=i;
|
---|
681 | }
|
---|
682 | else i3=0;
|
---|
683 |
|
---|
684 | bool isVirtual = false, isAbstract = false, isOverride = false;
|
---|
685 | if(i3==ESC_ABSTRACT){
|
---|
686 | isAbstract=1;
|
---|
687 | isVirtual=1;
|
---|
688 | i+=2;
|
---|
689 |
|
---|
690 | i3=basbuf[i+1];
|
---|
691 | }
|
---|
692 | else if(i3==ESC_VIRTUAL){
|
---|
693 | isAbstract=0;
|
---|
694 | isVirtual=1;
|
---|
695 | i+=2;
|
---|
696 |
|
---|
697 | i3=basbuf[i+1];
|
---|
698 | }
|
---|
699 | else if(i3==ESC_OVERRIDE){
|
---|
700 | isOverride=1;
|
---|
701 | isVirtual=1;
|
---|
702 |
|
---|
703 | i+=2;
|
---|
704 |
|
---|
705 | i3=basbuf[i+1];
|
---|
706 | }
|
---|
707 |
|
---|
708 | for(i2=0;;i++,i2++){
|
---|
709 | if(IsCommandDelimitation(basbuf[i])){
|
---|
710 | temporary[i2]=0;
|
---|
711 | break;
|
---|
712 | }
|
---|
713 | temporary[i2]=basbuf[i];
|
---|
714 | }
|
---|
715 | if(temporary[0]=='\0'){
|
---|
716 | if(basbuf[i]=='\0'){
|
---|
717 |
|
---|
718 | if(dwClassType==ESC_CLASS)
|
---|
719 | compiler.errorMessenger.Output(22,"Class",top_pos);
|
---|
720 | else
|
---|
721 | compiler.errorMessenger.Output(22,"Type",top_pos);
|
---|
722 |
|
---|
723 | i--;
|
---|
724 | break;
|
---|
725 | }
|
---|
726 | continue;
|
---|
727 | }
|
---|
728 |
|
---|
729 | //End Class記述の場合
|
---|
730 | if(temporary[0]==1&&temporary[1]==ESC_ENDCLASS&&dwClassType==ESC_CLASS) break;
|
---|
731 | if(temporary[0]==1&&temporary[1]==ESC_ENDTYPE&&dwClassType==ESC_TYPE) break;
|
---|
732 |
|
---|
733 | //アクセスを変更
|
---|
734 | if(lstrcmpi(temporary,"Private")==0){
|
---|
735 | accessibility = Prototype::Private;
|
---|
736 | continue;
|
---|
737 | }
|
---|
738 | if(lstrcmpi(temporary,"Public")==0){
|
---|
739 | accessibility = Prototype::Public;
|
---|
740 | continue;
|
---|
741 | }
|
---|
742 | if(lstrcmpi(temporary,"Protected")==0){
|
---|
743 | accessibility = Prototype::Protected;
|
---|
744 | continue;
|
---|
745 | }
|
---|
746 |
|
---|
747 | extern int cp;
|
---|
748 | if(i3==0){
|
---|
749 | if(bStatic){
|
---|
750 | //静的メンバを追加
|
---|
751 | cp=i; //エラー用
|
---|
752 | pobj_c->AddStaticMember( accessibility, isConst, false, temporary, i);
|
---|
753 | }
|
---|
754 | else{
|
---|
755 | //メンバを追加
|
---|
756 | cp=i; //エラー用
|
---|
757 | pobj_c->AddMember( accessibility, isConst, false, temporary, i );
|
---|
758 |
|
---|
759 |
|
---|
760 | if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
|
---|
761 | if( !pobj_c->GetDynamicMembers().back()->GetType().GetClass().IsReady() ){
|
---|
762 | //参照先が読み取られていないとき
|
---|
763 | GetClass_recur(pobj_c->GetDynamicMembers().back()->GetType().GetClass().GetName().c_str());
|
---|
764 | }
|
---|
765 | }
|
---|
766 |
|
---|
767 |
|
---|
768 | if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
|
---|
769 | //循環参照のチェック
|
---|
770 | pobj_LoopRefCheck->add(pobj_c->GetName().c_str());
|
---|
771 | if(!MemberVar_LoopRefCheck(pobj_c->GetDynamicMembers().back()->GetType().GetClass())){
|
---|
772 | //エラー回避
|
---|
773 | Type &type = const_cast<Type &>(pobj_c->GetDynamicMembers().back()->GetType());
|
---|
774 | type.SetBasicType( DEF_PTR_VOID );
|
---|
775 | }
|
---|
776 | pobj_LoopRefCheck->del(pobj_c->GetName().c_str());
|
---|
777 | }
|
---|
778 | }
|
---|
779 | }
|
---|
780 | else{
|
---|
781 | //メソッドを追加
|
---|
782 | cp=i; //エラー用
|
---|
783 | pobj_c->AddMethod(pobj_c,
|
---|
784 | accessibility,
|
---|
785 | bStatic,
|
---|
786 | isConst,
|
---|
787 | isAbstract,
|
---|
788 | isVirtual,
|
---|
789 | isOverride,
|
---|
790 | false,
|
---|
791 | temporary,
|
---|
792 | sub_address);
|
---|
793 |
|
---|
794 | if( isAbstract ) continue;
|
---|
795 |
|
---|
796 | for(;;i++){
|
---|
797 | if(basbuf[i]=='\0'){
|
---|
798 | i--;
|
---|
799 | break;
|
---|
800 | }
|
---|
801 | if(basbuf[i-1]!='*'&&
|
---|
802 | basbuf[i]==1&&(
|
---|
803 | basbuf[i+1]==ESC_SUB||
|
---|
804 | basbuf[i+1]==ESC_FUNCTION||
|
---|
805 | basbuf[i+1]==ESC_MACRO||
|
---|
806 | basbuf[i+1]==ESC_TYPE||
|
---|
807 | basbuf[i+1]==ESC_CLASS||
|
---|
808 | basbuf[i+1]==ESC_INTERFACE||
|
---|
809 | basbuf[i+1]==ESC_ENUM)){
|
---|
810 | GetDefaultNameFromES(i3,temporary);
|
---|
811 | compiler.errorMessenger.Output(22,temporary,i);
|
---|
812 | }
|
---|
813 | if(basbuf[i]==1&&basbuf[i+1]==GetEndXXXCommand((char)i3)){
|
---|
814 | i+=2;
|
---|
815 | break;
|
---|
816 | }
|
---|
817 | }
|
---|
818 | }
|
---|
819 | }
|
---|
820 | }
|
---|
821 | }
|
---|
822 |
|
---|
823 | // 呼び出し元でコンパイル中のクラスポインタを元に戻す
|
---|
824 | compiler.pCompilingClass = pBackCompilingClass;
|
---|
825 |
|
---|
826 | // 名前空間を元に戻す
|
---|
827 | compiler.GetNamespaceSupporter().GetLivingNamespaceScopes() = backupNamespaceScopes;
|
---|
828 |
|
---|
829 | // インポートされた名前空間を元に戻す
|
---|
830 | compiler.GetNamespaceSupporter().GetImportedNamespaces() = backupImportedNamespaces;
|
---|
831 | }
|
---|
832 |
|
---|
833 | void Classes::LookaheadClass( const char *className )
|
---|
834 | {
|
---|
835 | pobj_LoopRefCheck->add( className );
|
---|
836 | compiler.GetObjectModule().meta.GetClasses().GetClass_recur( className );
|
---|
837 | pobj_LoopRefCheck->del( className );
|
---|
838 | }
|
---|
839 |
|
---|
840 | bool Classes::LoopRefCheck( const CClass &objClass )
|
---|
841 | {
|
---|
842 | if( pobj_LoopRefCheck->check( objClass ) )
|
---|
843 | {
|
---|
844 | return false;
|
---|
845 | }
|
---|
846 |
|
---|
847 | return true;
|
---|
848 | }
|
---|
849 |
|
---|
850 | void Classes::GetAllClassInfo(void){
|
---|
851 | //ループ継承チェック用のクラス
|
---|
852 | pobj_LoopRefCheck=new CLoopRefCheck();
|
---|
853 |
|
---|
854 | //クラスを取得
|
---|
855 | GetClass_recur(0);
|
---|
856 |
|
---|
857 | delete pobj_LoopRefCheck;
|
---|
858 | pobj_LoopRefCheck=0;
|
---|
859 |
|
---|
860 | // イテレータの準備
|
---|
861 | this->Iterator_Init();
|
---|
862 | }
|
---|