source: src/SynTree/Expression.h @ bfc7811

new-envwith_gc
Last change on this file since bfc7811 was 68f9c43, checked in by Aaron Moss <a3moss@…>, 6 years ago

First pass at delete removal

  • Property mode set to 100644
File size: 31.1 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// Expression.h --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : 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
187        CastExpr( Expression * arg );
188        CastExpr( Expression * arg, Type * toType );
189        CastExpr( const CastExpr & other );
190
191        Expression * get_arg() const { return arg; }
192        void set_arg( Expression * newValue ) { arg = newValue; }
193
194        virtual CastExpr * clone() const { return new CastExpr( * this ); }
195        virtual void accept( Visitor & v ) { v.visit( this ); }
196        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
197        virtual void print( std::ostream & os, Indenter indent = {} ) const;
198};
199
200/// VirtualCastExpr repersents a virtual dynamic cast, e.g. (virtual exception)e
201class VirtualCastExpr : public Expression {
202  public:
203        Expression * arg;
204
205        VirtualCastExpr( Expression * arg, Type * toType );
206        VirtualCastExpr( const VirtualCastExpr & other );
207
208        Expression * get_arg() const { return arg; }
209        void set_arg( Expression * newValue ) { arg = newValue; }
210
211        virtual VirtualCastExpr * clone() const { return new VirtualCastExpr( * this ); }
212        virtual void accept( Visitor & v ) { v.visit( this ); }
213        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
214        virtual void print( std::ostream & os, Indenter indent = {} ) const;
215};
216
217/// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
218class UntypedMemberExpr : public Expression {
219  public:
220        Expression * member;
221        Expression * aggregate;
222
223        UntypedMemberExpr( Expression * member, Expression * aggregate );
224        UntypedMemberExpr( const UntypedMemberExpr & other );
225
226        Expression * get_member() const { return member; }
227        void set_member( Expression * newValue ) { member = newValue; }
228        Expression * get_aggregate() const { return aggregate; }
229        void set_aggregate( Expression * newValue ) { aggregate = newValue; }
230
231        virtual UntypedMemberExpr * clone() const { return new UntypedMemberExpr( * this ); }
232        virtual void accept( Visitor & v ) { v.visit( this ); }
233        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
234        virtual void print( std::ostream & os, Indenter indent = {} ) const;
235};
236
237/// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer.
238/// Does not take ownership of member.
239class MemberExpr : public Expression {
240  public:
241        DeclarationWithType * member;
242        Expression * aggregate;
243
244        MemberExpr( DeclarationWithType * member, Expression * aggregate );
245        MemberExpr( const MemberExpr & other );
246
247        DeclarationWithType * get_member() const { return member; }
248        void set_member( DeclarationWithType * newValue ) { member = newValue; }
249        Expression * get_aggregate() const { return aggregate; }
250        void set_aggregate( Expression * newValue ) { aggregate = newValue; }
251
252        virtual MemberExpr * clone() const { return new MemberExpr( * 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/// VariableExpr represents an expression that simply refers to the value of a named variable.
259/// Does not take ownership of var.
260class VariableExpr : public Expression {
261  public:
262        DeclarationWithType * var;
263
264        VariableExpr( DeclarationWithType * var );
265        VariableExpr( const VariableExpr & other );
266
267        DeclarationWithType * get_var() const { return var; }
268        void set_var( DeclarationWithType * newValue ) { var = newValue; }
269
270        static VariableExpr * functionPointer( FunctionDecl * decl );
271
272        virtual VariableExpr * clone() const { return new VariableExpr( * this ); }
273        virtual void accept( Visitor & v ) { v.visit( this ); }
274        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
275        virtual void print( std::ostream & os, Indenter indent = {} ) const;
276};
277
278/// ConstantExpr represents an expression that simply refers to the value of a constant
279class ConstantExpr : public Expression {
280  public:
281        Constant constant;
282
283        ConstantExpr( Constant constant );
284        ConstantExpr( const ConstantExpr & other );
285
286        Constant * get_constant() { return & constant; }
287        const Constant * get_constant() const { return & constant; }
288        void set_constant( const Constant & newValue ) { constant = newValue; }
289
290        long long int intValue() const;
291
292        virtual ConstantExpr * clone() const { return new ConstantExpr( * this ); }
293        virtual void accept( Visitor & v ) { v.visit( this ); }
294        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
295        virtual void print( std::ostream & os, Indenter indent = {} ) const;
296};
297
298/// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
299class SizeofExpr : public Expression {
300  public:
301        Expression * expr;
302        Type * type;
303        bool isType;
304
305        SizeofExpr( Expression * expr );
306        SizeofExpr( const SizeofExpr & other );
307        SizeofExpr( Type * type );
308
309        Expression * get_expr() const { return expr; }
310        void set_expr( Expression * newValue ) { expr = newValue; }
311        Type * get_type() const { return type; }
312        void set_type( Type * newValue ) { type = newValue; }
313        bool get_isType() const { return isType; }
314        void set_isType( bool newValue ) { isType = newValue; }
315
316        virtual SizeofExpr * clone() const { return new SizeofExpr( * this ); }
317        virtual void accept( Visitor & v ) { v.visit( this ); }
318        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
319        virtual void print( std::ostream & os, Indenter indent = {} ) const;
320};
321
322/// AlignofExpr represents an alignof expression
323class AlignofExpr : public Expression {
324  public:
325        Expression * expr;
326        Type * type;
327        bool isType;
328
329        AlignofExpr( Expression * expr );
330        AlignofExpr( const AlignofExpr & other );
331        AlignofExpr( Type * type );
332
333        Expression * get_expr() const { return expr; }
334        void set_expr( Expression * newValue ) { expr = newValue; }
335        Type * get_type() const { return type; }
336        void set_type( Type * newValue ) { type = newValue; }
337        bool get_isType() const { return isType; }
338        void set_isType( bool newValue ) { isType = newValue; }
339
340        virtual AlignofExpr * clone() const { return new AlignofExpr( * this ); }
341        virtual void accept( Visitor & v ) { v.visit( this ); }
342        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
343        virtual void print( std::ostream & os, Indenter indent = {} ) const;
344};
345
346/// UntypedOffsetofExpr represents an offsetof expression before resolution
347class UntypedOffsetofExpr : public Expression {
348  public:
349        Type * type;
350        std::string member;
351
352        UntypedOffsetofExpr( Type * type, const std::string & member );
353        UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
354
355        std::string get_member() const { return member; }
356        void set_member( const std::string & newValue ) { member = newValue; }
357        Type * get_type() const { return type; }
358        void set_type( Type * newValue ) { type = newValue; }
359
360        virtual UntypedOffsetofExpr * clone() const { return new UntypedOffsetofExpr( * this ); }
361        virtual void accept( Visitor & v ) { v.visit( this ); }
362        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
363        virtual void print( std::ostream & os, Indenter indent = {} ) const;
364};
365
366/// OffsetofExpr represents an offsetof expression
367class OffsetofExpr : public Expression {
368  public:
369        Type * type;
370        DeclarationWithType * member;
371
372        OffsetofExpr( Type * type, DeclarationWithType * member );
373        OffsetofExpr( const OffsetofExpr & other );
374
375        Type * get_type() const { return type; }
376        void set_type( Type * newValue ) { type = newValue; }
377        DeclarationWithType * get_member() const { return member; }
378        void set_member( DeclarationWithType * newValue ) { member = newValue; }
379
380        virtual OffsetofExpr * clone() const { return new OffsetofExpr( * this ); }
381        virtual void accept( Visitor & v ) { v.visit( this ); }
382        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
383        virtual void print( std::ostream & os, Indenter indent = {} ) const;
384};
385
386/// Expression representing a pack of field-offsets for a generic type
387class OffsetPackExpr : public Expression {
388public:
389        StructInstType * type;
390
391        OffsetPackExpr( StructInstType * type );
392        OffsetPackExpr( const OffsetPackExpr & other );
393
394        StructInstType * get_type() const { return type; }
395        void set_type( StructInstType * newValue ) { type = newValue; }
396
397        virtual OffsetPackExpr * clone() const { return new OffsetPackExpr( * this ); }
398        virtual void accept( Visitor & v ) { v.visit( this ); }
399        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
400        virtual void print( std::ostream & os, Indenter indent = {} ) const;
401};
402
403/// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
404class AttrExpr : public Expression {
405  public:
406        Expression * attr;
407        Expression * expr;
408        Type * type;
409        bool isType;
410
411        AttrExpr(Expression * attr, Expression * expr );
412        AttrExpr( const AttrExpr & other );
413        AttrExpr( Expression * attr, Type * type );
414
415        Expression * get_attr() const { return attr; }
416        void set_attr( Expression * newValue ) { attr = newValue; }
417        Expression * get_expr() const { return expr; }
418        void set_expr( Expression * newValue ) { expr = newValue; }
419        Type * get_type() const { return type; }
420        void set_type( Type * newValue ) { type = newValue; }
421        bool get_isType() const { return isType; }
422        void set_isType( bool newValue ) { isType = newValue; }
423
424        virtual AttrExpr * clone() const { return new AttrExpr( * this ); }
425        virtual void accept( Visitor & v ) { v.visit( this ); }
426        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
427        virtual void print( std::ostream & os, Indenter indent = {} ) const;
428};
429
430/// LogicalExpr represents a short-circuit boolean expression (&& or ||)
431class LogicalExpr : public Expression {
432  public:
433        Expression * arg1;
434        Expression * arg2;
435
436        LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true );
437        LogicalExpr( const LogicalExpr & other );
438
439        bool get_isAnd() const { return isAnd; }
440        Expression * get_arg1() { return arg1; }
441        void set_arg1( Expression * newValue ) { arg1 = newValue; }
442        Expression * get_arg2() const { return arg2; }
443        void set_arg2( Expression * newValue ) { arg2 = newValue; }
444
445        virtual LogicalExpr * clone() const { return new LogicalExpr( * 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  private:
451        bool isAnd;
452};
453
454/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
455class ConditionalExpr : public Expression {
456  public:
457        Expression * arg1;
458        Expression * arg2;
459        Expression * arg3;
460
461        ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 );
462        ConditionalExpr( const ConditionalExpr & other );
463
464        Expression * get_arg1() const { return arg1; }
465        void set_arg1( Expression * newValue ) { arg1 = newValue; }
466        Expression * get_arg2() const { return arg2; }
467        void set_arg2( Expression * newValue ) { arg2 = newValue; }
468        Expression * get_arg3() const { return arg3; }
469        void set_arg3( Expression * newValue ) { arg3 = newValue; }
470
471        virtual ConditionalExpr * clone() const { return new ConditionalExpr( * this ); }
472        virtual void accept( Visitor & v ) { v.visit( this ); }
473        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
474        virtual void print( std::ostream & os, Indenter indent = {} ) const;
475};
476
477/// CommaExpr represents the sequence operator ( a, b )
478class CommaExpr : public Expression {
479  public:
480        Expression * arg1;
481        Expression * arg2;
482
483        CommaExpr( Expression * arg1, Expression * arg2 );
484        CommaExpr( const CommaExpr & other );
485
486        Expression * get_arg1() const { return arg1; }
487        void set_arg1( Expression * newValue ) { arg1 = newValue; }
488        Expression * get_arg2() const { return arg2; }
489        void set_arg2( Expression * newValue ) { arg2 = newValue; }
490
491        virtual CommaExpr * clone() const { return new CommaExpr( * this ); }
492        virtual void accept( Visitor & v ) { v.visit( this ); }
493        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
494        virtual void print( std::ostream & os, Indenter indent = {} ) const;
495};
496
497/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
498class TypeExpr : public Expression {
499  public:
500        Type * type;
501
502        TypeExpr( Type * type );
503        TypeExpr( const TypeExpr & other );
504
505        Type * get_type() const { return type; }
506        void set_type( Type * newValue ) { type = newValue; }
507
508        virtual TypeExpr * clone() const { return new TypeExpr( * this ); }
509        virtual void accept( Visitor & v ) { v.visit( this ); }
510        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
511        virtual void print( std::ostream & os, Indenter indent = {} ) const;
512};
513
514/// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
515class AsmExpr : public Expression {
516  public:
517        Expression * inout;
518        Expression * constraint;
519        Expression * operand;
520
521        AsmExpr( Expression * inout, Expression * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
522        AsmExpr( const AsmExpr & other );
523
524        Expression * get_inout() const { return inout; }
525        void set_inout( Expression * newValue ) { inout = newValue; }
526
527        Expression * get_constraint() const { return constraint; }
528        void set_constraint( Expression * newValue ) { constraint = newValue; }
529
530        Expression * get_operand() const { return operand; }
531        void set_operand( Expression * newValue ) { operand = newValue; }
532
533        virtual AsmExpr * clone() const { return new AsmExpr( * this ); }
534        virtual void accept( Visitor & v ) { v.visit( this ); }
535        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
536        virtual void print( std::ostream & os, Indenter indent = {} ) const;
537
538        // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
539};
540
541/// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
542/// along with a set of copy constructor calls, one for each argument.
543class ImplicitCopyCtorExpr : public Expression {
544protected:
545        virtual ~ImplicitCopyCtorExpr();
546
547public:
548        ApplicationExpr * callExpr;
549        std::list< ObjectDecl * > tempDecls;
550        std::list< ObjectDecl * > returnDecls;
551        std::list< Expression * > dtors;
552
553        ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
554        ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
555
556        ApplicationExpr * get_callExpr() const { return callExpr; }
557        void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
558
559        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
560        std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
561        std::list< Expression * > & get_dtors() { return dtors; }
562
563        virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
564        virtual void accept( Visitor & v ) { v.visit( this ); }
565        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
566        virtual void print( std::ostream & os, Indenter indent = {} ) const;
567};
568
569/// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
570class ConstructorExpr : public Expression {
571public:
572        Expression * callExpr;
573
574        ConstructorExpr( Expression * callExpr );
575        ConstructorExpr( const ConstructorExpr & other );
576
577        Expression * get_callExpr() const { return callExpr; }
578        void set_callExpr( Expression * newValue ) { callExpr = newValue; }
579
580        virtual ConstructorExpr * clone() const { return new ConstructorExpr( * this ); }
581        virtual void accept( Visitor & v ) { v.visit( this ); }
582        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
583        virtual void print( std::ostream & os, Indenter indent = {} ) const;
584};
585
586/// CompoundLiteralExpr represents a C99 'compound literal'
587class CompoundLiteralExpr : public Expression {
588  public:
589        Initializer * initializer;
590
591        CompoundLiteralExpr( Type * type, Initializer * initializer );
592        CompoundLiteralExpr( const CompoundLiteralExpr & other );
593
594        Initializer * get_initializer() const { return initializer; }
595        void set_initializer( Initializer * i ) { initializer = i; }
596
597        virtual CompoundLiteralExpr * clone() const { return new CompoundLiteralExpr( * this ); }
598        virtual void accept( Visitor & v ) { v.visit( this ); }
599        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
600        virtual void print( std::ostream & os, Indenter indent = {} ) const;
601};
602
603/// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
604class RangeExpr : public Expression {
605  public:
606        Expression * low, * high;
607
608        RangeExpr( Expression * low, Expression * high );
609        RangeExpr( const RangeExpr & other );
610
611        Expression * get_low() const { return low; }
612        Expression * get_high() const { return high; }
613        RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; }
614        RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
615
616        virtual RangeExpr * clone() const { return new RangeExpr( * this ); }
617        virtual void accept( Visitor & v ) { v.visit( this ); }
618        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
619        virtual void print( std::ostream & os, Indenter indent = {} ) const;
620};
621
622/// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution
623class UntypedTupleExpr : public Expression {
624  public:
625        std::list<Expression*> exprs;
626
627        UntypedTupleExpr( const std::list< Expression * > & exprs );
628        UntypedTupleExpr( const UntypedTupleExpr & other );
629
630        std::list<Expression*>& get_exprs() { return exprs; }
631
632        virtual UntypedTupleExpr * clone() const { return new UntypedTupleExpr( * this ); }
633        virtual void accept( Visitor & v ) { v.visit( this ); }
634        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
635        virtual void print( std::ostream & os, Indenter indent = {} ) const;
636};
637
638/// TupleExpr represents a tuple expression ( [a, b, c] )
639class TupleExpr : public Expression {
640  public:
641        std::list<Expression*> exprs;
642
643        TupleExpr( const std::list< Expression * > & exprs );
644        TupleExpr( const TupleExpr & other );
645
646        std::list<Expression*>& get_exprs() { return exprs; }
647
648        virtual TupleExpr * clone() const { return new TupleExpr( * this ); }
649        virtual void accept( Visitor & v ) { v.visit( this ); }
650        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
651        virtual void print( std::ostream & os, Indenter indent = {} ) const;
652};
653
654/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
655class TupleIndexExpr : public Expression {
656  public:
657        Expression * tuple;
658        unsigned int index;
659
660        TupleIndexExpr( Expression * tuple, unsigned int index );
661        TupleIndexExpr( const TupleIndexExpr & other );
662
663        Expression * get_tuple() const { return tuple; }
664        int get_index() const { return index; }
665        TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; }
666        TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
667
668        virtual TupleIndexExpr * clone() const { return new TupleIndexExpr( * this ); }
669        virtual void accept( Visitor & v ) { v.visit( this ); }
670        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
671        virtual void print( std::ostream & os, Indenter indent = {} ) const;
672};
673
674/// 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
675class TupleAssignExpr : public Expression {
676  public:
677        StmtExpr * stmtExpr = nullptr;
678
679        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls );
680        TupleAssignExpr( const TupleAssignExpr & other );
681
682        TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
683        StmtExpr * get_stmtExpr() const { return stmtExpr; }
684
685        virtual TupleAssignExpr * clone() const { return new TupleAssignExpr( * this ); }
686        virtual void accept( Visitor & v ) { v.visit( this ); }
687        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
688        virtual void print( std::ostream & os, Indenter indent = {} ) const;
689};
690
691/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
692class StmtExpr : public Expression {
693public:
694        CompoundStmt * statements;
695        std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
696        std::list< Expression * > dtors; // destructor(s) for return variable(s)
697
698        StmtExpr( CompoundStmt * statements );
699        StmtExpr( const StmtExpr & other );
700
701        CompoundStmt * get_statements() const { return statements; }
702        StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
703
704        // call to set the result type of this StmtExpr based on its body
705        void computeResult();
706
707        std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
708        std::list< Expression * > & get_dtors() { return dtors; }
709
710        virtual StmtExpr * clone() const { return new StmtExpr( * this ); }
711        virtual void accept( Visitor & v ) { v.visit( this ); }
712        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
713        virtual void print( std::ostream & os, Indenter indent = {} ) const;
714};
715
716class UniqueExpr : public Expression {
717public:
718        Expression * expr;
719        ObjectDecl * object;
720        VariableExpr * var;
721
722        UniqueExpr( Expression * expr, long long idVal = -1 );
723        UniqueExpr( const UniqueExpr & other );
724
725        Expression * get_expr() const { return expr; }
726        UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
727
728        ObjectDecl * get_object() const { return object; }
729        UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; }
730
731        VariableExpr * get_var() const { return var; }
732        UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; }
733
734        int get_id() const { return id; }
735
736        virtual UniqueExpr * clone() const { return new UniqueExpr( * this ); }
737        virtual void accept( Visitor & v ) { v.visit( this ); }
738        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
739        virtual void print( std::ostream & os, Indenter indent = {} ) const;
740
741private:
742        int id;
743        static long long count;
744};
745
746struct InitAlternative {
747public:
748        Type * type = nullptr;
749        Designation * designation = nullptr;
750        InitAlternative( Type * type, Designation * designation );
751        InitAlternative( const InitAlternative & other );
752        InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it
753};
754
755class UntypedInitExpr : public Expression {
756public:
757        Expression * expr;
758        std::list<InitAlternative> initAlts;
759
760        UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
761        UntypedInitExpr( const UntypedInitExpr & other );
762
763        Expression * get_expr() const { return expr; }
764        UntypedInitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
765
766        std::list<InitAlternative> & get_initAlts() { return initAlts; }
767
768        virtual UntypedInitExpr * clone() const { return new UntypedInitExpr( * this ); }
769        virtual void accept( Visitor & v ) { v.visit( this ); }
770        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
771        virtual void print( std::ostream & os, Indenter indent = {} ) const;
772};
773
774class InitExpr : public Expression {
775public:
776        Expression * expr;
777        Designation * designation;
778
779        InitExpr( Expression * expr, Designation * designation );
780        InitExpr( const InitExpr & other );
781
782        Expression * get_expr() const { return expr; }
783        InitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
784
785        Designation * get_designation() const { return designation; }
786        InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; }
787
788        virtual InitExpr * clone() const { return new InitExpr( * this ); }
789        virtual void accept( Visitor & v ) { v.visit( this ); }
790        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
791        virtual void print( std::ostream & os, Indenter indent = {} ) const;
792};
793
794/// expression that contains a deleted identifier - should never make it past the resolver.
795class DeletedExpr : public Expression {
796public:
797        Expression * expr;
798        BaseSyntaxNode * deleteStmt;
799
800        DeletedExpr( Expression * expr, BaseSyntaxNode * deleteStmt );
801        DeletedExpr( const DeletedExpr & other );
802
803        virtual DeletedExpr * clone() const { return new DeletedExpr( * this ); }
804        virtual void accept( Visitor & v ) { v.visit( this ); }
805        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
806        virtual void print( std::ostream & os, Indenter indent = {} ) const;
807};
808
809// Local Variables: //
810// tab-width: 4 //
811// mode: c++ //
812// compile-command: "make install" //
813// End: //
Note: See TracBrowser for help on using the repository browser.