| [0dd3a2f] | 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 | //
 | 
|---|
| [3be261a] | 7 | // Expression.h --
 | 
|---|
| [0dd3a2f] | 8 | //
 | 
|---|
 | 9 | // Author           : Richard C. Bilson
 | 
|---|
 | 10 | // Created On       : Mon May 18 07:44:20 2015
 | 
|---|
| [e04ef3a] | 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| [6b0b624] | 12 | // Last Modified On : Sat Jul 22 09:53:16 2017
 | 
|---|
 | 13 | // Update Count     : 42
 | 
|---|
| [0dd3a2f] | 14 | //
 | 
|---|
| [51b73452] | 15 | 
 | 
|---|
| [6b0b624] | 16 | #pragma once
 | 
|---|
| [51b73452] | 17 | 
 | 
|---|
 | 18 | #include <map>
 | 
|---|
| [8688ce1] | 19 | #include <memory>
 | 
|---|
| [294647b] | 20 | 
 | 
|---|
 | 21 | #include "BaseSyntaxNode.h"
 | 
|---|
 | 22 | #include "Constant.h"
 | 
|---|
 | 23 | #include "Mutator.h"
 | 
|---|
| [51b73452] | 24 | #include "SynTree.h"
 | 
|---|
 | 25 | #include "Visitor.h"
 | 
|---|
| [db4ecc5] | 26 | #include "Common/UniqueName.h"
 | 
|---|
| [51b73452] | 27 | 
 | 
|---|
| [47534159] | 28 | /// Expression is the root type for all expressions
 | 
|---|
| [294647b] | 29 | class Expression : public BaseSyntaxNode{
 | 
|---|
| [0dd3a2f] | 30 |   public:
 | 
|---|
| [5ded739] | 31 |         Expression( Expression * _aname = nullptr );
 | 
|---|
 | 32 |         Expression( const Expression & other );
 | 
|---|
| [0dd3a2f] | 33 |         virtual ~Expression();
 | 
|---|
 | 34 | 
 | 
|---|
| [906e24d] | 35 |         Type *& get_result() { return result; }
 | 
|---|
| [fbcde64] | 36 |         const Type * get_result() const { return result; }
 | 
|---|
| [5ded739] | 37 |         void set_result( Type * newValue ) { result = newValue; }
 | 
|---|
| [906e24d] | 38 |         bool has_result() const { return result != nullptr; }
 | 
|---|
| [0dd3a2f] | 39 | 
 | 
|---|
| [5ded739] | 40 |         TypeSubstitution * get_env() const { return env; }
 | 
|---|
 | 41 |         void set_env( TypeSubstitution * newValue ) { env = newValue; }
 | 
|---|
 | 42 |         Expression * get_argName() const { return argName; }
 | 
|---|
 | 43 |         void set_argName( Expression * name ) { argName = name; }
 | 
|---|
| [e04ef3a] | 44 |         bool get_extension() const { return extension; }
 | 
|---|
| [8e9cbb2] | 45 |         Expression * set_extension( bool exten ) { extension = exten; return this; }
 | 
|---|
| [0dd3a2f] | 46 | 
 | 
|---|
| [5ded739] | 47 |         virtual Expression * clone() const = 0;
 | 
|---|
 | 48 |         virtual void accept( Visitor & v ) = 0;
 | 
|---|
 | 49 |         virtual Expression * acceptMutator( Mutator & m ) = 0;
 | 
|---|
 | 50 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 51 |   protected:
 | 
|---|
| [906e24d] | 52 |         Type * result;
 | 
|---|
| [5ded739] | 53 |         TypeSubstitution * env;
 | 
|---|
 | 54 |         Expression * argName; // if expression is used as an argument, it can be "designated" by this name
 | 
|---|
| [e04ef3a] | 55 |         bool extension = false;
 | 
|---|
| [51b73452] | 56 | };
 | 
|---|
 | 57 | 
 | 
|---|
| [6c3a988f] | 58 | struct ParamEntry;
 | 
|---|
 | 59 | typedef std::map< UniqueId, ParamEntry > InferredParams;
 | 
|---|
 | 60 | 
 | 
|---|
| [47534159] | 61 | /// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
 | 
|---|
 | 62 | /// but subject to decay-to-pointer and type parameter renaming
 | 
|---|
| [0dd3a2f] | 63 | struct ParamEntry {
 | 
|---|
| [6c3a988f] | 64 |         ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ), inferParams( new InferredParams ) {}
 | 
|---|
| [5ded739] | 65 |         ParamEntry( UniqueId decl, Type * actualType, Type * formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ), inferParams( new InferredParams ) {}
 | 
|---|
 | 66 |         ParamEntry( const ParamEntry & other );
 | 
|---|
| [0dd3a2f] | 67 |         ~ParamEntry();
 | 
|---|
| [5ded739] | 68 |         ParamEntry & operator=( const ParamEntry & other );
 | 
|---|
| [0dd3a2f] | 69 | 
 | 
|---|
 | 70 |         UniqueId decl;
 | 
|---|
| [5ded739] | 71 |         Type * actualType;
 | 
|---|
 | 72 |         Type * formalType;
 | 
|---|
| [0dd3a2f] | 73 |         Expression* expr;
 | 
|---|
| [6c3a988f] | 74 |         std::unique_ptr< InferredParams > inferParams;
 | 
|---|
| [51b73452] | 75 | };
 | 
|---|
 | 76 | 
 | 
|---|
| [9706554] | 77 | /// ApplicationExpr represents the application of a function to a set of parameters.  This is the result of running an
 | 
|---|
 | 78 | /// UntypedExpr through the expression analyzer.
 | 
|---|
| [0dd3a2f] | 79 | class ApplicationExpr : public Expression {
 | 
|---|
 | 80 |   public:
 | 
|---|
| [5ded739] | 81 |         ApplicationExpr( Expression * function );
 | 
|---|
 | 82 |         ApplicationExpr( const ApplicationExpr & other );
 | 
|---|
| [0dd3a2f] | 83 |         virtual ~ApplicationExpr();
 | 
|---|
 | 84 | 
 | 
|---|
| [5ded739] | 85 |         Expression * get_function() const { return function; }
 | 
|---|
 | 86 |         void set_function( Expression * newValue ) { function = newValue; }
 | 
|---|
| [0dd3a2f] | 87 |         std::list<Expression *>& get_args() { return args; }
 | 
|---|
| [5ded739] | 88 |         InferredParams & get_inferParams() { return inferParams; }
 | 
|---|
| [0dd3a2f] | 89 | 
 | 
|---|
| [5ded739] | 90 |         virtual ApplicationExpr * clone() const { return new ApplicationExpr( * this ); }
 | 
|---|
 | 91 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 92 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 93 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 94 |   private:
 | 
|---|
| [5ded739] | 95 |         Expression * function;
 | 
|---|
| [0dd3a2f] | 96 |         std::list<Expression *> args;
 | 
|---|
 | 97 |         InferredParams inferParams;
 | 
|---|
| [51b73452] | 98 | };
 | 
