source: src/SynTree/Expression.h@ 158b026

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 158b026 was 5d00425, checked in by Andrew Beach <ajbeach@…>, 6 years ago

StmtExpr also does not have the lvalue I originally expected.

  • 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
[3b58d91]277 Expression * get_member() const { return member; }
278 void set_member( Expression * newValue ) { member = newValue; }
[5ded739]279 Expression * get_aggregate() const { return aggregate; }
280 void set_aggregate( Expression * newValue ) { aggregate = newValue; }
[0dd3a2f]281
[7870799]282 virtual UntypedMemberExpr * clone() const override { return new UntypedMemberExpr( * this ); }
283 virtual void accept( Visitor & v ) override { v.visit( this ); }
284 virtual void accept( Visitor & v ) const override { v.visit( this ); }
285 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
286 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b73452]287};
288
[4551a6e]289/// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer.
290/// Does not take ownership of member.
[0dd3a2f]291class MemberExpr : public Expression {
292 public:
[65cdc1e]293 DeclarationWithType * member;
294 Expression * aggregate;
295
[bf4b4cf]296 MemberExpr( DeclarationWithType * member, Expression * aggregate );
[5ded739]297 MemberExpr( const MemberExpr & other );
[0dd3a2f]298 virtual ~MemberExpr();
299
[14388c1]300 bool get_lvalue() const final;
301
[5ded739]302 DeclarationWithType * get_member() const { return member; }
303 void set_member( DeclarationWithType * newValue ) { member = newValue; }
304 Expression * get_aggregate() const { return aggregate; }
305 void set_aggregate( Expression * newValue ) { aggregate = newValue; }
[0dd3a2f]306
[7870799]307 virtual MemberExpr * clone() const override { return new MemberExpr( * this ); }
308 virtual void accept( Visitor & v ) override { v.visit( this ); }
309 virtual void accept( Visitor & v ) const override { v.visit( this ); }
310 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
311 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b73452]312};
313
[4551a6e]314/// VariableExpr represents an expression that simply refers to the value of a named variable.
315/// Does not take ownership of var.
[0dd3a2f]316class VariableExpr : public Expression {
317 public:
[65cdc1e]318 DeclarationWithType * var;
319
[546e712]320 VariableExpr();
[bf4b4cf]321 VariableExpr( DeclarationWithType * var );
[5ded739]322 VariableExpr( const VariableExpr & other );
[0dd3a2f]323 virtual ~VariableExpr();
324
[14388c1]325 bool get_lvalue() const final;
326
[5ded739]327 DeclarationWithType * get_var() const { return var; }
328 void set_var( DeclarationWithType * newValue ) { var = newValue; }
[0dd3a2f]329
[8a6cf7e]330 static VariableExpr * functionPointer( FunctionDecl * decl );
331
[7870799]332 virtual VariableExpr * clone() const override { return new VariableExpr( * this ); }
333 virtual void accept( Visitor & v ) override { v.visit( this ); }
334 virtual void accept( Visitor & v ) const override { v.visit( this ); }
335 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
336 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b73452]337};
338
[3be261a]339/// ConstantExpr represents an expression that simply refers to the value of a constant
[0dd3a2f]340class ConstantExpr : public Expression {
341 public:
[65cdc1e]342 Constant constant;
343
[bf4b4cf]344 ConstantExpr( Constant constant );
[5ded739]345 ConstantExpr( const ConstantExpr & other );
[0dd3a2f]346 virtual ~ConstantExpr();
347
[5ded739]348 Constant * get_constant() { return & constant; }
[ddb80bd]349 const Constant * get_constant() const { return & constant; }
[5ded739]350 void set_constant( const Constant & newValue ) { constant = newValue; }
[0dd3a2f]351
[ddb80bd]352 long long int intValue() const;
353
[7870799]354 virtual ConstantExpr * clone() const override { return new ConstantExpr( * this ); }
355 virtual void accept( Visitor & v ) override { v.visit( this ); }
356 virtual void accept( Visitor & v ) const override { v.visit( this ); }
357 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
358 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b73452]359};
360
[47534159]361/// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
[0dd3a2f]362class SizeofExpr : public Expression {
363 public:
[65cdc1e]364 Expression * expr;
365 Type * type;
366 bool isType;
367
[bf4b4cf]368 SizeofExpr( Expression * expr );
[5ded739]369 SizeofExpr( const SizeofExpr & other );
[bf4b4cf]370 SizeofExpr( Type * type );
[0dd3a2f]371 virtual ~SizeofExpr();
372
[5ded739]373 Expression * get_expr() const { return expr; }
374 void set_expr( Expression * newValue ) { expr = newValue; }
375 Type * get_type() const { return type; }
376 void set_type( Type * newValue ) { type = newValue; }
[0dd3a2f]377 bool get_isType() const { return isType; }
378 void set_isType( bool newValue ) { isType = newValue; }
379
[7870799]380 virtual SizeofExpr * clone() const override { return new SizeofExpr( * this ); }
381 virtual void accept( Visitor & v ) override { v.visit( this ); }
382 virtual void accept( Visitor & v ) const override { v.visit( this ); }
383 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
384 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b73452]385};
386
[47534159]387/// AlignofExpr represents an alignof expression
388class AlignofExpr : public Expression {
389 public:
[65cdc1e]390 Expression * expr;
391 Type * type;
392 bool isType;
393
[bf4b4cf]394 AlignofExpr( Expression * expr );
[5ded739]395 AlignofExpr( const AlignofExpr & other );
[bf4b4cf]396 AlignofExpr( Type * type );
[47534159]397 virtual ~AlignofExpr();
398
[5ded739]399 Expression * get_expr() const { return expr; }
400 void set_expr( Expression * newValue ) { expr = newValue; }
401 Type * get_type() const { return type; }
402 void set_type( Type * newValue ) { type = newValue; }
[47534159]403 bool get_isType() const { return isType; }
404 void set_isType( bool newValue ) { isType = newValue; }
405
[7870799]406 virtual AlignofExpr * clone() const override { return new AlignofExpr( * this ); }
407 virtual void accept( Visitor & v ) override { v.visit( this ); }
408 virtual void accept( Visitor & v ) const override { v.visit( this ); }
409 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
410 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[47534159]411};
412
[2a4b088]413/// UntypedOffsetofExpr represents an offsetof expression before resolution
414class UntypedOffsetofExpr : public Expression {
415 public:
[65cdc1e]416 Type * type;
417 std::string member;
418
[bf4b4cf]419 UntypedOffsetofExpr( Type * type, const std::string & member );
[5ded739]420 UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
[2a4b088]421 virtual ~UntypedOffsetofExpr();
422
423 std::string get_member() const { return member; }
[5ded739]424 void set_member( const std::string & newValue ) { member = newValue; }
425 Type * get_type() const { return type; }
426 void set_type( Type * newValue ) { type = newValue; }
427
[7870799]428 virtual UntypedOffsetofExpr * clone() const override { return new UntypedOffsetofExpr( * this ); }
429 virtual void accept( Visitor & v ) override { v.visit( this ); }
430 virtual void accept( Visitor & v ) const override { v.visit( this ); }
431 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
432 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[2a4b088]433};
434
[25a054f]435/// OffsetofExpr represents an offsetof expression
436class OffsetofExpr : public Expression {
437 public:
[65cdc1e]438 Type * type;
439 DeclarationWithType * member;
440
[bf4b4cf]441 OffsetofExpr( Type * type, DeclarationWithType * member );
[5ded739]442 OffsetofExpr( const OffsetofExpr & other );
[25a054f]443 virtual ~OffsetofExpr();
444
[5ded739]445 Type * get_type() const { return type; }
446 void set_type( Type * newValue ) { type = newValue; }
447 DeclarationWithType * get_member() const { return member; }
448 void set_member( DeclarationWithType * newValue ) { member = newValue; }
449
[7870799]450 virtual OffsetofExpr * clone() const override { return new OffsetofExpr( * this ); }
451 virtual void accept( Visitor & v ) override { v.visit( this ); }
452 virtual void accept( Visitor & v ) const override { v.visit( this ); }
453 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
454 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[25a054f]455};
456
[afc1045]457/// Expression representing a pack of field-offsets for a generic type
458class OffsetPackExpr : public Expression {
459public:
[65cdc1e]460 StructInstType * type;
461
[bf4b4cf]462 OffsetPackExpr( StructInstType * type );
[5ded739]463 OffsetPackExpr( const OffsetPackExpr & other );
[afc1045]464 virtual ~OffsetPackExpr();
465
[5ded739]466 StructInstType * get_type() const { return type; }
467 void set_type( StructInstType * newValue ) { type = newValue; }
[afc1045]468
[7870799]469 virtual OffsetPackExpr * clone() const override { return new OffsetPackExpr( * this ); }
470 virtual void accept( Visitor & v ) override { v.visit( this ); }
471 virtual void accept( Visitor & v ) const override { v.visit( this ); }
472 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
473 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[afc1045]474};
475
[47534159]476/// LogicalExpr represents a short-circuit boolean expression (&& or ||)
[0dd3a2f]477class LogicalExpr : public Expression {
478 public:
[65cdc1e]479 Expression * arg1;
480 Expression * arg2;
481
[bf4b4cf]482 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true );
[5ded739]483 LogicalExpr( const LogicalExpr & other );
[0dd3a2f]484 virtual ~LogicalExpr();
485
486 bool get_isAnd() const { return isAnd; }
[5ded739]487 Expression * get_arg1() { return arg1; }
488 void set_arg1( Expression * newValue ) { arg1 = newValue; }
489 Expression * get_arg2() const { return arg2; }
490 void set_arg2( Expression * newValue ) { arg2 = newValue; }
491
[7870799]492 virtual LogicalExpr * clone() const override { return new LogicalExpr( * this ); }
493 virtual void accept( Visitor & v ) override { v.visit( this ); }
494 virtual void accept( Visitor & v ) const override { v.visit( this ); }
495 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
496 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[65cdc1e]497
[0dd3a2f]498 private:
499 bool isAnd;
[51b73452]500};
501
[47534159]502/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
[0dd3a2f]503class ConditionalExpr : public Expression {
504 public:
[65cdc1e]505 Expression * arg1;
506 Expression * arg2;
507 Expression * arg3;
508
[bf4b4cf]509 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 );
[5ded739]510 ConditionalExpr( const ConditionalExpr & other );
[0dd3a2f]511 virtual ~ConditionalExpr();
512
[14388c1]513 bool get_lvalue() const final;
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
[7870799]522 virtual ConditionalExpr * clone() const override { return new ConditionalExpr( * this ); }
523 virtual void accept( Visitor & v ) override { v.visit( this ); }
524 virtual void accept( Visitor & v ) const override { v.visit( this ); }
525 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
526 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b73452]527};
528
[47534159]529/// CommaExpr represents the sequence operator ( a, b )
[0dd3a2f]530class CommaExpr : public Expression {
531 public:
[65cdc1e]532 Expression * arg1;
533 Expression * arg2;
534
[bf4b4cf]535 CommaExpr( Expression * arg1, Expression * arg2 );
[5ded739]536 CommaExpr( const CommaExpr & other );
[0dd3a2f]537 virtual ~CommaExpr();
538
[14388c1]539 bool get_lvalue() const final;
540
[5ded739]541 Expression * get_arg1() const { return arg1; }
542 void set_arg1( Expression * newValue ) { arg1 = newValue; }
543 Expression * get_arg2() const { return arg2; }
544 void set_arg2( Expression * newValue ) { arg2 = newValue; }
[0dd3a2f]545
[7870799]546 virtual CommaExpr * clone() const override { return new CommaExpr( * this ); }
547 virtual void accept( Visitor & v ) override { v.visit( this ); }
548 virtual void accept( Visitor & v ) const override { v.visit( this ); }
549 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
550 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b73452]551};
552
[47534159]553/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
[0dd3a2f]554class TypeExpr : public Expression {
555 public:
[65cdc1e]556 Type * type;
557
[5ded739]558 TypeExpr( Type * type );
559 TypeExpr( const TypeExpr & other );
[0dd3a2f]560 virtual ~TypeExpr();
561
[5ded739]562 Type * get_type() const { return type; }
563 void set_type( Type * newValue ) { type = newValue; }
[0dd3a2f]564
[7870799]565 virtual TypeExpr * clone() const override { return new TypeExpr( * this ); }
566 virtual void accept( Visitor & v ) override { v.visit( this ); }
567 virtual void accept( Visitor & v ) const override { v.visit( this ); }
568 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
569 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b73452]570};
571
[47534159]572/// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
[7f5566b]573class AsmExpr : public Expression {
574 public:
[65cdc1e]575 Expression * inout;
[e612146c]576 Expression * constraint;
[65cdc1e]577 Expression * operand;
578
[e612146c]579 AsmExpr( Expression * inout, Expression * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
[3be261a]580 AsmExpr( const AsmExpr & other );
[7f5566b]581 virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
582
[5ded739]583 Expression * get_inout() const { return inout; }
584 void set_inout( Expression * newValue ) { inout = newValue; }
[7f5566b]585
[e612146c]586 Expression * get_constraint() const { return constraint; }
587 void set_constraint( Expression * newValue ) { constraint = newValue; }
[7f5566b]588
[5ded739]589 Expression * get_operand() const { return operand; }
590 void set_operand( Expression * newValue ) { operand = newValue; }
[7f5566b]591
[7870799]592 virtual AsmExpr * clone() const override { return new AsmExpr( * this ); }
593 virtual void accept( Visitor & v ) override { v.visit( this ); }
594 virtual void accept( Visitor & v ) const override { v.visit( this ); }
595 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
596 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[65cdc1e]597
[7f5566b]598 // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
599};
600
[db4ecc5]601/// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
602/// along with a set of copy constructor calls, one for each argument.
603class ImplicitCopyCtorExpr : public Expression {
604public:
[2f86ddf]605 ApplicationExpr * callExpr = nullptr;
[65cdc1e]606
[db4ecc5]607 ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
608 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
609 virtual ~ImplicitCopyCtorExpr();
610
[7870799]611 virtual ImplicitCopyCtorExpr * clone() const override { return new ImplicitCopyCtorExpr( * this ); }
612 virtual void accept( Visitor & v ) override { v.visit( this ); }
613 virtual void accept( Visitor & v ) const override { v.visit( this ); }
614 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
615 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[db4ecc5]616};
617
[b6fe7e6]618/// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
619class ConstructorExpr : public Expression {
620public:
[65cdc1e]621 Expression * callExpr;
622
[b6fe7e6]623 ConstructorExpr( Expression * callExpr );
624 ConstructorExpr( const ConstructorExpr & other );
625 ~ConstructorExpr();
[0dd3a2f]626
[14388c1]627 bool get_lvalue() const final;
628
[5ded739]629 Expression * get_callExpr() const { return callExpr; }
630 void set_callExpr( Expression * newValue ) { callExpr = newValue; }
[0dd3a2f]631
[7870799]632 virtual ConstructorExpr * clone() const override { return new ConstructorExpr( * this ); }
633 virtual void accept( Visitor & v ) override { v.visit( this ); }
634 virtual void accept( Visitor & v ) const override { v.visit( this ); }
635 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
636 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b73452]637};
638
[630a82a]639/// CompoundLiteralExpr represents a C99 'compound literal'
640class CompoundLiteralExpr : public Expression {
641 public:
[65cdc1e]642 Initializer * initializer;
643
[630a82a]644 CompoundLiteralExpr( Type * type, Initializer * initializer );
[5ded739]645 CompoundLiteralExpr( const CompoundLiteralExpr & other );
[3b58d91]646 virtual ~CompoundLiteralExpr();
[630a82a]647
[14388c1]648 bool get_lvalue() const final;
649
[630a82a]650 Initializer * get_initializer() const { return initializer; }
651 void set_initializer( Initializer * i ) { initializer = i; }
652
[7870799]653 virtual CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr( * this ); }
654 virtual void accept( Visitor & v ) override { v.visit( this ); }
655 virtual void accept( Visitor & v ) const override { v.visit( this ); }
656 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
657 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[630a82a]658};
659
[b6fe7e6]660/// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
[8688ce1]661class RangeExpr : public Expression {
662 public:
[65cdc1e]663 Expression * low, * high;
664
[5ded739]665 RangeExpr( Expression * low, Expression * high );
666 RangeExpr( const RangeExpr & other );
[8688ce1]667
[d9e2280]668 Expression * get_low() const { return low; }
669 Expression * get_high() const { return high; }
[5ded739]670 RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; }
671 RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
[8688ce1]672
[7870799]673 virtual RangeExpr * clone() const override { return new RangeExpr( * this ); }
674 virtual void accept( Visitor & v ) override { v.visit( this ); }
675 virtual void accept( Visitor & v ) const override { v.visit( this ); }
676 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
677 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[8688ce1]678};
679
[907eccb]680/// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution
681class UntypedTupleExpr : public Expression {
682 public:
[65cdc1e]683 std::list<Expression*> exprs;
684
[bf4b4cf]685 UntypedTupleExpr( const std::list< Expression * > & exprs );
[5ded739]686 UntypedTupleExpr( const UntypedTupleExpr & other );
[907eccb]687 virtual ~UntypedTupleExpr();
688
689 std::list<Expression*>& get_exprs() { return exprs; }
690
[7870799]691 virtual UntypedTupleExpr * clone() const override { return new UntypedTupleExpr( * this ); }
692 virtual void accept( Visitor & v ) override { v.visit( this ); }
693 virtual void accept( Visitor & v ) const override { v.visit( this ); }
694 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
695 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[907eccb]696};
697
[6eb8948]698/// TupleExpr represents a tuple expression ( [a, b, c] )
699class TupleExpr : public Expression {
700 public:
[65cdc1e]701 std::list<Expression*> exprs;
702
[bf4b4cf]703 TupleExpr( const std::list< Expression * > & exprs );
[5ded739]704 TupleExpr( const TupleExpr & other );
[6eb8948]705 virtual ~TupleExpr();
706
[3c7f01b]707 bool get_lvalue() const final;
708
[6eb8948]709 std::list<Expression*>& get_exprs() { return exprs; }
710
[7870799]711 virtual TupleExpr * clone() const override { return new TupleExpr( * this ); }
712 virtual void accept( Visitor & v ) override { v.visit( this ); }
713 virtual void accept( Visitor & v ) const override { v.visit( this ); }
714 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
715 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[6eb8948]716};
717
[3b58d91]718/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
719class TupleIndexExpr : public Expression {
720 public:
[65cdc1e]721 Expression * tuple;
722 unsigned int index;
723
[3b58d91]724 TupleIndexExpr( Expression * tuple, unsigned int index );
[5ded739]725 TupleIndexExpr( const TupleIndexExpr & other );
[3b58d91]726 virtual ~TupleIndexExpr();
727
[14388c1]728 bool get_lvalue() const final;
729
[3b58d91]730 Expression * get_tuple() const { return tuple; }
731 int get_index() const { return index; }
[5ded739]732 TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; }
[3b58d91]733 TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
734
[7870799]735 virtual TupleIndexExpr * clone() const override { return new TupleIndexExpr( * this ); }
736 virtual void accept( Visitor & v ) override { v.visit( this ); }
737 virtual void accept( Visitor & v ) const override { v.visit( this ); }
738 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
739 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[3b58d91]740};
741
[65660bd]742/// 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]743class TupleAssignExpr : public Expression {
[3b58d91]744 public:
[65cdc1e]745 StmtExpr * stmtExpr = nullptr;
746
[bf4b4cf]747 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls );
[5ded739]748 TupleAssignExpr( const TupleAssignExpr & other );
[6eb8948]749 virtual ~TupleAssignExpr();
[3b58d91]750
[d5556a3]751 TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
752 StmtExpr * get_stmtExpr() const { return stmtExpr; }
[3b58d91]753
[7870799]754 virtual TupleAssignExpr * clone() const override { return new TupleAssignExpr( * this ); }
755 virtual void accept( Visitor & v ) override { v.visit( this ); }
756 virtual void accept( Visitor & v ) const override { v.visit( this ); }
757 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
758 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[20de6fb]759
760 friend class ConverterNewToOld;
761 private:
762 TupleAssignExpr( StmtExpr * stmts );
[3b58d91]763};
764
[6eb8948]765/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
766class StmtExpr : public Expression {
767public:
[65cdc1e]768 CompoundStmt * statements;
769 std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
770 std::list< Expression * > dtors; // destructor(s) for return variable(s)
771
[0e315a5]772 // readonly
773 ExprStmt * resultExpr = nullptr;
774
[5ded739]775 StmtExpr( CompoundStmt * statements );
[6eb8948]776 StmtExpr( const StmtExpr & other );
777 virtual ~StmtExpr();
[3b58d91]778
[5d00425]779 bool get_lvalue() const final;
780
[6eb8948]781 CompoundStmt * get_statements() const { return statements; }
782 StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
[3b58d91]783
[5e2c348]784 // call to set the result type of this StmtExpr based on its body
785 void computeResult();
786
[d5556a3]787 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
788 std::list< Expression * > & get_dtors() { return dtors; }
789
[7870799]790 virtual StmtExpr * clone() const override { return new StmtExpr( * this ); }
791 virtual void accept( Visitor & v ) override { v.visit( this ); }
792 virtual void accept( Visitor & v ) const override { v.visit( this ); }
793 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
794 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[3b58d91]795};
796
[3c13c03]797class UniqueExpr : public Expression {
798public:
[65cdc1e]799 Expression * expr;
800 ObjectDecl * object;
801 VariableExpr * var;
802
[bf32bb8]803 UniqueExpr( Expression * expr, long long idVal = -1 );
[3c13c03]804 UniqueExpr( const UniqueExpr & other );
805 ~UniqueExpr();
806
[141b786]807 Expression * get_expr() const { return expr; }
808 UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
[3c13c03]809
[141b786]810 ObjectDecl * get_object() const { return object; }
811 UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; }
812
813 VariableExpr * get_var() const { return var; }
814 UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; }
[77971f6]815
[bf32bb8]816 int get_id() const { return id; }
817
[7870799]818 virtual UniqueExpr * clone() const override { return new UniqueExpr( * this ); }
819 virtual void accept( Visitor & v ) override { v.visit( this ); }
820 virtual void accept( Visitor & v ) const override { v.visit( this ); }
821 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
822 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[65cdc1e]823
[3c13c03]824private:
[bf32bb8]825 int id;
826 static long long count;
[3c13c03]827};
828
[e4d829b]829struct InitAlternative {
830public:
831 Type * type = nullptr;
832 Designation * designation = nullptr;
833 InitAlternative( Type * type, Designation * designation );
834 InitAlternative( const InitAlternative & other );
835 InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it
836 ~InitAlternative();
837};
838
839class UntypedInitExpr : public Expression {
840public:
[65cdc1e]841 Expression * expr;
842 std::list<InitAlternative> initAlts;
843
[e4d829b]844 UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
845 UntypedInitExpr( const UntypedInitExpr & other );
846 ~UntypedInitExpr();
847
848 Expression * get_expr() const { return expr; }
849 UntypedInitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
850
851 std::list<InitAlternative> & get_initAlts() { return initAlts; }
852
[7870799]853 virtual UntypedInitExpr * clone() const override { return new UntypedInitExpr( * this ); }
854 virtual void accept( Visitor & v ) override { v.visit( this ); }
855 virtual void accept( Visitor & v ) const override { v.visit( this ); }
856 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
857 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[e4d829b]858};
859
860class InitExpr : public Expression {
861public:
[65cdc1e]862 Expression * expr;
863 Designation * designation;
864
[62423350]865 InitExpr( Expression * expr, Designation * designation );
[e4d829b]866 InitExpr( const InitExpr & other );
867 ~InitExpr();
868
869 Expression * get_expr() const { return expr; }
870 InitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
871
872 Designation * get_designation() const { return designation; }
873 InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; }
874
[7870799]875 virtual InitExpr * clone() const override { return new InitExpr( * this ); }
876 virtual void accept( Visitor & v ) override { v.visit( this ); }
877 virtual void accept( Visitor & v ) const override { v.visit( this ); }
878 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
879 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[e4d829b]880};
881
[44b4114]882/// expression that contains a deleted identifier - should never make it past the resolver.
883class DeletedExpr : public Expression {
884public:
885 Expression * expr;
[e67991f]886 Declaration * deleteStmt;
[44b4114]887
[e67991f]888 DeletedExpr( Expression * expr, Declaration * deleteStmt );
[44b4114]889 DeletedExpr( const DeletedExpr & other );
890 ~DeletedExpr();
891
[7870799]892 virtual DeletedExpr * clone() const override { return new DeletedExpr( * this ); }
893 virtual void accept( Visitor & v ) override { v.visit( this ); }
894 virtual void accept( Visitor & v ) const override { v.visit( this ); }
895 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
896 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[44b4114]897};
898
[0f79853]899/// expression wrapping the use of a default argument - should never make it past the resolver.
900class DefaultArgExpr : public Expression {
901public:
902 Expression * expr;
903
904 DefaultArgExpr( Expression * expr );
905 DefaultArgExpr( const DefaultArgExpr & other );
906 ~DefaultArgExpr();
907
[7870799]908 virtual DefaultArgExpr * clone() const override { return new DefaultArgExpr( * this ); }
909 virtual void accept( Visitor & v ) override { v.visit( this ); }
910 virtual void accept( Visitor & v ) const override { v.visit( this ); }
911 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
912 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[0f79853]913};
914
[d807ca28]915/// C11 _Generic expression
916class GenericExpr : public Expression {
917public:
918 struct Association {
919 Type * type = nullptr;
920 Expression * expr = nullptr;
921 bool isDefault = false;
922
923 Association( Type * type, Expression * expr );
924 Association( Expression * expr );
925 Association( const Association & other );
926 Association & operator=( const Association & other ) = delete; // at the moment this isn't used, and I don't want to implement it
927 ~Association();
928 };
929
930 Expression * control;
931 std::list<Association> associations;
932
933 GenericExpr( Expression * control, const std::list<Association> & assoc );
934 GenericExpr( const GenericExpr & other );
935 virtual ~GenericExpr();
936
[7870799]937 virtual GenericExpr * clone() const override { return new GenericExpr( * this ); }
938 virtual void accept( Visitor & v ) override { v.visit( this ); }
939 virtual void accept( Visitor & v ) const override { v.visit( this ); }
940 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
941 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[d807ca28]942};
943
[0dd3a2f]944// Local Variables: //
945// tab-width: 4 //
946// mode: c++ //
947// compile-command: "make install" //
948// End: //
Note: See TracBrowser for help on using the repository browser.