source: src/SynTree/Expression.h@ 0698aa1

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

Big push on designations and initialization: works with generic types, tuples, arrays, tests pass.
Refactor guard_value_impl.
Add list of declarations to TupleType.

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