Changeset d9a0e76 for translator/SynTree/Visitor.h
- Timestamp:
- Dec 16, 2014, 9:41:50 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 17cd4eb
- Parents:
- 3848e0e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SynTree/Visitor.h
r3848e0e rd9a0e76 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Visitor.h,v 1.23 2005/08/29 20:59:27 rcbilson Exp $5 *6 */7 8 1 #ifndef VISITOR_H 9 2 #define VISITOR_H … … 14 7 15 8 16 class Visitor 17 { 18 protected: 9 class Visitor { 10 protected: 19 11 Visitor(); 20 12 virtual ~Visitor(); 13 public: 14 virtual void visit( ObjectDecl *objectDecl ); 15 virtual void visit( FunctionDecl *functionDecl ); 16 virtual void visit( StructDecl *aggregateDecl ); 17 virtual void visit( UnionDecl *aggregateDecl ); 18 virtual void visit( EnumDecl *aggregateDecl ); 19 virtual void visit( ContextDecl *aggregateDecl ); 20 virtual void visit( TypeDecl *typeDecl ); 21 virtual void visit( TypedefDecl *typeDecl ); 21 22 22 public: 23 virtual void visit(ObjectDecl *objectDecl); 24 virtual void visit(FunctionDecl *functionDecl); 25 virtual void visit(StructDecl *aggregateDecl); 26 virtual void visit(UnionDecl *aggregateDecl); 27 virtual void visit(EnumDecl *aggregateDecl); 28 virtual void visit(ContextDecl *aggregateDecl); 29 virtual void visit(TypeDecl *typeDecl); 30 virtual void visit(TypedefDecl *typeDecl); 23 virtual void visit( CompoundStmt *compoundStmt ); 24 virtual void visit( ExprStmt *exprStmt ); 25 virtual void visit( IfStmt *ifStmt ); 26 virtual void visit( WhileStmt *whileStmt ); 27 virtual void visit( ForStmt *forStmt ); 28 virtual void visit( SwitchStmt *switchStmt ); 29 virtual void visit( ChooseStmt *switchStmt ); 30 virtual void visit( FallthruStmt *switchStmt ); 31 virtual void visit( CaseStmt *caseStmt ); 32 virtual void visit( BranchStmt *branchStmt ); 33 virtual void visit( ReturnStmt *returnStmt ); 34 virtual void visit( TryStmt *tryStmt ); 35 virtual void visit( CatchStmt *catchStmt ); 36 virtual void visit( FinallyStmt *finallyStmt ); 37 virtual void visit( NullStmt *nullStmt ); 38 virtual void visit( DeclStmt *declStmt ); 31 39 32 virtual void visit(CompoundStmt *compoundStmt); 33 virtual void visit(ExprStmt *exprStmt); 34 virtual void visit(IfStmt *ifStmt); 35 virtual void visit(WhileStmt *whileStmt); 36 virtual void visit(ForStmt *forStmt); 37 virtual void visit(SwitchStmt *switchStmt); 38 virtual void visit(ChooseStmt *switchStmt); 39 virtual void visit(FallthruStmt *switchStmt); 40 virtual void visit(CaseStmt *caseStmt); 41 virtual void visit(BranchStmt *branchStmt); 42 virtual void visit(ReturnStmt *returnStmt); 43 virtual void visit(TryStmt *tryStmt); 44 virtual void visit(CatchStmt *catchStmt); 45 virtual void visit(FinallyStmt *finallyStmt); 46 virtual void visit(NullStmt *nullStmt); 47 virtual void visit(DeclStmt *declStmt); 40 virtual void visit( ApplicationExpr *applicationExpr ); 41 virtual void visit( UntypedExpr *untypedExpr ); 42 virtual void visit( NameExpr *nameExpr ); 43 virtual void visit( CastExpr *castExpr ); 44 virtual void visit( AddressExpr *addressExpr ); 45 virtual void visit( LabelAddressExpr *labAddressExpr ); 46 virtual void visit( UntypedMemberExpr *memberExpr ); 47 virtual void visit( MemberExpr *memberExpr ); 48 virtual void visit( VariableExpr *variableExpr ); 49 virtual void visit( ConstantExpr *constantExpr ); 50 virtual void visit( SizeofExpr *sizeofExpr ); 51 virtual void visit( AttrExpr *attrExpr ); 52 virtual void visit( LogicalExpr *logicalExpr ); 53 virtual void visit( ConditionalExpr *conditionalExpr ); 54 virtual void visit( CommaExpr *commaExpr ); 55 virtual void visit( TupleExpr *tupleExpr ); 56 virtual void visit( SolvedTupleExpr *tupleExpr ); 57 virtual void visit( TypeExpr *typeExpr ); 58 virtual void visit( UntypedValofExpr *valofExpr ); 48 59 49 virtual void visit(ApplicationExpr *applicationExpr); 50 virtual void visit(UntypedExpr *untypedExpr); 51 virtual void visit(NameExpr *nameExpr); 52 virtual void visit(CastExpr *castExpr); 53 virtual void visit(AddressExpr *addressExpr); 54 virtual void visit(LabelAddressExpr *labAddressExpr); 55 virtual void visit(UntypedMemberExpr *memberExpr); 56 virtual void visit(MemberExpr *memberExpr); 57 virtual void visit(VariableExpr *variableExpr); 58 virtual void visit(ConstantExpr *constantExpr); 59 virtual void visit(SizeofExpr *sizeofExpr); 60 virtual void visit(AttrExpr *attrExpr); 61 virtual void visit(LogicalExpr *logicalExpr); 62 virtual void visit(ConditionalExpr *conditionalExpr); 63 virtual void visit(CommaExpr *commaExpr); 64 virtual void visit(TupleExpr *tupleExpr); 65 virtual void visit(SolvedTupleExpr *tupleExpr); 66 virtual void visit(TypeExpr *typeExpr); 67 virtual void visit(UntypedValofExpr *valofExpr); 60 virtual void visit( VoidType *basicType ); 61 virtual void visit( BasicType *basicType ); 62 virtual void visit( PointerType *pointerType ); 63 virtual void visit( ArrayType *arrayType ); 64 virtual void visit( FunctionType *functionType ); 65 virtual void visit( StructInstType *aggregateUseType ); 66 virtual void visit( UnionInstType *aggregateUseType ); 67 virtual void visit( EnumInstType *aggregateUseType ); 68 virtual void visit( ContextInstType *aggregateUseType ); 69 virtual void visit( TypeInstType *aggregateUseType ); 70 virtual void visit( TupleType *tupleType ); 71 virtual void visit( TypeofType *typeofType ); 72 virtual void visit( AttrType *attrType ); 68 73 69 virtual void visit(VoidType *basicType); 70 virtual void visit(BasicType *basicType); 71 virtual void visit(PointerType *pointerType); 72 virtual void visit(ArrayType *arrayType); 73 virtual void visit(FunctionType *functionType); 74 virtual void visit(StructInstType *aggregateUseType); 75 virtual void visit(UnionInstType *aggregateUseType); 76 virtual void visit(EnumInstType *aggregateUseType); 77 virtual void visit(ContextInstType *aggregateUseType); 78 virtual void visit(TypeInstType *aggregateUseType); 79 virtual void visit(TupleType *tupleType); 80 virtual void visit(TypeofType *typeofType); 81 virtual void visit(AttrType *attrType); 74 virtual void visit( MemberInit *memberInit ); 75 virtual void visit( ElementInit *elementInit ); 76 virtual void visit( SingleInit *singleInit ); 77 virtual void visit( ListInit *listInit ); 82 78 83 virtual void visit(MemberInit *memberInit); 84 virtual void visit(ElementInit *elementInit); 85 virtual void visit(SingleInit *singleInit); 86 virtual void visit(ListInit *listInit); 79 virtual void visit( Subrange *subrange ); 87 80 88 virtual void visit(Subrange *subrange); 89 90 virtual void visit(Constant *constant); 91 92 private: 93 virtual void visit(AggregateDecl *aggregateDecl); 94 virtual void visit(NamedTypeDecl *typeDecl); 95 virtual void visit(ReferenceToType *aggregateUseType); 81 virtual void visit( Constant *constant ); 82 private: 83 virtual void visit( AggregateDecl *aggregateDecl ); 84 virtual void visit( NamedTypeDecl *typeDecl ); 85 virtual void visit( ReferenceToType *aggregateUseType ); 96 86 }; 97 87 98 88 template< typename TreeType, typename VisitorType > 99 inline void 100 maybeAccept( TreeType *tree, VisitorType &visitor ) 101 { 102 if( tree ) { 89 inline void maybeAccept( TreeType *tree, VisitorType &visitor ) { 90 if ( tree ) { 103 91 tree->accept( visitor ); 104 92 } … … 106 94 107 95 template< typename Container, typename VisitorType > 108 inline void 109 acceptAll( Container &container, VisitorType &visitor ) 110 { 96 inline void acceptAll( Container &container, VisitorType &visitor ) { 111 97 SemanticError errors; 112 for( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {98 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 113 99 try { 114 if ( *i ) {100 if ( *i ) { 115 101 (*i)->accept( visitor ); 116 102 } … … 119 105 } 120 106 } 121 if ( !errors.isEmpty() ) {107 if ( !errors.isEmpty() ) { 122 108 throw errors; 123 109 } … … 125 111 126 112 template< typename Container, typename VisitorType > 127 void 128 acceptAllFold( Container &container, VisitorType &visitor, VisitorType &around ) 129 { 113 void acceptAllFold( Container &container, VisitorType &visitor, VisitorType &around ) { 130 114 SemanticError errors; 131 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {115 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 132 116 try { 133 if ( *i ) {134 117 if ( *i ) { 118 VisitorType *v = new VisitorType; 135 119 (*i)->accept( *v ); 136 120 137 138 if( nxt == container.end() )139 visitor += *v;140 141 visitor += *v + around;121 typename Container::iterator nxt = i; nxt++; // forward_iterator 122 if ( nxt == container.end() ) 123 visitor += *v; 124 else 125 visitor += *v + around; 142 126 143 127 delete v; 144 128 } 145 129 } catch( SemanticError &e ) { … … 147 131 } 148 132 } 149 if ( !errors.isEmpty() ) {133 if ( !errors.isEmpty() ) { 150 134 throw errors; 151 135 } 152 136 } 153 137 154 155 #endif /* #ifndef VISITOR_H */ 156 157 158 /* 159 Local Variables: 160 mode: c++ 161 End: 162 */ 138 #endif // VISITOR_H
Note: See TracChangeset
for help on using the changeset viewer.