source: src/SynTree/Expression.h @ aaeacf4

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

Removed global look-up table from UniqueId? to Decl

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