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

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

#171への対応。テンプレート展開後のクラスメソッドの実装で、SizeOf(T)が正常値を返さない不具合を修正(特にTが4バイト未満の型場合)。

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( lstrcmp(className,"Control")==0)
1025 {
1026 int test=0;
1027 }
1028
1029 if(pobj_c->IsReady()){
1030 //既に先読みされているとき
1031 continue;
1032 }
1033
1034
1035 /////////////////////////////////////////////////////////
1036 // ☆★☆ ジェネリクスサポート ☆★☆
1037 for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ )
1038 {
1039 Type baseType( DEF_OBJECT, *classes.GetObjectClassPtr() );
1040 if( typeParameterBaseClassNames[i2].size() )
1041 {
1042 if( !compiler.StringToType( typeParameterBaseClassNames[i2], baseType ) )
1043 {
1044 compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
1045 }
1046 else if( !baseType.IsObject() )
1047 {
1048 compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
1049 }
1050 }
1051
1052 pobj_c->AddFormalGenericType( GenericType( typeParameters[i2], baseType ) );
1053 }
1054 /////////////////////////////////////////////////////////
1055
1056
1057 pobj_c->SetFixedAlignment( iAlign );
1058
1059 pobj_c->Readed();
1060
1061 pobj_c->SetConstructorMemberSubIndex( -1 );
1062 pobj_c->SetDestructorMemberSubIndex( -1 );
1063
1064 //アクセス制限の初期値をセット
1065 Prototype::Accessibility accessibility;
1066 if(dwClassType==ESC_CLASS){
1067 accessibility = Prototype::Private;
1068 }
1069 else{
1070 accessibility = Prototype::Public;
1071 }
1072
1073 if( pobj_c->GetName() == "Object"
1074 || dwClassType == ESC_TYPE )
1075 {
1076 // 何も継承しない
1077
1078 if( &pobj_c->GetSuperClass() || pobj_c->GetVtblNum() )
1079 {
1080 // TODO: ここに来ないことが実証できたらこの分岐は消す
1081 Jenga::Throw( "GetClass_recur内の例外" );
1082 }
1083 }
1084 else{
1085 if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS)
1086 {
1087 // クラス継承先が指定されているとき
1088 i += 3;
1089 GetCommandToken( temporary, basbuf, i );
1090
1091 if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
1092 compiler.errorMessenger.Output(105,temporary,i);
1093 goto InheritsError;
1094 }
1095 }
1096 else
1097 {
1098 // 何の指定もないときはObjectクラスを継承する
1099 lstrcpy( temporary, "Object" );
1100 }
1101 LexicalAnalyzer::Inherits( *pobj_c, temporary, i );
1102
1103 if( basbuf[i+1] == 1 && basbuf[i+2] == ESC_IMPLEMENTS )
1104 {
1105 // インターフェイス実装を行う場合
1106 i += 3;
1107 GetCommandToken( temporary, basbuf, i );
1108
1109 LexicalAnalyzer::Implements( *pobj_c, temporary, i );
1110 }
1111 }
1112InheritsError:
1113
1114 //メンバとメソッドを取得
1115 while(1){
1116 i++;
1117
1118 //エラー
1119 if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
1120 compiler.errorMessenger.Output(22,"Class",i);
1121 i--;
1122 break;
1123 }
1124
1125 if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
1126 compiler.errorMessenger.Output(111,NULL,i);
1127 break;
1128 }
1129 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPLEMENTS )
1130 {
1131 compiler.errorMessenger.Output(137, NULL, i );
1132 break;
1133 }
1134
1135 //Static修飾子
1136 BOOL bStatic;
1137 if(basbuf[i]==1&&basbuf[i+1]==ESC_STATIC){
1138 bStatic=1;
1139 i+=2;
1140 }
1141 else bStatic=0;
1142
1143 //Const修飾子
1144 bool isConst = false;
1145 if( basbuf[i] == 1 && basbuf[i + 1] == ESC_CONST ){
1146 isConst = true;
1147 i += 2;
1148 }
1149
1150 if(basbuf[i]==1&&(
1151 basbuf[i+1]==ESC_ABSTRACT||basbuf[i+1]==ESC_VIRTUAL||basbuf[i+1]==ESC_OVERRIDE||
1152 basbuf[i+1]==ESC_SUB||basbuf[i+1]==ESC_FUNCTION
1153 )){
1154 i3=basbuf[i+1];
1155 sub_address=i;
1156 }
1157 else i3=0;
1158
1159 bool isVirtual = false, isAbstract = false, isOverride = false;
1160 if(i3==ESC_ABSTRACT){
1161 isAbstract=1;
1162 isVirtual=1;
1163 i+=2;
1164
1165 i3=basbuf[i+1];
1166 }
1167 else if(i3==ESC_VIRTUAL){
1168 isAbstract=0;
1169 isVirtual=1;
1170 i+=2;
1171
1172 i3=basbuf[i+1];
1173 }
1174 else if(i3==ESC_OVERRIDE){
1175 isOverride=1;
1176 isVirtual=1;
1177
1178 i+=2;
1179
1180 i3=basbuf[i+1];
1181 }
1182
1183 for(i2=0;;i++,i2++){
1184 if(IsCommandDelimitation(basbuf[i])){
1185 temporary[i2]=0;
1186 break;
1187 }
1188 temporary[i2]=basbuf[i];
1189 }
1190 if(temporary[0]=='\0'){
1191 if(basbuf[i]=='\0'){
1192
1193 if(dwClassType==ESC_CLASS)
1194 compiler.errorMessenger.Output(22,"Class",top_pos);
1195 else
1196 compiler.errorMessenger.Output(22,"Type",top_pos);
1197
1198 i--;
1199 break;
1200 }
1201 continue;
1202 }
1203
1204 //End Class記述の場合
1205 if(temporary[0]==1&&temporary[1]==ESC_ENDCLASS&&dwClassType==ESC_CLASS) break;
1206 if(temporary[0]==1&&temporary[1]==ESC_ENDTYPE&&dwClassType==ESC_TYPE) break;
1207
1208 //アクセスを変更
1209 if(lstrcmpi(temporary,"Private")==0){
1210 accessibility = Prototype::Private;
1211 continue;
1212 }
1213 if(lstrcmpi(temporary,"Public")==0){
1214 accessibility = Prototype::Public;
1215 continue;
1216 }
1217 if(lstrcmpi(temporary,"Protected")==0){
1218 accessibility = Prototype::Protected;
1219 continue;
1220 }
1221
1222 extern int cp;
1223 if(i3==0){
1224 cp=i; //エラー用
1225 Member *pMember = LexicalAnalyzer::CreateMember( *pobj_c, accessibility, isConst, false, temporary, i );
1226 if( pMember )
1227 {
1228 if(bStatic)
1229 {
1230 //静的メンバを追加
1231 pobj_c->AddStaticMember( pMember );
1232 }
1233 else
1234 {
1235 //メンバを追加
1236 pobj_c->AddDynamicMember( pMember );
1237
1238
1239 if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
1240 if( !pobj_c->GetDynamicMembers().back()->GetType().GetClass().IsReady() ){
1241 //参照先が読み取られていないとき
1242 GetClass_recur( pobj_c->GetDynamicMembers().back()->GetType().GetClass().GetName().c_str(), classes );
1243 }
1244 }
1245
1246
1247 if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
1248 //循環参照のチェック
1249 pobj_LoopRefCheck->add(pobj_c->GetName().c_str());
1250 if(!MemberVar_LoopRefCheck(pobj_c->GetDynamicMembers().back()->GetType().GetClass())){
1251 //エラー回避
1252 Type &type = const_cast<Type &>(pobj_c->GetDynamicMembers().back()->GetType());
1253 type.SetBasicType( DEF_PTR_VOID );
1254 }
1255 pobj_LoopRefCheck->del(pobj_c->GetName().c_str());
1256 }
1257 }
1258 }
1259 }
1260 else{
1261 //関数ハッシュへ登録
1262 char interfaceName[VN_SIZE] = "";
1263 UserProc *pUserProc = LexicalAnalyzer::ParseUserProc( NamespaceScopes(), NamespaceScopesCollection(), temporary,sub_address,isVirtual,pobj_c, (bStatic!=0), interfaceName );
1264 if( pUserProc )
1265 {
1266 // 関数を追加
1267 if( compiler.GetObjectModule().meta.GetUserProcs().IsExist( pUserProc ) )
1268 {
1269 // 既に存在している
1270 compiler.errorMessenger.Output(15,pUserProc->GetName(),i);
1271
1272 delete pUserProc;
1273 }
1274 else
1275 {
1276 compiler.GetObjectModule().meta.GetUserProcs().Put( pUserProc );
1277 }
1278
1279 //メソッドを追加
1280 cp=i; //エラー用
1281 LexicalAnalyzer::AddMethod(pobj_c,
1282 pUserProc,
1283 accessibility,
1284 bStatic,
1285 isConst,
1286 isAbstract,
1287 isVirtual,
1288 isOverride,
1289 interfaceName,
1290 false,
1291 sub_address);
1292 }
1293
1294 if( isAbstract ) continue;
1295
1296 for(;;i++){
1297 if(basbuf[i]=='\0'){
1298 i--;
1299 break;
1300 }
1301 if(basbuf[i-1]!='*'&&
1302 basbuf[i]==1&&(
1303 basbuf[i+1]==ESC_SUB||
1304 basbuf[i+1]==ESC_FUNCTION||
1305 basbuf[i+1]==ESC_MACRO||
1306 basbuf[i+1]==ESC_TYPE||
1307 basbuf[i+1]==ESC_CLASS||
1308 basbuf[i+1]==ESC_INTERFACE||
1309 basbuf[i+1]==ESC_ENUM)){
1310 GetDefaultNameFromES(i3,temporary);
1311 compiler.errorMessenger.Output(22,temporary,i);
1312 }
1313 if(basbuf[i]==1&&basbuf[i+1]==GetEndXXXCommand((char)i3)){
1314 i+=2;
1315 break;
1316 }
1317 }
1318 }
1319 }
1320 }
1321 }
1322
1323 // 呼び出し元でコンパイル中のクラスポインタを元に戻す
1324 compiler.SetCompilingClass( pBackCompilingClass );
1325
1326 // 名前空間を元に戻す
1327 compiler.GetNamespaceSupporter().GetLivingNamespaceScopes() = backupNamespaceScopes;
1328
1329 // インポートされた名前空間を元に戻す
1330 compiler.GetNamespaceSupporter().SetImportedNamespaces( backupImportedNamespaces );
1331}
1332
1333void LexicalAnalyzer::LookaheadClass( const char *className, Classes &classes )
1334{
1335 pobj_LoopRefCheck->add( className );
1336 GetClass_recur( className, classes );
1337 pobj_LoopRefCheck->del( className );
1338}
1339
1340bool LexicalAnalyzer::LoopRefCheck( const CClass &objClass )
1341{
1342 if( pobj_LoopRefCheck->check( objClass ) )
1343 {
1344 return false;
1345 }
1346
1347 return true;
1348}
1349
1350void LexicalAnalyzer::CollectClasses( const char *source, Classes &classes ){
1351 //ループ継承チェック用のクラス
1352 pobj_LoopRefCheck=new CLoopRefCheck();
1353
1354 //クラスを取得
1355 GetClass_recur( 0, classes );
1356
1357 delete pobj_LoopRefCheck;
1358 pobj_LoopRefCheck=0;
1359
1360 // イテレータの準備
1361 classes.Iterator_Init();
1362}
1363
1364void LexicalAnalyzer::TemplateExpand_ResolveMethod( const CMethod *pBaseMethod, const Types &actualTypes, CClass *pNewClass )
1365{
1366 UserProc *pUserProc = new UserProc(
1367 pBaseMethod->GetUserProc(),
1368 pNewClass
1369 );
1370 pUserProc->Using();
1371 pUserProc->GetParameters().clear();
1372 pUserProc->RealParams().clear();
1373
1374 // パラメータのジェネリック型を解決
1375 BOOST_FOREACH( const Parameter *pParam, pBaseMethod->GetUserProc().Params() )
1376 {
1377 Type type = pParam->IsTypeParameter()
1378 ? actualTypes[pParam->GetFormalTypeIndex()]
1379 : *pParam;
1380 type.SetPtrLevel( pParam->PtrLevel() );
1381
1382 pUserProc->GetParameters().push_back( new Parameter( *pParam, type ) );
1383 }
1384 BOOST_FOREACH( const Parameter *pParam, pBaseMethod->GetUserProc().RealParams() )
1385 {
1386 Type type = pParam->IsTypeParameter()
1387 ? actualTypes[pParam->GetFormalTypeIndex()]
1388 : *pParam;
1389 type.SetPtrLevel( pParam->PtrLevel() );
1390
1391 pUserProc->RealParams().push_back( new Parameter( *pParam, type ) );
1392 }
1393
1394 // 戻り値のジェネリック型を解決
1395 if( pUserProc->ReturnType().IsTypeParameter() )
1396 {
1397 Type type = actualTypes[pUserProc->ReturnType().GetFormalTypeIndex()];
1398 type.SetPtrLevel( pUserProc->ReturnType().PtrLevel() );
1399 pUserProc->SetReturnType( type );
1400 }
1401
1402 compiler.GetObjectModule().meta.GetUserProcs().Put( pUserProc );
1403 compiler.GetObjectModule().meta.GetUserProcs().Iterator_Init();
1404
1405 LexicalAnalyzer::AddMethod(
1406 pNewClass,
1407 pUserProc,
1408 pBaseMethod->GetAccessibility(),
1409 pBaseMethod->IsStatic(),
1410 pBaseMethod->IsConst(),
1411 pBaseMethod->IsAbstract(),
1412 pBaseMethod->IsVirtual(),
1413 false,
1414 "",
1415 false,
1416 -1
1417 );
1418}
1419
1420const CClass *LexicalAnalyzer::TemplateExpand( CClass &_class, const Types &actualTypes )
1421{
1422 // 展開済みのクラスがあればそれを返す
1423 BOOST_FOREACH( const ExpandedTemplateClass *pExpandedTemplateClass, _class.expandedTemplateClasses )
1424 {
1425 if( pExpandedTemplateClass->GetActualTypes().IsEquals( actualTypes ) )
1426 {
1427 return &pExpandedTemplateClass->GetClass();
1428 }
1429 }
1430
1431
1432 /////////////////////////////////////////////////////////////////
1433 // 未展開の場合は新たに展開する
1434 /////////////////////////////////////////////////////////////////
1435
1436 // クラスをコピー
1437 CClass *pNewClass = new CClass(
1438 _class,
1439 _class.GetImportedNamespaces(),
1440 _class.GetClassType(),
1441 _class.GetFormalGenericTypes(),
1442 _class.GetSuperClassActualTypeParameters(),
1443 _class.GetConstructorMemberSubIndex(),
1444 _class.GetDestructorMemberSubIndex(),
1445 0,
1446 _class.GetFixedAlignment(),
1447 actualTypes
1448 );
1449
1450 // 基底クラス
1451 pNewClass->SetSuperClass( &_class.GetSuperClass() );
1452
1453 // インターフェイスのジェネリック型を解決
1454 BOOST_FOREACH( const ::Interface *pInterface, _class.GetInterfaces() )
1455 {
1456 pNewClass->AddInterface( new ::Interface( &pInterface->GetClass(), actualTypes ) );
1457 }
1458
1459 // メンバのジェネリック型を解決
1460 BOOST_FOREACH( const Member *pMember, _class.GetDynamicMembers() )
1461 {
1462 Type type = pMember->GetType();
1463 if( type.IsTypeParameter() )
1464 {
1465 // ジェネリック型だったときは値型に変換
1466 type = actualTypes[type.GetFormalTypeIndex()];
1467 type.SetPtrLevel( pMember->GetType().PtrLevel() );
1468 }
1469
1470 pNewClass->GetDynamicMembers().push_back(
1471 new Member( *pMember, type )
1472 );
1473 }
1474
1475 // クラス メソッドのジェネリック型を解決
1476 BOOST_FOREACH( const CMethod *pMethod, _class.GetDynamicMethods() )
1477 {
1478 if( pMethod->GetUserProc().GetParentClassPtr() == &_class )
1479 {
1480 // ターゲットクラス内で実装されるメソッドの場合
1481
1482 TemplateExpand_ResolveMethod( pMethod, actualTypes, pNewClass );
1483 }
1484 else
1485 {
1486 DynamicMethod *pNewDynamicMethod = new DynamicMethod( *pMethod );
1487 pNewClass->GetDynamicMethods().push_back( pNewDynamicMethod );
1488 }
1489 }
1490
1491 // インターフェイス メソッドのジェネリック型を解決
1492 BOOST_FOREACH( const ::Interface *pInterface, _class.GetInterfaces() )
1493 {
1494 BOOST_FOREACH( const CMethod *pMethod, pInterface->GetDynamicMethods() )
1495 {
1496 TemplateExpand_ResolveMethod( pMethod, actualTypes, pNewClass );
1497 }
1498 }
1499
1500 pNewClass->SetVtblNum( _class.GetVtblNum() );
1501
1502 // 展開済みクラスとして登録
1503 _class.expandedTemplateClasses.push_back( new ExpandedTemplateClass( pNewClass, actualTypes ) );
1504
1505 pNewClass->Readed();
1506
1507 return pNewClass;
1508}
Note: See TracBrowser for help on using the repository browser.