Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.h

    r906e24d r6eb8948  
    3232        virtual ~Expression();
    3333
    34         Type *& get_result() { return result; }
    35         void set_result( Type *newValue ) { result = newValue; }
    36         bool has_result() const { return result != nullptr; }
     34        std::list<Type *>& get_results() { return results; }
     35        void add_result( Type *t );
    3736
    3837        TypeSubstitution *get_env() const { return env; }
     
    4847        virtual void print( std::ostream &os, int indent = 0 ) const;
    4948  protected:
    50         Type * result;
     49        std::list<Type *> results;
    5150        TypeSubstitution *env;
    5251        Expression* argName; // if expression is used as an argument, it can be "designated" by this name
     
    9998class UntypedExpr : public Expression {
    10099  public:
    101         UntypedExpr( Expression *function, Expression *_aname = nullptr );
     100        UntypedExpr( Expression *function, const std::list<Expression *> &args = std::list< Expression * >(), Expression *_aname = nullptr );
    102101        UntypedExpr( const UntypedExpr &other );
    103         UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = nullptr );
    104102        virtual ~UntypedExpr();
    105103
     
    201199class UntypedMemberExpr : public Expression {
    202200  public:
    203         UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = nullptr );
     201        UntypedMemberExpr( Expression *member, Expression *aggregate, Expression *_aname = nullptr );
    204202        UntypedMemberExpr( const UntypedMemberExpr &other );
    205203        virtual ~UntypedMemberExpr();
    206204
    207         std::string get_member() const { return member; }
    208         void set_member( const std::string &newValue ) { member = newValue; }
     205        Expression * get_member() const { return member; }
     206        void set_member( Expression * newValue ) { member = newValue; }
    209207        Expression *get_aggregate() const { return aggregate; }
    210208        void set_aggregate( Expression *newValue ) { aggregate = newValue; }
     
    215213        virtual void print( std::ostream &os, int indent = 0 ) const;
    216214  private:
    217         std::string member;
     215        Expression *member;
    218216        Expression *aggregate;
    219217};
     
    484482};
    485483
    486 /// TupleExpr represents a tuple expression ( [a, b, c] )
    487 class TupleExpr : public Expression {
    488   public:
    489         TupleExpr( Expression *_aname = nullptr );
    490         TupleExpr( const TupleExpr &other );
    491         virtual ~TupleExpr();
    492 
    493         void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
    494         std::list<Expression*>& get_exprs() { return exprs; }
    495 
    496         virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
    497         virtual void accept( Visitor &v ) { v.visit( this ); }
    498         virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    499         virtual void print( std::ostream &os, int indent = 0 ) const;
    500   private:
    501         std::list<Expression*> exprs;
    502 };
    503 
    504 /// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
    505 class SolvedTupleExpr : public Expression {
    506   public:
    507         SolvedTupleExpr( Expression *_aname = nullptr ) : Expression( _aname ) {}
    508         SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = nullptr );
    509         SolvedTupleExpr( const SolvedTupleExpr &other );
    510         virtual ~SolvedTupleExpr() {}
    511 
    512         std::list<Expression*> &get_exprs() { return exprs; }
    513 
    514         virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); }
    515         virtual void accept( Visitor &v ) { v.visit( this ); }
    516         virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    517         virtual void print( std::ostream &os, int indent = 0 ) const;
    518   private:
    519         std::list<Expression*> exprs;
    520 };
    521 
    522484/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
    523485class TypeExpr : public Expression {
     
    619581        CompoundLiteralExpr( Type * type, Initializer * initializer );
    620582        CompoundLiteralExpr( const CompoundLiteralExpr &other );
    621         ~CompoundLiteralExpr();
     583        virtual ~CompoundLiteralExpr();
    622584
    623585        Type * get_type() const { return type; }
     
    671633  private:
    672634        Expression *low, *high;
     635};
     636
     637/// TupleExpr represents a tuple expression ( [a, b, c] )
     638class TupleExpr : public Expression {
     639  public:
     640        TupleExpr( Expression *_aname = nullptr );
     641        TupleExpr( const TupleExpr &other );
     642        virtual ~TupleExpr();
     643
     644        void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
     645        std::list<Expression*>& get_exprs() { return exprs; }
     646
     647        virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
     648        virtual void accept( Visitor &v ) { v.visit( this ); }
     649        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     650        virtual void print( std::ostream &os, int indent = 0 ) const;
     651  private:
     652        std::list<Expression*> exprs;
     653};
     654
     655/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
     656class TupleIndexExpr : public Expression {
     657  public:
     658        TupleIndexExpr( Expression * tuple, unsigned int index );
     659        TupleIndexExpr( const TupleIndexExpr &other );
     660        virtual ~TupleIndexExpr();
     661
     662        Expression * get_tuple() const { return tuple; }
     663        int get_index() const { return index; }
     664        TupleIndexExpr * set_tuple( Expression *newValue ) { tuple = newValue; return this; }
     665        TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
     666
     667        virtual TupleIndexExpr *clone() const { return new TupleIndexExpr( *this ); }
     668        virtual void accept( Visitor &v ) { v.visit( this ); }
     669        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     670        virtual void print( std::ostream &os, int indent = 0 ) const;
     671  private:
     672        Expression * tuple;
     673        unsigned int index;
     674};
     675
     676/// MemberTupleExpr represents a tuple member selection operation on a struct type, e.g. s.[a, b, c] after processing by the expression analyzer
     677class MemberTupleExpr : public Expression {
     678  public:
     679        MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname = nullptr );
     680        MemberTupleExpr( const MemberTupleExpr &other );
     681        virtual ~MemberTupleExpr();
     682
     683        Expression * get_member() const { return member; }
     684        Expression * get_aggregate() const { return aggregate; }
     685        MemberTupleExpr * set_member( Expression *newValue ) { member = newValue; return this; }
     686        MemberTupleExpr * set_aggregate( Expression *newValue ) { aggregate = newValue; return this; }
     687
     688        virtual MemberTupleExpr *clone() const { return new MemberTupleExpr( *this ); }
     689        virtual void accept( Visitor &v ) { v.visit( this ); }
     690        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     691        virtual void print( std::ostream &os, int indent = 0 ) const;
     692  private:
     693        Expression * member;
     694        Expression * aggregate;
     695};
     696
     697/// TupleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];, or 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;
     698class TupleAssignExpr : public Expression {
     699  public:
     700        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
     701        TupleAssignExpr( const TupleAssignExpr &other );
     702        virtual ~TupleAssignExpr();
     703
     704        std::list< Expression * > & get_assigns() { return assigns; }
     705        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
     706
     707        virtual TupleAssignExpr *clone() const { return new TupleAssignExpr( *this ); }
     708        virtual void accept( Visitor &v ) { v.visit( this ); }
     709        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     710        virtual void print( std::ostream &os, int indent = 0 ) const;
     711  private:
     712        std::list< Expression * > assigns; // assignment expressions that use tempDecls
     713        std::list< ObjectDecl * > tempDecls; // temporaries for address of lhs exprs
     714};
     715
     716/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
     717class StmtExpr : public Expression {
     718public:
     719        StmtExpr( CompoundStmt *statements );
     720        StmtExpr( const StmtExpr & other );
     721        virtual ~StmtExpr();
     722
     723        CompoundStmt * get_statements() const { return statements; }
     724        StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
     725
     726        virtual StmtExpr *clone() const { return new StmtExpr( *this ); }
     727        virtual void accept( Visitor &v ) { v.visit( this ); }
     728        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     729        virtual void print( std::ostream &os, int indent = 0 ) const;
     730private:
     731        CompoundStmt * statements;
    673732};
    674733
Note: See TracChangeset for help on using the changeset viewer.