|---|
 | 99 | 
 | 
|---|
| [9706554] | 100 | /// UntypedExpr represents the application of a function to a set of parameters, but where the particular overload for
 | 
|---|
 | 101 | /// the function name has not yet been determined.  Most operators are converted into functional form automatically, to
 | 
|---|
 | 102 | /// permit operator overloading.
 | 
|---|
| [0dd3a2f] | 103 | class UntypedExpr : public Expression {
 | 
|---|
 | 104 |   public:
 | 
|---|
| [5ded739] | 105 |         UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >(), Expression *_aname = nullptr );
 | 
|---|
 | 106 |         UntypedExpr( const UntypedExpr & other );
 | 
|---|
| [0dd3a2f] | 107 |         virtual ~UntypedExpr();
 | 
|---|
 | 108 | 
 | 
|---|
| [5ded739] | 109 |         Expression * get_function() const { return function; }
 | 
|---|
 | 110 |         void set_function( Expression * newValue ) { function = newValue; }
 | 
|---|
| [0dd3a2f] | 111 | 
 | 
|---|
| [5ded739] | 112 |         void set_args( std::list<Expression *> & listArgs ) { args = listArgs; }
 | 
|---|
| [0dd3a2f] | 113 |         std::list<Expression*>::iterator begin_args() { return args.begin(); }
 | 
|---|
 | 114 |         std::list<Expression*>::iterator end_args() { return args.end(); }
 | 
|---|
 | 115 |         std::list<Expression*>& get_args() { return args; }
 | 
|---|
 | 116 | 
 | 
|---|
| [b3b2077] | 117 |         static UntypedExpr * createDeref( Expression * arg );
 | 
|---|
 | 118 |         static UntypedExpr * createAssign( Expression * arg1, Expression * arg2 );
 | 
|---|
 | 119 | 
 | 
|---|
| [5ded739] | 120 |         virtual UntypedExpr * clone() const { return new UntypedExpr( * this ); }
 | 
|---|
 | 121 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 122 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 123 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
 | 124 |         virtual void printArgs(std::ostream & os, int indent = 0) const;
 | 
|---|
| [0dd3a2f] | 125 |   private:
 | 
|---|
| [5ded739] | 126 |         Expression * function;
 | 
|---|
| [0dd3a2f] | 127 |         std::list<Expression*> args;
 | 
|---|
| [51b73452] | 128 | };
 | 
|---|
 | 129 | 
 | 
|---|
| [47534159] | 130 | /// NameExpr contains a name whose meaning is still not determined
 | 
|---|
| [0dd3a2f] | 131 | class NameExpr : public Expression {
 | 
|---|
 | 132 |   public:
 | 
|---|
| [7bf7fb9] | 133 |         NameExpr( std::string name, Expression *_aname = nullptr );
 | 
|---|
| [5ded739] | 134 |         NameExpr( const NameExpr & other );
 | 
|---|
| [0dd3a2f] | 135 |         virtual ~NameExpr();
 | 
|---|
 | 136 | 
 | 
|---|
| [5ded739] | 137 |         const std::string & get_name() const { return name; }
 | 
|---|
| [0dd3a2f] | 138 |         void set_name( std::string newValue ) { name = newValue; }
 | 
|---|
 | 139 | 
 | 
|---|
| [5ded739] | 140 |         virtual NameExpr * clone() const { return new NameExpr( * this ); }
 | 
|---|
 | 141 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 142 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 143 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 144 |   private:
 | 
|---|
 | 145 |         std::string name;
 | 
|---|
| [51b73452] | 146 | };
 | 
|---|
 | 147 | 
 | 
|---|
 | 148 | // The following classes are used to represent expression types that cannot be converted into
 | 
|---|
 | 149 | // function-call format.
 | 
|---|
 | 150 | 
 | 
|---|
| [5ded739] | 151 | /// AddressExpr represents a address-of expression, e.g. & e
 | 
|---|
| [0dd3a2f] | 152 | class AddressExpr : public Expression {
 | 
|---|
 | 153 |   public:
 | 
|---|
| [5ded739] | 154 |         AddressExpr( Expression * arg, Expression *_aname = nullptr );
 | 
|---|
 | 155 |         AddressExpr( const AddressExpr & other );
 | 
|---|
| [0dd3a2f] | 156 |         virtual ~AddressExpr();
 | 
|---|
 | 157 | 
 | 
|---|
| [5ded739] | 158 |         Expression * get_arg() const { return arg; }
 | 
|---|
 | 159 |         void set_arg(Expression * newValue ) { arg = newValue; }
 | 
|---|
| [0dd3a2f] | 160 | 
 | 
|---|
| [5ded739] | 161 |         virtual AddressExpr * clone() const { return new AddressExpr( * this ); }
 | 
|---|
 | 162 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 163 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 164 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 165 |   private:
 | 
|---|
| [5ded739] | 166 |         Expression * arg;
 | 
|---|
| [51b73452] | 167 | };
 | 
|---|
 | 168 | 
 | 
|---|
| [3be261a] | 169 | // xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack
 | 
|---|
| [0dd3a2f] | 170 | class LabelAddressExpr : public Expression {
 | 
|---|
 | 171 |   public:
 | 
|---|
| [5ded739] | 172 |         LabelAddressExpr( Expression * arg );
 | 
|---|
 | 173 |         LabelAddressExpr( const LabelAddressExpr & other );
 | 
|---|
| [0dd3a2f] | 174 |         virtual ~LabelAddressExpr();
 | 
|---|
 | 175 | 
 | 
|---|
| [5ded739] | 176 |         Expression * get_arg() const { return arg; }
 | 
|---|
 | 177 |         void set_arg(Expression * newValue ) { arg = newValue; }
 | 
|---|
| [0dd3a2f] | 178 | 
 | 
|---|
| [5ded739] | 179 |         virtual LabelAddressExpr * clone() const { return new LabelAddressExpr( * this ); }
 | 
|---|
 | 180 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 181 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 182 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 183 |   private:
 | 
|---|
| [5ded739] | 184 |         Expression * arg;
 | 
|---|
| [51b73452] | 185 | };
 | 
|---|
 | 186 | 
 | 
|---|
| [47534159] | 187 | /// CastExpr represents a type cast expression, e.g. (int)e
 | 
