source: src/SynTree/Expression.h@ 5964127

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 resolv-new with_gc
Last change on this file since 5964127 was 44b4114, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Add DeletedExpr node for use of deleted identifiers

  • Property mode set to 100644
File size: 31.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
191 CastExpr( Expression * arg );
192 CastExpr( Expression * arg, Type * toType );
193 CastExpr( const CastExpr & other );
194 virtual ~CastExpr();
195
196 Expression * get_arg() const { return arg; }
197 void set_arg( Expression * newValue ) { arg = newValue; }
198
199 virtual CastExpr * clone() const { return new CastExpr( * this ); }
200 virtual void accept( Visitor & v ) { v.visit( this ); }
201 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
202 virtual void print( std::ostream & os, Indenter indent = {} ) const;
203};
204
205/// VirtualCastExpr repersents a virtual dynamic cast, e.g. (virtual exception)e
206class VirtualCastExpr : public Expression {
207 public:
208 Expression * arg;
209
210 VirtualCastExpr( Expression * arg, Type * toType );
211 VirtualCastExpr( const VirtualCastExpr & other );
212 virtual ~VirtualCastExpr();
213
214 Expression * get_arg() const { return arg; }
215 void set_arg( Expression * newValue ) { arg = newValue; }
216
217 virtual VirtualCastExpr * clone() const { return new VirtualCastExpr( * this ); }
218 virtual void accept( Visitor & v ) { v.visit( this ); }
219 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
220 virtual void print( std::ostream & os, Indenter indent = {} ) const;
221};
222
223/// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
224class UntypedMemberExpr : public Expression {
225 public:
226 Expression * member;
227 Expression * aggregate;
228
229 UntypedMemberExpr( Expression * member, Expression * aggregate );
230 UntypedMemberExpr( const UntypedMemberExpr & other );
231 virtual ~UntypedMemberExpr();
232
233 Expression * get_member() const { return member; }
234 void set_member( Expression * newValue ) { member = newValue; }
235 Expression * get_aggregate() const { return aggregate; }
236 void set_aggregate( Expression * newValue ) { aggregate = newValue; }
237
238 virtual UntypedMemberExpr * clone() const { return new UntypedMemberExpr( * this ); }
239 virtual void accept( Visitor & v ) { v.visit( this ); }
240 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
241 virtual void print( std::ostream & os, Indenter indent = {} ) const;
242};
243
244/// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer.
245/// Does not take ownership of member.
246class MemberExpr : public Expression {
247 public:
248 DeclarationWithType * member;
249 Expression * aggregate;
250
251 MemberExpr( DeclarationWithType * member, Expression * aggregate );
252 MemberExpr( const MemberExpr & other );
253 virtual ~MemberExpr();
254
255 DeclarationWithType * get_member() const { return member; }
256 void set_member( DeclarationWithType * newValue ) { member = newValue; }
257 Expression * get_aggregate() const { return aggregate; }
258 void set_aggregate( Expression * newValue ) { aggregate = newValue; }
259
260 virtual MemberExpr * clone() const { return new MemberExpr( * 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/// VariableExpr represents an expression that simply refers to the value of a named variable.
267/// Does not take ownership of var.
268class VariableExpr : public Expression {
269 public:
270 DeclarationWithType * var;
271
272 VariableExpr( DeclarationWithType * var );
273 VariableExpr( const VariableExpr & other );
274 virtual ~VariableExpr();
275
276 DeclarationWithType * get_var() const { return var; }
277 void set_var( DeclarationWithType * newValue ) { var = newValue; }
278
279 static VariableExpr * functionPointer( FunctionDecl * decl );
280
281 virtual VariableExpr * clone() const { return new VariableExpr( * this ); }
282 virtual void accept( Visitor & v ) { v.visit( this ); }
283 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
284 virtual void print( std::ostream & os, Indenter indent = {} ) const;
285};
286
287/// ConstantExpr represents an expression that simply refers to the value of a constant
288class ConstantExpr : public Expression {
289 public:
290 Constant constant;
291
292 ConstantExpr( Constant constant );
293 ConstantExpr( const ConstantExpr & other );
294 virtual ~ConstantExpr();
295
296 Constant * get_constant() { return & constant; }
297 const Constant * get_constant() const { return & constant; }
298 void set_constant( const Constant & newValue ) { constant = newValue; }
299
300 long long int intValue() const;
301
302 virtual ConstantExpr * clone() const { return new ConstantExpr( * this ); }
303 virtual void accept( Visitor & v ) { v.visit( this ); }
304 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
305 virtual void print( std::ostream & os, Indenter indent = {} ) const;
306};
307
308/// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
309class SizeofExpr : public Expression {
310 public:
311 Expression * expr;
312 Type * type;
313 bool isType;
314
315 SizeofExpr( Expression * expr );
316 SizeofExpr( const SizeofExpr & other );
317 SizeofExpr( Type * type );
318 virtual ~SizeofExpr();
319
320 Expression * get_expr() const { return expr; }
321 void set_expr( Expression * newValue ) { expr = newValue; }
322 Type * get_type() const { return type; }
323 void set_type( Type * newValue ) { type = newValue; }
324 bool get_isType() const { return isType; }
325 void set_isType( bool newValue ) { isType = newValue; }
326
327 virtual SizeofExpr * clone() const { return new SizeofExpr( * this ); }
328 virtual void accept( Visitor & v ) { v.visit( this ); }
329 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
330 virtual void print( std::ostream & os, Indenter indent = {} ) const;
331};
332
333/// AlignofExpr represents an alignof expression
334class AlignofExpr : public Expression {
335 public:
336 Expression * expr;
337 Type * type;
338 bool isType;
339
340 AlignofExpr( Expression * expr );
341 AlignofExpr( const AlignofExpr & other );
342 AlignofExpr( Type * type );
343 virtual ~AlignofExpr();
344
345 Expression * get_expr() const { return expr; }
346 void set_expr( Expression * newValue ) { expr = newValue; }
347 Type * get_type() const { return type; }
348 void set_type( Type * newValue ) { type = newValue; }
349 bool get_isType() const { return isType; }
350 void set_isType( bool newValue ) { isType = newValue; }
351
352 virtual AlignofExpr * clone() const { return new AlignofExpr( * this ); }
353 virtual void accept( Visitor & v ) { v.visit( this ); }
354 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
355 virtual void print( std::ostream & os, Indenter indent = {} ) const;
356};
357
358/// UntypedOffsetofExpr represents an offsetof expression before resolution
359class UntypedOffsetofExpr : public Expression {
360 public:
361 Type * type;
362 std::string member;
363
364 UntypedOffsetofExpr( Type * type, const std::string & member );
365 UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
366 virtual ~UntypedOffsetofExpr();
367
368 std::string get_member() const { return member; }
369 void set_member( const std::string & newValue ) { member = newValue; }
370 Type * get_type() const { return type; }
371 void set_type( Type * newValue ) { type = newValue; }
372
373 virtual UntypedOffsetofExpr * clone() const { return new UntypedOffsetofExpr( * this ); }
374 virtual void accept( Visitor & v ) { v.visit( this ); }
375 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
376 virtual void print( std::ostream & os, Indenter indent = {} ) const;
377};
378
379/// OffsetofExpr represents an offsetof expression
380class OffsetofExpr : public Expression {
381 public:
382 Type * type;
383 DeclarationWithType * member;
384
385 OffsetofExpr( Type * type, DeclarationWithType * member );
386 OffsetofExpr( const OffsetofExpr & other );
387 virtual ~OffsetofExpr();
388
389 Type * get_type() const { return type; }
390 void set_type( Type * newValue ) { type = newValue; }
391 DeclarationWithType * get_member() const { return member; }
392 void set_member( DeclarationWithType * newValue ) { member = newValue; }
393
394 virtual OffsetofExpr * clone() const { return new OffsetofExpr( * this ); }
395 virtual void accept( Visitor & v ) { v.visit( this ); }
396 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
397 virtual void print( std::ostream & os, Indenter indent = {} ) const;
398};
399
400/// Expression representing a pack of field-offsets for a generic type
401class OffsetPackExpr : public Expression {
402public:
403 StructInstType * type;
404
405 OffsetPackExpr( StructInstType * type );
406 OffsetPackExpr( const OffsetPackExpr & other );
407 virtual ~OffsetPackExpr();
408
409 StructInstType * get_type() const { return type; }
410 void set_type( StructInstType * newValue ) { type = newValue; }
411
412 virtual OffsetPackExpr * clone() const { return new OffsetPackExpr( * this ); }
413 virtual void accept( Visitor & v ) { v.visit( this ); }
414 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
415 virtual void print( std::ostream & os, Indenter indent = {} ) const;
416};
417
418/// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
419class AttrExpr : public Expression {
420 public:
421 Expression * attr;
422 Expression * expr;
423 Type * type;
424 bool isType;
425
426 AttrExpr(Expression * attr, Expression * expr );
427 AttrExpr( const AttrExpr & other );
428 AttrExpr( Expression * attr, Type * type );
429 virtual ~AttrExpr();
430
431 Expression * get_attr() const { return attr; }
432 void set_attr( Expression * newValue ) { attr = newValue; }
433 Expression * get_expr() const { return expr; }
434 void set_expr( Expression * newValue ) { expr = newValue; }
435 Type * get_type() const { return type; }
436 void set_type( Type * newValue ) { type = newValue; }
437 bool get_isType() const { return isType; }
438 void set_isType( bool newValue ) { isType = newValue; }
439
440 virtual AttrExpr * clone() const { return new AttrExpr( * this ); }
441 virtual void accept( Visitor & v ) { v.visit( this ); }
442 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
443 virtual void print( std::ostream & os, Indenter indent = {} ) const;
444};
445
446/// LogicalExpr represents a short-circuit boolean expression (&& or ||)
447class LogicalExpr : public Expression {
448 public:
449 Expression * arg1;
450 Expression * arg2;
451
452 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true );
453 LogicalExpr( const LogicalExpr & other );
454 virtual ~LogicalExpr();
455
456 bool get_isAnd() const { return isAnd; }
457 Expression * get_arg1() { return arg1; }
458 void set_arg1( Expression * newValue ) { arg1 = newValue; }
459 Expression * get_arg2() const { return arg2; }
460 void set_arg2( Expression * newValue ) { arg2 = newValue; }
461
462 virtual LogicalExpr * clone() const { return new LogicalExpr( * 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 private:
468 bool isAnd;
469};
470
471/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
472class ConditionalExpr : public Expression {
473 public:
474 Expression * arg1;
475 Expression * arg2;
476 Expression * arg3;
477
478 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 );
479 ConditionalExpr( const ConditionalExpr & other );
480 virtual ~ConditionalExpr();
481
482 Expression * get_arg1() const { return arg1; }
483 void set_arg1( Expression * newValue ) { arg1 = newValue; }
484 Expression * get_arg2() const { return arg2; }
485 void set_arg2( Expression * newValue ) { arg2 = newValue; }
486 Expression * get_arg3() const { return arg3; }
487 void set_arg3( Expression * newValue ) { arg3 = newValue; }
488
489 virtual ConditionalExpr * clone() const { return new ConditionalExpr( * this ); }
490 virtual void accept( Visitor & v ) { v.visit( this ); }
491 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
492 virtual void print( std::ostream & os, Indenter indent = {} ) const;
493};
494
495/// CommaExpr represents the sequence operator ( a, b )
496class CommaExpr : public Expression {
497 public:
498 Expression * arg1;
499 Expression * arg2;
500
501 CommaExpr( Expression * arg1, Expression * arg2 );
502 CommaExpr( const CommaExpr & other );
503 virtual ~CommaExpr();
504
505 Expression * get_arg1() const { return arg1; }
506 void set_arg1( Expression * newValue ) { arg1 = newValue; }
507 Expression * get_arg2() const { return arg2; }
508 void set_arg2( Expression * newValue ) { arg2 = newValue; }
509
510 virtual CommaExpr * clone() const { return new CommaExpr( * this ); }
511 virtual void accept( Visitor & v ) { v.visit( this ); }
512 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
513 virtual void print( std::ostream & os, Indenter indent = {} ) const;
514};
515
516/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
517class TypeExpr : public Expression {
518 public:
519 Type * type;
520
521 TypeExpr( Type * type );
522 TypeExpr( const TypeExpr & other );
523 virtual ~TypeExpr();
524
525 Type * get_type() const { return type; }
526 void set_type( Type * newValue ) { type = newValue; }
527
528 virtual TypeExpr * clone() const { return new TypeExpr( * this ); }
529 virtual void accept( Visitor & v ) { v.visit( this ); }
530 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
531 virtual void print( std::ostream & os, Indenter indent = {} ) const;
532};
533
534/// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
535class AsmExpr : public Expression {
536 public:
537 Expression * inout;
538 Expression * constraint;
539 Expression * operand;
540
541 AsmExpr( Expression * inout, Expression * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
542 AsmExpr( const AsmExpr & other );
543 virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
544
545 Expression * get_inout() const { return inout; }
546 void set_inout( Expression * newValue ) { inout = newValue; }
547
548 Expression * get_constraint() const { return constraint; }
549 void set_constraint( Expression * newValue ) { constraint = newValue; }
550
551 Expression * get_operand() const { return operand; }
552 void set_operand( Expression * newValue ) { operand = newValue; }
553
554 virtual AsmExpr * clone() const { return new AsmExpr( * this ); }
555 virtual void accept( Visitor & v ) { v.visit( this ); }
556 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
557 virtual void print( std::ostream & os, Indenter indent = {} ) const;
558
559 // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
560};
561
562/// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
563/// along with a set of copy constructor calls, one for each argument.
564class ImplicitCopyCtorExpr : public Expression {
565public:
566 ApplicationExpr * callExpr;
567 std::list< ObjectDecl * > tempDecls;
568 std::list< ObjectDecl * > returnDecls;
569 std::list< Expression * > dtors;
570
571 ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
572 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
573 virtual ~ImplicitCopyCtorExpr();
574
575 ApplicationExpr * get_callExpr() const { return callExpr; }
576 void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
577
578 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
579 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
580 std::list< Expression * > & get_dtors() { return dtors; }
581
582 virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
583 virtual void accept( Visitor & v ) { v.visit( this ); }
584 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
585 virtual void print( std::ostream & os, Indenter indent = {} ) const;
586};
587
588/// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
589class ConstructorExpr : public Expression {
590public:
591 Expression * callExpr;
592
593 ConstructorExpr( Expression * callExpr );
594 ConstructorExpr( const ConstructorExpr & other );
595 ~ConstructorExpr();
596
597 Expression * get_callExpr() const { return callExpr; }
598 void set_callExpr( Expression * newValue ) { callExpr = newValue; }
599
600 virtual ConstructorExpr * clone() const { return new ConstructorExpr( * this ); }
601 virtual void accept( Visitor & v ) { v.visit( this ); }
602 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
603 virtual void print( std::ostream & os, Indenter indent = {} ) const;
604};
605
606/// CompoundLiteralExpr represents a C99 'compound literal'
607class CompoundLiteralExpr : public Expression {
608 public:
609 Initializer * initializer;
610
611 CompoundLiteralExpr( Type * type, Initializer * initializer );
612 CompoundLiteralExpr( const CompoundLiteralExpr & other );
613 virtual ~CompoundLiteralExpr();
614
615 Initializer * get_initializer() const { return initializer; }
616 void set_initializer( Initializer * i ) { initializer = i; }
617
618 virtual CompoundLiteralExpr * clone() const { return new CompoundLiteralExpr( * this ); }
619 virtual void accept( Visitor & v ) { v.visit( this ); }
620 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
621 virtual void print( std::ostream & os, Indenter indent = {} ) const;
622};
623
624/// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
625class RangeExpr : public Expression {
626 public:
627 Expression * low, * high;
628
629 RangeExpr( Expression * low, Expression * high );
630 RangeExpr( const RangeExpr & other );
631
632 Expression * get_low() const { return low; }
633 Expression * get_high() const { return high; }
634 RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; }
635 RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
636
637 virtual RangeExpr * clone() const { return new RangeExpr( * this ); }
638 virtual void accept( Visitor & v ) { v.visit( this ); }
639 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
640 virtual void print( std::ostream & os, Indenter indent = {} ) const;
641};
642
643/// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution
644class UntypedTupleExpr : public Expression {
645 public:
646 std::list<Expression*> exprs;
647
648 UntypedTupleExpr( const std::list< Expression * > & exprs );
649 UntypedTupleExpr( const UntypedTupleExpr & other );
650 virtual ~UntypedTupleExpr();
651
652 std::list<Expression*>& get_exprs() { return exprs; }
653
654 virtual UntypedTupleExpr * clone() const { return new UntypedTupleExpr( * this ); }
655 virtual void accept( Visitor & v ) { v.visit( this ); }
656 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
657 virtual void print( std::ostream & os, Indenter indent = {} ) const;
658};
659
660/// TupleExpr represents a tuple expression ( [a, b, c] )
661class TupleExpr : public Expression {
662 public:
663 std::list<Expression*> exprs;
664
665 TupleExpr( const std::list< Expression * > & exprs );
666 TupleExpr( const TupleExpr & other );
667 virtual ~TupleExpr();
668
669 std::list<Expression*>& get_exprs() { return exprs; }
670
671 virtual TupleExpr * clone() const { return new TupleExpr( * this ); }
672 virtual void accept( Visitor & v ) { v.visit( this ); }
673 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
674 virtual void print( std::ostream & os, Indenter indent = {} ) const;
675};
676
677/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
678class TupleIndexExpr : public Expression {
679 public:
680 Expression * tuple;
681 unsigned int index;
682
683 TupleIndexExpr( Expression * tuple, unsigned int index );
684 TupleIndexExpr( const TupleIndexExpr & other );
685 virtual ~TupleIndexExpr();
686
687 Expression * get_tuple() const { return tuple; }
688 int get_index() const { return index; }
689 TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; }
690 TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
691
692 virtual TupleIndexExpr * clone() const { return new TupleIndexExpr( * this ); }
693 virtual void accept( Visitor & v ) { v.visit( this ); }
694 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
695 virtual void print( std::ostream & os, Indenter indent = {} ) const;
696};
697
698/// 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
699class TupleAssignExpr : public Expression {
700 public:
701 StmtExpr * stmtExpr = nullptr;
702
703 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls );
704 TupleAssignExpr( const TupleAssignExpr & other );
705 virtual ~TupleAssignExpr();
706
707 TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
708 StmtExpr * get_stmtExpr() const { return stmtExpr; }
709
710 virtual TupleAssignExpr * clone() const { return new TupleAssignExpr( * this ); }
711 virtual void accept( Visitor & v ) { v.visit( this ); }
712 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
713 virtual void print( std::ostream & os, Indenter indent = {} ) const;
714};
715
716/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
717class StmtExpr : public Expression {
718public:
719 CompoundStmt * statements;
720 std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
721 std::list< Expression * > dtors; // destructor(s) for return variable(s)
722
723 StmtExpr( CompoundStmt * statements );
724 StmtExpr( const StmtExpr & other );
725 virtual ~StmtExpr();
726
727 CompoundStmt * get_statements() const { return statements; }
728 StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
729
730 // call to set the result type of this StmtExpr based on its body
731 void computeResult();
732
733 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
734 std::list< Expression * > & get_dtors() { return dtors; }
735
736 virtual StmtExpr * clone() const { return new StmtExpr( * this ); }
737 virtual void accept( Visitor & v ) { v.visit( this ); }
738 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
739 virtual void print( std::ostream & os, Indenter indent = {} ) const;
740};
741
742class UniqueExpr : public Expression {
743public:
744 Expression * expr;
745 ObjectDecl * object;
746 VariableExpr * var;
747
748 UniqueExpr( Expression * expr, long long idVal = -1 );
749 UniqueExpr( const UniqueExpr & other );
750 ~UniqueExpr();
751
752 Expression * get_expr() const { return expr; }
753 UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
754
755 ObjectDecl * get_object() const { return object; }
756 UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; }
757
758 VariableExpr * get_var() const { return var; }
759 UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; }
760
761 int get_id() const { return id; }
762
763 virtual UniqueExpr * clone() const { return new UniqueExpr( * this ); }
764 virtual void accept( Visitor & v ) { v.visit( this ); }
765 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
766 virtual void print( std::ostream & os, Indenter indent = {} ) const;
767
768private:
769 int id;
770 static long long count;
771};
772
773struct InitAlternative {
774public:
775 Type * type = nullptr;
776 Designation * designation = nullptr;
777 InitAlternative( Type * type, Designation * designation );
778 InitAlternative( const InitAlternative & other );
779 InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it
780 ~InitAlternative();
781};
782
783class UntypedInitExpr : public Expression {
784public:
785 Expression * expr;
786 std::list<InitAlternative> initAlts;
787
788 UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
789 UntypedInitExpr( const UntypedInitExpr & other );
790 ~UntypedInitExpr();
791
792 Expression * get_expr() const { return expr; }
793 UntypedInitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
794
795 std::list<InitAlternative> & get_initAlts() { return initAlts; }
796
797 virtual UntypedInitExpr * clone() const { return new UntypedInitExpr( * this ); }
798 virtual void accept( Visitor & v ) { v.visit( this ); }
799 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
800 virtual void print( std::ostream & os, Indenter indent = {} ) const;
801};
802
803class InitExpr : public Expression {
804public:
805 Expression * expr;
806 Designation * designation;
807
808 InitExpr( Expression * expr, Designation * designation );
809 InitExpr( const InitExpr & other );
810 ~InitExpr();
811
812 Expression * get_expr() const { return expr; }
813 InitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
814
815 Designation * get_designation() const { return designation; }
816 InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; }
817
818 virtual InitExpr * clone() const { return new InitExpr( * this ); }
819 virtual void accept( Visitor & v ) { v.visit( this ); }
820 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
821 virtual void print( std::ostream & os, Indenter indent = {} ) const;
822};
823
824/// expression that contains a deleted identifier - should never make it past the resolver.
825class DeletedExpr : public Expression {
826public:
827 Expression * expr;
828 BaseSyntaxNode * deleteStmt;
829
830 DeletedExpr( Expression * expr, BaseSyntaxNode * deleteStmt );
831 DeletedExpr( const DeletedExpr & other );
832 ~DeletedExpr();
833
834 virtual DeletedExpr * clone() const { return new DeletedExpr( * this ); }
835 virtual void accept( Visitor & v ) { v.visit( this ); }
836 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
837 virtual void print( std::ostream & os, Indenter indent = {} ) const;
838};
839
840// Local Variables: //
841// tab-width: 4 //
842// mode: c++ //
843// compile-command: "make install" //
844// End: //
Note: See TracBrowser for help on using the repository browser.