Changeset d9a0e76 for translator/SynTree
- 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
- Location:
- translator/SynTree
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SynTree/Initializer.cc
r3848e0e rd9a0e76 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Initializer.cc,v 1.10 2005/08/29 20:59:25 rcbilson Exp $5 *6 */7 8 1 #include "Initializer.h" 9 2 #include "Expression.h" … … 11 4 12 5 13 Initializer::Initializer( ) 14 { 15 } 6 Initializer::Initializer() {} 16 7 17 Initializer::~Initializer( ) 18 { 19 } 8 Initializer::~Initializer() {} 20 9 21 10 std::string Initializer::designator_name( Expression *des ) { 22 if ( NameExpr *n = dynamic_cast<NameExpr *>(des) )11 if ( NameExpr *n = dynamic_cast<NameExpr *>(des) ) 23 12 return n->get_name(); 24 13 else … … 26 15 } 27 16 28 void 29 Initializer::print( std::ostream &os, int indent ) 30 { 17 void Initializer::print( std::ostream &os, int indent ) {} 18 19 SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators ) : value ( v ), designators( _designators ) { 31 20 } 32 21 33 SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators ) 34 : value ( v ), designators( _designators ) 35 { 36 } 37 38 SingleInit::SingleInit ( const SingleInit &other ) 39 : value ( other.value ) 40 { 22 SingleInit::SingleInit( const SingleInit &other ) : value ( other.value ) { 41 23 cloneAll(other.designators, designators ); 42 24 } 43 25 44 SingleInit::~SingleInit() 45 { 46 } 26 SingleInit::~SingleInit() {} 47 27 48 28 SingleInit *SingleInit::clone() const { return new SingleInit( *this); } 49 29 50 void SingleInit::print( std::ostream &os, int indent ) 51 { 30 void SingleInit::print( std::ostream &os, int indent ) { 52 31 os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: "; 53 32 value->print( os, indent+2 ); 54 33 55 if ( ! designators.empty() ) 56 { 57 os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " ; 58 for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) 59 ( *i )->print(os, indent + 4 ); 60 } 34 if ( ! designators.empty() ) { 35 os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " ; 36 for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) 37 ( *i )->print(os, indent + 4 ); 38 } 61 39 } 62 40 63 MemberInit::MemberInit( Expression *_value, std::string _member ) 64 : member ( _member ), value ( _value ) 65 { 66 } 41 MemberInit::MemberInit( Expression *_value, std::string _member ) : member ( _member ), value ( _value ) {} 67 42 68 MemberInit::~MemberInit() 69 { 70 } 43 MemberInit::~MemberInit() {} 71 44 72 MemberInit * MemberInit::clone() const 73 { 45 MemberInit * MemberInit::clone() const { 74 46 return new MemberInit( *this ); 75 47 } 76 48 77 void MemberInit::print( std::ostream &os, int indent ) 78 { 49 void MemberInit::print( std::ostream &os, int indent ) { 79 50 os << "Member Initializer"; 80 51 value->print( os, indent+2 ); … … 82 53 83 54 ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators ) 84 : initializers( _initializers ), designators( _designators ) 85 { 55 : initializers( _initializers ), designators( _designators ) { 86 56 } 87 57 88 ListInit::~ListInit() 89 { 90 } 58 ListInit::~ListInit() {} 91 59 92 ListInit *ListInit::clone() const 93 { 60 ListInit *ListInit::clone() const { 94 61 return new ListInit( *this ); 95 62 } 96 63 97 void ListInit::print( std::ostream &os, int indent ) 98 { 64 void ListInit::print( std::ostream &os, int indent ) { 99 65 os << std::endl << std::string(indent, ' ') << "Compound initializer: "; 100 if ( ! designators.empty() ) {66 if ( ! designators.empty() ) { 101 67 os << std::string(indent + 2, ' ' ) << "designated by: ["; 102 68 for ( std::list < Expression * >::iterator i = designators.begin(); -
translator/SynTree/Initializer.h
r3848e0e rd9a0e76 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Initializer.h,v 1.14 2005/08/29 20:59:25 rcbilson Exp $5 *6 */7 8 1 #ifndef INITIALIZER_H 9 2 #define INITIALIZER_H … … 17 10 18 11 // Initializer: base class for object initializers (provide default values) 19 class Initializer 20 { 21 public: 12 class Initializer { 13 public: 22 14 // Initializer( std::string _name = std::string(""), int _pos = 0 ); 23 15 Initializer( ); … … 41 33 virtual Initializer *acceptMutator( Mutator &m ) = 0; 42 34 virtual void print( std::ostream &os, int indent = 0 ); 43 44 private: 35 private: 45 36 // std::string name; 46 37 // int pos; … … 48 39 49 40 // SingleInit represents an initializer for a common object (e.g., int x = 4) 50 class SingleInit : public Initializer 51 { 52 public: 41 class SingleInit : public Initializer { 42 public: 53 43 SingleInit( Expression *value, std::list< Expression *> &designators ); 54 44 SingleInit( const SingleInit &other ); … … 65 55 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 66 56 virtual void print( std::ostream &os, int indent = 0 ); 67 68 private: 57 private: 69 58 //Constant *value; 70 59 Expression *value; // has to be a compile-time constant … … 72 61 }; 73 62 74 // MemberInit represents an initializer for a member of an aggregate object 75 // (e.g., struct q { int a } x = { a: 4 } ) 76 class MemberInit : public Initializer 77 { 78 public: 63 // MemberInit represents an initializer for a member of an aggregate object (e.g., struct q { int a; } x = { a : 4 } ) 64 class MemberInit : public Initializer { 65 public: 79 66 MemberInit( Expression *value, std::string member = std::string("") ); 80 67 virtual ~MemberInit(); … … 89 76 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 90 77 virtual void print( std::ostream &os, int indent = 0 ); 91 92 private: 78 private: 93 79 std::string member; 94 80 Expression *value; 95 81 }; 96 82 97 // ElementInit represents an initializer of an element of an array 98 // (e.g., [10] int x = { [7]: 4 } 99 class ElementInit : public Initializer 100 { 101 public: 83 // ElementInit represents an initializer of an element of an array (e.g., [10] int x = { [7] : 4 } 84 class ElementInit : public Initializer { 85 public: 102 86 ElementInit( Expression *value ); 103 87 virtual ~ElementInit(); … … 112 96 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 113 97 virtual void print( std::ostream &os, int indent = 0 ); 114 115 private: 98 private: 116 99 int index; 117 100 Expression *value; 118 101 }; 119 102 120 // ListInit represents an initializer that is composed recursively of a list of initializers; this 121 // is used to initialize an array or aggregate 122 class ListInit : public Initializer 123 { 124 public: 103 // ListInit represents an initializer that is composed recursively of a list of initializers; this is used to initialize 104 // an array or aggregate 105 class ListInit : public Initializer { 106 public: 125 107 ListInit( std::list<Initializer*> &, 126 std::list<Expression *> &designators = *(new std::list<Expression *>()) );108 std::list<Expression *> &designators = *(new std::list<Expression *>()) ); 127 109 virtual ~ListInit(); 128 110 … … 139 121 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 140 122 virtual void print( std::ostream &os, int indent = 0 ); 141 142 private: 123 private: 143 124 std::list<Initializer*> initializers; // order *is* important 144 125 std::list<Expression *> designators; 145 126 }; 146 127 147 148 #endif /* #ifndef INITIALIZER_H */ 149 150 /* 151 Local Variables: 152 mode: c++ 153 End: 154 */ 128 #endif // INITIALIZER_H -
translator/SynTree/Mutator.cc
r3848e0e rd9a0e76 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Mutator.cc,v 1.30 2005/08/29 20:59:25 rcbilson Exp $5 *6 */7 8 1 #include <cassert> 9 2 #include "Mutator.h" … … 16 9 #include "utility.h" 17 10 18 Mutator::Mutator() 19 { 20 } 21 22 Mutator::~Mutator() 23 { 24 } 25 26 ObjectDecl* 27 Mutator::mutate(ObjectDecl *objectDecl) 28 { 11 Mutator::Mutator() {} 12 13 Mutator::~Mutator() {} 14 15 ObjectDecl *Mutator::mutate( ObjectDecl *objectDecl ) { 29 16 objectDecl->set_type( maybeMutate( objectDecl->get_type(), *this ) ); 30 17 objectDecl->set_init( maybeMutate( objectDecl->get_init(), *this ) ); … … 33 20 } 34 21 35 DeclarationWithType* 36 Mutator::mutate(FunctionDecl *functionDecl) 37 { 22 DeclarationWithType *Mutator::mutate( FunctionDecl *functionDecl ) { 38 23 functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) ); 39 24 mutateAll( functionDecl->get_oldDecls(), *this ); … … 42 27 } 43 28 44 Declaration* 45 Mutator::handleAggregateDecl(AggregateDecl *aggregateDecl) 46 { 29 Declaration *Mutator::handleAggregateDecl( AggregateDecl *aggregateDecl ) { 47 30 mutateAll( aggregateDecl->get_parameters(), *this ); 48 31 mutateAll( aggregateDecl->get_members(), *this ); … … 50 33 } 51 34 52 Declaration* 53 Mutator::mutate(StructDecl *aggregateDecl) 54 { 35 Declaration *Mutator::mutate( StructDecl *aggregateDecl ) { 55 36 handleAggregateDecl( aggregateDecl ); 56 37 return aggregateDecl; 57 38 } 58 39 59 Declaration* 60 Mutator::mutate(UnionDecl *aggregateDecl) 61 { 40 Declaration *Mutator::mutate( UnionDecl *aggregateDecl ) { 62 41 handleAggregateDecl( aggregateDecl ); 63 42 return aggregateDecl; 64 43 } 65 44 66 Declaration* 67 Mutator::mutate(EnumDecl *aggregateDecl) 68 { 45 Declaration *Mutator::mutate( EnumDecl *aggregateDecl ) { 69 46 handleAggregateDecl( aggregateDecl ); 70 47 return aggregateDecl; 71 48 } 72 49 73 Declaration* 74 Mutator::mutate(ContextDecl *aggregateDecl) 75 { 50 Declaration *Mutator::mutate( ContextDecl *aggregateDecl ) { 76 51 handleAggregateDecl( aggregateDecl ); 77 52 return aggregateDecl; 78 53 } 79 54 80 Declaration* 81 Mutator::handleNamedTypeDecl(NamedTypeDecl *typeDecl) 82 { 55 Declaration *Mutator::handleNamedTypeDecl( NamedTypeDecl *typeDecl ) { 83 56 mutateAll( typeDecl->get_parameters(), *this ); 84 57 mutateAll( typeDecl->get_assertions(), *this ); … … 87 60 } 88 61 89 TypeDecl* 90 Mutator::mutate(TypeDecl *typeDecl) 91 { 62 TypeDecl *Mutator::mutate( TypeDecl *typeDecl ) { 92 63 handleNamedTypeDecl( typeDecl ); 93 64 return typeDecl; 94 65 } 95 66 96 Declaration* 97 Mutator::mutate(TypedefDecl *typeDecl) 98 { 67 Declaration *Mutator::mutate( TypedefDecl *typeDecl ) { 99 68 handleNamedTypeDecl( typeDecl ); 100 69 return typeDecl; 101 70 } 102 71 103 CompoundStmt* 104 Mutator::mutate(CompoundStmt *compoundStmt) 105 { 72 CompoundStmt *Mutator::mutate( CompoundStmt *compoundStmt ) { 106 73 mutateAll( compoundStmt->get_kids(), *this ); 107 74 return compoundStmt; 108 75 } 109 76 110 Statement* 111 Mutator::mutate(ExprStmt *exprStmt) 112 { 77 Statement *Mutator::mutate( ExprStmt *exprStmt ) { 113 78 exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) ); 114 79 return exprStmt; 115 80 } 116 81 117 Statement* 118 Mutator::mutate(IfStmt *ifStmt) 119 { 120 ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) ); 121 ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) ); 122 ifStmt->set_elsePart( maybeMutate( ifStmt->get_elsePart(), *this ) ); 82 Statement *Mutator::mutate( IfStmt *ifStmt ) { 83 ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) ); 84 ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) ); 85 ifStmt->set_elsePart( maybeMutate( ifStmt->get_elsePart(), *this ) ); 123 86 return ifStmt; 124 87 } 125 88 126 Statement* 127 Mutator::mutate(WhileStmt *whileStmt) 128 { 129 whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) ); 130 whileStmt->set_body( maybeMutate( whileStmt->get_body(), *this ) ); 89 Statement *Mutator::mutate( WhileStmt *whileStmt ) { 90 whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) ); 91 whileStmt->set_body( maybeMutate( whileStmt->get_body(), *this ) ); 131 92 return whileStmt; 132 93 } 133 94 134 Statement* 135 Mutator::mutate(ForStmt *forStmt) 136 { 137 forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ) ); 138 forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) ); 139 forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) ); 140 forStmt->set_body( maybeMutate( forStmt->get_body(), *this ) ); 95 Statement *Mutator::mutate( ForStmt *forStmt ) { 96 forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ) ); 97 forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) ); 98 forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) ); 99 forStmt->set_body( maybeMutate( forStmt->get_body(), *this ) ); 141 100 return forStmt; 142 101 } 143 102 144 Statement* 145 Mutator::mutate(SwitchStmt *switchStmt) 146 { 103 Statement *Mutator::mutate( SwitchStmt *switchStmt ) { 147 104 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); 148 105 mutateAll( switchStmt->get_branches(), *this ); … … 150 107 } 151 108 152 Statement* 153 Mutator::mutate(ChooseStmt *switchStmt) 154 { 155 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); 109 Statement *Mutator::mutate( ChooseStmt *switchStmt ) { 110 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); 156 111 mutateAll( switchStmt->get_branches(), *this ); 157 112 return switchStmt; 158 113 } 159 114 160 Statement* 161 Mutator::mutate(FallthruStmt *fallthruStmt) 162 { 115 Statement *Mutator::mutate( FallthruStmt *fallthruStmt ) { 163 116 return fallthruStmt; 164 117 } 165 118 166 Statement* 167 Mutator::mutate(CaseStmt *caseStmt) 168 { 169 caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) ); 119 Statement *Mutator::mutate( CaseStmt *caseStmt ) { 120 caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) ); 170 121 mutateAll (caseStmt->get_statements(), *this ); 171 122 … … 173 124 } 174 125 175 Statement* 176 Mutator::mutate(BranchStmt *branchStmt) 177 { 126 Statement *Mutator::mutate( BranchStmt *branchStmt ) { 178 127 return branchStmt; 179 128 } 180 129 181 Statement* 182 Mutator::mutate(ReturnStmt *returnStmt) 183 { 184 returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) ); 130 Statement *Mutator::mutate( ReturnStmt *returnStmt ) { 131 returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) ); 185 132 return returnStmt; 186 133 } 187 134 188 Statement* 189 Mutator::mutate(TryStmt *tryStmt) 190 { 135 Statement *Mutator::mutate( TryStmt *tryStmt ) { 191 136 tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) ); 192 137 mutateAll( tryStmt->get_catchers(), *this ); … … 194 139 } 195 140 196 Statement* 197 Mutator::mutate(CatchStmt *catchStmt) 198 { 141 Statement *Mutator::mutate( CatchStmt *catchStmt ) { 199 142 catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) ); 200 143 catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) ); … … 202 145 } 203 146 204 Statement* 205 Mutator::mutate(FinallyStmt *finalStmt) 206 { 147 Statement *Mutator::mutate( FinallyStmt *finalStmt ) { 207 148 finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) ); 208 149 return finalStmt; 209 150 } 210 151 211 NullStmt* 212 Mutator::mutate(NullStmt *nullStmt) 213 { 152 NullStmt *Mutator::mutate( NullStmt *nullStmt ) { 214 153 return nullStmt; 215 154 } 216 155 217 Statement* 218 Mutator::mutate(DeclStmt *declStmt) 219 { 156 Statement *Mutator::mutate( DeclStmt *declStmt ) { 220 157 declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) ); 221 158 return declStmt; 222 159 } 223 160 224 Expression* 225 Mutator::mutate(ApplicationExpr *applicationExpr) 226 { 161 Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) { 227 162 mutateAll( applicationExpr->get_results(), *this ); 228 applicationExpr->set_function( 163 applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) ); 229 164 mutateAll( applicationExpr->get_args(), *this ); 230 165 return applicationExpr; 231 166 } 232 167 233 Expression* 234 Mutator::mutate(UntypedExpr *untypedExpr) 235 { 168 Expression *Mutator::mutate( UntypedExpr *untypedExpr ) { 236 169 mutateAll( untypedExpr->get_results(), *this ); 237 170 mutateAll( untypedExpr->get_args(), *this ); … … 239 172 } 240 173 241 Expression* 242 Mutator::mutate(NameExpr *nameExpr) 243 { 174 Expression *Mutator::mutate( NameExpr *nameExpr ) { 244 175 mutateAll( nameExpr->get_results(), *this ); 245 176 return nameExpr; 246 177 } 247 178 248 Expression* 249 Mutator::mutate(AddressExpr *addressExpr) 250 { 179 Expression *Mutator::mutate( AddressExpr *addressExpr ) { 251 180 mutateAll( addressExpr->get_results(), *this ); 252 addressExpr->set_arg( 181 addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) ); 253 182 return addressExpr; 254 183 } 255 184 256 Expression* 257 Mutator::mutate(LabelAddressExpr *labelAddressExpr) 258 { 185 Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) { 259 186 mutateAll( labelAddressExpr->get_results(), *this ); 260 labelAddressExpr->set_arg( 187 labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) ); 261 188 return labelAddressExpr; 262 189 } 263 190 264 Expression* 265 Mutator::mutate(CastExpr *castExpr) 266 { 191 Expression *Mutator::mutate( CastExpr *castExpr ) { 267 192 mutateAll( castExpr->get_results(), *this ); 268 castExpr->set_arg( 193 castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) ); 269 194 return castExpr; 270 195 } 271 196 272 Expression* 273 Mutator::mutate(UntypedMemberExpr *memberExpr) 274 { 197 Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) { 275 198 mutateAll( memberExpr->get_results(), *this ); 276 memberExpr->set_aggregate( 199 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); 277 200 return memberExpr; 278 201 } 279 202 280 Expression* 281 Mutator::mutate(MemberExpr *memberExpr) 282 { 203 Expression *Mutator::mutate( MemberExpr *memberExpr ) { 283 204 mutateAll( memberExpr->get_results(), *this ); 284 memberExpr->set_aggregate( 205 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); 285 206 return memberExpr; 286 207 } 287 208 288 Expression* 289 Mutator::mutate(VariableExpr *variableExpr) 290 { 209 Expression *Mutator::mutate( VariableExpr *variableExpr ) { 291 210 mutateAll( variableExpr->get_results(), *this ); 292 211 return variableExpr; 293 212 } 294 213 295 Expression* 296 Mutator::mutate(ConstantExpr *constantExpr) 297 { 214 Expression *Mutator::mutate( ConstantExpr *constantExpr ) { 298 215 mutateAll( constantExpr->get_results(), *this ); 299 216 // maybeMutate( constantExpr->get_constant(), *this ) … … 301 218 } 302 219 303 Expression* 304 Mutator::mutate(SizeofExpr *sizeofExpr) 305 { 220 Expression *Mutator::mutate( SizeofExpr *sizeofExpr ) { 306 221 mutateAll( sizeofExpr->get_results(), *this ); 307 if ( sizeofExpr->get_isType() ) {308 sizeofExpr->set_type( 222 if ( sizeofExpr->get_isType() ) { 223 sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) ); 309 224 } else { 310 sizeofExpr->set_expr( 225 sizeofExpr->set_expr( maybeMutate( sizeofExpr->get_expr(), *this ) ); 311 226 } 312 227 return sizeofExpr; 313 228 } 314 229 315 Expression* 316 Mutator::mutate(AttrExpr *attrExpr) 317 { 230 Expression *Mutator::mutate( AttrExpr *attrExpr ) { 318 231 mutateAll( attrExpr->get_results(), *this ); 319 if ( attrExpr->get_isType() ) {320 attrExpr->set_type( 232 if ( attrExpr->get_isType() ) { 233 attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) ); 321 234 } else { 322 attrExpr->set_expr( 235 attrExpr->set_expr( maybeMutate( attrExpr->get_expr(), *this ) ); 323 236 } 324 237 return attrExpr; 325 238 } 326 239 327 Expression* 328 Mutator::mutate(LogicalExpr *logicalExpr) 329 { 240 Expression *Mutator::mutate( LogicalExpr *logicalExpr ) { 330 241 mutateAll( logicalExpr->get_results(), *this ); 331 logicalExpr->set_arg1( 332 logicalExpr->set_arg2( 242 logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) ); 243 logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) ); 333 244 return logicalExpr; 334 245 } 335 246 336 Expression* 337 Mutator::mutate(ConditionalExpr *conditionalExpr) 338 { 247 Expression *Mutator::mutate( ConditionalExpr *conditionalExpr ) { 339 248 mutateAll( conditionalExpr->get_results(), *this ); 340 conditionalExpr->set_arg1( 341 conditionalExpr->set_arg2( 342 conditionalExpr->set_arg3( 249 conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) ); 250 conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) ); 251 conditionalExpr->set_arg3( maybeMutate( conditionalExpr->get_arg3(), *this ) ); 343 252 return conditionalExpr; 344 253 } 345 254 346 Expression* 347 Mutator::mutate(CommaExpr *commaExpr) 348 { 255 Expression *Mutator::mutate( CommaExpr *commaExpr ) { 349 256 mutateAll( commaExpr->get_results(), *this ); 350 commaExpr->set_arg1( 351 commaExpr->set_arg2( 257 commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) ); 258 commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) ); 352 259 return commaExpr; 353 260 } 354 261 355 Expression* 356 Mutator::mutate(TupleExpr *tupleExpr) 357 { 262 Expression *Mutator::mutate( TupleExpr *tupleExpr ) { 358 263 mutateAll( tupleExpr->get_results(), *this ); 359 264 mutateAll( tupleExpr->get_exprs(), *this ); … … 361 266 } 362 267 363 Expression* 364 Mutator::mutate(SolvedTupleExpr *tupleExpr) 365 { 268 Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) { 366 269 mutateAll( tupleExpr->get_results(), *this ); 367 270 mutateAll( tupleExpr->get_exprs(), *this ); … … 369 272 } 370 273 371 Expression* 372 Mutator::mutate(TypeExpr *typeExpr) 373 { 274 Expression *Mutator::mutate( TypeExpr *typeExpr ) { 374 275 mutateAll( typeExpr->get_results(), *this ); 375 276 typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) ); … … 377 278 } 378 279 379 Expression* 380 Mutator::mutate(UntypedValofExpr *valofExpr) 381 { 280 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) { 382 281 mutateAll( valofExpr->get_results(), *this ); 383 282 return valofExpr; 384 283 } 385 284 386 Type* 387 Mutator::mutate(VoidType *voidType) 388 { 285 Type *Mutator::mutate( VoidType *voidType ) { 389 286 mutateAll( voidType->get_forall(), *this ); 390 287 return voidType; 391 288 } 392 289 393 Type* 394 Mutator::mutate(BasicType *basicType) 395 { 290 Type *Mutator::mutate( BasicType *basicType ) { 396 291 mutateAll( basicType->get_forall(), *this ); 397 292 return basicType; 398 293 } 399 294 400 Type* 401 Mutator::mutate(PointerType *pointerType) 402 { 295 Type *Mutator::mutate( PointerType *pointerType ) { 403 296 mutateAll( pointerType->get_forall(), *this ); 404 297 pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) ); … … 406 299 } 407 300 408 Type* 409 Mutator::mutate(ArrayType *arrayType) 410 { 301 Type *Mutator::mutate( ArrayType *arrayType ) { 411 302 mutateAll( arrayType->get_forall(), *this ); 412 303 arrayType->set_dimension( maybeMutate( arrayType->get_dimension(), *this ) ); … … 415 306 } 416 307 417 Type* 418 Mutator::mutate(FunctionType *functionType) 419 { 308 Type *Mutator::mutate( FunctionType *functionType ) { 420 309 mutateAll( functionType->get_forall(), *this ); 421 310 mutateAll( functionType->get_returnVals(), *this ); … … 424 313 } 425 314 426 Type* 427 Mutator::handleReferenceToType(ReferenceToType *aggregateUseType) 428 { 315 Type *Mutator::handleReferenceToType( ReferenceToType *aggregateUseType ) { 429 316 mutateAll( aggregateUseType->get_forall(), *this ); 430 317 mutateAll( aggregateUseType->get_parameters(), *this ); … … 432 319 } 433 320 434 Type* 435 Mutator::mutate(StructInstType *aggregateUseType) 436 { 437 handleReferenceToType( aggregateUseType ); 438 return aggregateUseType; 439 } 440 441 Type* 442 Mutator::mutate(UnionInstType *aggregateUseType) 443 { 444 handleReferenceToType( aggregateUseType ); 445 return aggregateUseType; 446 } 447 448 Type* 449 Mutator::mutate(EnumInstType *aggregateUseType) 450 { 451 handleReferenceToType( aggregateUseType ); 452 return aggregateUseType; 453 } 454 455 Type* 456 Mutator::mutate(ContextInstType *aggregateUseType) 457 { 321 Type *Mutator::mutate( StructInstType *aggregateUseType ) { 322 handleReferenceToType( aggregateUseType ); 323 return aggregateUseType; 324 } 325 326 Type *Mutator::mutate( UnionInstType *aggregateUseType ) { 327 handleReferenceToType( aggregateUseType ); 328 return aggregateUseType; 329 } 330 331 Type *Mutator::mutate( EnumInstType *aggregateUseType ) { 332 handleReferenceToType( aggregateUseType ); 333 return aggregateUseType; 334 } 335 336 Type *Mutator::mutate( ContextInstType *aggregateUseType ) { 458 337 handleReferenceToType( aggregateUseType ); 459 338 mutateAll( aggregateUseType->get_members(), *this ); … … 461 340 } 462 341 463 Type* 464 Mutator::mutate(TypeInstType *aggregateUseType) 465 { 466 handleReferenceToType( aggregateUseType ); 467 return aggregateUseType; 468 } 469 470 Type* 471 Mutator::mutate(TupleType *tupleType) 472 { 342 Type *Mutator::mutate( TypeInstType *aggregateUseType ) { 343 handleReferenceToType( aggregateUseType ); 344 return aggregateUseType; 345 } 346 347 Type *Mutator::mutate( TupleType *tupleType ) { 473 348 mutateAll( tupleType->get_forall(), *this ); 474 349 mutateAll( tupleType->get_types(), *this ); … … 476 351 } 477 352 478 Type* 479 Mutator::mutate(TypeofType *typeofType) 480 { 353 Type *Mutator::mutate( TypeofType *typeofType ) { 481 354 assert( typeofType->get_expr() ); 482 355 typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) ); … … 484 357 } 485 358 486 Type* 487 Mutator::mutate(AttrType *attrType) 488 { 489 if( attrType->get_isType() ) { 359 Type *Mutator::mutate( AttrType *attrType ) { 360 if ( attrType->get_isType() ) { 490 361 assert( attrType->get_type() ); 491 362 attrType->set_type( attrType->get_type()->acceptMutator( *this ) ); … … 497 368 } 498 369 499 Initializer* 500 Mutator::mutate(MemberInit *memberInit) 501 { 370 Initializer *Mutator::mutate( MemberInit *memberInit ) { 502 371 memberInit->set_value( memberInit->get_value()->acceptMutator( *this ) ); 503 372 return memberInit; 504 373 } 505 374 506 Initializer* 507 Mutator::mutate(ElementInit *elementInit) 508 { 375 Initializer *Mutator::mutate( ElementInit *elementInit ) { 509 376 elementInit->set_value( elementInit->get_value()->acceptMutator( *this ) ); 510 377 return elementInit; 511 378 } 512 379 513 Initializer* 514 Mutator::mutate(SingleInit *singleInit) 515 { 380 Initializer *Mutator::mutate( SingleInit *singleInit ) { 516 381 singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) ); 517 382 return singleInit; 518 383 } 519 384 520 Initializer* 521 Mutator::mutate(ListInit *listInit) 522 { 385 Initializer *Mutator::mutate( ListInit *listInit ) { 523 386 mutateAll( listInit->get_designators(), *this ); 524 387 mutateAll( listInit->get_initializers(), *this ); … … 526 389 } 527 390 528 Subrange * 529 Mutator::mutate(Subrange *subrange) 530 { 391 Subrange *Mutator::mutate( Subrange *subrange ) { 531 392 return subrange; 532 393 } 533 394 534 Constant * 535 Mutator::mutate(Constant *constant) 536 { 395 Constant *Mutator::mutate( Constant *constant ) { 537 396 return constant; 538 397 } 539 -
translator/SynTree/Mutator.h
r3848e0e rd9a0e76 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Mutator.h,v 1.19 2005/08/29 20:59:25 rcbilson Exp $5 *6 */7 8 1 #include <cassert> 9 2 … … 14 7 #define SYNTREE_MUTATOR_H 15 8 16 17 class Mutator 18 { 19 protected: 9 class Mutator { 10 protected: 20 11 Mutator(); 21 12 virtual ~Mutator(); 13 public: 14 virtual ObjectDecl* mutate( ObjectDecl *objectDecl ); 15 virtual DeclarationWithType* mutate( FunctionDecl *functionDecl ); 16 virtual Declaration* mutate( StructDecl *aggregateDecl ); 17 virtual Declaration* mutate( UnionDecl *aggregateDecl ); 18 virtual Declaration* mutate( EnumDecl *aggregateDecl ); 19 virtual Declaration* mutate( ContextDecl *aggregateDecl ); 20 virtual TypeDecl* mutate( TypeDecl *typeDecl ); 21 virtual Declaration* mutate( TypedefDecl *typeDecl ); 22 22 23 public: 24 virtual ObjectDecl* mutate(ObjectDecl *objectDecl); 25 virtual DeclarationWithType* mutate(FunctionDecl *functionDecl); 26 virtual Declaration* mutate(StructDecl *aggregateDecl); 27 virtual Declaration* mutate(UnionDecl *aggregateDecl); 28 virtual Declaration* mutate(EnumDecl *aggregateDecl); 29 virtual Declaration* mutate(ContextDecl *aggregateDecl); 30 virtual TypeDecl* mutate(TypeDecl *typeDecl); 31 virtual Declaration* mutate(TypedefDecl *typeDecl); 23 virtual CompoundStmt* mutate( CompoundStmt *compoundStmt ); 24 virtual Statement* mutate( ExprStmt *exprStmt ); 25 virtual Statement* mutate( IfStmt *ifStmt ); 26 virtual Statement* mutate( WhileStmt *whileStmt ); 27 virtual Statement* mutate( ForStmt *forStmt ); 28 virtual Statement* mutate( SwitchStmt *switchStmt ); 29 virtual Statement* mutate( ChooseStmt *chooseStmt ); 30 virtual Statement* mutate( FallthruStmt *fallthruStmt ); 31 virtual Statement* mutate( CaseStmt *caseStmt ); 32 virtual Statement* mutate( BranchStmt *branchStmt ); 33 virtual Statement* mutate( ReturnStmt *returnStmt ); 34 virtual Statement* mutate( TryStmt *returnStmt ); 35 virtual Statement* mutate( CatchStmt *catchStmt ); 36 virtual Statement* mutate( FinallyStmt *catchStmt ); 37 virtual NullStmt* mutate( NullStmt *nullStmt ); 38 virtual Statement* mutate( DeclStmt *declStmt ); 32 39 33 virtual CompoundStmt* mutate(CompoundStmt *compoundStmt); 34 virtual Statement* mutate(ExprStmt *exprStmt); 35 virtual Statement* mutate(IfStmt *ifStmt); 36 virtual Statement* mutate(WhileStmt *whileStmt); 37 virtual Statement* mutate(ForStmt *forStmt); 38 virtual Statement* mutate(SwitchStmt *switchStmt); 39 virtual Statement* mutate(ChooseStmt *chooseStmt); 40 virtual Statement* mutate(FallthruStmt *fallthruStmt); 41 virtual Statement* mutate(CaseStmt *caseStmt); 42 virtual Statement* mutate(BranchStmt *branchStmt); 43 virtual Statement* mutate(ReturnStmt *returnStmt); 44 virtual Statement* mutate(TryStmt *returnStmt); 45 virtual Statement* mutate(CatchStmt *catchStmt); 46 virtual Statement* mutate(FinallyStmt *catchStmt); 47 virtual NullStmt* mutate(NullStmt *nullStmt); 48 virtual Statement* mutate(DeclStmt *declStmt); 40 virtual Expression* mutate( ApplicationExpr *applicationExpr ); 41 virtual Expression* mutate( UntypedExpr *untypedExpr ); 42 virtual Expression* mutate( NameExpr *nameExpr ); 43 virtual Expression* mutate( AddressExpr *castExpr ); 44 virtual Expression* mutate( LabelAddressExpr *labAddressExpr ); 45 virtual Expression* mutate( CastExpr *castExpr ); 46 virtual Expression* mutate( UntypedMemberExpr *memberExpr ); 47 virtual Expression* mutate( MemberExpr *memberExpr ); 48 virtual Expression* mutate( VariableExpr *variableExpr ); 49 virtual Expression* mutate( ConstantExpr *constantExpr ); 50 virtual Expression* mutate( SizeofExpr *sizeofExpr ); 51 virtual Expression* mutate( AttrExpr *attrExpr ); 52 virtual Expression* mutate( LogicalExpr *logicalExpr ); 53 virtual Expression* mutate( ConditionalExpr *conditionalExpr ); 54 virtual Expression* mutate( CommaExpr *commaExpr ); 55 virtual Expression* mutate( TupleExpr *tupleExpr ); 56 virtual Expression* mutate( SolvedTupleExpr *tupleExpr ); 57 virtual Expression* mutate( TypeExpr *typeExpr ); 58 virtual Expression* mutate( UntypedValofExpr *valofExpr ); 49 59 50 virtual Expression* mutate(ApplicationExpr *applicationExpr); 51 virtual Expression* mutate(UntypedExpr *untypedExpr); 52 virtual Expression* mutate(NameExpr *nameExpr); 53 virtual Expression* mutate(AddressExpr *castExpr); 54 virtual Expression* mutate(LabelAddressExpr *labAddressExpr); 55 virtual Expression* mutate(CastExpr *castExpr); 56 virtual Expression* mutate(UntypedMemberExpr *memberExpr); 57 virtual Expression* mutate(MemberExpr *memberExpr); 58 virtual Expression* mutate(VariableExpr *variableExpr); 59 virtual Expression* mutate(ConstantExpr *constantExpr); 60 virtual Expression* mutate(SizeofExpr *sizeofExpr); 61 virtual Expression* mutate(AttrExpr *attrExpr); 62 virtual Expression* mutate(LogicalExpr *logicalExpr); 63 virtual Expression* mutate(ConditionalExpr *conditionalExpr); 64 virtual Expression* mutate(CommaExpr *commaExpr); 65 virtual Expression* mutate(TupleExpr *tupleExpr); 66 virtual Expression* mutate(SolvedTupleExpr *tupleExpr); 67 virtual Expression* mutate(TypeExpr *typeExpr); 68 virtual Expression* mutate(UntypedValofExpr *valofExpr); 60 virtual Type* mutate( VoidType *basicType ); 61 virtual Type* mutate( BasicType *basicType ); 62 virtual Type* mutate( PointerType *pointerType ); 63 virtual Type* mutate( ArrayType *arrayType ); 64 virtual Type* mutate( FunctionType *functionType ); 65 virtual Type* mutate( StructInstType *aggregateUseType ); 66 virtual Type* mutate( UnionInstType *aggregateUseType ); 67 virtual Type* mutate( EnumInstType *aggregateUseType ); 68 virtual Type* mutate( ContextInstType *aggregateUseType ); 69 virtual Type* mutate( TypeInstType *aggregateUseType ); 70 virtual Type* mutate( TupleType *tupleType ); 71 virtual Type* mutate( TypeofType *typeofType ); 72 virtual Type* mutate( AttrType *attrType ); 69 73 70 virtual Type* mutate(VoidType *basicType); 71 virtual Type* mutate(BasicType *basicType); 72 virtual Type* mutate(PointerType *pointerType); 73 virtual Type* mutate(ArrayType *arrayType); 74 virtual Type* mutate(FunctionType *functionType); 75 virtual Type* mutate(StructInstType *aggregateUseType); 76 virtual Type* mutate(UnionInstType *aggregateUseType); 77 virtual Type* mutate(EnumInstType *aggregateUseType); 78 virtual Type* mutate(ContextInstType *aggregateUseType); 79 virtual Type* mutate(TypeInstType *aggregateUseType); 80 virtual Type* mutate(TupleType *tupleType); 81 virtual Type* mutate(TypeofType *typeofType); 82 virtual Type* mutate(AttrType *attrType); 74 virtual Initializer* mutate( MemberInit *memberInit ); 75 virtual Initializer* mutate( ElementInit *elementInit ); 76 virtual Initializer* mutate( SingleInit *singleInit ); 77 virtual Initializer* mutate( ListInit *listInit ); 83 78 84 virtual Initializer* mutate(MemberInit *memberInit); 85 virtual Initializer* mutate(ElementInit *elementInit); 86 virtual Initializer* mutate(SingleInit *singleInit); 87 virtual Initializer* mutate(ListInit *listInit); 79 virtual Subrange *mutate( Subrange *subrange ); 88 80 89 virtual Subrange *mutate(Subrange *subrange); 90 91 virtual Constant *mutate(Constant *constant); 92 93 private: 94 virtual Declaration* handleAggregateDecl(AggregateDecl *aggregateDecl); 95 virtual Declaration* handleNamedTypeDecl(NamedTypeDecl *typeDecl); 96 virtual Type* handleReferenceToType(ReferenceToType *aggregateUseType); 81 virtual Constant *mutate( Constant *constant ); 82 private: 83 virtual Declaration* handleAggregateDecl(AggregateDecl *aggregateDecl ); 84 virtual Declaration* handleNamedTypeDecl(NamedTypeDecl *typeDecl ); 85 virtual Type* handleReferenceToType(ReferenceToType *aggregateUseType ); 97 86 }; 98 87 99 88 template< typename TreeType, typename MutatorType > 100 inline TreeType * 101 maybeMutate( TreeType *tree, MutatorType &mutator ) 102 { 103 if( tree ) { 89 inline TreeType *maybeMutate( TreeType *tree, MutatorType &mutator ) { 90 if ( tree ) { 104 91 TreeType *newnode = dynamic_cast< TreeType* >( tree->acceptMutator( mutator ) ); 105 92 assert( newnode ); … … 112 99 113 100 template< typename Container, typename MutatorType > 114 inline void 115 mutateAll( Container &container, MutatorType &mutator ) 116 { 101 inline void mutateAll( Container &container, MutatorType &mutator ) { 117 102 SemanticError errors; 118 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {103 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 119 104 try { 120 if ( *i ) {105 if ( *i ) { 121 106 /// *i = (*i)->acceptMutator( mutator ); 122 107 *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) ); … … 127 112 } 128 113 } 129 if ( !errors.isEmpty() ) {114 if ( !errors.isEmpty() ) { 130 115 throw errors; 131 116 } 132 117 } 133 118 134 135 136 #endif /* #ifndef SYNTREE_MUTATOR_H */ 119 #endif // SYNTREE_MUTATOR_H 137 120 138 121 // Local Variables: // -
translator/SynTree/ObjectDecl.cc
r3848e0e rd9a0e76 1 /*2 * This file is part of the Cforall project3 *4 * $Id: ObjectDecl.cc,v 1.8 2005/08/29 20:59:25 rcbilson Exp $5 *6 */7 8 1 #include "Declaration.h" 9 2 #include "Type.h" … … 14 7 15 8 ObjectDecl::ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init ) 16 : Parent( name, sc, linkage ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) 17 { 9 : Parent( name, sc, linkage ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) { 18 10 } 19 11 20 12 ObjectDecl::ObjectDecl( const ObjectDecl &other ) 21 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) 22 { 13 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) { 23 14 } 24 15 25 ObjectDecl::~ObjectDecl() 26 { 16 ObjectDecl::~ObjectDecl() { 27 17 delete type; 28 18 delete init; … … 30 20 } 31 21 32 void 33 ObjectDecl::print( std::ostream &os, int indent ) const 34 { 35 if( get_name() != "" ) { 22 void ObjectDecl::print( std::ostream &os, int indent ) const { 23 if ( get_name() != "" ) { 36 24 os << get_name() << ": a "; 37 25 } 38 if( get_linkage() != LinkageSpec::Cforall ) { 26 27 if ( get_linkage() != LinkageSpec::Cforall ) { 39 28 os << LinkageSpec::toString( get_linkage() ) << " "; 40 29 } 41 if( get_storageClass() != NoStorageClass ) { 30 31 if ( get_storageClass() != NoStorageClass ) { 42 32 os << storageClassName[ get_storageClass() ] << ' '; 43 33 } 44 if( get_type() ) { 34 35 if ( get_type() ) { 45 36 get_type()->print( os, indent ); 46 37 } else { 47 38 os << "untyped entity "; 48 39 } 49 if( init ) { 40 41 if ( init ) { 50 42 os << "with initializer "; 51 43 init->print( os, indent ); 52 44 } 53 if( bitfieldWidth ) { 45 46 if ( bitfieldWidth ) { 54 47 os << "with bitfield width "; 55 48 bitfieldWidth->print( os ); … … 57 50 } 58 51 59 void 60 ObjectDecl::printShort( std::ostream &os, int indent ) const 61 { 62 if( get_name() != "" ) { 52 void ObjectDecl::printShort( std::ostream &os, int indent ) const { 53 if ( get_name() != "" ) { 63 54 os << get_name() << ": a "; 64 55 } 65 if( get_storageClass() != NoStorageClass ) { 56 57 if ( get_storageClass() != NoStorageClass ) { 66 58 os << storageClassName[ get_storageClass() ] << ' '; 67 59 } 68 if( get_type() ) { 60 61 if ( get_type() ) { 69 62 get_type()->print( os, indent ); 70 63 } else { 71 64 os << "untyped entity "; 72 65 } 73 if( bitfieldWidth ) { 66 67 if ( bitfieldWidth ) { 74 68 os << "with bitfield width "; 75 69 bitfieldWidth->print( os ); 76 70 } 77 71 } 78 -
translator/SynTree/Visitor.cc
r3848e0e rd9a0e76 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Visitor.cc,v 1.30 2005/08/29 20:59:27 rcbilson Exp $5 *6 */7 8 1 #include <cassert> 9 2 #include "Visitor.h" … … 16 9 17 10 18 Visitor::Visitor() 19 { 20 } 21 22 Visitor::~Visitor() 23 { 24 } 25 26 void 27 Visitor::visit(ObjectDecl *objectDecl) 28 { 11 Visitor::Visitor() {} 12 13 Visitor::~Visitor() {} 14 15 void Visitor::visit(ObjectDecl *objectDecl) { 29 16 maybeAccept( objectDecl->get_type(), *this ); 30 17 maybeAccept( objectDecl->get_init(), *this ); … … 32 19 } 33 20 34 void 35 Visitor::visit(FunctionDecl *functionDecl) 36 { 21 void Visitor::visit(FunctionDecl *functionDecl) { 37 22 maybeAccept( functionDecl->get_functionType(), *this ); 38 23 acceptAll( functionDecl->get_oldDecls(), *this ); … … 40 25 } 41 26 42 void 43 Visitor::visit(AggregateDecl *aggregateDecl) 44 { 27 void Visitor::visit(AggregateDecl *aggregateDecl) { 45 28 acceptAll( aggregateDecl->get_parameters(), *this ); 46 29 acceptAll( aggregateDecl->get_members(), *this ); 47 30 } 48 31 49 void 50 Visitor::visit(StructDecl *aggregateDecl) 51 { 32 void Visitor::visit(StructDecl *aggregateDecl) { 52 33 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 53 34 } 54 35 55 void 56 Visitor::visit(UnionDecl *aggregateDecl) 57 { 36 void Visitor::visit(UnionDecl *aggregateDecl) { 58 37 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 59 38 } 60 39 61 void 62 Visitor::visit(EnumDecl *aggregateDecl) 63 { 40 void Visitor::visit(EnumDecl *aggregateDecl) { 64 41 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 65 42 } 66 43 67 void 68 Visitor::visit(ContextDecl *aggregateDecl) 69 { 44 void Visitor::visit(ContextDecl *aggregateDecl) { 70 45 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 71 46 } 72 47 73 void 74 Visitor::visit(NamedTypeDecl *typeDecl) 75 { 48 void Visitor::visit(NamedTypeDecl *typeDecl) { 76 49 acceptAll( typeDecl->get_parameters(), *this ); 77 50 acceptAll( typeDecl->get_assertions(), *this ); … … 79 52 } 80 53 81 void 82 Visitor::visit(TypeDecl *typeDecl) 83 { 54 void Visitor::visit(TypeDecl *typeDecl) { 84 55 visit( static_cast< NamedTypeDecl* >( typeDecl ) ); 85 56 } 86 57 87 void 88 Visitor::visit(TypedefDecl *typeDecl) 89 { 58 void Visitor::visit(TypedefDecl *typeDecl) { 90 59 visit( static_cast< NamedTypeDecl* >( typeDecl ) ); 91 60 } 92 61 93 void 94 Visitor::visit(CompoundStmt *compoundStmt) 95 { 62 void Visitor::visit(CompoundStmt *compoundStmt) { 96 63 acceptAll( compoundStmt->get_kids(), *this ); 97 64 } 98 65 99 void 100 Visitor::visit(ExprStmt *exprStmt) 101 { 66 void Visitor::visit(ExprStmt *exprStmt) { 102 67 maybeAccept( exprStmt->get_expr(), *this ); 103 68 } 104 69 105 void 106 Visitor::visit(IfStmt *ifStmt) 107 { 70 void Visitor::visit(IfStmt *ifStmt) { 108 71 maybeAccept( ifStmt->get_condition(), *this ); 109 72 maybeAccept( ifStmt->get_thenPart(), *this ); … … 111 74 } 112 75 113 void 114 Visitor::visit(WhileStmt *whileStmt) 115 { 76 void Visitor::visit(WhileStmt *whileStmt) { 116 77 maybeAccept( whileStmt->get_condition(), *this ); 117 78 maybeAccept( whileStmt->get_body(), *this ); 118 79 } 119 80 120 void 121 Visitor::visit(ForStmt *forStmt) 122 { 81 void Visitor::visit(ForStmt *forStmt) { 123 82 // ForStmt still needs to be fixed 124 83 maybeAccept( forStmt->get_initialization(), *this ); … … 128 87 } 129 88 130 void 131 Visitor::visit(SwitchStmt *switchStmt) 132 { 89 void Visitor::visit(SwitchStmt *switchStmt) { 133 90 maybeAccept( switchStmt->get_condition(), *this ); 134 91 acceptAll( switchStmt->get_branches(), *this ); 135 92 } 136 93 137 void 138 Visitor::visit(ChooseStmt *switchStmt) 139 { 94 void Visitor::visit(ChooseStmt *switchStmt) { 140 95 maybeAccept( switchStmt->get_condition(), *this ); 141 96 acceptAll( switchStmt->get_branches(), *this ); 142 97 } 143 98 144 void 145 Visitor::visit(FallthruStmt *fallthruStmt){} 146 147 void 148 Visitor::visit(CaseStmt *caseStmt) 149 { 99 void Visitor::visit(FallthruStmt *fallthruStmt){} 100 101 void Visitor::visit(CaseStmt *caseStmt) { 150 102 maybeAccept( caseStmt->get_condition(), *this ); 151 103 acceptAll( caseStmt->get_statements(), *this ); 152 104 } 153 105 154 void 155 Visitor::visit(BranchStmt *branchStmt) 156 { 157 } 158 159 void 160 Visitor::visit(ReturnStmt *returnStmt) 161 { 106 void Visitor::visit(BranchStmt *branchStmt) { 107 } 108 109 void Visitor::visit(ReturnStmt *returnStmt) { 162 110 maybeAccept( returnStmt->get_expr(), *this ); 163 111 } 164 112 165 void 166 Visitor::visit(TryStmt *tryStmt) 167 { 113 void Visitor::visit(TryStmt *tryStmt) { 168 114 maybeAccept( tryStmt->get_block(), *this ); 169 115 acceptAll( tryStmt->get_catchers(), *this ); 170 116 } 171 117 172 void 173 Visitor::visit(CatchStmt *catchStmt) 174 { 118 void Visitor::visit(CatchStmt *catchStmt) { 175 119 maybeAccept( catchStmt->get_decl(), *this ); 176 120 maybeAccept( catchStmt->get_body(), *this ); 177 121 } 178 122 179 void 180 Visitor::visit(FinallyStmt *finalStmt) 181 { 123 void Visitor::visit(FinallyStmt *finalStmt) { 182 124 maybeAccept( finalStmt->get_block(), *this ); 183 125 } 184 126 185 void 186 Visitor::visit(NullStmt *nullStmt) 187 { 188 } 189 190 void 191 Visitor::visit(DeclStmt *declStmt) 192 { 127 void Visitor::visit(NullStmt *nullStmt) { 128 } 129 130 void Visitor::visit(DeclStmt *declStmt) { 193 131 maybeAccept( declStmt->get_decl(), *this ); 194 132 } 195 133 196 void 197 Visitor::visit(ApplicationExpr *applicationExpr) 198 { 134 void Visitor::visit(ApplicationExpr *applicationExpr) { 199 135 acceptAll( applicationExpr->get_results(), *this ); 200 136 maybeAccept( applicationExpr->get_function(), *this ); … … 202 138 } 203 139 204 void 205 Visitor::visit(UntypedExpr *untypedExpr) 206 { 140 void Visitor::visit(UntypedExpr *untypedExpr) { 207 141 acceptAll( untypedExpr->get_results(), *this ); 208 142 acceptAll( untypedExpr->get_args(), *this ); 209 143 } 210 144 211 void 212 Visitor::visit(NameExpr *nameExpr) 213 { 145 void Visitor::visit(NameExpr *nameExpr) { 214 146 acceptAll( nameExpr->get_results(), *this ); 215 147 } 216 148 217 void 218 Visitor::visit(AddressExpr *addressExpr) 219 { 149 void Visitor::visit(AddressExpr *addressExpr) { 220 150 acceptAll( addressExpr->get_results(), *this ); 221 151 maybeAccept( addressExpr->get_arg(), *this ); 222 152 } 223 153 224 void 225 Visitor::visit(LabelAddressExpr *labAddressExpr) 226 { 154 void Visitor::visit(LabelAddressExpr *labAddressExpr) { 227 155 acceptAll( labAddressExpr->get_results(), *this ); 228 156 maybeAccept( labAddressExpr->get_arg(), *this ); 229 157 } 230 158 231 void 232 Visitor::visit(CastExpr *castExpr) 233 { 159 void Visitor::visit(CastExpr *castExpr) { 234 160 acceptAll( castExpr->get_results(), *this ); 235 161 maybeAccept( castExpr->get_arg(), *this ); 236 162 } 237 163 238 void 239 Visitor::visit(UntypedMemberExpr *memberExpr) 240 { 164 void Visitor::visit(UntypedMemberExpr *memberExpr) { 241 165 acceptAll( memberExpr->get_results(), *this ); 242 166 maybeAccept( memberExpr->get_aggregate(), *this ); 243 167 } 244 168 245 void 246 Visitor::visit(MemberExpr *memberExpr) 247 { 169 void Visitor::visit(MemberExpr *memberExpr) { 248 170 acceptAll( memberExpr->get_results(), *this ); 249 171 maybeAccept( memberExpr->get_aggregate(), *this ); 250 172 } 251 173 252 void 253 Visitor::visit(VariableExpr *variableExpr) 254 { 174 void Visitor::visit(VariableExpr *variableExpr) { 255 175 acceptAll( variableExpr->get_results(), *this ); 256 176 } 257 177 258 void 259 Visitor::visit(ConstantExpr *constantExpr) 260 { 178 void Visitor::visit(ConstantExpr *constantExpr) { 261 179 acceptAll( constantExpr->get_results(), *this ); 262 180 maybeAccept( constantExpr->get_constant(), *this ); 263 181 } 264 182 265 void 266 Visitor::visit(SizeofExpr *sizeofExpr) 267 { 183 void Visitor::visit(SizeofExpr *sizeofExpr) { 268 184 acceptAll( sizeofExpr->get_results(), *this ); 269 if ( sizeofExpr->get_isType() ) {185 if ( sizeofExpr->get_isType() ) { 270 186 maybeAccept( sizeofExpr->get_type(), *this ); 271 187 } else { … … 274 190 } 275 191 276 void 277 Visitor::visit(AttrExpr *attrExpr) 278 { 192 void Visitor::visit(AttrExpr *attrExpr) { 279 193 acceptAll( attrExpr->get_results(), *this ); 280 if ( attrExpr->get_isType() ) {194 if ( attrExpr->get_isType() ) { 281 195 maybeAccept( attrExpr->get_type(), *this ); 282 196 } else { … … 285 199 } 286 200 287 void 288 Visitor::visit(LogicalExpr *logicalExpr) 289 { 201 void Visitor::visit(LogicalExpr *logicalExpr) { 290 202 acceptAll( logicalExpr->get_results(), *this ); 291 203 maybeAccept( logicalExpr->get_arg1(), *this ); … … 293 205 } 294 206 295 void 296 Visitor::visit(ConditionalExpr *conditionalExpr) 297 { 207 void Visitor::visit(ConditionalExpr *conditionalExpr) { 298 208 acceptAll( conditionalExpr->get_results(), *this ); 299 209 maybeAccept( conditionalExpr->get_arg1(), *this ); … … 302 212 } 303 213 304 void 305 Visitor::visit(CommaExpr *commaExpr) 306 { 214 void Visitor::visit(CommaExpr *commaExpr) { 307 215 acceptAll( commaExpr->get_results(), *this ); 308 216 maybeAccept( commaExpr->get_arg1(), *this ); … … 310 218 } 311 219 312 void 313 Visitor::visit(TupleExpr *tupleExpr) 314 { 220 void Visitor::visit(TupleExpr *tupleExpr) { 315 221 acceptAll( tupleExpr->get_results(), *this ); 316 222 acceptAll( tupleExpr->get_exprs(), *this ); 317 223 } 318 224 319 void 320 Visitor::visit(SolvedTupleExpr *tupleExpr) 321 { 225 void Visitor::visit(SolvedTupleExpr *tupleExpr) { 322 226 acceptAll( tupleExpr->get_results(), *this ); 323 227 acceptAll( tupleExpr->get_exprs(), *this ); 324 228 } 325 229 326 void 327 Visitor::visit(TypeExpr *typeExpr) 328 { 230 void Visitor::visit(TypeExpr *typeExpr) { 329 231 acceptAll( typeExpr->get_results(), *this ); 330 232 maybeAccept( typeExpr->get_type(), *this ); 331 233 } 332 234 333 void 334 Visitor::visit(UntypedValofExpr *valofExpr) 335 { 235 void Visitor::visit(UntypedValofExpr *valofExpr) { 336 236 acceptAll( valofExpr->get_results(), *this ); 337 237 maybeAccept( valofExpr->get_body(), *this ); 338 238 } 339 239 340 void 341 Visitor::visit(VoidType *voidType) 342 { 240 void Visitor::visit(VoidType *voidType) { 343 241 acceptAll( voidType->get_forall(), *this ); 344 242 } 345 243 346 void 347 Visitor::visit(BasicType *basicType) 348 { 244 void Visitor::visit(BasicType *basicType) { 349 245 acceptAll( basicType->get_forall(), *this ); 350 246 } 351 247 352 void 353 Visitor::visit(PointerType *pointerType) 354 { 248 void Visitor::visit(PointerType *pointerType) { 355 249 acceptAll( pointerType->get_forall(), *this ); 356 250 maybeAccept( pointerType->get_base(), *this ); 357 251 } 358 252 359 void 360 Visitor::visit(ArrayType *arrayType) 361 { 253 void Visitor::visit(ArrayType *arrayType) { 362 254 acceptAll( arrayType->get_forall(), *this ); 363 255 maybeAccept( arrayType->get_dimension(), *this ); … … 365 257 } 366 258 367 void 368 Visitor::visit(FunctionType *functionType) 369 { 259 void Visitor::visit(FunctionType *functionType) { 370 260 acceptAll( functionType->get_forall(), *this ); 371 261 acceptAll( functionType->get_returnVals(), *this ); … … 373 263 } 374 264 375 void 376 Visitor::visit(ReferenceToType *aggregateUseType) 377 { 265 void Visitor::visit(ReferenceToType *aggregateUseType) { 378 266 acceptAll( aggregateUseType->get_forall(), *this ); 379 267 acceptAll( aggregateUseType->get_parameters(), *this ); 380 268 } 381 269 382 void 383 Visitor::visit(StructInstType *aggregateUseType) 384 { 385 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 386 } 387 388 void 389 Visitor::visit(UnionInstType *aggregateUseType) 390 { 391 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 392 } 393 394 void 395 Visitor::visit(EnumInstType *aggregateUseType) 396 { 397 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 398 } 399 400 void 401 Visitor::visit(ContextInstType *aggregateUseType) 402 { 270 void Visitor::visit(StructInstType *aggregateUseType) { 271 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 272 } 273 274 void Visitor::visit(UnionInstType *aggregateUseType) { 275 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 276 } 277 278 void Visitor::visit(EnumInstType *aggregateUseType) { 279 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 280 } 281 282 void Visitor::visit(ContextInstType *aggregateUseType) { 403 283 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 404 284 acceptAll( aggregateUseType->get_members(), *this ); 405 285 } 406 286 407 void 408 Visitor::visit(TypeInstType *aggregateUseType) 409 { 410 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 411 } 412 413 void 414 Visitor::visit(TupleType *tupleType) 415 { 287 void Visitor::visit(TypeInstType *aggregateUseType) { 288 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 289 } 290 291 void Visitor::visit(TupleType *tupleType) { 416 292 acceptAll( tupleType->get_forall(), *this ); 417 293 acceptAll( tupleType->get_types(), *this ); 418 294 } 419 295 420 void 421 Visitor::visit(TypeofType *typeofType) 422 { 296 void Visitor::visit(TypeofType *typeofType) { 423 297 assert( typeofType->get_expr() ); 424 298 typeofType->get_expr()->accept( *this ); 425 299 } 426 300 427 void 428 Visitor::visit(AttrType *attrType) 429 { 430 if( attrType->get_isType() ) { 301 void Visitor::visit(AttrType *attrType) { 302 if ( attrType->get_isType() ) { 431 303 assert( attrType->get_type() ); 432 304 attrType->get_type()->accept( *this ); … … 437 309 } 438 310 439 void 440 Visitor::visit(MemberInit *memberInit) 441 { 311 void Visitor::visit(MemberInit *memberInit) { 442 312 memberInit->get_value()->accept( *this ); 443 313 } 444 314 445 void 446 Visitor::visit(ElementInit *elementInit) 447 { 315 void Visitor::visit(ElementInit *elementInit) { 448 316 elementInit->get_value()->accept( *this ); 449 317 } 450 318 451 void 452 Visitor::visit(SingleInit *singleInit) 453 { 319 void Visitor::visit(SingleInit *singleInit) { 454 320 singleInit->get_value()->accept( *this ); 455 321 } 456 322 457 void 458 Visitor::visit(ListInit *listInit) 459 { 323 void Visitor::visit(ListInit *listInit) { 460 324 acceptAll( listInit->get_designators(), *this ); 461 325 acceptAll( listInit->get_initializers(), *this ); 462 326 } 463 327 464 void 465 Visitor::visit(Subrange *subrange) 466 { 467 } 468 469 void 470 Visitor::visit(Constant *constant) 471 { 472 } 473 328 void Visitor::visit(Subrange *subrange) {} 329 330 void Visitor::visit(Constant *constant) {} -
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.