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