[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 | |
---|
[bbf17d5] | 165 | // [Qualifier].name; Qualifier is the type_name from the parser |
---|
| 166 | class QualifiedNameExpr : public Expression { |
---|
| 167 | public: |
---|
[b0d9ff7] | 168 | Declaration * type_decl; |
---|
| 169 | std::string name; |
---|
| 170 | DeclarationWithType * var; |
---|
[bbf17d5] | 171 | |
---|
[b0d9ff7] | 172 | QualifiedNameExpr( Declaration * decl, std::string name): Expression(), type_decl(decl), name(name) {} |
---|
| 173 | QualifiedNameExpr( const QualifiedNameExpr & other): Expression(other), type_decl(other.type_decl), name(other.name), var(other.var) {} |
---|
| 174 | DeclarationWithType * get_var() const { return var; } |
---|
| 175 | void set_var( DeclarationWithType * newValue ) { var = newValue; } |
---|
[bbf17d5] | 176 | |
---|
| 177 | virtual ~QualifiedNameExpr() { |
---|
[b0d9ff7] | 178 | delete var; |
---|
| 179 | delete type_decl; |
---|
[bbf17d5] | 180 | } |
---|
| 181 | |
---|
| 182 | virtual QualifiedNameExpr * clone() const override { |
---|
| 183 | return new QualifiedNameExpr( * this ); |
---|
| 184 | } |
---|
[b0d9ff7] | 185 | virtual void accept( Visitor & v ) override { v.visit(this); } |
---|
| 186 | virtual void accept( Visitor & v ) const override { v.visit(this); } |
---|
| 187 | virtual Expression * acceptMutator( Mutator & m ) override { |
---|
| 188 | return m.mutate( this ); |
---|
| 189 | } |
---|
| 190 | |
---|
[bbf17d5] | 191 | virtual void print( std::ostream & os, Indenter indent = {} ) const override { |
---|
[b0d9ff7] | 192 | type_decl->print( os, indent ); |
---|
| 193 | os << name << std::endl; |
---|
[bbf17d5] | 194 | } |
---|
| 195 | }; |
---|
| 196 | |
---|
[d5631b3] | 197 | /// VariableExpr represents an expression that simply refers to the value of a named variable. |
---|
| 198 | /// Does not take ownership of var. |
---|
| 199 | class VariableExpr : public Expression { |
---|
| 200 | public: |
---|
| 201 | DeclarationWithType * var; |
---|
| 202 | |
---|
| 203 | VariableExpr(); |
---|
| 204 | VariableExpr( DeclarationWithType * var ); |
---|
| 205 | VariableExpr( const VariableExpr & other ); |
---|
| 206 | virtual ~VariableExpr(); |
---|
| 207 | |
---|
| 208 | bool get_lvalue() const final; |
---|
| 209 | |
---|
| 210 | DeclarationWithType * get_var() const { return var; } |
---|
| 211 | void set_var( DeclarationWithType * newValue ) { var = newValue; } |
---|
| 212 | |
---|
| 213 | static VariableExpr * functionPointer( FunctionDecl * decl ); |
---|
| 214 | |
---|
| 215 | virtual VariableExpr * clone() const override { return new VariableExpr( * this ); } |
---|
| 216 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 217 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 218 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 219 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 220 | }; |
---|
| 221 | |
---|
[51b7345] | 222 | // The following classes are used to represent expression types that cannot be converted into |
---|
| 223 | // function-call format. |
---|
| 224 | |
---|
[5ded739] | 225 | /// AddressExpr represents a address-of expression, e.g. & e |
---|
[0dd3a2f] | 226 | class AddressExpr : public Expression { |
---|
| 227 | public: |
---|
[65cdc1e] | 228 | Expression * arg; |
---|
| 229 | |
---|
[bf4b4cf] | 230 | AddressExpr( Expression * arg ); |
---|
[5ded739] | 231 | AddressExpr( const AddressExpr & other ); |
---|
[0dd3a2f] | 232 | virtual ~AddressExpr(); |
---|
| 233 | |
---|
[5ded739] | 234 | Expression * get_arg() const { return arg; } |
---|
| 235 | void set_arg(Expression * newValue ) { arg = newValue; } |
---|
[0dd3a2f] | 236 | |
---|
[7870799] | 237 | virtual AddressExpr * clone() const override { return new AddressExpr( * this ); } |
---|
| 238 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 239 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 240 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 241 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 242 | }; |
---|
| 243 | |
---|
[5809461] | 244 | // GCC &&label |
---|
| 245 | // https://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Labels-as-Values.html |
---|
[0dd3a2f] | 246 | class LabelAddressExpr : public Expression { |
---|
| 247 | public: |
---|
[5809461] | 248 | Label arg; |
---|
[65cdc1e] | 249 | |
---|
[5809461] | 250 | LabelAddressExpr( const Label &arg ); |
---|
[5ded739] | 251 | LabelAddressExpr( const LabelAddressExpr & other ); |
---|
[0dd3a2f] | 252 | virtual ~LabelAddressExpr(); |
---|
| 253 | |
---|
[7870799] | 254 | virtual LabelAddressExpr * clone() const override { return new LabelAddressExpr( * this ); } |
---|
| 255 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 256 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 257 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 258 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 259 | }; |
---|
| 260 | |
---|
[47534159] | 261 | /// CastExpr represents a type cast expression, e.g. (int)e |
---|
[0dd3a2f] | 262 | class CastExpr : public Expression { |
---|
| 263 | public: |
---|
[65cdc1e] | 264 | Expression * arg; |
---|
[b81fd95] | 265 | |
---|
| 266 | // Inidicates cast is introduced by the CFA type system. |
---|
| 267 | // true for casts that the resolver introduces to force a return type |
---|
| 268 | // false for casts from user code |
---|
| 269 | // false for casts from desugaring advanced CFA features into simpler CFA |
---|
| 270 | // example |
---|
| 271 | // int * p; // declaration |
---|
| 272 | // (float *) p; // use, with subject cast |
---|
| 273 | // subject cast isGenerated means we are considering an interpretation with a type mismatch |
---|
| 274 | // subject cast not isGenerated means someone in charge wants it that way |
---|
| 275 | bool isGenerated = true; |
---|
[65cdc1e] | 276 | |
---|
[c0bf94e] | 277 | CastExpr( Expression * arg, bool isGenerated = true ); |
---|
| 278 | CastExpr( Expression * arg, Type * toType, bool isGenerated = true ); |
---|
[9a705dc8] | 279 | CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor |
---|
[5ded739] | 280 | CastExpr( const CastExpr & other ); |
---|
[0dd3a2f] | 281 | virtual ~CastExpr(); |
---|
| 282 | |
---|
[14388c1] | 283 | bool get_lvalue() const final; |
---|
| 284 | |
---|
[5ded739] | 285 | Expression * get_arg() const { return arg; } |
---|
[a5f0529] | 286 | void set_arg( Expression * newValue ) { arg = newValue; } |
---|
[0dd3a2f] | 287 | |
---|
[7870799] | 288 | virtual CastExpr * clone() const override { return new CastExpr( * 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 | |
---|
[9a705dc8] | 295 | /// KeywordCastExpr represents a cast to 'keyword types', e.g. (thread &)t |
---|
| 296 | class KeywordCastExpr : public Expression { |
---|
| 297 | public: |
---|
| 298 | Expression * arg; |
---|
[3b0c8cb] | 299 | struct Concrete { |
---|
| 300 | std::string field; |
---|
| 301 | std::string getter; |
---|
| 302 | }; |
---|
[312029a] | 303 | AggregateDecl::Aggregate target; |
---|
[3b0c8cb] | 304 | Concrete concrete_target; |
---|
[9a705dc8] | 305 | |
---|
[312029a] | 306 | KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target ); |
---|
[4ef08f7] | 307 | KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target, const Concrete & concrete_target ); |
---|
[9a705dc8] | 308 | KeywordCastExpr( const KeywordCastExpr & other ); |
---|
| 309 | virtual ~KeywordCastExpr(); |
---|
| 310 | |
---|
[312029a] | 311 | const char * targetString() const; |
---|
[9a705dc8] | 312 | |
---|
[7870799] | 313 | virtual KeywordCastExpr * clone() const override { return new KeywordCastExpr( * 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; |
---|
[9a705dc8] | 318 | }; |
---|
| 319 | |
---|
[a5f0529] | 320 | /// VirtualCastExpr repersents a virtual dynamic cast, e.g. (virtual exception)e |
---|
| 321 | class VirtualCastExpr : public Expression { |
---|
| 322 | public: |
---|
[5ded739] | 323 | Expression * arg; |
---|
[65cdc1e] | 324 | |
---|
[a5f0529] | 325 | VirtualCastExpr( Expression * arg, Type * toType ); |
---|
| 326 | VirtualCastExpr( const VirtualCastExpr & other ); |
---|
| 327 | virtual ~VirtualCastExpr(); |
---|
| 328 | |
---|
| 329 | Expression * get_arg() const { return arg; } |
---|
| 330 | void set_arg( Expression * newValue ) { arg = newValue; } |
---|
| 331 | |
---|
[7870799] | 332 | virtual VirtualCastExpr * clone() const override { return new VirtualCastExpr( * this ); } |
---|
| 333 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 334 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 335 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 336 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 337 | }; |
---|
| 338 | |
---|
[47534159] | 339 | /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer |
---|
[0dd3a2f] | 340 | class UntypedMemberExpr : public Expression { |
---|
| 341 | public: |
---|
[65cdc1e] | 342 | Expression * member; |
---|
| 343 | Expression * aggregate; |
---|
| 344 | |
---|
[bf4b4cf] | 345 | UntypedMemberExpr( Expression * member, Expression * aggregate ); |
---|
[5ded739] | 346 | UntypedMemberExpr( const UntypedMemberExpr & other ); |
---|
[0dd3a2f] | 347 | virtual ~UntypedMemberExpr(); |
---|
| 348 | |
---|
[849720f] | 349 | bool get_lvalue() const final; |
---|
| 350 | |
---|
[3b58d91] | 351 | Expression * get_member() const { return member; } |
---|
| 352 | void set_member( Expression * newValue ) { member = newValue; } |
---|
[5ded739] | 353 | Expression * get_aggregate() const { return aggregate; } |
---|
| 354 | void set_aggregate( Expression * newValue ) { aggregate = newValue; } |
---|
[0dd3a2f] | 355 | |
---|
[7870799] | 356 | virtual UntypedMemberExpr * clone() const override { return new UntypedMemberExpr( * this ); } |
---|
| 357 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 358 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 359 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 360 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 361 | }; |
---|
| 362 | |
---|
[4551a6e] | 363 | /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer. |
---|
| 364 | /// Does not take ownership of member. |
---|
[0dd3a2f] | 365 | class MemberExpr : public Expression { |
---|
| 366 | public: |
---|
[65cdc1e] | 367 | DeclarationWithType * member; |
---|
| 368 | Expression * aggregate; |
---|
| 369 | |
---|
[bf4b4cf] | 370 | MemberExpr( DeclarationWithType * member, Expression * aggregate ); |
---|
[5ded739] | 371 | MemberExpr( const MemberExpr & other ); |
---|
[0dd3a2f] | 372 | virtual ~MemberExpr(); |
---|
| 373 | |
---|
[14388c1] | 374 | bool get_lvalue() const final; |
---|
| 375 | |
---|
[5ded739] | 376 | DeclarationWithType * get_member() const { return member; } |
---|
| 377 | void set_member( DeclarationWithType * newValue ) { member = newValue; } |
---|
| 378 | Expression * get_aggregate() const { return aggregate; } |
---|
| 379 | void set_aggregate( Expression * newValue ) { aggregate = newValue; } |
---|
[0dd3a2f] | 380 | |
---|
[7870799] | 381 | virtual MemberExpr * clone() const override { return new MemberExpr( * this ); } |
---|
| 382 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 383 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 384 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 385 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 386 | }; |
---|
| 387 | |
---|
[3be261a] | 388 | /// ConstantExpr represents an expression that simply refers to the value of a constant |
---|
[0dd3a2f] | 389 | class ConstantExpr : public Expression { |
---|
| 390 | public: |
---|
[65cdc1e] | 391 | Constant constant; |
---|
| 392 | |
---|
[bf4b4cf] | 393 | ConstantExpr( Constant constant ); |
---|
[5ded739] | 394 | ConstantExpr( const ConstantExpr & other ); |
---|
[0dd3a2f] | 395 | virtual ~ConstantExpr(); |
---|
| 396 | |
---|
[5ded739] | 397 | Constant * get_constant() { return & constant; } |
---|
[ddb80bd] | 398 | const Constant * get_constant() const { return & constant; } |
---|
[5ded739] | 399 | void set_constant( const Constant & newValue ) { constant = newValue; } |
---|
[0dd3a2f] | 400 | |
---|
[ddb80bd] | 401 | long long int intValue() const; |
---|
| 402 | |
---|
[7870799] | 403 | virtual ConstantExpr * clone() const override { return new ConstantExpr( * this ); } |
---|
| 404 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 405 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 406 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 407 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 408 | }; |
---|
| 409 | |
---|
[47534159] | 410 | /// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4) |
---|
[0dd3a2f] | 411 | class SizeofExpr : public Expression { |
---|
| 412 | public: |
---|
[65cdc1e] | 413 | Expression * expr; |
---|
| 414 | Type * type; |
---|
| 415 | bool isType; |
---|
| 416 | |
---|
[bf4b4cf] | 417 | SizeofExpr( Expression * expr ); |
---|
[5ded739] | 418 | SizeofExpr( const SizeofExpr & other ); |
---|
[bf4b4cf] | 419 | SizeofExpr( Type * type ); |
---|
[0dd3a2f] | 420 | virtual ~SizeofExpr(); |
---|
| 421 | |
---|
[5ded739] | 422 | Expression * get_expr() const { return expr; } |
---|
| 423 | void set_expr( Expression * newValue ) { expr = newValue; } |
---|
| 424 | Type * get_type() const { return type; } |
---|
| 425 | void set_type( Type * newValue ) { type = newValue; } |
---|
[0dd3a2f] | 426 | bool get_isType() const { return isType; } |
---|
| 427 | void set_isType( bool newValue ) { isType = newValue; } |
---|
| 428 | |
---|
[7870799] | 429 | virtual SizeofExpr * clone() const override { return new SizeofExpr( * this ); } |
---|
| 430 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 431 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 432 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 433 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 434 | }; |
---|
| 435 | |
---|
[47534159] | 436 | /// AlignofExpr represents an alignof expression |
---|
| 437 | class AlignofExpr : public Expression { |
---|
| 438 | public: |
---|
[65cdc1e] | 439 | Expression * expr; |
---|
| 440 | Type * type; |
---|
| 441 | bool isType; |
---|
| 442 | |
---|
[bf4b4cf] | 443 | AlignofExpr( Expression * expr ); |
---|
[5ded739] | 444 | AlignofExpr( const AlignofExpr & other ); |
---|
[bf4b4cf] | 445 | AlignofExpr( Type * type ); |
---|
[47534159] | 446 | virtual ~AlignofExpr(); |
---|
| 447 | |
---|
[5ded739] | 448 | Expression * get_expr() const { return expr; } |
---|
| 449 | void set_expr( Expression * newValue ) { expr = newValue; } |
---|
| 450 | Type * get_type() const { return type; } |
---|
| 451 | void set_type( Type * newValue ) { type = newValue; } |
---|
[47534159] | 452 | bool get_isType() const { return isType; } |
---|
| 453 | void set_isType( bool newValue ) { isType = newValue; } |
---|
| 454 | |
---|
[7870799] | 455 | virtual AlignofExpr * clone() const override { return new AlignofExpr( * this ); } |
---|
| 456 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 457 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 458 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 459 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[47534159] | 460 | }; |
---|
| 461 | |
---|
[2a4b088] | 462 | /// UntypedOffsetofExpr represents an offsetof expression before resolution |
---|
| 463 | class UntypedOffsetofExpr : public Expression { |
---|
| 464 | public: |
---|
[65cdc1e] | 465 | Type * type; |
---|
| 466 | std::string member; |
---|
| 467 | |
---|
[bf4b4cf] | 468 | UntypedOffsetofExpr( Type * type, const std::string & member ); |
---|
[5ded739] | 469 | UntypedOffsetofExpr( const UntypedOffsetofExpr & other ); |
---|
[2a4b088] | 470 | virtual ~UntypedOffsetofExpr(); |
---|
| 471 | |
---|
| 472 | std::string get_member() const { return member; } |
---|
[5ded739] | 473 | void set_member( const std::string & newValue ) { member = newValue; } |
---|
| 474 | Type * get_type() const { return type; } |
---|
| 475 | void set_type( Type * newValue ) { type = newValue; } |
---|
| 476 | |
---|
[7870799] | 477 | virtual UntypedOffsetofExpr * clone() const override { return new UntypedOffsetofExpr( * this ); } |
---|
| 478 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 479 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 480 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 481 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[2a4b088] | 482 | }; |
---|
| 483 | |
---|
[25a054f] | 484 | /// OffsetofExpr represents an offsetof expression |
---|
| 485 | class OffsetofExpr : public Expression { |
---|
| 486 | public: |
---|
[65cdc1e] | 487 | Type * type; |
---|
| 488 | DeclarationWithType * member; |
---|
| 489 | |
---|
[bf4b4cf] | 490 | OffsetofExpr( Type * type, DeclarationWithType * member ); |
---|
[5ded739] | 491 | OffsetofExpr( const OffsetofExpr & other ); |
---|
[25a054f] | 492 | virtual ~OffsetofExpr(); |
---|
| 493 | |
---|
[5ded739] | 494 | Type * get_type() const { return type; } |
---|
| 495 | void set_type( Type * newValue ) { type = newValue; } |
---|
| 496 | DeclarationWithType * get_member() const { return member; } |
---|
| 497 | void set_member( DeclarationWithType * newValue ) { member = newValue; } |
---|
| 498 | |
---|
[7870799] | 499 | virtual OffsetofExpr * clone() const override { return new OffsetofExpr( * this ); } |
---|
| 500 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 501 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 502 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 503 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[25a054f] | 504 | }; |
---|
| 505 | |
---|
[afc1045] | 506 | /// Expression representing a pack of field-offsets for a generic type |
---|
| 507 | class OffsetPackExpr : public Expression { |
---|
| 508 | public: |
---|
[65cdc1e] | 509 | StructInstType * type; |
---|
| 510 | |
---|
[bf4b4cf] | 511 | OffsetPackExpr( StructInstType * type ); |
---|
[5ded739] | 512 | OffsetPackExpr( const OffsetPackExpr & other ); |
---|
[afc1045] | 513 | virtual ~OffsetPackExpr(); |
---|
| 514 | |
---|
[5ded739] | 515 | StructInstType * get_type() const { return type; } |
---|
| 516 | void set_type( StructInstType * newValue ) { type = newValue; } |
---|
[afc1045] | 517 | |
---|
[7870799] | 518 | virtual OffsetPackExpr * clone() const override { return new OffsetPackExpr( * this ); } |
---|
| 519 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 520 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 521 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 522 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[afc1045] | 523 | }; |
---|
| 524 | |
---|
[47534159] | 525 | /// LogicalExpr represents a short-circuit boolean expression (&& or ||) |
---|
[0dd3a2f] | 526 | class LogicalExpr : public Expression { |
---|
| 527 | public: |
---|
[65cdc1e] | 528 | Expression * arg1; |
---|
| 529 | Expression * arg2; |
---|
| 530 | |
---|
[bf4b4cf] | 531 | LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true ); |
---|
[5ded739] | 532 | LogicalExpr( const LogicalExpr & other ); |
---|
[0dd3a2f] | 533 | virtual ~LogicalExpr(); |
---|
| 534 | |
---|
| 535 | bool get_isAnd() const { return isAnd; } |
---|
[5ded739] | 536 | Expression * get_arg1() { return arg1; } |
---|
| 537 | void set_arg1( Expression * newValue ) { arg1 = newValue; } |
---|
| 538 | Expression * get_arg2() const { return arg2; } |
---|
| 539 | void set_arg2( Expression * newValue ) { arg2 = newValue; } |
---|
| 540 | |
---|
[7870799] | 541 | virtual LogicalExpr * clone() const override { return new LogicalExpr( * this ); } |
---|
| 542 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 543 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 544 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 545 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[65cdc1e] | 546 | |
---|
[0dd3a2f] | 547 | private: |
---|
| 548 | bool isAnd; |
---|
[51b7345] | 549 | }; |
---|
| 550 | |
---|
[47534159] | 551 | /// ConditionalExpr represents the three-argument conditional ( p ? a : b ) |
---|
[0dd3a2f] | 552 | class ConditionalExpr : public Expression { |
---|
| 553 | public: |
---|
[65cdc1e] | 554 | Expression * arg1; |
---|
| 555 | Expression * arg2; |
---|
| 556 | Expression * arg3; |
---|
| 557 | |
---|
[bf4b4cf] | 558 | ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 ); |
---|
[5ded739] | 559 | ConditionalExpr( const ConditionalExpr & other ); |
---|
[0dd3a2f] | 560 | virtual ~ConditionalExpr(); |
---|
| 561 | |
---|
[14388c1] | 562 | bool get_lvalue() const final; |
---|
| 563 | |
---|
[5ded739] | 564 | Expression * get_arg1() const { return arg1; } |
---|
| 565 | void set_arg1( Expression * newValue ) { arg1 = newValue; } |
---|
| 566 | Expression * get_arg2() const { return arg2; } |
---|
| 567 | void set_arg2( Expression * newValue ) { arg2 = newValue; } |
---|
| 568 | Expression * get_arg3() const { return arg3; } |
---|
| 569 | void set_arg3( Expression * newValue ) { arg3 = newValue; } |
---|
| 570 | |
---|
[7870799] | 571 | virtual ConditionalExpr * clone() const override { return new ConditionalExpr( * 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 | /// CommaExpr represents the sequence operator ( a, b ) |
---|
[0dd3a2f] | 579 | class CommaExpr : public Expression { |
---|
| 580 | public: |
---|
[65cdc1e] | 581 | Expression * arg1; |
---|
| 582 | Expression * arg2; |
---|
| 583 | |
---|
[bf4b4cf] | 584 | CommaExpr( Expression * arg1, Expression * arg2 ); |
---|
[5ded739] | 585 | CommaExpr( const CommaExpr & other ); |
---|
[0dd3a2f] | 586 | virtual ~CommaExpr(); |
---|
| 587 | |
---|
[14388c1] | 588 | bool get_lvalue() const final; |
---|
| 589 | |
---|
[5ded739] | 590 | Expression * get_arg1() const { return arg1; } |
---|
| 591 | void set_arg1( Expression * newValue ) { arg1 = newValue; } |
---|
| 592 | Expression * get_arg2() const { return arg2; } |
---|
| 593 | void set_arg2( Expression * newValue ) { arg2 = newValue; } |
---|
[0dd3a2f] | 594 | |
---|
[7870799] | 595 | virtual CommaExpr * clone() const override { return new CommaExpr( * this ); } |
---|
| 596 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 597 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 598 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 599 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 600 | }; |
---|
| 601 | |
---|
[47534159] | 602 | /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter) |
---|
[0dd3a2f] | 603 | class TypeExpr : public Expression { |
---|
| 604 | public: |
---|
[65cdc1e] | 605 | Type * type; |
---|
| 606 | |
---|
[5ded739] | 607 | TypeExpr( Type * type ); |
---|
| 608 | TypeExpr( const TypeExpr & other ); |
---|
[0dd3a2f] | 609 | virtual ~TypeExpr(); |
---|
| 610 | |
---|
[5ded739] | 611 | Type * get_type() const { return type; } |
---|
| 612 | void set_type( Type * newValue ) { type = newValue; } |
---|
[0dd3a2f] | 613 | |
---|
[7870799] | 614 | virtual TypeExpr * clone() const override { return new TypeExpr( * this ); } |
---|
| 615 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 616 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 617 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
[6e50a6b] | 618 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 619 | }; |
---|
| 620 | |
---|
| 621 | /// DimensionExpr represents a type-system provided value used in an expression ( forrall([N]) ... N + 1 ) |
---|
| 622 | class DimensionExpr : public Expression { |
---|
| 623 | public: |
---|
| 624 | std::string name; |
---|
| 625 | |
---|
| 626 | DimensionExpr( std::string name ); |
---|
| 627 | DimensionExpr( const DimensionExpr & other ); |
---|
| 628 | virtual ~DimensionExpr(); |
---|
| 629 | |
---|
| 630 | const std::string & get_name() const { return name; } |
---|
| 631 | void set_name( std::string newValue ) { name = newValue; } |
---|
| 632 | |
---|
| 633 | virtual DimensionExpr * clone() const override { return new DimensionExpr( * this ); } |
---|
| 634 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 635 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 636 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
[7870799] | 637 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 638 | }; |
---|
| 639 | |
---|
[47534159] | 640 | /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result) |
---|
[7f5566b] | 641 | class AsmExpr : public Expression { |
---|
| 642 | public: |
---|
[665f432] | 643 | std::string inout; |
---|
[e612146c] | 644 | Expression * constraint; |
---|
[65cdc1e] | 645 | Expression * operand; |
---|
| 646 | |
---|
[665f432] | 647 | AsmExpr( const std::string * _inout, Expression * constraint, Expression * operand ) : inout( _inout ? *_inout : "" ), constraint( constraint ), operand( operand ) { delete _inout; } |
---|
[3be261a] | 648 | AsmExpr( const AsmExpr & other ); |
---|
[665f432] | 649 | virtual ~AsmExpr() { delete constraint; delete operand; }; |
---|
[7f5566b] | 650 | |
---|
[7870799] | 651 | virtual AsmExpr * clone() const override { return new AsmExpr( * this ); } |
---|
| 652 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 653 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 654 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 655 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[65cdc1e] | 656 | |
---|
[7f5566b] | 657 | // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints |
---|
| 658 | }; |
---|
| 659 | |
---|
[db4ecc5] | 660 | /// ImplicitCopyCtorExpr represents the application of a function to a set of parameters, |
---|
| 661 | /// along with a set of copy constructor calls, one for each argument. |
---|
| 662 | class ImplicitCopyCtorExpr : public Expression { |
---|
| 663 | public: |
---|
[2f86ddf] | 664 | ApplicationExpr * callExpr = nullptr; |
---|
[65cdc1e] | 665 | |
---|
[db4ecc5] | 666 | ImplicitCopyCtorExpr( ApplicationExpr * callExpr ); |
---|
| 667 | ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ); |
---|
| 668 | virtual ~ImplicitCopyCtorExpr(); |
---|
| 669 | |
---|
[7870799] | 670 | virtual ImplicitCopyCtorExpr * clone() const override { return new ImplicitCopyCtorExpr( * 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; |
---|
[db4ecc5] | 675 | }; |
---|
| 676 | |
---|
[b6fe7e6] | 677 | /// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 }; |
---|
| 678 | class ConstructorExpr : public Expression { |
---|
| 679 | public: |
---|
[65cdc1e] | 680 | Expression * callExpr; |
---|
| 681 | |
---|
[b6fe7e6] | 682 | ConstructorExpr( Expression * callExpr ); |
---|
| 683 | ConstructorExpr( const ConstructorExpr & other ); |
---|
| 684 | ~ConstructorExpr(); |
---|
[0dd3a2f] | 685 | |
---|
[14388c1] | 686 | bool get_lvalue() const final; |
---|
| 687 | |
---|
[5ded739] | 688 | Expression * get_callExpr() const { return callExpr; } |
---|
| 689 | void set_callExpr( Expression * newValue ) { callExpr = newValue; } |
---|
[0dd3a2f] | 690 | |
---|
[7870799] | 691 | virtual ConstructorExpr * clone() const override { return new ConstructorExpr( * this ); } |
---|
| 692 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 693 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 694 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 695 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 696 | }; |
---|
| 697 | |
---|
[630a82a] | 698 | /// CompoundLiteralExpr represents a C99 'compound literal' |
---|
| 699 | class CompoundLiteralExpr : public Expression { |
---|
| 700 | public: |
---|
[65cdc1e] | 701 | Initializer * initializer; |
---|
| 702 | |
---|
[630a82a] | 703 | CompoundLiteralExpr( Type * type, Initializer * initializer ); |
---|
[5ded739] | 704 | CompoundLiteralExpr( const CompoundLiteralExpr & other ); |
---|
[3b58d91] | 705 | virtual ~CompoundLiteralExpr(); |
---|
[630a82a] | 706 | |
---|
[14388c1] | 707 | bool get_lvalue() const final; |
---|
| 708 | |
---|
[630a82a] | 709 | Initializer * get_initializer() const { return initializer; } |
---|
| 710 | void set_initializer( Initializer * i ) { initializer = i; } |
---|
| 711 | |
---|
[7870799] | 712 | virtual CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr( * 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; |
---|
[630a82a] | 717 | }; |
---|
| 718 | |
---|
[b6fe7e6] | 719 | /// RangeExpr represents a range e.g. '3 ... 5' or '1~10' |
---|
[8688ce1] | 720 | class RangeExpr : public Expression { |
---|
| 721 | public: |
---|
[65cdc1e] | 722 | Expression * low, * high; |
---|
| 723 | |
---|
[5ded739] | 724 | RangeExpr( Expression * low, Expression * high ); |
---|
| 725 | RangeExpr( const RangeExpr & other ); |
---|
[8688ce1] | 726 | |
---|
[d9e2280] | 727 | Expression * get_low() const { return low; } |
---|
| 728 | Expression * get_high() const { return high; } |
---|
[5ded739] | 729 | RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; } |
---|
| 730 | RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; } |
---|
[8688ce1] | 731 | |
---|
[7870799] | 732 | virtual RangeExpr * clone() const override { return new RangeExpr( * 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; |
---|
[8688ce1] | 737 | }; |
---|
| 738 | |
---|
[907eccb] | 739 | /// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution |
---|
| 740 | class UntypedTupleExpr : public Expression { |
---|
| 741 | public: |
---|
[65cdc1e] | 742 | std::list<Expression*> exprs; |
---|
| 743 | |
---|
[bf4b4cf] | 744 | UntypedTupleExpr( const std::list< Expression * > & exprs ); |
---|
[5ded739] | 745 | UntypedTupleExpr( const UntypedTupleExpr & other ); |
---|
[907eccb] | 746 | virtual ~UntypedTupleExpr(); |
---|
| 747 | |
---|
| 748 | std::list<Expression*>& get_exprs() { return exprs; } |
---|
| 749 | |
---|
[7870799] | 750 | virtual UntypedTupleExpr * clone() const override { return new UntypedTupleExpr( * this ); } |
---|
| 751 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 752 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 753 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 754 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[907eccb] | 755 | }; |
---|
| 756 | |
---|
[6eb8948] | 757 | /// TupleExpr represents a tuple expression ( [a, b, c] ) |
---|
| 758 | class TupleExpr : public Expression { |
---|
| 759 | public: |
---|
[65cdc1e] | 760 | std::list<Expression*> exprs; |
---|
| 761 | |
---|
[bf4b4cf] | 762 | TupleExpr( const std::list< Expression * > & exprs ); |
---|
[5ded739] | 763 | TupleExpr( const TupleExpr & other ); |
---|
[6eb8948] | 764 | virtual ~TupleExpr(); |
---|
| 765 | |
---|
[3c7f01b] | 766 | bool get_lvalue() const final; |
---|
| 767 | |
---|
[6eb8948] | 768 | std::list<Expression*>& get_exprs() { return exprs; } |
---|
| 769 | |
---|
[7870799] | 770 | virtual TupleExpr * clone() const override { return new TupleExpr( * this ); } |
---|
| 771 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 772 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 773 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 774 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[6eb8948] | 775 | }; |
---|
| 776 | |
---|
[3b58d91] | 777 | /// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer |
---|
| 778 | class TupleIndexExpr : public Expression { |
---|
| 779 | public: |
---|
[65cdc1e] | 780 | Expression * tuple; |
---|
| 781 | unsigned int index; |
---|
| 782 | |
---|
[3b58d91] | 783 | TupleIndexExpr( Expression * tuple, unsigned int index ); |
---|
[5ded739] | 784 | TupleIndexExpr( const TupleIndexExpr & other ); |
---|
[3b58d91] | 785 | virtual ~TupleIndexExpr(); |
---|
| 786 | |
---|
[14388c1] | 787 | bool get_lvalue() const final; |
---|
| 788 | |
---|
[3b58d91] | 789 | Expression * get_tuple() const { return tuple; } |
---|
| 790 | int get_index() const { return index; } |
---|
[5ded739] | 791 | TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; } |
---|
[3b58d91] | 792 | TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; } |
---|
| 793 | |
---|
[7870799] | 794 | virtual TupleIndexExpr * clone() const override { return new TupleIndexExpr( * this ); } |
---|
| 795 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 796 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 797 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 798 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[3b58d91] | 799 | }; |
---|
| 800 | |
---|
[65660bd] | 801 | /// 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] | 802 | class TupleAssignExpr : public Expression { |
---|
[3b58d91] | 803 | public: |
---|
[65cdc1e] | 804 | StmtExpr * stmtExpr = nullptr; |
---|
| 805 | |
---|
[bf4b4cf] | 806 | TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls ); |
---|
[5ded739] | 807 | TupleAssignExpr( const TupleAssignExpr & other ); |
---|
[6eb8948] | 808 | virtual ~TupleAssignExpr(); |
---|
[3b58d91] | 809 | |
---|
[d5556a3] | 810 | TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; } |
---|
| 811 | StmtExpr * get_stmtExpr() const { return stmtExpr; } |
---|
[3b58d91] | 812 | |
---|
[7870799] | 813 | virtual TupleAssignExpr * clone() const override { return new TupleAssignExpr( * this ); } |
---|
| 814 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 815 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 816 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 817 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[20de6fb] | 818 | |
---|
| 819 | friend class ConverterNewToOld; |
---|
| 820 | private: |
---|
| 821 | TupleAssignExpr( StmtExpr * stmts ); |
---|
[3b58d91] | 822 | }; |
---|
| 823 | |
---|
[6eb8948] | 824 | /// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; }) |
---|
| 825 | class StmtExpr : public Expression { |
---|
| 826 | public: |
---|
[65cdc1e] | 827 | CompoundStmt * statements; |
---|
| 828 | std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression |
---|
| 829 | std::list< Expression * > dtors; // destructor(s) for return variable(s) |
---|
| 830 | |
---|
[0e315a5] | 831 | // readonly |
---|
| 832 | ExprStmt * resultExpr = nullptr; |
---|
| 833 | |
---|
[5ded739] | 834 | StmtExpr( CompoundStmt * statements ); |
---|
[6eb8948] | 835 | StmtExpr( const StmtExpr & other ); |
---|
| 836 | virtual ~StmtExpr(); |
---|
[3b58d91] | 837 | |
---|
[5d00425] | 838 | bool get_lvalue() const final; |
---|
| 839 | |
---|
[6eb8948] | 840 | CompoundStmt * get_statements() const { return statements; } |
---|
| 841 | StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; } |
---|
[3b58d91] | 842 | |
---|
[5e2c348] | 843 | // call to set the result type of this StmtExpr based on its body |
---|
| 844 | void computeResult(); |
---|
| 845 | |
---|
[d5556a3] | 846 | std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; } |
---|
| 847 | std::list< Expression * > & get_dtors() { return dtors; } |
---|
| 848 | |
---|
[7870799] | 849 | virtual StmtExpr * clone() const override { return new StmtExpr( * this ); } |
---|
| 850 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 851 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 852 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 853 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[3b58d91] | 854 | }; |
---|
| 855 | |
---|
[3c13c03] | 856 | class UniqueExpr : public Expression { |
---|
| 857 | public: |
---|
[65cdc1e] | 858 | Expression * expr; |
---|
| 859 | ObjectDecl * object; |
---|
| 860 | VariableExpr * var; |
---|
| 861 | |
---|
[bf32bb8] | 862 | UniqueExpr( Expression * expr, long long idVal = -1 ); |
---|
[3c13c03] | 863 | UniqueExpr( const UniqueExpr & other ); |
---|
| 864 | ~UniqueExpr(); |
---|
| 865 | |
---|
[141b786] | 866 | Expression * get_expr() const { return expr; } |
---|
| 867 | UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; } |
---|
[3c13c03] | 868 | |
---|
[141b786] | 869 | ObjectDecl * get_object() const { return object; } |
---|
| 870 | UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; } |
---|
| 871 | |
---|
| 872 | VariableExpr * get_var() const { return var; } |
---|
| 873 | UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; } |
---|
[77971f6] | 874 | |
---|
[bf32bb8] | 875 | int get_id() const { return id; } |
---|
| 876 | |
---|
[7870799] | 877 | virtual UniqueExpr * clone() const override { return new UniqueExpr( * this ); } |
---|
| 878 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 879 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 880 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 881 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[65cdc1e] | 882 | |
---|
[3c13c03] | 883 | private: |
---|
[bf32bb8] | 884 | int id; |
---|
| 885 | static long long count; |
---|
[3c13c03] | 886 | }; |
---|
| 887 | |
---|
[e4d829b] | 888 | struct InitAlternative { |
---|
| 889 | public: |
---|
| 890 | Type * type = nullptr; |
---|
| 891 | Designation * designation = nullptr; |
---|
| 892 | InitAlternative( Type * type, Designation * designation ); |
---|
| 893 | InitAlternative( const InitAlternative & other ); |
---|
| 894 | InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it |
---|
| 895 | ~InitAlternative(); |
---|
| 896 | }; |
---|
| 897 | |
---|
| 898 | class UntypedInitExpr : public Expression { |
---|
| 899 | public: |
---|
[65cdc1e] | 900 | Expression * expr; |
---|
| 901 | std::list<InitAlternative> initAlts; |
---|
| 902 | |
---|
[e4d829b] | 903 | UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ); |
---|
| 904 | UntypedInitExpr( const UntypedInitExpr & other ); |
---|
| 905 | ~UntypedInitExpr(); |
---|
| 906 | |
---|
| 907 | Expression * get_expr() const { return expr; } |
---|
| 908 | UntypedInitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; } |
---|
| 909 | |
---|
| 910 | std::list<InitAlternative> & get_initAlts() { return initAlts; } |
---|
| 911 | |
---|
[7870799] | 912 | virtual UntypedInitExpr * clone() const override { return new UntypedInitExpr( * 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; |
---|
[e4d829b] | 917 | }; |
---|
| 918 | |
---|
| 919 | class InitExpr : public Expression { |
---|
| 920 | public: |
---|
[65cdc1e] | 921 | Expression * expr; |
---|
| 922 | Designation * designation; |
---|
| 923 | |
---|
[62423350] | 924 | InitExpr( Expression * expr, Designation * designation ); |
---|
[e4d829b] | 925 | InitExpr( const InitExpr & other ); |
---|
| 926 | ~InitExpr(); |
---|
| 927 | |
---|
| 928 | Expression * get_expr() const { return expr; } |
---|
| 929 | InitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; } |
---|
| 930 | |
---|
| 931 | Designation * get_designation() const { return designation; } |
---|
| 932 | InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; } |
---|
| 933 | |
---|
[7870799] | 934 | virtual InitExpr * clone() const override { return new InitExpr( * 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; |
---|
[e4d829b] | 939 | }; |
---|
| 940 | |
---|
[44b4114] | 941 | /// expression that contains a deleted identifier - should never make it past the resolver. |
---|
| 942 | class DeletedExpr : public Expression { |
---|
| 943 | public: |
---|
| 944 | Expression * expr; |
---|
[e67991f] | 945 | Declaration * deleteStmt; |
---|
[44b4114] | 946 | |
---|
[e67991f] | 947 | DeletedExpr( Expression * expr, Declaration * deleteStmt ); |
---|
[44b4114] | 948 | DeletedExpr( const DeletedExpr & other ); |
---|
| 949 | ~DeletedExpr(); |
---|
| 950 | |
---|
[7870799] | 951 | virtual DeletedExpr * clone() const override { return new DeletedExpr( * this ); } |
---|
| 952 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 953 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 954 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 955 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[44b4114] | 956 | }; |
---|
| 957 | |
---|
[0f79853] | 958 | /// expression wrapping the use of a default argument - should never make it past the resolver. |
---|
| 959 | class DefaultArgExpr : public Expression { |
---|
| 960 | public: |
---|
| 961 | Expression * expr; |
---|
| 962 | |
---|
| 963 | DefaultArgExpr( Expression * expr ); |
---|
| 964 | DefaultArgExpr( const DefaultArgExpr & other ); |
---|
| 965 | ~DefaultArgExpr(); |
---|
| 966 | |
---|
[7870799] | 967 | virtual DefaultArgExpr * clone() const override { return new DefaultArgExpr( * this ); } |
---|
| 968 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 969 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 970 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 971 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[0f79853] | 972 | }; |
---|
| 973 | |
---|
[d807ca28] | 974 | /// C11 _Generic expression |
---|
| 975 | class GenericExpr : public Expression { |
---|
| 976 | public: |
---|
| 977 | struct Association { |
---|
| 978 | Type * type = nullptr; |
---|
| 979 | Expression * expr = nullptr; |
---|
| 980 | bool isDefault = false; |
---|
| 981 | |
---|
| 982 | Association( Type * type, Expression * expr ); |
---|
| 983 | Association( Expression * expr ); |
---|
| 984 | Association( const Association & other ); |
---|
| 985 | Association & operator=( const Association & other ) = delete; // at the moment this isn't used, and I don't want to implement it |
---|
| 986 | ~Association(); |
---|
| 987 | }; |
---|
| 988 | |
---|
| 989 | Expression * control; |
---|
| 990 | std::list<Association> associations; |
---|
| 991 | |
---|
| 992 | GenericExpr( Expression * control, const std::list<Association> & assoc ); |
---|
| 993 | GenericExpr( const GenericExpr & other ); |
---|
| 994 | virtual ~GenericExpr(); |
---|
| 995 | |
---|
[7870799] | 996 | virtual GenericExpr * clone() const override { return new GenericExpr( * this ); } |
---|
| 997 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 998 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 999 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 1000 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[d807ca28] | 1001 | }; |
---|
| 1002 | |
---|
[0dd3a2f] | 1003 | // Local Variables: // |
---|
| 1004 | // tab-width: 4 // |
---|
| 1005 | // mode: c++ // |
---|
| 1006 | // compile-command: "make install" // |
---|
| 1007 | // End: // |
---|