|---|
| [0dd3a2f] | 188 | class CastExpr : public Expression {
 | 
|---|
 | 189 |   public:
 | 
|---|
| [5ded739] | 190 |         CastExpr( Expression * arg, Expression *_aname = nullptr );
 | 
|---|
 | 191 |         CastExpr( Expression * arg, Type * toType, Expression *_aname = nullptr );
 | 
|---|
 | 192 |         CastExpr( const CastExpr & other );
 | 
|---|
| [0dd3a2f] | 193 |         virtual ~CastExpr();
 | 
|---|
 | 194 | 
 | 
|---|
| [5ded739] | 195 |         Expression * get_arg() const { return arg; }
 | 
|---|
 | 196 |         void set_arg(Expression * newValue ) { arg = newValue; }
 | 
|---|
| [0dd3a2f] | 197 | 
 | 
|---|
| [5ded739] | 198 |         virtual CastExpr * clone() const { return new CastExpr( * this ); }
 | 
|---|
 | 199 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 200 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 201 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 202 |   private:
 | 
|---|
| [5ded739] | 203 |         Expression * arg;
 | 
|---|
| [51b73452] | 204 | };
 | 
|---|
 | 205 | 
 | 
|---|
| [47534159] | 206 | /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
 | 
|---|
| [0dd3a2f] | 207 | class UntypedMemberExpr : public Expression {
 | 
|---|
 | 208 |   public:
 | 
|---|
| [5ded739] | 209 |         UntypedMemberExpr( Expression * member, Expression * aggregate, Expression *_aname = nullptr );
 | 
|---|
 | 210 |         UntypedMemberExpr( const UntypedMemberExpr & other );
 | 
|---|
| [0dd3a2f] | 211 |         virtual ~UntypedMemberExpr();
 | 
|---|
 | 212 | 
 | 
|---|
| [3b58d91] | 213 |         Expression * get_member() const { return member; }
 | 
|---|
 | 214 |         void set_member( Expression * newValue ) { member = newValue; }
 | 
|---|
| [5ded739] | 215 |         Expression * get_aggregate() const { return aggregate; }
 | 
|---|
 | 216 |         void set_aggregate( Expression * newValue ) { aggregate = newValue; }
 | 
|---|
| [0dd3a2f] | 217 | 
 | 
|---|
| [5ded739] | 218 |         virtual UntypedMemberExpr * clone() const { return new UntypedMemberExpr( * this ); }
 | 
|---|
 | 219 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 220 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 221 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 222 |   private:
 | 
|---|
| [5ded739] | 223 |         Expression * member;
 | 
|---|
 | 224 |         Expression * aggregate;
 | 
|---|
| [51b73452] | 225 | };
 | 
|---|
 | 226 | 
 | 
|---|
| [4551a6e] | 227 | /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer.
 | 
|---|
 | 228 | /// Does not take ownership of member.
 | 
|---|
| [0dd3a2f] | 229 | class MemberExpr : public Expression {
 | 
|---|
 | 230 |   public:
 | 
|---|
| [5ded739] | 231 |         MemberExpr( DeclarationWithType * member, Expression * aggregate, Expression *_aname = nullptr );
 | 
|---|
 | 232 |         MemberExpr( const MemberExpr & other );
 | 
|---|
| [0dd3a2f] | 233 |         virtual ~MemberExpr();
 | 
|---|
 | 234 | 
 | 
|---|
| [5ded739] | 235 |         DeclarationWithType * get_member() const { return member; }
 | 
|---|
 | 236 |         void set_member( DeclarationWithType * newValue ) { member = newValue; }
 | 
|---|
 | 237 |         Expression * get_aggregate() const { return aggregate; }
 | 
|---|
 | 238 |         void set_aggregate( Expression * newValue ) { aggregate = newValue; }
 | 
|---|
| [0dd3a2f] | 239 | 
 | 
|---|
| [5ded739] | 240 |         virtual MemberExpr * clone() const { return new MemberExpr( * this ); }
 | 
|---|
 | 241 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 242 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 243 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 244 |   private:
 | 
|---|
| [5ded739] | 245 |         DeclarationWithType * member;
 | 
|---|
 | 246 |         Expression * aggregate;
 | 
|---|
| [51b73452] | 247 | };
 | 
|---|
 | 248 | 
 | 
|---|
| [4551a6e] | 249 | /// VariableExpr represents an expression that simply refers to the value of a named variable.
 | 
|---|
 | 250 | /// Does not take ownership of var.
 | 
|---|
| [0dd3a2f] | 251 | class VariableExpr : public Expression {
 | 
|---|
 | 252 |   public:
 | 
|---|
| [5ded739] | 253 |         VariableExpr( DeclarationWithType * var, Expression *_aname = nullptr );
 | 
|---|
 | 254 |         VariableExpr( const VariableExpr & other );
 | 
|---|
| [0dd3a2f] | 255 |         virtual ~VariableExpr();
 | 
|---|
 | 256 | 
 | 
|---|
| [5ded739] | 257 |         DeclarationWithType * get_var() const { return var; }
 | 
|---|
 | 258 |         void set_var( DeclarationWithType * newValue ) { var = newValue; }
 | 
|---|
| [0dd3a2f] | 259 | 
 | 
|---|
| [5ded739] | 260 |         virtual VariableExpr * clone() const { return new VariableExpr( * this ); }
 | 
|---|
 | 261 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 262 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 263 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 264 |   private:
 | 
|---|
| [5ded739] | 265 |         DeclarationWithType * var;
 | 
|---|
| [51b73452] | 266 | };
 | 
|---|
 | 267 | 
 | 
|---|
| [3be261a] | 268 | /// ConstantExpr represents an expression that simply refers to the value of a constant
 | 
|---|
| [0dd3a2f] | 269 | class ConstantExpr : public Expression {
 | 
|---|
 | 270 |   public:
 | 
|---|
| [7bf7fb9] | 271 |         ConstantExpr( Constant constant, Expression *_aname = nullptr );
 | 
|---|
| [5ded739] | 272 |         ConstantExpr( const ConstantExpr & other );
 | 
|---|
| [0dd3a2f] | 273 |         virtual ~ConstantExpr();
 | 
|---|
 | 274 | 
 | 
|---|
| [5ded739] | 275 |         Constant * get_constant() { return & constant; }
 | 
|---|
 | 276 |         void set_constant( const Constant & newValue ) { constant = newValue; }
 | 
|---|
| [0dd3a2f] | 277 | 
 | 
|---|
| [5ded739] | 278 |         virtual ConstantExpr * clone() const { return new ConstantExpr( * this ); }
 | 
|---|
 | 279 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 280 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 281 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 282 |   private:
 | 
|---|
 | 283 |         Constant constant;
 | 
|---|
| [51b73452] | 284 | };
 | 
