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