source: src/SynTree/Expression.h @ 2fbc904

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 2fbc904 was 4ef08f7, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Implemented KeywordCast? in CandidateFinder? of new AST.

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