source: src/SynTree/Expression.h @ 44264c5

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 44264c5 was fbcde64, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

remove duplication in compound literal, support aggregate-type compound literals

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