source: src/SynTree/Expression.h@ fcd17b2f

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 fcd17b2f was a5f0529, checked in by Andrew Beach <ajbeach@…>, 8 years ago

Virtual casts have been added. They still require a lot of hand coded support to work but for simple cases it should be enough.

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