source: src/SynTree/Expression.h@ b2da0574

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum with_gc
Last change on this file since b2da0574 was c0bf94e, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Add isGenerated flag to CastExpr to differentiate casts in source from compiler-generated casts

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