source: src/SynTree/Expression.h@ cc32d83

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum with_gc
Last change on this file since cc32d83 was 9a705dc8, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Implement concurrency keyword casts

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