source: src/SynTree/Expression.h @ 60ba456

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since 60ba456 was c0bf94e, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Add isGenerated flag to CastExpr? to differentiate casts in source from compiler-generated casts

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