|---|
 | 285 | 
 | 
|---|
| [47534159] | 286 | /// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
 | 
|---|
| [0dd3a2f] | 287 | class SizeofExpr : public Expression {
 | 
|---|
 | 288 |   public:
 | 
|---|
| [5ded739] | 289 |         SizeofExpr( Expression * expr, Expression *_aname = nullptr );
 | 
|---|
 | 290 |         SizeofExpr( const SizeofExpr & other );
 | 
|---|
 | 291 |         SizeofExpr( Type * type, Expression *_aname = nullptr );
 | 
|---|
| [0dd3a2f] | 292 |         virtual ~SizeofExpr();
 | 
|---|
 | 293 | 
 | 
|---|
| [5ded739] | 294 |         Expression * get_expr() const { return expr; }
 | 
|---|
 | 295 |         void set_expr( Expression * newValue ) { expr = newValue; }
 | 
|---|
 | 296 |         Type * get_type() const { return type; }
 | 
|---|
 | 297 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
| [0dd3a2f] | 298 |         bool get_isType() const { return isType; }
 | 
|---|
 | 299 |         void set_isType( bool newValue ) { isType = newValue; }
 | 
|---|
 | 300 | 
 | 
|---|
| [5ded739] | 301 |         virtual SizeofExpr * clone() const { return new SizeofExpr( * this ); }
 | 
|---|
 | 302 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 303 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 304 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 305 |   private:
 | 
|---|
| [5ded739] | 306 |         Expression * expr;
 | 
|---|
 | 307 |         Type * type;
 | 
|---|
| [0dd3a2f] | 308 |         bool isType;
 | 
|---|
| [51b73452] | 309 | };
 | 
|---|
 | 310 | 
 | 
|---|
| [47534159] | 311 | /// AlignofExpr represents an alignof expression
 | 
|---|
 | 312 | class AlignofExpr : public Expression {
 | 
|---|
 | 313 |   public:
 | 
|---|
| [5ded739] | 314 |         AlignofExpr( Expression * expr, Expression *_aname = nullptr );
 | 
|---|
 | 315 |         AlignofExpr( const AlignofExpr & other );
 | 
|---|
 | 316 |         AlignofExpr( Type * type, Expression *_aname = nullptr );
 | 
|---|
| [47534159] | 317 |         virtual ~AlignofExpr();
 | 
|---|
 | 318 | 
 | 
|---|
| [5ded739] | 319 |         Expression * get_expr() const { return expr; }
 | 
|---|
 | 320 |         void set_expr( Expression * newValue ) { expr = newValue; }
 | 
|---|
 | 321 |         Type * get_type() const { return type; }
 | 
|---|
 | 322 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
| [47534159] | 323 |         bool get_isType() const { return isType; }
 | 
|---|
 | 324 |         void set_isType( bool newValue ) { isType = newValue; }
 | 
|---|
 | 325 | 
 | 
|---|
| [5ded739] | 326 |         virtual AlignofExpr * clone() const { return new AlignofExpr( * this ); }
 | 
|---|
 | 327 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 328 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 329 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [47534159] | 330 |   private:
 | 
|---|
| [5ded739] | 331 |         Expression * expr;
 | 
|---|
 | 332 |         Type * type;
 | 
|---|
| [47534159] | 333 |         bool isType;
 | 
|---|
 | 334 | };
 | 
|---|
 | 335 | 
 | 
|---|
| [2a4b088] | 336 | /// UntypedOffsetofExpr represents an offsetof expression before resolution
 | 
|---|
 | 337 | class UntypedOffsetofExpr : public Expression {
 | 
|---|
 | 338 |   public:
 | 
|---|
| [5ded739] | 339 |         UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr );
 | 
|---|
 | 340 |         UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
 | 
|---|
| [2a4b088] | 341 |         virtual ~UntypedOffsetofExpr();
 | 
|---|
 | 342 | 
 | 
|---|
 | 343 |         std::string get_member() const { return member; }
 | 
|---|
| [5ded739] | 344 |         void set_member( const std::string & newValue ) { member = newValue; }
 | 
|---|
 | 345 |         Type * get_type() const { return type; }
 | 
|---|
 | 346 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
 | 347 | 
 | 
|---|
 | 348 |         virtual UntypedOffsetofExpr * clone() const { return new UntypedOffsetofExpr( * this ); }
 | 
|---|
 | 349 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 350 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 351 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [2a4b088] | 352 |   private:
 | 
|---|
| [5ded739] | 353 |         Type * type;
 | 
|---|
| [2a4b088] | 354 |         std::string member;
 | 
|---|
 | 355 | };
 | 
|---|
 | 356 | 
 | 
|---|
| [25a054f] | 357 | /// OffsetofExpr represents an offsetof expression
 | 
|---|
 | 358 | class OffsetofExpr : public Expression {
 | 
|---|
 | 359 |   public:
 | 
|---|
| [5ded739] | 360 |         OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr );
 | 
|---|
 | 361 |         OffsetofExpr( const OffsetofExpr & other );
 | 
|---|
| [25a054f] | 362 |         virtual ~OffsetofExpr();
 | 
|---|
 | 363 | 
 | 
|---|
| [5ded739] | 364 |         Type * get_type() const { return type; }
 | 
|---|
 | 365 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
 | 366 |         DeclarationWithType * get_member() const { return member; }
 | 
|---|
 | 367 |         void set_member( DeclarationWithType * newValue ) { member = newValue; }
 | 
|---|
 | 368 | 
 | 
|---|
 | 369 |         virtual OffsetofExpr * clone() const { return new OffsetofExpr( * this ); }
 | 
|---|
 | 370 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 371 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 372 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [25a054f] | 373 |   private:
 | 
|---|
| [5ded739] | 374 |         Type * type;
 | 
|---|
 | 375 |         DeclarationWithType * member;
 | 
|---|
| [25a054f] | 376 | };
 | 
|---|
 | 377 | 
 | 
|---|
| [afc1045] | 378 | /// Expression representing a pack of field-offsets for a generic type
 | 
|---|
 | 379 | class OffsetPackExpr : public Expression {
 | 
|---|
 | 380 | public:
 | 
|---|
| [5ded739] | 381 |         OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 );
 | 
|---|
 | 382 |         OffsetPackExpr( const OffsetPackExpr & other );
 | 
|---|
| [afc1045] | 383 |         virtual ~OffsetPackExpr();
 | 
