source: src/SynTree/Expression.h @ 824a2dc

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

Leftover cleanup from merge

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