source: src/SynTree/Expression.h@ 89d129c

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 89d129c was 294647b, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Filename and linenumber handling for parsing errors

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