source: src/SynTree/Expression.h @ f9a7cf0

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since f9a7cf0 was 546e712, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Fix for 1 bug of N

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