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