source: src/SynTree/Expression.h@ b05a4eb

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 b05a4eb was d29fa5f, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Remove has_result

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