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