source: src/SynTree/Expression.h@ 83794e1

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

Fix various reference features.

  • Eliminate multiple address-ofs resulting from &(T&) [address-of reference-cast].
  • Keep rvalue cast if reference base type is incompatible with rvalue type.
  • Keep pointer qualifiers when eliminating reference types.
  • Add VariableExpr::functionPointer helper function to create variable expressions with function pointer type.
  • Change ConstructorExpr translation so that it temporarily generates a 'fake' assignment operator rather than use UntypedExpr, so that the correct transformations occur in the Lvalue pass. This is a hack that can be fixed once PassVisitor properly supports Indexer.
  • Property mode set to 100644
File size: 31.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:
[f19339e]82 ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list<Expression *>() );
[5ded739]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
[8a6cf7e]261 static VariableExpr * functionPointer( FunctionDecl * decl );
262
[5ded739]263 virtual VariableExpr * clone() const { return new VariableExpr( * 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;
[0dd3a2f]267 private:
[5ded739]268 DeclarationWithType * var;
[51b73452]269};
270
[3be261a]271/// ConstantExpr represents an expression that simply refers to the value of a constant
[0dd3a2f]272class ConstantExpr : public Expression {
273 public:
[7bf7fb9]274 ConstantExpr( Constant constant, Expression *_aname = nullptr );
[5ded739]275 ConstantExpr( const ConstantExpr & other );
[0dd3a2f]276 virtual ~ConstantExpr();
277
[5ded739]278 Constant * get_constant() { return & constant; }
279 void set_constant( const Constant & newValue ) { constant = newValue; }
[0dd3a2f]280
[5ded739]281 virtual ConstantExpr * clone() const { return new ConstantExpr( * this ); }
282 virtual void accept( Visitor & v ) { v.visit( this ); }
283 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
284 virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]285 private:
286 Constant constant;
[51b73452]287};
288
[47534159]289/// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
[0dd3a2f]290class SizeofExpr : public Expression {
291 public:
[5ded739]292 SizeofExpr( Expression * expr, Expression *_aname = nullptr );
293 SizeofExpr( const SizeofExpr & other );
294 SizeofExpr( Type * type, Expression *_aname = nullptr );
[0dd3a2f]295 virtual ~SizeofExpr();
296
[5ded739]297 Expression * get_expr() const { return expr; }
298 void set_expr( Expression * newValue ) { expr = newValue; }
299 Type * get_type() const { return type; }
300 void set_type( Type * newValue ) { type = newValue; }
[0dd3a2f]301 bool get_isType() const { return isType; }
302 void set_isType( bool newValue ) { isType = newValue; }
303
[5ded739]304 virtual SizeofExpr * clone() const { return new SizeofExpr( * this ); }
305 virtual void accept( Visitor & v ) { v.visit( this ); }
306 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
307 virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]308 private:
[5ded739]309 Expression * expr;
310 Type * type;
[0dd3a2f]311 bool isType;
[51b73452]312};
313
[47534159]314/// AlignofExpr represents an alignof expression
315class AlignofExpr : public Expression {
316 public:
[5ded739]317 AlignofExpr( Expression * expr, Expression *_aname = nullptr );
318 AlignofExpr( const AlignofExpr & other );
319 AlignofExpr( Type * type, Expression *_aname = nullptr );
[47534159]320 virtual ~AlignofExpr();
321
[5ded739]322 Expression * get_expr() const { return expr; }
323 void set_expr( Expression * newValue ) { expr = newValue; }
324 Type * get_type() const { return type; }
325 void set_type( Type * newValue ) { type = newValue; }
[47534159]326 bool get_isType() const { return isType; }
327 void set_isType( bool newValue ) { isType = newValue; }
328
[5ded739]329 virtual AlignofExpr * clone() const { return new AlignofExpr( * this ); }
330 virtual void accept( Visitor & v ) { v.visit( this ); }
331 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
332 virtual void print( std::ostream & os, int indent = 0 ) const;
[47534159]333 private:
[5ded739]334 Expression * expr;
335 Type * type;
[47534159]336 bool isType;
337};
338
[2a4b088]339/// UntypedOffsetofExpr represents an offsetof expression before resolution
340class UntypedOffsetofExpr : public Expression {
341 public:
[5ded739]342 UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr );
343 UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
[2a4b088]344 virtual ~UntypedOffsetofExpr();
345
346 std::string get_member() const { return member; }
[5ded739]347 void set_member( const std::string & newValue ) { member = newValue; }
348 Type * get_type() const { return type; }
349 void set_type( Type * newValue ) { type = newValue; }
350
351 virtual UntypedOffsetofExpr * clone() const { return new UntypedOffsetofExpr( * this ); }
352 virtual void accept( Visitor & v ) { v.visit( this ); }
353 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
354 virtual void print( std::ostream & os, int indent = 0 ) const;
[2a4b088]355 private:
[5ded739]356 Type * type;
[2a4b088]357 std::string member;
358};
359
[25a054f]360/// OffsetofExpr represents an offsetof expression
361class OffsetofExpr : public Expression {
362 public:
[5ded739]363 OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr );
364 OffsetofExpr( const OffsetofExpr & other );
[25a054f]365 virtual ~OffsetofExpr();
366
[5ded739]367 Type * get_type() const { return type; }
368 void set_type( Type * newValue ) { type = newValue; }
369 DeclarationWithType * get_member() const { return member; }
370 void set_member( DeclarationWithType * newValue ) { member = newValue; }
371
372 virtual OffsetofExpr * clone() const { return new OffsetofExpr( * this ); }
373 virtual void accept( Visitor & v ) { v.visit( this ); }
374 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
375 virtual void print( std::ostream & os, int indent = 0 ) const;
[25a054f]376 private:
[5ded739]377 Type * type;
378 DeclarationWithType * member;
[25a054f]379};
380
[afc1045]381/// Expression representing a pack of field-offsets for a generic type
382class OffsetPackExpr : public Expression {
383public:
[5ded739]384 OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 );
385 OffsetPackExpr( const OffsetPackExpr & other );
[afc1045]386 virtual ~OffsetPackExpr();
387
[5ded739]388 StructInstType * get_type() const { return type; }
389 void set_type( StructInstType * newValue ) { type = newValue; }
[afc1045]390
[5ded739]391 virtual OffsetPackExpr * clone() const { return new OffsetPackExpr( * this ); }
392 virtual void accept( Visitor & v ) { v.visit( this ); }
393 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
[afc1045]394
[5ded739]395 virtual void print( std::ostream & os, int indent = 0 ) const;
[afc1045]396
397private:
[5ded739]398 StructInstType * type;
[afc1045]399};
400
[47534159]401/// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
[0dd3a2f]402class AttrExpr : public Expression {
403 public:
[5ded739]404 AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr );
405 AttrExpr( const AttrExpr & other );
406 AttrExpr( Expression * attr, Type * type, Expression *_aname = nullptr );
[0dd3a2f]407 virtual ~AttrExpr();
408
[5ded739]409 Expression * get_attr() const { return attr; }
410 void set_attr( Expression * newValue ) { attr = newValue; }
411 Expression * get_expr() const { return expr; }
412 void set_expr( Expression * newValue ) { expr = newValue; }
413 Type * get_type() const { return type; }
414 void set_type( Type * newValue ) { type = newValue; }
[0dd3a2f]415 bool get_isType() const { return isType; }
416 void set_isType( bool newValue ) { isType = newValue; }
417
[5ded739]418 virtual AttrExpr * clone() const { return new AttrExpr( * this ); }
419 virtual void accept( Visitor & v ) { v.visit( this ); }
420 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
421 virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]422 private:
[5ded739]423 Expression * attr;
424 Expression * expr;
425 Type * type;
[0dd3a2f]426 bool isType;
[51b73452]427};
428
[47534159]429/// LogicalExpr represents a short-circuit boolean expression (&& or ||)
[0dd3a2f]430class LogicalExpr : public Expression {
431 public:
[5ded739]432 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr );
433 LogicalExpr( const LogicalExpr & other );
[0dd3a2f]434 virtual ~LogicalExpr();
435
436 bool get_isAnd() const { return isAnd; }
[5ded739]437 Expression * get_arg1() { return arg1; }
438 void set_arg1( Expression * newValue ) { arg1 = newValue; }
439 Expression * get_arg2() const { return arg2; }
440 void set_arg2( Expression * newValue ) { arg2 = newValue; }
441
442 virtual LogicalExpr * clone() const { return new LogicalExpr( * this ); }
443 virtual void accept( Visitor & v ) { v.visit( this ); }
444 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
445 virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]446 private:
[5ded739]447 Expression * arg1;
448 Expression * arg2;
[0dd3a2f]449 bool isAnd;
[51b73452]450};
451
[47534159]452/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
[0dd3a2f]453class ConditionalExpr : public Expression {
454 public:
[5ded739]455 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr );
456 ConditionalExpr( const ConditionalExpr & other );
[0dd3a2f]457 virtual ~ConditionalExpr();
458
[5ded739]459 Expression * get_arg1() const { return arg1; }
460 void set_arg1( Expression * newValue ) { arg1 = newValue; }
461 Expression * get_arg2() const { return arg2; }
462 void set_arg2( Expression * newValue ) { arg2 = newValue; }
463 Expression * get_arg3() const { return arg3; }
464 void set_arg3( Expression * newValue ) { arg3 = newValue; }
465
466 virtual ConditionalExpr * clone() const { return new ConditionalExpr( * this ); }
467 virtual void accept( Visitor & v ) { v.visit( this ); }
468 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
469 virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]470 private:
[5ded739]471 Expression * arg1;
472 Expression * arg2;
473 Expression * arg3;
[51b73452]474};
475
[47534159]476/// CommaExpr represents the sequence operator ( a, b )
[0dd3a2f]477class CommaExpr : public Expression {
478 public:
[5ded739]479 CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr );
480 CommaExpr( const CommaExpr & other );
[0dd3a2f]481 virtual ~CommaExpr();
482
[5ded739]483 Expression * get_arg1() const { return arg1; }
484 void set_arg1( Expression * newValue ) { arg1 = newValue; }
485 Expression * get_arg2() const { return arg2; }
486 void set_arg2( Expression * newValue ) { arg2 = newValue; }
[0dd3a2f]487
[5ded739]488 virtual CommaExpr * clone() const { return new CommaExpr( * this ); }
489 virtual void accept( Visitor & v ) { v.visit( this ); }
490 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
491 virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]492 private:
[5ded739]493 Expression * arg1;
494 Expression * arg2;
[51b73452]495};
496
[47534159]497/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
[0dd3a2f]498class TypeExpr : public Expression {
499 public:
[5ded739]500 TypeExpr( Type * type );
501 TypeExpr( const TypeExpr & other );
[0dd3a2f]502 virtual ~TypeExpr();
503
[5ded739]504 Type * get_type() const { return type; }
505 void set_type( Type * newValue ) { type = newValue; }
[0dd3a2f]506
[5ded739]507 virtual TypeExpr * clone() const { return new TypeExpr( * this ); }
508 virtual void accept( Visitor & v ) { v.visit( this ); }
509 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
510 virtual void print( std::ostream & os, int indent = 0 ) const;
[0dd3a2f]511 private:
[5ded739]512 Type * type;
[51b73452]513};
514
[47534159]515/// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
[7f5566b]516class AsmExpr : public Expression {
517 public:
[5ded739]518 AsmExpr( Expression * inout, ConstantExpr * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
[3be261a]519 AsmExpr( const AsmExpr & other );
[7f5566b]520 virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
521
[5ded739]522 Expression * get_inout() const { return inout; }
523 void set_inout( Expression * newValue ) { inout = newValue; }
[7f5566b]524
[5ded739]525 ConstantExpr * get_constraint() const { return constraint; }
526 void set_constraint( ConstantExpr * newValue ) { constraint = newValue; }
[7f5566b]527
[5ded739]528 Expression * get_operand() const { return operand; }
529 void set_operand( Expression * newValue ) { operand = newValue; }
[7f5566b]530
[5ded739]531 virtual AsmExpr * clone() const { return new AsmExpr( * this ); }
532 virtual void accept( Visitor & v ) { v.visit( this ); }
533 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
534 virtual void print( std::ostream & os, int indent = 0 ) const;
[7f5566b]535 private:
536 // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
[5ded739]537 Expression * inout;
538 ConstantExpr * constraint;
539 Expression * operand;
[7f5566b]540};
541
[db4ecc5]542/// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
543/// along with a set of copy constructor calls, one for each argument.
544class ImplicitCopyCtorExpr : public Expression {
545public:
546 ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
547 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
548 virtual ~ImplicitCopyCtorExpr();
549
[5ded739]550 ApplicationExpr * get_callExpr() const { return callExpr; }
551 void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
[db4ecc5]552
553 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
554 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
555 std::list< Expression * > & get_dtors() { return dtors; }
556
[5ded739]557 virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
558 virtual void accept( Visitor & v ) { v.visit( this ); }
559 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
560 virtual void print( std::ostream & os, int indent = 0 ) const;
[db4ecc5]561 private:
562 ApplicationExpr * callExpr;
563 std::list< ObjectDecl * > tempDecls;
564 std::list< ObjectDecl * > returnDecls;
565 std::list< Expression * > dtors;
566};
567
[b6fe7e6]568/// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
569class ConstructorExpr : public Expression {
570public:
571 ConstructorExpr( Expression * callExpr );
572 ConstructorExpr( const ConstructorExpr & other );
573 ~ConstructorExpr();
[0dd3a2f]574
[5ded739]575 Expression * get_callExpr() const { return callExpr; }
576 void set_callExpr( Expression * newValue ) { callExpr = newValue; }
[0dd3a2f]577
[5ded739]578 virtual ConstructorExpr * clone() const { return new ConstructorExpr( * this ); }
579 virtual void accept( Visitor & v ) { v.visit( this ); }
580 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
581 virtual void print( std::ostream & os, int indent = 0 ) const;
[b6fe7e6]582private:
583 Expression * callExpr;
[51b73452]584};
585
[630a82a]586/// CompoundLiteralExpr represents a C99 'compound literal'
587class CompoundLiteralExpr : public Expression {
588 public:
589 CompoundLiteralExpr( Type * type, Initializer * initializer );
[5ded739]590 CompoundLiteralExpr( const CompoundLiteralExpr & other );
[3b58d91]591 virtual ~CompoundLiteralExpr();
[630a82a]592
593 Initializer * get_initializer() const { return initializer; }
594 void set_initializer( Initializer * i ) { initializer = i; }
595
[5ded739]596 virtual CompoundLiteralExpr * clone() const { return new CompoundLiteralExpr( * this ); }
597 virtual void accept( Visitor & v ) { v.visit( this ); }
598 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
599 virtual void print( std::ostream & os, int indent = 0 ) const;
[630a82a]600 private:
601 Initializer * initializer;
602};
603
[b6fe7e6]604/// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
[8688ce1]605class RangeExpr : public Expression {
606 public:
[5ded739]607 RangeExpr( Expression * low, Expression * high );
608 RangeExpr( const RangeExpr & other );
[8688ce1]609
[d9e2280]610 Expression * get_low() const { return low; }
611 Expression * get_high() const { return high; }
[5ded739]612 RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; }
613 RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
[8688ce1]614
[5ded739]615 virtual RangeExpr * clone() const { return new RangeExpr( * this ); }
616 virtual void accept( Visitor & v ) { v.visit( this ); }
617 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
618 virtual void print( std::ostream & os, int indent = 0 ) const;
[8688ce1]619 private:
[5ded739]620 Expression * low, * high;
[8688ce1]621};
622
[907eccb]623/// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution
624class UntypedTupleExpr : public Expression {
625 public:
626 UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
[5ded739]627 UntypedTupleExpr( const UntypedTupleExpr & other );
[907eccb]628 virtual ~UntypedTupleExpr();
629
630 std::list<Expression*>& get_exprs() { return exprs; }
631
[5ded739]632 virtual UntypedTupleExpr * clone() const { return new UntypedTupleExpr( * 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;
[907eccb]636 private:
637 std::list<Expression*> exprs;
638};
639
[6eb8948]640/// TupleExpr represents a tuple expression ( [a, b, c] )
641class TupleExpr : public Expression {
642 public:
[907eccb]643 TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
[5ded739]644 TupleExpr( const TupleExpr & other );
[6eb8948]645 virtual ~TupleExpr();
646
647 std::list<Expression*>& get_exprs() { return exprs; }
648
[5ded739]649 virtual TupleExpr * clone() const { return new TupleExpr( * 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;
[6eb8948]653 private:
654 std::list<Expression*> exprs;
655};
656
[3b58d91]657/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
658class TupleIndexExpr : public Expression {
659 public:
660 TupleIndexExpr( Expression * tuple, unsigned int index );
[5ded739]661 TupleIndexExpr( const TupleIndexExpr & other );
[3b58d91]662 virtual ~TupleIndexExpr();
663
664 Expression * get_tuple() const { return tuple; }
665 int get_index() const { return index; }
[5ded739]666 TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; }
[3b58d91]667 TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
668
[5ded739]669 virtual TupleIndexExpr * clone() const { return new TupleIndexExpr( * 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;
[3b58d91]673 private:
674 Expression * tuple;
675 unsigned int index;
676};
677
[65660bd]678/// 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]679class TupleAssignExpr : public Expression {
[3b58d91]680 public:
[6eb8948]681 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
[5ded739]682 TupleAssignExpr( const TupleAssignExpr & other );
[6eb8948]683 virtual ~TupleAssignExpr();
[3b58d91]684
[d5556a3]685 TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
686 StmtExpr * get_stmtExpr() const { return stmtExpr; }
[3b58d91]687
[5ded739]688 virtual TupleAssignExpr * clone() const { return new TupleAssignExpr( * this ); }
689 virtual void accept( Visitor & v ) { v.visit( this ); }
690 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
691 virtual void print( std::ostream & os, int indent = 0 ) const;
[3b58d91]692 private:
[d5556a3]693 StmtExpr * stmtExpr = nullptr;
[3b58d91]694};
695
[6eb8948]696/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
697class StmtExpr : public Expression {
698public:
[5ded739]699 StmtExpr( CompoundStmt * statements );
[6eb8948]700 StmtExpr( const StmtExpr & other );
701 virtual ~StmtExpr();
[3b58d91]702
[6eb8948]703 CompoundStmt * get_statements() const { return statements; }
704 StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
[3b58d91]705
[d5556a3]706 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
707 std::list< Expression * > & get_dtors() { return dtors; }
708
[5ded739]709 virtual StmtExpr * clone() const { return new StmtExpr( * this ); }
710 virtual void accept( Visitor & v ) { v.visit( this ); }
711 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
712 virtual void print( std::ostream & os, int indent = 0 ) const;
[6eb8948]713private:
714 CompoundStmt * statements;
[d5556a3]715 std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
716 std::list< Expression * > dtors; // destructor(s) for return variable(s)
[3b58d91]717};
718
[3c13c03]719class UniqueExpr : public Expression {
720public:
[bf32bb8]721 UniqueExpr( Expression * expr, long long idVal = -1 );
[3c13c03]722 UniqueExpr( const UniqueExpr & other );
723 ~UniqueExpr();
724
[141b786]725 Expression * get_expr() const { return expr; }
726 UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
[3c13c03]727
[141b786]728 ObjectDecl * get_object() const { return object; }
729 UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; }
730
731 VariableExpr * get_var() const { return var; }
732 UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; }
[77971f6]733
[bf32bb8]734 int get_id() const { return id; }
735
[5ded739]736 virtual UniqueExpr * clone() const { return new UniqueExpr( * this ); }
737 virtual void accept( Visitor & v ) { v.visit( this ); }
738 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
739 virtual void print( std::ostream & os, int indent = 0 ) const;
[3c13c03]740private:
[141b786]741 Expression * expr;
742 ObjectDecl * object;
743 VariableExpr * var;
[bf32bb8]744 int id;
745 static long long count;
[3c13c03]746};
747
[e4d829b]748struct InitAlternative {
749public:
750 Type * type = nullptr;
751 Designation * designation = nullptr;
752 InitAlternative( Type * type, Designation * designation );
753 InitAlternative( const InitAlternative & other );
754 InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it
755 ~InitAlternative();
756};
757
758class UntypedInitExpr : public Expression {
759public:
760 UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
761 UntypedInitExpr( const UntypedInitExpr & other );
762 ~UntypedInitExpr();
763
764 Expression * get_expr() const { return expr; }
765 UntypedInitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
766
767 std::list<InitAlternative> & get_initAlts() { return initAlts; }
768
769 virtual UntypedInitExpr * clone() const { return new UntypedInitExpr( * this ); }
770 virtual void accept( Visitor & v ) { v.visit( this ); }
771 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
772 virtual void print( std::ostream & os, int indent = 0 ) const;
773private:
774 Expression * expr;
775 std::list<InitAlternative> initAlts;
776};
777
778class InitExpr : public Expression {
779public:
[62423350]780 InitExpr( Expression * expr, Designation * designation );
[e4d829b]781 InitExpr( const InitExpr & other );
782 ~InitExpr();
783
784 Expression * get_expr() const { return expr; }
785 InitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
786
787 Designation * get_designation() const { return designation; }
788 InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; }
789
790 virtual InitExpr * clone() const { return new InitExpr( * this ); }
791 virtual void accept( Visitor & v ) { v.visit( this ); }
792 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
793 virtual void print( std::ostream & os, int indent = 0 ) const;
794private:
795 Expression * expr;
796 Designation * designation;
797};
798
799
[3906301]800std::ostream & operator<<( std::ostream & out, const Expression * expr );
[baf7fee]801
[0dd3a2f]802#endif // EXPRESSION_H
[51b73452]803
[0dd3a2f]804// Local Variables: //
805// tab-width: 4 //
806// mode: c++ //
807// compile-command: "make install" //
808// End: //
Note: See TracBrowser for help on using the repository browser.