source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Class.cpp@ 682

Last change on this file since 682 was 682, checked in by dai_9181, 16 years ago

テスト用のコードを除去

File size: 38.9 KB
Line 
1#include "stdafx.h"
2
3#include "../common.h"
4#ifdef _AMD64_
5#include "../../compiler_x64/opcode.h"
6#else
7#include "../../compiler_x86/opcode.h"
8#endif
9
10using namespace ActiveBasic::Compiler;
11
12
13void LexicalAnalyzer::CollectClassesForNameOnly( const char *source, Classes &classes )
14{
15 int i, i2;
16 char temporary[VN_SIZE];
17
18 // 名前空間管理
19 NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
20 namespaceScopes.clear();
21
22 // Imports情報のクリア
23 compiler.GetNamespaceSupporter().ClearImportedNamespaces();
24
25 for(i=0;;i++){
26 if(source[i]=='\0') break;
27
28 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
29 for(i+=2,i2=0;;i2++,i++){
30 if( IsCommandDelimitation( source[i] ) ){
31 temporary[i2]=0;
32 break;
33 }
34 temporary[i2]=source[i];
35 }
36 namespaceScopes.push_back( temporary );
37
38 continue;
39 }
40 else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
41 if( namespaceScopes.size() <= 0 ){
42 compiler.errorMessenger.Output(12, "End Namespace", i );
43 }
44 else{
45 namespaceScopes.pop_back();
46 }
47
48 i += 2;
49 continue;
50 }
51 else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
52 for(i+=2,i2=0;;i2++,i++){
53 if( IsCommandDelimitation( source[i] ) ){
54 temporary[i2]=0;
55 break;
56 }
57 temporary[i2]=source[i];
58 }
59 if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
60 {
61 compiler.errorMessenger.Output(64,temporary,i );
62 }
63
64 continue;
65 }
66 else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED )
67 {
68 // Imports情報のクリア
69 compiler.GetNamespaceSupporter().ClearImportedNamespaces();
70 continue;
71 }
72
73 if(source[i]==1&&(
74 source[i+1]==ESC_CLASS||
75 source[i+1]==ESC_TYPE||
76 source[i+1]==ESC_INTERFACE
77 ))
78 {
79 int nowLine = i;
80 i += 2;
81
82 Type blittableType;
83 if(memicmp(source+i,"Align(",6)==0){
84 //アラインメント修飾子
85 i+=6;
86 i=JumpStringInPare(source,i)+1;
87 }
88 else if( memicmp( source + i, "Blittable(", 10 ) == 0 ){
89 // Blittable修飾子
90 i+=10;
91 i+=GetStringInPare_RemovePare(temporary,source+i)+1;
92 compiler.StringToType( temporary, blittableType );
93 }
94
95 bool isEnum = false;
96 bool isDelegate = false;
97 if( source[i] == 1 && source[i+1] == ESC_ENUM ){
98 // 列挙型の場合
99 isEnum = true;
100
101 i += 2;
102 }
103 else if( source[i] == 1 && source[i+1] == ESC_DELEGATE )
104 {
105 // デリゲートの場合
106 isDelegate = true;
107
108 i += 2;
109 }
110
111 for(i2=0;;i++,i2++){
112 if(!IsVariableChar(source[i])){
113 temporary[i2]=0;
114 break;
115 }
116 temporary[i2]=source[i];
117 }
118
119 //クラスを追加
120 CClass *pClass = new CClass( Symbol( namespaceScopes, temporary ), compiler.GetNamespaceSupporter().GetImportedNamespaces() );
121 if( classes.IsExist( pClass ) )
122 {
123 // 既に存在している
124 compiler.errorMessenger.Output(15,pClass->GetName(), nowLine);
125
126 delete pClass;
127
128 continue;
129 }
130
131 classes.Put( pClass );
132
133 if( source[nowLine+1] == ESC_CLASS )
134 {
135 if( isEnum )
136 {
137 pClass->SetClassType( CClass::Enum );
138 }
139 else if( isDelegate )
140 {
141 pClass->SetClassType( CClass::Delegate );
142 }
143 else{
144 pClass->SetClassType( CClass::Class );
145 }
146 }
147 else if( source[nowLine+1] == ESC_INTERFACE )
148 {
149 pClass->SetClassType( CClass::Interface );
150 }
151 else
152 {
153 pClass->SetClassType( CClass::Structure );
154 }
155
156 // Blittable型の場合
157 if( !blittableType.IsNull() ){
158 pClass->SetBlittableType( blittableType );
159
160 // Blittable型として登録
161 compiler.GetObjectModule().meta.GetBlittableTypes().push_back( BlittableType( blittableType, pClass ) );
162 }
163 }
164 }
165}
166
167
168class CLoopRefCheck{
169 char **names;
170 int num;
171 void init(){
172 int i;
173 for(i=0;i<num;i++){
174 free(names[i]);
175 }
176 free(names);
177 }
178public:
179 CLoopRefCheck()
180 {
181 names=(char **)malloc(1);
182 num=0;
183 }
184 ~CLoopRefCheck()
185 {
186 init();
187 }
188 void add(const char *lpszInheritsClass)
189 {
190 names=(char **)realloc(names,(num+1)*sizeof(char *));
191 names[num]=(char *)malloc(lstrlen(lpszInheritsClass)+1);
192 lstrcpy(names[num],lpszInheritsClass);
193 num++;
194 }
195 void del(const char *lpszInheritsClass)
196 {
197 int i;
198 for(i=0;i<num;i++){
199 if(lstrcmp(names[i],lpszInheritsClass)==0){
200 free(names[i]);
201 break;
202 }
203 }
204 if(i!=num){
205 num--;
206 for(;i<num;i++){
207 names[i]=names[i+1];
208 }
209 }
210 }
211 BOOL check(const CClass &inheritsClass) const
212 {
213 //ループ継承チェック
214 int i;
215 for(i=0;i<num;i++){
216 if( inheritsClass.GetName() == names[i] ){
217 return 1;
218 }
219 }
220 return 0;
221 }
222};
223CLoopRefCheck *pobj_LoopRefCheck;
224
225bool MemberVar_LoopRefCheck(const CClass &objClass){
226 if( objClass.HasSuperClass() )
227 {
228 // 基底クラスをチェック
229 if( MemberVar_LoopRefCheck( objClass.GetSuperClass() ) == false )
230 {
231 return false;
232 }
233 }
234
235 bool result = true;
236 BOOST_FOREACH( Member *pMember, objClass.GetDynamicMembers() ){
237 if(pMember->GetType().IsStruct()){
238 //循環参照でないかをチェック
239 if(pobj_LoopRefCheck->check(pMember->GetType().GetClass())){
240 extern int cp;
241 compiler.errorMessenger.Output(124,pMember->GetType().GetClass().GetName(),cp);
242 return false;
243 }
244
245 pobj_LoopRefCheck->add(objClass.GetName().c_str());
246
247 bool tempResult = MemberVar_LoopRefCheck(pMember->GetType().GetClass());
248 if( result )
249 {
250 result = tempResult;
251 }
252
253 pobj_LoopRefCheck->del(objClass.GetName().c_str());
254 }
255 }
256
257 return result;
258}
259
260void OverrideErrorCheck( const DynamicMethod::OverrideResult &result )
261{
262 switch( result.enumType )
263 {
264 case DynamicMethod::OverrideResult::Successful:
265 break;
266 case DynamicMethod::OverrideResult::NotVirtual:
267 compiler.errorMessenger.Output(136, result.pMethod->GetUserProc().GetName(), cp);
268 break;
269 case DynamicMethod::OverrideResult::NotUseOverrideModifier:
270 compiler.errorMessenger.Output(127, result.pMethod->GetUserProc().GetName(), cp);
271 break;
272 case DynamicMethod::OverrideResult::DifferentAccesibility:
273 compiler.errorMessenger.Output(128, result.pMethod->GetUserProc().GetName(), cp);
274 break;
275 default:
276 throw;
277 }
278}
279
280Member *LexicalAnalyzer::CreateMember( const CClass &_class, Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine )
281{
282 extern int cp;
283
284 //構文を解析
285 char VarName[VN_SIZE];
286 char initBuffer[VN_SIZE];
287 char lpszConstructParameter[VN_SIZE];
288 Subscripts subscripts;
289 Type type;
290 if( !GetDimentionFormat(buffer,VarName,subscripts,type,initBuffer,lpszConstructParameter) )
291 {
292 return NULL;
293 }
294
295 //重複チェック
296 if( _class.DupliCheckAll( VarName ) ){
297 compiler.errorMessenger.Output(15,VarName,cp);
298 }
299
300 Member *pMember = new Member( accessibility, VarName, type, isConst, subscripts, initBuffer, lpszConstructParameter );
301 pMember->source_code_address = nowLine;
302 return pMember;
303}
304
305void LexicalAnalyzer::AddMethod(CClass *pobj_c, UserProc *pUserProc, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
306 bool isVirtual, bool isOverride, const char *interfaceName, bool isAutoGeneration, int nowLine)
307{
308 if( isAutoGeneration )
309 {
310 // コード自動生成
311 pUserProc->ThisIsAutoGenerationProc();
312 }
313
314
315 ////////////////////////////////////////////////////////////
316 // コンストラクタ、デストラクタの場合の処理
317 ////////////////////////////////////////////////////////////
318 BOOL fConstructor=0,bDestructor=0;
319
320 if( pUserProc->GetName() == pobj_c->GetName() ){
321 //コンストラクタの場合
322
323 //標準コンストラクタ(引数なし)
324 if(pUserProc->Params().size()==0) fConstructor=1;
325
326 //強制的にConst修飾子をつける
327 isConst = true;
328 }
329 else if(pUserProc->GetName()[0]=='~'){
330 //デストラクタの場合はその名前が正しいかチェックを行う
331 if(lstrcmp(pUserProc->GetName().c_str()+1,pobj_c->GetName().c_str())!=0)
332 compiler.errorMessenger.Output(117,NULL,nowLine);
333 else
334 bDestructor=1;
335 }
336 if(fConstructor||bDestructor){
337 // コンストラクタ、デストラクタのアクセシビリティをチェック
338
339 //強制的にConst修飾子をつける
340 isConst = true;
341 }
342
343 if( fConstructor == 1 )
344 pobj_c->SetConstructorMemberSubIndex( (int)pobj_c->GetDynamicMethods().size() );
345 else if( bDestructor )
346 pobj_c->SetDestructorMemberSubIndex( (int)pobj_c->GetDynamicMethods().size() );
347
348
349
350 //////////////////
351 // 重複チェック
352 //////////////////
353
354 if(pobj_c->DupliCheckMember( pUserProc->GetName().c_str() )){
355 compiler.errorMessenger.Output(15,pUserProc->GetName(),nowLine);
356 return;
357 }
358
359 //メソッド
360 BOOST_FOREACH( const CMethod *pMethod, pobj_c->GetDynamicMethods() )
361 {
362 //基底クラスと重複する場合はオーバーライドを行う
363 if( pMethod->GetInheritsClassPtr() ) continue;
364
365 if( pMethod->GetUserProc().IsEqualForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc ) )
366 {
367 //関数名、パラメータ、戻り値が合致したとき
368 compiler.errorMessenger.Output(15,pUserProc->GetName().c_str(),nowLine);
369 return;
370 }
371 }
372
373 //仮想関数の場合
374 if( isAbstract ) pUserProc->CompleteCompile();
375
376 // メソッドのオーバーライド
377 DynamicMethod *pMethodForOverride = pobj_c->GetDynamicMethods().FindForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc );
378 if( pMethodForOverride )
379 {
380 DynamicMethod::OverrideResult result;
381 result.enumType = pMethodForOverride->Override( pUserProc, accessibility, isOverride );
382 result.pMethod = pMethodForOverride;
383 OverrideErrorCheck( result );
384
385 pUserProc->SetMethod( pMethodForOverride );
386 return;
387 }
388 else
389 {
390 // インターフェイス メソッドのオーバーライド
391 BOOST_FOREACH( ::Interface *pInterface, pobj_c->GetInterfaces() )
392 {
393 if( interfaceName[0] )
394 {
395 if( pInterface->GetClass().GetName() != interfaceName )
396 {
397 // 指定されたインターフェイス名と整合しないとき
398 continue;
399 }
400 }
401
402 if( !pInterface->GetClass().IsReady() ){
403 // インターフェイスが未解析のとき
404 LexicalAnalyzer::LookaheadClass(
405 pInterface->GetClass().GetName().c_str(),
406 compiler.GetObjectModule().meta.GetClasses()
407 );
408 }
409
410 DynamicMethod *pMethodForOverride = pInterface->GetDynamicMethods().FindForOverride( pInterface->GetActualTypeParameters(), pUserProc );
411 if( pMethodForOverride )
412 {
413 DynamicMethod::OverrideResult result;
414 result.enumType = pMethodForOverride->Override( pUserProc, accessibility, isOverride );
415 result.pMethod = pMethodForOverride;
416 OverrideErrorCheck( result );
417
418 pUserProc->SetMethod( pMethodForOverride );
419 return;
420 }
421 }
422 }
423
424 if( interfaceName[0] )
425 {
426 compiler.errorMessenger.Output(139,interfaceName,nowLine);
427 }
428
429 if( isVirtual ){
430 pobj_c->AddVtblNum( 1 );
431 }
432
433 if( isOverride ){
434 compiler.errorMessenger.Output(12,"Override",nowLine);
435 }
436
437 if(bStatic){
438 pobj_c->GetStaticMethods().AddStatic( pUserProc, accessibility );
439 }
440 else{
441 pobj_c->GetDynamicMethods().Add(pUserProc, accessibility, isConst, isAbstract, isVirtual);
442 }
443}
444
445bool LexicalAnalyzer::Inherits( CClass &_class, const char *inheritNames, int nowLine ){
446 int i = 0;
447 bool isInheritsClass = false;
448 while( true ){
449
450 char temporary[VN_SIZE];
451 for( int i2=0;; i++, i2++ ){
452 if( inheritNames[i] == '\0' || inheritNames[i] == ',' ){
453 temporary[i2] = 0;
454 break;
455 }
456 temporary[i2] = inheritNames[i];
457 }
458
459 // ジェネリクス構文を分解
460 char className[VN_SIZE];
461 Jenga::Common::Strings typeParameterStrings;
462 SplitGenericClassInstance( temporary, className, typeParameterStrings );
463
464 // 型パラメータ文字列から型データを取得
465 Types actualTypeParameters;
466 BOOST_FOREACH( const std::string &typeParameterStr, typeParameterStrings )
467 {
468 Type type;
469 compiler.StringToType( typeParameterStr, type );
470 actualTypeParameters.push_back( type );
471 }
472
473 //継承元クラスを取得
474 const CClass *pInheritsClass = compiler.GetObjectModule().meta.FindClassSupportedTypeDef(
475 LexicalAnalyzer::FullNameToSymbol( className )
476 );
477 if( !pInheritsClass ){
478 compiler.errorMessenger.Output(106,className,nowLine);
479 return false;
480 }
481
482 if( pInheritsClass->IsClass() ){
483 // クラスを継承する
484 isInheritsClass = true;
485
486 //ループ継承でないかをチェック
487 if( !LexicalAnalyzer::LoopRefCheck(*pInheritsClass) )
488 {
489 compiler.errorMessenger.Output(123,pInheritsClass->GetName(),nowLine);
490 return false;
491 }
492
493 if( !pInheritsClass->IsReady() ){
494 //継承先が読み取られていないとき
495 LexicalAnalyzer::LookaheadClass(
496 pInheritsClass->GetName().c_str(),
497 compiler.GetObjectModule().meta.GetClasses()
498 );
499 }
500
501 if( !_class.InheritsClass( *pInheritsClass, actualTypeParameters, nowLine ) ){
502 return false;
503 }
504 }
505 else{
506 compiler.errorMessenger.Output(135,pInheritsClass->GetFullName().c_str(),nowLine);
507 return false;
508 }
509
510 if( inheritNames[i] == '\0' ){
511 break;
512 }
513 i++;
514 }
515
516 if( !isInheritsClass ){
517 const CClass *pObjectClass = compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr();
518 //ループ継承でないかをチェック
519 if( !LexicalAnalyzer::LoopRefCheck( *pObjectClass ) )
520 {
521 compiler.errorMessenger.Output(123,pObjectClass->GetName(),nowLine);
522 return false;
523 }
524
525 if( !pObjectClass->IsReady() ){
526 //継承先が読み取られていないとき
527 LexicalAnalyzer::LookaheadClass(
528 pObjectClass->GetName().c_str(),
529 compiler.GetObjectModule().meta.GetClasses()
530 );
531 }
532
533 // クラスを一つも継承していないとき
534 if( !_class.InheritsClass( *pObjectClass, Types(), nowLine ) ){
535 return false;
536 }
537 }
538
539 return true;
540}
541
542void LexicalAnalyzer::Implements( CClass &_class, Interface *pInterface, std::vector<DynamicMethod::OverrideResult> &overrideResults )
543{
544 _class.AddInterface( pInterface );
545
546
547 /////////////////////////////////////////////////////////////////
548 // 基底クラスのメソッドからインターフェイスメソッドを再実装する
549 /////////////////////////////////////////////////////////////////
550 BOOST_FOREACH( CMethod *pMethod, _class.GetDynamicMethods() )
551 {
552 DynamicMethod *pMethodForOverride = pInterface->GetDynamicMethods().FindForOverride( pInterface->GetActualTypeParameters(), &pMethod->GetUserProc() );
553 if( pMethodForOverride )
554 {
555 DynamicMethod::OverrideResult result;
556 result.enumType = pMethodForOverride->Override( &pMethod->GetUserProc(), pMethod->GetAccessibility(), false );
557 result.pMethod = pMethod;
558 overrideResults.push_back( result );
559
560 // 実装元になるメソッドは呼び出し不可にしておく(オーバーロードの解決から除外する)
561 pMethod->SetNotUseMark( true );
562 }
563 }
564
565
566 /////////////////////////////////////////////////////////////////
567 // キャストメソッドを追加(内部コードは自動生成すること)
568 // ※COMインターフェイスは除外すること
569 /////////////////////////////////////////////////////////////////
570 if( pInterface->GetClass().IsInterface() )
571 {
572 // Function Operator() As ITest
573
574 char methodName[255] = { 1, ESC_OPERATOR, CALC_AS, '\0' };
575
576 //関数ハッシュへ登録
577 UserProc *pUserProc = new UserProc(
578 Symbol( NamespaceScopes(), methodName ),
579 NamespaceScopesCollection(),
580 Procedure::Function,
581 false,
582 false,
583 false );
584 pUserProc->SetParentClass( &_class );
585
586 Parameters params;
587 params.push_back( new Parameter( "_System_LocalThis", Type( DEF_PTR_VOID ) ) );
588 pUserProc->SetRealParams( params );
589
590 pUserProc->SetReturnType( Type( DEF_OBJECT, pInterface->GetClass() ) );
591 pUserProc->_paramStr = "";
592 pUserProc->Using();
593
594 // 関数を追加
595 if( compiler.GetObjectModule().meta.GetUserProcs().IsExist( pUserProc ) )
596 {
597 // 既に存在している
598 compiler.errorMessenger.Output(15,pUserProc->GetName(),-1);
599
600 delete pUserProc;
601 }
602 else
603 {
604 compiler.GetObjectModule().meta.GetUserProcs().Put( pUserProc );
605 }
606
607 LexicalAnalyzer::AddMethod(
608 &_class,
609 pUserProc,
610 Prototype::Public,
611 0,
612 false, // isConst
613 false, // isAbstract
614 false, // isVirtual
615 false, // isOverride
616 "",
617 true, // isAutoGeneration
618 -1
619 );
620 }
621}
622
623bool LexicalAnalyzer::Implements( CClass &_class, const char *interfaceNames, int nowLine )
624{
625 Jenga::Common::Strings paramStrs;
626 SplitParameter( interfaceNames, paramStrs );
627
628 BOOST_FOREACH( const std::string &paramStr, paramStrs )
629 {
630 char className[VN_SIZE];
631 Jenga::Common::Strings typeParameterStrings;
632 SplitGenericClassInstance( paramStr.c_str(), className, typeParameterStrings );
633
634 Types actualTypeParameters;
635 BOOST_FOREACH( const std::string &typeParameterStr, typeParameterStrings )
636 {
637 Type type;
638 compiler.StringToType( typeParameterStr, type );
639 actualTypeParameters.push_back( type );
640 }
641
642 //継承元クラスを取得
643 const CClass *pInterfaceClass = compiler.GetObjectModule().meta.FindClassSupportedTypeDef(
644 LexicalAnalyzer::FullNameToSymbol( className )
645 );
646 if( !pInterfaceClass ){
647 compiler.errorMessenger.Output(106,paramStr.c_str(),nowLine);
648 continue;
649 }
650
651 if( !pInterfaceClass->IsReady() ){
652 // インターフェイスが未解析のとき
653 LexicalAnalyzer::LookaheadClass(
654 pInterfaceClass->GetName().c_str(),
655 compiler.GetObjectModule().meta.GetClasses()
656 );
657 }
658
659 if( pInterfaceClass->IsInterface() || pInterfaceClass->IsComInterface() )
660 {
661 // インターフェイスを継承する
662 std::vector<DynamicMethod::OverrideResult> overrideResults;
663 Implements(
664 _class,
665 new ::Interface( pInterfaceClass, actualTypeParameters ),
666 overrideResults
667 );
668
669 // エラーチェック
670 BOOST_FOREACH( const DynamicMethod::OverrideResult result, overrideResults )
671 {
672 OverrideErrorCheck( result );
673 }
674 }
675 else
676 {
677 // インターフェイスではないとき
678 compiler.errorMessenger.Output(138,pInterfaceClass->GetName().c_str(),nowLine );
679 }
680 }
681
682 return true;
683}
684
685void GetClass_recur( const char *lpszInheritsClass, Classes &classes )
686{
687 extern char *basbuf;
688 int i,i2,i3,sub_address,top_pos;
689 char temporary[8192];
690
691 // 名前空間管理
692 NamespaceScopes backupNamespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
693 NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
694 namespaceScopes.clear();
695
696 // Importsされた名前空間の管理
697 NamespaceScopesCollection backupImportedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
698 compiler.GetNamespaceSupporter().ClearImportedNamespaces();
699
700 // 呼び出し元でコンパイル中のクラスポインタをバックアップ
701 const CClass *pBackCompilingClass = compiler.IsCompilingClass()
702 ? &compiler.GetCompilingClass()
703 : NULL;
704
705 for(i=0;;i++){
706 if(basbuf[i]=='\0') break;
707
708
709 // 名前空間
710 if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
711 for(i+=2,i2=0;;i2++,i++){
712 if( IsCommandDelimitation( basbuf[i] ) ){
713 temporary[i2]=0;
714 break;
715 }
716 temporary[i2]=basbuf[i];
717 }
718 namespaceScopes.push_back( temporary );
719
720 continue;
721 }
722 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
723 if( namespaceScopes.size() <= 0 ){
724 compiler.errorMessenger.Output(12, "End Namespace", i );
725 }
726 else{
727 namespaceScopes.pop_back();
728 }
729
730 i += 2;
731 continue;
732 }
733
734 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){
735 for(i+=2,i2=0;;i2++,i++){
736 if( IsCommandDelimitation( basbuf[i] ) ){
737 temporary[i2]=0;
738 break;
739 }
740 temporary[i2]=basbuf[i];
741 }
742 if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
743 {
744 compiler.errorMessenger.Output(64,temporary,i );
745 }
746
747 continue;
748 }
749 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED )
750 {
751 // Imports情報のクリア
752 compiler.GetNamespaceSupporter().ClearImportedNamespaces();
753 continue;
754 }
755
756
757
758 if(basbuf[i]==1&&basbuf[i+1]==ESC_INTERFACE){
759 //////////////////////////
760 // インターフェイス
761 //////////////////////////
762
763 top_pos=i;
764
765 i+=2;
766
767 //インターフェイス名を取得
768 GetCommandToken( temporary, basbuf, i );
769
770 char className[VN_SIZE];
771 Jenga::Common::Strings typeParameters;
772 Jenga::Common::Strings typeParameterBaseClassNames;
773 SplitGenericClassInstance( temporary, className, typeParameters, true, &typeParameterBaseClassNames );
774
775 CClass *pobj_c = const_cast<CClass *>( classes.FindEx( Symbol( namespaceScopes, className ) ) );
776 if(!pobj_c) continue;
777
778 compiler.SetCompilingClass( pobj_c );
779
780 if(lpszInheritsClass){
781 if(lstrcmp(lpszInheritsClass,pobj_c->GetName().c_str())!=0){
782 //継承先先読み用
783 continue;
784 }
785 }
786
787 if(pobj_c->IsReady()){
788 //既に先読みされているとき
789 continue;
790 }
791
792 /////////////////////////////////////////////////////////
793 // ☆★☆ ジェネリクスサポート ☆★☆
794 for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ )
795 {
796 Type baseType( DEF_OBJECT, *classes.GetObjectClassPtr() );
797 if( typeParameterBaseClassNames[i2].size() )
798 {
799 if( !compiler.StringToType( typeParameterBaseClassNames[i2], baseType ) )
800 {
801 compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
802 }
803 else if( !baseType.IsObject() )
804 {
805 compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
806 }
807 }
808
809 pobj_c->AddFormalGenericType( GenericType( typeParameters[i2], baseType ) );
810 }
811 /////////////////////////////////////////////////////////
812
813 pobj_c->Readed();
814
815 pobj_c->SetConstructorMemberSubIndex( -1 );
816 pobj_c->SetDestructorMemberSubIndex( -1 );
817
818 if( memcmp( basbuf+i+1, "__COM", 5 ) == 0 && IsCommandDelimitation( basbuf[i+1+5] ) )
819 {
820 // COMインターフェイス
821 pobj_c->SetClassType( CClass::ComInterface );
822
823 i += 6;
824 }
825
826 if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS){
827 //継承を行う場合
828 for(i+=3,i2=0;;i++,i2++){
829 if(IsCommandDelimitation(basbuf[i])){
830 temporary[i2]=0;
831 break;
832 }
833 temporary[i2]=basbuf[i];
834 }
835
836 if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
837 compiler.errorMessenger.Output(105,temporary,i);
838 goto Interface_InheritsError;
839 }
840
841 //継承元クラスを取得
842 const CClass *pInheritsClass = compiler.GetObjectModule().meta.FindClassSupportedTypeDef(
843 LexicalAnalyzer::FullNameToSymbol( temporary )
844 );
845 if( !pInheritsClass ){
846 compiler.errorMessenger.Output(106,temporary,i);
847 goto Interface_InheritsError;
848 }
849
850 //ループ継承でないかをチェック
851 if( !LexicalAnalyzer::LoopRefCheck( *pInheritsClass ) )
852 {
853 compiler.errorMessenger.Output(123,pInheritsClass->GetName(),i);
854 goto Interface_InheritsError;
855 }
856
857 //継承させる
858 if( !pobj_c->InheritsClass( *pInheritsClass, Types(), i ) ){
859 goto Interface_InheritsError;
860 }
861 }
862 else{
863 //継承無し
864 if( &pobj_c->GetSuperClass() || pobj_c->GetVtblNum() )
865 {
866 // TODO: ここに来ないことが実証できたらこの分岐は消す
867 Jenga::Throw( "GetClass_recur内の例外" );
868 }
869 }
870Interface_InheritsError:
871
872 //メンバ変数、関数を取得
873 while(1){
874 i++;
875
876 //エラー
877 if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE||basbuf[i+1]==ESC_INTERFACE)){
878 compiler.errorMessenger.Output(22,"Interface",i);
879 i--;
880 break;
881 }
882
883 if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
884 compiler.errorMessenger.Output(111,NULL,i);
885 break;
886 }
887 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPLEMENTS )
888 {
889 compiler.errorMessenger.Output(137, NULL, i );
890 break;
891 }
892
893 sub_address=i;
894
895 for(i2=0;;i++,i2++){
896 if(IsCommandDelimitation(basbuf[i])){
897 temporary[i2]=0;
898 break;
899 }
900 temporary[i2]=basbuf[i];
901 }
902 if(temporary[0]=='\0'){
903 if(basbuf[i]=='\0'){
904 i--;
905 compiler.errorMessenger.Output(22,"Interface",top_pos);
906 break;
907 }
908 continue;
909 }
910
911 //End Interface記述の場合
912 if(temporary[0]==1&&temporary[1]==ESC_ENDINTERFACE) break;
913
914 if(!(temporary[0]==1&&(
915 temporary[1]==ESC_SUB||temporary[1]==ESC_FUNCTION
916 ))){
917 compiler.errorMessenger.Output(1,NULL,i);
918 break;
919 }
920
921 //関数ハッシュへ登録
922 char interfaceName[VN_SIZE] = "";
923 UserProc *pUserProc = LexicalAnalyzer::ParseUserProc( NamespaceScopes(), NamespaceScopesCollection(), temporary,sub_address,true,pobj_c, false, interfaceName );
924 if( pUserProc )
925 {
926 // 関数を追加
927 if( compiler.GetObjectModule().meta.GetUserProcs().IsExist( pUserProc ) )
928 {
929 // 既に存在している
930 compiler.errorMessenger.Output(15,pUserProc->GetName(),i);
931
932 delete pUserProc;
933 }
934 else
935 {
936 compiler.GetObjectModule().meta.GetUserProcs().Put( pUserProc );
937 }
938
939 //メンバ関数を追加
940 LexicalAnalyzer::AddMethod(pobj_c,
941 pUserProc,
942 Prototype::Public, //Publicアクセス権
943 0, // bStatic
944 false, // isConst
945 true, // isAbstract
946 true, // isVirtual
947 false, // isOverride
948 interfaceName,
949 false, // isAutoGeneration
950 sub_address
951 );
952 }
953 }
954 }
955
956 if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
957 //////////////////////////
958 // クラス
959 //////////////////////////
960
961 top_pos=i;
962
963 const DWORD dwClassType=basbuf[i+1];
964
965 i+=2;
966
967 int iAlign=0;
968 if(memicmp(basbuf+i,"Align(",6)==0){
969 //アラインメント修飾子
970 i+=6;
971 i+=GetStringInPare_RemovePare(temporary,basbuf+i)+1;
972 iAlign=atoi(temporary);
973
974 if( dwClassType != ESC_TYPE )
975 {
976 compiler.errorMessenger.Output(140,NULL,i);
977 }
978
979 if(!(iAlign==1||iAlign==2||iAlign==4||iAlign==8||iAlign==16))
980 compiler.errorMessenger.Output(51,NULL,i);
981 }
982 else if( memicmp( basbuf + i, "Blittable(", 10 ) == 0 ){
983 // Blittable修飾子
984 i+=10;
985 i=JumpStringInPare(basbuf,i)+1;
986
987 if( dwClassType != ESC_CLASS )
988 {
989 compiler.errorMessenger.Output(141,NULL,i);
990 }
991 }
992
993 if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENUM )
994 {
995 // 列挙型の場合
996 i += 2;
997 }
998 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_DELEGATE )
999 {
1000 // デリゲートの場合
1001 i += 2;
1002 }
1003
1004 //クラス名を取得
1005 GetCommandToken( temporary, basbuf, i );
1006
1007 char className[VN_SIZE];
1008 Jenga::Common::Strings typeParameters;
1009 Jenga::Common::Strings typeParameterBaseClassNames;
1010 SplitGenericClassInstance( temporary, className, typeParameters, true, &typeParameterBaseClassNames );
1011
1012 CClass *pobj_c = const_cast<CClass *>( classes.FindEx( Symbol( namespaceScopes, className ) ) );
1013 if(!pobj_c) continue;
1014
1015 compiler.SetCompilingClass( pobj_c );
1016
1017 if(lpszInheritsClass){
1018 if( pobj_c->GetName() != lpszInheritsClass ){
1019 //継承先先読み用
1020 continue;
1021 }
1022 }
1023
1024 if(pobj_c->IsReady()){
1025 //既に先読みされているとき
1026 continue;
1027 }
1028
1029
1030 /////////////////////////////////////////////////////////
1031 // ☆★☆ ジェネリクスサポート ☆★☆
1032 for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ )
1033 {
1034 Type baseType( DEF_OBJECT, *classes.GetObjectClassPtr() );
1035 if( typeParameterBaseClassNames[i2].size() )
1036 {
1037 if( !compiler.StringToType( typeParameterBaseClassNames[i2], baseType ) )
1038 {
1039 compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
1040 }
1041 else if( !baseType.IsObject() )
1042 {
1043 compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
1044 }
1045 }
1046
1047 pobj_c->AddFormalGenericType( GenericType( typeParameters[i2], baseType ) );
1048 }
1049 /////////////////////////////////////////////////////////
1050
1051
1052 pobj_c->SetFixedAlignment( iAlign );
1053
1054 pobj_c->Readed();
1055
1056 pobj_c->SetConstructorMemberSubIndex( -1 );
1057 pobj_c->SetDestructorMemberSubIndex( -1 );
1058
1059 //アクセス制限の初期値をセット
1060 Prototype::Accessibility accessibility;
1061 if(dwClassType==ESC_CLASS){
1062 accessibility = Prototype::Private;
1063 }
1064 else{
1065 accessibility = Prototype::Public;
1066 }
1067
1068 if( pobj_c->GetName() == "Object"
1069 || dwClassType == ESC_TYPE )
1070 {
1071 // 何も継承しない
1072
1073 if( &pobj_c->GetSuperClass() || pobj_c->GetVtblNum() )
1074 {
1075 // TODO: ここに来ないことが実証できたらこの分岐は消す
1076 Jenga::Throw( "GetClass_recur内の例外" );
1077 }
1078 }
1079 else{
1080 if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS)
1081 {
1082 // クラス継承先が指定されているとき
1083 i += 3;
1084 GetCommandToken( temporary, basbuf, i );
1085
1086 if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
1087 compiler.errorMessenger.Output(105,temporary,i);
1088 goto InheritsError;
1089 }
1090 }
1091 else
1092 {
1093 // 何の指定もないときはObjectクラスを継承する
1094 lstrcpy( temporary, "Object" );
1095 }
1096 LexicalAnalyzer::Inherits( *pobj_c, temporary, i );
1097
1098 if( basbuf[i+1] == 1 && basbuf[i+2] == ESC_IMPLEMENTS )
1099 {
1100 // インターフェイス実装を行う場合
1101 i += 3;
1102 GetCommandToken( temporary, basbuf, i );
1103
1104 LexicalAnalyzer::Implements( *pobj_c, temporary, i );
1105 }
1106 }
1107InheritsError:
1108
1109 //メンバとメソッドを取得
1110 while(1){
1111 i++;
1112
1113 //エラー
1114 if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
1115 compiler.errorMessenger.Output(22,"Class",i);
1116 i--;
1117 break;
1118 }
1119
1120 if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
1121 compiler.errorMessenger.Output(111,NULL,i);
1122 break;
1123 }
1124 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPLEMENTS )
1125 {
1126 compiler.errorMessenger.Output(137, NULL, i );
1127 break;
1128 }
1129
1130 //Static修飾子
1131 BOOL bStatic;
1132 if(basbuf[i]==1&&basbuf[i+1]==ESC_STATIC){
1133 bStatic=1;
1134 i+=2;
1135 }
1136 else bStatic=0;
1137
1138 //Const修飾子
1139 bool isConst = false;
1140 if( basbuf[i] == 1 && basbuf[i + 1] == ESC_CONST ){
1141 isConst = true;
1142 i += 2;
1143 }
1144
1145 if(basbuf[i]==1&&(
1146 basbuf[i+1]==ESC_ABSTRACT||basbuf[i+1]==ESC_VIRTUAL||basbuf[i+1]==ESC_OVERRIDE||
1147 basbuf[i+1]==ESC_SUB||basbuf[i+1]==ESC_FUNCTION
1148 )){
1149 i3=basbuf[i+1];
1150 sub_address=i;
1151 }
1152 else i3=0;
1153
1154 bool isVirtual = false, isAbstract = false, isOverride = false;
1155 if(i3==ESC_ABSTRACT){
1156 isAbstract=1;
1157 isVirtual=1;
1158 i+=2;
1159
1160 i3=basbuf[i+1];
1161 }
1162 else if(i3==ESC_VIRTUAL){
1163 isAbstract=0;
1164 isVirtual=1;
1165 i+=2;
1166
1167 i3=basbuf[i+1];
1168 }
1169 else if(i3==ESC_OVERRIDE){
1170 isOverride=1;
1171 isVirtual=1;
1172
1173 i+=2;
1174
1175 i3=basbuf[i+1];
1176 }
1177
1178 for(i2=0;;i++,i2++){
1179 if(IsCommandDelimitation(basbuf[i])){
1180 temporary[i2]=0;
1181 break;
1182 }
1183 temporary[i2]=basbuf[i];
1184 }
1185 if(temporary[0]=='\0'){
1186 if(basbuf[i]=='\0'){
1187
1188 if(dwClassType==ESC_CLASS)
1189 compiler.errorMessenger.Output(22,"Class",top_pos);
1190 else
1191 compiler.errorMessenger.Output(22,"Type",top_pos);
1192
1193 i--;
1194 break;
1195 }
1196 continue;
1197 }
1198
1199 //End Class記述の場合
1200 if(temporary[0]==1&&temporary[1]==ESC_ENDCLASS&&dwClassType==ESC_CLASS) break;
1201 if(temporary[0]==1&&temporary[1]==ESC_ENDTYPE&&dwClassType==ESC_TYPE) break;
1202
1203 //アクセスを変更
1204 if(lstrcmpi(temporary,"Private")==0){
1205 accessibility = Prototype::Private;
1206 continue;
1207 }
1208 if(lstrcmpi(temporary,"Public")==0){
1209 accessibility = Prototype::Public;
1210 continue;
1211 }
1212 if(lstrcmpi(temporary,"Protected")==0){
1213 accessibility = Prototype::Protected;
1214 continue;
1215 }
1216
1217 extern int cp;
1218 if(i3==0){
1219 cp=i; //エラー用
1220 Member *pMember = LexicalAnalyzer::CreateMember( *pobj_c, accessibility, isConst, false, temporary, i );
1221 if( pMember )
1222 {
1223 if(bStatic)
1224 {
1225 //静的メンバを追加
1226 pobj_c->AddStaticMember( pMember );
1227 }
1228 else
1229 {
1230 //メンバを追加
1231 pobj_c->AddDynamicMember( pMember );
1232
1233
1234 if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
1235 if( !pobj_c->GetDynamicMembers().back()->GetType().GetClass().IsReady() ){
1236 //参照先が読み取られていないとき
1237 GetClass_recur( pobj_c->GetDynamicMembers().back()->GetType().GetClass().GetName().c_str(), classes );
1238 }
1239 }
1240
1241
1242 if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
1243 //循環参照のチェック
1244 pobj_LoopRefCheck->add(pobj_c->GetName().c_str());
1245 if(!MemberVar_LoopRefCheck(pobj_c->GetDynamicMembers().back()->GetType().GetClass())){
1246 //エラー回避
1247 Type &type = const_cast<Type &>(pobj_c->GetDynamicMembers().back()->GetType());
1248 type.SetBasicType( DEF_PTR_VOID );
1249 }
1250 pobj_LoopRefCheck->del(pobj_c->GetName().c_str());
1251 }
1252 }
1253 }
1254 }
1255 else{
1256 //関数ハッシュへ登録
1257 char interfaceName[VN_SIZE] = "";
1258 UserProc *pUserProc = LexicalAnalyzer::ParseUserProc( NamespaceScopes(), NamespaceScopesCollection(), temporary,sub_address,isVirtual,pobj_c, (bStatic!=0), interfaceName );
1259 if( pUserProc )
1260 {
1261 // 関数を追加
1262 if( compiler.GetObjectModule().meta.GetUserProcs().IsExist( pUserProc ) )
1263 {
1264 // 既に存在している
1265 compiler.errorMessenger.Output(15,pUserProc->GetName(),i);
1266
1267 delete pUserProc;
1268 }
1269 else
1270 {
1271 compiler.GetObjectModule().meta.GetUserProcs().Put( pUserProc );
1272 }
1273
1274 //メソッドを追加
1275 cp=i; //エラー用
1276 LexicalAnalyzer::AddMethod(pobj_c,
1277 pUserProc,
1278 accessibility,
1279 bStatic,
1280 isConst,
1281 isAbstract,
1282 isVirtual,
1283 isOverride,
1284 interfaceName,
1285 false,
1286 sub_address);
1287 }
1288
1289 if( isAbstract ) continue;
1290
1291 for(;;i++){
1292 if(basbuf[i]=='\0'){
1293 i--;
1294 break;
1295 }
1296 if(basbuf[i-1]!='*'&&
1297 basbuf[i]==1&&(
1298 basbuf[i+1]==ESC_SUB||
1299 basbuf[i+1]==ESC_FUNCTION||
1300 basbuf[i+1]==ESC_MACRO||
1301 basbuf[i+1]==ESC_TYPE||
1302 basbuf[i+1]==ESC_CLASS||
1303 basbuf[i+1]==ESC_INTERFACE||
1304 basbuf[i+1]==ESC_ENUM)){
1305 GetDefaultNameFromES(i3,temporary);
1306 compiler.errorMessenger.Output(22,temporary,i);
1307 }
1308 if(basbuf[i]==1&&basbuf[i+1]==GetEndXXXCommand((char)i3)){
1309 i+=2;
1310 break;
1311 }
1312 }
1313 }
1314 }
1315 }
1316 }
1317
1318 // 呼び出し元でコンパイル中のクラスポインタを元に戻す
1319 compiler.SetCompilingClass( pBackCompilingClass );
1320
1321 // 名前空間を元に戻す
1322 compiler.GetNamespaceSupporter().GetLivingNamespaceScopes() = backupNamespaceScopes;
1323
1324 // インポートされた名前空間を元に戻す
1325 compiler.GetNamespaceSupporter().SetImportedNamespaces( backupImportedNamespaces );
1326}
1327
1328void LexicalAnalyzer::LookaheadClass( const char *className, Classes &classes )
1329{
1330 pobj_LoopRefCheck->add( className );
1331 GetClass_recur( className, classes );
1332 pobj_LoopRefCheck->del( className );
1333}
1334
1335bool LexicalAnalyzer::LoopRefCheck( const CClass &objClass )
1336{
1337 if( pobj_LoopRefCheck->check( objClass ) )
1338 {
1339 return false;
1340 }
1341
1342 return true;
1343}
1344
1345void LexicalAnalyzer::CollectClasses( const char *source, Classes &classes ){
1346 //ループ継承チェック用のクラス
1347 pobj_LoopRefCheck=new CLoopRefCheck();
1348
1349 //クラスを取得
1350 GetClass_recur( 0, classes );
1351
1352 delete pobj_LoopRefCheck;
1353 pobj_LoopRefCheck=0;
1354
1355 // イテレータの準備
1356 classes.Iterator_Init();
1357}
1358
1359void LexicalAnalyzer::TemplateExpand_ResolveMethod( const CMethod *pBaseMethod, const Types &actualTypes, CClass *pNewClass )
1360{
1361 UserProc *pUserProc = new UserProc(
1362 pBaseMethod->GetUserProc(),
1363 pNewClass
1364 );
1365 pUserProc->Using();
1366 pUserProc->GetParameters().clear();
1367 pUserProc->RealParams().clear();
1368
1369 // パラメータのジェネリック型を解決
1370 BOOST_FOREACH( const Parameter *pParam, pBaseMethod->GetUserProc().Params() )
1371 {
1372 Type type = pParam->IsTypeParameter()
1373 ? actualTypes[pParam->GetFormalTypeIndex()]
1374 : *pParam;
1375 type.SetPtrLevel( pParam->PtrLevel() );
1376
1377 pUserProc->GetParameters().push_back( new Parameter( *pParam, type ) );
1378 }
1379 BOOST_FOREACH( const Parameter *pParam, pBaseMethod->GetUserProc().RealParams() )
1380 {
1381 Type type = pParam->IsTypeParameter()
1382 ? actualTypes[pParam->GetFormalTypeIndex()]
1383 : *pParam;
1384 type.SetPtrLevel( pParam->PtrLevel() );
1385
1386 pUserProc->RealParams().push_back( new Parameter( *pParam, type ) );
1387 }
1388
1389 // 戻り値のジェネリック型を解決
1390 if( pUserProc->ReturnType().IsTypeParameter() )
1391 {
1392 Type type = actualTypes[pUserProc->ReturnType().GetFormalTypeIndex()];
1393 type.SetPtrLevel( pUserProc->ReturnType().PtrLevel() );
1394 pUserProc->SetReturnType( type );
1395 }
1396
1397 compiler.GetObjectModule().meta.GetUserProcs().Put( pUserProc );
1398 compiler.GetObjectModule().meta.GetUserProcs().Iterator_Init();
1399
1400 LexicalAnalyzer::AddMethod(
1401 pNewClass,
1402 pUserProc,
1403 pBaseMethod->GetAccessibility(),
1404 pBaseMethod->IsStatic(),
1405 pBaseMethod->IsConst(),
1406 pBaseMethod->IsAbstract(),
1407 pBaseMethod->IsVirtual(),
1408 false,
1409 "",
1410 false,
1411 -1
1412 );
1413}
1414
1415const CClass *LexicalAnalyzer::TemplateExpand( CClass &_class, const Types &actualTypes )
1416{
1417 // 展開済みのクラスがあればそれを返す
1418 BOOST_FOREACH( const ExpandedTemplateClass *pExpandedTemplateClass, _class.expandedTemplateClasses )
1419 {
1420 if( pExpandedTemplateClass->GetActualTypes().IsEquals( actualTypes ) )
1421 {
1422 return &pExpandedTemplateClass->GetClass();
1423 }
1424 }
1425
1426
1427 /////////////////////////////////////////////////////////////////
1428 // 未展開の場合は新たに展開する
1429 /////////////////////////////////////////////////////////////////
1430
1431 // クラスをコピー
1432 CClass *pNewClass = new CClass(
1433 _class,
1434 _class.GetImportedNamespaces(),
1435 _class.GetClassType(),
1436 _class.GetFormalGenericTypes(),
1437 _class.GetSuperClassActualTypeParameters(),
1438 _class.GetConstructorMemberSubIndex(),
1439 _class.GetDestructorMemberSubIndex(),
1440 0,
1441 _class.GetFixedAlignment(),
1442 actualTypes
1443 );
1444
1445 // 基底クラス
1446 pNewClass->SetSuperClass( &_class.GetSuperClass() );
1447
1448 // インターフェイスのジェネリック型を解決
1449 BOOST_FOREACH( const ::Interface *pInterface, _class.GetInterfaces() )
1450 {
1451 pNewClass->AddInterface( new ::Interface( &pInterface->GetClass(), actualTypes ) );
1452 }
1453
1454 // メンバのジェネリック型を解決
1455 BOOST_FOREACH( const Member *pMember, _class.GetDynamicMembers() )
1456 {
1457 Type type = pMember->GetType();
1458 if( type.IsTypeParameter() )
1459 {
1460 // ジェネリック型だったときは値型に変換
1461 type = actualTypes[type.GetFormalTypeIndex()];
1462 type.SetPtrLevel( pMember->GetType().PtrLevel() );
1463 }
1464
1465 pNewClass->GetDynamicMembers().push_back(
1466 new Member( *pMember, type )
1467 );
1468 }
1469
1470 // クラス メソッドのジェネリック型を解決
1471 BOOST_FOREACH( const CMethod *pMethod, _class.GetDynamicMethods() )
1472 {
1473 if( pMethod->GetUserProc().GetParentClassPtr() == &_class )
1474 {
1475 // ターゲットクラス内で実装されるメソッドの場合
1476
1477 TemplateExpand_ResolveMethod( pMethod, actualTypes, pNewClass );
1478 }
1479 else
1480 {
1481 DynamicMethod *pNewDynamicMethod = new DynamicMethod( *pMethod );
1482 pNewClass->GetDynamicMethods().push_back( pNewDynamicMethod );
1483 }
1484 }
1485
1486 // インターフェイス メソッドのジェネリック型を解決
1487 BOOST_FOREACH( const ::Interface *pInterface, _class.GetInterfaces() )
1488 {
1489 BOOST_FOREACH( const CMethod *pMethod, pInterface->GetDynamicMethods() )
1490 {
1491 TemplateExpand_ResolveMethod( pMethod, actualTypes, pNewClass );
1492 }
1493 }
1494
1495 pNewClass->SetVtblNum( _class.GetVtblNum() );
1496
1497 // 展開済みクラスとして登録
1498 _class.expandedTemplateClasses.push_back( new ExpandedTemplateClass( pNewClass, actualTypes ) );
1499
1500 pNewClass->Readed();
1501
1502 return pNewClass;
1503}
Note: See TracBrowser for help on using the repository browser.