source: src/SynTree/Expression.h @ 824a2dc

new-envwith_gc
Last change on this file since 824a2dc was 42107b4, checked in by Aaron Moss <a3moss@…>, 6 years ago

Leftover cleanup from merge

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