Changeset 522363e
- Timestamp:
- Sep 14, 2017, 1:46:06 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 3e3d923, bff09c8, f92c696
- Parents:
- c57ded70
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.impl.h
rc57ded70 r522363e 66 66 DeclList_t* beforeDecls = visitor.get_beforeDecls(); 67 67 DeclList_t* afterDecls = visitor.get_afterDecls(); 68 SemanticError errors; 68 69 69 70 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { … … 73 74 if ( i == decls.end() ) break; 74 75 75 // run mutator on declaration 76 maybeAccept( *i, visitor ); 76 try { 77 // run visitor on declaration 78 maybeAccept( *i, visitor ); 79 } catch( SemanticError &e ) { 80 e.set_location( (*i)->location ); 81 errors.append( e ); 82 } 77 83 78 84 // splice in new declarations before current decl 79 85 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } 80 86 } 87 if ( ! errors.isEmpty() ) { 88 throw errors; 89 } 81 90 } 82 91 … … 86 95 DeclList_t* beforeDecls = mutator.get_beforeDecls(); 87 96 DeclList_t* afterDecls = mutator.get_afterDecls(); 97 SemanticError errors; 88 98 89 99 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { … … 92 102 93 103 if ( i == decls.end() ) break; 94 95 // run mutator on declaration 96 *i = maybeMutate( *i, mutator ); 104 try { 105 // run mutator on declaration 106 *i = maybeMutate( *i, mutator ); 107 } catch( SemanticError &e ) { 108 e.set_location( (*i)->location ); 109 errors.append( e ); 110 } 97 111 98 112 // splice in new declarations before current decl 99 113 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } 114 } 115 if ( ! errors.isEmpty() ) { 116 throw errors; 100 117 } 101 118 } … … 445 462 indexerAddEnum( node ); 446 463 447 // unlike structs, contexts, and unions, enums inject their members into the global scope464 // unlike structs, traits, and unions, enums inject their members into the global scope 448 465 maybeMutateRef( node->parameters, *this ); 449 466 maybeMutateRef( node->members , *this ); -
src/Common/PassVisitor.proto.h
rc57ded70 r522363e 179 179 180 180 template<typename pass_type> 181 static inline auto indexer_impl_enterScope( pass_type &, int) {}181 static inline auto indexer_impl_enterScope( pass_type &, long ) {} 182 182 183 183 template<typename pass_type> … … 187 187 188 188 template<typename pass_type> 189 static inline auto indexer_impl_leaveScope( pass_type &, int) {}189 static inline auto indexer_impl_leaveScope( pass_type &, long ) {} 190 190 191 191 … … 197 197 \ 198 198 template<typename pass_type> \ 199 static inline void indexer_impl_##func ( pass_type &, long, type ) { } \199 static inline void indexer_impl_##func ( pass_type &, long, type ) { } \ 200 200 201 201 INDEXER_FUNC( addId , DeclarationWithType * ); … … 215 215 216 216 template<typename pass_type> 217 static inline auto indexer_impl_addStructFwd( pass_type &, int, StructDecl * ) {}217 static inline auto indexer_impl_addStructFwd( pass_type &, long, StructDecl * ) {} 218 218 219 219 template<typename pass_type> … … 225 225 226 226 template<typename pass_type> 227 static inline auto indexer_impl_addUnionFwd( pass_type &, int, UnionDecl * ) {}227 static inline auto indexer_impl_addUnionFwd( pass_type &, long, UnionDecl * ) {} 228 228 229 229 template<typename pass_type> … … 235 235 236 236 template<typename pass_type> 237 static inline auto indexer_impl_addStruct( pass_type &, int, const std::string & ) {}237 static inline auto indexer_impl_addStruct( pass_type &, long, const std::string & ) {} 238 238 239 239 template<typename pass_type> … … 245 245 246 246 template<typename pass_type> 247 static inline auto indexer_impl_addUnion( pass_type &, int, const std::string & ) {}247 static inline auto indexer_impl_addUnion( pass_type &, long, const std::string & ) {} -
src/SymTab/Indexer.cc
rc57ded70 r522363e 37 37 #include "SynTree/Type.h" // for Type, StructInstType, UnionInstType 38 38 39 #define debugPrint(x) if ( doDebug ) { std::c out<< x; }39 #define debugPrint(x) if ( doDebug ) { std::cerr << x; } 40 40 41 41 namespace SymTab { -
src/SymTab/Indexer.h
rc57ded70 r522363e 104 104 105 105 void print( std::ostream &os, int indent = 0 ) const; 106 private: 106 107 107 /// looks up a specific mangled ID at the given scope 108 108 DeclarationWithType *lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const; … … 127 127 void addTrait( TraitDecl *decl ); 128 128 129 private: 129 130 struct Impl; 130 131 -
src/SymTab/Validate.cc
rc57ded70 r522363e 123 123 124 124 /// Associates forward declarations of aggregates with their definitions 125 class LinkReferenceToTypes final : public Indexer { 126 typedef Indexer Parent; 127 public: 128 LinkReferenceToTypes( bool doDebug, const Indexer *indexer ); 129 using Parent::visit; 130 void visit( TypeInstType *typeInst ) final; 131 132 void visit( EnumInstType *enumInst ) final; 133 void visit( StructInstType *structInst ) final; 134 void visit( UnionInstType *unionInst ) final; 135 void visit( TraitInstType *traitInst ) final; 136 137 void visit( EnumDecl *enumDecl ) final; 138 void visit( StructDecl *structDecl ) final; 139 void visit( UnionDecl *unionDecl ) final; 140 void visit( TraitDecl * traitDecl ) final; 125 struct LinkReferenceToTypes final : public WithIndexer { 126 LinkReferenceToTypes( const Indexer *indexer ); 127 void postvisit( TypeInstType *typeInst ); 128 129 void postvisit( EnumInstType *enumInst ); 130 void postvisit( StructInstType *structInst ); 131 void postvisit( UnionInstType *unionInst ); 132 void postvisit( TraitInstType *traitInst ); 133 134 void postvisit( EnumDecl *enumDecl ); 135 void postvisit( StructDecl *structDecl ); 136 void postvisit( UnionDecl *unionDecl ); 137 void postvisit( TraitDecl * traitDecl ); 141 138 142 139 private: 143 const Indexer * indexer;140 const Indexer *local_indexer; 144 141 145 142 typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType; … … 152 149 153 150 /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID. 154 class ForallPointerDecay final : public Indexer { 155 typedef Indexer Parent; 156 public: 157 using Parent::visit; 158 ForallPointerDecay( const Indexer *indexer ); 159 160 virtual void visit( ObjectDecl *object ) override; 161 virtual void visit( FunctionDecl *func ) override; 162 163 const Indexer *indexer; 151 struct ForallPointerDecay final { 152 void previsit( ObjectDecl *object ); 153 void previsit( FunctionDecl *func ); 164 154 }; 165 155 … … 263 253 }; 264 254 265 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {255 void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) { 266 256 PassVisitor<EnumAndPointerDecay> epc; 267 LinkReferenceToTypes lrt( doDebug, 0);268 ForallPointerDecay fpd( 0 );257 PassVisitor<LinkReferenceToTypes> lrt( nullptr ); 258 PassVisitor<ForallPointerDecay> fpd; 269 259 PassVisitor<CompoundLiteral> compoundliteral; 270 260 PassVisitor<ValidateGenericParameters> genericParams; … … 293 283 void validateType( Type *type, const Indexer *indexer ) { 294 284 PassVisitor<EnumAndPointerDecay> epc; 295 LinkReferenceToTypes lrt( false,indexer );296 ForallPointerDecay fpd( indexer );285 PassVisitor<LinkReferenceToTypes> lrt( indexer ); 286 PassVisitor<ForallPointerDecay> fpd; 297 287 type->accept( epc ); 298 288 type->accept( lrt ); … … 408 398 } 409 399 410 LinkReferenceToTypes::LinkReferenceToTypes( bool doDebug, const Indexer *other_indexer ) : Indexer( doDebug) {400 LinkReferenceToTypes::LinkReferenceToTypes( const Indexer *other_indexer ) { 411 401 if ( other_indexer ) { 412 indexer = other_indexer;402 local_indexer = other_indexer; 413 403 } else { 414 indexer = this; 415 } // if 416 } 417 418 void LinkReferenceToTypes::visit( EnumInstType *enumInst ) { 419 Parent::visit( enumInst ); 420 EnumDecl *st = indexer->lookupEnum( enumInst->get_name() ); 404 local_indexer = &indexer; 405 } // if 406 } 407 408 void LinkReferenceToTypes::postvisit( EnumInstType *enumInst ) { 409 EnumDecl *st = local_indexer->lookupEnum( enumInst->get_name() ); 421 410 // it's not a semantic error if the enum is not found, just an implicit forward declaration 422 411 if ( st ) { … … 430 419 } 431 420 432 void LinkReferenceToTypes::visit( StructInstType *structInst ) { 433 Parent::visit( structInst ); 434 StructDecl *st = indexer->lookupStruct( structInst->get_name() ); 421 void LinkReferenceToTypes::postvisit( StructInstType *structInst ) { 422 StructDecl *st = local_indexer->lookupStruct( structInst->get_name() ); 435 423 // it's not a semantic error if the struct is not found, just an implicit forward declaration 436 424 if ( st ) { … … 444 432 } 445 433 446 void LinkReferenceToTypes::visit( UnionInstType *unionInst ) { 447 Parent::visit( unionInst ); 448 UnionDecl *un = indexer->lookupUnion( unionInst->get_name() ); 434 void LinkReferenceToTypes::postvisit( UnionInstType *unionInst ) { 435 UnionDecl *un = local_indexer->lookupUnion( unionInst->get_name() ); 449 436 // it's not a semantic error if the union is not found, just an implicit forward declaration 450 437 if ( un ) { … … 499 486 } 500 487 501 void LinkReferenceToTypes::visit( TraitDecl * traitDecl ) { 502 Parent::visit( traitDecl ); 503 488 void LinkReferenceToTypes::postvisit( TraitDecl * traitDecl ) { 504 489 if ( traitDecl->name == "sized" ) { 505 490 // "sized" is a special trait - flick the sized status on for the type variable … … 523 508 } 524 509 525 void LinkReferenceToTypes::visit( TraitInstType * traitInst ) { 526 Parent::visit( traitInst ); 510 void LinkReferenceToTypes::postvisit( TraitInstType * traitInst ) { 527 511 // handle other traits 528 TraitDecl *traitDecl = indexer->lookupTrait( traitInst->name );512 TraitDecl *traitDecl = local_indexer->lookupTrait( traitInst->name ); 529 513 if ( ! traitDecl ) { 530 514 throw SemanticError( "use of undeclared trait " + traitInst->name ); … … 547 531 } 548 532 549 void LinkReferenceToTypes:: visit( EnumDecl *enumDecl ) {533 void LinkReferenceToTypes::postvisit( EnumDecl *enumDecl ) { 550 534 // visit enum members first so that the types of self-referencing members are updated properly 551 Parent::visit( enumDecl );552 535 if ( ! enumDecl->get_members().empty() ) { 553 536 ForwardEnumsType::iterator fwds = forwardEnums.find( enumDecl->get_name() ); … … 561 544 } 562 545 563 void LinkReferenceToTypes:: visit( StructDecl *structDecl ) {546 void LinkReferenceToTypes::postvisit( StructDecl *structDecl ) { 564 547 // visit struct members first so that the types of self-referencing members are updated properly 565 // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and and their defaults) 566 Parent::visit( structDecl ); 548 // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and their defaults) 567 549 if ( ! structDecl->get_members().empty() ) { 568 550 ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() ); … … 576 558 } 577 559 578 void LinkReferenceToTypes::visit( UnionDecl *unionDecl ) { 579 Parent::visit( unionDecl ); 560 void LinkReferenceToTypes::postvisit( UnionDecl *unionDecl ) { 580 561 if ( ! unionDecl->get_members().empty() ) { 581 562 ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() ); … … 589 570 } 590 571 591 void LinkReferenceToTypes:: visit( TypeInstType *typeInst ) {592 if ( NamedTypeDecl *namedTypeDecl = lo okupType( typeInst->get_name() ) ) {572 void LinkReferenceToTypes::postvisit( TypeInstType *typeInst ) { 573 if ( NamedTypeDecl *namedTypeDecl = local_indexer->lookupType( typeInst->get_name() ) ) { 593 574 if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) { 594 575 typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype ); 595 576 } // if 596 } // if597 }598 599 ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) : Indexer( false ) {600 if ( other_indexer ) {601 indexer = other_indexer;602 } else {603 indexer = this;604 577 } // if 605 578 } … … 633 606 } 634 607 635 void ForallPointerDecay:: visit( ObjectDecl *object ) {608 void ForallPointerDecay::previsit( ObjectDecl *object ) { 636 609 forallFixer( object->get_type() ); 637 610 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) { 638 611 forallFixer( pointer->get_base() ); 639 612 } // if 640 Parent::visit( object );641 613 object->fixUniqueId(); 642 614 } 643 615 644 void ForallPointerDecay:: visit( FunctionDecl *func ) {616 void ForallPointerDecay::previsit( FunctionDecl *func ) { 645 617 forallFixer( func->get_type() ); 646 Parent::visit( func );647 618 func->fixUniqueId(); 648 619 }
Note: See TracChangeset
for help on using the changeset viewer.