|---|
 | 384 | 
 | 
|---|
| [5ded739] | 385 |         StructInstType * get_type() const { return type; }
 | 
|---|
 | 386 |         void set_type( StructInstType * newValue ) { type = newValue; }
 | 
|---|
| [afc1045] | 387 | 
 | 
|---|
| [5ded739] | 388 |         virtual OffsetPackExpr * clone() const { return new OffsetPackExpr( * this ); }
 | 
|---|
 | 389 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 390 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| [afc1045] | 391 | 
 | 
|---|
| [5ded739] | 392 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [afc1045] | 393 | 
 | 
|---|
 | 394 | private:
 | 
|---|
| [5ded739] | 395 |         StructInstType * type;
 | 
|---|
| [afc1045] | 396 | };
 | 
|---|
 | 397 | 
 | 
|---|
| [47534159] | 398 | /// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
 | 
|---|
| [0dd3a2f] | 399 | class AttrExpr : public Expression {
 | 
|---|
 | 400 |   public:
 | 
|---|
| [5ded739] | 401 |         AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr );
 | 
|---|
 | 402 |         AttrExpr( const AttrExpr & other );
 | 
|---|
 | 403 |         AttrExpr( Expression * attr, Type * type, Expression *_aname = nullptr );
 | 
|---|
| [0dd3a2f] | 404 |         virtual ~AttrExpr();
 | 
|---|
 | 405 | 
 | 
|---|
| [5ded739] | 406 |         Expression * get_attr() const { return attr; }
 | 
|---|
 | 407 |         void set_attr( Expression * newValue ) { attr = newValue; }
 | 
|---|
 | 408 |         Expression * get_expr() const { return expr; }
 | 
|---|
 | 409 |         void set_expr( Expression * newValue ) { expr = newValue; }
 | 
|---|
 | 410 |         Type * get_type() const { return type; }
 | 
|---|
 | 411 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
| [0dd3a2f] | 412 |         bool get_isType() const { return isType; }
 | 
|---|
 | 413 |         void set_isType( bool newValue ) { isType = newValue; }
 | 
|---|
 | 414 | 
 | 
|---|
| [5ded739] | 415 |         virtual AttrExpr * clone() const { return new AttrExpr( * this ); }
 | 
|---|
 | 416 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 417 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 418 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 419 |   private:
 | 
|---|
| [5ded739] | 420 |         Expression * attr;
 | 
|---|
 | 421 |         Expression * expr;
 | 
|---|
 | 422 |         Type * type;
 | 
|---|
| [0dd3a2f] | 423 |         bool isType;
 | 
|---|
| [51b73452] | 424 | };
 | 
|---|
 | 425 | 
 | 
|---|
| [47534159] | 426 | /// LogicalExpr represents a short-circuit boolean expression (&& or ||)
 | 
|---|
| [0dd3a2f] | 427 | class LogicalExpr : public Expression {
 | 
|---|
 | 428 |   public:
 | 
|---|
| [5ded739] | 429 |         LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr );
 | 
|---|
 | 430 |         LogicalExpr( const LogicalExpr & other );
 | 
|---|
| [0dd3a2f] | 431 |         virtual ~LogicalExpr();
 | 
|---|
 | 432 | 
 | 
|---|
 | 433 |         bool get_isAnd() const { return isAnd; }
 | 
|---|
| [5ded739] | 434 |         Expression * get_arg1() { return arg1; }
 | 
|---|
 | 435 |         void set_arg1( Expression * newValue ) { arg1 = newValue; }
 | 
|---|
 | 436 |         Expression * get_arg2() const { return arg2; }
 | 
|---|
 | 437 |         void set_arg2( Expression * newValue ) { arg2 = newValue; }
 | 
|---|
 | 438 | 
 | 
|---|
 | 439 |         virtual LogicalExpr * clone() const { return new LogicalExpr( * this ); }
 | 
|---|
 | 440 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 441 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 442 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 443 |   private:
 | 
|---|
| [5ded739] | 444 |         Expression * arg1;
 | 
|---|
 | 445 |         Expression * arg2;
 | 
|---|
| [0dd3a2f] | 446 |         bool isAnd;
 | 
|---|
| [51b73452] | 447 | };
 | 
|---|
 | 448 | 
 | 
|---|
| [47534159] | 449 | /// ConditionalExpr represents the three-argument conditional ( p ? a : b )
 | 
|---|
| [0dd3a2f] | 450 | class ConditionalExpr : public Expression {
 | 
|---|
 | 451 |   public:
 | 
|---|
| [5ded739] | 452 |         ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr );
 | 
|---|
 | 453 |         ConditionalExpr( const ConditionalExpr & other );
 | 
|---|
| [0dd3a2f] | 454 |         virtual ~ConditionalExpr();
 | 
|---|
 | 455 | 
 | 
|---|
| [5ded739] | 456 |         Expression * get_arg1() const { return arg1; }
 | 
|---|
 | 457 |         void set_arg1( Expression * newValue ) { arg1 = newValue; }
 | 
|---|
 | 458 |         Expression * get_arg2() const { return arg2; }
 | 
|---|
 | 459 |         void set_arg2( Expression * newValue ) { arg2 = newValue; }
 | 
|---|
 | 460 |         Expression * get_arg3() const { return arg3; }
 | 
|---|
 | 461 |         void set_arg3( Expression * newValue ) { arg3 = newValue; }
 | 
|---|
 | 462 | 
 | 
|---|
 | 463 |         virtual ConditionalExpr * clone() const { return new ConditionalExpr( * this ); }
 | 
|---|
 | 464 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 465 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 466 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 467 |   private:
 | 
|---|
| [5ded739] | 468 |         Expression * arg1;
 | 
|---|
 | 469 |         Expression * arg2;
 | 
|---|
 | 470 |         Expression * arg3;
 | 
|---|
| [51b73452] | 471 | };
 | 
|---|
 | 472 | 
 | 
|---|
| [47534159] | 473 | /// CommaExpr represents the sequence operator ( a, b )
 | 
|---|
| [0dd3a2f] | 474 | class CommaExpr : public Expression {
 | 
|---|
 | 475 |   public:
 | 
|---|
| [5ded739] | 476 |         CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr );
 | 
|---|
 | 477 |         CommaExpr( const CommaExpr & other );
 | 
|---|
| [0dd3a2f] | 478 |         virtual ~CommaExpr();
 | 
|---|
 | 479 | 
 | 
|---|
| [5ded739] | 480 |         Expression * get_arg1() const { return arg1; }
 | 
|---|
 | 481 |         void set_arg1( Expression * newValue ) { arg1 = newValue; }
 | 
