Changeset 41b24c8
- Timestamp:
- May 16, 2019, 4:23:47 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- acd80b4
- Parents:
- e61207e7 (diff), c671112 (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. - Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.hfa
re61207e7 r41b24c8 49 49 50 50 forall(dtype T | is_coroutine(T)) 51 static inline voidresume(T & cor);51 static inline T & resume(T & cor); 52 52 53 53 forall(dtype T | is_coroutine(T)) -
src/AST/Convert.cpp
re61207e7 r41b24c8 135 135 decl->parent = parent; 136 136 decl->body = old->body; 137 decl->param eters = params;137 decl->params = params; 138 138 decl->members = members; 139 139 decl->extension = old->extension; … … 592 592 593 593 } 594 595 virtual void visit( AttrExpr * ) override final { 596 597 assert( 0 ); 598 } 594 599 }; 595 600 -
src/AST/Decl.hpp
re61207e7 r41b24c8 30 30 #include "Parser/ParseNode.h" // for DeclarationNode::Aggregate 31 31 32 // Must be included in *all* AST classes; should be #undef'd at the end of the file 33 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 34 32 35 namespace ast { 33 36 … … 55 58 private: 56 59 Decl * clone() const override = 0; 60 MUTATE_FRIEND 57 61 }; 58 62 … … 87 91 private: 88 92 DeclWithType * clone() const override = 0; 93 MUTATE_FRIEND 89 94 }; 90 95 … … 108 113 private: 109 114 ObjectDecl * clone() const override { return new ObjectDecl{ *this }; } 110 111 /// Must be copied in ALL derived classes 112 template<typename node_t> 113 friend node_t * mutate(const node_t * node); 115 MUTATE_FRIEND 114 116 }; 115 117 … … 135 137 private: 136 138 FunctionDecl * clone() const override { return new FunctionDecl( *this ); } 137 138 /// Must be copied in ALL derived classes 139 template<typename node_t> 140 friend node_t * mutate(const node_t * node); 139 MUTATE_FRIEND 141 140 }; 142 141 … … 157 156 private: 158 157 NamedTypeDecl* clone() const override = 0; 158 MUTATE_FRIEND 159 159 }; 160 160 … … 198 198 private: 199 199 TypeDecl * clone() const override { return new TypeDecl{ *this }; } 200 201 /// Must be copied in ALL derived classes 202 template<typename node_t> 203 friend node_t * mutate(const node_t * node); 200 MUTATE_FRIEND 204 201 }; 205 202 … … 216 213 private: 217 214 TypedefDecl * clone() const override { return new TypedefDecl{ *this }; } 218 219 /// Must be copied in ALL derived classes 220 template<typename node_t> 221 friend node_t * mutate(const node_t * node); 215 MUTATE_FRIEND 222 216 }; 223 217 … … 238 232 AggregateDecl* set_body( bool b ) { body = b; return this; } 239 233 234 private: 235 AggregateDecl * clone() const override = 0; 236 MUTATE_FRIEND 237 240 238 protected: 241 239 /// Produces a name for the kind of aggregate … … 260 258 private: 261 259 StructDecl * clone() const override { return new StructDecl{ *this }; } 262 263 /// Must be copied in ALL derived classes 264 template<typename node_t> 265 friend node_t * mutate(const node_t * node); 260 MUTATE_FRIEND 266 261 267 262 std::string typeString() const override { return "struct"; } … … 278 273 private: 279 274 UnionDecl * clone() const override { return new UnionDecl{ *this }; } 280 281 /// Must be copied in ALL derived classes 282 template<typename node_t> 283 friend node_t * mutate(const node_t * node); 275 MUTATE_FRIEND 284 276 285 277 std::string typeString() const override { return "union"; } … … 299 291 private: 300 292 EnumDecl * clone() const override { return new EnumDecl{ *this }; } 301 302 /// Must be copied in ALL derived classes 303 template<typename node_t> 304 friend node_t * mutate(const node_t * node); 293 MUTATE_FRIEND 305 294 306 295 std::string typeString() const override { return "enum"; } … … 320 309 private: 321 310 TraitDecl * clone() const override { return new TraitDecl{ *this }; } 322 323 /// Must be copied in ALL derived classes 324 template<typename node_t> 325 friend node_t * mutate(const node_t * node); 311 MUTATE_FRIEND 326 312 327 313 std::string typeString() const override { return "trait"; } … … 338 324 private: 339 325 AsmDecl *clone() const override { return new AsmDecl( *this ); } 340 341 /// Must be copied in ALL derived classes 342 template<typename node_t> 343 friend node_t * mutate(const node_t * node); 326 MUTATE_FRIEND 344 327 }; 345 328 … … 355 338 private: 356 339 StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); } 357 358 /// Must be copied in ALL derived classes 359 template<typename node_t> 360 friend node_t * mutate(const node_t * node); 340 MUTATE_FRIEND 361 341 }; 362 342 363 343 } 344 345 #undef MUTATE_FRIEND 364 346 365 347 // Local Variables: // -
src/AST/Expr.hpp
re61207e7 r41b24c8 27 27 #include "Visitor.hpp" 28 28 29 // Must be included in *all* AST classes; should be #undef'd at the end of the file 30 #define MUTATE_FRIEND template<typename node_t> friend auto mutate(const node_t * node); 31 29 32 namespace ast { 30 33 … … 127 130 private: 128 131 Expr * clone() const override = 0; 132 MUTATE_FRIEND 129 133 }; 130 134 … … 141 145 private: 142 146 ApplicationExpr * clone() const override { return new ApplicationExpr{ *this }; } 147 MUTATE_FRIEND 143 148 }; 144 149 … … 160 165 private: 161 166 UntypedExpr * clone() const override { return new UntypedExpr{ *this }; } 167 MUTATE_FRIEND 162 168 }; 163 169 … … 173 179 private: 174 180 NameExpr * clone() const override { return new NameExpr{ *this }; } 181 MUTATE_FRIEND 175 182 }; 176 183 … … 185 192 private: 186 193 AddressExpr * clone() const override { return new AddressExpr{ *this }; } 194 MUTATE_FRIEND 187 195 }; 188 196 … … 198 206 private: 199 207 LabelAddressExpr * clone() const override { return new LabelAddressExpr{ *this }; } 208 MUTATE_FRIEND 200 209 }; 201 210 … … 217 226 private: 218 227 CastExpr * clone() const override { return new CastExpr{ *this }; } 228 MUTATE_FRIEND 219 229 }; 220 230 … … 234 244 private: 235 245 KeywordCastExpr * clone() const override { return new KeywordCastExpr{ *this }; } 246 MUTATE_FRIEND 236 247 }; 237 248 … … 247 258 private: 248 259 VirtualCastExpr * clone() const override { return new VirtualCastExpr{ *this }; } 260 MUTATE_FRIEND 249 261 }; 250 262 … … 261 273 private: 262 274 UntypedMemberExpr * clone() const override { return new UntypedMemberExpr{ *this }; } 275 MUTATE_FRIEND 263 276 }; 264 277 … … 274 287 private: 275 288 MemberExpr * clone() const override { return new MemberExpr{ *this }; } 289 MUTATE_FRIEND 276 290 }; 277 291 … … 289 303 private: 290 304 VariableExpr * clone() const override { return new VariableExpr{ *this }; } 305 MUTATE_FRIEND 291 306 }; 292 307 … … 332 347 private: 333 348 ConstantExpr * clone() const override { return new ConstantExpr{ *this }; } 349 MUTATE_FRIEND 334 350 }; 335 351 … … 347 363 private: 348 364 SizeofExpr * clone() const override { return new SizeofExpr{ *this }; } 365 MUTATE_FRIEND 349 366 }; 350 367 … … 362 379 private: 363 380 AlignofExpr * clone() const override { return new AlignofExpr{ *this }; } 381 MUTATE_FRIEND 364 382 }; 365 383 … … 376 394 private: 377 395 UntypedOffsetofExpr * clone() const override { return new UntypedOffsetofExpr{ *this }; } 396 MUTATE_FRIEND 378 397 }; 379 398 … … 389 408 private: 390 409 OffsetofExpr * clone() const override { return new OffsetofExpr{ *this }; } 410 MUTATE_FRIEND 391 411 }; 392 412 … … 401 421 private: 402 422 OffsetPackExpr * clone() const override { return new OffsetPackExpr{ *this }; } 423 MUTATE_FRIEND 403 424 }; 404 425 … … 418 439 private: 419 440 LogicalExpr * clone() const override { return new LogicalExpr{ *this }; } 441 MUTATE_FRIEND 420 442 }; 421 443 … … 433 455 private: 434 456 ConditionalExpr * clone() const override { return new ConditionalExpr{ *this }; } 457 MUTATE_FRIEND 435 458 }; 436 459 … … 447 470 private: 448 471 CommaExpr * clone() const override { return new CommaExpr{ *this }; } 472 MUTATE_FRIEND 449 473 }; 450 474 … … 459 483 private: 460 484 TypeExpr * clone() const override { return new TypeExpr{ *this }; } 485 MUTATE_FRIEND 461 486 }; 462 487 … … 470 495 471 496 } 497 498 #undef MUTATE_FRIEND 472 499 473 500 // Local Variables: // -
src/AST/Init.hpp
re61207e7 r41b24c8 23 23 #include "Visitor.hpp" 24 24 25 // Must be included in *all* AST classes; should be #undef'd at the end of the file 26 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 27 25 28 namespace ast { 26 29 … … 40 43 private: 41 44 Designation* clone() const override { return new Designation{ *this }; } 45 MUTATE_FRIEND 42 46 }; 43 47 … … 55 59 private: 56 60 Init * clone() const override = 0; 61 MUTATE_FRIEND 57 62 }; 58 63 … … 69 74 private: 70 75 SingleInit * clone() const override { return new SingleInit{ *this }; } 71 72 /// Must be copied in ALL derived classes 73 template<typename node_t> 74 friend node_t * mutate(const node_t * node); 76 MUTATE_FRIEND 75 77 }; 76 78 … … 97 99 private: 98 100 ListInit * clone() const override { return new ListInit{ *this }; } 99 100 /// Must be copied in ALL derived classes 101 template<typename node_t> 102 friend node_t * mutate(const node_t * node); 101 MUTATE_FRIEND 103 102 }; 104 103 … … 120 119 private: 121 120 ConstructorInit * clone() const override { return new ConstructorInit{ *this }; } 122 123 /// Must be copied in ALL derived classes 124 template<typename node_t> 125 friend node_t * mutate(const node_t * node); 121 MUTATE_FRIEND 126 122 }; 127 123 128 124 } 125 126 #undef MUTATE_FRIEND 129 127 130 128 // Local Variables: // -
src/AST/Pass.impl.hpp
re61207e7 r41b24c8 19 19 #include <type_traits> 20 20 #include <unordered_map> 21 22 #include "AST/TypeSubstitution.hpp" 21 23 22 24 #define VISIT_START( node ) \ -
src/AST/Stmt.hpp
re61207e7 r41b24c8 26 26 #include "Common/CodeLocation.h" 27 27 28 // Must be included in *all* AST classes; should be #undef'd at the end of the file 29 #define MUTATE_FRIEND template<typename node_t> friend auto mutate(const node_t * node); 30 28 31 namespace ast { 29 32 … … 35 38 std::vector<Label> labels; 36 39 37 Stmt( const CodeLocation & loc, std::vector<Label>&& labels = {} )40 Stmt( const CodeLocation & loc, std::vector<Label> && labels = {} ) 38 41 : ParseNode(loc), labels(std::move(labels)) {} 39 42 40 43 Stmt(const Stmt& o) : ParseNode(o), labels(o.labels) {} 41 44 42 const Stmt* accept( Visitor& v ) const override = 0; 43 private: 44 Stmt* clone() const override = 0; 45 const Stmt * accept( Visitor & v ) const override = 0; 46 private: 47 Stmt * clone() const override = 0; 48 MUTATE_FRIEND 45 49 }; 46 50 … … 50 54 std::list<ptr<Stmt>> kids; 51 55 52 CompoundStmt(const CodeLocation & loc, std::list<ptr<Stmt>>&& ks = {} )56 CompoundStmt(const CodeLocation & loc, std::list<ptr<Stmt>> && ks = {} ) 53 57 : Stmt(loc), kids(std::move(ks)) {} 54 58 … … 56 60 CompoundStmt( CompoundStmt&& o ) = default; 57 61 58 void push_back( Stmt* s ) { kids.emplace_back( s ); } 59 void push_front( Stmt* s ) { kids.emplace_front( s ); } 60 61 const CompoundStmt* accept( Visitor& v ) const override { return v.visit( this ); } 62 private: 63 CompoundStmt* clone() const override { return new CompoundStmt{ *this }; } 64 65 /// Must be copied in ALL derived classes 66 template<typename node_t> 67 friend node_t * mutate(const node_t * node); 62 void push_back( Stmt * s ) { kids.emplace_back( s ); } 63 void push_front( Stmt * s ) { kids.emplace_front( s ); } 64 65 const CompoundStmt * accept( Visitor & v ) const override { return v.visit( this ); } 66 private: 67 CompoundStmt * clone() const override { return new CompoundStmt{ *this }; } 68 MUTATE_FRIEND 68 69 }; 69 70 … … 71 72 class NullStmt final : public Stmt { 72 73 public: 73 NullStmt( const CodeLocation & loc, std::vector<Label>&& labels = {} )74 NullStmt( const CodeLocation & loc, std::vector<Label> && labels = {} ) 74 75 : Stmt(loc, std::move(labels)) {} 75 76 76 const NullStmt* accept( Visitor& v ) const override { return v.visit( this ); } 77 private: 78 NullStmt* clone() const override { return new NullStmt{ *this }; } 79 80 /// Must be copied in ALL derived classes 81 template<typename node_t> 82 friend node_t * mutate(const node_t * node); 77 const NullStmt * accept( Visitor & v ) const override { return v.visit( this ); } 78 private: 79 NullStmt * clone() const override { return new NullStmt{ *this }; } 80 MUTATE_FRIEND 83 81 }; 84 82 … … 90 88 ExprStmt( const CodeLocation & loc, const Expr * e ) : Stmt(loc), expr(e) {} 91 89 92 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }90 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 93 91 private: 94 92 ExprStmt * clone() const override { return new ExprStmt{ *this }; } 95 96 /// Must be copied in ALL derived classes 97 template<typename node_t> 98 friend node_t * mutate(const node_t * node); 93 MUTATE_FRIEND 99 94 }; 100 95 … … 107 102 std::vector<Label> gotoLabels; 108 103 109 AsmStmt( const CodeLocation & loc, bool isVolatile, const Expr * instruction,110 std::vector<ptr<Expr>> && output, std::vector<ptr<Expr>>&& input,111 std::vector<ptr<ConstantExpr>> && clobber, std::vector<Label>&& gotoLabels,112 std::vector<Label> && labels = {})104 AsmStmt( const CodeLocation & loc, bool isVolatile, const Expr * instruction, 105 std::vector<ptr<Expr>> && output, std::vector<ptr<Expr>> && input, 106 std::vector<ptr<ConstantExpr>> && clobber, std::vector<Label> && gotoLabels, 107 std::vector<Label> && labels = {}) 113 108 : Stmt(loc, std::move(labels)), isVolatile(isVolatile), instruction(instruction), 114 109 output(std::move(output)), input(std::move(input)), clobber(std::move(clobber)), 115 110 gotoLabels(std::move(gotoLabels)) {} 116 111 117 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 118 private: 119 AsmStmt* clone() const override { return new AsmStmt{ *this }; } 120 121 /// Must be copied in ALL derived classes 122 template<typename node_t> 123 friend node_t * mutate(const node_t * node); 112 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 113 private: 114 AsmStmt * clone() const override { return new AsmStmt{ *this }; } 115 MUTATE_FRIEND 124 116 }; 125 117 … … 128 120 std::string directive; 129 121 130 DirectiveStmt( const CodeLocation & loc, const std::string & directive,131 std::vector<Label> && labels = {} )122 DirectiveStmt( const CodeLocation & loc, const std::string & directive, 123 std::vector<Label> && labels = {} ) 132 124 : Stmt(loc, std::move(labels)), directive(directive) {} 133 125 134 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 135 private: 136 DirectiveStmt* clone() const override { return new DirectiveStmt{ *this }; } 137 138 /// Must be copied in ALL derived classes 139 template<typename node_t> 140 friend node_t * mutate(const node_t * node); 126 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 127 private: 128 DirectiveStmt * clone() const override { return new DirectiveStmt{ *this }; } 129 MUTATE_FRIEND 141 130 }; 142 131 … … 148 137 std::vector<ptr<Stmt>> inits; 149 138 150 IfStmt( const CodeLocation & loc, const Expr* cond, const Stmt* thenPart,151 Stmt * const elsePart, std::vector<ptr<Stmt>> && inits,152 std::vector<Label> && labels = {} )139 IfStmt( const CodeLocation & loc, const Expr * cond, const Stmt * thenPart, 140 Stmt * const elsePart, std::vector<ptr<Stmt>> && inits, 141 std::vector<Label> && labels = {} ) 153 142 : Stmt(loc, std::move(labels)), cond(cond), thenPart(thenPart), elsePart(elsePart), 154 143 inits(std::move(inits)) {} 155 144 156 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 157 private: 158 IfStmt* clone() const override { return new IfStmt{ *this }; } 159 160 /// Must be copied in ALL derived classes 161 template<typename node_t> 162 friend node_t * mutate(const node_t * node); 145 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 146 private: 147 IfStmt * clone() const override { return new IfStmt{ *this }; } 148 MUTATE_FRIEND 163 149 }; 164 150 … … 168 154 std::vector<ptr<Stmt>> stmts; 169 155 170 SwitchStmt( const CodeLocation & loc, const Expr* cond, std::vector<ptr<Stmt>>&& stmts,171 std::vector<Label> && labels = {} )156 SwitchStmt( const CodeLocation & loc, const Expr * cond, std::vector<ptr<Stmt>> && stmts, 157 std::vector<Label> && labels = {} ) 172 158 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 173 159 174 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 175 private: 176 SwitchStmt* clone() const override { return new SwitchStmt{ *this }; } 177 178 /// Must be copied in ALL derived classes 179 template<typename node_t> 180 friend node_t * mutate(const node_t * node); 160 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 161 private: 162 SwitchStmt * clone() const override { return new SwitchStmt{ *this }; } 163 MUTATE_FRIEND 181 164 }; 182 165 … … 186 169 std::vector<ptr<Stmt>> stmts; 187 170 188 CaseStmt( const CodeLocation& loc, const Expr* cond, std::vector<ptr<Stmt>>&& stmts,189 std::vector<Label>&& labels = {} )190 171 CaseStmt( const CodeLocation & loc, const Expr * cond, std::vector<ptr<Stmt>> && stmts, 172 std::vector<Label> && labels = {} ) 173 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 191 174 192 175 bool isDefault() { return !cond; } 193 176 194 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 195 private: 196 CaseStmt* clone() const override { return new CaseStmt{ *this }; } 197 198 /// Must be copied in ALL derived classes 199 template<typename node_t> 200 friend node_t * mutate(const node_t * node); 177 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 178 private: 179 CaseStmt * clone() const override { return new CaseStmt{ *this }; } 180 MUTATE_FRIEND 201 181 }; 202 182 … … 208 188 bool isDoWhile; 209 189 210 WhileStmt( const CodeLocation & loc, const Expr* cond, const Stmt* body,211 std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, std::vector<Label>&& labels = {} )190 WhileStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body, 191 std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, std::vector<Label> && labels = {} ) 212 192 : Stmt(loc, std::move(labels)), cond(cond), body(body), inits(std::move(inits)), 213 193 isDoWhile(isDoWhile) {} 214 194 215 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 216 private: 217 WhileStmt* clone() const override { return new WhileStmt{ *this }; } 218 219 /// Must be copied in ALL derived classes 220 template<typename node_t> 221 friend node_t * mutate(const node_t * node); 195 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 196 private: 197 WhileStmt * clone() const override { return new WhileStmt{ *this }; } 198 MUTATE_FRIEND 222 199 }; 223 200 … … 229 206 ptr<Stmt> body; 230 207 231 ForStmt( const CodeLocation & loc, std::vector<ptr<Stmt>>&& inits, const Expr* cond,232 const Expr * inc, const Stmt* body, std::vector<Label>&& labels = {} )208 ForStmt( const CodeLocation & loc, std::vector<ptr<Stmt>> && inits, const Expr * cond, 209 const Expr * inc, const Stmt * body, std::vector<Label> && labels = {} ) 233 210 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), 234 211 body(body) {} 235 212 236 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 237 private: 238 ForStmt* clone() const override { return new ForStmt{ *this }; } 239 240 /// Must be copied in ALL derived classes 241 template<typename node_t> 242 friend node_t * mutate(const node_t * node); 213 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 214 private: 215 ForStmt * clone() const override { return new ForStmt{ *this }; } 216 MUTATE_FRIEND 243 217 }; 244 218 … … 253 227 Kind kind; 254 228 255 BranchStmt( const CodeLocation & loc, Kind kind, Label target,256 std::vector<Label> && labels = {} );257 BranchStmt( const CodeLocation & loc, const Expr* computedTarget,258 std::vector<Label> && labels = {} )229 BranchStmt( const CodeLocation & loc, Kind kind, Label target, 230 std::vector<Label> && labels = {} ); 231 BranchStmt( const CodeLocation & loc, const Expr * computedTarget, 232 std::vector<Label> && labels = {} ) 259 233 : Stmt(loc, std::move(labels)), originalTarget(loc), target(loc), 260 234 computedTarget(computedTarget), kind(Goto) {} … … 262 236 const char * kindName() { return kindNames[kind]; } 263 237 264 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 265 private: 266 BranchStmt* clone() const override { return new BranchStmt{ *this }; } 267 268 /// Must be copied in ALL derived classes 269 template<typename node_t> 270 friend node_t * mutate(const node_t * node); 238 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 239 private: 240 BranchStmt * clone() const override { return new BranchStmt{ *this }; } 241 MUTATE_FRIEND 271 242 272 243 static const char * kindNames[kindEnd]; … … 277 248 ptr<Expr> expr; 278 249 279 ReturnStmt( const CodeLocation & loc, const Expr* expr, std::vector<Label>&& labels = {} )250 ReturnStmt( const CodeLocation & loc, const Expr * expr, std::vector<Label> && labels = {} ) 280 251 : Stmt(loc, std::move(labels)), expr(expr) {} 281 252 282 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 283 private: 284 ReturnStmt* clone() const override { return new ReturnStmt{ *this }; } 285 286 /// Must be copied in ALL derived classes 287 template<typename node_t> 288 friend node_t * mutate(const node_t * node); 253 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 254 private: 255 ReturnStmt * clone() const override { return new ReturnStmt{ *this }; } 256 MUTATE_FRIEND 289 257 }; 290 258 … … 297 265 Kind kind; 298 266 299 ThrowStmt( const CodeLocation & loc, Kind kind, const Expr* expr, const Expr* target,300 std::vector<Label> && labels = {} )267 ThrowStmt( const CodeLocation & loc, Kind kind, const Expr * expr, const Expr * target, 268 std::vector<Label> && labels = {} ) 301 269 : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {} 302 270 303 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 304 private: 305 ThrowStmt* clone() const override { return new ThrowStmt{ *this }; } 306 307 /// Must be copied in ALL derived classes 308 template<typename node_t> 309 friend node_t * mutate(const node_t * node); 271 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 272 private: 273 ThrowStmt * clone() const override { return new ThrowStmt{ *this }; } 274 MUTATE_FRIEND 310 275 }; 311 276 … … 316 281 ptr<FinallyStmt> finally; 317 282 318 TryStmt( const CodeLocation & loc, const CompoundStmt* body,319 std::vector<ptr<CatchStmt>> && handlers, const FinallyStmt* finally,320 std::vector<Label> && labels = {} )283 TryStmt( const CodeLocation & loc, const CompoundStmt * body, 284 std::vector<ptr<CatchStmt>> && handlers, const FinallyStmt * finally, 285 std::vector<Label> && labels = {} ) 321 286 : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {} 322 287 323 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 324 private: 325 TryStmt* clone() const override { return new TryStmt{ *this }; } 326 327 /// Must be copied in ALL derived classes 328 template<typename node_t> 329 friend node_t * mutate(const node_t * node); 288 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 289 private: 290 TryStmt * clone() const override { return new TryStmt{ *this }; } 291 MUTATE_FRIEND 330 292 }; 331 293 … … 339 301 Kind kind; 340 302 341 CatchStmt( const CodeLocation & loc, Kind kind, const Decl* decl, const Expr* cond,342 const Stmt * body, std::vector<Label>&& labels = {} )303 CatchStmt( const CodeLocation & loc, Kind kind, const Decl * decl, const Expr * cond, 304 const Stmt * body, std::vector<Label> && labels = {} ) 343 305 : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {} 344 306 345 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 346 private: 347 CatchStmt* clone() const override { return new CatchStmt{ *this }; } 348 349 /// Must be copied in ALL derived classes 350 template<typename node_t> 351 friend node_t * mutate(const node_t * node); 307 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 308 private: 309 CatchStmt * clone() const override { return new CatchStmt{ *this }; } 310 MUTATE_FRIEND 352 311 }; 353 312 … … 356 315 ptr<CompoundStmt> body; 357 316 358 FinallyStmt( const CodeLocation & loc, const CompoundStmt* body,359 std::vector<Label> && labels = {} )317 FinallyStmt( const CodeLocation & loc, const CompoundStmt * body, 318 std::vector<Label> && labels = {} ) 360 319 : Stmt(loc, std::move(labels)), body(body) {} 361 320 362 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 363 private: 364 FinallyStmt* clone() const override { return new FinallyStmt{ *this }; } 365 366 /// Must be copied in ALL derived classes 367 template<typename node_t> 368 friend node_t * mutate(const node_t * node); 321 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 322 private: 323 FinallyStmt * clone() const override { return new FinallyStmt{ *this }; } 324 MUTATE_FRIEND 369 325 }; 370 326 … … 397 353 OrElse orElse; 398 354 399 WaitForStmt( const CodeLocation & loc, std::vector<Label>&& labels = {} )355 WaitForStmt( const CodeLocation & loc, std::vector<Label> && labels = {} ) 400 356 : Stmt(loc, std::move(labels)) {} 401 357 402 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 403 private: 404 WaitForStmt* clone() const override { return new WaitForStmt{ *this }; } 405 406 /// Must be copied in ALL derived classes 407 template<typename node_t> 408 friend node_t * mutate(const node_t * node); 358 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 359 private: 360 WaitForStmt * clone() const override { return new WaitForStmt{ *this }; } 361 MUTATE_FRIEND 409 362 }; 410 363 … … 414 367 ptr<Stmt> stmt; 415 368 416 WithStmt( const CodeLocation & loc, std::vector<ptr<Expr>>&& exprs, const Stmt* stmt,417 std::vector<Label> && labels = {} )369 WithStmt( const CodeLocation & loc, std::vector<ptr<Expr>> && exprs, const Stmt * stmt, 370 std::vector<Label> && labels = {} ) 418 371 : Stmt(loc, std::move(labels)), exprs(std::move(exprs)), stmt(stmt) {} 419 372 420 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 421 private: 422 WithStmt* clone() const override { return new WithStmt{ *this }; } 423 424 /// Must be copied in ALL derived classes 425 template<typename node_t> 426 friend node_t * mutate(const node_t * node); 373 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 374 private: 375 WithStmt * clone() const override { return new WithStmt{ *this }; } 376 MUTATE_FRIEND 427 377 }; 428 378 … … 431 381 ptr<Decl> decl; 432 382 433 DeclStmt( const CodeLocation & loc, const Decl* decl, std::vector<Label>&& labels = {} )383 DeclStmt( const CodeLocation & loc, const Decl * decl, std::vector<Label> && labels = {} ) 434 384 : Stmt(loc, std::move(labels)), decl(decl) {} 435 385 436 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 437 private: 438 DeclStmt* clone() const override { return new DeclStmt{ *this }; } 439 440 /// Must be copied in ALL derived classes 441 template<typename node_t> 442 friend node_t * mutate(const node_t * node); 386 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 387 private: 388 DeclStmt * clone() const override { return new DeclStmt{ *this }; } 389 MUTATE_FRIEND 443 390 }; 444 391 … … 447 394 readonly<Stmt> callStmt; 448 395 449 ImplicitCtorDtorStmt( const CodeLocation & loc, const Stmt* callStmt,450 std::vector<Label> && labels = {} )396 ImplicitCtorDtorStmt( const CodeLocation & loc, const Stmt * callStmt, 397 std::vector<Label> && labels = {} ) 451 398 : Stmt(loc, std::move(labels)), callStmt(callStmt) {} 452 399 453 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 454 private: 455 ImplicitCtorDtorStmt* clone() const override { return new ImplicitCtorDtorStmt{ *this }; } 456 457 /// Must be copied in ALL derived classes 458 template<typename node_t> 459 friend node_t * mutate(const node_t * node); 400 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 401 private: 402 ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt{ *this }; } 403 MUTATE_FRIEND 460 404 }; 461 405 462 406 } 407 408 #undef MUTATE_FRIEND 463 409 464 410 // Local Variables: // -
src/AST/Type.hpp
re61207e7 r41b24c8 29 29 #include "Visitor.hpp" 30 30 31 // Must be included in *all* AST classes; should be #undef'd at the end of the file 32 #define MUTATE_FRIEND template<typename node_t> friend auto mutate(const node_t * node); 33 31 34 namespace ast { 32 35 … … 70 73 private: 71 74 virtual Type * clone() const override = 0; 75 MUTATE_FRIEND 72 76 }; 73 77 … … 84 88 private: 85 89 VoidType * clone() const override { return new VoidType{ *this }; } 90 MUTATE_FRIEND 86 91 }; 87 92 … … 146 151 private: 147 152 BasicType * clone() const override { return new BasicType{ *this }; } 153 MUTATE_FRIEND 148 154 }; 149 155 … … 176 182 private: 177 183 PointerType * clone() const override { return new PointerType{ *this }; } 184 MUTATE_FRIEND 178 185 }; 179 186 … … 197 204 private: 198 205 ArrayType * clone() const override { return new ArrayType{ *this }; } 206 MUTATE_FRIEND 199 207 }; 200 208 … … 216 224 private: 217 225 ReferenceType * clone() const override { return new ReferenceType{ *this }; } 226 MUTATE_FRIEND 218 227 }; 219 228 … … 230 239 private: 231 240 QualifiedType * clone() const override { return new QualifiedType{ *this }; } 241 MUTATE_FRIEND 232 242 }; 233 243 … … 245 255 private: 246 256 virtual ParameterizedType * clone() const override = 0; 257 MUTATE_FRIEND 247 258 }; 248 259 … … 274 285 private: 275 286 FunctionType * clone() const override { return new FunctionType{ *this }; } 287 MUTATE_FRIEND 276 288 }; 277 289 … … 295 307 private: 296 308 virtual ReferenceToType * clone() const override = 0; 309 MUTATE_FRIEND 297 310 298 311 protected: … … 319 332 private: 320 333 StructInstType * clone() const override { return new StructInstType{ *this }; } 334 MUTATE_FRIEND 321 335 322 336 std::string typeString() const override { return "struct"; } … … 341 355 private: 342 356 UnionInstType * clone() const override { return new UnionInstType{ *this }; } 357 MUTATE_FRIEND 343 358 344 359 std::string typeString() const override { return "union"; } … … 363 378 private: 364 379 EnumInstType * clone() const override { return new EnumInstType{ *this }; } 380 MUTATE_FRIEND 365 381 366 382 std::string typeString() const override { return "enum"; } … … 386 402 private: 387 403 TraitInstType * clone() const override { return new TraitInstType{ *this }; } 404 MUTATE_FRIEND 388 405 389 406 std::string typeString() const override { return "trait"; } … … 414 431 private: 415 432 TypeInstType * clone() const override { return new TypeInstType{ *this }; } 433 MUTATE_FRIEND 416 434 417 435 std::string typeString() const override { return "type"; } … … 442 460 private: 443 461 TupleType * clone() const override { return new TupleType{ *this }; } 462 MUTATE_FRIEND 444 463 }; 445 464 … … 456 475 private: 457 476 TypeofType * clone() const override { return new TypeofType{ *this }; } 477 MUTATE_FRIEND 458 478 }; 459 479 … … 466 486 private: 467 487 VarArgsType * clone() const override { return new VarArgsType{ *this }; } 488 MUTATE_FRIEND 468 489 }; 469 490 … … 476 497 private: 477 498 ZeroType * clone() const override { return new ZeroType{ *this }; } 499 MUTATE_FRIEND 478 500 }; 479 501 … … 486 508 private: 487 509 OneType * clone() const override { return new OneType{ *this }; } 510 MUTATE_FRIEND 488 511 }; 489 512 … … 496 519 private: 497 520 GlobalScopeType * clone() const override { return new GlobalScopeType{ *this }; } 521 MUTATE_FRIEND 498 522 }; 499 523 500 524 } 525 526 #undef MUTATE_FRIEND 501 527 502 528 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.