source: src/SynTree/Expression.h@ 982f95d

new-env
Last change on this file since 982f95d was eba74ba, checked in by Aaron Moss <a3moss@…>, 7 years ago

Merge remote-tracking branch 'origin/master' into with_gc

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