source: src/SynTree/Expression.h@ 99cadc60

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 99cadc60 was 033ff37, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

remove attribute expression '@'name mechanism

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