Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.h

    rb6fe7e6 rbf32bb8  
    3232        virtual ~Expression();
    3333
    34         std::list<Type *>& get_results() { return results; }
    35         void add_result( Type *t );
     34        Type *& get_result() { return result; }
     35        void set_result( Type *newValue ) { result = newValue; }
     36        bool has_result() const { return result != nullptr; }
    3637
    3738        TypeSubstitution *get_env() const { return env; }
     
    4748        virtual void print( std::ostream &os, int indent = 0 ) const;
    4849  protected:
    49         std::list<Type *> results;
     50        Type * result;
    5051        TypeSubstitution *env;
    5152        Expression* argName; // if expression is used as an argument, it can be "designated" by this name
     
    9899class UntypedExpr : public Expression {
    99100  public:
    100         UntypedExpr( Expression *function, Expression *_aname = nullptr );
     101        UntypedExpr( Expression *function, const std::list<Expression *> &args = std::list< Expression * >(), Expression *_aname = nullptr );
    101102        UntypedExpr( const UntypedExpr &other );
    102         UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = nullptr );
    103103        virtual ~UntypedExpr();
    104104
     
    200200class UntypedMemberExpr : public Expression {
    201201  public:
    202         UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = nullptr );
     202        UntypedMemberExpr( Expression *member, Expression *aggregate, Expression *_aname = nullptr );
    203203        UntypedMemberExpr( const UntypedMemberExpr &other );
    204204        virtual ~UntypedMemberExpr();
    205205
    206         std::string get_member() const { return member; }
    207         void set_member( const std::string &newValue ) { member = newValue; }
     206        Expression * get_member() const { return member; }
     207        void set_member( Expression * newValue ) { member = newValue; }
    208208        Expression *get_aggregate() const { return aggregate; }
    209209        void set_aggregate( Expression *newValue ) { aggregate = newValue; }
     
    214214        virtual void print( std::ostream &os, int indent = 0 ) const;
    215215  private:
    216         std::string member;
     216        Expression *member;
    217217        Expression *aggregate;
    218218};
     
    483483};
    484484
    485 /// TupleExpr represents a tuple expression ( [a, b, c] )
    486 class TupleExpr : public Expression {
    487   public:
    488         TupleExpr( Expression *_aname = nullptr );
    489         TupleExpr( const TupleExpr &other );
    490         virtual ~TupleExpr();
    491 
    492         void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
    493         std::list<Expression*>& get_exprs() { return exprs; }
    494 
    495         virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
    496         virtual void accept( Visitor &v ) { v.visit( this ); }
    497         virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    498         virtual void print( std::ostream &os, int indent = 0 ) const;
    499   private:
    500         std::list<Expression*> exprs;
    501 };
    502 
    503 /// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
    504 class SolvedTupleExpr : public Expression {
    505   public:
    506         SolvedTupleExpr( Expression *_aname = nullptr ) : Expression( _aname ) {}
    507         SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = nullptr );
    508         SolvedTupleExpr( const SolvedTupleExpr &other );
    509         virtual ~SolvedTupleExpr() {}
    510 
    511         std::list<Expression*> &get_exprs() { return exprs; }
    512 
    513         virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); }
    514         virtual void accept( Visitor &v ) { v.visit( this ); }
    515         virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    516         virtual void print( std::ostream &os, int indent = 0 ) const;
    517   private:
    518         std::list<Expression*> exprs;
    519 };
    520 
    521485/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
    522486class TypeExpr : public Expression {
     
    618582        CompoundLiteralExpr( Type * type, Initializer * initializer );
    619583        CompoundLiteralExpr( const CompoundLiteralExpr &other );
    620         ~CompoundLiteralExpr();
     584        virtual ~CompoundLiteralExpr();
    621585
    622586        Type * get_type() const { return type; }
     
    670634  private:
    671635        Expression *low, *high;
     636};
     637
     638/// TupleExpr represents a tuple expression ( [a, b, c] )
     639class TupleExpr : public Expression {
     640  public:
     641        TupleExpr( const std::list< Expression * > & exprs = std::list< Expression * >(), Expression *_aname = nullptr );
     642        TupleExpr( const TupleExpr &other );
     643        virtual ~TupleExpr();
     644
     645        void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
     646        std::list<Expression*>& get_exprs() { return exprs; }
     647
     648        virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
     649        virtual void accept( Visitor &v ) { v.visit( this ); }
     650        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     651        virtual void print( std::ostream &os, int indent = 0 ) const;
     652  private:
     653        std::list<Expression*> exprs;
     654};
     655
     656/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
     657class TupleIndexExpr : public Expression {
     658  public:
     659        TupleIndexExpr( Expression * tuple, unsigned int index );
     660        TupleIndexExpr( const TupleIndexExpr &other );
     661        virtual ~TupleIndexExpr();
     662
     663        Expression * get_tuple() const { return tuple; }
     664        int get_index() const { return index; }
     665        TupleIndexExpr * set_tuple( Expression *newValue ) { tuple = newValue; return this; }
     666        TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
     667
     668        virtual TupleIndexExpr *clone() const { return new TupleIndexExpr( *this ); }
     669        virtual void accept( Visitor &v ) { v.visit( this ); }
     670        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     671        virtual void print( std::ostream &os, int indent = 0 ) const;
     672  private:
     673        Expression * tuple;
     674        unsigned int index;
     675};
     676
     677/// MemberTupleExpr represents a tuple member selection operation on a struct type, e.g. s.[a, b, c] after processing by the expression analyzer
     678class MemberTupleExpr : public Expression {
     679  public:
     680        MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname = nullptr );
     681        MemberTupleExpr( const MemberTupleExpr &other );
     682        virtual ~MemberTupleExpr();
     683
     684        Expression * get_member() const { return member; }
     685        Expression * get_aggregate() const { return aggregate; }
     686        MemberTupleExpr * set_member( Expression *newValue ) { member = newValue; return this; }
     687        MemberTupleExpr * set_aggregate( Expression *newValue ) { aggregate = newValue; return this; }
     688
     689        virtual MemberTupleExpr *clone() const { return new MemberTupleExpr( *this ); }
     690        virtual void accept( Visitor &v ) { v.visit( this ); }
     691        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     692        virtual void print( std::ostream &os, int indent = 0 ) const;
     693  private:
     694        Expression * member;
     695        Expression * aggregate;
     696};
     697
     698/// TupleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];, a mass assignment operation, where the left hand side has tuple type and the right hand side does not, e.g. [a, b, c] = 5.0;, or a tuple ctor/dtor expression
     699class TupleAssignExpr : public Expression {
     700  public:
     701        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
     702        TupleAssignExpr( const TupleAssignExpr &other );
     703        virtual ~TupleAssignExpr();
     704
     705        std::list< Expression * > & get_assigns() { return assigns; }
     706        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
     707
     708        virtual TupleAssignExpr *clone() const { return new TupleAssignExpr( *this ); }
     709        virtual void accept( Visitor &v ) { v.visit( this ); }
     710        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     711        virtual void print( std::ostream &os, int indent = 0 ) const;
     712  private:
     713        std::list< Expression * > assigns; // assignment expressions that use tempDecls
     714        std::list< ObjectDecl * > tempDecls; // temporaries for address of lhs exprs
     715};
     716
     717/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
     718class StmtExpr : public Expression {
     719public:
     720        StmtExpr( CompoundStmt *statements );
     721        StmtExpr( const StmtExpr & other );
     722        virtual ~StmtExpr();
     723
     724        CompoundStmt * get_statements() const { return statements; }
     725        StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
     726
     727        virtual StmtExpr *clone() const { return new StmtExpr( *this ); }
     728        virtual void accept( Visitor &v ) { v.visit( this ); }
     729        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     730        virtual void print( std::ostream &os, int indent = 0 ) const;
     731private:
     732        CompoundStmt * statements;
     733};
     734
     735class UniqueExpr : public Expression {
     736public:
     737        UniqueExpr( Expression * expr, long long idVal = -1 );
     738        UniqueExpr( const UniqueExpr & other );
     739        ~UniqueExpr();
     740
     741        Expression * get_expr() const { return *expr; }
     742        UniqueExpr * set_expr( Expression * newValue ) { *expr = newValue; return this; }
     743
     744        int get_id() const { return id; }
     745
     746        virtual UniqueExpr *clone() const { return new UniqueExpr( *this ); }
     747        virtual void accept( Visitor &v ) { v.visit( this ); }
     748        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     749        virtual void print( std::ostream &os, int indent = 0 ) const;
     750private:
     751        std::shared_ptr< Expression * > expr;
     752        int id;
     753        static long long count;
    672754};
    673755
Note: See TracChangeset for help on using the changeset viewer.