source: src/SynTree/Expression.h @ cdc4d43

new-envwith_gc
Last change on this file since cdc4d43 was eba74ba, checked in by Aaron Moss <a3moss@…>, 6 years ago

Merge remote-tracking branch 'origin/master' into with_gc

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