source: src/SynTree/Expression.h@ 158b026

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 158b026 was 5d00425, checked in by Andrew Beach <ajbeach@…>, 6 years ago

StmtExpr also does not have the lvalue I originally expected.

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