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