source: src/SynTree/Expression.h@ 90ce35aa

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

lvalue should now always come directly from the expression.

  • 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 bool get_lvalue() const final;
278
279 Expression * get_member() const { return member; }
280 void set_member( Expression * newValue ) { member = newValue; }
281 Expression * get_aggregate() const { return aggregate; }
282 void set_aggregate( Expression * newValue ) { aggregate = newValue; }
283
284 virtual UntypedMemberExpr * clone() const override { return new UntypedMemberExpr( * this ); }
285 virtual void accept( Visitor & v ) override { v.visit( this ); }
286 virtual void accept( Visitor & v ) const override { v.visit( this ); }
287 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
288 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
289};
290
291/// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer.
292/// Does not take ownership of member.
293class MemberExpr : public Expression {
294 public:
295 DeclarationWithType * member;
296 Expression * aggregate;
297
298 MemberExpr( DeclarationWithType * member, Expression * aggregate );
299 MemberExpr( const MemberExpr & other );
300 virtual ~MemberExpr();
301
302 bool get_lvalue() const final;
303
304 DeclarationWithType * get_member() const { return member; }
305 void set_member( DeclarationWithType * newValue ) { member = newValue; }
306 Expression * get_aggregate() const { return aggregate; }
307 void set_aggregate( Expression * newValue ) { aggregate = newValue; }
308
309 virtual MemberExpr * clone() const override { return new MemberExpr( * this ); }
310 virtual void accept( Visitor & v ) override { v.visit( this ); }
311 virtual void accept( Visitor & v ) const override { v.visit( this ); }
312 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
313 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
314};
315
316/// VariableExpr represents an expression that simply refers to the value of a named variable.
317/// Does not take ownership of var.
318class VariableExpr : public Expression {
319 public:
320 DeclarationWithType * var;
321
322 VariableExpr();
323 VariableExpr( DeclarationWithType * var );
324 VariableExpr( const VariableExpr & other );
325 virtual ~VariableExpr();
326
327 bool get_lvalue() const final;
328
329 DeclarationWithType * get_var() const { return var; }
330 void set_var( DeclarationWithType * newValue ) { var = newValue; }
331
332 static VariableExpr * functionPointer( FunctionDecl * decl );
333
334 virtual VariableExpr * clone() const override { return new VariableExpr( * this ); }
335 virtual void accept( Visitor & v ) override { v.visit( this ); }
336 virtual void accept( Visitor & v ) const override { v.visit( this ); }
337 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
338 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
339};
340
341/// ConstantExpr represents an expression that simply refers to the value of a constant
342class ConstantExpr : public Expression {
343 public:
344 Constant constant;
345
346 ConstantExpr( Constant constant );
347 ConstantExpr( const ConstantExpr & other );
348 virtual ~ConstantExpr();
349
350 Constant * get_constant() { return & constant; }
351 const Constant * get_constant() const { return & constant; }
352 void set_constant( const Constant & newValue ) { constant = newValue; }
353
354 long long int intValue() const;
355
356 virtual ConstantExpr * clone() const override { return new ConstantExpr( * this ); }
357 virtual void accept( Visitor & v ) override { v.visit( this ); }
358 virtual void accept( Visitor & v ) const override { v.visit( this ); }
359 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
360 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
361};
362
363/// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
364class SizeofExpr : public Expression {
365 public:
366 Expression * expr;
367 Type * type;
368 bool isType;
369
370 SizeofExpr( Expression * expr );
371 SizeofExpr( const SizeofExpr & other );
372 SizeofExpr( Type * type );
373 virtual ~SizeofExpr();
374
375 Expression * get_expr() const { return expr; }
376 void set_expr( Expression * newValue ) { expr = newValue; }
377 Type * get_type() const { return type; }
378 void set_type( Type * newValue ) { type = newValue; }
379 bool get_isType() const { return isType; }
380 void set_isType( bool newValue ) { isType = newValue; }
381
382 virtual SizeofExpr * clone() const override { return new SizeofExpr( * this ); }
383 virtual void accept( Visitor & v ) override { v.visit( this ); }
384 virtual void accept( Visitor & v ) const override { v.visit( this ); }
385 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
386 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
387};
388
389/// AlignofExpr represents an alignof expression
390class AlignofExpr : public Expression {
391 public:
392 Expression * expr;
393 Type * type;
394 bool isType;
395
396 AlignofExpr( Expression * expr );
397 AlignofExpr( const AlignofExpr & other );
398 AlignofExpr( Type * type );
399 virtual ~AlignofExpr();
400
401 Expression * get_expr() const { return expr; }
402 void set_expr( Expression * newValue ) { expr = newValue; }
403 Type * get_type() const { return type; }
404 void set_type( Type * newValue ) { type = newValue; }
405 bool get_isType() const { return isType; }
406 void set_isType( bool newValue ) { isType = newValue; }
407
408 virtual AlignofExpr * clone() const override { return new AlignofExpr( * this ); }
409 virtual void accept( Visitor & v ) override { v.visit( this ); }
410 virtual void accept( Visitor & v ) const override { v.visit( this ); }
411 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
412 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
413};
414
415/// UntypedOffsetofExpr represents an offsetof expression before resolution
416class UntypedOffsetofExpr : public Expression {
417 public:
418 Type * type;
419 std::string member;
420
421 UntypedOffsetofExpr( Type * type, const std::string & member );
422 UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
423 virtual ~UntypedOffsetofExpr();
424
425 std::string get_member() const { return member; }
426 void set_member( const std::string & newValue ) { member = newValue; }
427 Type * get_type() const { return type; }
428 void set_type( Type * newValue ) { type = newValue; }
429
430 virtual UntypedOffsetofExpr * clone() const override { return new UntypedOffsetofExpr( * this ); }
431 virtual void accept( Visitor & v ) override { v.visit( this ); }
432 virtual void accept( Visitor & v ) const override { v.visit( this ); }
433 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
434 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
435};
436
437/// OffsetofExpr represents an offsetof expression
438class OffsetofExpr : public Expression {
439 public:
440 Type * type;
441 DeclarationWithType * member;
442
443 OffsetofExpr( Type * type, DeclarationWithType * member );
444 OffsetofExpr( const OffsetofExpr & other );
445 virtual ~OffsetofExpr();
446
447 Type * get_type() const { return type; }
448 void set_type( Type * newValue ) { type = newValue; }
449 DeclarationWithType * get_member() const { return member; }
450 void set_member( DeclarationWithType * newValue ) { member = newValue; }
451
452 virtual OffsetofExpr * clone() const override { return new OffsetofExpr( * this ); }
453 virtual void accept( Visitor & v ) override { v.visit( this ); }
454 virtual void accept( Visitor & v ) const override { v.visit( this ); }
455 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
456 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
457};
458
459/// Expression representing a pack of field-offsets for a generic type
460class OffsetPackExpr : public Expression {
461public:
462 StructInstType * type;
463
464 OffsetPackExpr( StructInstType * type );
465 OffsetPackExpr( const OffsetPackExpr & other );
466 virtual ~OffsetPackExpr();
467
468 StructInstType * get_type() const { return type; }
469 void set_type( StructInstType * newValue ) { type = newValue; }
470
471 virtual OffsetPackExpr * clone() const override { return new OffsetPackExpr( * this ); }
472 virtual void accept( Visitor & v ) override { v.visit( this ); }
473 virtual void accept( Visitor & v ) const override { v.visit( this ); }
474 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
475 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
476};
477
478/// LogicalExpr represents a short-circuit boolean expression (&& or ||)
479class LogicalExpr : public Expression {
480 public:
481 Expression * arg1;
482 Expression * arg2;
483
484 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true );
485 LogicalExpr( const LogicalExpr & other );
486 virtual ~LogicalExpr();
487
488 bool get_isAnd() const { return isAnd; }
489 Expression * get_arg1() { return arg1; }
490 void set_arg1( Expression * newValue ) { arg1 = newValue; }
491 Expression * get_arg2() const { return arg2; }
492 void set_arg2( Expression * newValue ) { arg2 = newValue; }
493
494 virtual LogicalExpr * clone() const override { return new LogicalExpr( * this ); }
495 virtual void accept( Visitor & v ) override { v.visit( this ); }
496 virtual void accept( Visitor & v ) const override { v.visit( this ); }
497 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
498 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
499
500 private:
501 bool isAnd;
502};
503
504/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
505class ConditionalExpr : public Expression {
506 public:
507 Expression * arg1;
508 Expression * arg2;
509 Expression * arg3;
510
511 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 );
512 ConditionalExpr( const ConditionalExpr & other );
513 virtual ~ConditionalExpr();
514
515 bool get_lvalue() const final;
516
517 Expression * get_arg1() const { return arg1; }
518 void set_arg1( Expression * newValue ) { arg1 = newValue; }
519 Expression * get_arg2() const { return arg2; }
520 void set_arg2( Expression * newValue ) { arg2 = newValue; }
521 Expression * get_arg3() const { return arg3; }
522 void set_arg3( Expression * newValue ) { arg3 = newValue; }
523
524 virtual ConditionalExpr * clone() const override { return new ConditionalExpr( * this ); }
525 virtual void accept( Visitor & v ) override { v.visit( this ); }
526 virtual void accept( Visitor & v ) const override { v.visit( this ); }
527 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
528 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
529};
530
531/// CommaExpr represents the sequence operator ( a, b )
532class CommaExpr : public Expression {
533 public:
534 Expression * arg1;
535 Expression * arg2;
536
537 CommaExpr( Expression * arg1, Expression * arg2 );
538 CommaExpr( const CommaExpr & other );
539 virtual ~CommaExpr();
540
541 bool get_lvalue() const final;
542
543 Expression * get_arg1() const { return arg1; }
544 void set_arg1( Expression * newValue ) { arg1 = newValue; }
545 Expression * get_arg2() const { return arg2; }
546 void set_arg2( Expression * newValue ) { arg2 = newValue; }
547
548 virtual CommaExpr * clone() const override { return new CommaExpr( * this ); }
549 virtual void accept( Visitor & v ) override { v.visit( this ); }
550 virtual void accept( Visitor & v ) const override { v.visit( this ); }
551 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
552 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
553};
554
555/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
556class TypeExpr : public Expression {
557 public:
558 Type * type;
559
560 TypeExpr( Type * type );
561 TypeExpr( const TypeExpr & other );
562 virtual ~TypeExpr();
563
564 Type * get_type() const { return type; }
565 void set_type( Type * newValue ) { type = newValue; }
566
567 virtual TypeExpr * clone() const override { return new TypeExpr( * this ); }
568 virtual void accept( Visitor & v ) override { v.visit( this ); }
569 virtual void accept( Visitor & v ) const override { v.visit( this ); }
570 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
571 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
572};
573
574/// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
575class AsmExpr : public Expression {
576 public:
577 Expression * inout;
578 Expression * constraint;
579 Expression * operand;
580
581 AsmExpr( Expression * inout, Expression * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
582 AsmExpr( const AsmExpr & other );
583 virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
584
585 Expression * get_inout() const { return inout; }
586 void set_inout( Expression * newValue ) { inout = newValue; }
587
588 Expression * get_constraint() const { return constraint; }
589 void set_constraint( Expression * newValue ) { constraint = newValue; }
590
591 Expression * get_operand() const { return operand; }
592 void set_operand( Expression * newValue ) { operand = newValue; }
593
594 virtual AsmExpr * clone() const override { return new AsmExpr( * this ); }
595 virtual void accept( Visitor & v ) override { v.visit( this ); }
596 virtual void accept( Visitor & v ) const override { v.visit( this ); }
597 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
598 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
599
600 // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
601};
602
603/// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
604/// along with a set of copy constructor calls, one for each argument.
605class ImplicitCopyCtorExpr : public Expression {
606public:
607 ApplicationExpr * callExpr = nullptr;
608
609 ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
610 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
611 virtual ~ImplicitCopyCtorExpr();
612
613 virtual ImplicitCopyCtorExpr * clone() const override { return new ImplicitCopyCtorExpr( * this ); }
614 virtual void accept( Visitor & v ) override { v.visit( this ); }
615 virtual void accept( Visitor & v ) const override { v.visit( this ); }
616 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
617 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
618};
619
620/// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
621class ConstructorExpr : public Expression {
622public:
623 Expression * callExpr;
624
625 ConstructorExpr( Expression * callExpr );
626 ConstructorExpr( const ConstructorExpr & other );
627 ~ConstructorExpr();
628
629 bool get_lvalue() const final;
630
631 Expression * get_callExpr() const { return callExpr; }
632 void set_callExpr( Expression * newValue ) { callExpr = newValue; }
633
634 virtual ConstructorExpr * clone() const override { return new ConstructorExpr( * this ); }
635 virtual void accept( Visitor & v ) override { v.visit( this ); }
636 virtual void accept( Visitor & v ) const override { v.visit( this ); }
637 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
638 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
639};
640
641/// CompoundLiteralExpr represents a C99 'compound literal'
642class CompoundLiteralExpr : public Expression {
643 public:
644 Initializer * initializer;
645
646 CompoundLiteralExpr( Type * type, Initializer * initializer );
647 CompoundLiteralExpr( const CompoundLiteralExpr & other );
648 virtual ~CompoundLiteralExpr();
649
650 bool get_lvalue() const final;
651
652 Initializer * get_initializer() const { return initializer; }
653 void set_initializer( Initializer * i ) { initializer = i; }
654
655 virtual CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr( * this ); }
656 virtual void accept( Visitor & v ) override { v.visit( this ); }
657 virtual void accept( Visitor & v ) const override { v.visit( this ); }
658 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
659 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
660};
661
662/// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
663class RangeExpr : public Expression {
664 public:
665 Expression * low, * high;
666
667 RangeExpr( Expression * low, Expression * high );
668 RangeExpr( const RangeExpr & other );
669
670 Expression * get_low() const { return low; }
671 Expression * get_high() const { return high; }
672 RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; }
673 RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
674
675 virtual RangeExpr * clone() const override { return new RangeExpr( * this ); }
676 virtual void accept( Visitor & v ) override { v.visit( this ); }
677 virtual void accept( Visitor & v ) const override { v.visit( this ); }
678 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
679 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
680};
681
682/// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution
683class UntypedTupleExpr : public Expression {
684 public:
685 std::list<Expression*> exprs;
686
687 UntypedTupleExpr( const std::list< Expression * > & exprs );
688 UntypedTupleExpr( const UntypedTupleExpr & other );
689 virtual ~UntypedTupleExpr();
690
691 std::list<Expression*>& get_exprs() { return exprs; }
692
693 virtual UntypedTupleExpr * clone() const override { return new UntypedTupleExpr( * this ); }
694 virtual void accept( Visitor & v ) override { v.visit( this ); }
695 virtual void accept( Visitor & v ) const override { v.visit( this ); }
696 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
697 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
698};
699
700/// TupleExpr represents a tuple expression ( [a, b, c] )
701class TupleExpr : public Expression {
702 public:
703 std::list<Expression*> exprs;
704
705 TupleExpr( const std::list< Expression * > & exprs );
706 TupleExpr( const TupleExpr & other );
707 virtual ~TupleExpr();
708
709 bool get_lvalue() const final;
710
711 std::list<Expression*>& get_exprs() { return exprs; }
712
713 virtual TupleExpr * clone() const override { return new TupleExpr( * this ); }
714 virtual void accept( Visitor & v ) override { v.visit( this ); }
715 virtual void accept( Visitor & v ) const override { v.visit( this ); }
716 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
717 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
718};
719
720/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
721class TupleIndexExpr : public Expression {
722 public:
723 Expression * tuple;
724 unsigned int index;
725
726 TupleIndexExpr( Expression * tuple, unsigned int index );
727 TupleIndexExpr( const TupleIndexExpr & other );
728 virtual ~TupleIndexExpr();
729
730 bool get_lvalue() const final;
731
732 Expression * get_tuple() const { return tuple; }
733 int get_index() const { return index; }
734 TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; }
735 TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
736
737 virtual TupleIndexExpr * clone() const override { return new TupleIndexExpr( * this ); }
738 virtual void accept( Visitor & v ) override { v.visit( this ); }
739 virtual void accept( Visitor & v ) const override { v.visit( this ); }
740 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
741 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
742};
743
744/// 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
745class TupleAssignExpr : public Expression {
746 public:
747 StmtExpr * stmtExpr = nullptr;
748
749 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls );
750 TupleAssignExpr( const TupleAssignExpr & other );
751 virtual ~TupleAssignExpr();
752
753 TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
754 StmtExpr * get_stmtExpr() const { return stmtExpr; }
755
756 virtual TupleAssignExpr * clone() const override { return new TupleAssignExpr( * this ); }
757 virtual void accept( Visitor & v ) override { v.visit( this ); }
758 virtual void accept( Visitor & v ) const override { v.visit( this ); }
759 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
760 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
761
762 friend class ConverterNewToOld;
763 private:
764 TupleAssignExpr( StmtExpr * stmts );
765};
766
767/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
768class StmtExpr : public Expression {
769public:
770 CompoundStmt * statements;
771 std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
772 std::list< Expression * > dtors; // destructor(s) for return variable(s)
773
774 // readonly
775 ExprStmt * resultExpr = nullptr;
776
777 StmtExpr( CompoundStmt * statements );
778 StmtExpr( const StmtExpr & other );
779 virtual ~StmtExpr();
780
781 bool get_lvalue() const final;
782
783 CompoundStmt * get_statements() const { return statements; }
784 StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
785
786 // call to set the result type of this StmtExpr based on its body
787 void computeResult();
788
789 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
790 std::list< Expression * > & get_dtors() { return dtors; }
791
792 virtual StmtExpr * clone() const override { return new StmtExpr( * this ); }
793 virtual void accept( Visitor & v ) override { v.visit( this ); }
794 virtual void accept( Visitor & v ) const override { v.visit( this ); }
795 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
796 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
797};
798
799class UniqueExpr : public Expression {
800public:
801 Expression * expr;
802 ObjectDecl * object;
803 VariableExpr * var;
804
805 UniqueExpr( Expression * expr, long long idVal = -1 );
806 UniqueExpr( const UniqueExpr & other );
807 ~UniqueExpr();
808
809 Expression * get_expr() const { return expr; }
810 UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
811
812 ObjectDecl * get_object() const { return object; }
813 UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; }
814
815 VariableExpr * get_var() const { return var; }
816 UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; }
817
818 int get_id() const { return id; }
819
820 virtual UniqueExpr * clone() const override { return new UniqueExpr( * this ); }
821 virtual void accept( Visitor & v ) override { v.visit( this ); }
822 virtual void accept( Visitor & v ) const override { v.visit( this ); }
823 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
824 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
825
826private:
827 int id;
828 static long long count;
829};
830
831struct InitAlternative {
832public:
833 Type * type = nullptr;
834 Designation * designation = nullptr;
835 InitAlternative( Type * type, Designation * designation );
836 InitAlternative( const InitAlternative & other );
837 InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it
838 ~InitAlternative();
839};
840
841class UntypedInitExpr : public Expression {
842public:
843 Expression * expr;
844 std::list<InitAlternative> initAlts;
845
846 UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
847 UntypedInitExpr( const UntypedInitExpr & other );
848 ~UntypedInitExpr();
849
850 Expression * get_expr() const { return expr; }
851 UntypedInitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
852
853 std::list<InitAlternative> & get_initAlts() { return initAlts; }
854
855 virtual UntypedInitExpr * clone() const override { return new UntypedInitExpr( * this ); }
856 virtual void accept( Visitor & v ) override { v.visit( this ); }
857 virtual void accept( Visitor & v ) const override { v.visit( this ); }
858 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
859 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
860};
861
862class InitExpr : public Expression {
863public:
864 Expression * expr;
865 Designation * designation;
866
867 InitExpr( Expression * expr, Designation * designation );
868 InitExpr( const InitExpr & other );
869 ~InitExpr();
870
871 Expression * get_expr() const { return expr; }
872 InitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
873
874 Designation * get_designation() const { return designation; }
875 InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; }
876
877 virtual InitExpr * clone() const override { return new InitExpr( * this ); }
878 virtual void accept( Visitor & v ) override { v.visit( this ); }
879 virtual void accept( Visitor & v ) const override { v.visit( this ); }
880 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
881 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
882};
883
884/// expression that contains a deleted identifier - should never make it past the resolver.
885class DeletedExpr : public Expression {
886public:
887 Expression * expr;
888 Declaration * deleteStmt;
889
890 DeletedExpr( Expression * expr, Declaration * deleteStmt );
891 DeletedExpr( const DeletedExpr & other );
892 ~DeletedExpr();
893
894 virtual DeletedExpr * clone() const override { return new DeletedExpr( * this ); }
895 virtual void accept( Visitor & v ) override { v.visit( this ); }
896 virtual void accept( Visitor & v ) const override { v.visit( this ); }
897 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
898 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
899};
900
901/// expression wrapping the use of a default argument - should never make it past the resolver.
902class DefaultArgExpr : public Expression {
903public:
904 Expression * expr;
905
906 DefaultArgExpr( Expression * expr );
907 DefaultArgExpr( const DefaultArgExpr & other );
908 ~DefaultArgExpr();
909
910 virtual DefaultArgExpr * clone() const override { return new DefaultArgExpr( * this ); }
911 virtual void accept( Visitor & v ) override { v.visit( this ); }
912 virtual void accept( Visitor & v ) const override { v.visit( this ); }
913 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
914 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
915};
916
917/// C11 _Generic expression
918class GenericExpr : public Expression {
919public:
920 struct Association {
921 Type * type = nullptr;
922 Expression * expr = nullptr;
923 bool isDefault = false;
924
925 Association( Type * type, Expression * expr );
926 Association( Expression * expr );
927 Association( const Association & other );
928 Association & operator=( const Association & other ) = delete; // at the moment this isn't used, and I don't want to implement it
929 ~Association();
930 };
931
932 Expression * control;
933 std::list<Association> associations;
934
935 GenericExpr( Expression * control, const std::list<Association> & assoc );
936 GenericExpr( const GenericExpr & other );
937 virtual ~GenericExpr();
938
939 virtual GenericExpr * clone() const override { return new GenericExpr( * this ); }
940 virtual void accept( Visitor & v ) override { v.visit( this ); }
941 virtual void accept( Visitor & v ) const override { v.visit( this ); }
942 virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
943 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
944};
945
946// Local Variables: //
947// tab-width: 4 //
948// mode: c++ //
949// compile-command: "make install" //
950// End: //
Note: See TracBrowser for help on using the repository browser.