source: src/SynTree/Expression.h @ 77e6fcb

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 77e6fcb was 5ded739, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

code formatting

  • Property mode set to 100644
File size: 31.1 KB
RevLine 
[0dd3a2f]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[3be261a]7// Expression.h --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[e04ef3a]11// Last Modified By : Peter A. Buhr
[5ded739]12// Last Modified On : Sat Jan 14 14:37:54 2017
13// Update Count     : 37
[0dd3a2f]14//
[51b7345]15
16#ifndef EXPRESSION_H
17#define EXPRESSION_H
18
19#include <map>
[8688ce1]20#include <memory>
[51b7345]21#include "SynTree.h"
22#include "Visitor.h"
23#include "Mutator.h"
24#include "Constant.h"
[db4ecc5]25#include "Common/UniqueName.h"
[51b7345]26
[47534159]27/// Expression is the root type for all expressions
[0dd3a2f]28class Expression {
29  public:
[5ded739]30        Expression( Expression * _aname = nullptr );
31        Expression( const Expression & other );
[0dd3a2f]32        virtual ~Expression();
33
[906e24d]34        Type *& get_result() { return result; }
[5ded739]35        void set_result( Type * newValue ) { result = newValue; }
[906e24d]36        bool has_result() const { return result != nullptr; }
[0dd3a2f]37
[5ded739]38        TypeSubstitution * get_env() const { return env; }
39        void set_env( TypeSubstitution * newValue ) { env = newValue; }
40        Expression * get_argName() const { return argName; }
41        void set_argName( Expression * name ) { argName = name; }
[e04ef3a]42        bool get_extension() const { return extension; }
[8e9cbb2]43        Expression * set_extension( bool exten ) { extension = exten; return this; }
[0dd3a2f]44
[5ded739]45        virtual Expression * clone() const = 0;
46        virtual void accept( Visitor & v ) = 0;
47        virtual Expression * acceptMutator( Mutator & m ) = 0;
48        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]49  protected:
[906e24d]50        Type * result;
[5ded739]51        TypeSubstitution * env;
52        Expression * argName; // if expression is used as an argument, it can be "designated" by this name
[e04ef3a]53        bool extension = false;
[51b7345]54};
55
[6c3a988f]56struct ParamEntry;
57typedef std::map< UniqueId, ParamEntry > InferredParams;
58
[47534159]59/// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
60/// but subject to decay-to-pointer and type parameter renaming
[0dd3a2f]61struct ParamEntry {
[6c3a988f]62        ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ), inferParams( new InferredParams ) {}
[5ded739]63        ParamEntry( UniqueId decl, Type * actualType, Type * formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ), inferParams( new InferredParams ) {}
64        ParamEntry( const ParamEntry & other );
[0dd3a2f]65        ~ParamEntry();
[5ded739]66        ParamEntry & operator=( const ParamEntry & other );
[0dd3a2f]67
68        UniqueId decl;
[5ded739]69        Type * actualType;
70        Type * formalType;
[0dd3a2f]71        Expression* expr;
[6c3a988f]72        std::unique_ptr< InferredParams > inferParams;
[51b7345]73};
74
[9706554]75/// ApplicationExpr represents the application of a function to a set of parameters.  This is the result of running an
76/// UntypedExpr through the expression analyzer.
[0dd3a2f]77class ApplicationExpr : public Expression {
78  public:
[5ded739]79        ApplicationExpr( Expression * function );
80        ApplicationExpr( const ApplicationExpr & other );
[0dd3a2f]81        virtual ~ApplicationExpr();
82
[5ded739]83        Expression * get_function() const { return function; }
84        void set_function( Expression * newValue ) { function = newValue; }
[0dd3a2f]85        std::list<Expression *>& get_args() { return args; }
[5ded739]86        InferredParams & get_inferParams() { return inferParams; }
[0dd3a2f]87
[5ded739]88        virtual ApplicationExpr * clone() const { return new ApplicationExpr( * this ); }
89        virtual void accept( Visitor & v ) { v.visit( this ); }
90        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
91        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]92  private:
[5ded739]93        Expression * function;
[0dd3a2f]94        std::list<Expression *> args;
95        InferredParams inferParams;
[51b7345]96};
97
[9706554]98/// UntypedExpr represents the application of a function to a set of parameters, but where the particular overload for
99/// the function name has not yet been determined.  Most operators are converted into functional form automatically, to
100/// permit operator overloading.
[0dd3a2f]101class UntypedExpr : public Expression {
102  public:
[5ded739]103        UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >(), Expression *_aname = nullptr );
104        UntypedExpr( const UntypedExpr & other );
[0dd3a2f]105        virtual ~UntypedExpr();
106
[5ded739]107        Expression * get_function() const { return function; }
108        void set_function( Expression * newValue ) { function = newValue; }
[0dd3a2f]109
[5ded739]110        void set_args( std::list<Expression *> & listArgs ) { args = listArgs; }
[0dd3a2f]111        std::list<Expression*>::iterator begin_args() { return args.begin(); }
112        std::list<Expression*>::iterator end_args() { return args.end(); }
113        std::list<Expression*>& get_args() { return args; }
114
[b3b2077]115        static UntypedExpr * createDeref( Expression * arg );
116        static UntypedExpr * createAssign( Expression * arg1, Expression * arg2 );
117
[5ded739]118        virtual UntypedExpr * clone() const { return new UntypedExpr( * this ); }
119        virtual void accept( Visitor & v ) { v.visit( this ); }
120        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
121        virtual void print( std::ostream & os, int indent = 0 ) const;
122        virtual void printArgs(std::ostream & os, int indent = 0) const;
[0dd3a2f]123  private:
[5ded739]124        Expression * function;
[0dd3a2f]125        std::list<Expression*> args;
[51b7345]126};
127
[47534159]128/// NameExpr contains a name whose meaning is still not determined
[0dd3a2f]129class NameExpr : public Expression {
130  public:
[7bf7fb9]131        NameExpr( std::string name, Expression *_aname = nullptr );
[5ded739]132        NameExpr( const NameExpr & other );
[0dd3a2f]133        virtual ~NameExpr();
134
[5ded739]135        const std::string & get_name() const { return name; }
[0dd3a2f]136        void set_name( std::string newValue ) { name = newValue; }
137
[5ded739]138        virtual NameExpr * clone() const { return new NameExpr( * this ); }
139        virtual void accept( Visitor & v ) { v.visit( this ); }
140        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
141        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]142  private:
143        std::string name;
[51b7345]144};
145
146// The following classes are used to represent expression types that cannot be converted into
147// function-call format.
148
[5ded739]149/// AddressExpr represents a address-of expression, e.g. & e
[0dd3a2f]150class AddressExpr : public Expression {
151  public:
[5ded739]152        AddressExpr( Expression * arg, Expression *_aname = nullptr );
153        AddressExpr( const AddressExpr & other );
[0dd3a2f]154        virtual ~AddressExpr();
155
[5ded739]156        Expression * get_arg() const { return arg; }
157        void set_arg(Expression * newValue ) { arg = newValue; }
[0dd3a2f]158
[5ded739]159        virtual AddressExpr * clone() const { return new AddressExpr( * this ); }
160        virtual void accept( Visitor & v ) { v.visit( this ); }
161        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
162        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]163  private:
[5ded739]164        Expression * arg;
[51b7345]165};
166
[3be261a]167// xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack
[0dd3a2f]168class LabelAddressExpr : public Expression {
169  public:
[5ded739]170        LabelAddressExpr( Expression * arg );
171        LabelAddressExpr( const LabelAddressExpr & other );
[0dd3a2f]172        virtual ~LabelAddressExpr();
173
[5ded739]174        Expression * get_arg() const { return arg; }
175        void set_arg(Expression * newValue ) { arg = newValue; }
[0dd3a2f]176
[5ded739]177        virtual LabelAddressExpr * clone() const { return new LabelAddressExpr( * this ); }
178        virtual void accept( Visitor & v ) { v.visit( this ); }
179        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
180        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]181  private:
[5ded739]182        Expression * arg;
[51b7345]183};
184
[47534159]185/// CastExpr represents a type cast expression, e.g. (int)e
[0dd3a2f]186class CastExpr : public Expression {
187  public:
[5ded739]188        CastExpr( Expression * arg, Expression *_aname = nullptr );
189        CastExpr( Expression * arg, Type * toType, Expression *_aname = nullptr );
190        CastExpr( const CastExpr & other );
[0dd3a2f]191        virtual ~CastExpr();
192
[5ded739]193        Expression * get_arg() const { return arg; }
194        void set_arg(Expression * newValue ) { arg = newValue; }
[0dd3a2f]195
[5ded739]196        virtual CastExpr * clone() const { return new CastExpr( * this ); }
197        virtual void accept( Visitor & v ) { v.visit( this ); }
198        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
199        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]200  private:
[5ded739]201        Expression * arg;
[51b7345]202};
203
[47534159]204/// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
[0dd3a2f]205class UntypedMemberExpr : public Expression {
206  public:
[5ded739]207        UntypedMemberExpr( Expression * member, Expression * aggregate, Expression *_aname = nullptr );
208        UntypedMemberExpr( const UntypedMemberExpr & other );
[0dd3a2f]209        virtual ~UntypedMemberExpr();
210
[3b58d91]211        Expression * get_member() const { return member; }
212        void set_member( Expression * newValue ) { member = newValue; }
[5ded739]213        Expression * get_aggregate() const { return aggregate; }
214        void set_aggregate( Expression * newValue ) { aggregate = newValue; }
[0dd3a2f]215
[5ded739]216        virtual UntypedMemberExpr * clone() const { return new UntypedMemberExpr( * this ); }
217        virtual void accept( Visitor & v ) { v.visit( this ); }
218        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
219        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]220  private:
[5ded739]221        Expression * member;
222        Expression * aggregate;
[51b7345]223};
224
[47534159]225/// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
[0dd3a2f]226class MemberExpr : public Expression {
227  public:
[5ded739]228        MemberExpr( DeclarationWithType * member, Expression * aggregate, Expression *_aname = nullptr );
229        MemberExpr( const MemberExpr & other );
[0dd3a2f]230        virtual ~MemberExpr();
231
[5ded739]232        DeclarationWithType * get_member() const { return member; }
233        void set_member( DeclarationWithType * newValue ) { member = newValue; }
234        Expression * get_aggregate() const { return aggregate; }
235        void set_aggregate( Expression * newValue ) { aggregate = newValue; }
[0dd3a2f]236
[5ded739]237        virtual MemberExpr * clone() const { return new MemberExpr( * this ); }
238        virtual void accept( Visitor & v ) { v.visit( this ); }
239        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
240        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]241  private:
[5ded739]242        DeclarationWithType * member;
243        Expression * aggregate;
[51b7345]244};
245
[47534159]246/// VariableExpr represents an expression that simply refers to the value of a named variable
[0dd3a2f]247class VariableExpr : public Expression {
248  public:
[5ded739]249        VariableExpr( DeclarationWithType * var, Expression *_aname = nullptr );
250        VariableExpr( const VariableExpr & other );
[0dd3a2f]251        virtual ~VariableExpr();
252
[5ded739]253        DeclarationWithType * get_var() const { return var; }
254        void set_var( DeclarationWithType * newValue ) { var = newValue; }
[0dd3a2f]255
[5ded739]256        virtual VariableExpr * clone() const { return new VariableExpr( * this ); }
257        virtual void accept( Visitor & v ) { v.visit( this ); }
258        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
259        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]260  private:
[5ded739]261        DeclarationWithType * var;
[51b7345]262};
263
[3be261a]264/// ConstantExpr represents an expression that simply refers to the value of a constant
[0dd3a2f]265class ConstantExpr : public Expression {
266  public:
[7bf7fb9]267        ConstantExpr( Constant constant, Expression *_aname = nullptr );
[5ded739]268        ConstantExpr( const ConstantExpr & other );
[0dd3a2f]269        virtual ~ConstantExpr();
270
[5ded739]271        Constant * get_constant() { return & constant; }
272        void set_constant( const Constant & newValue ) { constant = newValue; }
[0dd3a2f]273
[5ded739]274        virtual ConstantExpr * clone() const { return new ConstantExpr( * this ); }
275        virtual void accept( Visitor & v ) { v.visit( this ); }
276        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
277        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]278  private:
279        Constant constant;
[51b7345]280};
281
[47534159]282/// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
[0dd3a2f]283class SizeofExpr : public Expression {
284  public:
[5ded739]285        SizeofExpr( Expression * expr, Expression *_aname = nullptr );
286        SizeofExpr( const SizeofExpr & other );
287        SizeofExpr( Type * type, Expression *_aname = nullptr );
[0dd3a2f]288        virtual ~SizeofExpr();
289
[5ded739]290        Expression * get_expr() const { return expr; }
291        void set_expr( Expression * newValue ) { expr = newValue; }
292        Type * get_type() const { return type; }
293        void set_type( Type * newValue ) { type = newValue; }
[0dd3a2f]294        bool get_isType() const { return isType; }
295        void set_isType( bool newValue ) { isType = newValue; }
296
[5ded739]297        virtual SizeofExpr * clone() const { return new SizeofExpr( * this ); }
298        virtual void accept( Visitor & v ) { v.visit( this ); }
299        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
300        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]301  private:
[5ded739]302        Expression * expr;
303        Type * type;
[0dd3a2f]304        bool isType;
[51b7345]305};
306
[47534159]307/// AlignofExpr represents an alignof expression
308class AlignofExpr : public Expression {
309  public:
[5ded739]310        AlignofExpr( Expression * expr, Expression *_aname = nullptr );
311        AlignofExpr( const AlignofExpr & other );
312        AlignofExpr( Type * type, Expression *_aname = nullptr );
[47534159]313        virtual ~AlignofExpr();
314
[5ded739]315        Expression * get_expr() const { return expr; }
316        void set_expr( Expression * newValue ) { expr = newValue; }
317        Type * get_type() const { return type; }
318        void set_type( Type * newValue ) { type = newValue; }
[47534159]319        bool get_isType() const { return isType; }
320        void set_isType( bool newValue ) { isType = newValue; }
321
[5ded739]322        virtual AlignofExpr * clone() const { return new AlignofExpr( * this ); }
323        virtual void accept( Visitor & v ) { v.visit( this ); }
324        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
325        virtual void print( std::ostream & os, int indent = 0 ) const;
[47534159]326  private:
[5ded739]327        Expression * expr;
328        Type * type;
[47534159]329        bool isType;
330};
331
[2a4b088]332/// UntypedOffsetofExpr represents an offsetof expression before resolution
333class UntypedOffsetofExpr : public Expression {
334  public:
[5ded739]335        UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr );
336        UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
[2a4b088]337        virtual ~UntypedOffsetofExpr();
338
339        std::string get_member() const { return member; }
[5ded739]340        void set_member( const std::string & newValue ) { member = newValue; }
341        Type * get_type() const { return type; }
342        void set_type( Type * newValue ) { type = newValue; }
343
344        virtual UntypedOffsetofExpr * clone() const { return new UntypedOffsetofExpr( * this ); }
345        virtual void accept( Visitor & v ) { v.visit( this ); }
346        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
347        virtual void print( std::ostream & os, int indent = 0 ) const;
[2a4b088]348  private:
[5ded739]349        Type * type;
[2a4b088]350        std::string member;
351};
352
[25a054f]353/// OffsetofExpr represents an offsetof expression
354class OffsetofExpr : public Expression {
355  public:
[5ded739]356        OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr );
357        OffsetofExpr( const OffsetofExpr & other );
[25a054f]358        virtual ~OffsetofExpr();
359
[5ded739]360        Type * get_type() const { return type; }
361        void set_type( Type * newValue ) { type = newValue; }
362        DeclarationWithType * get_member() const { return member; }
363        void set_member( DeclarationWithType * newValue ) { member = newValue; }
364
365        virtual OffsetofExpr * clone() const { return new OffsetofExpr( * this ); }
366        virtual void accept( Visitor & v ) { v.visit( this ); }
367        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
368        virtual void print( std::ostream & os, int indent = 0 ) const;
[25a054f]369  private:
[5ded739]370        Type * type;
371        DeclarationWithType * member;
[25a054f]372};
373
[afc1045]374/// Expression representing a pack of field-offsets for a generic type
375class OffsetPackExpr : public Expression {
376public:
[5ded739]377        OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 );
378        OffsetPackExpr( const OffsetPackExpr & other );
[afc1045]379        virtual ~OffsetPackExpr();
380
[5ded739]381        StructInstType * get_type() const { return type; }
382        void set_type( StructInstType * newValue ) { type = newValue; }
[afc1045]383
[5ded739]384        virtual OffsetPackExpr * clone() const { return new OffsetPackExpr( * this ); }
385        virtual void accept( Visitor & v ) { v.visit( this ); }
386        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
[afc1045]387
[5ded739]388        virtual void print( std::ostream & os, int indent = 0 ) const;
[afc1045]389
390private:
[5ded739]391        StructInstType * type;
[afc1045]392};
393
[47534159]394/// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
[0dd3a2f]395class AttrExpr : public Expression {
396  public:
[5ded739]397        AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr );
398        AttrExpr( const AttrExpr & other );
399        AttrExpr( Expression * attr, Type * type, Expression *_aname = nullptr );
[0dd3a2f]400        virtual ~AttrExpr();
401
[5ded739]402        Expression * get_attr() const { return attr; }
403        void set_attr( Expression * newValue ) { attr = newValue; }
404        Expression * get_expr() const { return expr; }
405        void set_expr( Expression * newValue ) { expr = newValue; }
406        Type * get_type() const { return type; }
407        void set_type( Type * newValue ) { type = newValue; }
[0dd3a2f]408        bool get_isType() const { return isType; }
409        void set_isType( bool newValue ) { isType = newValue; }
410
[5ded739]411        virtual AttrExpr * clone() const { return new AttrExpr( * this ); }
412        virtual void accept( Visitor & v ) { v.visit( this ); }
413        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
414        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]415  private:
[5ded739]416        Expression * attr;
417        Expression * expr;
418        Type * type;
[0dd3a2f]419        bool isType;
[51b7345]420};
421
[47534159]422/// LogicalExpr represents a short-circuit boolean expression (&& or ||)
[0dd3a2f]423class LogicalExpr : public Expression {
424  public:
[5ded739]425        LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr );
426        LogicalExpr( const LogicalExpr & other );
[0dd3a2f]427        virtual ~LogicalExpr();
428
429        bool get_isAnd() const { return isAnd; }
[5ded739]430        Expression * get_arg1() { return arg1; }
431        void set_arg1( Expression * newValue ) { arg1 = newValue; }
432        Expression * get_arg2() const { return arg2; }
433        void set_arg2( Expression * newValue ) { arg2 = newValue; }
434
435        virtual LogicalExpr * clone() const { return new LogicalExpr( * this ); }
436        virtual void accept( Visitor & v ) { v.visit( this ); }
437        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
438        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]439  private:
[5ded739]440        Expression * arg1;
441        Expression * arg2;
[0dd3a2f]442        bool isAnd;
[51b7345]443};
444
[47534159]445/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
[0dd3a2f]446class ConditionalExpr : public Expression {
447  public:
[5ded739]448        ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr );
449        ConditionalExpr( const ConditionalExpr & other );
[0dd3a2f]450        virtual ~ConditionalExpr();
451
[5ded739]452        Expression * get_arg1() const { return arg1; }
453        void set_arg1( Expression * newValue ) { arg1 = newValue; }
454        Expression * get_arg2() const { return arg2; }
455        void set_arg2( Expression * newValue ) { arg2 = newValue; }
456        Expression * get_arg3() const { return arg3; }
457        void set_arg3( Expression * newValue ) { arg3 = newValue; }
458
459        virtual ConditionalExpr * clone() const { return new ConditionalExpr( * this ); }
460        virtual void accept( Visitor & v ) { v.visit( this ); }
461        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
462        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]463  private:
[5ded739]464        Expression * arg1;
465        Expression * arg2;
466        Expression * arg3;
[51b7345]467};
468
[47534159]469/// CommaExpr represents the sequence operator ( a, b )
[0dd3a2f]470class CommaExpr : public Expression {
471  public:
[5ded739]472        CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr );
473        CommaExpr( const CommaExpr & other );
[0dd3a2f]474        virtual ~CommaExpr();
475
[5ded739]476        Expression * get_arg1() const { return arg1; }
477        void set_arg1( Expression * newValue ) { arg1 = newValue; }
478        Expression * get_arg2() const { return arg2; }
479        void set_arg2( Expression * newValue ) { arg2 = newValue; }
[0dd3a2f]480
[5ded739]481        virtual CommaExpr * clone() const { return new CommaExpr( * this ); }
482        virtual void accept( Visitor & v ) { v.visit( this ); }
483        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
484        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]485  private:
[5ded739]486        Expression * arg1;
487        Expression * arg2;
[51b7345]488};
489
[47534159]490/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
[0dd3a2f]491class TypeExpr : public Expression {
492  public:
[5ded739]493        TypeExpr( Type * type );
494        TypeExpr( const TypeExpr & other );
[0dd3a2f]495        virtual ~TypeExpr();
496
[5ded739]497        Type * get_type() const { return type; }
498        void set_type( Type * newValue ) { type = newValue; }
[0dd3a2f]499
[5ded739]500        virtual TypeExpr * clone() const { return new TypeExpr( * this ); }
501        virtual void accept( Visitor & v ) { v.visit( this ); }
502        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
503        virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]504  private:
[5ded739]505        Type * type;
[51b7345]506};
507
[47534159]508/// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
[7f5566b]509class AsmExpr : public Expression {
510  public:
[5ded739]511        AsmExpr( Expression * inout, ConstantExpr * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
[3be261a]512        AsmExpr( const AsmExpr & other );
[7f5566b]513        virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
514
[5ded739]515        Expression * get_inout() const { return inout; }
516        void set_inout( Expression * newValue ) { inout = newValue; }
[7f5566b]517
[5ded739]518        ConstantExpr * get_constraint() const { return constraint; }
519        void set_constraint( ConstantExpr * newValue ) { constraint = newValue; }
[7f5566b]520
[5ded739]521        Expression * get_operand() const { return operand; }
522        void set_operand( Expression * newValue ) { operand = newValue; }
[7f5566b]523
[5ded739]524        virtual AsmExpr * clone() const { return new AsmExpr( * this ); }
525        virtual void accept( Visitor & v ) { v.visit( this ); }
526        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
527        virtual void print( std::ostream & os, int indent = 0 ) const;
[7f5566b]528  private:
529        // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
[5ded739]530        Expression * inout;
531        ConstantExpr * constraint;
532        Expression * operand;
[7f5566b]533};
534
[db4ecc5]535/// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
536/// along with a set of copy constructor calls, one for each argument.
537class ImplicitCopyCtorExpr : public Expression {
538public:
539        ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
540        ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
541        virtual ~ImplicitCopyCtorExpr();
542
[5ded739]543        ApplicationExpr * get_callExpr() const { return callExpr; }
544        void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
[db4ecc5]545
546        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
547        std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
548        std::list< Expression * > & get_dtors() { return dtors; }
549
[5ded739]550        virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
551        virtual void accept( Visitor & v ) { v.visit( this ); }
552        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
553        virtual void print( std::ostream & os, int indent = 0 ) const;
[db4ecc5]554  private:
555        ApplicationExpr * callExpr;
556        std::list< ObjectDecl * > tempDecls;
557        std::list< ObjectDecl * > returnDecls;
558        std::list< Expression * > dtors;
559};
560
[b6fe7e6]561/// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
562class ConstructorExpr : public Expression {
563public:
564        ConstructorExpr( Expression * callExpr );
565        ConstructorExpr( const ConstructorExpr & other );
566        ~ConstructorExpr();
[0dd3a2f]567
[5ded739]568        Expression * get_callExpr() const { return callExpr; }
569        void set_callExpr( Expression * newValue ) { callExpr = newValue; }
[0dd3a2f]570
[5ded739]571        virtual ConstructorExpr * clone() const { return new ConstructorExpr( * this ); }
572        virtual void accept( Visitor & v ) { v.visit( this ); }
573        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
574        virtual void print( std::ostream & os, int indent = 0 ) const;
[b6fe7e6]575private:
576        Expression * callExpr;
[51b7345]577};
578
[630a82a]579/// CompoundLiteralExpr represents a C99 'compound literal'
580class CompoundLiteralExpr : public Expression {
581  public:
582        CompoundLiteralExpr( Type * type, Initializer * initializer );
[5ded739]583        CompoundLiteralExpr( const CompoundLiteralExpr & other );
[3b58d91]584        virtual ~CompoundLiteralExpr();
[630a82a]585
586        Type * get_type() const { return type; }
587        void set_type( Type * t ) { type = t; }
588
589        Initializer * get_initializer() const { return initializer; }
590        void set_initializer( Initializer * i ) { initializer = i; }
591
[5ded739]592        virtual CompoundLiteralExpr * clone() const { return new CompoundLiteralExpr( * this ); }
593        virtual void accept( Visitor & v ) { v.visit( this ); }
594        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
595        virtual void print( std::ostream & os, int indent = 0 ) const;
[630a82a]596  private:
597        Type * type;
598        Initializer * initializer;
599};
600
[b6fe7e6]601/// ValofExpr represents a GCC 'lambda expression'
602class UntypedValofExpr : public Expression {
603  public:
604        UntypedValofExpr( Statement *_body, Expression *_aname = nullptr ) : Expression( _aname ), body ( _body ) {}
605        UntypedValofExpr( const UntypedValofExpr & other );
606        virtual ~UntypedValofExpr();
607
[5ded739]608        Expression * get_value();
609        Statement * get_body() const { return body; }
[b6fe7e6]610
[5ded739]611        virtual UntypedValofExpr * clone() const { return new UntypedValofExpr( * this ); }
612        virtual void accept( Visitor & v ) { v.visit( this ); }
613        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
614        virtual void print( std::ostream & os, int indent = 0 ) const;
[b6fe7e6]615  private:
[5ded739]616        Statement * body;
[b6fe7e6]617};
618
619/// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
[8688ce1]620class RangeExpr : public Expression {
621  public:
[5ded739]622        RangeExpr( Expression * low, Expression * high );
623        RangeExpr( const RangeExpr & other );
[8688ce1]624
[d9e2280]625        Expression * get_low() const { return low; }
626        Expression * get_high() const { return high; }
[5ded739]627        RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; }
628        RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
[8688ce1]629
[5ded739]630        virtual RangeExpr * clone() const { return new RangeExpr( * this ); }
631        virtual void accept( Visitor & v ) { v.visit( this ); }
632        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
633        virtual void print( std::ostream & os, int indent = 0 ) const;
[8688ce1]634  private:
[5ded739]635        Expression * low, * high;
[8688ce1]636};
637
[907eccb]638/// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution
639class UntypedTupleExpr : public Expression {
640  public:
641        UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
[5ded739]642        UntypedTupleExpr( const UntypedTupleExpr & other );
[907eccb]643        virtual ~UntypedTupleExpr();
644
645        std::list<Expression*>& get_exprs() { return exprs; }
646
[5ded739]647        virtual UntypedTupleExpr * clone() const { return new UntypedTupleExpr( * 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;
[907eccb]651  private:
652        std::list<Expression*> exprs;
653};
654
[6eb8948]655/// TupleExpr represents a tuple expression ( [a, b, c] )
656class TupleExpr : public Expression {
657  public:
[907eccb]658        TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
[5ded739]659        TupleExpr( const TupleExpr & other );
[6eb8948]660        virtual ~TupleExpr();
661
662        std::list<Expression*>& get_exprs() { return exprs; }
663
[5ded739]664        virtual TupleExpr * clone() const { return new TupleExpr( * this ); }
665        virtual void accept( Visitor & v ) { v.visit( this ); }
666        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
667        virtual void print( std::ostream & os, int indent = 0 ) const;
[6eb8948]668  private:
669        std::list<Expression*> exprs;
670};
671
[3b58d91]672/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
673class TupleIndexExpr : public Expression {
674  public:
675        TupleIndexExpr( Expression * tuple, unsigned int index );
[5ded739]676        TupleIndexExpr( const TupleIndexExpr & other );
[3b58d91]677        virtual ~TupleIndexExpr();
678
679        Expression * get_tuple() const { return tuple; }
680        int get_index() const { return index; }
[5ded739]681        TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; }
[3b58d91]682        TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
683
[5ded739]684        virtual TupleIndexExpr * clone() const { return new TupleIndexExpr( * this ); }
685        virtual void accept( Visitor & v ) { v.visit( this ); }
686        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
687        virtual void print( std::ostream & os, int indent = 0 ) const;
[3b58d91]688  private:
689        Expression * tuple;
690        unsigned int index;
691};
692
693/// MemberTupleExpr represents a tuple member selection operation on a struct type, e.g. s.[a, b, c] after processing by the expression analyzer
694class MemberTupleExpr : public Expression {
695  public:
696        MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname = nullptr );
[5ded739]697        MemberTupleExpr( const MemberTupleExpr & other );
[3b58d91]698        virtual ~MemberTupleExpr();
699
700        Expression * get_member() const { return member; }
701        Expression * get_aggregate() const { return aggregate; }
[5ded739]702        MemberTupleExpr * set_member( Expression * newValue ) { member = newValue; return this; }
703        MemberTupleExpr * set_aggregate( Expression * newValue ) { aggregate = newValue; return this; }
[3b58d91]704
[5ded739]705        virtual MemberTupleExpr * clone() const { return new MemberTupleExpr( * this ); }
706        virtual void accept( Visitor & v ) { v.visit( this ); }
707        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
708        virtual void print( std::ostream & os, int indent = 0 ) const;
[3b58d91]709  private:
710        Expression * member;
711        Expression * aggregate;
712};
713
[65660bd]714/// TupleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];, 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;, or a tuple ctor/dtor expression
[6eb8948]715class TupleAssignExpr : public Expression {
[3b58d91]716  public:
[6eb8948]717        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
[5ded739]718        TupleAssignExpr( const TupleAssignExpr & other );
[6eb8948]719        virtual ~TupleAssignExpr();
[3b58d91]720
[d5556a3]721        TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
722        StmtExpr * get_stmtExpr() const { return stmtExpr; }
[3b58d91]723
[5ded739]724        virtual TupleAssignExpr * clone() const { return new TupleAssignExpr( * this ); }
725        virtual void accept( Visitor & v ) { v.visit( this ); }
726        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
727        virtual void print( std::ostream & os, int indent = 0 ) const;
[3b58d91]728  private:
[d5556a3]729        StmtExpr * stmtExpr = nullptr;
[3b58d91]730};
731
[6eb8948]732/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
733class StmtExpr : public Expression {
734public:
[5ded739]735        StmtExpr( CompoundStmt * statements );
[6eb8948]736        StmtExpr( const StmtExpr & other );
737        virtual ~StmtExpr();
[3b58d91]738
[6eb8948]739        CompoundStmt * get_statements() const { return statements; }
740        StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
[3b58d91]741
[d5556a3]742        std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
743        std::list< Expression * > & get_dtors() { return dtors; }
744
[5ded739]745        virtual StmtExpr * clone() const { return new StmtExpr( * this ); }
746        virtual void accept( Visitor & v ) { v.visit( this ); }
747        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
748        virtual void print( std::ostream & os, int indent = 0 ) const;
[6eb8948]749private:
750        CompoundStmt * statements;
[d5556a3]751        std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
752        std::list< Expression * > dtors; // destructor(s) for return variable(s)
[3b58d91]753};
754
[3c13c03]755class UniqueExpr : public Expression {
756public:
[bf32bb8]757        UniqueExpr( Expression * expr, long long idVal = -1 );
[3c13c03]758        UniqueExpr( const UniqueExpr & other );
759        ~UniqueExpr();
760
[141b786]761        Expression * get_expr() const { return expr; }
762        UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
[3c13c03]763
[141b786]764        ObjectDecl * get_object() const { return object; }
765        UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; }
766
767        VariableExpr * get_var() const { return var; }
768        UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; }
[77971f6]769
[bf32bb8]770        int get_id() const { return id; }
771
[5ded739]772        virtual UniqueExpr * clone() const { return new UniqueExpr( * this ); }
773        virtual void accept( Visitor & v ) { v.visit( this ); }
774        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
775        virtual void print( std::ostream & os, int indent = 0 ) const;
[3c13c03]776private:
[141b786]777        Expression * expr;
778        ObjectDecl * object;
779        VariableExpr * var;
[bf32bb8]780        int id;
781        static long long count;
[3c13c03]782};
783
[3906301]784std::ostream & operator<<( std::ostream & out, const Expression * expr );
[baf7fee]785
[0dd3a2f]786#endif // EXPRESSION_H
[51b7345]787
[0dd3a2f]788// Local Variables: //
789// tab-width: 4 //
790// mode: c++ //
791// compile-command: "make install" //
792// End: //
Note: See TracBrowser for help on using the repository browser.