source: src/SynTree/Expression.h@ 1d60da8

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 1d60da8 was 665f432, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Fixed trac #149 where operand names in asm statements where incorrectly resolved (i.e., should not have been resolved)

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