Changes in src/SymTab/Indexer.cc [e67991f:114bde6]
- File:
-
- 1 edited
-
src/SymTab/Indexer.cc (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Indexer.cc
re67991f r114bde6 74 74 } 75 75 76 Indexer::Indexer() 77 : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 78 prevScope(), scope( 0 ), repScope( 0 ) { ++* stats().count; }76 Indexer::Indexer() 77 : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 78 prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; } 79 79 80 80 Indexer::~Indexer() { … … 84 84 void Indexer::lazyInitScope() { 85 85 if ( repScope < scope ) { 86 ++* stats().lazy_scopes;86 ++*stats().lazy_scopes; 87 87 // create rollback 88 prevScope = std::make_shared<Indexer>( * this );88 prevScope = std::make_shared<Indexer>( *this ); 89 89 // update repScope 90 90 repScope = scope; … … 95 95 ++scope; 96 96 97 ++* stats().new_scopes;97 ++*stats().new_scopes; 98 98 stats().avg_scope_depth->push( scope ); 99 99 stats().max_scope_depth->push( scope ); … … 103 103 if ( repScope == scope ) { 104 104 Ptr prev = prevScope; // make sure prevScope stays live 105 * this = std::move(*prevScope); // replace with previous scope105 *this = std::move(*prevScope); // replace with previous scope 106 106 } 107 107 … … 109 109 } 110 110 111 void Indexer::lookupId( const std::string & id, std::list< IdData > &out ) const {112 ++* stats().lookup_calls;111 void Indexer::lookupId( const std::string &id, std::list< IdData > &out ) const { 112 ++*stats().lookup_calls; 113 113 if ( ! idTable ) return; 114 114 115 ++* stats().map_lookups;115 ++*stats().map_lookups; 116 116 auto decls = idTable->find( id ); 117 117 if ( decls == idTable->end() ) return; … … 122 122 } 123 123 124 const NamedTypeDecl * Indexer::lookupType( const std::string &id ) const {125 ++* stats().lookup_calls;124 NamedTypeDecl *Indexer::lookupType( const std::string &id ) const { 125 ++*stats().lookup_calls; 126 126 if ( ! typeTable ) return nullptr; 127 ++* stats().map_lookups;127 ++*stats().map_lookups; 128 128 auto it = typeTable->find( id ); 129 129 return it == typeTable->end() ? nullptr : it->second.decl; 130 130 } 131 131 132 const StructDecl * Indexer::lookupStruct( const std::string &id ) const {133 ++* stats().lookup_calls;132 StructDecl *Indexer::lookupStruct( const std::string &id ) const { 133 ++*stats().lookup_calls; 134 134 if ( ! structTable ) return nullptr; 135 ++* stats().map_lookups;135 ++*stats().map_lookups; 136 136 auto it = structTable->find( id ); 137 137 return it == structTable->end() ? nullptr : it->second.decl; 138 138 } 139 139 140 const EnumDecl * Indexer::lookupEnum( const std::string &id ) const {141 ++* stats().lookup_calls;140 EnumDecl *Indexer::lookupEnum( const std::string &id ) const { 141 ++*stats().lookup_calls; 142 142 if ( ! enumTable ) return nullptr; 143 ++* stats().map_lookups;143 ++*stats().map_lookups; 144 144 auto it = enumTable->find( id ); 145 145 return it == enumTable->end() ? nullptr : it->second.decl; 146 146 } 147 147 148 const UnionDecl * Indexer::lookupUnion( const std::string &id ) const {149 ++* stats().lookup_calls;148 UnionDecl *Indexer::lookupUnion( const std::string &id ) const { 149 ++*stats().lookup_calls; 150 150 if ( ! unionTable ) return nullptr; 151 ++* stats().map_lookups;151 ++*stats().map_lookups; 152 152 auto it = unionTable->find( id ); 153 153 return it == unionTable->end() ? nullptr : it->second.decl; 154 154 } 155 155 156 const TraitDecl * Indexer::lookupTrait( const std::string &id ) const {157 ++* stats().lookup_calls;156 TraitDecl *Indexer::lookupTrait( const std::string &id ) const { 157 ++*stats().lookup_calls; 158 158 if ( ! traitTable ) return nullptr; 159 ++* stats().map_lookups;159 ++*stats().map_lookups; 160 160 auto it = traitTable->find( id ); 161 161 return it == traitTable->end() ? nullptr : it->second.decl; 162 162 } 163 163 164 const Indexer * Indexer::atScope( unsigned long target ) const {164 const Indexer* Indexer::atScope( unsigned long target ) const { 165 165 // by lazy construction, final indexer in list has repScope 0, cannot be > target 166 166 // otherwise, will find first scope representing the target 167 const Indexer * indexer = this;167 const Indexer* indexer = this; 168 168 while ( indexer->repScope > target ) { 169 169 indexer = indexer->prevScope.get(); … … 172 172 } 173 173 174 const NamedTypeDecl * Indexer::globalLookupType( const std::string &id ) const {174 NamedTypeDecl *Indexer::globalLookupType( const std::string &id ) const { 175 175 return atScope( 0 )->lookupType( id ); 176 176 } 177 177 178 const StructDecl * Indexer::globalLookupStruct( const std::string &id ) const {178 StructDecl *Indexer::globalLookupStruct( const std::string &id ) const { 179 179 return atScope( 0 )->lookupStruct( id ); 180 180 } 181 181 182 const UnionDecl * Indexer::globalLookupUnion( const std::string &id ) const {182 UnionDecl *Indexer::globalLookupUnion( const std::string &id ) const { 183 183 return atScope( 0 )->lookupUnion( id ); 184 184 } 185 185 186 const EnumDecl * Indexer::globalLookupEnum( const std::string &id ) const {186 EnumDecl *Indexer::globalLookupEnum( const std::string &id ) const { 187 187 return atScope( 0 )->lookupEnum( id ); 188 188 } 189 189 190 bool isFunction( constDeclarationWithType * decl ) {190 bool isFunction( DeclarationWithType * decl ) { 191 191 return GenPoly::getFunctionType( decl->get_type() ); 192 192 } 193 193 194 bool isObject( constDeclarationWithType * decl ) {194 bool isObject( DeclarationWithType * decl ) { 195 195 return ! isFunction( decl ); 196 196 } 197 197 198 bool isDefinition( constDeclarationWithType * decl ) {199 if ( const FunctionDecl * func = dynamic_cast< constFunctionDecl * >( decl ) ) {198 bool isDefinition( DeclarationWithType * decl ) { 199 if ( FunctionDecl * func = dynamic_cast< FunctionDecl * >( decl ) ) { 200 200 // a function is a definition if it has a body 201 201 return func->statements; … … 207 207 } 208 208 209 210 bool Indexer::addedIdConflicts( 211 const Indexer::IdData & existing, const DeclarationWithType * added,212 Indexer::OnConflict handleConflicts, const Declaration* deleteStmt ) {213 // if we're giving the same name mangling to things of different types then there is 209 210 bool Indexer::addedIdConflicts( 211 const Indexer::IdData & existing, DeclarationWithType *added, 212 Indexer::OnConflict handleConflicts, BaseSyntaxNode * deleteStmt ) { 213 // if we're giving the same name mangling to things of different types then there is 214 214 // something wrong 215 215 assert( (isObject( added ) && isObject( existing.id ) ) … … 219 219 // new definition shadows the autogenerated one, even at the same scope 220 220 return false; 221 } else if ( LinkageSpec::isMangled( added->linkage ) 222 || ResolvExpr::typesCompatible( 221 } else if ( LinkageSpec::isMangled( added->linkage ) 222 || ResolvExpr::typesCompatible( 223 223 added->get_type(), existing.id->get_type(), Indexer() ) ) { 224 224 … … 238 238 if ( isDefinition( added ) && isDefinition( existing.id ) ) { 239 239 if ( handleConflicts.mode == OnConflict::Error ) { 240 SemanticError( added, 241 isFunction( added ) ? 242 "duplicate function definition for " : 240 SemanticError( added, 241 isFunction( added ) ? 242 "duplicate function definition for " : 243 243 "duplicate object definition for " ); 244 244 } … … 255 255 } 256 256 257 bool Indexer::hasCompatibleCDecl( const std::string & id, const std::string &mangleName ) const {257 bool Indexer::hasCompatibleCDecl( const std::string &id, const std::string &mangleName ) const { 258 258 if ( ! idTable ) return false; 259 259 260 ++* stats().map_lookups;260 ++*stats().map_lookups; 261 261 auto decls = idTable->find( id ); 262 262 if ( decls == idTable->end() ) return false; … … 270 270 } 271 271 } 272 272 273 273 return false; 274 274 } 275 275 276 bool Indexer::hasIncompatibleCDecl(const std::string & id, const std::string &mangleName ) const { 276 bool Indexer::hasIncompatibleCDecl( 277 const std::string &id, const std::string &mangleName ) const { 277 278 if ( ! idTable ) return false; 278 279 279 ++* stats().map_lookups;280 ++*stats().map_lookups; 280 281 auto decls = idTable->find( id ); 281 282 if ( decls == idTable->end() ) return false; … … 294 295 295 296 /// gets the base type of the first parameter; decl must be a ctor/dtor/assignment function 296 std::string getOtypeKey( const FunctionDecl* function ) {297 std::string getOtypeKey( FunctionDecl* function ) { 297 298 auto& params = function->type->parameters; 298 299 assert( ! params.empty() ); 299 300 // use base type of pointer, so that qualifiers on the pointer type aren't considered. 300 Type * base = InitTweak::getPointerBase( params.front()->get_type() );301 Type* base = InitTweak::getPointerBase( params.front()->get_type() ); 301 302 assert( base ); 302 303 return Mangler::mangle( base ); 303 304 } 304 305 305 /// gets the declaration for the function acting on a type specified by otype key, 306 /// gets the declaration for the function acting on a type specified by otype key, 306 307 /// nullptr if none such 307 const FunctionDecl * getFunctionForOtype( constDeclarationWithType * decl, const std::string& otypeKey ) {308 const FunctionDecl * func = dynamic_cast< constFunctionDecl * >( decl );308 FunctionDecl * getFunctionForOtype( DeclarationWithType * decl, const std::string& otypeKey ) { 309 FunctionDecl * func = dynamic_cast< FunctionDecl * >( decl ); 309 310 if ( ! func || otypeKey != getOtypeKey( func ) ) return nullptr; 310 311 return func; 311 312 } 312 313 313 bool Indexer::removeSpecialOverrides(Indexer::IdData& data, Indexer::MangleTable::Ptr& mangleTable ) { 314 // if a type contains user defined ctor/dtor/assign, then special rules trigger, which 315 // determinethe set of ctor/dtor/assign that can be used by the requester. In particular, 316 // if the user defines a default ctor, then the generated default ctor is unavailable, 317 // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated 318 // field ctors are available. If the user defines any ctor then the generated default ctor 319 // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines 320 // anything that looks like a copy constructor, then the generated copy constructor is 314 bool Indexer::removeSpecialOverrides( 315 Indexer::IdData& data, Indexer::MangleTable::Ptr& mangleTable ) { 316 // if a type contains user defined ctor/dtor/assign, then special rules trigger, which 317 // determinethe set of ctor/dtor/assign that can be used by the requester. In particular, 318 // if the user defines a default ctor, then the generated default ctor is unavailable, 319 // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated 320 // field ctors are available. If the user defines any ctor then the generated default ctor 321 // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines 322 // anything that looks like a copy constructor, then the generated copy constructor is 321 323 // unavailable, and likewise for the assignment operator. 322 324 323 325 // only relevant on function declarations 324 const FunctionDecl * function = dynamic_cast< constFunctionDecl * >( data.id );326 FunctionDecl * function = dynamic_cast< FunctionDecl * >( data.id ); 325 327 if ( ! function ) return true; 326 328 // only need to perform this check for constructors, destructors, and assignment functions … … 338 340 std::vector< MangleTable::value_type > deleted; 339 341 bool alreadyUserDefinedFunc = false; 340 341 for ( const auto& entry : * mangleTable ) {342 343 for ( const auto& entry : *mangleTable ) { 342 344 // skip decls that aren't functions or are for the wrong type 343 constFunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );345 FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey ); 344 346 if ( ! decl ) continue; 345 347 … … 366 368 // perform removals from mangle table, and deletions if necessary 367 369 for ( const auto& key : removed ) { 368 ++* stats().map_mutations;370 ++*stats().map_mutations; 369 371 mangleTable = mangleTable->erase( key ); 370 372 } 371 373 if ( ! alreadyUserDefinedFunc ) for ( const auto& entry : deleted ) { 372 ++* stats().map_mutations;374 ++*stats().map_mutations; 373 375 mangleTable = mangleTable->set( entry.first, IdData{ entry.second, function } ); 374 376 } … … 377 379 // if this is the first user-defined function, delete non-user-defined overloads 378 380 std::vector< MangleTable::value_type > deleted; 379 380 for ( const auto& entry : * mangleTable ) {381 382 for ( const auto& entry : *mangleTable ) { 381 383 // skip decls that aren't functions or are for the wrong type 382 constFunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );384 FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey ); 383 385 if ( ! decl ) continue; 384 386 … … 400 402 // this needs to be a separate loop because of iterator invalidation 401 403 for ( const auto& entry : deleted ) { 402 ++* stats().map_mutations;404 ++*stats().map_mutations; 403 405 mangleTable = mangleTable->set( entry.first, IdData{ entry.second, function } ); 404 406 } … … 406 408 // this is an overridable generated function 407 409 // if there already exists a matching user-defined function, delete this appropriately 408 for ( const auto& entry : * mangleTable ) {410 for ( const auto& entry : *mangleTable ) { 409 411 // skip decls that aren't functions or are for the wrong type 410 constFunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );412 FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey ); 411 413 if ( ! decl ) continue; 412 414 … … 416 418 if ( dataIsCopyFunc ) { 417 419 // remove current function if exists a user-defined copy function 418 // since the signatures for copy functions don't need to match exactly, using 420 // since the signatures for copy functions don't need to match exactly, using 419 421 // a delete statement is the wrong approach 420 422 if ( InitTweak::isCopyFunction( decl, decl->name ) ) return false; … … 426 428 } 427 429 } 428 430 429 431 // nothing (more) to fix, return true 430 432 return true; 431 433 } 432 434 433 void Indexer::addId(const DeclarationWithType * decl, OnConflict handleConflicts, const Expression * baseExpr, 434 const Declaration * deleteStmt ) { 435 ++* stats().add_calls; 435 void Indexer::addId( 436 DeclarationWithType *decl, OnConflict handleConflicts, Expression * baseExpr, 437 BaseSyntaxNode * deleteStmt ) { 438 ++*stats().add_calls; 436 439 const std::string &name = decl->name; 437 440 if ( name == "" ) return; 438 441 439 442 std::string mangleName; 440 443 if ( LinkageSpec::isOverridable( decl->linkage ) ) { 441 // mangle the name without including the appropriate suffix, so overridable routines 444 // mangle the name without including the appropriate suffix, so overridable routines 442 445 // are placed into the same "bucket" as their user defined versions. 443 446 mangleName = Mangler::mangle( decl, false ); … … 446 449 } // if 447 450 448 // this ensures that no two declarations with the same unmangled name at the same scope 451 // this ensures that no two declarations with the same unmangled name at the same scope 449 452 // both have C linkage 450 453 if ( LinkageSpec::isMangled( decl->linkage ) ) { … … 454 457 } 455 458 } else { 456 // NOTE: only correct if name mangling is completely isomorphic to C 459 // NOTE: only correct if name mangling is completely isomorphic to C 457 460 // type-compatibility, which it may not be. 458 461 if ( hasIncompatibleCDecl( name, mangleName ) ) { … … 467 470 mangleTable = MangleTable::new_ptr(); 468 471 } else { 469 ++* stats().map_lookups;472 ++*stats().map_lookups; 470 473 auto decls = idTable->find( name ); 471 474 if ( decls == idTable->end() ) { … … 474 477 mangleTable = decls->second; 475 478 // skip in-scope repeat declarations of same identifier 476 ++* stats().map_lookups;479 ++*stats().map_lookups; 477 480 auto existing = mangleTable->find( mangleName ); 478 481 if ( existing != mangleTable->end() … … 483 486 // set delete expression for conflicting identifier 484 487 lazyInitScope(); 485 * stats().map_mutations += 2;488 *stats().map_mutations += 2; 486 489 idTable = idTable->set( 487 490 name, 488 mangleTable->set( 489 mangleName, 491 mangleTable->set( 492 mangleName, 490 493 IdData{ existing->second, handleConflicts.deleteStmt } ) ); 491 494 } … … 501 504 // Ensure that auto-generated ctor/dtor/assignment are deleted if necessary 502 505 if ( ! removeSpecialOverrides( data, mangleTable ) ) return; 503 * stats().map_mutations += 2;506 *stats().map_mutations += 2; 504 507 idTable = idTable->set( name, mangleTable->set( mangleName, std::move(data) ) ); 505 508 } 506 509 507 void Indexer::addId( const DeclarationWithType * decl, constExpression * baseExpr ) {510 void Indexer::addId( DeclarationWithType * decl, Expression * baseExpr ) { 508 511 // default handling of conflicts is to raise an error 509 512 addId( decl, OnConflict::error(), baseExpr, decl->isDeleted ? decl : nullptr ); 510 513 } 511 514 512 void Indexer::addDeletedId( const DeclarationWithType * decl, const Declaration* deleteStmt ) {515 void Indexer::addDeletedId( DeclarationWithType * decl, BaseSyntaxNode * deleteStmt ) { 513 516 // default handling of conflicts is to raise an error 514 517 addId( decl, OnConflict::error(), nullptr, deleteStmt ); 515 518 } 516 519 517 bool addedTypeConflicts( const NamedTypeDecl * existing, const NamedTypeDecl *added ) {520 bool addedTypeConflicts( NamedTypeDecl *existing, NamedTypeDecl *added ) { 518 521 if ( existing->base == nullptr ) { 519 522 return false; … … 527 530 } 528 531 } 529 // does not need to be added to the table if both existing and added have a base that are 532 // does not need to be added to the table if both existing and added have a base that are 530 533 // the same 531 534 return true; 532 535 } 533 536 534 void Indexer::addType( const NamedTypeDecl *decl ) {535 ++* stats().add_calls;536 const std::string & id = decl->name;537 538 if ( ! typeTable ) { 537 void Indexer::addType( NamedTypeDecl *decl ) { 538 ++*stats().add_calls; 539 const std::string &id = decl->name; 540 541 if ( ! typeTable ) { 539 542 typeTable = TypeTable::new_ptr(); 540 543 } else { 541 ++* stats().map_lookups;544 ++*stats().map_lookups; 542 545 auto existing = typeTable->find( id ); 543 if ( existing != typeTable->end() 544 && existing->second.scope == scope 546 if ( existing != typeTable->end() 547 && existing->second.scope == scope 545 548 && addedTypeConflicts( existing->second.decl, decl ) ) return; 546 549 } 547 550 548 551 lazyInitScope(); 549 ++* stats().map_mutations;552 ++*stats().map_mutations; 550 553 typeTable = typeTable->set( id, Scoped<NamedTypeDecl>{ decl, scope } ); 551 554 } 552 555 553 bool addedDeclConflicts( const AggregateDecl * existing, const AggregateDecl *added ) {556 bool addedDeclConflicts( AggregateDecl *existing, AggregateDecl *added ) { 554 557 if ( ! existing->body ) { 555 558 return false; … … 560 563 } 561 564 562 void Indexer::addStruct( const std::string & id ) {565 void Indexer::addStruct( const std::string &id ) { 563 566 addStruct( new StructDecl( id ) ); 564 567 } 565 568 566 void Indexer::addStruct( const StructDecl *decl ) {567 ++* stats().add_calls;568 const std::string & id = decl->name;569 void Indexer::addStruct( StructDecl *decl ) { 570 ++*stats().add_calls; 571 const std::string &id = decl->name; 569 572 570 573 if ( ! structTable ) { 571 574 structTable = StructTable::new_ptr(); 572 575 } else { 573 ++* stats().map_lookups;576 ++*stats().map_lookups; 574 577 auto existing = structTable->find( id ); 575 if ( existing != structTable->end() 576 && existing->second.scope == scope 578 if ( existing != structTable->end() 579 && existing->second.scope == scope 577 580 && addedDeclConflicts( existing->second.decl, decl ) ) return; 578 581 } 579 582 580 583 lazyInitScope(); 581 ++* stats().map_mutations;584 ++*stats().map_mutations; 582 585 structTable = structTable->set( id, Scoped<StructDecl>{ decl, scope } ); 583 586 } 584 587 585 void Indexer::addEnum( const EnumDecl *decl ) {586 ++* stats().add_calls;587 const std::string & id = decl->name;588 void Indexer::addEnum( EnumDecl *decl ) { 589 ++*stats().add_calls; 590 const std::string &id = decl->name; 588 591 589 592 if ( ! enumTable ) { 590 593 enumTable = EnumTable::new_ptr(); 591 594 } else { 592 ++* stats().map_lookups;595 ++*stats().map_lookups; 593 596 auto existing = enumTable->find( id ); 594 if ( existing != enumTable->end() 595 && existing->second.scope == scope 597 if ( existing != enumTable->end() 598 && existing->second.scope == scope 596 599 && addedDeclConflicts( existing->second.decl, decl ) ) return; 597 600 } 598 601 599 602 lazyInitScope(); 600 ++* stats().map_mutations;603 ++*stats().map_mutations; 601 604 enumTable = enumTable->set( id, Scoped<EnumDecl>{ decl, scope } ); 602 605 } 603 606 604 void Indexer::addUnion( const std::string & id ) {607 void Indexer::addUnion( const std::string &id ) { 605 608 addUnion( new UnionDecl( id ) ); 606 609 } 607 610 608 void Indexer::addUnion( const UnionDecl *decl ) {609 ++* stats().add_calls;610 const std::string & id = decl->name;611 void Indexer::addUnion( UnionDecl *decl ) { 612 ++*stats().add_calls; 613 const std::string &id = decl->name; 611 614 612 615 if ( ! unionTable ) { 613 616 unionTable = UnionTable::new_ptr(); 614 617 } else { 615 ++* stats().map_lookups;618 ++*stats().map_lookups; 616 619 auto existing = unionTable->find( id ); 617 if ( existing != unionTable->end() 618 && existing->second.scope == scope 620 if ( existing != unionTable->end() 621 && existing->second.scope == scope 619 622 && addedDeclConflicts( existing->second.decl, decl ) ) return; 620 623 } 621 624 622 625 lazyInitScope(); 623 ++* stats().map_mutations;626 ++*stats().map_mutations; 624 627 unionTable = unionTable->set( id, Scoped<UnionDecl>{ decl, scope } ); 625 628 } 626 629 627 void Indexer::addTrait( const TraitDecl *decl ) {628 ++* stats().add_calls;629 const std::string & id = decl->name;630 void Indexer::addTrait( TraitDecl *decl ) { 631 ++*stats().add_calls; 632 const std::string &id = decl->name; 630 633 631 634 if ( ! traitTable ) { 632 635 traitTable = TraitTable::new_ptr(); 633 636 } else { 634 ++* stats().map_lookups;637 ++*stats().map_lookups; 635 638 auto existing = traitTable->find( id ); 636 if ( existing != traitTable->end() 637 && existing->second.scope == scope 639 if ( existing != traitTable->end() 640 && existing->second.scope == scope 638 641 && addedDeclConflicts( existing->second.decl, decl ) ) return; 639 642 } 640 643 641 644 lazyInitScope(); 642 ++* stats().map_mutations;645 ++*stats().map_mutations; 643 646 traitTable = traitTable->set( id, Scoped<TraitDecl>{ decl, scope } ); 644 647 } 645 648 646 void Indexer::addMembers( const AggregateDecl * aggr, const Expression * expr, OnConflict handleConflicts ) { 649 void Indexer::addMembers( AggregateDecl * aggr, Expression * expr, 650 OnConflict handleConflicts ) { 647 651 for ( Declaration * decl : aggr->members ) { 648 652 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) { 649 653 addId( dwt, handleConflicts, expr ); 650 654 if ( dwt->name == "" ) { 651 constType * t = dwt->get_type()->stripReferences();652 if ( dynamic_cast< const StructInstType *>( t ) || dynamic_cast<const UnionInstType*>( t ) ) {655 Type * t = dwt->get_type()->stripReferences(); 656 if ( dynamic_cast<StructInstType*>( t ) || dynamic_cast<UnionInstType*>( t ) ) { 653 657 Expression * base = expr->clone(); 654 658 ResolvExpr::Cost cost = ResolvExpr::Cost::zero; // xxx - carry this cost into the indexer as a base cost? … … 661 665 } 662 666 663 void Indexer::addWith( const std::list< Expression * > & withExprs, const Declaration* withStmt ) {664 for ( constExpression * expr : withExprs ) {667 void Indexer::addWith( std::list< Expression * > & withExprs, BaseSyntaxNode * withStmt ) { 668 for ( Expression * expr : withExprs ) { 665 669 if ( expr->result ) { 666 670 AggregateDecl * aggr = expr->result->stripReferences()->getAggr(); … … 685 689 } 686 690 687 void Indexer::addFunctionType( constFunctionType * ftype ) {691 void Indexer::addFunctionType( FunctionType * ftype ) { 688 692 addTypes( ftype->forall ); 689 693 addIds( ftype->returnVals ); … … 696 700 Expression * base = baseExpr->clone(); 697 701 ResolvExpr::referenceToRvalueConversion( base, cost ); 698 ret = new MemberExpr( const_cast<DeclarationWithType *>(id), base );702 ret = new MemberExpr( id, base ); 699 703 // xxx - this introduces hidden environments, for now remove them. 700 704 // std::swap( base->env, ret->env ); … … 702 706 base->env = nullptr; 703 707 } else { 704 ret = new VariableExpr( const_cast<DeclarationWithType *>(id));705 } 706 if ( deleteStmt ) ret = new DeletedExpr( ret, const_cast<Declaration *>(deleteStmt));708 ret = new VariableExpr( id ); 709 } 710 if ( deleteStmt ) ret = new DeletedExpr( ret, deleteStmt ); 707 711 return ret; 708 712 }
Note:
See TracChangeset
for help on using the changeset viewer.