Changeset 9b4f329
- Timestamp:
- May 16, 2019, 6:46:51 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:
- 246c245
- Parents:
- f3cc5b6
- Location:
- src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/AST/Expr.cpp ¶
rf3cc5b6 r9b4f329 20 20 #include <vector> 21 21 22 #include "Stmt.hpp" 22 23 #include "Type.hpp" 23 24 #include "Common/SemanticError.h" … … 25 26 #include "InitTweak/InitTweak.h" // for getPointerBase 26 27 #include "ResolvExpr/typeops.h" // for extractResultType 28 #include "Tuples/Tuples.h" // for makeTupleType 27 29 28 30 namespace ast { … … 287 289 : Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {} 288 290 291 // --- ConstructorExpr 292 293 ConstructorExpr::ConstructorExpr( const CodeLocation & loc, const Expr * call ) 294 : Expr( loc ), callExpr( call ) { 295 // allow resolver to type a constructor used as an expression if it has the same type as its 296 // first argument 297 assert( callExpr ); 298 const Expr * arg = InitTweak::getCallArg( callExpr, 0 ); 299 assert( arg ); 300 result = arg->result; 301 } 302 303 // --- CompoundLiteralExpr 304 305 CompoundLiteralExpr::CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i ) 306 : Expr( loc ), init( i ) { 307 assert( t && i ); 308 result.set_and_mutate( t )->set_lvalue( true ); 309 } 310 311 // --- TupleExpr 312 313 TupleExpr::TupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs ) 314 : Expr( loc, Tuples::makeTupleType( xs ) ), exprs( xs ) {} 315 316 // --- TupleIndexExpr 317 318 TupleIndexExpr::TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i ) 319 : Expr( loc ), tuple( t ), index( i ) { 320 const TupleType * type = strict_dynamic_cast< const TupleType * >( tuple->result ); 321 assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested " 322 "index %d in expr %s", type->size(), index, toString( tuple ).c_str() ); 323 // like MemberExpr, TupleIndexExpr is always an lvalue 324 result.set_and_mutate( type->types[ index ] )->set_lvalue( true ); 325 } 326 327 // --- TupleAssignExpr 328 329 TupleAssignExpr::TupleAssignExpr( 330 const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, 331 std::vector<ptr<ObjectDecl>> && tempDecls ) 332 : Expr( loc, Tuples::makeTupleType( assigns ) ), stmtExpr() { 333 // convert internally into a StmtExpr which contains the declarations and produces the tuple of 334 // the assignments 335 std::list<ptr<Stmt>> stmts; 336 for ( const ObjectDecl * obj : tempDecls ) { 337 stmts.emplace_back( new DeclStmt{ loc, obj } ); 338 } 339 TupleExpr * tupleExpr = new TupleExpr{ loc, std::move(assigns) }; 340 assert( tupleExpr->result ); 341 stmts.emplace_back( new ExprStmt{ loc, tupleExpr } ); 342 stmtExpr = new StmtExpr{ loc, new CompoundStmt{ loc, std::move(stmts) } }; 343 } 344 345 // --- StmtExpr 346 347 StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss ) 348 : Expr( loc ), stmts( ss ), returnDecls(), dtors() { computeResult(); } 349 350 void StmtExpr::computeResult() { 351 assert( stmts ); 352 const std::list<ptr<Stmt>> & body = stmts->kids; 353 if ( ! returnDecls.empty() ) { 354 // prioritize return decl for result type, since if a return decl exists, then the StmtExpr 355 // is currently in an intermediate state where the body will always give a void result type 356 result = returnDecls.front()->get_type(); 357 } else if ( ! body.empty() ) { 358 if ( const ExprStmt * exprStmt = body.back().as< ExprStmt >() ) { 359 result = exprStmt->expr->result; 360 } 361 } 362 // ensure a result type exists 363 if ( ! result ) { result = new VoidType{}; } 364 } 365 366 // --- UniqueExpr 367 368 unsigned long long UniqueExpr::nextId = 0; 369 370 UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i = -1 ) 371 : Expr( loc, e->result ), id( i ) { 372 assert( expr ); 373 if ( id == -1 ) { 374 assert( nextId != -1 ); 375 id = nextId++; 376 } 289 377 } 290 378 -
TabularUnified src/AST/Expr.hpp ¶
rf3cc5b6 r9b4f329 491 491 public: 492 492 ptr<Expr> inout; 493 ptr<Expr> constraint; 493 ptr<Expr> constraint; 494 ptr<Expr> operand; 495 496 AsmExpr( const CodeLocation & loc, const Expr * io, const Expr * con, const Expr * op ) 497 : Expr( loc ), inout( io ), constraint( con ), operand( op ) {} 498 499 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 500 private: 501 AsmExpr * clone() const override { return new AsmExpr{ *this }; } 502 MUTATE_FRIEND 503 }; 504 505 /// The application of a function to a set of parameters, along with a set of copy constructor 506 /// calls, one for each argument 507 class ImplicitCopyCtorExpr final : public Expr { 508 public: 509 ptr<ApplicationExpr> callExpr; 510 std::vector<ptr<ObjectDecl>> tempDecls; 511 std::vector<ptr<ObjectDecl>> returnDecls; 512 std::vector<ptr<ObjectDecl>> dtors; 513 514 ImplicitCopyCtorExpr( const CodeLocation& loc, const ApplicationExpr * call ) 515 : Expr( loc, call->result ), tempDecls(), returnDecls(), dtors() { assert( call ); } 516 517 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 518 private: 519 ImplicitCopyCtorExpr * clone() const override { return new ImplicitCopyCtorExpr{ *this }; } 520 MUTATE_FRIEND 521 }; 522 523 /// Constructor in expression context, e.g. `int * x = alloc() { 42 };` 524 class ConstructorExpr final : public Expr { 525 public: 526 ptr<Expr> callExpr; 527 528 ConstructorExpr( const CodeLocation & loc, const Expr * call ); 529 530 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 531 private: 532 ConstructorExpr * clone() const override { return new ConstructorExpr{ *this }; } 533 MUTATE_FRIEND 534 }; 535 536 /// A C99 compound literal, e.g. `(MyType){ a, b, c }` 537 class CompoundLiteralExpr final : public Expr { 538 public: 539 ptr<Init> init; 540 541 CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i ); 542 543 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 544 private: 545 CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr{ *this }; } 546 MUTATE_FRIEND 547 }; 548 549 /// A range, e.g. `3 ... 5` or `1~10` 550 class RangeExpr final : public Expr { 551 public: 552 ptr<Expr> low; 553 ptr<Expr> high; 554 555 RangeExpr( const CodeLocation & loc, const Expr * l, const Expr * h ) 556 : Expr( loc ), low( l ), high( h ) {} 557 558 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 559 private: 560 RangeExpr * clone() const override { return new RangeExpr{ *this }; } 561 MUTATE_FRIEND 562 }; 563 564 /// A tuple expression before resolution, e.g. `[a, b, c]` 565 class UntypedTupleExpr final : public Expr { 566 public: 567 std::vector<ptr<Expr>> exprs; 568 569 UntypedTupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs ) 570 : Expr( loc ), exprs( std::move(xs) ) {} 571 572 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 573 private: 574 UntypedTupleExpr * clone() const override { return new UntypedTupleExpr{ *this }; } 575 MUTATE_FRIEND 576 }; 577 578 /// A tuple expression after resolution, e.g. `[a, b, c]` 579 class TupleExpr final : public Expr { 580 public: 581 std::vector<ptr<Expr>> exprs; 582 583 TupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs ); 584 585 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 586 private: 587 TupleExpr * clone() const override { return new TupleExpr{ *this }; } 588 MUTATE_FRIEND 589 }; 590 591 /// An element selection operation on a tuple value, e.g. `t.3` after analysis 592 class TupleIndexExpr final : public Expr { 593 public: 594 ptr<Expr> tuple; 595 unsigned index; 596 597 TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i ); 598 599 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 600 private: 601 TupleIndexExpr * clone() const override { return new TupleIndexExpr{ *this }; } 602 MUTATE_FRIEND 603 }; 604 605 /// A multiple- or mass-assignment operation, or a tuple ctor/dtor expression. 606 /// multiple-assignment: both sides of the assignment have tuple type, 607 /// e.g. `[a, b, c] = [d, e, f];` 608 /// mass-assignment: left-hand side has tuple type and right-hand side does not: 609 /// e.g. `[a, b, c] = 42;` 610 class TupleAssignExpr final : public Expr { 611 public: 612 ptr<StmtExpr> stmtExpr; 613 614 TupleAssignExpr( 615 const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, 616 std::vector<ptr<ObjectDecl>> && tempDecls ); 617 618 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 619 private: 620 TupleAssignExpr * clone() const override { return new TupleAssignExpr{ *this }; } 621 MUTATE_FRIEND 622 }; 623 624 /// A GCC "statement expression", e.g. `({ int x = 5; x })` 625 class StmtExpr final : public Expr { 626 public: 627 ptr<CompoundStmt> stmts; 628 std::vector<ptr<ObjectDecl>> returnDecls; ///< return variable(s) for statement expression 629 std::vector<ptr<Expr>> dtors; ///< destructor(s) for return variable(s) 630 631 StmtExpr( const CodeLocation & loc, const CompoundStmt * ss ); 632 633 /// Set the result type of this StmtExpr based on its body 634 void computeResult(); 635 636 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 637 private: 638 StmtExpr * clone() const override { return new StmtExpr{ *this }; } 639 MUTATE_FRIEND 640 }; 641 642 /// An expression which must only be evaluated once 643 class UniqueExpr final : public Expr { 644 static unsigned long long nextId; 645 public: 646 ptr<Expr> expr; 647 ptr<ObjectDecl> object; 648 ptr<VariableExpr> var; 649 unsigned long long id; 650 651 UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i = -1 ); 652 653 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 654 private: 655 UniqueExpr * clone() const override { return new UniqueExpr{ *this }; } 656 MUTATE_FRIEND 657 }; 658 659 /// One option for resolving an initializer expression 660 struct InitAlternative { 661 ptr<Type> type; 662 ptr<Designation> designation; 663 664 InitAlternative() = default; 665 InitAlternative( const Type * ty, const Designation * des ) : type( ty ), designation( des ) {} 666 }; 667 668 /// Pre-resolution initializer expression 669 class UntypedInitExpr final : public Expr { 670 public: 671 ptr<Expr> expr; 672 std::vector<InitAlternative> initAlts; 673 674 UntypedInitExpr( const CodeLocation & loc, const Expr * e, std::vector<InitAlternative> && as ) 675 : Expr( loc ), expr( e ), initAlts( std::move(as) ) {} 676 677 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 678 private: 679 UntypedInitExpr * clone() const override { return new UntypedInitExpr{ *this }; } 680 MUTATE_FRIEND 681 }; 682 683 /// Post-resolution initializer expression 684 class InitExpr final : public Expr { 685 public: 686 ptr<Expr> expr; 687 ptr<Designation> designation; 688 689 InitExpr( const CodeLocation & loc, const Expr * e, const Designation * des ) 690 : Expr( loc, e->result ), expr( e ), designation( des ) {} 691 692 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 693 private: 694 InitExpr * clone() const override { return new InitExpr{ *this }; } 695 MUTATE_FRIEND 696 }; 697 698 /// Expression containing a deleted identifier. 699 /// Internal to resolver. 700 class DeletedExpr final : public Expr { 701 public: 702 ptr<Expr> expr; 703 readonly<Node> deleteStmt; 704 705 DeletedExpr( const CodeLocation & loc, const Expr * e, const Node * del ) 706 : Expr( loc, e->result ), expr( e ), deleteStmt( del ) { assert( expr->result ); } 707 708 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 709 private: 710 DeletedExpr * clone() const override { return new DeletedExpr{ *this }; } 711 MUTATE_FRIEND 712 }; 713 714 /// Use of a default argument. 715 /// Internal to resolver. 716 class DefaultArgExpr final : public Expr { 717 public: 718 ptr<Expr> expr; 719 720 DefaultArgExpr( const CodeLocation & loc, const Expr * e ) 721 : Expr( loc, e->result ), expr( e ) { assert( e->result ); } 722 723 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 724 private: 725 DefaultArgExpr * clone() const override { return new DefaultArgExpr{ *this }; } 726 MUTATE_FRIEND 727 }; 728 729 /// C11 _Generic expression 730 class GenericExpr final : public Expr { 731 public: 732 /// One arm of the _Generic expr 733 struct Association { 734 ptr<Type> type; 735 ptr<Expr> expr; 736 737 Association() = default; 738 // default case 739 Association( const Expr * e ) : type(), expr( e ) {} 740 // non-default case 741 Association( const Type * t, const Expr * e ) : type( t ), expr( e ) {} 742 }; 743 744 ptr<Expr> control; 745 std::vector<Association> associations; 746 747 GenericExpr( const CodeLocation & loc, const Expr * ctrl, std::vector<Association> && assns ) 748 : Expr( loc ), control( ctrl ), associations( std::move(assns) ) {} 749 750 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 751 private: 752 GenericExpr * clone() const override { return new GenericExpr{ *this }; } 753 MUTATE_FRIEND 494 754 }; 495 755 … … 545 805 inline void increment( const class AsmExpr * node, Node::ref_type ref ) { node->increment(ref); } 546 806 inline void decrement( const class AsmExpr * node, Node::ref_type ref ) { node->decrement(ref); } 547 // inline void increment( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->increment(ref); } 548 // inline void decrement( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->decrement(ref); } 549 // inline void increment( const class ConstructorExpr * node, Node::ref_type ref ) { node->increment(ref); } 550 // inline void decrement( const class ConstructorExpr * node, Node::ref_type ref ) { node->decrement(ref); } 551 // inline void increment( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->increment(ref); } 552 // inline void decrement( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->decrement(ref); } 553 // inline void increment( const class UntypedValofExpr * node, Node::ref_type ref ) { node->increment(ref); } 554 // inline void decrement( const class UntypedValofExpr * node, Node::ref_type ref ) { node->decrement(ref); } 555 // inline void increment( const class RangeExpr * node, Node::ref_type ref ) { node->increment(ref); } 556 // inline void decrement( const class RangeExpr * node, Node::ref_type ref ) { node->decrement(ref); } 557 // inline void increment( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->increment(ref); } 558 // inline void decrement( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->decrement(ref); } 559 // inline void increment( const class TupleExpr * node, Node::ref_type ref ) { node->increment(ref); } 560 // inline void decrement( const class TupleExpr * node, Node::ref_type ref ) { node->decrement(ref); } 561 // inline void increment( const class TupleIndexExpr * node, Node::ref_type ref ) { node->increment(ref); } 562 // inline void decrement( const class TupleIndexExpr * node, Node::ref_type ref ) { node->decrement(ref); } 563 // inline void increment( const class TupleAssignExpr * node, Node::ref_type ref ) { node->increment(ref); } 564 // inline void decrement( const class TupleAssignExpr * node, Node::ref_type ref ) { node->decrement(ref); } 565 // inline void increment( const class StmtExpr * node, Node::ref_type ref ) { node->increment(ref); } 566 // inline void decrement( const class StmtExpr * node, Node::ref_type ref ) { node->decrement(ref); } 567 // inline void increment( const class UniqueExpr * node, Node::ref_type ref ) { node->increment(ref); } 568 // inline void decrement( const class UniqueExpr * node, Node::ref_type ref ) { node->decrement(ref); } 569 // inline void increment( const class UntypedInitExpr * node, Node::ref_type ref ) { node->increment(ref); } 570 // inline void decrement( const class UntypedInitExpr * node, Node::ref_type ref ) { node->decrement(ref); } 571 // inline void increment( const class InitExpr * node, Node::ref_type ref ) { node->increment(ref); } 572 // inline void decrement( const class InitExpr * node, Node::ref_type ref ) { node->decrement(ref); } 573 // inline void increment( const class DeletedExpr * node, Node::ref_type ref ) { node->increment(ref); } 574 // inline void decrement( const class DeletedExpr * node, Node::ref_type ref ) { node->decrement(ref); } 575 // inline void increment( const class DefaultArgExpr * node, Node::ref_type ref ) { node->increment(ref); } 576 // inline void decrement( const class DefaultArgExpr * node, Node::ref_type ref ) { node->decrement(ref); } 577 // inline void increment( const class GenericExpr * node, Node::ref_type ref ) { node->increment(ref); } 578 // inline void decrement( const class GenericExpr * 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); } 579 837 } 580 838 -
TabularUnified src/AST/Fwd.hpp ¶
rf3cc5b6 r9b4f329 85 85 class ConstructorExpr; 86 86 class CompoundLiteralExpr; 87 class UntypedValofExpr;88 87 class RangeExpr; 89 88 class UntypedTupleExpr; … … 267 266 inline void increment( const class CompoundLiteralExpr *, Node::ref_type ); 268 267 inline void decrement( const class CompoundLiteralExpr *, Node::ref_type ); 269 inline void increment( const class UntypedValofExpr *, Node::ref_type );270 inline void decrement( const class UntypedValofExpr *, Node::ref_type );271 268 inline void increment( const class RangeExpr *, Node::ref_type ); 272 269 inline void decrement( const class RangeExpr *, Node::ref_type ); -
TabularUnified src/AST/Type.hpp ¶
rf3cc5b6 r9b4f329 23 23 24 24 #include "CVQualifiers.hpp" 25 #include "Decl.hpp" 25 #include "Decl.hpp" // for AggregateDecl subclasses 26 26 #include "Fwd.hpp" 27 27 #include "Node.hpp" // for Node, ptr -
TabularUnified src/AST/porting.md ¶
rf3cc5b6 r9b4f329 68 68 * prefer `#pragma once` over `#ifdef` guards 69 69 * namespaces that cover entire files don't get indented 70 * The general node headers only `#include "Fwd.hpp"` if they can get away with it 71 * Anything that needs definitions goes in the .cpp file 72 * `Type.hpp` includes `Decl.hpp` so that it knows the `AggregateDecl` subclasses for `ReferenceToType::aggr()` overloads 70 73 71 74 ### Documentation ### … … 166 169 * un-defaulted constructor parameter determining `&&` or `||` 167 170 171 `CompoundLiteralExpr` 172 * `initializer` => `init` 173 174 `RangeExpr` 175 * removed `set_low`, `set_high` due to disuse 176 177 `TupleIndexExpr` 178 * removed `set_tuple`, `set_index` due to disuse 179 180 `GenericExpr` 181 * `Association::isDefault` removed: `! type` is equivalent 182 183 `StmtExpr` 184 * `statements` => `stmts` 185 168 186 `Init` 169 187 * `bool maybeConstruct` => `enum ConstructFlag { DoConstruct, MaybeConstruct }` -
TabularUnified src/InitTweak/InitTweak.cc ¶
rf3cc5b6 r9b4f329 5 5 #include <memory> // for __shared_ptr 6 6 7 #include "AST/Expr.hpp" 8 #include "AST/Stmt.hpp" 7 9 #include "AST/Type.hpp" 8 10 #include "Common/PassVisitor.h" … … 27 29 #include "Tuples/Tuples.h" // for Tuples::isTtype 28 30 29 class UntypedValofExpr;30 31 31 namespace InitTweak { 32 32 namespace { … … 433 433 assert( false ); 434 434 } 435 436 // template<typename CallExpr> 437 // const ast::Expr * callArg( const CallExpr * call, unsigned int pos ) { 438 // if( pos >= call->args.size() ) { 439 // assertf( false, "getCallArg for argument that doesn't exist: (%u); %s.", 440 // pos, toString( call ).c_str() ); 441 // } 442 // for ( const ast::Expr * arg : call->args ) { 443 // if ( pos == 0 ) return arg; 444 // --pos; 445 // } 446 // assert( false ); 447 // } 435 448 } 436 449 … … 452 465 assertf( false, "Unexpected expression type passed to getCallArg: %s", toString( callExpr ).c_str() ); 453 466 } 467 } 468 const ast::Expr * getCallArg( const ast::Expr * call, unsigned pos ) { 469 assert(!"implemented; needs to build AST/Expr.cpp"); 470 // if ( auto app = dynamic_cast< const ast::ApplicationExpr * >( call ) ) { 471 // return callArg( app, pos ); 472 // } else if ( auto untyped = dynamic_cast< const ast::UntypedExpr * >( call ) ) { 473 // return callArg( untyped, pos ); 474 // } else if ( auto tupleAssn = dynamic_cast< const ast::TupleAssignExpr * >( call ) ) { 475 // const std::list<ast::ptr<ast::Stmt>>& stmts = tupleAssn->stmtExpr->stmts->kids; 476 // assertf( ! stmts.empty(), "TupleAssignExpr missing statements." ); 477 // const ExprStmt * stmt = strict_dynamic_cast< const ast::ExprStmt * >( stmts.back() ); 478 // const TupleExpr * tuple = strict_dynamic_cast< const ast::TupleExpr * >( stmt->expr ); 479 // assertf( ! tuple->exprs.empty(), "TupleAssignExpr has empty tuple expr."); 480 // return getCallArg( tuple->exprs.front(), pos ); 481 // } else if ( auto ctor = dynamic_cast< const ast::ImplicitCopyCtorExpr * >( call ) ) { 482 // return getCallArg( ctor->callExpr, pos ); 483 // } else { 484 // assertf( false, "Unexpected expression type passed to getCallArg: %s", 485 // toString( call ).c_str() ); 486 // } 454 487 } 455 488 … … 516 549 const ast::Type* getPointerBase( const ast::Type* t ) { 517 550 assert(!"needs to build Type.cpp before inclusion"); 518 // if ( const a st::PointerType* p = dynamic_cast< const ast::PointerType* >( t ) ) {551 // if ( const auto * p = dynamic_cast< const ast::PointerType * >( t ) ) { 519 552 // return p->base; 520 // } else if ( const a st::ArrayType* a = dynamic_cast< const ast::ArrayType* >( t ) ) {553 // } else if ( const auto * a = dynamic_cast< const ast::ArrayType * >( t ) ) { 521 554 // return a->base; 522 // } else if ( const a st::ReferenceType* r = dynamic_cast< const ast::ReferenceType* >( t ) ) {555 // } else if ( const auto * r = dynamic_cast< const ast::ReferenceType * >( t ) ) { 523 556 // return r->base; 524 557 // } else return nullptr; -
TabularUnified src/InitTweak/InitTweak.h ¶
rf3cc5b6 r9b4f329 81 81 /// returns the argument to a call expression in position N indexed from 0 82 82 Expression *& getCallArg( Expression * callExpr, unsigned int pos ); 83 const ast::Expr * getCallArg( const ast::Expr * call, unsigned pos ); 83 84 84 85 /// returns the base type of a PointerType or ArrayType, else returns NULL -
TabularUnified src/SynTree/SynTree.h ¶
rf3cc5b6 r9b4f329 90 90 class ConstructorExpr; 91 91 class CompoundLiteralExpr; 92 class UntypedValofExpr;93 92 class RangeExpr; 94 93 class UntypedTupleExpr; -
TabularUnified src/Tuples/TupleExpansion.cc ¶
rf3cc5b6 r9b4f329 17 17 #include <cassert> // for assert 18 18 #include <list> // for list 19 19 #include <vector> 20 21 #include "AST/CVQualifiers.hpp" 22 #include "AST/Expr.hpp" 23 #include "AST/Node.hpp" 24 #include "AST/Type.hpp" 20 25 #include "Common/PassVisitor.h" // for PassVisitor, WithDeclsToAdd, WithGu... 21 26 #include "Common/ScopedMap.h" // for ScopedMap … … 314 319 return new TupleType( qualifiers, types ); 315 320 } 321 const ast::Type * makeTupleType( const std::vector<ast::ptr<ast::Expr>> & exprs ) { 322 assert(!"implemented; needs Type.cpp in build"); 323 // // produce the TupleType which aggregates the types of the exprs 324 // std::vector<ast::ptr<ast::Type>> types; 325 // ast::CV::Qualifiers quals{ 326 // ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Lvalue | 327 // ast::CV::Atomic | ast::CV::Mutex }; 328 329 // for ( const ast::Expr * expr : exprs ) { 330 // assert( expr->result ); 331 // // if the type of any expr is void, the type of the entire tuple is void 332 // if ( expr->result->isVoid() ) return new ast::VoidType{}; 333 334 // // qualifiers on the tuple type are the qualifiers that exist on all components 335 // quals &= expr->result->qualifiers; 336 337 // types.emplace_back( expr->result ); 338 // } 339 340 // if ( exprs.empty() ) { quals = ast::CV::Qualifiers{}; } 341 // return new ast::TupleType{ std::move(types), quals }; 342 } 316 343 317 344 TypeInstType * isTtype( Type * type ) { -
TabularUnified src/Tuples/Tuples.h ¶
rf3cc5b6 r9b4f329 19 19 #include <vector> 20 20 21 #include "AST/Fwd.hpp" 22 #include "AST/Node.hpp" 21 23 #include "SynTree/Expression.h" 22 24 #include "SynTree/Declaration.h" … … 42 44 /// returns VoidType if any of the expressions have Voidtype, otherwise TupleType of the Expression result types 43 45 Type * makeTupleType( const std::list< Expression * > & exprs ); 46 const ast::Type * makeTupleType( const std::vector<ast::ptr<ast::Expr>> & exprs ); 44 47 45 48 /// returns a TypeInstType if `type` is a ttype, nullptr otherwise
Note: See TracChangeset
for help on using the changeset viewer.