Changeset 8024bc8 for src/Common
- Timestamp:
- Sep 18, 2017, 11:02:23 AM (8 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, stuck-waitfor-destruct, with_gc
- Children:
- 6994d8c
- Parents:
- ed235b6 (diff), 5f782f7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/Common
- Files:
-
- 2 edited
-
PassVisitor.impl.h (modified) (16 diffs)
-
PassVisitor.proto.h (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.impl.h
red235b6 r8024bc8 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 } … … 166 183 167 184 } catch ( SemanticError &e ) { 185 e.set_location( (*i)->location ); 168 186 errors.append( e ); 169 187 } … … 275 293 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 276 294 295 // A NOTE ON THE ORDER OF TRAVERSAL 296 // 297 // Types and typedefs have their base types visited before they are added to the type table. This is ok, since there is 298 // no such thing as a recursive type or typedef. 299 // 300 // typedef struct { T *x; } T; // never allowed 301 // 302 // for structs/unions, it is possible to have recursion, so the decl should be added as if it's incomplete to begin, the 303 // members are traversed, and then the complete type should be added (assuming the type is completed by this particular 304 // declaration). 305 // 306 // struct T { struct T *x; }; // allowed 307 // 308 // It is important to add the complete type to the symbol table *after* the members/base has been traversed, since that 309 // traversal may modify the definition of the type and these modifications should be visible when the symbol table is 310 // queried later in this pass. 311 // 312 // TODO: figure out whether recursive contexts are sensible/possible/reasonable. 277 313 278 314 //-------------------------------------------------------------------------- … … 432 468 indexerAddEnum( node ); 433 469 434 // unlike structs, contexts, and unions, enums inject their members into the global scope470 // unlike structs, traits, and unions, enums inject their members into the global scope 435 471 maybeAccept( node->parameters, *this ); 436 472 maybeAccept( node->members , *this ); … … 445 481 indexerAddEnum( node ); 446 482 447 // unlike structs, contexts, and unions, enums inject their members into the global scope483 // unlike structs, traits, and unions, enums inject their members into the global scope 448 484 maybeMutateRef( node->parameters, *this ); 449 485 maybeMutateRef( node->members , *this ); … … 496 532 } 497 533 534 // see A NOTE ON THE ORDER OF TRAVERSAL, above 535 // note that assertions come after the type is added to the symtab, since they are not part of the type proper 536 // and may depend on the type itself 498 537 indexerAddType( node ); 499 538 … … 515 554 } 516 555 556 // see A NOTE ON THE ORDER OF TRAVERSAL, above 557 // note that assertions come after the type is added to the symtab, since they are not part of the type proper 558 // and may depend on the type itself 517 559 indexerAddType( node ); 518 560 … … 641 683 void PassVisitor< pass_type >::visit( IfStmt * node ) { 642 684 VISIT_START( node ); 643 644 visitExpression( node->condition ); 645 node->thenPart = visitStatement( node->thenPart ); 646 node->elsePart = visitStatement( node->elsePart ); 647 685 { 686 // if statements introduce a level of scope (for the initialization) 687 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 688 acceptAll( node->get_initialization(), *this ); 689 visitExpression( node->condition ); 690 node->thenPart = visitStatement( node->thenPart ); 691 node->elsePart = visitStatement( node->elsePart ); 692 } 648 693 VISIT_END( node ); 649 694 } … … 653 698 MUTATE_START( node ); 654 699 { 655 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 700 // if statements introduce a level of scope (for the initialization) 701 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 702 maybeMutateRef( node->get_initialization(), *this ); 656 703 node->condition = mutateExpression( node->condition ); 657 704 node->thenPart = mutateStatement ( node->thenPart ); … … 689 736 VISIT_START( node ); 690 737 { 738 // for statements introduce a level of scope (for the initialization) 691 739 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 692 740 maybeAccept( node->initialization, *this ); … … 702 750 MUTATE_START( node ); 703 751 { 752 // for statements introduce a level of scope (for the initialization) 704 753 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 705 754 maybeMutateRef( node->initialization, *this ); … … 830 879 VISIT_START( node ); 831 880 { 881 // catch statements introduce a level of scope (for the caught exception) 832 882 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 833 883 maybeAccept( node->decl, *this ); … … 842 892 MUTATE_START( node ); 843 893 { 894 // catch statements introduce a level of scope (for the caught exception) 844 895 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 845 896 maybeMutateRef( node->decl, *this ); -
src/Common/PassVisitor.proto.h
red235b6 r8024bc8 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 & ) {}
Note:
See TracChangeset
for help on using the changeset viewer.