source: src/SynTree/Expression.h@ c3acf0aa

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 c3acf0aa was 65cdc1e, checked in by Andrew Beach <ajbeach@…>, 8 years ago

Syntax Nodes give public access to the fields with effective public access.X

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