source: src/SynTree/Expression.h@ d76f32c

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum stuck-waitfor-destruct
Last change on this file since d76f32c was aaeacf4, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Removed global look-up table from UniqueId to Decl

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