Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.h

    r7f5566b r8688ce1  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Expression.h -- 
     7// Expression.h --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 24 13:49:28 2015
    13 // Update Count     : 18
     12// Last Modified On : Wed Aug  3 17:08:44 2016
     13// Update Count     : 27
    1414//
    1515
     
    1818
    1919#include <map>
     20#include <memory>
    2021#include "SynTree.h"
    2122#include "Visitor.h"
    2223#include "Mutator.h"
    2324#include "Constant.h"
    24 
     25#include "Common/UniqueName.h"
     26
     27/// Expression is the root type for all expressions
    2528class Expression {
    2629  public:
     
    3639        Expression *get_argName() const { return argName; }
    3740        void set_argName( Expression *name ) { argName = name; }
     41        bool get_extension() const { return extension; }
     42        Expression * set_extension( bool exten ) { extension = exten; return this; }
    3843
    3944        virtual Expression *clone() const = 0;
     
    4550        TypeSubstitution *env;
    4651        Expression* argName; // if expression is used as an argument, it can be "designated" by this name
    47 };
    48 
    49 // ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
    50 // but subject to decay-to-pointer and type parameter renaming
    51 
     52        bool extension = false;
     53};
     54
     55/// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
     56/// but subject to decay-to-pointer and type parameter renaming
    5257struct ParamEntry {
    5358        ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {}
     
    6570typedef std::map< UniqueId, ParamEntry > InferredParams;
    6671
    67 // ApplicationExpr represents the application of a function to a set of parameters.  This is the
    68 // result of running an UntypedExpr through the expression analyzer.
    69 
     72/// ApplicationExpr represents the application of a function to a set of parameters.  This is the
     73/// result of running an UntypedExpr through the expression analyzer.
    7074class ApplicationExpr : public Expression {
    7175  public:
     
    8993};
    9094
    91 // UntypedExpr represents the application of a function to a set of parameters, but where the
    92 // particular overload for the function name has not yet been determined.  Most operators are
    93 // converted into functional form automatically, to permit operator overloading.
    94 
     95/// UntypedExpr represents the application of a function to a set of parameters, but where the
     96/// particular overload for the function name has not yet been determined.  Most operators are
     97/// converted into functional form automatically, to permit operator overloading.
    9598class UntypedExpr : public Expression {
    9699  public:
     
    118121};
    119122
    120 // this class contains a name whose meaning is still not determined
     123/// NameExpr contains a name whose meaning is still not determined
    121124class NameExpr : public Expression {
    122125  public:
     
    139142// function-call format.
    140143
    141 // AddressExpr represents a address-of expression, e.g. &e
     144/// AddressExpr represents a address-of expression, e.g. &e
    142145class AddressExpr : public Expression {
    143146  public:
     
    157160};
    158161
     162// xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack
    159163class LabelAddressExpr : public Expression {
    160164  public:
    161165        LabelAddressExpr( Expression *arg );
    162         LabelAddressExpr( const AddressExpr &other );
     166        LabelAddressExpr( const LabelAddressExpr &other );
    163167        virtual ~LabelAddressExpr();
    164168
     
    174178};
    175179
    176 // CastExpr represents a type cast expression, e.g. (int)e
     180/// CastExpr represents a type cast expression, e.g. (int)e
    177181class CastExpr : public Expression {
    178182  public:
     
    193197};
    194198
    195 // UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
     199/// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
    196200class UntypedMemberExpr : public Expression {
    197201  public:
     
    214218};
    215219
    216 // MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
     220/// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
    217221class MemberExpr : public Expression {
    218222  public:
     
    235239};
    236240
    237 // VariableExpr represents an expression that simply refers to the value of a named variable
     241/// VariableExpr represents an expression that simply refers to the value of a named variable
    238242class VariableExpr : public Expression {
    239243  public:
     
    253257};
    254258
    255 // ConstantExpr represents an expression that simply refers to the value of a constant
     259/// ConstantExpr represents an expression that simply refers to the value of a constant
    256260class ConstantExpr : public Expression {
    257261  public:
     
    271275};
    272276
    273 // SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
     277/// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
    274278class SizeofExpr : public Expression {
    275279  public:
     
    296300};
    297301
    298 // AttrExpr represents an @attribute expression (like sizeof, but user-defined)
     302/// AlignofExpr represents an alignof expression
     303class AlignofExpr : public Expression {
     304  public:
     305        AlignofExpr( Expression *expr, Expression *_aname = 0 );
     306        AlignofExpr( const AlignofExpr &other );
     307        AlignofExpr( Type *type, Expression *_aname = 0 );
     308        virtual ~AlignofExpr();
     309
     310        Expression *get_expr() const { return expr; }
     311        void set_expr( Expression *newValue ) { expr = newValue; }
     312        Type *get_type() const { return type; }
     313        void set_type( Type *newValue ) { type = newValue; }
     314        bool get_isType() const { return isType; }
     315        void set_isType( bool newValue ) { isType = newValue; }
     316
     317        virtual AlignofExpr *clone() const { return new AlignofExpr( *this ); }
     318        virtual void accept( Visitor &v ) { v.visit( this ); }
     319        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     320        virtual void print( std::ostream &os, int indent = 0 ) const;
     321  private:
     322        Expression *expr;
     323        Type *type;
     324        bool isType;
     325};
     326
     327/// UntypedOffsetofExpr represents an offsetof expression before resolution
     328class UntypedOffsetofExpr : public Expression {
     329  public:
     330        UntypedOffsetofExpr( Type *type, const std::string &member, Expression *_aname = 0 );
     331        UntypedOffsetofExpr( const UntypedOffsetofExpr &other );
     332        virtual ~UntypedOffsetofExpr();
     333
     334        std::string get_member() const { return member; }
     335        void set_member( const std::string &newValue ) { member = newValue; }
     336        Type *get_type() const { return type; }
     337        void set_type( Type *newValue ) { type = newValue; }
     338
     339        virtual UntypedOffsetofExpr *clone() const { return new UntypedOffsetofExpr( *this ); }
     340        virtual void accept( Visitor &v ) { v.visit( this ); }
     341        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     342        virtual void print( std::ostream &os, int indent = 0 ) const;
     343  private:
     344        Type *type;
     345        std::string member;
     346};
     347
     348/// OffsetofExpr represents an offsetof expression
     349class OffsetofExpr : public Expression {
     350  public:
     351        OffsetofExpr( Type *type, DeclarationWithType *member, Expression *_aname = 0 );
     352        OffsetofExpr( const OffsetofExpr &other );
     353        virtual ~OffsetofExpr();
     354
     355        Type *get_type() const { return type; }
     356        void set_type( Type *newValue ) { type = newValue; }
     357        DeclarationWithType *get_member() const { return member; }
     358        void set_member( DeclarationWithType *newValue ) { member = newValue; }
     359
     360        virtual OffsetofExpr *clone() const { return new OffsetofExpr( *this ); }
     361        virtual void accept( Visitor &v ) { v.visit( this ); }
     362        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     363        virtual void print( std::ostream &os, int indent = 0 ) const;
     364  private:
     365        Type *type;
     366        DeclarationWithType *member;
     367};
     368
     369/// Expression representing a pack of field-offsets for a generic type
     370class OffsetPackExpr : public Expression {
     371public:
     372        OffsetPackExpr( StructInstType *type_, Expression *aname_ = 0 );
     373        OffsetPackExpr( const OffsetPackExpr &other );
     374        virtual ~OffsetPackExpr();
     375
     376        StructInstType *get_type() const { return type; }
     377        void set_type( StructInstType *newValue ) { type = newValue; }
     378
     379        virtual OffsetPackExpr *clone() const { return new OffsetPackExpr( *this ); }
     380        virtual void accept( Visitor &v ) { v.visit( this ); }
     381        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     382
     383        virtual void print( std::ostream &os, int indent = 0 ) const;
     384
     385private:
     386        StructInstType *type;
     387};
     388
     389/// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
    299390class AttrExpr : public Expression {
    300391  public:
     
    324415};
    325416
    326 // LogicalExpr represents a short-circuit boolean expression (&& or ||)
     417/// LogicalExpr represents a short-circuit boolean expression (&& or ||)
    327418class LogicalExpr : public Expression {
    328419  public:
     
    347438};
    348439
    349 // ConditionalExpr represents the three-argument conditional ( p ? a : b )
     440/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
    350441class ConditionalExpr : public Expression {
    351442  public:
     
    371462};
    372463
    373 // CommaExpr represents the sequence operator ( a, b )
     464/// CommaExpr represents the sequence operator ( a, b )
    374465class CommaExpr : public Expression {
    375466  public:
     
    392483};
    393484
    394 // TupleExpr represents a tuple expression ( [a, b, c] )
     485/// TupleExpr represents a tuple expression ( [a, b, c] )
    395486class TupleExpr : public Expression {
    396487  public:
     
    410501};
    411502
    412 // SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
     503/// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
    413504class SolvedTupleExpr : public Expression {
    414505  public:
     
    428519};
    429520
    430 // TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
     521/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
    431522class TypeExpr : public Expression {
    432523  public:
     
    446537};
    447538
    448 // AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
     539/// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
    449540class AsmExpr : public Expression {
    450541  public:
    451542        AsmExpr( Expression *inout, ConstantExpr *constraint, Expression *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
     543        AsmExpr( const AsmExpr & other );
    452544        virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
    453545
     
    472564};
    473565
    474 // ValofExpr represents a GCC 'lambda expression'
     566/// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
     567/// along with a set of copy constructor calls, one for each argument.
     568class ImplicitCopyCtorExpr : public Expression {
     569public:
     570        ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
     571        ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
     572        virtual ~ImplicitCopyCtorExpr();
     573
     574        ApplicationExpr *get_callExpr() const { return callExpr; }
     575        void set_callExpr( ApplicationExpr *newValue ) { callExpr = newValue; }
     576
     577        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
     578        void set_tempDecls( std::list< ObjectDecl * > newValue ) { tempDecls = newValue; }
     579
     580        std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
     581        void set_returnDecls( std::list< ObjectDecl * > newValue ) { returnDecls = newValue; }
     582
     583        std::list< Expression * > & get_dtors() { return dtors; }
     584        void set_dtors( std::list< Expression * > newValue ) { dtors = newValue; }
     585
     586        virtual ImplicitCopyCtorExpr *clone() const { return new ImplicitCopyCtorExpr( *this ); }
     587        virtual void accept( Visitor &v ) { v.visit( this ); }
     588        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     589        virtual void print( std::ostream &os, int indent = 0 ) const;
     590  private:
     591        ApplicationExpr * callExpr;
     592        std::list< ObjectDecl * > tempDecls;
     593        std::list< ObjectDecl * > returnDecls;
     594        std::list< Expression * > dtors;
     595};
     596
     597/// ValofExpr represents a GCC 'lambda expression'
    475598class UntypedValofExpr : public Expression {
    476599  public:
    477600        UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {}
    478         virtual ~UntypedValofExpr() {}
     601        UntypedValofExpr( const UntypedValofExpr & other );
     602        virtual ~UntypedValofExpr();
    479603
    480604        Expression *get_value();
     
    488612        Statement *body;
    489613};
     614
     615/// CompoundLiteralExpr represents a C99 'compound literal'
     616class CompoundLiteralExpr : public Expression {
     617  public:
     618        CompoundLiteralExpr( Type * type, Initializer * initializer );
     619        CompoundLiteralExpr( const CompoundLiteralExpr &other );
     620        ~CompoundLiteralExpr();
     621
     622        Type * get_type() const { return type; }
     623        void set_type( Type * t ) { type = t; }
     624
     625        Initializer * get_initializer() const { return initializer; }
     626        void set_initializer( Initializer * i ) { initializer = i; }
     627
     628        virtual CompoundLiteralExpr *clone() const { return new CompoundLiteralExpr( *this ); }
     629        virtual void accept( Visitor &v ) { v.visit( this ); }
     630        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     631        virtual void print( std::ostream &os, int indent = 0 ) const;
     632  private:
     633        Type * type;
     634        Initializer * initializer;
     635};
     636
     637class RangeExpr : public Expression {
     638  public:
     639        RangeExpr( ConstantExpr *low, ConstantExpr *high );
     640        RangeExpr( const RangeExpr &other );
     641
     642        ConstantExpr * get_low() const { return low.get(); }
     643        ConstantExpr * get_high() const { return high.get(); }
     644        RangeExpr * set_low( ConstantExpr *low ) { RangeExpr::low.reset( low ); return this; }
     645        RangeExpr * set_high( ConstantExpr *high ) { RangeExpr::high.reset( high ); return this; }
     646
     647        virtual RangeExpr *clone() const { return new RangeExpr( *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::unique_ptr<ConstantExpr> low, high;
     653};
     654
     655std::ostream & operator<<( std::ostream & out, Expression * expr );
    490656
    491657#endif // EXPRESSION_H
Note: See TracChangeset for help on using the changeset viewer.