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