Changeset 9b4f329 for src/AST/Expr.hpp


Ignore:
Timestamp:
May 16, 2019, 6:46:51 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
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
Message:

Finished porting AST::Expr subclasses

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.hpp

    rf3cc5b6 r9b4f329  
    491491public:
    492492        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 ); }
     500private:
     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
     507class ImplicitCopyCtorExpr final : public Expr {
     508public:
     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 ); }
     518private:
     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 };`
     524class ConstructorExpr final : public Expr {
     525public:
     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 ); }
     531private:
     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 }`
     537class CompoundLiteralExpr final : public Expr {
     538public:
     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 ); }
     544private:
     545        CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr{ *this }; }
     546        MUTATE_FRIEND
     547};
     548
     549/// A range, e.g. `3 ... 5` or `1~10`
     550class RangeExpr final : public Expr {
     551public:
     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 ); }
     559private:
     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]`
     565class UntypedTupleExpr final : public Expr {
     566public:
     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 ); }
     573private:
     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]`
     579class TupleExpr final : public Expr {
     580public:
     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 ); }
     586private:
     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
     592class TupleIndexExpr final : public Expr {
     593public:
     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 ); }
     600private:
     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;`
     610class TupleAssignExpr final : public Expr {
     611public:
     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 ); }
     619private:
     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 })`
     625class StmtExpr final : public Expr {
     626public:
     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 ); }
     637private:
     638        StmtExpr * clone() const override { return new StmtExpr{ *this }; }
     639        MUTATE_FRIEND
     640};
     641
     642/// An expression which must only be evaluated once
     643class UniqueExpr final : public Expr {
     644        static unsigned long long nextId;
     645public:
     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 ); }
     654private:
     655        UniqueExpr * clone() const override { return new UniqueExpr{ *this }; }
     656        MUTATE_FRIEND
     657};
     658
     659/// One option for resolving an initializer expression
     660struct 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
     669class UntypedInitExpr final : public Expr {
     670public:
     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 ); }
     678private:
     679        UntypedInitExpr * clone() const override { return new UntypedInitExpr{ *this }; }
     680        MUTATE_FRIEND
     681};
     682
     683/// Post-resolution initializer expression
     684class InitExpr final : public Expr {
     685public:
     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 ); }
     693private:
     694        InitExpr * clone() const override { return new InitExpr{ *this }; }
     695        MUTATE_FRIEND
     696};
     697
     698/// Expression containing a deleted identifier.
     699/// Internal to resolver.
     700class DeletedExpr final : public Expr {
     701public:
     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 ); }
     709private:
     710        DeletedExpr * clone() const override { return new DeletedExpr{ *this }; }
     711        MUTATE_FRIEND
     712};
     713
     714/// Use of a default argument.
     715/// Internal to resolver.
     716class DefaultArgExpr final : public Expr {
     717public:
     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 ); }
     724private:
     725        DefaultArgExpr * clone() const override { return new DefaultArgExpr{ *this }; }
     726        MUTATE_FRIEND
     727};
     728
     729/// C11 _Generic expression
     730class GenericExpr final : public Expr {
     731public:
     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 ); }
     751private:
     752        GenericExpr * clone() const override { return new GenericExpr{ *this }; }
     753        MUTATE_FRIEND
    494754};
    495755
     
    545805inline void increment( const class AsmExpr * node, Node::ref_type ref ) { node->increment(ref); }
    546806inline 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); }
     807inline void increment( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->increment(ref); }
     808inline void decrement( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     809inline void increment( const class ConstructorExpr * node, Node::ref_type ref ) { node->increment(ref); }
     810inline void decrement( const class ConstructorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     811inline void increment( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->increment(ref); }
     812inline void decrement( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     813inline void increment( const class RangeExpr * node, Node::ref_type ref ) { node->increment(ref); }
     814inline void decrement( const class RangeExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     815inline void increment( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->increment(ref); }
     816inline void decrement( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     817inline void increment( const class TupleExpr * node, Node::ref_type ref ) { node->increment(ref); }
     818inline void decrement( const class TupleExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     819inline void increment( const class TupleIndexExpr * node, Node::ref_type ref ) { node->increment(ref); }
     820inline void decrement( const class TupleIndexExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     821inline void increment( const class TupleAssignExpr * node, Node::ref_type ref ) { node->increment(ref); }
     822inline void decrement( const class TupleAssignExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     823inline void increment( const class StmtExpr * node, Node::ref_type ref ) { node->increment(ref); }
     824inline void decrement( const class StmtExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     825inline void increment( const class UniqueExpr * node, Node::ref_type ref ) { node->increment(ref); }
     826inline void decrement( const class UniqueExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     827inline void increment( const class UntypedInitExpr * node, Node::ref_type ref ) { node->increment(ref); }
     828inline void decrement( const class UntypedInitExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     829inline void increment( const class InitExpr * node, Node::ref_type ref ) { node->increment(ref); }
     830inline void decrement( const class InitExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     831inline void increment( const class DeletedExpr * node, Node::ref_type ref ) { node->increment(ref); }
     832inline void decrement( const class DeletedExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     833inline void increment( const class DefaultArgExpr * node, Node::ref_type ref ) { node->increment(ref); }
     834inline void decrement( const class DefaultArgExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     835inline void increment( const class GenericExpr * node, Node::ref_type ref ) { node->increment(ref); }
     836inline void decrement( const class GenericExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    579837}
    580838
Note: See TracChangeset for help on using the changeset viewer.