source: src/SynTree/Expression.h@ 6559a9d

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 6559a9d was 849720f, checked in by Andrew Beach <ajbeach@…>, 6 years ago

lvalue should now always come directly from the expression.

  • Property mode set to 100644
File size: 37.7 KB
RevLine 
[0dd3a2f]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[3be261a]7// Expression.h --
[0dd3a2f]8//
9// Author : Richard C. Bilson
10// Created On : Mon May 18 07:44:20 2015
[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:
[65cdc1e]577 Expression * inout;
[e612146c]578 Expression * constraint;
[65cdc1e]579 Expression * operand;
580
[e612146c]581 AsmExpr( Expression * inout, Expression * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
[3be261a]582 AsmExpr( const AsmExpr & other );
[7f5566b]583 virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
584
[5ded739]585 Expression * get_inout() const { return inout; }
586 void set_inout( Expression * newValue ) { inout = newValue; }
[7f5566b]587
[e612146c]588 Expression * get_constraint() const { return constraint; }
589 void set_constraint( Expression * newValue ) { constraint = newValue; }
[7f5566b]590
[5ded739]591 Expression * get_operand() const { return operand; }
592 void set_operand( Expression * newValue ) { operand = newValue; }
[7f5566b]593
[7870799]594 virtual AsmExpr * clone() const override { return new AsmExpr( * this ); }
595 virtual void accept( Visitor & v ) override { v.visit( this ); }
596 virtual void accept( Visitor & v ) const override { v.visit( this ); }
597 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
598 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[65cdc1e]599
[7f5566b]600 // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
601};
602
[db4ecc5]603/// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
604/// along with a set of copy constructor calls, one for each argument.
605class ImplicitCopyCtorExpr : public Expression {
606public:
[2f86ddf]607 ApplicationExpr * callExpr = nullptr;
[65cdc1e]608
[db4ecc5]609 ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
610 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
611 virtual ~ImplicitCopyCtorExpr();
612
[7870799]613 virtual ImplicitCopyCtorExpr * clone() const override { return new ImplicitCopyCtorExpr( * this ); }
614 virtual void accept( Visitor & v ) override { v.visit( this ); }
615 virtual void accept( Visitor & v ) const override { v.visit( this ); }
616 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
617 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[db4ecc5]618};
619
[b6fe7e6]620/// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
621class ConstructorExpr : public Expression {
622public:
[65cdc1e]623 Expression * callExpr;
624
[b6fe7e6]625 ConstructorExpr( Expression * callExpr );
626 ConstructorExpr( const ConstructorExpr & other );
627 ~ConstructorExpr();
[0dd3a2f]628
[14388c1]629 bool get_lvalue() const final;
630
[5ded739]631 Expression * get_callExpr() const { return callExpr; }
632 void set_callExpr( Expression * newValue ) { callExpr = newValue; }
[0dd3a2f]633
[7870799]634 virtual ConstructorExpr * clone() const override { return new ConstructorExpr( * this ); }
635 virtual void accept( Visitor & v ) override { v.visit( this ); }
636 virtual void accept( Visitor & v ) const override { v.visit( this ); }
637 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
638 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b73452]639};
640
[630a82a]641/// CompoundLiteralExpr represents a C99 'compound literal'
642class CompoundLiteralExpr : public Expression {
643 public:
[65cdc1e]644 Initializer * initializer;
645
[630a82a]646 CompoundLiteralExpr( Type * type, Initializer * initializer );
[5ded739]647 CompoundLiteralExpr( const CompoundLiteralExpr & other );
[3b58d91]648 virtual ~CompoundLiteralExpr();
[630a82a]649
[14388c1]650 bool get_lvalue() const final;
651
[630a82a]652 Initializer * get_initializer() const { return initializer; }
653 void set_initializer( Initializer * i ) { initializer = i; }
654
[7870799]655 virtual CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr( * this ); }
656 virtual void accept( Visitor & v ) override { v.visit( this ); }
657 virtual void accept( Visitor & v ) const override { v.visit( this ); }
658 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
659 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[630a82a]660};
661
[b6fe7e6]662/// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
[8688ce1]663class RangeExpr : public Expression {
664 public:
[65cdc1e]665 Expression * low, * high;
666
[5ded739]667 RangeExpr( Expression * low, Expression * high );
668 RangeExpr( const RangeExpr & other );
[8688ce1]669
[d9e2280]670 Expression * get_low() const { return low; }
671 Expression * get_high() const { return high; }
[5ded739]672 RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; }
673 RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
[8688ce1]674
[7870799]675 virtual RangeExpr * clone() const override { return new RangeExpr( * this ); }
676 virtual void accept( Visitor & v ) override { v.visit( this ); }
677 virtual void accept( Visitor & v ) const override { v.visit( this ); }
678 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
679 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[8688ce1]680};
681
[907eccb]682/// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution
683class UntypedTupleExpr : public Expression {
684 public:
[65cdc1e]685 std::list<Expression*> exprs;
686
[bf4b4cf]687 UntypedTupleExpr( const std::list< Expression * > & exprs );
[5ded739]688 UntypedTupleExpr( const UntypedTupleExpr & other );
[907eccb]689 virtual ~UntypedTupleExpr();
690
691 std::list<Expression*>& get_exprs() { return exprs; }
692
[7870799]693 virtual UntypedTupleExpr * clone() const override { return new UntypedTupleExpr( * this ); }
694 virtual void accept( Visitor & v ) override { v.visit( this ); }
695 virtual void accept( Visitor & v ) const override { v.visit( this ); }
696 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
697 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[907eccb]698};
699
[6eb8948]700/// TupleExpr represents a tuple expression ( [a, b, c] )
701class TupleExpr : public Expression {
702 public:
[65cdc1e]703 std::list<Expression*> exprs;
704
[bf4b4cf]705 TupleExpr( const std::list< Expression * > & exprs );
[5ded739]706 TupleExpr( const TupleExpr & other );
[6eb8948]707 virtual ~TupleExpr();
708
[3c7f01b]709 bool get_lvalue() const final;
710
[6eb8948]711 std::list<Expression*>& get_exprs() { return exprs; }
712
[7870799]713 virtual TupleExpr * clone() const override { return new TupleExpr( * this ); }
714 virtual void accept( Visitor & v ) override { v.visit( this ); }
715 virtual void accept( Visitor & v ) const override { v.visit( this ); }
716 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
717 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[6eb8948]718};
719
[3b58d91]720/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
721class TupleIndexExpr : public Expression {
722 public:
[65cdc1e]723 Expression * tuple;
724 unsigned int index;
725
[3b58d91]726 TupleIndexExpr( Expression * tuple, unsigned int index );
[5ded739]727 TupleIndexExpr( const TupleIndexExpr & other );
[3b58d91]728 virtual ~TupleIndexExpr();
729
[14388c1]730 bool get_lvalue() const final;
731
[3b58d91]732 Expression * get_tuple() const { return tuple; }
733 int get_index() const { return index; }
[5ded739]734 TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; }
[3b58d91]735 TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
736
[7870799]737 virtual TupleIndexExpr * clone() const override { return new TupleIndexExpr( * this ); }
738 virtual void accept( Visitor & v ) override { v.visit( this ); }
739 virtual void accept( Visitor & v ) const override { v.visit( this ); }
740 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
741 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[3b58d91]742};
743
[65660bd]744/// 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]745class TupleAssignExpr : public Expression {
[3b58d91]746 public:
[65cdc1e]747 StmtExpr * stmtExpr = nullptr;
748
[bf4b4cf]749 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls );
[5ded739]750 TupleAssignExpr( const TupleAssignExpr & other );
[6eb8948]751 virtual ~TupleAssignExpr();
[3b58d91]752
[d5556a3]753 TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
754 StmtExpr * get_stmtExpr() const { return stmtExpr; }
[3b58d91]755
[7870799]756 virtual TupleAssignExpr * clone() const override { return new TupleAssignExpr( * this ); }
757 virtual void accept( Visitor & v ) override { v.visit( this ); }
758 virtual void accept( Visitor & v ) const override { v.visit( this ); }
759 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
760 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[20de6fb]761
762 friend class ConverterNewToOld;
763 private:
764 TupleAssignExpr( StmtExpr * stmts );
[3b58d91]765};
766
[6eb8948]767/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
768class StmtExpr : public Expression {
769public:
[65cdc1e]770 CompoundStmt * statements;
771 std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
772 std::list< Expression * > dtors; // destructor(s) for return variable(s)
773
[0e315a5]774 // readonly
775 ExprStmt * resultExpr = nullptr;
776
[5ded739]777 StmtExpr( CompoundStmt * statements );
[6eb8948]778 StmtExpr( const StmtExpr & other );
779 virtual ~StmtExpr();
[3b58d91]780
[5d00425]781 bool get_lvalue() const final;
782
[6eb8948]783 CompoundStmt * get_statements() const { return statements; }
784 StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
[3b58d91]785
[5e2c348]786 // call to set the result type of this StmtExpr based on its body
787 void computeResult();
788
[d5556a3]789 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
790 std::list< Expression * > & get_dtors() { return dtors; }
791
[7870799]792 virtual StmtExpr * clone() const override { return new StmtExpr( * this ); }
793 virtual void accept( Visitor & v ) override { v.visit( this ); }
794 virtual void accept( Visitor & v ) const override { v.visit( this ); }
795 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
796 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[3b58d91]797};
798
[3c13c03]799class UniqueExpr : public Expression {
800public:
[65cdc1e]801 Expression * expr;
802 ObjectDecl * object;
803 VariableExpr * var;
804
[bf32bb8]805 UniqueExpr( Expression * expr, long long idVal = -1 );
[3c13c03]806 UniqueExpr( const UniqueExpr & other );
807 ~UniqueExpr();
808
[141b786]809 Expression * get_expr() const { return expr; }
810 UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
[3c13c03]811
[141b786]812 ObjectDecl * get_object() const { return object; }
813 UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; }
814
815 VariableExpr * get_var() const { return var; }
816 UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; }
[77971f6]817
[bf32bb8]818 int get_id() const { return id; }
819
[7870799]820 virtual UniqueExpr * clone() const override { return new UniqueExpr( * this ); }
821 virtual void accept( Visitor & v ) override { v.visit( this ); }
822 virtual void accept( Visitor & v ) const override { v.visit( this ); }
823 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
824 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[65cdc1e]825
[3c13c03]826private:
[bf32bb8]827 int id;
828 static long long count;
[3c13c03]829};
830
[e4d829b]831struct InitAlternative {
832public:
833 Type * type = nullptr;
834 Designation * designation = nullptr;
835 InitAlternative( Type * type, Designation * designation );
836 InitAlternative( const InitAlternative & other );
837 InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it
838 ~InitAlternative();
839};
840
841class UntypedInitExpr : public Expression {
842public:
[65cdc1e]843 Expression * expr;
844 std::list<InitAlternative> initAlts;
845
[e4d829b]846 UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
847 UntypedInitExpr( const UntypedInitExpr & other );
848 ~UntypedInitExpr();
849
850 Expression * get_expr() const { return expr; }
851 UntypedInitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
852
853 std::list<InitAlternative> & get_initAlts() { return initAlts; }
854
[7870799]855 virtual UntypedInitExpr * clone() const override { return new UntypedInitExpr( * this ); }
856 virtual void accept( Visitor & v ) override { v.visit( this ); }
857 virtual void accept( Visitor & v ) const override { v.visit( this ); }
858 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
859 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[e4d829b]860};
861
862class InitExpr : public Expression {
863public:
[65cdc1e]864 Expression * expr;
865 Designation * designation;
866
[62423350]867 InitExpr( Expression * expr, Designation * designation );
[e4d829b]868 InitExpr( const InitExpr & other );
869 ~InitExpr();
870
871 Expression * get_expr() const { return expr; }
872 InitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
873
874 Designation * get_designation() const { return designation; }
875 InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; }
876
[7870799]877 virtual InitExpr * clone() const override { return new InitExpr( * this ); }
878 virtual void accept( Visitor & v ) override { v.visit( this ); }
879 virtual void accept( Visitor & v ) const override { v.visit( this ); }
880 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
881 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[e4d829b]882};
883
[44b4114]884/// expression that contains a deleted identifier - should never make it past the resolver.
885class DeletedExpr : public Expression {
886public:
887 Expression * expr;
[e67991f]888 Declaration * deleteStmt;
[44b4114]889
[e67991f]890 DeletedExpr( Expression * expr, Declaration * deleteStmt );
[44b4114]891 DeletedExpr( const DeletedExpr & other );
892 ~DeletedExpr();
893
[7870799]894 virtual DeletedExpr * clone() const override { return new DeletedExpr( * this ); }
895 virtual void accept( Visitor & v ) override { v.visit( this ); }
896 virtual void accept( Visitor & v ) const override { v.visit( this ); }
897 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
898 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[44b4114]899};
900
[0f79853]901/// expression wrapping the use of a default argument - should never make it past the resolver.
902class DefaultArgExpr : public Expression {
903public:
904 Expression * expr;
905
906 DefaultArgExpr( Expression * expr );
907 DefaultArgExpr( const DefaultArgExpr & other );
908 ~DefaultArgExpr();
909
[7870799]910 virtual DefaultArgExpr * clone() const override { return new DefaultArgExpr( * this ); }
911 virtual void accept( Visitor & v ) override { v.visit( this ); }
912 virtual void accept( Visitor & v ) const override { v.visit( this ); }
913 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
914 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[0f79853]915};
916
[d807ca28]917/// C11 _Generic expression
918class GenericExpr : public Expression {
919public:
920 struct Association {
921 Type * type = nullptr;
922 Expression * expr = nullptr;
923 bool isDefault = false;
924
925 Association( Type * type, Expression * expr );
926 Association( Expression * expr );
927 Association( const Association & other );
928 Association & operator=( const Association & other ) = delete; // at the moment this isn't used, and I don't want to implement it
929 ~Association();
930 };
931
932 Expression * control;
933 std::list<Association> associations;
934
935 GenericExpr( Expression * control, const std::list<Association> & assoc );
936 GenericExpr( const GenericExpr & other );
937 virtual ~GenericExpr();
938
[7870799]939 virtual GenericExpr * clone() const override { return new GenericExpr( * this ); }
940 virtual void accept( Visitor & v ) override { v.visit( this ); }
941 virtual void accept( Visitor & v ) const override { v.visit( this ); }
942 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
943 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[d807ca28]944};
945
[0dd3a2f]946// Local Variables: //
947// tab-width: 4 //
948// mode: c++ //
949// compile-command: "make install" //
950// End: //
Note: See TracBrowser for help on using the repository browser.