source: src/SynTree/Expression.h @ 0f19f5e5

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 0f19f5e5 was 2d80111, checked in by Andrew Beach <ajbeach@…>, 5 years ago

Lvalue is checked through Expression::get_lvalue. Only three other places use Type::get_lvalue directly now: CodeGen/GenType?, ResolvExpr/ConversionCost? & SynTree/TopLvalue?.

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