Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.h

    r8688ce1 r7f5566b  
    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 : Wed Aug  3 17:08:44 2016
    13 // Update Count     : 27
     12// Last Modified On : Fri Jul 24 13:49:28 2015
     13// Update Count     : 18
    1414//
    1515
     
    1818
    1919#include <map>
    20 #include <memory>
    2120#include "SynTree.h"
    2221#include "Visitor.h"
    2322#include "Mutator.h"
    2423#include "Constant.h"
    25 #include "Common/UniqueName.h"
    26 
    27 /// Expression is the root type for all expressions
     24
    2825class Expression {
    2926  public:
     
    3936        Expression *get_argName() const { return argName; }
    4037        void set_argName( Expression *name ) { argName = name; }
    41         bool get_extension() const { return extension; }
    42         Expression * set_extension( bool exten ) { extension = exten; return this; }
    4338
    4439        virtual Expression *clone() const = 0;
     
    5045        TypeSubstitution *env;
    5146        Expression* argName; // if expression is used as an argument, it can be "designated" by this name
    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
     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
    5752struct ParamEntry {
    5853        ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {}
     
    7065typedef std::map< UniqueId, ParamEntry > InferredParams;
    7166
    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.
     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
    7470class ApplicationExpr : public Expression {
    7571  public:
     
    9389};
    9490
    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.
     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
    9895class UntypedExpr : public Expression {
    9996  public:
     
    121118};
    122119
    123 /// NameExpr contains a name whose meaning is still not determined
     120// this class contains a name whose meaning is still not determined
    124121class NameExpr : public Expression {
    125122  public:
     
    142139// function-call format.
    143140
    144 /// AddressExpr represents a address-of expression, e.g. &e
     141// AddressExpr represents a address-of expression, e.g. &e
    145142class AddressExpr : public Expression {
    146143  public:
     
    160157};
    161158
    162 // xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack
    163159class LabelAddressExpr : public Expression {
    164160  public:
    165161        LabelAddressExpr( Expression *arg );
    166         LabelAddressExpr( const LabelAddressExpr &other );
     162        LabelAddressExpr( const AddressExpr &other );
    167163        virtual ~LabelAddressExpr();
    168164
     
    178174};
    179175
    180 /// CastExpr represents a type cast expression, e.g. (int)e
     176// CastExpr represents a type cast expression, e.g. (int)e
    181177class CastExpr : public Expression {
    182178  public:
     
    197193};
    198194
    199 /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
     195// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
    200196class UntypedMemberExpr : public Expression {
    201197  public:
     
    218214};
    219215
    220 /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
     216// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
    221217class MemberExpr : public Expression {
    222218  public:
     
    239235};
    240236
    241 /// VariableExpr represents an expression that simply refers to the value of a named variable
     237// VariableExpr represents an expression that simply refers to the value of a named variable
    242238class VariableExpr : public Expression {
    243239  public:
     
    257253};
    258254
    259 /// ConstantExpr represents an expression that simply refers to the value of a constant
     255// ConstantExpr represents an expression that simply refers to the value of a constant
    260256class ConstantExpr : public Expression {
    261257  public:
     
    275271};
    276272
    277 /// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
     273// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
    278274class SizeofExpr : public Expression {
    279275  public:
     
    300296};
    301297
    302 /// AlignofExpr represents an alignof expression
    303 class 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
    328 class 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
    349 class 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
    370 class OffsetPackExpr : public Expression {
    371 public:
    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 
    385 private:
    386         StructInstType *type;
    387 };
    388 
    389 /// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
     298// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
    390299class AttrExpr : public Expression {
    391300  public:
     
    415324};
    416325
    417 /// LogicalExpr represents a short-circuit boolean expression (&& or ||)
     326// LogicalExpr represents a short-circuit boolean expression (&& or ||)
    418327class LogicalExpr : public Expression {
    419328  public:
     
    438347};
    439348
    440 /// ConditionalExpr represents the three-argument conditional ( p ? a : b )
     349// ConditionalExpr represents the three-argument conditional ( p ? a : b )
    441350class ConditionalExpr : public Expression {
    442351  public:
     
    462371};
    463372
    464 /// CommaExpr represents the sequence operator ( a, b )
     373// CommaExpr represents the sequence operator ( a, b )
    465374class CommaExpr : public Expression {
    466375  public:
     
    483392};
    484393
    485 /// TupleExpr represents a tuple expression ( [a, b, c] )
     394// TupleExpr represents a tuple expression ( [a, b, c] )
    486395class TupleExpr : public Expression {
    487396  public:
     
    501410};
    502411
    503 /// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
     412// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
    504413class SolvedTupleExpr : public Expression {
    505414  public:
     
    519428};
    520429
    521 /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
     430// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
    522431class TypeExpr : public Expression {
    523432  public:
     
    537446};
    538447
    539 /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
     448// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
    540449class AsmExpr : public Expression {
    541450  public:
    542451        AsmExpr( Expression *inout, ConstantExpr *constraint, Expression *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
    543         AsmExpr( const AsmExpr & other );
    544452        virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
    545453
     
    564472};
    565473
    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.
    568 class ImplicitCopyCtorExpr : public Expression {
    569 public:
    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'
     474// ValofExpr represents a GCC 'lambda expression'
    598475class UntypedValofExpr : public Expression {
    599476  public:
    600477        UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {}
    601         UntypedValofExpr( const UntypedValofExpr & other );
    602         virtual ~UntypedValofExpr();
     478        virtual ~UntypedValofExpr() {}
    603479
    604480        Expression *get_value();
     
    612488        Statement *body;
    613489};
    614 
    615 /// CompoundLiteralExpr represents a C99 'compound literal'
    616 class 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 
    637 class 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 
    655 std::ostream & operator<<( std::ostream & out, Expression * expr );
    656490
    657491#endif // EXPRESSION_H
Note: See TracChangeset for help on using the changeset viewer.