Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.h

    r6eb8948 r906e24d  
    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, const std::list<Expression *> &args = std::list< Expression * >(), Expression *_aname = nullptr );
     101        UntypedExpr( Expression *function, Expression *_aname = nullptr );
    101102        UntypedExpr( const UntypedExpr &other );
     103        UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = nullptr );
    102104        virtual ~UntypedExpr();
    103105
     
    199201class UntypedMemberExpr : public Expression {
    200202  public:
    201         UntypedMemberExpr( Expression *member, Expression *aggregate, Expression *_aname = nullptr );
     203        UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = nullptr );
    202204        UntypedMemberExpr( const UntypedMemberExpr &other );
    203205        virtual ~UntypedMemberExpr();
    204206
    205         Expression * get_member() const { return member; }
    206         void set_member( Expression * newValue ) { member = newValue; }
     207        std::string get_member() const { return member; }
     208        void set_member( const std::string &newValue ) { member = newValue; }
    207209        Expression *get_aggregate() const { return aggregate; }
    208210        void set_aggregate( Expression *newValue ) { aggregate = newValue; }
     
    213215        virtual void print( std::ostream &os, int indent = 0 ) const;
    214216  private:
    215         Expression *member;
     217        std::string member;
    216218        Expression *aggregate;
    217219};
     
    482484};
    483485
     486/// TupleExpr represents a tuple expression ( [a, b, c] )
     487class 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
     505class 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
    484522/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
    485523class TypeExpr : public Expression {
     
    581619        CompoundLiteralExpr( Type * type, Initializer * initializer );
    582620        CompoundLiteralExpr( const CompoundLiteralExpr &other );
    583         virtual ~CompoundLiteralExpr();
     621        ~CompoundLiteralExpr();
    584622
    585623        Type * get_type() const { return type; }
     
    633671  private:
    634672        Expression *low, *high;
    635 };
    636 
    637 /// TupleExpr represents a tuple expression ( [a, b, c] )
    638 class 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
    656 class 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
    677 class 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;
    698 class 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; })
    717 class StmtExpr : public Expression {
    718 public:
    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;
    730 private:
    731         CompoundStmt * statements;
    732673};
    733674
Note: See TracChangeset for help on using the changeset viewer.