source: src/SynTree/Expression.h@ 33218c6

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 33218c6 was 6b0b624, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

change #ifndef to #pragma once

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