|---|
 | 482 |         Expression * get_arg2() const { return arg2; }
 | 
|---|
 | 483 |         void set_arg2( Expression * newValue ) { arg2 = newValue; }
 | 
|---|
| [0dd3a2f] | 484 | 
 | 
|---|
| [5ded739] | 485 |         virtual CommaExpr * clone() const { return new CommaExpr( * this ); }
 | 
|---|
 | 486 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 487 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 488 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 489 |   private:
 | 
|---|
| [5ded739] | 490 |         Expression * arg1;
 | 
|---|
 | 491 |         Expression * arg2;
 | 
|---|
| [51b73452] | 492 | };
 | 
|---|
 | 493 | 
 | 
|---|
| [47534159] | 494 | /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
 | 
|---|
| [0dd3a2f] | 495 | class TypeExpr : public Expression {
 | 
|---|
 | 496 |   public:
 | 
|---|
| [5ded739] | 497 |         TypeExpr( Type * type );
 | 
|---|
 | 498 |         TypeExpr( const TypeExpr & other );
 | 
|---|
| [0dd3a2f] | 499 |         virtual ~TypeExpr();
 | 
|---|
 | 500 | 
 | 
|---|
| [5ded739] | 501 |         Type * get_type() const { return type; }
 | 
|---|
 | 502 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
| [0dd3a2f] | 503 | 
 | 
|---|
| [5ded739] | 504 |         virtual TypeExpr * clone() const { return new TypeExpr( * this ); }
 | 
|---|
 | 505 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 506 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 507 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [0dd3a2f] | 508 |   private:
 | 
|---|
| [5ded739] | 509 |         Type * type;
 | 
|---|
| [51b73452] | 510 | };
 | 
|---|
 | 511 | 
 | 
|---|
| [47534159] | 512 | /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
 | 
|---|
| [7f5566b] | 513 | class AsmExpr : public Expression {
 | 
|---|
 | 514 |   public:
 | 
|---|
| [5ded739] | 515 |         AsmExpr( Expression * inout, ConstantExpr * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
 | 
|---|
| [3be261a] | 516 |         AsmExpr( const AsmExpr & other );
 | 
|---|
| [7f5566b] | 517 |         virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
 | 
|---|
 | 518 | 
 | 
|---|
| [5ded739] | 519 |         Expression * get_inout() const { return inout; }
 | 
|---|
 | 520 |         void set_inout( Expression * newValue ) { inout = newValue; }
 | 
|---|
| [7f5566b] | 521 | 
 | 
|---|
| [5ded739] | 522 |         ConstantExpr * get_constraint() const { return constraint; }
 | 
|---|
 | 523 |         void set_constraint( ConstantExpr * newValue ) { constraint = newValue; }
 | 
|---|
| [7f5566b] | 524 | 
 | 
|---|
| [5ded739] | 525 |         Expression * get_operand() const { return operand; }
 | 
|---|
 | 526 |         void set_operand( Expression * newValue ) { operand = newValue; }
 | 
|---|
| [7f5566b] | 527 | 
 | 
|---|
| [5ded739] | 528 |         virtual AsmExpr * clone() const { return new AsmExpr( * this ); }
 | 
|---|
 | 529 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 530 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 531 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [7f5566b] | 532 |   private:
 | 
|---|
 | 533 |         // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
 | 
|---|
| [5ded739] | 534 |         Expression * inout;
 | 
|---|
 | 535 |         ConstantExpr * constraint;
 | 
|---|
 | 536 |         Expression * operand;
 | 
|---|
| [7f5566b] | 537 | };
 | 
|---|
 | 538 | 
 | 
|---|
| [db4ecc5] | 539 | /// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
 | 
|---|
 | 540 | /// along with a set of copy constructor calls, one for each argument.
 | 
|---|
 | 541 | class ImplicitCopyCtorExpr : public Expression {
 | 
|---|
 | 542 | public:
 | 
|---|
 | 543 |         ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
 | 
|---|
 | 544 |         ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
 | 
|---|
 | 545 |         virtual ~ImplicitCopyCtorExpr();
 | 
|---|
 | 546 | 
 | 
|---|
| [5ded739] | 547 |         ApplicationExpr * get_callExpr() const { return callExpr; }
 | 
|---|
 | 548 |         void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
 | 
|---|
| [db4ecc5] | 549 | 
 | 
|---|
 | 550 |         std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
 | 
|---|
 | 551 |         std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
 | 
|---|
 | 552 |         std::list< Expression * > & get_dtors() { return dtors; }
 | 
|---|
 | 553 | 
 | 
|---|
| [5ded739] | 554 |         virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
 | 
|---|
 | 555 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 556 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 557 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [db4ecc5] | 558 |   private:
 | 
|---|
 | 559 |         ApplicationExpr * callExpr;
 | 
|---|
 | 560 |         std::list< ObjectDecl * > tempDecls;
 | 
|---|
 | 561 |         std::list< ObjectDecl * > returnDecls;
 | 
|---|
 | 562 |         std::list< Expression * > dtors;
 | 
|---|
 | 563 | };
 | 
|---|
 | 564 | 
 | 
|---|
| [b6fe7e6] | 565 | /// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
 | 
|---|
 | 566 | class ConstructorExpr : public Expression {
 | 
|---|
 | 567 | public:
 | 
|---|
 | 568 |         ConstructorExpr( Expression * callExpr );
 | 
|---|
 | 569 |         ConstructorExpr( const ConstructorExpr & other );
 | 
|---|
 | 570 |         ~ConstructorExpr();
 | 
|---|
| [0dd3a2f] | 571 | 
 | 
|---|
| [5ded739] | 572 |         Expression * get_callExpr() const { return callExpr; }
 | 
|---|
 | 573 |         void set_callExpr( Expression * newValue ) { callExpr = newValue; }
 | 
|---|
| [0dd3a2f] | 574 | 
 | 
|---|
| [5ded739] | 575 |         virtual ConstructorExpr * clone() const { return new ConstructorExpr( * this ); }
 | 
|---|
 | 576 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 577 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 578 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [b6fe7e6] | 579 | private:
 | 
|---|
 | 580 |         Expression * callExpr;
 | 
|---|
| [51b73452] | 581 | };
 | 
|---|
 | 582 | 
 | 
|---|
| [630a82a] | 583 | /// CompoundLiteralExpr represents a C99 'compound literal'
 | 
|---|
 | 584 | class CompoundLiteralExpr : public Expression {
 | 
|---|
 | 585 |   public:
 | 
|---|
 | 586 |         CompoundLiteralExpr( Type * type, Initializer * initializer );
 | 
|---|
| [5ded739] | 587 |         CompoundLiteralExpr( const CompoundLiteralExpr & other );
 | 
|---|
| [3b58d91] | 588 |         virtual ~CompoundLiteralExpr();
 | 
|---|
| [630a82a] | 589 | 
 | 
|---|
 | 590 |         Initializer * get_initializer() const { return initializer; }
 | 
|---|
 | 591 |         void set_initializer( Initializer * i ) { initializer = i; }
 | 
|---|
 | 592 | 
 | 
|---|
| [5ded739] | 593 |         virtual CompoundLiteralExpr * clone() const { return new CompoundLiteralExpr( * this ); }
 | 
|---|
 | 594 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 595 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 596 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [630a82a] | 597 |   private:
 | 
|---|
 | 598 |         Initializer * initializer;
 | 
|---|
 | 599 | };
 | 
|---|
 | 600 | 
 | 
|---|
| [b6fe7e6] | 601 | /// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
 | 
|---|
| [8688ce1] | 602 | class RangeExpr : public Expression {
 | 
|---|
 | 603 |   public:
 | 
|---|
| [5ded739] | 604 |         RangeExpr( Expression * low, Expression * high );
 | 
|---|
 | 605 |         RangeExpr( const RangeExpr & other );
 | 
|---|
| [8688ce1] | 606 | 
 | 
|---|
| [d9e2280] | 607 |         Expression * get_low() const { return low; }
 | 
|---|
 | 608 |         Expression * get_high() const { return high; }
 | 
|---|
| [5ded739] | 609 |         RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; }
 | 
|---|
 | 610 |         RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
 | 
|---|
| [8688ce1] | 611 | 
 | 
|---|
| [5ded739] | 612 |         virtual RangeExpr * clone() const { return new RangeExpr( * this ); }
 | 
|---|
 | 613 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 614 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 615 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [8688ce1] | 616 |   private:
 | 
|---|
| [5ded739] | 617 |         Expression * low, * high;
 | 
|---|
| [8688ce1] | 618 | };
 | 
