source: src/SynTree/Expression.h@ 83794e1

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

Fix various reference features.

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