source: src/SynTree/Expression.h@ 4d6d62e

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 with_gc
Last change on this file since 4d6d62e was 4d6d62e, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Add move operators for ParamEntry

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