|---|
 | 619 | 
 | 
|---|
| [907eccb] | 620 | /// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution
 | 
|---|
 | 621 | class UntypedTupleExpr : public Expression {
 | 
|---|
 | 622 |   public:
 | 
|---|
 | 623 |         UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
 | 
|---|
| [5ded739] | 624 |         UntypedTupleExpr( const UntypedTupleExpr & other );
 | 
|---|
| [907eccb] | 625 |         virtual ~UntypedTupleExpr();
 | 
|---|
 | 626 | 
 | 
|---|
 | 627 |         std::list<Expression*>& get_exprs() { return exprs; }
 | 
|---|
 | 628 | 
 | 
|---|
| [5ded739] | 629 |         virtual UntypedTupleExpr * clone() const { return new UntypedTupleExpr( * this ); }
 | 
|---|
 | 630 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 631 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 632 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [907eccb] | 633 |   private:
 | 
|---|
 | 634 |         std::list<Expression*> exprs;
 | 
|---|
 | 635 | };
 | 
|---|
 | 636 | 
 | 
|---|
| [6eb8948] | 637 | /// TupleExpr represents a tuple expression ( [a, b, c] )
 | 
|---|
 | 638 | class TupleExpr : public Expression {
 | 
|---|
 | 639 |   public:
 | 
|---|
| [907eccb] | 640 |         TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
 | 
|---|
| [5ded739] | 641 |         TupleExpr( const TupleExpr & other );
 | 
|---|
| [6eb8948] | 642 |         virtual ~TupleExpr();
 | 
|---|
 | 643 | 
 | 
|---|
 | 644 |         std::list<Expression*>& get_exprs() { return exprs; }
 | 
|---|
 | 645 | 
 | 
|---|
| [5ded739] | 646 |         virtual TupleExpr * clone() const { return new TupleExpr( * this ); }
 | 
|---|
 | 647 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 648 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 649 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [6eb8948] | 650 |   private:
 | 
|---|
 | 651 |         std::list<Expression*> exprs;
 | 
|---|
 | 652 | };
 | 
|---|
 | 653 | 
 | 
|---|
| [3b58d91] | 654 | /// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
 | 
|---|
 | 655 | class TupleIndexExpr : public Expression {
 | 
|---|
 | 656 |   public:
 | 
|---|
 | 657 |         TupleIndexExpr( Expression * tuple, unsigned int index );
 | 
|---|
| [5ded739] | 658 |         TupleIndexExpr( const TupleIndexExpr & other );
 | 
|---|
| [3b58d91] | 659 |         virtual ~TupleIndexExpr();
 | 
|---|
 | 660 | 
 | 
|---|
 | 661 |         Expression * get_tuple() const { return tuple; }
 | 
|---|
 | 662 |         int get_index() const { return index; }
 | 
|---|
| [5ded739] | 663 |         TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; }
 | 
|---|
| [3b58d91] | 664 |         TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
 | 
|---|
 | 665 | 
 | 
|---|
| [5ded739] | 666 |         virtual TupleIndexExpr * clone() const { return new TupleIndexExpr( * this ); }
 | 
|---|
 | 667 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 668 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 669 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [3b58d91] | 670 |   private:
 | 
|---|
 | 671 |         Expression * tuple;
 | 
|---|
 | 672 |         unsigned int index;
 | 
|---|
 | 673 | };
 | 
|---|
 | 674 | 
 | 
|---|
| [65660bd] | 675 | /// 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
 | 
|---|
| [6eb8948] | 676 | class TupleAssignExpr : public Expression {
 | 
|---|
| [3b58d91] | 677 |   public:
 | 
|---|
| [6eb8948] | 678 |         TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
 | 
|---|
| [5ded739] | 679 |         TupleAssignExpr( const TupleAssignExpr & other );
 | 
|---|
| [6eb8948] | 680 |         virtual ~TupleAssignExpr();
 | 
|---|
| [3b58d91] | 681 | 
 | 
|---|
| [d5556a3] | 682 |         TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
 | 
|---|
 | 683 |         StmtExpr * get_stmtExpr() const { return stmtExpr; }
 | 
|---|
| [3b58d91] | 684 | 
 | 
|---|
| [5ded739] | 685 |         virtual TupleAssignExpr * clone() const { return new TupleAssignExpr( * this ); }
 | 
|---|
 | 686 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 687 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 688 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [3b58d91] | 689 |   private:
 | 
|---|
| [d5556a3] | 690 |         StmtExpr * stmtExpr = nullptr;
 | 
|---|
| [3b58d91] | 691 | };
 | 
|---|
 | 692 | 
 | 
|---|
| [6eb8948] | 693 | /// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
 | 
