Changeset 246c245
- Timestamp:
- May 16, 2019, 6:51:18 PM (4 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:
- 8ff178d, d66e7b7
- Parents:
- 9b4f329 (diff), 6f8e87d (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:
-
- 3 added
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.hfa
r9b4f329 r246c245 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/Attribute.hpp
r9b4f329 r246c245 50 50 /// Must be copied in ALL derived classes 51 51 template<typename node_t> 52 friend automutate(const node_t * node);52 friend node_t * mutate(const node_t * node); 53 53 }; 54 54 55 56 57 //=================================================================================================58 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency59 /// remove only if there is a better solution60 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with61 /// forward declarations62 inline void increment( const class Attribute * node, Node::ref_type ref ) { node->increment( ref ); }63 inline void decrement( const class Attribute * node, Node::ref_type ref ) { node->decrement( ref ); }64 55 } 65 56 -
src/AST/Convert.cpp
r9b4f329 r246c245 9 9 // Author : Thierry Delisle 10 10 // Created On : Thu May 09 15::37::05 2019 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu May 16 17:21:00 2019 13 // Update Count : 1 14 14 // 15 15 … … 74 74 ast::Node * node; 75 75 76 // Local Utilities: 77 78 template<typename NewT, typename OldT> 79 NewT * getAccept1( OldT old ) { 80 old->accept(*this); 81 return strict_dynamic_cast< NewT * >( node ); 82 } 83 84 # define GET_ACCEPT_1(child, type) \ 85 getAccept1< ast::type, decltype( old->child ) >( old->child ) 86 87 template<typename NewT, typename OldC> 88 std::vector< ast::ptr<NewT> > getAcceptV( OldC& old ) { 89 std::vector< ast::ptr<NewT> > ret; 90 ret.reserve( old.size() ); 91 for ( auto a : old ) { 92 a->accept( *this ); 93 ret.emplace_back( strict_dynamic_cast< NewT * >(node) ); 94 } 95 return ret; 96 } 97 98 # define GET_ACCEPT_V(child, type) \ 99 getAcceptV< ast::type, decltype( old->child ) >( old->child ) 100 101 ast::Label make_label(Label* old) { 102 return ast::Label( 103 old->labelled->location, 104 old->name, 105 GET_ACCEPT_V(attributes, Attribute) 106 ); 107 } 108 76 109 template<template <class...> class C> 77 110 C<ast::Label> make_labels(C<Label> olds) { 78 111 C<ast::Label> ret; 79 for(auto oldn : olds) { 80 auto old = &oldn; // to reuse the MACRO 81 ACCEPT_N(attr, attributes, Attribute) 82 ast::Label l( 83 {}, 84 old->get_name(), 85 to<std::vector>::from( std::move( attr ) ) 86 ); 87 ret.push_back( l ); 112 for (auto oldn : olds) { 113 ret.push_back( make_label( &oldn ) ); 88 114 } 89 115 return ret; 90 116 } 117 118 # define GET_LABELS_V(labels) \ 119 to<std::vector>::from( make_labels( std::move( labels ) ) ) 120 121 // Now all the visit functions: 91 122 92 123 virtual void visit( ObjectDecl * old ) override final { … … 135 166 decl->parent = parent; 136 167 decl->body = old->body; 137 decl->param eters = params;168 decl->params = params; 138 169 decl->members = members; 139 170 decl->extension = old->extension; … … 158 189 decl->parent = parent; 159 190 decl->body = old->body; 160 decl->param eters = params;191 decl->params = params; 161 192 decl->members = members; 162 193 decl->extension = old->extension; … … 181 212 decl->parent = parent; 182 213 decl->body = old->body; 183 decl->param eters = params;214 decl->params = params; 184 215 decl->members = members; 185 216 decl->extension = old->extension; … … 204 235 decl->parent = parent; 205 236 decl->body = old->body; 206 decl->param eters = params;237 decl->params = params; 207 238 decl->members = members; 208 239 decl->extension = old->extension; … … 230 261 231 262 decl->assertions = asserts; 232 decl->param eters= params;263 decl->params = params; 233 264 decl->extension = old->extension; 234 265 decl->uniqueId = old->uniqueId; … … 258 289 259 290 virtual void visit( ExprStmt * old ) override final { 260 ACCEPT_1(expr, expr, Expr) 261 auto stmt = new ast::ExprStmt( 262 old->location, 263 expr 264 ); 265 stmt->labels = to<std::vector>::from( make_labels( std::move( old->labels ) ) ); 291 this->node = new ast::ExprStmt( 292 old->location, 293 GET_ACCEPT_1(expr, Expr), 294 GET_LABELS_V(old->labels) 295 ); 296 } 297 298 virtual void visit( AsmStmt * old ) override final { 299 this->node = new ast::AsmStmt( 300 old->location, 301 old->voltile, 302 GET_ACCEPT_1(instruction, Expr), 303 GET_ACCEPT_V(output, Expr), 304 GET_ACCEPT_V(input, Expr), 305 GET_ACCEPT_V(clobber, ConstantExpr), 306 GET_LABELS_V(old->gotolabels), 307 GET_LABELS_V(old->labels) 308 ); 309 } 310 311 virtual void visit( DirectiveStmt * old ) override final { 312 this->node = new ast::DirectiveStmt( 313 old->location, 314 old->directive, 315 GET_LABELS_V(old->labels) 316 ); 317 } 318 319 virtual void visit( IfStmt * old ) override final { 320 this->node = new ast::IfStmt( 321 old->location, 322 GET_ACCEPT_1(condition, Expr), 323 GET_ACCEPT_1(thenPart, Stmt), 324 GET_ACCEPT_1(elsePart, Stmt), 325 GET_ACCEPT_V(initialization, Stmt), 326 GET_LABELS_V(old->labels) 327 ); 328 } 329 330 virtual void visit( SwitchStmt * old ) override final { 331 this->node = new ast::SwitchStmt( 332 old->location, 333 GET_ACCEPT_1(condition, Expr), 334 GET_ACCEPT_V(statements, Stmt), 335 GET_LABELS_V(old->labels) 336 ); 337 } 338 339 virtual void visit( CaseStmt * old ) override final { 340 this->node = new ast::CaseStmt( 341 old->location, 342 GET_ACCEPT_1(condition, Expr), 343 GET_ACCEPT_V(stmts, Stmt), 344 GET_LABELS_V(old->labels) 345 ); 346 } 347 348 virtual void visit( WhileStmt * old ) override final { 349 this->node = new ast::WhileStmt( 350 old->location, 351 GET_ACCEPT_1(condition, Expr), 352 GET_ACCEPT_1(body, Stmt), 353 GET_ACCEPT_V(initialization, Stmt), 354 old->isDoWhile, 355 GET_LABELS_V(old->labels) 356 ); 357 } 358 359 virtual void visit( ForStmt * old ) override final { 360 this->node = new ast::ForStmt( 361 old->location, 362 GET_ACCEPT_V(initialization, Stmt), 363 GET_ACCEPT_1(condition, Expr), 364 GET_ACCEPT_1(increment, Expr), 365 GET_ACCEPT_1(body, Stmt), 366 GET_LABELS_V(old->labels) 367 ); 368 } 369 370 virtual void visit( BranchStmt * old ) override final { 371 if (old->computedTarget) { 372 this->node = new ast::BranchStmt( 373 old->location, 374 GET_ACCEPT_1(computedTarget, Expr), 375 GET_LABELS_V(old->labels) 376 ); 377 } else { 378 ast::BranchStmt::Kind kind; 379 switch (old->type) { 380 #define CASE(n) \ 381 case BranchStmt::n: \ 382 kind = ast::BranchStmt::n; \ 383 break 384 CASE(Goto); 385 CASE(Break); 386 CASE(Continue); 387 CASE(FallThrough); 388 CASE(FallThroughDefault); 389 #undef CASE 390 } 391 392 Label label = old->originalTarget; 393 auto stmt = new ast::BranchStmt( 394 old->location, 395 kind, 396 make_label(&label), 397 GET_LABELS_V(old->labels) 398 ); 399 stmt->target = make_label(&old->target); 400 this->node = stmt; 401 } 402 } 403 404 virtual void visit( ReturnStmt * old ) override final { 405 this->node = new ast::ReturnStmt( 406 old->location, 407 GET_ACCEPT_1(expr, Expr), 408 GET_LABELS_V(old->labels) 409 ); 410 } 411 412 virtual void visit( ThrowStmt * old ) override final { 413 ast::ThrowStmt::Kind kind; 414 switch (old->kind) { 415 case ThrowStmt::Terminate: 416 kind = ast::ThrowStmt::Terminate; 417 break; 418 case ThrowStmt::Resume: 419 kind = ast::ThrowStmt::Resume; 420 break; 421 } 422 423 this->node = new ast::ThrowStmt( 424 old->location, 425 kind, 426 GET_ACCEPT_1(expr, Expr), 427 GET_ACCEPT_1(target, Expr), 428 GET_LABELS_V(old->labels) 429 ); 430 } 431 432 virtual void visit( TryStmt * old ) override final { 433 this->node = new ast::TryStmt( 434 old->location, 435 GET_ACCEPT_1(block, CompoundStmt), 436 GET_ACCEPT_V(handlers, CatchStmt), 437 GET_ACCEPT_1(finallyBlock, FinallyStmt), 438 GET_LABELS_V(old->labels) 439 ); 440 } 441 442 virtual void visit( CatchStmt * old ) override final { 443 ast::CatchStmt::Kind kind; 444 switch (old->kind) { 445 case CatchStmt::Terminate: 446 kind = ast::CatchStmt::Terminate; 447 break; 448 case CatchStmt::Resume: 449 kind = ast::CatchStmt::Resume; 450 break; 451 } 452 453 this->node = new ast::CatchStmt( 454 old->location, 455 kind, 456 GET_ACCEPT_1(decl, Decl), 457 GET_ACCEPT_1(cond, Expr), 458 GET_ACCEPT_1(body, Stmt), 459 GET_LABELS_V(old->labels) 460 ); 461 } 462 463 virtual void visit( FinallyStmt * old ) override final { 464 this->node = new ast::FinallyStmt( 465 old->location, 466 GET_ACCEPT_1(block, CompoundStmt), 467 GET_LABELS_V(old->labels) 468 ); 469 } 470 471 virtual void visit( WaitForStmt * old ) override final { 472 ast::WaitForStmt * stmt = new ast::WaitForStmt( 473 old->location, 474 GET_LABELS_V(old->labels) 475 ); 476 477 stmt->clauses.reserve( old->clauses.size() ); 478 for (size_t i = 0 ; i < old->clauses.size() ; ++i) { 479 stmt->clauses.push_back({ 480 ast::WaitForStmt::Target{ 481 GET_ACCEPT_1(clauses[i].target.function, Expr), 482 GET_ACCEPT_V(clauses[i].target.arguments, Expr) 483 }, 484 GET_ACCEPT_1(clauses[i].statement, Stmt), 485 GET_ACCEPT_1(clauses[i].condition, Expr) 486 }); 487 } 488 stmt->timeout = { 489 GET_ACCEPT_1(timeout.time, Expr), 490 GET_ACCEPT_1(timeout.statement, Stmt), 491 GET_ACCEPT_1(timeout.condition, Expr), 492 }; 493 stmt->orElse = { 494 GET_ACCEPT_1(timeout.statement, Stmt), 495 GET_ACCEPT_1(timeout.condition, Expr), 496 }; 266 497 267 498 this->node = stmt; 268 499 } 269 500 270 virtual void visit( AsmStmt * ) override final { 271 272 } 273 274 virtual void visit( DirectiveStmt * ) override final { 275 276 } 277 278 virtual void visit( IfStmt * ) override final { 279 280 } 281 282 virtual void visit( WhileStmt * ) override final { 283 284 } 285 286 virtual void visit( ForStmt * ) override final { 287 288 } 289 290 virtual void visit( SwitchStmt * ) override final { 291 292 } 293 294 virtual void visit( CaseStmt * ) override final { 295 296 } 297 298 virtual void visit( BranchStmt * ) override final { 299 300 } 301 302 virtual void visit( ReturnStmt * ) override final { 303 304 } 305 306 virtual void visit( ThrowStmt * ) override final { 307 308 } 309 310 virtual void visit( TryStmt * ) override final { 311 312 } 313 314 virtual void visit( CatchStmt * ) override final { 315 316 } 317 318 virtual void visit( FinallyStmt * ) override final { 319 320 } 321 322 virtual void visit( WaitForStmt * ) override final { 323 324 } 325 326 virtual void visit( WithStmt * ) override final { 327 501 virtual void visit( WithStmt * old ) override final { 502 this->node = new ast::WithStmt( 503 old->location, 504 GET_ACCEPT_V(exprs, Expr), 505 GET_ACCEPT_1(stmt, Stmt), 506 GET_LABELS_V(old->labels) 507 ); 328 508 } 329 509 330 510 virtual void visit( NullStmt * old ) override final { 331 auto stmt = new ast::NullStmt( 332 old->location, 333 to<std::vector>::from( make_labels( std::move( old->labels ) ) ) 334 ); 335 336 this->node = stmt; 337 } 338 339 virtual void visit( DeclStmt * ) override final { 340 341 } 342 343 virtual void visit( ImplicitCtorDtorStmt * ) override final { 344 511 this->node = new ast::NullStmt( 512 old->location, 513 GET_LABELS_V(old->labels) 514 ); 515 } 516 517 virtual void visit( DeclStmt * old ) override final { 518 this->node = new ast::DeclStmt( 519 old->location, 520 GET_ACCEPT_1(decl, Decl), 521 GET_LABELS_V(old->labels) 522 ); 523 } 524 525 virtual void visit( ImplicitCtorDtorStmt * old ) override final { 526 this->node = new ast::ImplicitCtorDtorStmt( 527 old->location, 528 GET_ACCEPT_1(callStmt, Stmt), 529 GET_LABELS_V(old->labels) 530 ); 345 531 } 346 532 … … 592 778 593 779 } 780 781 virtual void visit( AttrExpr * ) override final { 782 783 assert( 0 ); 784 } 594 785 }; 786 787 #undef GET_LABELS_V 788 #undef GET_ACCEPT_V 789 #undef GET_ACCEPT_1 595 790 596 791 #undef ACCEPT_N -
src/AST/Decl.cpp
r9b4f329 r246c245 20 20 #include <unordered_map> 21 21 22 #include "Common/utility.h" 23 22 24 #include "Fwd.hpp" // for UniqueId 23 25 #include "Init.hpp" 24 26 #include "Node.hpp" // for readonly 27 #include "Type.hpp" // for readonly 25 28 #include "Parser/ParseNode.h" // for DeclarationNode 26 29 … … 47 50 // --- FunctionDecl 48 51 49 const Type * FunctionDecl::get_type() const override{ return type.get(); }50 void FunctionDecl::set_type(Type * t) override{ type = strict_dynamic_cast< FunctionType* >( t ); }52 const Type * FunctionDecl::get_type() const { return type.get(); } 53 void FunctionDecl::set_type(Type * t) { type = strict_dynamic_cast< FunctionType* >( t ); } 51 54 52 55 // --- TypeDecl … … 75 78 const ObjectDecl* field = strict_dynamic_cast< const ObjectDecl* >( member ); 76 79 if ( field->init ) { 77 const SingleInit * init = strict_dynamic_cast< const SingleInit* >( field->init);80 const SingleInit * init = strict_dynamic_cast< const SingleInit* >( field->init.get() ); 78 81 auto result = eval( init->value ); 79 82 if ( ! result.second ) { -
src/AST/Decl.hpp
r9b4f329 r246c245 31 31 32 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 automutate(const node_t * node);33 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 34 34 35 35 namespace ast { … … 341 341 }; 342 342 343 //=================================================================================================344 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency345 /// remove only if there is a better solution346 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with347 /// forward declarations348 inline void increment( const class Decl * node, Node::ref_type ref ) { node->increment(ref); }349 inline void decrement( const class Decl * node, Node::ref_type ref ) { node->decrement(ref); }350 inline void increment( const class DeclWithType * node, Node::ref_type ref ) { node->increment(ref); }351 inline void decrement( const class DeclWithType * node, Node::ref_type ref ) { node->decrement(ref); }352 inline void increment( const class ObjectDecl * node, Node::ref_type ref ) { node->increment(ref); }353 inline void decrement( const class ObjectDecl * node, Node::ref_type ref ) { node->decrement(ref); }354 inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); }355 inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); }356 inline void increment( const class AggregateDecl * node, Node::ref_type ref ) { node->increment(ref); }357 inline void decrement( const class AggregateDecl * node, Node::ref_type ref ) { node->decrement(ref); }358 inline void increment( const class StructDecl * node, Node::ref_type ref ) { node->increment(ref); }359 inline void decrement( const class StructDecl * node, Node::ref_type ref ) { node->decrement(ref); }360 inline void increment( const class UnionDecl * node, Node::ref_type ref ) { node->increment(ref); }361 inline void decrement( const class UnionDecl * node, Node::ref_type ref ) { node->decrement(ref); }362 inline void increment( const class EnumDecl * node, Node::ref_type ref ) { node->increment(ref); }363 inline void decrement( const class EnumDecl * node, Node::ref_type ref ) { node->decrement(ref); }364 inline void increment( const class TraitDecl * node, Node::ref_type ref ) { node->increment(ref); }365 inline void decrement( const class TraitDecl * node, Node::ref_type ref ) { node->decrement(ref); }366 inline void increment( const class NamedTypeDecl * node, Node::ref_type ref ) { node->increment(ref); }367 inline void decrement( const class NamedTypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }368 inline void increment( const class TypeDecl * node, Node::ref_type ref ) { node->increment(ref); }369 inline void decrement( const class TypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }370 inline void increment( const class TypedefDecl * node, Node::ref_type ref ) { node->increment(ref); }371 inline void decrement( const class TypedefDecl * node, Node::ref_type ref ) { node->decrement(ref); }372 inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); }373 inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); }374 inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); }375 inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); }376 377 343 } 378 344 -
src/AST/Expr.cpp
r9b4f329 r246c245 32 32 // --- ApplicationExpr 33 33 34 ApplicationExpr::ApplicationExpr( const CodeLocation & loc, const Expr * f, 35 std::vector<ptr<Expr>> && as ) 36 : Expr( loc ), func( f ), args( std::move(a rgs) ) {34 ApplicationExpr::ApplicationExpr( const CodeLocation & loc, const Expr * f, 35 std::vector<ptr<Expr>> && as ) 36 : Expr( loc ), func( f ), args( std::move(as) ) { 37 37 // ensure that `ApplicationExpr` result type is `FuncExpr` 38 38 const PointerType * pt = strict_dynamic_cast< const PointerType * >( f->result.get() ); … … 48 48 assert( arg ); 49 49 50 UntypedExpr * ret = new UntypedExpr{ 51 loc, new NameExpr{loc, "*?"}, std::vector<ptr<Expr>>{ ptr<Expr>{ arg } } 50 UntypedExpr * ret = new UntypedExpr{ 51 loc, new NameExpr{loc, "*?"}, std::vector<ptr<Expr>>{ ptr<Expr>{ arg } } 52 52 }; 53 53 if ( const Type * ty = arg->result ) { … … 59 59 ret->result = new ReferenceType{ base }; 60 60 } else { 61 // references have been removed, in which case dereference returns an lvalue of the 61 // references have been removed, in which case dereference returns an lvalue of the 62 62 // base type 63 63 ret->result.set_and_mutate( base )->set_lvalue( true ); … … 112 112 } else { 113 113 // taking address of non-lvalue, must be a reference, loses one layer of reference 114 if ( const ReferenceType * refType = 114 if ( const ReferenceType * refType = 115 115 dynamic_cast< const ReferenceType * >( arg->result.get() ) ) { 116 116 Type * res = addrType( refType->base ); … … 118 118 result = res; 119 119 } else { 120 SemanticError( loc, arg->result, 120 SemanticError( loc, arg->result, 121 121 "Attempt to take address of non-lvalue expression: " ); 122 122 } … … 128 128 129 129 // label address always has type `void*` 130 LabelAddressExpr::LabelAddressExpr( const CodeLocation & loc, Label && a ) 130 LabelAddressExpr::LabelAddressExpr( const CodeLocation & loc, Label && a ) 131 131 : Expr( loc, new PointerType{ new VoidType{} } ), arg( a ) {} 132 132 133 133 // --- CastExpr 134 134 135 CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g ) 135 CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g ) 136 136 : Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ) {} 137 137 … … 169 169 } 170 170 171 VariableExpr * VariableExpr::functionPointer( 171 VariableExpr * VariableExpr::functionPointer( 172 172 const CodeLocation & loc, const FunctionDecl * decl ) { 173 173 // wrap usually-determined result type in a pointer … … 202 202 203 203 ConstantExpr * ConstantExpr::from_bool( const CodeLocation & loc, bool b ) { 204 return new ConstantExpr{ 204 return new ConstantExpr{ 205 205 loc, new BasicType{ BasicType::Bool }, b ? "1" : "0", (unsigned long long)b }; 206 206 } 207 207 208 208 ConstantExpr * ConstantExpr::from_char( const CodeLocation & loc, char c ) { 209 return new ConstantExpr{ 209 return new ConstantExpr{ 210 210 loc, new BasicType{ BasicType::Char }, std::to_string( c ), (unsigned long long)c }; 211 211 } 212 212 213 213 ConstantExpr * ConstantExpr::from_int( const CodeLocation & loc, int i ) { 214 return new ConstantExpr{ 214 return new ConstantExpr{ 215 215 loc, new BasicType{ BasicType::SignedInt }, std::to_string( i ), (unsigned long long)i }; 216 216 } 217 217 218 218 ConstantExpr * ConstantExpr::from_ulong( const CodeLocation & loc, unsigned long i ) { 219 return new ConstantExpr{ 220 loc, new BasicType{ BasicType::LongUnsignedInt }, std::to_string( i ), 219 return new ConstantExpr{ 220 loc, new BasicType{ BasicType::LongUnsignedInt }, std::to_string( i ), 221 221 (unsigned long long)i }; 222 222 } … … 229 229 return new ConstantExpr{ 230 230 loc, 231 new ArrayType{ 231 new ArrayType{ 232 232 new BasicType{ BasicType::Char, CV::Const }, 233 233 ConstantExpr::from_int( loc, s.size() + 1 /* null terminator */ ), … … 258 258 : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( nullptr ), type( t ) {} 259 259 260 // --- UntypedOffsetofExpr261 262 UntypedOffsetofExpr::UntypedOffsetofExpr(263 const CodeLocation & loc, const Type * ty, const std::string & mem )264 : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), type( ty ), member( mem ) {265 assert( type );266 }267 268 260 // --- OffsetofExpr 269 261 … … 277 269 278 270 OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty ) 279 : Expr( loc, new ArrayType{ 280 new BasicType{ BasicType::LongUnsignedInt }, nullptr, FixedLen, DynamicDim } 271 : Expr( loc, new ArrayType{ 272 new BasicType{ BasicType::LongUnsignedInt }, nullptr, FixedLen, DynamicDim } 281 273 ), type( ty ) { 282 274 assert( type ); … … 285 277 // --- LogicalExpr 286 278 287 LogicalExpr::LogicalExpr( 279 LogicalExpr::LogicalExpr( 288 280 const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia ) 289 281 : Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {} -
src/AST/Expr.hpp
r9b4f329 r246c245 28 28 29 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 automutate(const node_t * node);30 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 31 31 32 32 namespace ast { … … 133 133 }; 134 134 135 /// The application of a function to a set of parameters. 135 /// The application of a function to a set of parameters. 136 136 /// Post-resolver form of `UntypedExpr` 137 137 class ApplicationExpr final : public Expr { … … 218 218 GeneratedFlag isGenerated; 219 219 220 CastExpr( const CodeLocation & loc, const Expr * a, const Type * to, 220 CastExpr( const CodeLocation & loc, const Expr * a, const Type * to, 221 221 GeneratedFlag g = GeneratedCast ) : Expr( loc, to ), arg( a ), isGenerated( g ) {} 222 222 /// Cast-to-void … … 311 311 unsigned long long ival; 312 312 double dval; 313 313 314 314 Val( unsigned long long i ) : ival( i ) {} 315 315 Val( double d ) : dval( d ) {} … … 318 318 std::string rep; 319 319 320 ConstantExpr( 320 ConstantExpr( 321 321 const CodeLocation & loc, const Type * ty, const std::string & r, unsigned long long v ) 322 322 : Expr( loc, ty ), val( v ), rep( r ) {} 323 323 ConstantExpr( const CodeLocation & loc, const Type * ty, const std::string & r, double v ) 324 324 : Expr( loc, ty ), val( v ), rep( r ) {} 325 325 326 326 /// Gets the value of this constant as an integer 327 327 long long int intValue() const; … … 464 464 ptr<Expr> arg2; 465 465 466 CommaExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2 ) 466 CommaExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2 ) 467 467 : Expr( loc ), arg1( a1 ), arg2( a2 ) {} 468 468 … … 754 754 }; 755 755 756 //================================================================================================= 757 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency 758 /// remove only if there is a better solution 759 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with 760 /// forward declarations 761 inline void increment( const class Expr * node, Node::ref_type ref ) { node->increment(ref); } 762 inline void decrement( const class Expr * node, Node::ref_type ref ) { node->decrement(ref); } 763 inline void increment( const class ApplicationExpr * node, Node::ref_type ref ) { node->increment(ref); } 764 inline void decrement( const class ApplicationExpr * node, Node::ref_type ref ) { node->decrement(ref); } 765 inline void increment( const class UntypedExpr * node, Node::ref_type ref ) { node->increment(ref); } 766 inline void decrement( const class UntypedExpr * node, Node::ref_type ref ) { node->decrement(ref); } 767 inline void increment( const class NameExpr * node, Node::ref_type ref ) { node->increment(ref); } 768 inline void decrement( const class NameExpr * node, Node::ref_type ref ) { node->decrement(ref); } 769 inline void increment( const class AddressExpr * node, Node::ref_type ref ) { node->increment(ref); } 770 inline void decrement( const class AddressExpr * node, Node::ref_type ref ) { node->decrement(ref); } 771 inline void increment( const class LabelAddressExpr * node, Node::ref_type ref ) { node->increment(ref); } 772 inline void decrement( const class LabelAddressExpr * node, Node::ref_type ref ) { node->decrement(ref); } 773 inline void increment( const class CastExpr * node, Node::ref_type ref ) { node->increment(ref); } 774 inline void decrement( const class CastExpr * node, Node::ref_type ref ) { node->decrement(ref); } 775 inline void increment( const class KeywordCastExpr * node, Node::ref_type ref ) { node->increment(ref); } 776 inline void decrement( const class KeywordCastExpr * node, Node::ref_type ref ) { node->decrement(ref); } 777 inline void increment( const class VirtualCastExpr * node, Node::ref_type ref ) { node->increment(ref); } 778 inline void decrement( const class VirtualCastExpr * node, Node::ref_type ref ) { node->decrement(ref); } 779 inline void increment( const class MemberExpr * node, Node::ref_type ref ) { node->increment(ref); } 780 inline void decrement( const class MemberExpr * node, Node::ref_type ref ) { node->decrement(ref); } 781 inline void increment( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->increment(ref); } 782 inline void decrement( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->decrement(ref); } 783 inline void increment( const class VariableExpr * node, Node::ref_type ref ) { node->increment(ref); } 784 inline void decrement( const class VariableExpr * node, Node::ref_type ref ) { node->decrement(ref); } 785 inline void increment( const class ConstantExpr * node, Node::ref_type ref ) { node->increment(ref); } 786 inline void decrement( const class ConstantExpr * node, Node::ref_type ref ) { node->decrement(ref); } 787 inline void increment( const class SizeofExpr * node, Node::ref_type ref ) { node->increment(ref); } 788 inline void decrement( const class SizeofExpr * node, Node::ref_type ref ) { node->decrement(ref); } 789 inline void increment( const class AlignofExpr * node, Node::ref_type ref ) { node->increment(ref); } 790 inline void decrement( const class AlignofExpr * node, Node::ref_type ref ) { node->decrement(ref); } 791 inline void increment( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); } 792 inline void decrement( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); } 793 inline void increment( const class OffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); } 794 inline void decrement( const class OffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); } 795 inline void increment( const class OffsetPackExpr * node, Node::ref_type ref ) { node->increment(ref); } 796 inline void decrement( const class OffsetPackExpr * node, Node::ref_type ref ) { node->decrement(ref); } 797 inline void increment( const class LogicalExpr * node, Node::ref_type ref ) { node->increment(ref); } 798 inline void decrement( const class LogicalExpr * node, Node::ref_type ref ) { node->decrement(ref); } 799 inline void increment( const class ConditionalExpr * node, Node::ref_type ref ) { node->increment(ref); } 800 inline void decrement( const class ConditionalExpr * node, Node::ref_type ref ) { node->decrement(ref); } 801 inline void increment( const class CommaExpr * node, Node::ref_type ref ) { node->increment(ref); } 802 inline void decrement( const class CommaExpr * node, Node::ref_type ref ) { node->decrement(ref); } 803 inline void increment( const class TypeExpr * node, Node::ref_type ref ) { node->increment(ref); } 804 inline void decrement( const class TypeExpr * node, Node::ref_type ref ) { node->decrement(ref); } 805 inline void increment( const class AsmExpr * node, Node::ref_type ref ) { node->increment(ref); } 806 inline void decrement( const class AsmExpr * node, Node::ref_type ref ) { node->decrement(ref); } 807 inline void increment( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->increment(ref); } 808 inline void decrement( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->decrement(ref); } 809 inline void increment( const class ConstructorExpr * node, Node::ref_type ref ) { node->increment(ref); } 810 inline void decrement( const class ConstructorExpr * node, Node::ref_type ref ) { node->decrement(ref); } 811 inline void increment( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->increment(ref); } 812 inline void decrement( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->decrement(ref); } 813 inline void increment( const class RangeExpr * node, Node::ref_type ref ) { node->increment(ref); } 814 inline void decrement( const class RangeExpr * node, Node::ref_type ref ) { node->decrement(ref); } 815 inline void increment( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->increment(ref); } 816 inline void decrement( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->decrement(ref); } 817 inline void increment( const class TupleExpr * node, Node::ref_type ref ) { node->increment(ref); } 818 inline void decrement( const class TupleExpr * node, Node::ref_type ref ) { node->decrement(ref); } 819 inline void increment( const class TupleIndexExpr * node, Node::ref_type ref ) { node->increment(ref); } 820 inline void decrement( const class TupleIndexExpr * node, Node::ref_type ref ) { node->decrement(ref); } 821 inline void increment( const class TupleAssignExpr * node, Node::ref_type ref ) { node->increment(ref); } 822 inline void decrement( const class TupleAssignExpr * node, Node::ref_type ref ) { node->decrement(ref); } 823 inline void increment( const class StmtExpr * node, Node::ref_type ref ) { node->increment(ref); } 824 inline void decrement( const class StmtExpr * node, Node::ref_type ref ) { node->decrement(ref); } 825 inline void increment( const class UniqueExpr * node, Node::ref_type ref ) { node->increment(ref); } 826 inline void decrement( const class UniqueExpr * node, Node::ref_type ref ) { node->decrement(ref); } 827 inline void increment( const class UntypedInitExpr * node, Node::ref_type ref ) { node->increment(ref); } 828 inline void decrement( const class UntypedInitExpr * node, Node::ref_type ref ) { node->decrement(ref); } 829 inline void increment( const class InitExpr * node, Node::ref_type ref ) { node->increment(ref); } 830 inline void decrement( const class InitExpr * node, Node::ref_type ref ) { node->decrement(ref); } 831 inline void increment( const class DeletedExpr * node, Node::ref_type ref ) { node->increment(ref); } 832 inline void decrement( const class DeletedExpr * node, Node::ref_type ref ) { node->decrement(ref); } 833 inline void increment( const class DefaultArgExpr * node, Node::ref_type ref ) { node->increment(ref); } 834 inline void decrement( const class DefaultArgExpr * node, Node::ref_type ref ) { node->decrement(ref); } 835 inline void increment( const class GenericExpr * node, Node::ref_type ref ) { node->increment(ref); } 836 inline void decrement( const class GenericExpr * node, Node::ref_type ref ) { node->decrement(ref); } 756 837 757 } 838 758 -
src/AST/Fwd.hpp
r9b4f329 r246c245 135 135 std::string toString( const Node * ); 136 136 137 //=================================================================================================138 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency139 /// remove only if there is a better solution140 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with141 /// forward declarations142 inline void decrement( const class Node * node, Node::ref_type ref ) { node->decrement(ref); }143 inline void increment( const class Node * node, Node::ref_type ref ) { node->increment(ref); }144 inline void increment( const class ParseNode *, Node::ref_type );145 inline void decrement( const class ParseNode *, Node::ref_type );146 inline void increment( const class Decl *, Node::ref_type );147 inline void decrement( const class Decl *, Node::ref_type );148 inline void increment( const class DeclWithType *, Node::ref_type );149 inline void decrement( const class DeclWithType *, Node::ref_type );150 inline void increment( const class ObjectDecl *, Node::ref_type );151 inline void decrement( const class ObjectDecl *, Node::ref_type );152 inline void increment( const class FunctionDecl *, Node::ref_type );153 inline void decrement( const class FunctionDecl *, Node::ref_type );154 inline void increment( const class AggregateDecl *, Node::ref_type );155 inline void decrement( const class AggregateDecl *, Node::ref_type );156 inline void increment( const class StructDecl *, Node::ref_type );157 inline void decrement( const class StructDecl *, Node::ref_type );158 inline void increment( const class UnionDecl *, Node::ref_type );159 inline void decrement( const class UnionDecl *, Node::ref_type );160 inline void increment( const class EnumDecl *, Node::ref_type );161 inline void decrement( const class EnumDecl *, Node::ref_type );162 inline void increment( const class TraitDecl *, Node::ref_type );163 inline void decrement( const class TraitDecl *, Node::ref_type );164 inline void increment( const class NamedTypeDecl *, Node::ref_type );165 inline void decrement( const class NamedTypeDecl *, Node::ref_type );166 inline void increment( const class TypeDecl *, Node::ref_type );167 inline void decrement( const class TypeDecl *, Node::ref_type );168 inline void increment( const class TypedefDecl *, Node::ref_type );169 inline void decrement( const class TypedefDecl *, Node::ref_type );170 inline void increment( const class AsmDecl *, Node::ref_type );171 inline void decrement( const class AsmDecl *, Node::ref_type );172 inline void increment( const class StaticAssertDecl *, Node::ref_type );173 inline void decrement( const class StaticAssertDecl *, Node::ref_type );174 inline void increment( const class Stmt *, Node::ref_type );175 inline void decrement( const class Stmt *, Node::ref_type );176 inline void increment( const class CompoundStmt *, Node::ref_type );177 inline void decrement( const class CompoundStmt *, Node::ref_type );178 inline void increment( const class ExprStmt *, Node::ref_type );179 inline void decrement( const class ExprStmt *, Node::ref_type );180 inline void increment( const class AsmStmt *, Node::ref_type );181 inline void decrement( const class AsmStmt *, Node::ref_type );182 inline void increment( const class DirectiveStmt *, Node::ref_type );183 inline void decrement( const class DirectiveStmt *, Node::ref_type );184 inline void increment( const class IfStmt *, Node::ref_type );185 inline void decrement( const class IfStmt *, Node::ref_type );186 inline void increment( const class WhileStmt *, Node::ref_type );187 inline void decrement( const class WhileStmt *, Node::ref_type );188 inline void increment( const class ForStmt *, Node::ref_type );189 inline void decrement( const class ForStmt *, Node::ref_type );190 inline void increment( const class SwitchStmt *, Node::ref_type );191 inline void decrement( const class SwitchStmt *, Node::ref_type );192 inline void increment( const class CaseStmt *, Node::ref_type );193 inline void decrement( const class CaseStmt *, Node::ref_type );194 inline void increment( const class BranchStmt *, Node::ref_type );195 inline void decrement( const class BranchStmt *, Node::ref_type );196 inline void increment( const class ReturnStmt *, Node::ref_type );197 inline void decrement( const class ReturnStmt *, Node::ref_type );198 inline void increment( const class ThrowStmt *, Node::ref_type );199 inline void decrement( const class ThrowStmt *, Node::ref_type );200 inline void increment( const class TryStmt *, Node::ref_type );201 inline void decrement( const class TryStmt *, Node::ref_type );202 inline void increment( const class CatchStmt *, Node::ref_type );203 inline void decrement( const class CatchStmt *, Node::ref_type );204 inline void increment( const class FinallyStmt *, Node::ref_type );205 inline void decrement( const class FinallyStmt *, Node::ref_type );206 inline void increment( const class WaitForStmt *, Node::ref_type );207 inline void decrement( const class WaitForStmt *, Node::ref_type );208 inline void increment( const class WithStmt *, Node::ref_type );209 inline void decrement( const class WithStmt *, Node::ref_type );210 inline void increment( const class DeclStmt *, Node::ref_type );211 inline void decrement( const class DeclStmt *, Node::ref_type );212 inline void increment( const class NullStmt *, Node::ref_type );213 inline void decrement( const class NullStmt *, Node::ref_type );214 inline void increment( const class ImplicitCtorDtorStmt *, Node::ref_type );215 inline void decrement( const class ImplicitCtorDtorStmt *, Node::ref_type );216 inline void increment( const class Expr *, Node::ref_type );217 inline void decrement( const class Expr *, Node::ref_type );218 inline void increment( const class ApplicationExpr *, Node::ref_type );219 inline void decrement( const class ApplicationExpr *, Node::ref_type );220 inline void increment( const class UntypedExpr *, Node::ref_type );221 inline void decrement( const class UntypedExpr *, Node::ref_type );222 inline void increment( const class NameExpr *, Node::ref_type );223 inline void decrement( const class NameExpr *, Node::ref_type );224 inline void increment( const class AddressExpr *, Node::ref_type );225 inline void decrement( const class AddressExpr *, Node::ref_type );226 inline void increment( const class LabelAddressExpr *, Node::ref_type );227 inline void decrement( const class LabelAddressExpr *, Node::ref_type );228 inline void increment( const class CastExpr *, Node::ref_type );229 inline void decrement( const class CastExpr *, Node::ref_type );230 inline void increment( const class KeywordCastExpr *, Node::ref_type );231 inline void decrement( const class KeywordCastExpr *, Node::ref_type );232 inline void increment( const class VirtualCastExpr *, Node::ref_type );233 inline void decrement( const class VirtualCastExpr *, Node::ref_type );234 inline void increment( const class MemberExpr *, Node::ref_type );235 inline void decrement( const class MemberExpr *, Node::ref_type );236 inline void increment( const class UntypedMemberExpr *, Node::ref_type );237 inline void decrement( const class UntypedMemberExpr *, Node::ref_type );238 inline void increment( const class VariableExpr *, Node::ref_type );239 inline void decrement( const class VariableExpr *, Node::ref_type );240 inline void increment( const class ConstantExpr *, Node::ref_type );241 inline void decrement( const class ConstantExpr *, Node::ref_type );242 inline void increment( const class SizeofExpr *, Node::ref_type );243 inline void decrement( const class SizeofExpr *, Node::ref_type );244 inline void increment( const class AlignofExpr *, Node::ref_type );245 inline void decrement( const class AlignofExpr *, Node::ref_type );246 inline void increment( const class UntypedOffsetofExpr *, Node::ref_type );247 inline void decrement( const class UntypedOffsetofExpr *, Node::ref_type );248 inline void increment( const class OffsetofExpr *, Node::ref_type );249 inline void decrement( const class OffsetofExpr *, Node::ref_type );250 inline void increment( const class OffsetPackExpr *, Node::ref_type );251 inline void decrement( const class OffsetPackExpr *, Node::ref_type );252 inline void increment( const class LogicalExpr *, Node::ref_type );253 inline void decrement( const class LogicalExpr *, Node::ref_type );254 inline void increment( const class ConditionalExpr *, Node::ref_type );255 inline void decrement( const class ConditionalExpr *, Node::ref_type );256 inline void increment( const class CommaExpr *, Node::ref_type );257 inline void decrement( const class CommaExpr *, Node::ref_type );258 inline void increment( const class TypeExpr *, Node::ref_type );259 inline void decrement( const class TypeExpr *, Node::ref_type );260 inline void increment( const class AsmExpr *, Node::ref_type );261 inline void decrement( const class AsmExpr *, Node::ref_type );262 inline void increment( const class ImplicitCopyCtorExpr *, Node::ref_type );263 inline void decrement( const class ImplicitCopyCtorExpr *, Node::ref_type );264 inline void increment( const class ConstructorExpr *, Node::ref_type );265 inline void decrement( const class ConstructorExpr *, Node::ref_type );266 inline void increment( const class CompoundLiteralExpr *, Node::ref_type );267 inline void decrement( const class CompoundLiteralExpr *, Node::ref_type );268 inline void increment( const class RangeExpr *, Node::ref_type );269 inline void decrement( const class RangeExpr *, Node::ref_type );270 inline void increment( const class UntypedTupleExpr *, Node::ref_type );271 inline void decrement( const class UntypedTupleExpr *, Node::ref_type );272 inline void increment( const class TupleExpr *, Node::ref_type );273 inline void decrement( const class TupleExpr *, Node::ref_type );274 inline void increment( const class TupleIndexExpr *, Node::ref_type );275 inline void decrement( const class TupleIndexExpr *, Node::ref_type );276 inline void increment( const class TupleAssignExpr *, Node::ref_type );277 inline void decrement( const class TupleAssignExpr *, Node::ref_type );278 inline void increment( const class StmtExpr *, Node::ref_type );279 inline void decrement( const class StmtExpr *, Node::ref_type );280 inline void increment( const class UniqueExpr *, Node::ref_type );281 inline void decrement( const class UniqueExpr *, Node::ref_type );282 inline void increment( const class UntypedInitExpr *, Node::ref_type );283 inline void decrement( const class UntypedInitExpr *, Node::ref_type );284 inline void increment( const class InitExpr *, Node::ref_type );285 inline void decrement( const class InitExpr *, Node::ref_type );286 inline void increment( const class DeletedExpr *, Node::ref_type );287 inline void decrement( const class DeletedExpr *, Node::ref_type );288 inline void increment( const class DefaultArgExpr *, Node::ref_type );289 inline void decrement( const class DefaultArgExpr *, Node::ref_type );290 inline void increment( const class GenericExpr *, Node::ref_type );291 inline void decrement( const class GenericExpr *, Node::ref_type );292 inline void increment( const class Type *, Node::ref_type );293 inline void decrement( const class Type *, Node::ref_type );294 inline void increment( const class VoidType *, Node::ref_type );295 inline void decrement( const class VoidType *, Node::ref_type );296 inline void increment( const class BasicType *, Node::ref_type );297 inline void decrement( const class BasicType *, Node::ref_type );298 inline void increment( const class PointerType *, Node::ref_type );299 inline void decrement( const class PointerType *, Node::ref_type );300 inline void increment( const class ArrayType *, Node::ref_type );301 inline void decrement( const class ArrayType *, Node::ref_type );302 inline void increment( const class ReferenceType *, Node::ref_type );303 inline void decrement( const class ReferenceType *, Node::ref_type );304 inline void increment( const class QualifiedType *, Node::ref_type );305 inline void decrement( const class QualifiedType *, Node::ref_type );306 inline void increment( const class FunctionType *, Node::ref_type );307 inline void decrement( const class FunctionType *, Node::ref_type );308 inline void increment( const class ReferenceToType *, Node::ref_type );309 inline void decrement( const class ReferenceToType *, Node::ref_type );310 inline void increment( const class StructInstType *, Node::ref_type );311 inline void decrement( const class StructInstType *, Node::ref_type );312 inline void increment( const class UnionInstType *, Node::ref_type );313 inline void decrement( const class UnionInstType *, Node::ref_type );314 inline void increment( const class EnumInstType *, Node::ref_type );315 inline void decrement( const class EnumInstType *, Node::ref_type );316 inline void increment( const class TraitInstType *, Node::ref_type );317 inline void decrement( const class TraitInstType *, Node::ref_type );318 inline void increment( const class TypeInstType *, Node::ref_type );319 inline void decrement( const class TypeInstType *, Node::ref_type );320 inline void increment( const class TupleType *, Node::ref_type );321 inline void decrement( const class TupleType *, Node::ref_type );322 inline void increment( const class TypeofType *, Node::ref_type );323 inline void decrement( const class TypeofType *, Node::ref_type );324 inline void increment( const class VarArgsType *, Node::ref_type );325 inline void decrement( const class VarArgsType *, Node::ref_type );326 inline void increment( const class ZeroType *, Node::ref_type );327 inline void decrement( const class ZeroType *, Node::ref_type );328 inline void increment( const class OneType *, Node::ref_type );329 inline void decrement( const class OneType *, Node::ref_type );330 inline void increment( const class GlobalScopeType *, Node::ref_type );331 inline void decrement( const class GlobalScopeType *, Node::ref_type );332 inline void increment( const class Designation *, Node::ref_type );333 inline void decrement( const class Designation *, Node::ref_type );334 inline void increment( const class Init *, Node::ref_type );335 inline void decrement( const class Init *, Node::ref_type );336 inline void increment( const class SingleInit *, Node::ref_type );337 inline void decrement( const class SingleInit *, Node::ref_type );338 inline void increment( const class ListInit *, Node::ref_type );339 inline void decrement( const class ListInit *, Node::ref_type );340 inline void increment( const class ConstructorInit *, Node::ref_type );341 inline void decrement( const class ConstructorInit *, Node::ref_type );342 inline void increment( const class Constant *, Node::ref_type );343 inline void decrement( const class Constant *, Node::ref_type );344 inline void increment( const class Attribute *, Node::ref_type );345 inline void decrement( const class Attribute *, Node::ref_type );346 inline void increment( const class TypeSubstitution *, Node::ref_type );347 inline void decrement( const class TypeSubstitution *, Node::ref_type );348 349 137 typedef unsigned int UniqueId; 350 138 -
src/AST/Init.cpp
r9b4f329 r246c245 22 22 namespace ast { 23 23 24 ListInit::ListInit( const CodeLocation& loc, std::vector<ptr<Init>>&& is, 25 std::vector<ptr<Designation>>&& ds, boolmc)24 ListInit::ListInit( const CodeLocation& loc, std::vector<ptr<Init>>&& is, 25 std::vector<ptr<Designation>>&& ds, ConstructFlag mc) 26 26 : Init( loc, mc ), initializers( std::move(is) ), designations( std::move(ds) ) { 27 // handle common case where ListInit is created without designations by making an 27 // handle common case where ListInit is created without designations by making an 28 28 // equivalent-length empty list 29 29 if ( designations.empty() ) { … … 32 32 } 33 33 } 34 34 35 35 assertf( initializers.size() == designations.size(), "Created ListInit with mismatching " 36 36 "initializers (%zd) and designations (%zd)", initializers.size(), designations.size() ); -
src/AST/Init.hpp
r9b4f329 r246c245 24 24 25 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 automutate(const node_t * node);26 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 27 27 28 28 namespace ast { … … 58 58 const Init * accept( Visitor& v ) const override = 0; 59 59 private: 60 constInit * clone() const override = 0;60 Init * clone() const override = 0; 61 61 MUTATE_FRIEND 62 62 }; … … 122 122 }; 123 123 124 125 //=================================================================================================126 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency127 /// remove only if there is a better solution128 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with129 /// forward declarations130 inline void increment( const class Init * node, Node::ref_type ref ) { node->increment( ref ); }131 inline void decrement( const class Init * node, Node::ref_type ref ) { node->decrement( ref ); }132 inline void increment( const class SingleInit * node, Node::ref_type ref ) { node->increment( ref ); }133 inline void decrement( const class SingleInit * node, Node::ref_type ref ) { node->decrement( ref ); }134 inline void increment( const class ListInit * node, Node::ref_type ref ) { node->increment( ref ); }135 inline void decrement( const class ListInit * node, Node::ref_type ref ) { node->decrement( ref ); }136 inline void increment( const class ConstructorInit * node, Node::ref_type ref ) { node->increment( ref ); }137 inline void decrement( const class ConstructorInit * node, Node::ref_type ref ) { node->decrement( ref ); }138 124 } 139 125 -
src/AST/LinkageSpec.cpp
r9b4f329 r246c245 43 43 44 44 std::string name( Spec spec ) { 45 switch ( spec ) {46 case Intrinsic : return "intrinsic";47 case C : return "C";48 case Cforall : return "Cforall";49 case AutoGen : return "autogenerated cfa";50 case Compiler : return "compiler built-in";51 case BuiltinCFA : return "cfa built-in";52 case BuiltinC : return "c built-in";45 switch ( spec.val ) { 46 case Intrinsic.val: return "intrinsic"; 47 case C.val: return "C"; 48 case Cforall.val: return "Cforall"; 49 case AutoGen.val: return "autogenerated cfa"; 50 case Compiler.val: return "compiler built-in"; 51 case BuiltinCFA.val: return "cfa built-in"; 52 case BuiltinC.val: return "c built-in"; 53 53 default: return "<unnamed linkage spec>"; 54 54 } -
src/AST/Node.hpp
r9b4f329 r246c245 44 44 }; 45 45 46 inline void increment(ref_type ref) const { 46 private: 47 /// Make a copy of this node; should be overridden in subclass with more precise return type 48 virtual Node * clone() const = 0; 49 50 /// Must be copied in ALL derived classes 51 template<typename node_t> 52 friend node_t * mutate(const node_t * node); 53 54 mutable size_t strong_count = 0; 55 mutable size_t weak_count = 0; 56 57 void increment(ref_type ref) const { 47 58 switch (ref) { 48 59 case ref_type::strong: strong_count++; break; … … 51 62 } 52 63 53 inline void decrement(ref_type ref) const {64 void decrement(ast::Node::ref_type ref) const { 54 65 switch (ref) { 55 66 case ref_type::strong: strong_count--; break; … … 61 72 } 62 73 } 63 private:64 /// Make a copy of this node; should be overridden in subclass with more precise return type65 virtual const Node * clone() const = 0;66 74 67 /// Must be copied in ALL derived classes 68 template<typename node_t> 69 friend auto mutate(const node_t * node); 70 71 mutable size_t strong_count = 0; 72 mutable size_t weak_count = 0; 75 template< typename node_t, enum Node::ref_type ref_t > 76 friend class ptr_base; 73 77 }; 74 78 … … 76 80 // problems and be able to use auto return 77 81 template<typename node_t> 78 auto mutate( const node_t * node ) { 79 assertf( 80 node->strong_count >= 1, 81 "Error: attempting to mutate a node that appears to have been linked" 82 ); 83 if (node->strong_count == 1) { 82 node_t * mutate( const node_t * node ) { 83 if (node->strong_count <= 1) { 84 84 return const_cast<node_t *>(node); 85 85 } … … 100 100 public: 101 101 ptr_base() : node(nullptr) {} 102 ptr_base( const node_t * n ) : node(n) { if( node ) increment(node, ref_t); }103 ~ptr_base() { if( node ) decrement(node, ref_t); }102 ptr_base( const node_t * n ) : node(n) { if( node ) _inc(node); } 103 ~ptr_base() { if( node ) _dec(node); } 104 104 105 105 template< enum Node::ref_type o_ref_t > 106 106 ptr_base( const ptr_base<node_t, o_ref_t> & o ) : node(o.node) { 107 if( node ) increment(node, ref_t);107 if( node ) _inc(node); 108 108 } 109 109 110 110 template< enum Node::ref_type o_ref_t > 111 111 ptr_base( ptr_base<node_t, o_ref_t> && o ) : node(o.node) { 112 if( node ) increment(node, ref_t);112 if( node ) _inc(node); 113 113 } 114 114 … … 147 147 assign( n ); 148 148 // get mutable version of `n` 149 auto r = mutate( node ); 149 auto r = mutate( node ); 150 150 // re-assign mutable version in case `mutate()` produced a new pointer 151 151 assign( r ); … … 157 157 private: 158 158 void assign( const node_t * other ) { 159 if( other ) increment(other, ref_t);160 if( node ) decrement(node , ref_t);159 if( other ) _inc(other); 160 if( node ) _dec(node ); 161 161 node = other; 162 162 } 163 164 void _inc( const node_t * other ); 165 void _dec( const node_t * other ); 163 166 164 167 protected: -
src/AST/ParseNode.hpp
r9b4f329 r246c245 34 34 35 35 ParseNode( const ParseNode& o ) = default; 36 private: 37 ParseNode * clone() const override = 0; 38 39 /// Must be copied in ALL derived classes 40 template<typename node_t> 41 friend node_t * mutate(const node_t * node); 36 42 }; 37 43 38 39 //=================================================================================================40 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency41 /// remove only if there is a better solution42 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with43 /// forward declarations44 inline void increment( const class ParseNode * node, Node::ref_type ref ) { node->increment( ref ); }45 inline void decrement( const class ParseNode * node, Node::ref_type ref ) { node->decrement( ref ); }46 44 } 47 45 -
src/AST/Pass.hpp
r9b4f329 r246c245 133 133 const ast::Expr * visit( const ast::OffsetofExpr * ) override final; 134 134 const ast::Expr * visit( const ast::OffsetPackExpr * ) override final; 135 const ast::Expr * visit( const ast::AttrExpr * ) override final;136 135 const ast::Expr * visit( const ast::LogicalExpr * ) override final; 137 136 const ast::Expr * visit( const ast::ConditionalExpr * ) override final; -
src/AST/Pass.impl.hpp
r9b4f329 r246c245 19 19 #include <type_traits> 20 20 #include <unordered_map> 21 22 #include "AST/TypeSubstitution.hpp" 21 23 22 24 #define VISIT_START( node ) \ … … 462 464 VISIT({ 463 465 guard_indexer guard { * this }; 464 maybe_accept( node, &StructDecl::param eters);465 maybe_accept( node, &StructDecl::members 466 maybe_accept( node, &StructDecl::params ); 467 maybe_accept( node, &StructDecl::members ); 466 468 }) 467 469 … … 483 485 VISIT({ 484 486 guard_indexer guard { * this }; 485 maybe_accept( node, &UnionDecl::param eters);486 maybe_accept( node, &UnionDecl::members 487 maybe_accept( node, &UnionDecl::params ); 488 maybe_accept( node, &UnionDecl::members ); 487 489 }) 488 490 … … 502 504 VISIT( 503 505 // unlike structs, traits, and unions, enums inject their members into the global scope 504 maybe_accept( node, &EnumDecl::param eters);505 maybe_accept( node, &EnumDecl::members 506 maybe_accept( node, &EnumDecl::params ); 507 maybe_accept( node, &EnumDecl::members ); 506 508 ) 507 509 … … 517 519 VISIT({ 518 520 guard_indexer guard { *this }; 519 maybe_accept( node, &TraitDecl::param eters);520 maybe_accept( node, &TraitDecl::members 521 maybe_accept( node, &TraitDecl::params ); 522 maybe_accept( node, &TraitDecl::members ); 521 523 }) 522 524 … … 534 536 VISIT({ 535 537 guard_indexer guard { *this }; 536 maybe_accept( node, &TypeDecl::param eters );537 maybe_accept( node, &TypeDecl::base 538 maybe_accept( node, &TypeDecl::params ); 539 maybe_accept( node, &TypeDecl::base ); 538 540 }) 539 541 … … 563 565 VISIT({ 564 566 guard_indexer guard { *this }; 565 maybe_accept( node, &TypedefDecl::param eters );566 maybe_accept( node, &TypedefDecl::base 567 maybe_accept( node, &TypedefDecl::params ); 568 maybe_accept( node, &TypedefDecl::base ); 567 569 }) 568 570 … … 688 690 maybe_accept( node, &WhileStmt::body ); 689 691 }) 692 693 VISIT_END( Stmt, node ); 694 } 695 696 //-------------------------------------------------------------------------- 697 // ForStmt 698 template< typename pass_t > 699 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ForStmt * node ) { 700 VISIT_START( node ); 701 702 VISIT({ 703 // for statements introduce a level of scope (for the initialization) 704 guard_indexer guard { *this }; 705 maybe_accept( node, &ForStmt::inits ); 706 maybe_accept( node, &ForStmt::cond ); 707 maybe_accept( node, &ForStmt::inc ); 708 maybe_accept( node, &ForStmt::body ); 709 }) 710 711 VISIT_END( Stmt, node ); 712 } 713 714 //-------------------------------------------------------------------------- 715 // SwitchStmt 716 template< typename pass_t > 717 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::SwitchStmt * node ) { 718 VISIT_START( node ); 719 720 VISIT( 721 maybe_accept( node, &SwitchStmt::cond ); 722 maybe_accept( node, &SwitchStmt::stmts ); 723 ) 724 725 VISIT_END( Stmt, node ); 726 } 727 728 //-------------------------------------------------------------------------- 729 // CaseStmt 730 template< typename pass_t > 731 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::CaseStmt * node ) { 732 VISIT_START( node ); 733 734 VISIT( 735 maybe_accept( node, &CaseStmt::cond ); 736 maybe_accept( node, &CaseStmt::stmts ); 737 ) 738 739 VISIT_END( Stmt, node ); 740 } 741 742 //-------------------------------------------------------------------------- 743 // BranchStmt 744 template< typename pass_t > 745 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::BranchStmt * node ) { 746 VISIT_START( node ); 747 VISIT_END( Stmt, node ); 748 } 749 750 //-------------------------------------------------------------------------- 751 // ReturnStmt 752 template< typename pass_t > 753 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ReturnStmt * node ) { 754 VISIT_START( node ); 755 756 VISIT( 757 maybe_accept( node, &ReturnStmt::expr ); 758 ) 759 760 VISIT_END( Stmt, node ); 761 } 762 763 //-------------------------------------------------------------------------- 764 // ThrowStmt 765 template< typename pass_t > 766 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ThrowStmt * node ) { 767 VISIT_START( node ); 768 769 VISIT( 770 maybe_accept( node, &ThrowStmt::expr ); 771 maybe_accept( node, &ThrowStmt::target ); 772 ) 773 774 VISIT_END( Stmt, node ); 775 } 776 777 //-------------------------------------------------------------------------- 778 // TryStmt 779 template< typename pass_t > 780 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::TryStmt * node ) { 781 VISIT_START( node ); 782 783 VISIT( 784 maybe_accept( node, &TryStmt::body ); 785 maybe_accept( node, &TryStmt::handlers ); 786 maybe_accept( node, &TryStmt::finally ); 787 ) 690 788 691 789 VISIT_END( Stmt, node ); -
src/AST/Pass.proto.hpp
r9b4f329 r246c245 247 247 static inline auto addStructFwd( pass_t & pass, int, const ast::StructDecl * decl ) -> decltype( pass.indexer.addStruct( decl ), void() ) { 248 248 ast::StructDecl * fwd = new ast::StructDecl( decl->location, decl->name ); 249 fwd->param eters = decl->parameters;249 fwd->params = decl->params; 250 250 pass.indexer.addStruct( fwd ); 251 251 } … … 257 257 static inline auto addUnionFwd( pass_t & pass, int, const ast::UnionDecl * decl ) -> decltype( pass.indexer.addUnion( decl ), void() ) { 258 258 UnionDecl * fwd = new UnionDecl( decl->location, decl->name ); 259 fwd->param eters = decl->parameters;259 fwd->params = decl->params; 260 260 pass.indexer.addUnion( fwd ); 261 261 } -
src/AST/Stmt.cpp
r9b4f329 r246c245 26 26 27 27 // --- BranchStmt 28 BranchStmt ( const CodeLocation& loc, Kind kind, Label target, std::vector<Label>&& labels )28 BranchStmt::BranchStmt( const CodeLocation& loc, Kind kind, Label target, std::vector<Label>&& labels ) 29 29 : Stmt(loc, std::move(labels)), originalTarget(target), target(target), kind(kind) { 30 30 // Make sure a syntax error hasn't slipped through. … … 34 34 const char * BranchStmt::kindNames[] = { 35 35 "Goto", "Break", "Continue", "FallThrough", "FallThroughDefault" 36 } 36 }; 37 37 38 38 } -
src/AST/Stmt.hpp
r9b4f329 r246c245 10 10 // Created On : Wed May 8 13:00:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 1 5 16:01:00 201913 // Update Count : 212 // Last Modified On : Wed May 16 12:20:00 2019 13 // Update Count : 3 14 14 // 15 15 … … 27 27 28 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 automutate(const node_t * node);29 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 30 30 31 31 namespace ast { … … 86 86 ptr<Expr> expr; 87 87 88 ExprStmt( const CodeLocation & loc, const Expr * e ) : Stmt(loc), expr(e) {} 88 ExprStmt( const CodeLocation& loc, const Expr* e, std::vector<Label>&& labels = {} ) 89 : Stmt(loc, std::move(labels)), expr(e) {} 89 90 90 91 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } … … 404 405 }; 405 406 406 //=================================================================================================407 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency408 /// remove only if there is a better solution409 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with410 /// forward declarations411 inline void increment( const class Stmt * node, Node::ref_type ref ) { node->increment( ref ); }412 inline void decrement( const class Stmt * node, Node::ref_type ref ) { node->decrement( ref ); }413 inline void increment( const class CompoundStmt * node, Node::ref_type ref ) { node->increment( ref ); }414 inline void decrement( const class CompoundStmt * node, Node::ref_type ref ) { node->decrement( ref ); }415 inline void increment( const class ExprStmt * node, Node::ref_type ref ) { node->increment( ref ); }416 inline void decrement( const class ExprStmt * node, Node::ref_type ref ) { node->decrement( ref ); }417 inline void increment( const class AsmStmt * node, Node::ref_type ref ) { node->increment( ref ); }418 inline void decrement( const class AsmStmt * node, Node::ref_type ref ) { node->decrement( ref ); }419 inline void increment( const class DirectiveStmt * node, Node::ref_type ref ) { node->increment( ref ); }420 inline void decrement( const class DirectiveStmt * node, Node::ref_type ref ) { node->decrement( ref ); }421 inline void increment( const class IfStmt * node, Node::ref_type ref ) { node->increment( ref ); }422 inline void decrement( const class IfStmt * node, Node::ref_type ref ) { node->decrement( ref ); }423 inline void increment( const class WhileStmt * node, Node::ref_type ref ) { node->increment( ref ); }424 inline void decrement( const class WhileStmt * node, Node::ref_type ref ) { node->decrement( ref ); }425 inline void increment( const class ForStmt * node, Node::ref_type ref ) { node->increment( ref ); }426 inline void decrement( const class ForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }427 inline void increment( const class SwitchStmt * node, Node::ref_type ref ) { node->increment( ref ); }428 inline void decrement( const class SwitchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }429 inline void increment( const class CaseStmt * node, Node::ref_type ref ) { node->increment( ref ); }430 inline void decrement( const class CaseStmt * node, Node::ref_type ref ) { node->decrement( ref ); }431 inline void increment( const class BranchStmt * node, Node::ref_type ref ) { node->increment( ref ); }432 inline void decrement( const class BranchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }433 inline void increment( const class ReturnStmt * node, Node::ref_type ref ) { node->increment( ref ); }434 inline void decrement( const class ReturnStmt * node, Node::ref_type ref ) { node->decrement( ref ); }435 inline void increment( const class ThrowStmt * node, Node::ref_type ref ) { node->increment( ref ); }436 inline void decrement( const class ThrowStmt * node, Node::ref_type ref ) { node->decrement( ref ); }437 inline void increment( const class TryStmt * node, Node::ref_type ref ) { node->increment( ref ); }438 inline void decrement( const class TryStmt * node, Node::ref_type ref ) { node->decrement( ref ); }439 inline void increment( const class CatchStmt * node, Node::ref_type ref ) { node->increment( ref ); }440 inline void decrement( const class CatchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }441 inline void increment( const class FinallyStmt * node, Node::ref_type ref ) { node->increment( ref ); }442 inline void decrement( const class FinallyStmt * node, Node::ref_type ref ) { node->decrement( ref ); }443 inline void increment( const class WaitForStmt * node, Node::ref_type ref ) { node->increment( ref ); }444 inline void decrement( const class WaitForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }445 inline void increment( const class WithStmt * node, Node::ref_type ref ) { node->increment( ref ); }446 inline void decrement( const class WithStmt * node, Node::ref_type ref ) { node->decrement( ref ); }447 inline void increment( const class DeclStmt * node, Node::ref_type ref ) { node->increment( ref ); }448 inline void decrement( const class DeclStmt * node, Node::ref_type ref ) { node->decrement( ref ); }449 inline void increment( const class NullStmt * node, Node::ref_type ref ) { node->increment( ref ); }450 inline void decrement( const class NullStmt * node, Node::ref_type ref ) { node->decrement( ref ); }451 inline void increment( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->increment( ref ); }452 inline void decrement( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->decrement( ref ); }453 454 407 } 455 408 -
src/AST/Type.cpp
r9b4f329 r246c245 42 42 const Type * t; 43 43 const ReferenceType * r; 44 for ( t = this; (r = dynamic_cast<const ReferenceType *>( ) ); t = r->base );44 for ( t = this; (r = dynamic_cast<const ReferenceType *>(t) ); t = r->base ); 45 45 return t; 46 46 } … … 103 103 104 104 bool FunctionType::isTtype() const { 105 return containsTtype( return Vals ) || containsTtype( parameters );105 return containsTtype( returns ) || containsTtype( params ); 106 106 } 107 107 … … 109 109 std::vector<readonly<Decl>> ReferenceToType::lookup( const std::string& name ) const { 110 110 assertf( aggr(), "Must have aggregate to perform lookup" ); 111 111 112 112 std::vector<readonly<Decl>> found; 113 113 for ( const Decl * decl : aggr()->members ) { … … 119 119 // --- StructInstType 120 120 121 StructInstType::StructInstType( const StructDecl * b, CV::Qualifiers q = {},122 std::vector<ptr<Attribute>>&& as = {})121 StructInstType::StructInstType( const StructDecl * b, CV::Qualifiers q, 122 std::vector<ptr<Attribute>>&& as ) 123 123 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {} 124 124 … … 127 127 // --- UnionInstType 128 128 129 UnionInstType::UnionInstType( const UnionDecl * b, CV::Qualifiers q = {},130 std::vector<ptr<Attribute>>&& as = {})129 UnionInstType::UnionInstType( const UnionDecl * b, CV::Qualifiers q, 130 std::vector<ptr<Attribute>>&& as ) 131 131 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {} 132 132 … … 135 135 // --- EnumInstType 136 136 137 EnumInstType::EnumInstType( const EnumDecl * b, CV::Qualifiers q = {},138 std::vector<ptr<Attribute>>&& as = {})137 EnumInstType::EnumInstType( const EnumDecl * b, CV::Qualifiers q, 138 std::vector<ptr<Attribute>>&& as ) 139 139 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {} 140 140 … … 152 152 // --- TupleType 153 153 154 TupleType::TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q = {})154 TupleType::TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q ) 155 155 : Type( q ), types( std::move(ts) ), members() { 156 // This constructor is awkward. `TupleType` needs to contain objects so that members can be 157 // named, but members without initializer nodes end up getting constructors, which breaks 158 // things. This happens because the object decls have to be visited so that their types are 159 // kept in sync with the types listed here. Ultimately, the types listed here should perhaps 160 // be eliminated and replaced with a list-view over members. The temporary solution is to 161 // make a `ListInit` with `maybeConstructed = false`, so when the object is visited it is not 156 // This constructor is awkward. `TupleType` needs to contain objects so that members can be 157 // named, but members without initializer nodes end up getting constructors, which breaks 158 // things. This happens because the object decls have to be visited so that their types are 159 // kept in sync with the types listed here. Ultimately, the types listed here should perhaps 160 // be eliminated and replaced with a list-view over members. The temporary solution is to 161 // make a `ListInit` with `maybeConstructed = false`, so when the object is visited it is not 162 162 // constructed. Potential better solutions include: 163 // a) Separate `TupleType` from its declarations, into `TupleDecl` and `Tuple{Inst?}Type`, 163 // a) Separate `TupleType` from its declarations, into `TupleDecl` and `Tuple{Inst?}Type`, 164 164 // similar to the aggregate types. 165 // b) Separate initializer nodes better, e.g. add a `MaybeConstructed` node that is replaced 165 // b) Separate initializer nodes better, e.g. add a `MaybeConstructed` node that is replaced 166 166 // by `genInit`, rather than the current boolean flag. 167 167 members.reserve( types.size() ); 168 168 for ( const Type * ty : types ) { 169 169 members.emplace_back( new ObjectDecl{ 170 CodeLocation{}, "", ty, new ListInit( CodeLocation{}, {}, {}, MaybeConstruct ), 170 CodeLocation{}, "", ty, new ListInit( CodeLocation{}, {}, {}, MaybeConstruct ), 171 171 Storage::Classes{}, Linkage::Cforall } ); 172 172 } -
src/AST/Type.hpp
r9b4f329 r246c245 30 30 31 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 automutate(const node_t * node);32 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 33 33 34 34 namespace ast { … … 37 37 public: 38 38 CV::Qualifiers qualifiers; 39 39 40 40 Type( CV::Qualifiers q = {} ) : qualifiers(q) {} 41 41 … … 80 80 public: 81 81 VoidType( CV::Qualifiers q = {} ) : Type( q ) {} 82 82 83 83 unsigned size() const override { return 0; } 84 84 bool isVoid() const override { return true; } … … 171 171 172 172 PointerType( const Type * b, CV::Qualifiers q = {} ) : Type(q), base(b), dimension() {} 173 PointerType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, 173 PointerType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, 174 174 CV::Qualifiers q = {} ) : Type(q), base(b), dimension(d), isVarLen(vl), isStatic(s) {} 175 175 … … 193 193 DimensionFlag isStatic; 194 194 195 ArrayType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, 195 ArrayType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, 196 196 CV::Qualifiers q = {} ) : Type(q), base(b), dimension(d), isVarLen(vl), isStatic(s) {} 197 197 … … 233 233 ptr<Type> child; 234 234 235 QualifiedType( const Type * p, const Type * c, CV::Qualifiers q = {} ) 235 QualifiedType( const Type * p, const Type * c, CV::Qualifiers q = {} ) 236 236 : Type(q), parent(p), child(c) {} 237 237 … … 249 249 ForallList forall; 250 250 251 ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {} ) 251 ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {} ) 252 252 : Type(q), forall(std::move(fs)) {} 253 253 ParameterizedType( CV::Qualifiers q ) : Type(q), forall() {} … … 267 267 std::vector<ptr<DeclWithType>> params; 268 268 269 /// Does the function accept a variable number of arguments following the arguments specified 269 /// Does the function accept a variable number of arguments following the arguments specified 270 270 /// in the parameters list. 271 271 /// This could be because of … … 296 296 bool hoistType = false; 297 297 298 ReferenceToType( const std::string& n, CV::Qualifiers q = {}, 298 ReferenceToType( const std::string& n, CV::Qualifiers q = {}, 299 299 std::vector<ptr<Attribute>> && as = {} ) 300 300 : ParameterizedType(q), params(), attributes(std::move(as)), name(n) {} … … 319 319 readonly<StructDecl> base; 320 320 321 StructInstType( const std::string& n, CV::Qualifiers q = {}, 321 StructInstType( const std::string& n, CV::Qualifiers q = {}, 322 322 std::vector<ptr<Attribute>> && as = {} ) 323 323 : ReferenceToType( n, q, std::move(as) ), base() {} 324 StructInstType( const StructDecl * b, CV::Qualifiers q = {}, 324 StructInstType( const StructDecl * b, CV::Qualifiers q = {}, 325 325 std::vector<ptr<Attribute>> && as = {} ); 326 326 327 327 bool isComplete() const override; 328 328 … … 342 342 readonly<UnionDecl> base; 343 343 344 UnionInstType( const std::string& n, CV::Qualifiers q = {}, 344 UnionInstType( const std::string& n, CV::Qualifiers q = {}, 345 345 std::vector<ptr<Attribute>> && as = {} ) 346 346 : ReferenceToType( n, q, std::move(as) ), base() {} 347 UnionInstType( const UnionDecl * b, CV::Qualifiers q = {}, 347 UnionInstType( const UnionDecl * b, CV::Qualifiers q = {}, 348 348 std::vector<ptr<Attribute>> && as = {} ); 349 349 350 350 bool isComplete() const override; 351 351 … … 365 365 readonly<EnumDecl> base; 366 366 367 EnumInstType( const std::string& n, CV::Qualifiers q = {}, 367 EnumInstType( const std::string& n, CV::Qualifiers q = {}, 368 368 std::vector<ptr<Attribute>> && as = {} ) 369 369 : ReferenceToType( n, q, std::move(as) ), base() {} 370 EnumInstType( const EnumDecl * b, CV::Qualifiers q = {}, 370 EnumInstType( const EnumDecl * b, CV::Qualifiers q = {}, 371 371 std::vector<ptr<Attribute>> && as = {} ); 372 372 373 373 bool isComplete() const override; 374 374 … … 388 388 readonly<TraitDecl> base; 389 389 390 TraitInstType( const std::string& n, CV::Qualifiers q = {}, 390 TraitInstType( const std::string& n, CV::Qualifiers q = {}, 391 391 std::vector<ptr<Attribute>> && as = {} ) 392 392 : ReferenceToType( n, q, std::move(as) ), base() {} 393 TraitInstType( const TraitDecl * b, CV::Qualifiers q = {}, 393 TraitInstType( const TraitDecl * b, CV::Qualifiers q = {}, 394 394 std::vector<ptr<Attribute>> && as = {} ); 395 395 396 396 // not meaningful for TraitInstType 397 397 bool isComplete() const override { assert(false); } … … 413 413 TypeVar::Kind kind; 414 414 415 TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {}, 415 TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {}, 416 416 std::vector<ptr<Attribute>> && as = {} ) 417 417 : ReferenceToType( n, q, std::move(as) ), base( b ), kind( b->kind ) {} 418 TypeInstType( const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {}, 418 TypeInstType( const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {}, 419 419 std::vector<ptr<Attribute>> && as = {} ) 420 420 : ReferenceToType( n, q, std::move(as) ), base(), kind( k ) {} … … 448 448 iterator begin() const { return types.begin(); } 449 449 iterator end() const { return types.end(); } 450 450 451 451 unsigned size() const override { return types.size(); } 452 452 453 453 const Type * getComponent( unsigned i ) override { 454 assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", 454 assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", 455 455 i, size() ); 456 456 return *(begin()+i); … … 469 469 enum Kind { Typeof, Basetypeof } kind; 470 470 471 TypeofType( const Expr * e, Kind k = Typeof, CV::Qualifiers q = {} ) 471 TypeofType( const Expr * e, Kind k = Typeof, CV::Qualifiers q = {} ) 472 472 : Type(q), expr(e), kind(k) {} 473 473 … … 482 482 public: 483 483 VarArgsType( CV::Qualifiers q = {} ) : Type( q ) {} 484 484 485 485 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 486 486 private: … … 493 493 public: 494 494 ZeroType( CV::Qualifiers q = {} ) : Type( q ) {} 495 495 496 496 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 497 497 private: … … 521 521 MUTATE_FRIEND 522 522 }; 523 524 //=================================================================================================525 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency526 /// remove only if there is a better solution.527 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with528 /// forward declarations529 inline void increment( const class Type * node, Node::ref_type ref ) { node->increment( ref ); }530 inline void decrement( const class Type * node, Node::ref_type ref ) { node->decrement( ref ); }531 inline void increment( const class VoidType * node, Node::ref_type ref ) { node->increment( ref ); }532 inline void decrement( const class VoidType * node, Node::ref_type ref ) { node->decrement( ref ); }533 inline void increment( const class BasicType * node, Node::ref_type ref ) { node->increment( ref ); }534 inline void decrement( const class BasicType * node, Node::ref_type ref ) { node->decrement( ref ); }535 inline void increment( const class PointerType * node, Node::ref_type ref ) { node->increment( ref ); }536 inline void decrement( const class PointerType * node, Node::ref_type ref ) { node->decrement( ref ); }537 inline void increment( const class ArrayType * node, Node::ref_type ref ) { node->increment( ref ); }538 inline void decrement( const class ArrayType * node, Node::ref_type ref ) { node->decrement( ref ); }539 inline void increment( const class ReferenceType * node, Node::ref_type ref ) { node->increment( ref ); }540 inline void decrement( const class ReferenceType * node, Node::ref_type ref ) { node->decrement( ref ); }541 inline void increment( const class QualifiedType * node, Node::ref_type ref ) { node->increment( ref ); }542 inline void decrement( const class QualifiedType * node, Node::ref_type ref ) { node->decrement( ref ); }543 inline void increment( const class FunctionType * node, Node::ref_type ref ) { node->increment( ref ); }544 inline void decrement( const class FunctionType * node, Node::ref_type ref ) { node->decrement( ref ); }545 inline void increment( const class ReferenceToType * node, Node::ref_type ref ) { node->increment( ref ); }546 inline void decrement( const class ReferenceToType * node, Node::ref_type ref ) { node->decrement( ref ); }547 inline void increment( const class StructInstType * node, Node::ref_type ref ) { node->increment( ref ); }548 inline void decrement( const class StructInstType * node, Node::ref_type ref ) { node->decrement( ref ); }549 inline void increment( const class UnionInstType * node, Node::ref_type ref ) { node->increment( ref ); }550 inline void decrement( const class UnionInstType * node, Node::ref_type ref ) { node->decrement( ref ); }551 inline void increment( const class EnumInstType * node, Node::ref_type ref ) { node->increment( ref ); }552 inline void decrement( const class EnumInstType * node, Node::ref_type ref ) { node->decrement( ref ); }553 inline void increment( const class TraitInstType * node, Node::ref_type ref ) { node->increment( ref ); }554 inline void decrement( const class TraitInstType * node, Node::ref_type ref ) { node->decrement( ref ); }555 inline void increment( const class TypeInstType * node, Node::ref_type ref ) { node->increment( ref ); }556 inline void decrement( const class TypeInstType * node, Node::ref_type ref ) { node->decrement( ref ); }557 inline void increment( const class TupleType * node, Node::ref_type ref ) { node->increment( ref ); }558 inline void decrement( const class TupleType * node, Node::ref_type ref ) { node->decrement( ref ); }559 inline void increment( const class TypeofType * node, Node::ref_type ref ) { node->increment( ref ); }560 inline void decrement( const class TypeofType * node, Node::ref_type ref ) { node->decrement( ref ); }561 inline void increment( const class VarArgsType * node, Node::ref_type ref ) { node->increment( ref ); }562 inline void decrement( const class VarArgsType * node, Node::ref_type ref ) { node->decrement( ref ); }563 inline void increment( const class ZeroType * node, Node::ref_type ref ) { node->increment( ref ); }564 inline void decrement( const class ZeroType * node, Node::ref_type ref ) { node->decrement( ref ); }565 inline void increment( const class OneType * node, Node::ref_type ref ) { node->increment( ref ); }566 inline void decrement( const class OneType * node, Node::ref_type ref ) { node->decrement( ref ); }567 inline void increment( const class GlobalScopeType * node, Node::ref_type ref ) { node->increment( ref ); }568 inline void decrement( const class GlobalScopeType * node, Node::ref_type ref ) { node->decrement( ref ); }569 523 570 524 } -
src/AST/porting.md
r9b4f329 r246c245 48 48 /// Must be copied in ALL derived classes 49 49 template<typename node_t> 50 friend automutate(const node_t * node);50 friend node_t * mutate(const node_t * node); 51 51 52 52 All leaves of the `Node` inheritance tree are now declared `final` -
src/Common/utility.h
r9b4f329 r246c245 463 463 std::pair<long long int, bool> eval(Expression * expr); 464 464 465 // ----------------------------------------------------------------------------- 466 /// Reorders the input range in-place so that the minimal-value elements according to the 467 /// comparator are in front; 465 namespace ast { 466 class Expr; 467 } 468 469 std::pair<long long int, bool> eval(const ast::Expr * expr); 470 471 // ----------------------------------------------------------------------------- 472 /// Reorders the input range in-place so that the minimal-value elements according to the 473 /// comparator are in front; 468 474 /// returns the iterator after the last minimal-value element. 469 475 template<typename Iter, typename Compare> 470 476 Iter sort_mins( Iter begin, Iter end, Compare& lt ) { 471 477 if ( begin == end ) return end; 472 478 473 479 Iter min_pos = begin; 474 480 for ( Iter i = begin + 1; i != end; ++i ) { -
src/Parser/ExpressionNode.cc
r9b4f329 r246c245 62 62 static inline bool checkB( char c ) { return c == 'b' || c == 'B'; } 63 63 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 64 static inline bool checkN( char c ) { return c == 'n' || c == 'N'; }64 // static inline bool checkN( char c ) { return c == 'n' || c == 'N'; } 65 65 66 66 void lnthSuffix( string & str, int & type, int & ltype ) { … … 217 217 } else { // explicit length, (length_type)constant 218 218 ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][ltype], false ), false ); 219 if ( ltype == 5 ) { // pointer, intptr( (uintptr_t)constant ) 220 ret = build_func( new ExpressionNode( build_varref( new string( "intptr" ) ) ), new ExpressionNode( ret ) ); 219 if ( ltype == 5 ) { // pointer, intptr( (uintptr_t)constant ) 220 ret = build_func( new ExpressionNode( build_varref( new string( "intptr" ) ) ), new ExpressionNode( ret ) ); 221 221 } // if 222 222 } // if -
src/SynTree/SynTree.h
r9b4f329 r246c245 34 34 class NamedTypeDecl; 35 35 class TypeDecl; 36 class FtypeDecl;37 class DtypeDecl;38 36 class TypedefDecl; 39 37 class AsmDecl;
Note: See TracChangeset
for help on using the changeset viewer.