Ignore:
Timestamp:
Aug 11, 2017, 10:33:37 AM (8 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:
54cd58b0
Parents:
3d4b23fa (diff), 59a75cb (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' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.h

    r3d4b23fa r0720e049  
    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 );
     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 );
     
    263284        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    264285        virtual void print( std::ostream & os, int indent = 0 ) const;
    265   private:
    266         DeclarationWithType * var;
    267286};
    268287
     
    270289class ConstantExpr : public Expression {
    271290  public:
     291        Constant constant;
     292
    272293        ConstantExpr( Constant constant, Expression *_aname = nullptr );
    273294        ConstantExpr( const ConstantExpr & other );
     
    281302        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    282303        virtual void print( std::ostream & os, int indent = 0 ) const;
    283   private:
    284         Constant constant;
    285304};
    286305
     
    288307class SizeofExpr : public Expression {
    289308  public:
     309        Expression * expr;
     310        Type * type;
     311        bool isType;
     312
    290313        SizeofExpr( Expression * expr, Expression *_aname = nullptr );
    291314        SizeofExpr( const SizeofExpr & other );
     
    304327        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    305328        virtual void print( std::ostream & os, int indent = 0 ) const;
    306   private:
     329};
     330
     331/// AlignofExpr represents an alignof expression
     332class AlignofExpr : public Expression {
     333  public:
    307334        Expression * expr;
    308335        Type * type;
    309336        bool isType;
    310 };
    311 
    312 /// AlignofExpr represents an alignof expression
    313 class AlignofExpr : public Expression {
    314   public:
     337
    315338        AlignofExpr( Expression * expr, Expression *_aname = nullptr );
    316339        AlignofExpr( const AlignofExpr & other );
     
    329352        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    330353        virtual void print( std::ostream & os, int indent = 0 ) const;
    331   private:
    332         Expression * expr;
    333         Type * type;
    334         bool isType;
    335354};
    336355
     
    338357class UntypedOffsetofExpr : public Expression {
    339358  public:
     359        Type * type;
     360        std::string member;
     361
    340362        UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr );
    341363        UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
     
    351373        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    352374        virtual void print( std::ostream & os, int indent = 0 ) const;
    353   private:
    354         Type * type;
    355         std::string member;
    356375};
    357376
     
    359378class OffsetofExpr : public Expression {
    360379  public:
     380        Type * type;
     381        DeclarationWithType * member;
     382
    361383        OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr );
    362384        OffsetofExpr( const OffsetofExpr & other );
     
    372394        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    373395        virtual void print( std::ostream & os, int indent = 0 ) const;
    374   private:
    375         Type * type;
    376         DeclarationWithType * member;
    377396};
    378397
     
    380399class OffsetPackExpr : public Expression {
    381400public:
     401        StructInstType * type;
     402
    382403        OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 );
    383404        OffsetPackExpr( const OffsetPackExpr & other );
     
    390411        virtual void accept( Visitor & v ) { v.visit( this ); }
    391412        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    392 
    393         virtual void print( std::ostream & os, int indent = 0 ) const;
    394 
    395 private:
    396         StructInstType * type;
     413        virtual void print( std::ostream & os, int indent = 0 ) const;
    397414};
    398415
     
    400417class AttrExpr : public Expression {
    401418  public:
     419        Expression * attr;
     420        Expression * expr;
     421        Type * type;
     422        bool isType;
     423
    402424        AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr );
    403425        AttrExpr( const AttrExpr & other );
     
    418440        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    419441        virtual void print( std::ostream & os, int indent = 0 ) const;
    420   private:
    421         Expression * attr;
    422         Expression * expr;
    423         Type * type;
    424         bool isType;
    425442};
    426443
     
    428445class LogicalExpr : public Expression {
    429446  public:
     447        Expression * arg1;
     448        Expression * arg2;
     449
    430450        LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr );
    431451        LogicalExpr( const LogicalExpr & other );
     
    442462        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    443463        virtual void print( std::ostream & os, int indent = 0 ) const;
     464
    444465  private:
     466        bool isAnd;
     467};
     468
     469/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
     470class ConditionalExpr : public Expression {
     471  public:
    445472        Expression * arg1;
    446473        Expression * arg2;
    447         bool isAnd;
    448 };
    449 
    450 /// ConditionalExpr represents the three-argument conditional ( p ? a : b )
    451 class ConditionalExpr : public Expression {
    452   public:
     474        Expression * arg3;
     475
    453476        ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr );
    454477        ConditionalExpr( const ConditionalExpr & other );
     
    466489        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    467490        virtual void print( std::ostream & os, int indent = 0 ) const;
    468   private:
     491};
     492
     493/// CommaExpr represents the sequence operator ( a, b )
     494class CommaExpr : public Expression {
     495  public:
    469496        Expression * arg1;
    470497        Expression * arg2;
    471         Expression * arg3;
    472 };
    473 
    474 /// CommaExpr represents the sequence operator ( a, b )
    475 class CommaExpr : public Expression {
    476   public:
     498
    477499        CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr );
    478500        CommaExpr( const CommaExpr & other );
     
    488510        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    489511        virtual void print( std::ostream & os, int indent = 0 ) const;
    490   private:
    491         Expression * arg1;
    492         Expression * arg2;
    493512};
    494513
     
    496515class TypeExpr : public Expression {
    497516  public:
     517        Type * type;
     518
    498519        TypeExpr( Type * type );
    499520        TypeExpr( const TypeExpr & other );
     
    507528        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    508529        virtual void print( std::ostream & os, int indent = 0 ) const;
    509   private:
    510         Type * type;
    511530};
    512531
     
    514533class AsmExpr : public Expression {
    515534  public:
     535        Expression * inout;
     536        ConstantExpr * constraint;
     537        Expression * operand;
     538
    516539        AsmExpr( Expression * inout, ConstantExpr * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
    517540        AsmExpr( const AsmExpr & other );
     
    531554        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    532555        virtual void print( std::ostream & os, int indent = 0 ) const;
    533   private:
     556
    534557        // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
    535         Expression * inout;
    536         ConstantExpr * constraint;
    537         Expression * operand;
    538558};
    539559
     
    542562class ImplicitCopyCtorExpr : public Expression {
    543563public:
    544         ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
    545         ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
    546         virtual ~ImplicitCopyCtorExpr();
    547 
    548         ApplicationExpr * get_callExpr() const { return callExpr; }
    549         void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
    550 
    551         std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
    552         std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
    553         std::list< Expression * > & get_dtors() { return dtors; }
    554 
    555         virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
    556         virtual void accept( Visitor & v ) { v.visit( this ); }
    557         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    558         virtual void print( std::ostream & os, int indent = 0 ) const;
    559   private:
    560564        ApplicationExpr * callExpr;
    561565        std::list< ObjectDecl * > tempDecls;
    562566        std::list< ObjectDecl * > returnDecls;
    563567        std::list< Expression * > dtors;
     568
     569        ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
     570        ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
     571        virtual ~ImplicitCopyCtorExpr();
     572
     573        ApplicationExpr * get_callExpr() const { return callExpr; }
     574        void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
     575
     576        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
     577        std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
     578        std::list< Expression * > & get_dtors() { return dtors; }
     579
     580        virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
     581        virtual void accept( Visitor & v ) { v.visit( this ); }
     582        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
     583        virtual void print( std::ostream & os, int indent = 0 ) const;
    564584};
    565585
     
    567587class ConstructorExpr : public Expression {
    568588public:
     589        Expression * callExpr;
     590
    569591        ConstructorExpr( Expression * callExpr );
    570592        ConstructorExpr( const ConstructorExpr & other );
     
    578600        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    579601        virtual void print( std::ostream & os, int indent = 0 ) const;
    580 private:
    581         Expression * callExpr;
    582602};
    583603
     
    585605class CompoundLiteralExpr : public Expression {
    586606  public:
     607        Initializer * initializer;
     608
    587609        CompoundLiteralExpr( Type * type, Initializer * initializer );
    588610        CompoundLiteralExpr( const CompoundLiteralExpr & other );
     
    596618        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    597619        virtual void print( std::ostream & os, int indent = 0 ) const;
    598   private:
    599         Initializer * initializer;
    600620};
    601621
     
    603623class RangeExpr : public Expression {
    604624  public:
     625        Expression * low, * high;
     626
    605627        RangeExpr( Expression * low, Expression * high );
    606628        RangeExpr( const RangeExpr & other );
     
    615637        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    616638        virtual void print( std::ostream & os, int indent = 0 ) const;
    617   private:
    618         Expression * low, * high;
    619639};
    620640
     
    622642class UntypedTupleExpr : public Expression {
    623643  public:
     644        std::list<Expression*> exprs;
     645
    624646        UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
    625647        UntypedTupleExpr( const UntypedTupleExpr & other );
     
    632654        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    633655        virtual void print( std::ostream & os, int indent = 0 ) const;
    634   private:
    635         std::list<Expression*> exprs;
    636656};
    637657
     
    639659class TupleExpr : public Expression {
    640660  public:
     661        std::list<Expression*> exprs;
     662
    641663        TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
    642664        TupleExpr( const TupleExpr & other );
     
    649671        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    650672        virtual void print( std::ostream & os, int indent = 0 ) const;
    651   private:
    652         std::list<Expression*> exprs;
    653673};
    654674
     
    656676class TupleIndexExpr : public Expression {
    657677  public:
     678        Expression * tuple;
     679        unsigned int index;
     680
    658681        TupleIndexExpr( Expression * tuple, unsigned int index );
    659682        TupleIndexExpr( const TupleIndexExpr & other );
     
    669692        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    670693        virtual void print( std::ostream & os, int indent = 0 ) const;
    671   private:
    672         Expression * tuple;
    673         unsigned int index;
    674694};
    675695
     
    677697class TupleAssignExpr : public Expression {
    678698  public:
     699        StmtExpr * stmtExpr = nullptr;
     700
    679701        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
    680702        TupleAssignExpr( const TupleAssignExpr & other );
     
    688710        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    689711        virtual void print( std::ostream & os, int indent = 0 ) const;
    690   private:
    691         StmtExpr * stmtExpr = nullptr;
    692712};
    693713
     
    695715class StmtExpr : public Expression {
    696716public:
     717        CompoundStmt * statements;
     718        std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
     719        std::list< Expression * > dtors; // destructor(s) for return variable(s)
     720
    697721        StmtExpr( CompoundStmt * statements );
    698722        StmtExpr( const StmtExpr & other );
     
    709733        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    710734        virtual void print( std::ostream & os, int indent = 0 ) const;
    711 private:
    712         CompoundStmt * statements;
    713         std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
    714         std::list< Expression * > dtors; // destructor(s) for return variable(s)
    715735};
    716736
    717737class UniqueExpr : public Expression {
    718738public:
     739        Expression * expr;
     740        ObjectDecl * object;
     741        VariableExpr * var;
     742
    719743        UniqueExpr( Expression * expr, long long idVal = -1 );
    720744        UniqueExpr( const UniqueExpr & other );
     
    736760        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    737761        virtual void print( std::ostream & os, int indent = 0 ) const;
     762
    738763private:
    739         Expression * expr;
    740         ObjectDecl * object;
    741         VariableExpr * var;
    742764        int id;
    743765        static long long count;
     
    756778class UntypedInitExpr : public Expression {
    757779public:
     780        Expression * expr;
     781        std::list<InitAlternative> initAlts;
     782
    758783        UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
    759784        UntypedInitExpr( const UntypedInitExpr & other );
     
    769794        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    770795        virtual void print( std::ostream & os, int indent = 0 ) const;
    771 private:
    772         Expression * expr;
    773         std::list<InitAlternative> initAlts;
    774796};
    775797
    776798class InitExpr : public Expression {
    777799public:
     800        Expression * expr;
     801        Designation * designation;
     802
    778803        InitExpr( Expression * expr, Designation * designation );
    779804        InitExpr( const InitExpr & other );
     
    790815        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    791816        virtual void print( std::ostream & os, int indent = 0 ) const;
    792 private:
    793         Expression * expr;
    794         Designation * designation;
    795817};
    796818
    797819
    798820std::ostream & operator<<( std::ostream & out, const Expression * expr );
    799 
    800 #endif // EXPRESSION_H
    801821
    802822// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.