source: src/SynTree/Expression.h@ a0c7dc36

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

Fix handling of GCC label address and computed goto

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