| [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 | 
|---|
| [630a82a] | 11 | // Last Modified By : Peter A. Buhr | 
|---|
|  | 12 | // Last Modified On : Fri Apr  8 17:18:06 2016 | 
|---|
|  | 13 | // Update Count     : 21 | 
|---|
| [0dd3a2f] | 14 | // | 
|---|
| [51b73452] | 15 |  | 
|---|
|  | 16 | #ifndef EXPRESSION_H | 
|---|
|  | 17 | #define EXPRESSION_H | 
|---|
|  | 18 |  | 
|---|
|  | 19 | #include <map> | 
|---|
|  | 20 | #include "SynTree.h" | 
|---|
|  | 21 | #include "Visitor.h" | 
|---|
|  | 22 | #include "Mutator.h" | 
|---|
|  | 23 | #include "Constant.h" | 
|---|
|  | 24 |  | 
|---|
| [47534159] | 25 | /// Expression is the root type for all expressions | 
|---|
| [0dd3a2f] | 26 | class Expression { | 
|---|
|  | 27 | public: | 
|---|
|  | 28 | Expression(Expression *_aname = 0 ); | 
|---|
|  | 29 | Expression( const Expression &other ); | 
|---|
|  | 30 | virtual ~Expression(); | 
|---|
|  | 31 |  | 
|---|
|  | 32 | std::list<Type *>& get_results() { return results; } | 
|---|
| [7f5566b] | 33 | void add_result( Type *t ); | 
|---|
| [0dd3a2f] | 34 |  | 
|---|
|  | 35 | TypeSubstitution *get_env() const { return env; } | 
|---|
|  | 36 | void set_env( TypeSubstitution *newValue ) { env = newValue; } | 
|---|
|  | 37 | Expression *get_argName() const { return argName; } | 
|---|
|  | 38 | void set_argName( Expression *name ) { argName = name; } | 
|---|
|  | 39 |  | 
|---|
|  | 40 | virtual Expression *clone() const = 0; | 
|---|
|  | 41 | virtual void accept( Visitor &v ) = 0; | 
|---|
|  | 42 | virtual Expression *acceptMutator( Mutator &m ) = 0; | 
|---|
|  | 43 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 44 | protected: | 
|---|
|  | 45 | std::list<Type *> results; | 
|---|
|  | 46 | TypeSubstitution *env; | 
|---|
|  | 47 | Expression* argName; // if expression is used as an argument, it can be "designated" by this name | 
|---|
| [51b73452] | 48 | }; | 
|---|
|  | 49 |  | 
|---|
| [47534159] | 50 | /// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration, | 
|---|
|  | 51 | /// but subject to decay-to-pointer and type parameter renaming | 
|---|
| [0dd3a2f] | 52 | struct ParamEntry { | 
|---|
|  | 53 | ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {} | 
|---|
|  | 54 | ParamEntry( UniqueId decl, Type *actualType, Type *formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ) {} | 
|---|
|  | 55 | ParamEntry( const ParamEntry &other ); | 
|---|
|  | 56 | ~ParamEntry(); | 
|---|
|  | 57 | ParamEntry &operator=( const ParamEntry &other ); | 
|---|
|  | 58 |  | 
|---|
|  | 59 | UniqueId decl; | 
|---|
|  | 60 | Type *actualType; | 
|---|
|  | 61 | Type *formalType; | 
|---|
|  | 62 | Expression* expr; | 
|---|
| [51b73452] | 63 | }; | 
|---|
|  | 64 |  | 
|---|
|  | 65 | typedef std::map< UniqueId, ParamEntry > InferredParams; | 
|---|
|  | 66 |  | 
|---|
| [47534159] | 67 | /// ApplicationExpr represents the application of a function to a set of parameters.  This is the | 
|---|
|  | 68 | /// result of running an UntypedExpr through the expression analyzer. | 
|---|
| [0dd3a2f] | 69 | class ApplicationExpr : public Expression { | 
|---|
|  | 70 | public: | 
|---|
|  | 71 | ApplicationExpr( Expression *function ); | 
|---|
|  | 72 | ApplicationExpr( const ApplicationExpr &other ); | 
|---|
|  | 73 | virtual ~ApplicationExpr(); | 
|---|
|  | 74 |  | 
|---|
|  | 75 | Expression *get_function() const { return function; } | 
|---|
|  | 76 | void set_function( Expression *newValue ) { function = newValue; } | 
|---|
|  | 77 | std::list<Expression *>& get_args() { return args; } | 
|---|
|  | 78 | InferredParams &get_inferParams() { return inferParams; } | 
|---|
|  | 79 |  | 
|---|
|  | 80 | virtual ApplicationExpr *clone() const { return new ApplicationExpr( *this ); } | 
|---|
|  | 81 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 82 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 83 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 84 | private: | 
|---|
|  | 85 | Expression *function; | 
|---|
|  | 86 | std::list<Expression *> args; | 
|---|
|  | 87 | InferredParams inferParams; | 
|---|
| [51b73452] | 88 | }; | 
|---|
|  | 89 |  | 
|---|
| [47534159] | 90 | /// UntypedExpr represents the application of a function to a set of parameters, but where the | 
|---|
|  | 91 | /// particular overload for the function name has not yet been determined.  Most operators are | 
|---|
|  | 92 | /// converted into functional form automatically, to permit operator overloading. | 
|---|
| [0dd3a2f] | 93 | class UntypedExpr : public Expression { | 
|---|
|  | 94 | public: | 
|---|
|  | 95 | UntypedExpr( Expression *function, Expression *_aname = 0 ); | 
|---|
|  | 96 | UntypedExpr( const UntypedExpr &other ); | 
|---|
|  | 97 | UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = 0 ); | 
|---|
|  | 98 | virtual ~UntypedExpr(); | 
|---|
|  | 99 |  | 
|---|
|  | 100 | Expression *get_function() const { return function; } | 
|---|
|  | 101 | void set_function( Expression *newValue ) { function = newValue; } | 
|---|
|  | 102 |  | 
|---|
|  | 103 | void set_args( std::list<Expression *> &listArgs ) { args = listArgs; } | 
|---|
|  | 104 | std::list<Expression*>::iterator begin_args() { return args.begin(); } | 
|---|
|  | 105 | std::list<Expression*>::iterator end_args() { return args.end(); } | 
|---|
|  | 106 | std::list<Expression*>& get_args() { return args; } | 
|---|
|  | 107 |  | 
|---|
|  | 108 | virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); } | 
|---|
|  | 109 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 110 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 111 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 112 | virtual void printArgs(std::ostream &os, int indent = 0) const; | 
|---|
|  | 113 | private: | 
|---|
|  | 114 | Expression *function; | 
|---|
|  | 115 | std::list<Expression*> args; | 
|---|
| [51b73452] | 116 | }; | 
|---|
|  | 117 |  | 
|---|
| [47534159] | 118 | /// NameExpr contains a name whose meaning is still not determined | 
|---|
| [0dd3a2f] | 119 | class NameExpr : public Expression { | 
|---|
|  | 120 | public: | 
|---|
|  | 121 | NameExpr( std::string name, Expression *_aname = 0 ); | 
|---|
|  | 122 | NameExpr( const NameExpr &other ); | 
|---|
|  | 123 | virtual ~NameExpr(); | 
|---|
|  | 124 |  | 
|---|
| [5f2f2d7] | 125 | const std::string &get_name() const { return name; } | 
|---|
| [0dd3a2f] | 126 | void set_name( std::string newValue ) { name = newValue; } | 
|---|
|  | 127 |  | 
|---|
|  | 128 | virtual NameExpr *clone() const { return new NameExpr( *this ); } | 
|---|
|  | 129 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 130 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 131 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 132 | private: | 
|---|
|  | 133 | std::string name; | 
|---|
| [51b73452] | 134 | }; | 
|---|
|  | 135 |  | 
|---|
|  | 136 | // The following classes are used to represent expression types that cannot be converted into | 
|---|
|  | 137 | // function-call format. | 
|---|
|  | 138 |  | 
|---|
| [47534159] | 139 | /// AddressExpr represents a address-of expression, e.g. &e | 
|---|
| [0dd3a2f] | 140 | class AddressExpr : public Expression { | 
|---|
|  | 141 | public: | 
|---|
|  | 142 | AddressExpr( Expression *arg, Expression *_aname = 0 ); | 
|---|
|  | 143 | AddressExpr( const AddressExpr &other ); | 
|---|
|  | 144 | virtual ~AddressExpr(); | 
|---|
|  | 145 |  | 
|---|
|  | 146 | Expression *get_arg() const { return arg; } | 
|---|
|  | 147 | void set_arg(Expression *newValue ) { arg = newValue; } | 
|---|
|  | 148 |  | 
|---|
|  | 149 | virtual AddressExpr *clone() const { return new AddressExpr( *this ); } | 
|---|
|  | 150 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 151 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 152 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 153 | private: | 
|---|
|  | 154 | Expression *arg; | 
|---|
| [51b73452] | 155 | }; | 
|---|
|  | 156 |  | 
|---|
| [3be261a] | 157 | // xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack | 
|---|
| [0dd3a2f] | 158 | class LabelAddressExpr : public Expression { | 
|---|
|  | 159 | public: | 
|---|
|  | 160 | LabelAddressExpr( Expression *arg ); | 
|---|
| [3be261a] | 161 | LabelAddressExpr( const LabelAddressExpr &other ); | 
|---|
| [0dd3a2f] | 162 | virtual ~LabelAddressExpr(); | 
|---|
|  | 163 |  | 
|---|
|  | 164 | Expression *get_arg() const { return arg; } | 
|---|
|  | 165 | void set_arg(Expression *newValue ) { arg = newValue; } | 
|---|
|  | 166 |  | 
|---|
|  | 167 | virtual LabelAddressExpr *clone() const { return new LabelAddressExpr( *this ); } | 
|---|
|  | 168 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 169 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 170 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 171 | private: | 
|---|
|  | 172 | Expression *arg; | 
|---|
| [51b73452] | 173 | }; | 
|---|
|  | 174 |  | 
|---|
| [47534159] | 175 | /// CastExpr represents a type cast expression, e.g. (int)e | 
|---|
| [0dd3a2f] | 176 | class CastExpr : public Expression { | 
|---|
|  | 177 | public: | 
|---|
|  | 178 | CastExpr( Expression *arg, Expression *_aname = 0 ); | 
|---|
|  | 179 | CastExpr( Expression *arg, Type *toType, Expression *_aname = 0 ); | 
|---|
|  | 180 | CastExpr( const CastExpr &other ); | 
|---|
|  | 181 | virtual ~CastExpr(); | 
|---|
|  | 182 |  | 
|---|
|  | 183 | Expression *get_arg() const { return arg; } | 
|---|
|  | 184 | void set_arg(Expression *newValue ) { arg = newValue; } | 
|---|
|  | 185 |  | 
|---|
|  | 186 | virtual CastExpr *clone() const { return new CastExpr( *this ); } | 
|---|
|  | 187 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 188 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 189 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 190 | private: | 
|---|
|  | 191 | Expression *arg; | 
|---|
| [51b73452] | 192 | }; | 
|---|
|  | 193 |  | 
|---|
| [47534159] | 194 | /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer | 
|---|
| [0dd3a2f] | 195 | class UntypedMemberExpr : public Expression { | 
|---|
|  | 196 | public: | 
|---|
|  | 197 | UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = 0 ); | 
|---|
|  | 198 | UntypedMemberExpr( const UntypedMemberExpr &other ); | 
|---|
|  | 199 | virtual ~UntypedMemberExpr(); | 
|---|
|  | 200 |  | 
|---|
|  | 201 | std::string get_member() const { return member; } | 
|---|
|  | 202 | void set_member( const std::string &newValue ) { member = newValue; } | 
|---|
|  | 203 | Expression *get_aggregate() const { return aggregate; } | 
|---|
|  | 204 | void set_aggregate( Expression *newValue ) { aggregate = newValue; } | 
|---|
|  | 205 |  | 
|---|
|  | 206 | virtual UntypedMemberExpr *clone() const { return new UntypedMemberExpr( *this ); } | 
|---|
|  | 207 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 208 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 209 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 210 | private: | 
|---|
|  | 211 | std::string member; | 
|---|
|  | 212 | Expression *aggregate; | 
|---|
| [51b73452] | 213 | }; | 
|---|
|  | 214 |  | 
|---|
| [47534159] | 215 | /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer | 
|---|
| [0dd3a2f] | 216 | class MemberExpr : public Expression { | 
|---|
|  | 217 | public: | 
|---|
|  | 218 | MemberExpr( DeclarationWithType *member, Expression *aggregate, Expression *_aname = 0 ); | 
|---|
|  | 219 | MemberExpr( const MemberExpr &other ); | 
|---|
|  | 220 | virtual ~MemberExpr(); | 
|---|
|  | 221 |  | 
|---|
|  | 222 | DeclarationWithType *get_member() const { return member; } | 
|---|
|  | 223 | void set_member( DeclarationWithType *newValue ) { member = newValue; } | 
|---|
|  | 224 | Expression *get_aggregate() const { return aggregate; } | 
|---|
|  | 225 | void set_aggregate( Expression *newValue ) { aggregate = newValue; } | 
|---|
|  | 226 |  | 
|---|
|  | 227 | virtual MemberExpr *clone() const { return new MemberExpr( *this ); } | 
|---|
|  | 228 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 229 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 230 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 231 | private: | 
|---|
|  | 232 | DeclarationWithType *member; | 
|---|
|  | 233 | Expression *aggregate; | 
|---|
| [51b73452] | 234 | }; | 
|---|
|  | 235 |  | 
|---|
| [47534159] | 236 | /// VariableExpr represents an expression that simply refers to the value of a named variable | 
|---|
| [0dd3a2f] | 237 | class VariableExpr : public Expression { | 
|---|
|  | 238 | public: | 
|---|
|  | 239 | VariableExpr( DeclarationWithType *var, Expression *_aname = 0 ); | 
|---|
|  | 240 | VariableExpr( const VariableExpr &other ); | 
|---|
|  | 241 | virtual ~VariableExpr(); | 
|---|
|  | 242 |  | 
|---|
|  | 243 | DeclarationWithType *get_var() const { return var; } | 
|---|
|  | 244 | void set_var( DeclarationWithType *newValue ) { var = newValue; } | 
|---|
|  | 245 |  | 
|---|
|  | 246 | virtual VariableExpr *clone() const { return new VariableExpr( *this ); } | 
|---|
|  | 247 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 248 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 249 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 250 | private: | 
|---|
|  | 251 | DeclarationWithType *var; | 
|---|
| [51b73452] | 252 | }; | 
|---|
|  | 253 |  | 
|---|
| [3be261a] | 254 | /// ConstantExpr represents an expression that simply refers to the value of a constant | 
|---|
| [0dd3a2f] | 255 | class ConstantExpr : public Expression { | 
|---|
|  | 256 | public: | 
|---|
|  | 257 | ConstantExpr( Constant constant, Expression *_aname = 0 ); | 
|---|
|  | 258 | ConstantExpr( const ConstantExpr &other ); | 
|---|
|  | 259 | virtual ~ConstantExpr(); | 
|---|
|  | 260 |  | 
|---|
|  | 261 | Constant *get_constant() { return &constant; } | 
|---|
|  | 262 | void set_constant( const Constant &newValue ) { constant = newValue; } | 
|---|
|  | 263 |  | 
|---|
|  | 264 | virtual ConstantExpr *clone() const { return new ConstantExpr( *this ); } | 
|---|
|  | 265 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 266 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 267 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 268 | private: | 
|---|
|  | 269 | Constant constant; | 
|---|
| [51b73452] | 270 | }; | 
|---|
|  | 271 |  | 
|---|
| [47534159] | 272 | /// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4) | 
|---|
| [0dd3a2f] | 273 | class SizeofExpr : public Expression { | 
|---|
|  | 274 | public: | 
|---|
|  | 275 | SizeofExpr( Expression *expr, Expression *_aname = 0 ); | 
|---|
|  | 276 | SizeofExpr( const SizeofExpr &other ); | 
|---|
|  | 277 | SizeofExpr( Type *type, Expression *_aname = 0 ); | 
|---|
|  | 278 | virtual ~SizeofExpr(); | 
|---|
|  | 279 |  | 
|---|
|  | 280 | Expression *get_expr() const { return expr; } | 
|---|
|  | 281 | void set_expr( Expression *newValue ) { expr = newValue; } | 
|---|
|  | 282 | Type *get_type() const { return type; } | 
|---|
|  | 283 | void set_type( Type *newValue ) { type = newValue; } | 
|---|
|  | 284 | bool get_isType() const { return isType; } | 
|---|
|  | 285 | void set_isType( bool newValue ) { isType = newValue; } | 
|---|
|  | 286 |  | 
|---|
|  | 287 | virtual SizeofExpr *clone() const { return new SizeofExpr( *this ); } | 
|---|
|  | 288 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 289 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 290 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 291 | private: | 
|---|
|  | 292 | Expression *expr; | 
|---|
|  | 293 | Type *type; | 
|---|
|  | 294 | bool isType; | 
|---|
| [51b73452] | 295 | }; | 
|---|
|  | 296 |  | 
|---|
| [47534159] | 297 | /// AlignofExpr represents an alignof expression | 
|---|
|  | 298 | class AlignofExpr : public Expression { | 
|---|
|  | 299 | public: | 
|---|
|  | 300 | AlignofExpr( Expression *expr, Expression *_aname = 0 ); | 
|---|
|  | 301 | AlignofExpr( const AlignofExpr &other ); | 
|---|
|  | 302 | AlignofExpr( Type *type, Expression *_aname = 0 ); | 
|---|
|  | 303 | virtual ~AlignofExpr(); | 
|---|
|  | 304 |  | 
|---|
|  | 305 | Expression *get_expr() const { return expr; } | 
|---|
|  | 306 | void set_expr( Expression *newValue ) { expr = newValue; } | 
|---|
|  | 307 | Type *get_type() const { return type; } | 
|---|
|  | 308 | void set_type( Type *newValue ) { type = newValue; } | 
|---|
|  | 309 | bool get_isType() const { return isType; } | 
|---|
|  | 310 | void set_isType( bool newValue ) { isType = newValue; } | 
|---|
|  | 311 |  | 
|---|
|  | 312 | virtual AlignofExpr *clone() const { return new AlignofExpr( *this ); } | 
|---|
|  | 313 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 314 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 315 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 316 | private: | 
|---|
|  | 317 | Expression *expr; | 
|---|
|  | 318 | Type *type; | 
|---|
|  | 319 | bool isType; | 
|---|
|  | 320 | }; | 
|---|
|  | 321 |  | 
|---|
| [2a4b088] | 322 | /// UntypedOffsetofExpr represents an offsetof expression before resolution | 
|---|
|  | 323 | class UntypedOffsetofExpr : public Expression { | 
|---|
|  | 324 | public: | 
|---|
|  | 325 | UntypedOffsetofExpr( Type *type, const std::string &member, Expression *_aname = 0 ); | 
|---|
|  | 326 | UntypedOffsetofExpr( const UntypedOffsetofExpr &other ); | 
|---|
|  | 327 | virtual ~UntypedOffsetofExpr(); | 
|---|
|  | 328 |  | 
|---|
|  | 329 | std::string get_member() const { return member; } | 
|---|
|  | 330 | void set_member( const std::string &newValue ) { member = newValue; } | 
|---|
|  | 331 | Type *get_type() const { return type; } | 
|---|
|  | 332 | void set_type( Type *newValue ) { type = newValue; } | 
|---|
|  | 333 |  | 
|---|
|  | 334 | virtual UntypedOffsetofExpr *clone() const { return new UntypedOffsetofExpr( *this ); } | 
|---|
|  | 335 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 336 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 337 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 338 | private: | 
|---|
|  | 339 | Type *type; | 
|---|
|  | 340 | std::string member; | 
|---|
|  | 341 | }; | 
|---|
|  | 342 |  | 
|---|
| [25a054f] | 343 | /// OffsetofExpr represents an offsetof expression | 
|---|
|  | 344 | class OffsetofExpr : public Expression { | 
|---|
|  | 345 | public: | 
|---|
|  | 346 | OffsetofExpr( Type *type, DeclarationWithType *member, Expression *_aname = 0 ); | 
|---|
|  | 347 | OffsetofExpr( const OffsetofExpr &other ); | 
|---|
|  | 348 | virtual ~OffsetofExpr(); | 
|---|
|  | 349 |  | 
|---|
|  | 350 | Type *get_type() const { return type; } | 
|---|
|  | 351 | void set_type( Type *newValue ) { type = newValue; } | 
|---|
|  | 352 | DeclarationWithType *get_member() const { return member; } | 
|---|
|  | 353 | void set_member( DeclarationWithType *newValue ) { member = newValue; } | 
|---|
|  | 354 |  | 
|---|
|  | 355 | virtual OffsetofExpr *clone() const { return new OffsetofExpr( *this ); } | 
|---|
|  | 356 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 357 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 358 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 359 | private: | 
|---|
|  | 360 | Type *type; | 
|---|
|  | 361 | DeclarationWithType *member; | 
|---|
|  | 362 | }; | 
|---|
|  | 363 |  | 
|---|
| [afc1045] | 364 | /// Expression representing a pack of field-offsets for a generic type | 
|---|
|  | 365 | class OffsetPackExpr : public Expression { | 
|---|
|  | 366 | public: | 
|---|
|  | 367 | OffsetPackExpr( StructInstType *type_, Expression *aname_ = 0 ); | 
|---|
|  | 368 | OffsetPackExpr( const OffsetPackExpr &other ); | 
|---|
|  | 369 | virtual ~OffsetPackExpr(); | 
|---|
|  | 370 |  | 
|---|
|  | 371 | StructInstType *get_type() const { return type; } | 
|---|
|  | 372 | void set_type( StructInstType *newValue ) { type = newValue; } | 
|---|
|  | 373 |  | 
|---|
|  | 374 | virtual OffsetPackExpr *clone() const { return new OffsetPackExpr( *this ); } | 
|---|
|  | 375 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 376 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 377 |  | 
|---|
|  | 378 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 379 |  | 
|---|
|  | 380 | private: | 
|---|
|  | 381 | StructInstType *type; | 
|---|
|  | 382 | }; | 
|---|
|  | 383 |  | 
|---|
| [47534159] | 384 | /// AttrExpr represents an @attribute expression (like sizeof, but user-defined) | 
|---|
| [0dd3a2f] | 385 | class AttrExpr : public Expression { | 
|---|
|  | 386 | public: | 
|---|
|  | 387 | AttrExpr(Expression *attr, Expression *expr, Expression *_aname = 0 ); | 
|---|
|  | 388 | AttrExpr( const AttrExpr &other ); | 
|---|
|  | 389 | AttrExpr( Expression *attr, Type *type, Expression *_aname = 0 ); | 
|---|
|  | 390 | virtual ~AttrExpr(); | 
|---|
|  | 391 |  | 
|---|
|  | 392 | Expression *get_attr() const { return attr; } | 
|---|
|  | 393 | void set_attr( Expression *newValue ) { attr = newValue; } | 
|---|
|  | 394 | Expression *get_expr() const { return expr; } | 
|---|
|  | 395 | void set_expr( Expression *newValue ) { expr = newValue; } | 
|---|
|  | 396 | Type *get_type() const { return type; } | 
|---|
|  | 397 | void set_type( Type *newValue ) { type = newValue; } | 
|---|
|  | 398 | bool get_isType() const { return isType; } | 
|---|
|  | 399 | void set_isType( bool newValue ) { isType = newValue; } | 
|---|
|  | 400 |  | 
|---|
|  | 401 | virtual AttrExpr *clone() const { return new AttrExpr( *this ); } | 
|---|
|  | 402 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 403 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 404 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 405 | private: | 
|---|
|  | 406 | Expression *attr; | 
|---|
|  | 407 | Expression *expr; | 
|---|
|  | 408 | Type *type; | 
|---|
|  | 409 | bool isType; | 
|---|
| [51b73452] | 410 | }; | 
|---|
|  | 411 |  | 
|---|
| [47534159] | 412 | /// LogicalExpr represents a short-circuit boolean expression (&& or ||) | 
|---|
| [0dd3a2f] | 413 | class LogicalExpr : public Expression { | 
|---|
|  | 414 | public: | 
|---|
|  | 415 | LogicalExpr( Expression *arg1, Expression *arg2, bool andp = true, Expression *_aname = 0 ); | 
|---|
|  | 416 | LogicalExpr( const LogicalExpr &other ); | 
|---|
|  | 417 | virtual ~LogicalExpr(); | 
|---|
|  | 418 |  | 
|---|
|  | 419 | bool get_isAnd() const { return isAnd; } | 
|---|
|  | 420 | Expression *get_arg1() { return arg1; } | 
|---|
|  | 421 | void set_arg1( Expression *newValue ) { arg1 = newValue; } | 
|---|
|  | 422 | Expression *get_arg2() const { return arg2; } | 
|---|
|  | 423 | void set_arg2( Expression *newValue ) { arg2 = newValue; } | 
|---|
|  | 424 |  | 
|---|
|  | 425 | virtual LogicalExpr *clone() const { return new LogicalExpr( *this ); } | 
|---|
|  | 426 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 427 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 428 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 429 | private: | 
|---|
|  | 430 | Expression *arg1; | 
|---|
|  | 431 | Expression *arg2; | 
|---|
|  | 432 | bool isAnd; | 
|---|
| [51b73452] | 433 | }; | 
|---|
|  | 434 |  | 
|---|
| [47534159] | 435 | /// ConditionalExpr represents the three-argument conditional ( p ? a : b ) | 
|---|
| [0dd3a2f] | 436 | class ConditionalExpr : public Expression { | 
|---|
|  | 437 | public: | 
|---|
|  | 438 | ConditionalExpr( Expression *arg1, Expression *arg2, Expression *arg3, Expression *_aname = 0 ); | 
|---|
|  | 439 | ConditionalExpr( const ConditionalExpr &other ); | 
|---|
|  | 440 | virtual ~ConditionalExpr(); | 
|---|
|  | 441 |  | 
|---|
|  | 442 | Expression *get_arg1() const { return arg1; } | 
|---|
|  | 443 | void set_arg1( Expression *newValue ) { arg1 = newValue; } | 
|---|
|  | 444 | Expression *get_arg2() const { return arg2; } | 
|---|
|  | 445 | void set_arg2( Expression *newValue ) { arg2 = newValue; } | 
|---|
|  | 446 | Expression *get_arg3() const { return arg3; } | 
|---|
|  | 447 | void set_arg3( Expression *newValue ) { arg3 = newValue; } | 
|---|
|  | 448 |  | 
|---|
|  | 449 | virtual ConditionalExpr *clone() const { return new ConditionalExpr( *this ); } | 
|---|
|  | 450 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 451 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 452 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 453 | private: | 
|---|
|  | 454 | Expression *arg1; | 
|---|
|  | 455 | Expression *arg2; | 
|---|
|  | 456 | Expression *arg3; | 
|---|
| [51b73452] | 457 | }; | 
|---|
|  | 458 |  | 
|---|
| [47534159] | 459 | /// CommaExpr represents the sequence operator ( a, b ) | 
|---|
| [0dd3a2f] | 460 | class CommaExpr : public Expression { | 
|---|
|  | 461 | public: | 
|---|
|  | 462 | CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname = 0 ); | 
|---|
|  | 463 | CommaExpr( const CommaExpr &other ); | 
|---|
|  | 464 | virtual ~CommaExpr(); | 
|---|
|  | 465 |  | 
|---|
|  | 466 | Expression *get_arg1() const { return arg1; } | 
|---|
|  | 467 | void set_arg1( Expression *newValue ) { arg1 = newValue; } | 
|---|
|  | 468 | Expression *get_arg2() const { return arg2; } | 
|---|
|  | 469 | void set_arg2( Expression *newValue ) { arg2 = newValue; } | 
|---|
|  | 470 |  | 
|---|
|  | 471 | virtual CommaExpr *clone() const { return new CommaExpr( *this ); } | 
|---|
|  | 472 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 473 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 474 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 475 | private: | 
|---|
|  | 476 | Expression *arg1; | 
|---|
|  | 477 | Expression *arg2; | 
|---|
| [51b73452] | 478 | }; | 
|---|
|  | 479 |  | 
|---|
| [47534159] | 480 | /// TupleExpr represents a tuple expression ( [a, b, c] ) | 
|---|
| [0dd3a2f] | 481 | class TupleExpr : public Expression { | 
|---|
|  | 482 | public: | 
|---|
|  | 483 | TupleExpr( Expression *_aname = 0 ); | 
|---|
|  | 484 | TupleExpr( const TupleExpr &other ); | 
|---|
|  | 485 | virtual ~TupleExpr(); | 
|---|
|  | 486 |  | 
|---|
|  | 487 | void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; } | 
|---|
|  | 488 | std::list<Expression*>& get_exprs() { return exprs; } | 
|---|
|  | 489 |  | 
|---|
|  | 490 | virtual TupleExpr *clone() const { return new TupleExpr( *this ); } | 
|---|
|  | 491 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 492 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 493 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 494 | private: | 
|---|
|  | 495 | std::list<Expression*> exprs; | 
|---|
| [51b73452] | 496 | }; | 
|---|
|  | 497 |  | 
|---|
| [47534159] | 498 | /// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on | 
|---|
| [0dd3a2f] | 499 | class SolvedTupleExpr : public Expression { | 
|---|
|  | 500 | public: | 
|---|
|  | 501 | SolvedTupleExpr( Expression *_aname = 0 ) : Expression( _aname ) {} | 
|---|
|  | 502 | SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = 0 ); | 
|---|
|  | 503 | SolvedTupleExpr( const SolvedTupleExpr &other ); | 
|---|
|  | 504 | virtual ~SolvedTupleExpr() {} | 
|---|
|  | 505 |  | 
|---|
|  | 506 | std::list<Expression*> &get_exprs() { return exprs; } | 
|---|
|  | 507 |  | 
|---|
|  | 508 | virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); } | 
|---|
|  | 509 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 510 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 511 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 512 | private: | 
|---|
|  | 513 | std::list<Expression*> exprs; | 
|---|
| [51b73452] | 514 | }; | 
|---|
|  | 515 |  | 
|---|
| [47534159] | 516 | /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter) | 
|---|
| [0dd3a2f] | 517 | class TypeExpr : public Expression { | 
|---|
|  | 518 | public: | 
|---|
|  | 519 | TypeExpr( Type *type ); | 
|---|
|  | 520 | TypeExpr( const TypeExpr &other ); | 
|---|
|  | 521 | virtual ~TypeExpr(); | 
|---|
|  | 522 |  | 
|---|
|  | 523 | Type *get_type() const { return type; } | 
|---|
|  | 524 | void set_type( Type *newValue ) { type = newValue; } | 
|---|
|  | 525 |  | 
|---|
|  | 526 | virtual TypeExpr *clone() const { return new TypeExpr( *this ); } | 
|---|
|  | 527 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 528 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 529 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 530 | private: | 
|---|
|  | 531 | Type *type; | 
|---|
| [51b73452] | 532 | }; | 
|---|
|  | 533 |  | 
|---|
| [47534159] | 534 | /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result) | 
|---|
| [7f5566b] | 535 | class AsmExpr : public Expression { | 
|---|
|  | 536 | public: | 
|---|
|  | 537 | AsmExpr( Expression *inout, ConstantExpr *constraint, Expression *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} | 
|---|
| [3be261a] | 538 | AsmExpr( const AsmExpr & other ); | 
|---|
| [7f5566b] | 539 | virtual ~AsmExpr() { delete inout; delete constraint; delete operand; }; | 
|---|
|  | 540 |  | 
|---|
|  | 541 | Expression *get_inout() const { return inout; } | 
|---|
|  | 542 | void set_inout( Expression *newValue ) { inout = newValue; } | 
|---|
|  | 543 |  | 
|---|
|  | 544 | ConstantExpr *get_constraint() const { return constraint; } | 
|---|
|  | 545 | void set_constraint( ConstantExpr *newValue ) { constraint = newValue; } | 
|---|
|  | 546 |  | 
|---|
|  | 547 | Expression *get_operand() const { return operand; } | 
|---|
|  | 548 | void set_operand( Expression *newValue ) { operand = newValue; } | 
|---|
|  | 549 |  | 
|---|
|  | 550 | virtual AsmExpr *clone() const { return new AsmExpr( *this ); } | 
|---|
|  | 551 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 552 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 553 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 554 | private: | 
|---|
|  | 555 | // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints | 
|---|
|  | 556 | Expression *inout; | 
|---|
|  | 557 | ConstantExpr *constraint; | 
|---|
|  | 558 | Expression *operand; | 
|---|
|  | 559 | }; | 
|---|
|  | 560 |  | 
|---|
| [47534159] | 561 | /// ValofExpr represents a GCC 'lambda expression' | 
|---|
| [0dd3a2f] | 562 | class UntypedValofExpr : public Expression { | 
|---|
|  | 563 | public: | 
|---|
|  | 564 | UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {} | 
|---|
| [3be261a] | 565 | UntypedValofExpr( const UntypedValofExpr & other ); | 
|---|
|  | 566 | virtual ~UntypedValofExpr(); | 
|---|
| [0dd3a2f] | 567 |  | 
|---|
|  | 568 | Expression *get_value(); | 
|---|
|  | 569 | Statement *get_body() const { return body; } | 
|---|
|  | 570 |  | 
|---|
|  | 571 | virtual UntypedValofExpr *clone() const { return new UntypedValofExpr( *this ); } | 
|---|
|  | 572 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 573 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 574 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 575 | private: | 
|---|
|  | 576 | Statement *body; | 
|---|
| [51b73452] | 577 | }; | 
|---|
|  | 578 |  | 
|---|
| [630a82a] | 579 | /// CompoundLiteralExpr represents a C99 'compound literal' | 
|---|
|  | 580 | class CompoundLiteralExpr : public Expression { | 
|---|
|  | 581 | public: | 
|---|
|  | 582 | CompoundLiteralExpr( Type * type, Initializer * initializer ); | 
|---|
|  | 583 | CompoundLiteralExpr( const CompoundLiteralExpr &other ); | 
|---|
|  | 584 | ~CompoundLiteralExpr(); | 
|---|
|  | 585 |  | 
|---|
|  | 586 | Type * get_type() const { return type; } | 
|---|
|  | 587 | void set_type( Type * t ) { type = t; } | 
|---|
|  | 588 |  | 
|---|
|  | 589 | Initializer * get_initializer() const { return initializer; } | 
|---|
|  | 590 | void set_initializer( Initializer * i ) { initializer = i; } | 
|---|
|  | 591 |  | 
|---|
|  | 592 | virtual CompoundLiteralExpr *clone() const { return new CompoundLiteralExpr( *this ); } | 
|---|
|  | 593 | virtual void accept( Visitor &v ) { v.visit( this ); } | 
|---|
|  | 594 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } | 
|---|
|  | 595 | virtual void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 596 | private: | 
|---|
|  | 597 | Type * type; | 
|---|
|  | 598 | Initializer * initializer; | 
|---|
|  | 599 | }; | 
|---|
|  | 600 |  | 
|---|
| [baf7fee] | 601 | std::ostream & operator<<( std::ostream & out, Expression * expr ); | 
|---|
|  | 602 |  | 
|---|
| [0dd3a2f] | 603 | #endif // EXPRESSION_H | 
|---|
| [51b73452] | 604 |  | 
|---|
| [0dd3a2f] | 605 | // Local Variables: // | 
|---|
|  | 606 | // tab-width: 4 // | 
|---|
|  | 607 | // mode: c++ // | 
|---|
|  | 608 | // compile-command: "make install" // | 
|---|
|  | 609 | // End: // | 
|---|