source: src/SynTree/Expression.h@ fa4805f

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 fa4805f was af5c204a, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

remove UntypedValOfExpr and hook in build for StmtExpr

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