source: src/SynTree/Expression.h@ e307e12

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 e307e12 was 3b0c8cb, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Implemented Keyword cast in the alternative finder to remove aliassing problems

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