source: src/SynTree/Expression.h@ a0c7dc36

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 resolv-new with_gc
Last change on this file since a0c7dc36 was 5809461, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Fix handling of GCC label address and computed goto

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