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

ADT ast-experimental pthread-emulation qualifiedEnum
Last change on this file since 1f4fde5 was 6e50a6b, checked in by Michael Brooks <mlbrooks@…>, 4 years ago

Implementing language-provided syntax for (array) dimensions.

Former z(i) and Z(N) macros are eliminated.

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