source: src/SynTree/Expression.h @ 2f86ddf

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 2f86ddf was 2f86ddf, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Add Destructor handlers for argument and return temporaries, merge and simplify ResolveCopyCtors/FixCopyCtors? passes, simplify ImplicitCopyCtorExpr?

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