source: src/SynTree/Expression.h @ 874960b

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 874960b was a5f0529, checked in by Andrew Beach <ajbeach@…>, 7 years ago

Virtual casts have been added. They still require a lot of hand coded support to work but for simple cases it should be enough.

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