|---|
 | 694 | class StmtExpr : public Expression {
 | 
|---|
 | 695 | public:
 | 
|---|
| [5ded739] | 696 |         StmtExpr( CompoundStmt * statements );
 | 
|---|
| [6eb8948] | 697 |         StmtExpr( const StmtExpr & other );
 | 
|---|
 | 698 |         virtual ~StmtExpr();
 | 
|---|
| [3b58d91] | 699 | 
 | 
|---|
| [6eb8948] | 700 |         CompoundStmt * get_statements() const { return statements; }
 | 
|---|
 | 701 |         StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
 | 
|---|
| [3b58d91] | 702 | 
 | 
|---|
| [d5556a3] | 703 |         std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
 | 
|---|
 | 704 |         std::list< Expression * > & get_dtors() { return dtors; }
 | 
|---|
 | 705 | 
 | 
|---|
| [5ded739] | 706 |         virtual StmtExpr * clone() const { return new StmtExpr( * this ); }
 | 
|---|
 | 707 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 708 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 709 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| [6eb8948] | 710 | private:
 | 
|---|
 | 711 |         CompoundStmt * statements;
 | 
|---|
| [d5556a3] | 712 |         std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
 | 
|---|
 | 713 |         std::list< Expression * > dtors; // destructor(s) for return variable(s)
 | 
|---|
| [3b58d91] | 714 | };
 | 
|---|
 | 715 | 
 | 
|---|
| [3c13c03] | 716 | class UniqueExpr : public Expression {
 | 
|---|
 | 717 | public:
 | 
|---|
| [bf32bb8] | 718 |         UniqueExpr( Expression * expr, long long idVal = -1 );
 | 
|---|
| [3c13c03] | 719 |         UniqueExpr( const UniqueExpr & other );
 | 
|---|
 | 720 |         ~UniqueExpr();
 | 
|---|
 | 721 | 
 | 
|---|
| [141b786] | 722 |         Expression * get_expr() const { return expr; }
 | 
|---|
 | 723 |         UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
 | 
|---|
| [3c13c03] | 724 | 
 | 
|---|
| [141b786] | 725 |         ObjectDecl * get_object() const { return object; }
 | 
|---|
 | 726 |         UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; }
 | 
|---|
 | 727 | 
 | 
|---|
 | 728 |         VariableExpr * get_var() const { return var; }
 | 
|---|
 | 729 |         UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; }
 | 
|---|
| [77971f6] | 730 | 
 | 
|---|
| [bf32bb8] | 731 |         int get_id() const { return id; }
 | 
|---|
 | 732 | 
 | 
|---|
| [5ded739] | 733 |         virtual UniqueExpr * clone() const { return new UniqueExpr( * 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, int indent = 0 ) const;
 | 
|---|
| [3c13c03] | 737 | private:
 | 
|---|
| [141b786] | 738 |         Expression * expr;
 | 
|---|
 | 739 |         ObjectDecl * object;
 | 
|---|
 | 740 |         VariableExpr * var;
 | 
|---|
| [bf32bb8] | 741 |         int id;
 | 
|---|
 | 742 |         static long long count;
 | 
|---|
| [3c13c03] | 743 | };
 | 
|---|
 | 744 | 
 | 
|---|
| [e4d829b] | 745 | struct InitAlternative {
 | 
|---|
 | 746 | public:
 | 
|---|
 | 747 |         Type * type = nullptr;
 | 
|---|
 | 748 |         Designation * designation = nullptr;
 | 
|---|
 | 749 |         InitAlternative( Type * type, Designation * designation );
 | 
|---|
 | 750 |         InitAlternative( const InitAlternative & other );
 | 
|---|
 | 751 |         InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it
 | 
|---|
 | 752 |         ~InitAlternative();
 | 
|---|
 | 753 | };
 | 
|---|
 | 754 | 
 | 
|---|
 | 755 | class UntypedInitExpr : public Expression {
 | 
|---|
 | 756 | public:
 | 
|---|
 | 757 |         UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
 | 
|---|
 | 758 |         UntypedInitExpr( const UntypedInitExpr & other );
 | 
|---|
 | 759 |         ~UntypedInitExpr();
 | 
|---|
 | 760 | 
 | 
|---|
 | 761 |         Expression * get_expr() const { return expr; }
 | 
|---|
 | 762 |         UntypedInitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
 | 
|---|
 | 763 | 
 | 
|---|
 | 764 |         std::list<InitAlternative> & get_initAlts() { return initAlts; }
 | 
|---|
 | 765 | 
 | 
|---|
 | 766 |         virtual UntypedInitExpr * clone() const { return new UntypedInitExpr( * 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, int indent = 0 ) const;
 | 
|---|
 | 770 | private:
 | 
|---|
 | 771 |         Expression * expr;
 | 
|---|
 | 772 |         std::list<InitAlternative> initAlts;
 | 
|---|
 | 773 | };
 | 
|---|
 | 774 | 
 | 
|---|
 | 775 | class InitExpr : public Expression {
 | 
|---|
 | 776 | public:
 | 
|---|
| [62423350] | 777 |         InitExpr( Expression * expr, Designation * designation );
 | 
|---|
| [e4d829b] | 778 |         InitExpr( const InitExpr & other );
 | 
|---|
 | 779 |         ~InitExpr();
 | 
|---|
 | 780 | 
 | 
|---|
 | 781 |         Expression * get_expr() const { return expr; }
 | 
|---|
 | 782 |         InitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
 | 
|---|
 | 783 | 
 | 
|---|
 | 784 |         Designation * get_designation() const { return designation; }
 | 
|---|
 | 785 |         InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; }
 | 
|---|
 | 786 | 
 | 
|---|
 | 787 |         virtual InitExpr * clone() const { return new InitExpr( * this ); }
 | 
|---|
 | 788 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
 | 789 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
 | 790 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
 | 791 | private:
 | 
|---|
 | 792 |         Expression * expr;
 | 
|---|
 | 793 |         Designation * designation;
 | 
|---|
 | 794 | };
 | 
|---|
 | 795 | 
 | 
|---|
 | 796 | 
 | 
|---|
| [3906301] | 797 | std::ostream & operator<<( std::ostream & out, const Expression * expr );
 | 
|---|
| [baf7fee] | 798 | 
 | 
|---|
| [0dd3a2f] | 799 | // Local Variables: //
 | 
|---|
 | 800 | // tab-width: 4 //
 | 
|---|
 | 801 | // mode: c++ //
 | 
|---|
 | 802 | // compile-command: "make install" //
 | 
|---|
 | 803 | // End: //
 | 
|---|