| 1 | /*
|
|---|
| 2 | * This file is part of the Cforall project
|
|---|
| 3 | *
|
|---|
| 4 | * $Id: Expression.h,v 1.31 2005/08/29 20:59:25 rcbilson Exp $
|
|---|
| 5 | *
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef EXPRESSION_H
|
|---|
| 9 | #define EXPRESSION_H
|
|---|
| 10 |
|
|---|
| 11 | #include <map>
|
|---|
| 12 | #include "SynTree.h"
|
|---|
| 13 | #include "Visitor.h"
|
|---|
| 14 | #include "Mutator.h"
|
|---|
| 15 | #include "Constant.h"
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 | class Expression
|
|---|
| 19 | {
|
|---|
| 20 | public:
|
|---|
| 21 | Expression(Expression *_aname = 0 );
|
|---|
| 22 | Expression( const Expression &other );
|
|---|
| 23 | virtual ~Expression();
|
|---|
| 24 |
|
|---|
| 25 | std::list<Type *>& get_results() { return results; }
|
|---|
| 26 | void add_result(Type *t);
|
|---|
| 27 |
|
|---|
| 28 | TypeSubstitution *get_env() const { return env; }
|
|---|
| 29 | void set_env( TypeSubstitution *newValue ) { env = newValue; }
|
|---|
| 30 | Expression *get_argName() const { return argName; }
|
|---|
| 31 | void set_argName( Expression *name ) { argName = name; }
|
|---|
| 32 |
|
|---|
| 33 | virtual Expression *clone() const = 0;
|
|---|
| 34 | virtual void accept( Visitor &v ) = 0;
|
|---|
| 35 | virtual Expression *acceptMutator( Mutator &m ) = 0;
|
|---|
| 36 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 37 |
|
|---|
| 38 | protected:
|
|---|
| 39 | std::list<Type *> results;
|
|---|
| 40 | TypeSubstitution *env;
|
|---|
| 41 | Expression* argName; // if expression is used as an argument, it can be "designated" by this name
|
|---|
| 42 | };
|
|---|
| 43 |
|
|---|
| 44 | // ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
|
|---|
| 45 | // but subject to decay-to-pointer and type parameter renaming
|
|---|
| 46 | struct ParamEntry
|
|---|
| 47 | {
|
|---|
| 48 | ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {}
|
|---|
| 49 | ParamEntry( UniqueId decl, Type *actualType, Type *formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ) {}
|
|---|
| 50 | ParamEntry( const ParamEntry &other );
|
|---|
| 51 | ~ParamEntry();
|
|---|
| 52 | ParamEntry &operator=( const ParamEntry &other );
|
|---|
| 53 |
|
|---|
| 54 | UniqueId decl;
|
|---|
| 55 | Type *actualType;
|
|---|
| 56 | Type *formalType;
|
|---|
| 57 | Expression* expr;
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | typedef std::map< UniqueId, ParamEntry > InferredParams;
|
|---|
| 61 |
|
|---|
| 62 | // ApplicationExpr represents the application of a function to a set of parameters. This is the
|
|---|
| 63 | // result of running an UntypedExpr through the expression analyzer.
|
|---|
| 64 | class ApplicationExpr : public Expression
|
|---|
| 65 | {
|
|---|
| 66 | public:
|
|---|
| 67 | ApplicationExpr( Expression *function );
|
|---|
| 68 | ApplicationExpr( const ApplicationExpr &other );
|
|---|
| 69 | virtual ~ApplicationExpr();
|
|---|
| 70 |
|
|---|
| 71 | Expression *get_function() const { return function; }
|
|---|
| 72 | void set_function( Expression *newValue ) { function = newValue; }
|
|---|
| 73 | std::list<Expression *>& get_args() { return args; }
|
|---|
| 74 | InferredParams &get_inferParams() { return inferParams; }
|
|---|
| 75 |
|
|---|
| 76 | virtual ApplicationExpr *clone() const { return new ApplicationExpr( *this ); }
|
|---|
| 77 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 78 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 79 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 80 |
|
|---|
| 81 | private:
|
|---|
| 82 | Expression *function;
|
|---|
| 83 | std::list<Expression *> args;
|
|---|
| 84 | InferredParams inferParams;
|
|---|
| 85 | };
|
|---|
| 86 |
|
|---|
| 87 | // UntypedExpr represents the application of a function to a set of parameters, but where the
|
|---|
| 88 | // particular overload for the function name has not yet been determined. Most operators are
|
|---|
| 89 | // converted into functional form automatically, to permit operator overloading.
|
|---|
| 90 | class UntypedExpr : public Expression
|
|---|
| 91 | {
|
|---|
| 92 | public:
|
|---|
| 93 | UntypedExpr( Expression *function, Expression *_aname = 0 );
|
|---|
| 94 | UntypedExpr( const UntypedExpr &other );
|
|---|
| 95 | UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = 0 );
|
|---|
| 96 | virtual ~UntypedExpr();
|
|---|
| 97 |
|
|---|
| 98 | Expression *get_function() const { return function; }
|
|---|
| 99 | void set_function( Expression *newValue ) { function = newValue; }
|
|---|
| 100 |
|
|---|
| 101 | void set_args( std::list<Expression *> &listArgs ) { args = listArgs; }
|
|---|
| 102 | std::list<Expression*>::iterator begin_args() { return args.begin(); }
|
|---|
| 103 | std::list<Expression*>::iterator end_args() { return args.end(); }
|
|---|
| 104 | std::list<Expression*>& get_args() { return args; }
|
|---|
| 105 |
|
|---|
| 106 | virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); }
|
|---|
| 107 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 108 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 109 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 110 | virtual void printArgs(std::ostream &os, int indent = 0) const;
|
|---|
| 111 |
|
|---|
| 112 | private:
|
|---|
| 113 |
|
|---|
| 114 | Expression *function;
|
|---|
| 115 | std::list<Expression*> args;
|
|---|
| 116 | };
|
|---|
| 117 |
|
|---|
| 118 | // this class contains a name whose meaning is still not determined
|
|---|
| 119 | class NameExpr : public Expression
|
|---|
| 120 | {
|
|---|
| 121 | public:
|
|---|
| 122 | NameExpr( std::string name, Expression *_aname = 0 );
|
|---|
| 123 | NameExpr( const NameExpr &other );
|
|---|
| 124 | virtual ~NameExpr();
|
|---|
| 125 |
|
|---|
| 126 | std::string get_name() const { return name; }
|
|---|
| 127 | void set_name( std::string newValue ) { name = newValue; }
|
|---|
| 128 |
|
|---|
| 129 | virtual NameExpr *clone() const { return new NameExpr( *this ); }
|
|---|
| 130 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 131 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 132 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 133 |
|
|---|
| 134 | private:
|
|---|
| 135 |
|
|---|
| 136 | std::string name;
|
|---|
| 137 | };
|
|---|
| 138 |
|
|---|
| 139 | // The following classes are used to represent expression types that cannot be converted into
|
|---|
| 140 | // function-call format.
|
|---|
| 141 |
|
|---|
| 142 | // AddressExpr represents a address-of expression, e.g. &e
|
|---|
| 143 | class AddressExpr : public Expression
|
|---|
| 144 | {
|
|---|
| 145 | public:
|
|---|
| 146 | AddressExpr( Expression *arg, Expression *_aname = 0 );
|
|---|
| 147 | AddressExpr( const AddressExpr &other );
|
|---|
| 148 | virtual ~AddressExpr();
|
|---|
| 149 |
|
|---|
| 150 | Expression *get_arg() const { return arg; }
|
|---|
| 151 | void set_arg(Expression *newValue ) { arg = newValue; }
|
|---|
| 152 |
|
|---|
| 153 | virtual AddressExpr *clone() const { return new AddressExpr( *this ); }
|
|---|
| 154 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 155 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 156 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 157 |
|
|---|
| 158 | private:
|
|---|
| 159 | Expression *arg;
|
|---|
| 160 | };
|
|---|
| 161 |
|
|---|
| 162 | class LabelAddressExpr : public Expression
|
|---|
| 163 | {
|
|---|
| 164 | public:
|
|---|
| 165 | LabelAddressExpr( Expression *arg );
|
|---|
| 166 | LabelAddressExpr( const AddressExpr &other );
|
|---|
| 167 | virtual ~LabelAddressExpr();
|
|---|
| 168 |
|
|---|
| 169 | Expression *get_arg() const { return arg; }
|
|---|
| 170 | void set_arg(Expression *newValue ) { arg = newValue; }
|
|---|
| 171 |
|
|---|
| 172 | virtual LabelAddressExpr *clone() const { return new LabelAddressExpr( *this ); }
|
|---|
| 173 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 174 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 175 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 176 |
|
|---|
| 177 | private:
|
|---|
| 178 | Expression *arg;
|
|---|
| 179 | };
|
|---|
| 180 |
|
|---|
| 181 | // CastExpr represents a type cast expression, e.g. (int)e
|
|---|
| 182 | class CastExpr : public Expression
|
|---|
| 183 | {
|
|---|
| 184 | public:
|
|---|
| 185 | CastExpr( Expression *arg, Expression *_aname = 0 );
|
|---|
| 186 | CastExpr( Expression *arg, Type *toType, Expression *_aname = 0 );
|
|---|
| 187 | CastExpr( const CastExpr &other );
|
|---|
| 188 | virtual ~CastExpr();
|
|---|
| 189 |
|
|---|
| 190 | Expression *get_arg() const { return arg; }
|
|---|
| 191 | void set_arg(Expression *newValue ) { arg = newValue; }
|
|---|
| 192 |
|
|---|
| 193 | virtual CastExpr *clone() const { return new CastExpr( *this ); }
|
|---|
| 194 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 195 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 196 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 197 |
|
|---|
| 198 | private:
|
|---|
| 199 | Expression *arg;
|
|---|
| 200 | };
|
|---|
| 201 |
|
|---|
| 202 | // UntypedMemberExpr represents a member selection operation, e.g. q.p
|
|---|
| 203 | // before processing by the expression analyzer
|
|---|
| 204 | class UntypedMemberExpr : public Expression
|
|---|
| 205 | {
|
|---|
| 206 | public:
|
|---|
| 207 | UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = 0 );
|
|---|
| 208 | UntypedMemberExpr( const UntypedMemberExpr &other );
|
|---|
| 209 | virtual ~UntypedMemberExpr();
|
|---|
| 210 |
|
|---|
| 211 | std::string get_member() const { return member; }
|
|---|
| 212 | void set_member( const std::string &newValue ) { member = newValue; }
|
|---|
| 213 | Expression *get_aggregate() const { return aggregate; }
|
|---|
| 214 | void set_aggregate( Expression *newValue ) { aggregate = newValue; }
|
|---|
| 215 |
|
|---|
| 216 | virtual UntypedMemberExpr *clone() const { return new UntypedMemberExpr( *this ); }
|
|---|
| 217 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 218 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 219 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 220 |
|
|---|
| 221 | private:
|
|---|
| 222 | std::string member;
|
|---|
| 223 | Expression *aggregate;
|
|---|
| 224 | };
|
|---|
| 225 |
|
|---|
| 226 | // MemberExpr represents a member selection operation, e.g. q.p
|
|---|
| 227 | // after processing by the expression analyzer
|
|---|
| 228 | class MemberExpr : public Expression
|
|---|
| 229 | {
|
|---|
| 230 | public:
|
|---|
| 231 | MemberExpr( DeclarationWithType *member, Expression *aggregate, Expression *_aname = 0 );
|
|---|
| 232 | MemberExpr( const MemberExpr &other );
|
|---|
| 233 | virtual ~MemberExpr();
|
|---|
| 234 |
|
|---|
| 235 | DeclarationWithType *get_member() const { return member; }
|
|---|
| 236 | void set_member( DeclarationWithType *newValue ) { member = newValue; }
|
|---|
| 237 | Expression *get_aggregate() const { return aggregate; }
|
|---|
| 238 | void set_aggregate( Expression *newValue ) { aggregate = newValue; }
|
|---|
| 239 |
|
|---|
| 240 | virtual MemberExpr *clone() const { return new MemberExpr( *this ); }
|
|---|
| 241 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 242 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 243 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 244 |
|
|---|
| 245 | private:
|
|---|
| 246 | DeclarationWithType *member;
|
|---|
| 247 | Expression *aggregate;
|
|---|
| 248 | };
|
|---|
| 249 |
|
|---|
| 250 | // VariableExpr represents an expression that simply refers to the value of a named variable
|
|---|
| 251 | class VariableExpr : public Expression
|
|---|
| 252 | {
|
|---|
| 253 | public:
|
|---|
| 254 | VariableExpr( DeclarationWithType *var, Expression *_aname = 0 );
|
|---|
| 255 | VariableExpr( const VariableExpr &other );
|
|---|
| 256 | virtual ~VariableExpr();
|
|---|
| 257 |
|
|---|
| 258 | DeclarationWithType *get_var() const { return var; }
|
|---|
| 259 | void set_var( DeclarationWithType *newValue ) { var = newValue; }
|
|---|
| 260 |
|
|---|
| 261 | virtual VariableExpr *clone() const { return new VariableExpr( *this ); }
|
|---|
| 262 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 263 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 264 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 265 |
|
|---|
| 266 | private:
|
|---|
| 267 | DeclarationWithType *var;
|
|---|
| 268 | };
|
|---|
| 269 |
|
|---|
| 270 | // ConstantExpr represents an expression that simply refers to the value of a constant
|
|---|
| 271 | class ConstantExpr : public Expression
|
|---|
| 272 | {
|
|---|
| 273 | public:
|
|---|
| 274 | ConstantExpr( Constant constant, Expression *_aname = 0 );
|
|---|
| 275 | ConstantExpr( const ConstantExpr &other );
|
|---|
| 276 | virtual ~ConstantExpr();
|
|---|
| 277 |
|
|---|
| 278 | Constant *get_constant() { return &constant; }
|
|---|
| 279 | void set_constant( const Constant &newValue ) { constant = newValue; }
|
|---|
| 280 |
|
|---|
| 281 | virtual ConstantExpr *clone() const { return new ConstantExpr( *this ); }
|
|---|
| 282 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 283 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 284 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 285 |
|
|---|
| 286 | private:
|
|---|
| 287 | Constant constant;
|
|---|
| 288 | };
|
|---|
| 289 |
|
|---|
| 290 | // SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
|
|---|
| 291 | class SizeofExpr : public Expression
|
|---|
| 292 | {
|
|---|
| 293 | public:
|
|---|
| 294 | SizeofExpr( Expression *expr, Expression *_aname = 0 );
|
|---|
| 295 | SizeofExpr( const SizeofExpr &other );
|
|---|
| 296 | SizeofExpr( Type *type, Expression *_aname = 0 );
|
|---|
| 297 | virtual ~SizeofExpr();
|
|---|
| 298 |
|
|---|
| 299 | Expression *get_expr() const { return expr; }
|
|---|
| 300 | void set_expr( Expression *newValue ) { expr = newValue; }
|
|---|
| 301 | Type *get_type() const { return type; }
|
|---|
| 302 | void set_type( Type *newValue ) { type = newValue; }
|
|---|
| 303 | bool get_isType() const { return isType; }
|
|---|
| 304 | void set_isType( bool newValue ) { isType = newValue; }
|
|---|
| 305 |
|
|---|
| 306 | virtual SizeofExpr *clone() const { return new SizeofExpr( *this ); }
|
|---|
| 307 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 308 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 309 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 310 |
|
|---|
| 311 | private:
|
|---|
| 312 | Expression *expr;
|
|---|
| 313 | Type *type;
|
|---|
| 314 | bool isType;
|
|---|
| 315 | };
|
|---|
| 316 |
|
|---|
| 317 | // AttrExpr represents an @attribute expression (like sizeof, but user-defined)
|
|---|
| 318 | class AttrExpr : public Expression
|
|---|
| 319 | {
|
|---|
| 320 | public:
|
|---|
| 321 | AttrExpr(Expression *attr, Expression *expr, Expression *_aname = 0 );
|
|---|
| 322 | AttrExpr( const AttrExpr &other );
|
|---|
| 323 | AttrExpr( Expression *attr, Type *type, Expression *_aname = 0 );
|
|---|
| 324 | virtual ~AttrExpr();
|
|---|
| 325 |
|
|---|
| 326 | Expression *get_attr() const { return attr; }
|
|---|
| 327 | void set_attr( Expression *newValue ) { attr = newValue; }
|
|---|
| 328 | Expression *get_expr() const { return expr; }
|
|---|
| 329 | void set_expr( Expression *newValue ) { expr = newValue; }
|
|---|
| 330 | Type *get_type() const { return type; }
|
|---|
| 331 | void set_type( Type *newValue ) { type = newValue; }
|
|---|
| 332 | bool get_isType() const { return isType; }
|
|---|
| 333 | void set_isType( bool newValue ) { isType = newValue; }
|
|---|
| 334 |
|
|---|
| 335 | virtual AttrExpr *clone() const { return new AttrExpr( *this ); }
|
|---|
| 336 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 337 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 338 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 339 |
|
|---|
| 340 | private:
|
|---|
| 341 | Expression *attr;
|
|---|
| 342 | Expression *expr;
|
|---|
| 343 | Type *type;
|
|---|
| 344 | bool isType;
|
|---|
| 345 | };
|
|---|
| 346 |
|
|---|
| 347 | // LogicalExpr represents a short-circuit boolean expression (&& or ||)
|
|---|
| 348 | class LogicalExpr : public Expression
|
|---|
| 349 | {
|
|---|
| 350 | public:
|
|---|
| 351 | LogicalExpr( Expression *arg1, Expression *arg2, bool andp = true, Expression *_aname = 0 );
|
|---|
| 352 | LogicalExpr( const LogicalExpr &other );
|
|---|
| 353 | virtual ~LogicalExpr();
|
|---|
| 354 |
|
|---|
| 355 | bool get_isAnd() const { return isAnd; }
|
|---|
| 356 | Expression *get_arg1() { return arg1; }
|
|---|
| 357 | void set_arg1( Expression *newValue ) { arg1 = newValue; }
|
|---|
| 358 | Expression *get_arg2() const { return arg2; }
|
|---|
| 359 | void set_arg2( Expression *newValue ) { arg2 = newValue; }
|
|---|
| 360 |
|
|---|
| 361 | virtual LogicalExpr *clone() const { return new LogicalExpr( *this ); }
|
|---|
| 362 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 363 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 364 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 365 |
|
|---|
| 366 | private:
|
|---|
| 367 | Expression *arg1;
|
|---|
| 368 | Expression *arg2;
|
|---|
| 369 | bool isAnd;
|
|---|
| 370 | };
|
|---|
| 371 |
|
|---|
| 372 | // ConditionalExpr represents the three-argument conditional ( p ? a : b )
|
|---|
| 373 | class ConditionalExpr : public Expression
|
|---|
| 374 | {
|
|---|
| 375 | public:
|
|---|
| 376 | ConditionalExpr( Expression *arg1, Expression *arg2, Expression *arg3, Expression *_aname = 0 );
|
|---|
| 377 | ConditionalExpr( const ConditionalExpr &other );
|
|---|
| 378 | virtual ~ConditionalExpr();
|
|---|
| 379 |
|
|---|
| 380 | Expression *get_arg1() const { return arg1; }
|
|---|
| 381 | void set_arg1( Expression *newValue ) { arg1 = newValue; }
|
|---|
| 382 | Expression *get_arg2() const { return arg2; }
|
|---|
| 383 | void set_arg2( Expression *newValue ) { arg2 = newValue; }
|
|---|
| 384 | Expression *get_arg3() const { return arg3; }
|
|---|
| 385 | void set_arg3( Expression *newValue ) { arg3 = newValue; }
|
|---|
| 386 |
|
|---|
| 387 | virtual ConditionalExpr *clone() const { return new ConditionalExpr( *this ); }
|
|---|
| 388 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 389 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 390 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 391 |
|
|---|
| 392 | private:
|
|---|
| 393 | Expression *arg1;
|
|---|
| 394 | Expression *arg2;
|
|---|
| 395 | Expression *arg3;
|
|---|
| 396 | };
|
|---|
| 397 |
|
|---|
| 398 | // CommaExpr represents the sequence operator ( a, b )
|
|---|
| 399 | class CommaExpr : public Expression
|
|---|
| 400 | {
|
|---|
| 401 | public:
|
|---|
| 402 | CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname = 0 );
|
|---|
| 403 | CommaExpr( const CommaExpr &other );
|
|---|
| 404 | virtual ~CommaExpr();
|
|---|
| 405 |
|
|---|
| 406 | Expression *get_arg1() const { return arg1; }
|
|---|
| 407 | void set_arg1( Expression *newValue ) { arg1 = newValue; }
|
|---|
| 408 | Expression *get_arg2() const { return arg2; }
|
|---|
| 409 | void set_arg2( Expression *newValue ) { arg2 = newValue; }
|
|---|
| 410 |
|
|---|
| 411 | virtual CommaExpr *clone() const { return new CommaExpr( *this ); }
|
|---|
| 412 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 413 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 414 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 415 |
|
|---|
| 416 | private:
|
|---|
| 417 | Expression *arg1;
|
|---|
| 418 | Expression *arg2;
|
|---|
| 419 | };
|
|---|
| 420 |
|
|---|
| 421 | // TupleExpr represents a tuple expression ( [a, b, c] )
|
|---|
| 422 | class TupleExpr : public Expression
|
|---|
| 423 | {
|
|---|
| 424 | public:
|
|---|
| 425 | TupleExpr( Expression *_aname = 0 );
|
|---|
| 426 | TupleExpr( const TupleExpr &other );
|
|---|
| 427 | virtual ~TupleExpr();
|
|---|
| 428 |
|
|---|
| 429 | void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
|
|---|
| 430 | std::list<Expression*>& get_exprs() { return exprs; }
|
|---|
| 431 |
|
|---|
| 432 | virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
|
|---|
| 433 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 434 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 435 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 436 |
|
|---|
| 437 | private:
|
|---|
| 438 | std::list<Expression*> exprs;
|
|---|
| 439 | };
|
|---|
| 440 |
|
|---|
| 441 | // SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
|
|---|
| 442 | class SolvedTupleExpr : public Expression
|
|---|
| 443 | {
|
|---|
| 444 | public:
|
|---|
| 445 |
|
|---|
| 446 | SolvedTupleExpr( Expression *_aname = 0 ) : Expression( _aname ) {}
|
|---|
| 447 | SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = 0 );
|
|---|
| 448 | SolvedTupleExpr( const SolvedTupleExpr &other );
|
|---|
| 449 | virtual ~SolvedTupleExpr() {}
|
|---|
| 450 |
|
|---|
| 451 | std::list<Expression*> &get_exprs() { return exprs; }
|
|---|
| 452 |
|
|---|
| 453 | virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); }
|
|---|
| 454 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 455 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 456 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 457 | private:
|
|---|
| 458 | std::list<Expression*> exprs;
|
|---|
| 459 | };
|
|---|
| 460 |
|
|---|
| 461 | // TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
|
|---|
| 462 | class TypeExpr : public Expression
|
|---|
| 463 | {
|
|---|
| 464 | public:
|
|---|
| 465 | TypeExpr( Type *type );
|
|---|
| 466 | TypeExpr( const TypeExpr &other );
|
|---|
| 467 | virtual ~TypeExpr();
|
|---|
| 468 |
|
|---|
| 469 | Type *get_type() const { return type; }
|
|---|
| 470 | void set_type( Type *newValue ) { type = newValue; }
|
|---|
| 471 |
|
|---|
| 472 | virtual TypeExpr *clone() const { return new TypeExpr( *this ); }
|
|---|
| 473 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 474 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 475 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 476 |
|
|---|
| 477 | private:
|
|---|
| 478 | Type *type;
|
|---|
| 479 | };
|
|---|
| 480 |
|
|---|
| 481 | // ValofExpr represents a GCC 'lambda expression'
|
|---|
| 482 | class UntypedValofExpr : public Expression
|
|---|
| 483 | {
|
|---|
| 484 | public:
|
|---|
| 485 | UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {}
|
|---|
| 486 | virtual ~UntypedValofExpr() {}
|
|---|
| 487 |
|
|---|
| 488 | Expression *get_value();
|
|---|
| 489 | Statement *get_body() const { return body; }
|
|---|
| 490 |
|
|---|
| 491 | virtual UntypedValofExpr *clone() const { return new UntypedValofExpr( *this ); }
|
|---|
| 492 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
|---|
| 493 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
|---|
| 494 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 495 |
|
|---|
| 496 | private:
|
|---|
| 497 | Statement *body;
|
|---|
| 498 | };
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 | #endif /* #ifndef EXPRESSION_H */
|
|---|
| 502 |
|
|---|
| 503 | /*
|
|---|
| 504 | Local Variables:
|
|---|
| 505 | mode: c++
|
|---|
| 506 | End:
|
|---|
| 507 | */
|
|---|