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