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