Ignore:
Timestamp:
Aug 14, 2017, 2:03:39 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
74b007ba
Parents:
fd344aa (diff), 54cd58b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into references

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.h

    rfd344aa r9236060  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 30 16:44:00 2017
    13 // Update Count     : 41
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Aug  8 11:54:00 2017
     13// Update Count     : 44
    1414//
    1515
    16 #ifndef EXPRESSION_H
    17 #define EXPRESSION_H
     16#pragma once
    1817
    1918#include <map>
     
    3029class Expression : public BaseSyntaxNode{
    3130  public:
     31        Type * result;
     32        TypeSubstitution * env;
     33        Expression * argName; // if expression is used as an argument, it can be "designated" by this name
     34        bool extension = false;
     35
    3236        Expression( Expression * _aname = nullptr );
    3337        Expression( const Expression & other );
     
    5054        virtual Expression * acceptMutator( Mutator & m ) = 0;
    5155        virtual void print( std::ostream & os, int indent = 0 ) const;
    52   protected:
    53         Type * result;
    54         TypeSubstitution * env;
    55         Expression * argName; // if expression is used as an argument, it can be "designated" by this name
    56         bool extension = false;
    5756};
    5857
     
    8079class ApplicationExpr : public Expression {
    8180  public:
    82         ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list<Expression *>() );
     81        Expression * function;
     82
     83        ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() );
    8384        ApplicationExpr( const ApplicationExpr & other );
    8485        virtual ~ApplicationExpr();
     
    9394        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    9495        virtual void print( std::ostream & os, int indent = 0 ) const;
     96
    9597  private:
    96         Expression * function;
    9798        std::list<Expression *> args;
    9899        InferredParams inferParams;
     
    104105class UntypedExpr : public Expression {
    105106  public:
     107        Expression * function;
     108        std::list<Expression*> args;
     109
    106110        UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >(), Expression *_aname = nullptr );
    107111        UntypedExpr( const UntypedExpr & other );
     
    124128        virtual void print( std::ostream & os, int indent = 0 ) const;
    125129        virtual void printArgs(std::ostream & os, int indent = 0) const;
    126   private:
    127         Expression * function;
    128         std::list<Expression*> args;
    129130};
    130131
     
    132133class NameExpr : public Expression {
    133134  public:
     135        std::string name;
     136
    134137        NameExpr( std::string name, Expression *_aname = nullptr );
    135138        NameExpr( const NameExpr & other );
     
    143146        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    144147        virtual void print( std::ostream & os, int indent = 0 ) const;
    145   private:
    146         std::string name;
    147148};
    148149
     
    153154class AddressExpr : public Expression {
    154155  public:
     156        Expression * arg;
     157
    155158        AddressExpr( Expression * arg, Expression *_aname = nullptr );
    156159        AddressExpr( const AddressExpr & other );
     
    164167        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    165168        virtual void print( std::ostream & os, int indent = 0 ) const;
    166   private:
    167         Expression * arg;
    168169};
    169170
     
    171172class LabelAddressExpr : public Expression {
    172173  public:
     174        Expression * arg;
     175
    173176        LabelAddressExpr( Expression * arg );
    174177        LabelAddressExpr( const LabelAddressExpr & other );
     
    182185        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    183186        virtual void print( std::ostream & os, int indent = 0 ) const;
    184   private:
    185         Expression * arg;
    186187};
    187188
     
    189190class CastExpr : public Expression {
    190191  public:
     192        Expression * arg;
     193
    191194        CastExpr( Expression * arg, Expression *_aname = nullptr );
    192195        CastExpr( Expression * arg, Type * toType, Expression *_aname = nullptr );
     
    195198
    196199        Expression * get_arg() const { return arg; }
    197         void set_arg(Expression * newValue ) { arg = newValue; }
     200        void set_arg( Expression * newValue ) { arg = newValue; }
    198201
    199202        virtual CastExpr * clone() const { return new CastExpr( * this ); }
     
    201204        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    202205        virtual void print( std::ostream & os, int indent = 0 ) const;
    203   private:
     206};
     207
     208/// VirtualCastExpr repersents a virtual dynamic cast, e.g. (virtual exception)e
     209class VirtualCastExpr : public Expression {
     210  public:
    204211        Expression * arg;
     212
     213        VirtualCastExpr( Expression * arg, Type * toType );
     214        VirtualCastExpr( const VirtualCastExpr & other );
     215        virtual ~VirtualCastExpr();
     216
     217        Expression * get_arg() const { return arg; }
     218        void set_arg( Expression * newValue ) { arg = newValue; }
     219
     220        virtual VirtualCastExpr * clone() const { return new VirtualCastExpr( * this ); }
     221        virtual void accept( Visitor & v ) { v.visit( this ); }
     222        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
     223        virtual void print( std::ostream & os, int indent = 0 ) const;
    205224};
    206225
     
    208227class UntypedMemberExpr : public Expression {
    209228  public:
     229        Expression * member;
     230        Expression * aggregate;
     231
    210232        UntypedMemberExpr( Expression * member, Expression * aggregate, Expression *_aname = nullptr );
    211233        UntypedMemberExpr( const UntypedMemberExpr & other );
     
    221243        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    222244        virtual void print( std::ostream & os, int indent = 0 ) const;
    223   private:
    224         Expression * member;
    225         Expression * aggregate;
    226245};
    227246
     
    230249class MemberExpr : public Expression {
    231250  public:
     251        DeclarationWithType * member;
     252        Expression * aggregate;
     253
    232254        MemberExpr( DeclarationWithType * member, Expression * aggregate, Expression *_aname = nullptr );
    233255        MemberExpr( const MemberExpr & other );
     
    243265        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    244266        virtual void print( std::ostream & os, int indent = 0 ) const;
    245   private:
    246         DeclarationWithType * member;
    247         Expression * aggregate;
    248267};
    249268
     
    252271class VariableExpr : public Expression {
    253272  public:
     273        DeclarationWithType * var;
     274
    254275        VariableExpr( DeclarationWithType * var, Expression *_aname = nullptr );
    255276        VariableExpr( const VariableExpr & other );
     
    265286        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    266287        virtual void print( std::ostream & os, int indent = 0 ) const;
    267   private:
    268         DeclarationWithType * var;
    269288};
    270289
     
    272291class ConstantExpr : public Expression {
    273292  public:
     293        Constant constant;
     294
    274295        ConstantExpr( Constant constant, Expression *_aname = nullptr );
    275296        ConstantExpr( const ConstantExpr & other );
     
    283304        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    284305        virtual void print( std::ostream & os, int indent = 0 ) const;
    285   private:
    286         Constant constant;
    287306};
    288307
     
    290309class SizeofExpr : public Expression {
    291310  public:
     311        Expression * expr;
     312        Type * type;
     313        bool isType;
     314
    292315        SizeofExpr( Expression * expr, Expression *_aname = nullptr );
    293316        SizeofExpr( const SizeofExpr & other );
     
    306329        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    307330        virtual void print( std::ostream & os, int indent = 0 ) const;
    308   private:
     331};
     332
     333/// AlignofExpr represents an alignof expression
     334class AlignofExpr : public Expression {
     335  public:
    309336        Expression * expr;
    310337        Type * type;
    311338        bool isType;
    312 };
    313 
    314 /// AlignofExpr represents an alignof expression
    315 class AlignofExpr : public Expression {
    316   public:
     339
    317340        AlignofExpr( Expression * expr, Expression *_aname = nullptr );
    318341        AlignofExpr( const AlignofExpr & other );
     
    331354        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    332355        virtual void print( std::ostream & os, int indent = 0 ) const;
    333   private:
    334         Expression * expr;
    335         Type * type;
    336         bool isType;
    337356};
    338357
     
    340359class UntypedOffsetofExpr : public Expression {
    341360  public:
     361        Type * type;
     362        std::string member;
     363
    342364        UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr );
    343365        UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
     
    353375        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    354376        virtual void print( std::ostream & os, int indent = 0 ) const;
    355   private:
    356         Type * type;
    357         std::string member;
    358377};
    359378
     
    361380class OffsetofExpr : public Expression {
    362381  public:
     382        Type * type;
     383        DeclarationWithType * member;
     384
    363385        OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr );
    364386        OffsetofExpr( const OffsetofExpr & other );
     
    374396        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    375397        virtual void print( std::ostream & os, int indent = 0 ) const;
    376   private:
    377         Type * type;
    378         DeclarationWithType * member;
    379398};
    380399
     
    382401class OffsetPackExpr : public Expression {
    383402public:
     403        StructInstType * type;
     404
    384405        OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 );
    385406        OffsetPackExpr( const OffsetPackExpr & other );
     
    392413        virtual void accept( Visitor & v ) { v.visit( this ); }
    393414        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    394 
    395         virtual void print( std::ostream & os, int indent = 0 ) const;
    396 
    397 private:
    398         StructInstType * type;
     415        virtual void print( std::ostream & os, int indent = 0 ) const;
    399416};
    400417
     
    402419class AttrExpr : public Expression {
    403420  public:
     421        Expression * attr;
     422        Expression * expr;
     423        Type * type;
     424        bool isType;
     425
    404426        AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr );
    405427        AttrExpr( const AttrExpr & other );
     
    420442        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    421443        virtual void print( std::ostream & os, int indent = 0 ) const;
    422   private:
    423         Expression * attr;
    424         Expression * expr;
    425         Type * type;
    426         bool isType;
    427444};
    428445
     
    430447class LogicalExpr : public Expression {
    431448  public:
     449        Expression * arg1;
     450        Expression * arg2;
     451
    432452        LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr );
    433453        LogicalExpr( const LogicalExpr & other );
     
    444464        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    445465        virtual void print( std::ostream & os, int indent = 0 ) const;
     466
    446467  private:
     468        bool isAnd;
     469};
     470
     471/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
     472class ConditionalExpr : public Expression {
     473  public:
    447474        Expression * arg1;
    448475        Expression * arg2;
    449         bool isAnd;
    450 };
    451 
    452 /// ConditionalExpr represents the three-argument conditional ( p ? a : b )
    453 class ConditionalExpr : public Expression {
    454   public:
     476        Expression * arg3;
     477
    455478        ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr );
    456479        ConditionalExpr( const ConditionalExpr & other );
     
    468491        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    469492        virtual void print( std::ostream & os, int indent = 0 ) const;
    470   private:
     493};
     494
     495/// CommaExpr represents the sequence operator ( a, b )
     496class CommaExpr : public Expression {
     497  public:
    471498        Expression * arg1;
    472499        Expression * arg2;
    473         Expression * arg3;
    474 };
    475 
    476 /// CommaExpr represents the sequence operator ( a, b )
    477 class CommaExpr : public Expression {
    478   public:
     500
    479501        CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr );
    480502        CommaExpr( const CommaExpr & other );
     
    490512        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    491513        virtual void print( std::ostream & os, int indent = 0 ) const;
    492   private:
    493         Expression * arg1;
    494         Expression * arg2;
    495514};
    496515
     
    498517class TypeExpr : public Expression {
    499518  public:
     519        Type * type;
     520
    500521        TypeExpr( Type * type );
    501522        TypeExpr( const TypeExpr & other );
     
    509530        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    510531        virtual void print( std::ostream & os, int indent = 0 ) const;
    511   private:
    512         Type * type;
    513532};
    514533
     
    516535class AsmExpr : public Expression {
    517536  public:
     537        Expression * inout;
     538        ConstantExpr * constraint;
     539        Expression * operand;
     540
    518541        AsmExpr( Expression * inout, ConstantExpr * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
    519542        AsmExpr( const AsmExpr & other );
     
    533556        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    534557        virtual void print( std::ostream & os, int indent = 0 ) const;
    535   private:
     558
    536559        // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
    537         Expression * inout;
    538         ConstantExpr * constraint;
    539         Expression * operand;
    540560};
    541561
     
    544564class ImplicitCopyCtorExpr : public Expression {
    545565public:
    546         ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
    547         ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
    548         virtual ~ImplicitCopyCtorExpr();
    549 
    550         ApplicationExpr * get_callExpr() const { return callExpr; }
    551         void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
    552 
    553         std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
    554         std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
    555         std::list< Expression * > & get_dtors() { return dtors; }
    556 
    557         virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
    558         virtual void accept( Visitor & v ) { v.visit( this ); }
    559         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    560         virtual void print( std::ostream & os, int indent = 0 ) const;
    561   private:
    562566        ApplicationExpr * callExpr;
    563567        std::list< ObjectDecl * > tempDecls;
    564568        std::list< ObjectDecl * > returnDecls;
    565569        std::list< Expression * > dtors;
     570
     571        ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
     572        ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
     573        virtual ~ImplicitCopyCtorExpr();
     574
     575        ApplicationExpr * get_callExpr() const { return callExpr; }
     576        void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
     577
     578        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
     579        std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
     580        std::list< Expression * > & get_dtors() { return dtors; }
     581
     582        virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
     583        virtual void accept( Visitor & v ) { v.visit( this ); }
     584        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
     585        virtual void print( std::ostream & os, int indent = 0 ) const;
    566586};
    567587
     
    569589class ConstructorExpr : public Expression {
    570590public:
     591        Expression * callExpr;
     592
    571593        ConstructorExpr( Expression * callExpr );
    572594        ConstructorExpr( const ConstructorExpr & other );
     
    580602        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    581603        virtual void print( std::ostream & os, int indent = 0 ) const;
    582 private:
    583         Expression * callExpr;
    584604};
    585605
     
    587607class CompoundLiteralExpr : public Expression {
    588608  public:
     609        Initializer * initializer;
     610
    589611        CompoundLiteralExpr( Type * type, Initializer * initializer );
    590612        CompoundLiteralExpr( const CompoundLiteralExpr & other );
     
    598620        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    599621        virtual void print( std::ostream & os, int indent = 0 ) const;
    600   private:
    601         Initializer * initializer;
    602622};
    603623
     
    605625class RangeExpr : public Expression {
    606626  public:
     627        Expression * low, * high;
     628
    607629        RangeExpr( Expression * low, Expression * high );
    608630        RangeExpr( const RangeExpr & other );
     
    617639        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    618640        virtual void print( std::ostream & os, int indent = 0 ) const;
    619   private:
    620         Expression * low, * high;
    621641};
    622642
     
    624644class UntypedTupleExpr : public Expression {
    625645  public:
     646        std::list<Expression*> exprs;
     647
    626648        UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
    627649        UntypedTupleExpr( const UntypedTupleExpr & other );
     
    634656        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    635657        virtual void print( std::ostream & os, int indent = 0 ) const;
    636   private:
    637         std::list<Expression*> exprs;
    638658};
    639659
     
    641661class TupleExpr : public Expression {
    642662  public:
     663        std::list<Expression*> exprs;
     664
    643665        TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
    644666        TupleExpr( const TupleExpr & other );
     
    651673        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    652674        virtual void print( std::ostream & os, int indent = 0 ) const;
    653   private:
    654         std::list<Expression*> exprs;
    655675};
    656676
     
    658678class TupleIndexExpr : public Expression {
    659679  public:
     680        Expression * tuple;
     681        unsigned int index;
     682
    660683        TupleIndexExpr( Expression * tuple, unsigned int index );
    661684        TupleIndexExpr( const TupleIndexExpr & other );
     
    671694        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    672695        virtual void print( std::ostream & os, int indent = 0 ) const;
    673   private:
    674         Expression * tuple;
    675         unsigned int index;
    676696};
    677697
     
    679699class TupleAssignExpr : public Expression {
    680700  public:
     701        StmtExpr * stmtExpr = nullptr;
     702
    681703        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
    682704        TupleAssignExpr( const TupleAssignExpr & other );
     
    690712        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    691713        virtual void print( std::ostream & os, int indent = 0 ) const;
    692   private:
    693         StmtExpr * stmtExpr = nullptr;
    694714};
    695715
     
    697717class StmtExpr : public Expression {
    698718public:
     719        CompoundStmt * statements;
     720        std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
     721        std::list< Expression * > dtors; // destructor(s) for return variable(s)
     722
    699723        StmtExpr( CompoundStmt * statements );
    700724        StmtExpr( const StmtExpr & other );
     
    711735        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    712736        virtual void print( std::ostream & os, int indent = 0 ) const;
    713 private:
    714         CompoundStmt * statements;
    715         std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
    716         std::list< Expression * > dtors; // destructor(s) for return variable(s)
    717737};
    718738
    719739class UniqueExpr : public Expression {
    720740public:
     741        Expression * expr;
     742        ObjectDecl * object;
     743        VariableExpr * var;
     744
    721745        UniqueExpr( Expression * expr, long long idVal = -1 );
    722746        UniqueExpr( const UniqueExpr & other );
     
    738762        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    739763        virtual void print( std::ostream & os, int indent = 0 ) const;
     764
    740765private:
    741         Expression * expr;
    742         ObjectDecl * object;
    743         VariableExpr * var;
    744766        int id;
    745767        static long long count;
     
    758780class UntypedInitExpr : public Expression {
    759781public:
     782        Expression * expr;
     783        std::list<InitAlternative> initAlts;
     784
    760785        UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
    761786        UntypedInitExpr( const UntypedInitExpr & other );
     
    771796        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    772797        virtual void print( std::ostream & os, int indent = 0 ) const;
    773 private:
    774         Expression * expr;
    775         std::list<InitAlternative> initAlts;
    776798};
    777799
    778800class InitExpr : public Expression {
    779801public:
     802        Expression * expr;
     803        Designation * designation;
     804
    780805        InitExpr( Expression * expr, Designation * designation );
    781806        InitExpr( const InitExpr & other );
     
    792817        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    793818        virtual void print( std::ostream & os, int indent = 0 ) const;
    794 private:
    795         Expression * expr;
    796         Designation * designation;
    797819};
    798820
    799821
    800822std::ostream & operator<<( std::ostream & out, const Expression * expr );
    801 
    802 #endif // EXPRESSION_H
    803823
    804824// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.