Changes in src/SynTree/Expression.h [8688ce1:7f5566b]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.h
r8688ce1 r7f5566b 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Expression.h -- 7 // Expression.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 3 17:08:44 201613 // Update Count : 2712 // Last Modified On : Fri Jul 24 13:49:28 2015 13 // Update Count : 18 14 14 // 15 15 … … 18 18 19 19 #include <map> 20 #include <memory>21 20 #include "SynTree.h" 22 21 #include "Visitor.h" 23 22 #include "Mutator.h" 24 23 #include "Constant.h" 25 #include "Common/UniqueName.h" 26 27 /// Expression is the root type for all expressions 24 28 25 class Expression { 29 26 public: … … 39 36 Expression *get_argName() const { return argName; } 40 37 void set_argName( Expression *name ) { argName = name; } 41 bool get_extension() const { return extension; }42 Expression * set_extension( bool exten ) { extension = exten; return this; }43 38 44 39 virtual Expression *clone() const = 0; … … 50 45 TypeSubstitution *env; 51 46 Expression* argName; // if expression is used as an argument, it can be "designated" by this name 52 bool extension = false;53 }; 54 55 // / ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,56 /// but subject to decay-to-pointer and type parameter renaming 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 57 52 struct ParamEntry { 58 53 ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {} … … 70 65 typedef std::map< UniqueId, ParamEntry > InferredParams; 71 66 72 /// ApplicationExpr represents the application of a function to a set of parameters. This is the 73 /// result of running an UntypedExpr through the expression analyzer. 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 74 70 class ApplicationExpr : public Expression { 75 71 public: … … 93 89 }; 94 90 95 /// UntypedExpr represents the application of a function to a set of parameters, but where the 96 /// particular overload for the function name has not yet been determined. Most operators are 97 /// converted into functional form automatically, to permit operator overloading. 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 98 95 class UntypedExpr : public Expression { 99 96 public: … … 121 118 }; 122 119 123 // / NameExprcontains a name whose meaning is still not determined120 // this class contains a name whose meaning is still not determined 124 121 class NameExpr : public Expression { 125 122 public: … … 142 139 // function-call format. 143 140 144 // /AddressExpr represents a address-of expression, e.g. &e141 // AddressExpr represents a address-of expression, e.g. &e 145 142 class AddressExpr : public Expression { 146 143 public: … … 160 157 }; 161 158 162 // xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack163 159 class LabelAddressExpr : public Expression { 164 160 public: 165 161 LabelAddressExpr( Expression *arg ); 166 LabelAddressExpr( const LabelAddressExpr &other );162 LabelAddressExpr( const AddressExpr &other ); 167 163 virtual ~LabelAddressExpr(); 168 164 … … 178 174 }; 179 175 180 // /CastExpr represents a type cast expression, e.g. (int)e176 // CastExpr represents a type cast expression, e.g. (int)e 181 177 class CastExpr : public Expression { 182 178 public: … … 197 193 }; 198 194 199 // /UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer195 // UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer 200 196 class UntypedMemberExpr : public Expression { 201 197 public: … … 218 214 }; 219 215 220 // /MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer216 // MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer 221 217 class MemberExpr : public Expression { 222 218 public: … … 239 235 }; 240 236 241 // /VariableExpr represents an expression that simply refers to the value of a named variable237 // VariableExpr represents an expression that simply refers to the value of a named variable 242 238 class VariableExpr : public Expression { 243 239 public: … … 257 253 }; 258 254 259 // / ConstantExpr represents an expression that simply refers to the value of a constant255 // ConstantExpr represents an expression that simply refers to the value of a constant 260 256 class ConstantExpr : public Expression { 261 257 public: … … 275 271 }; 276 272 277 // /SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)273 // SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4) 278 274 class SizeofExpr : public Expression { 279 275 public: … … 300 296 }; 301 297 302 /// AlignofExpr represents an alignof expression 303 class AlignofExpr : public Expression { 304 public: 305 AlignofExpr( Expression *expr, Expression *_aname = 0 ); 306 AlignofExpr( const AlignofExpr &other ); 307 AlignofExpr( Type *type, Expression *_aname = 0 ); 308 virtual ~AlignofExpr(); 309 310 Expression *get_expr() const { return expr; } 311 void set_expr( Expression *newValue ) { expr = newValue; } 312 Type *get_type() const { return type; } 313 void set_type( Type *newValue ) { type = newValue; } 314 bool get_isType() const { return isType; } 315 void set_isType( bool newValue ) { isType = newValue; } 316 317 virtual AlignofExpr *clone() const { return new AlignofExpr( *this ); } 318 virtual void accept( Visitor &v ) { v.visit( this ); } 319 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 320 virtual void print( std::ostream &os, int indent = 0 ) const; 321 private: 322 Expression *expr; 323 Type *type; 324 bool isType; 325 }; 326 327 /// UntypedOffsetofExpr represents an offsetof expression before resolution 328 class UntypedOffsetofExpr : public Expression { 329 public: 330 UntypedOffsetofExpr( Type *type, const std::string &member, Expression *_aname = 0 ); 331 UntypedOffsetofExpr( const UntypedOffsetofExpr &other ); 332 virtual ~UntypedOffsetofExpr(); 333 334 std::string get_member() const { return member; } 335 void set_member( const std::string &newValue ) { member = newValue; } 336 Type *get_type() const { return type; } 337 void set_type( Type *newValue ) { type = newValue; } 338 339 virtual UntypedOffsetofExpr *clone() const { return new UntypedOffsetofExpr( *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 Type *type; 345 std::string member; 346 }; 347 348 /// OffsetofExpr represents an offsetof expression 349 class OffsetofExpr : public Expression { 350 public: 351 OffsetofExpr( Type *type, DeclarationWithType *member, Expression *_aname = 0 ); 352 OffsetofExpr( const OffsetofExpr &other ); 353 virtual ~OffsetofExpr(); 354 355 Type *get_type() const { return type; } 356 void set_type( Type *newValue ) { type = newValue; } 357 DeclarationWithType *get_member() const { return member; } 358 void set_member( DeclarationWithType *newValue ) { member = newValue; } 359 360 virtual OffsetofExpr *clone() const { return new OffsetofExpr( *this ); } 361 virtual void accept( Visitor &v ) { v.visit( this ); } 362 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 363 virtual void print( std::ostream &os, int indent = 0 ) const; 364 private: 365 Type *type; 366 DeclarationWithType *member; 367 }; 368 369 /// Expression representing a pack of field-offsets for a generic type 370 class OffsetPackExpr : public Expression { 371 public: 372 OffsetPackExpr( StructInstType *type_, Expression *aname_ = 0 ); 373 OffsetPackExpr( const OffsetPackExpr &other ); 374 virtual ~OffsetPackExpr(); 375 376 StructInstType *get_type() const { return type; } 377 void set_type( StructInstType *newValue ) { type = newValue; } 378 379 virtual OffsetPackExpr *clone() const { return new OffsetPackExpr( *this ); } 380 virtual void accept( Visitor &v ) { v.visit( this ); } 381 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 382 383 virtual void print( std::ostream &os, int indent = 0 ) const; 384 385 private: 386 StructInstType *type; 387 }; 388 389 /// AttrExpr represents an @attribute expression (like sizeof, but user-defined) 298 // AttrExpr represents an @attribute expression (like sizeof, but user-defined) 390 299 class AttrExpr : public Expression { 391 300 public: … … 415 324 }; 416 325 417 // /LogicalExpr represents a short-circuit boolean expression (&& or ||)326 // LogicalExpr represents a short-circuit boolean expression (&& or ||) 418 327 class LogicalExpr : public Expression { 419 328 public: … … 438 347 }; 439 348 440 // /ConditionalExpr represents the three-argument conditional ( p ? a : b )349 // ConditionalExpr represents the three-argument conditional ( p ? a : b ) 441 350 class ConditionalExpr : public Expression { 442 351 public: … … 462 371 }; 463 372 464 // /CommaExpr represents the sequence operator ( a, b )373 // CommaExpr represents the sequence operator ( a, b ) 465 374 class CommaExpr : public Expression { 466 375 public: … … 483 392 }; 484 393 485 // /TupleExpr represents a tuple expression ( [a, b, c] )394 // TupleExpr represents a tuple expression ( [a, b, c] ) 486 395 class TupleExpr : public Expression { 487 396 public: … … 501 410 }; 502 411 503 // /SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on412 // SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on 504 413 class SolvedTupleExpr : public Expression { 505 414 public: … … 519 428 }; 520 429 521 // /TypeExpr represents a type used in an expression (e.g. as a type generator parameter)430 // TypeExpr represents a type used in an expression (e.g. as a type generator parameter) 522 431 class TypeExpr : public Expression { 523 432 public: … … 537 446 }; 538 447 539 // /AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)448 // AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result) 540 449 class AsmExpr : public Expression { 541 450 public: 542 451 AsmExpr( Expression *inout, ConstantExpr *constraint, Expression *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} 543 AsmExpr( const AsmExpr & other );544 452 virtual ~AsmExpr() { delete inout; delete constraint; delete operand; }; 545 453 … … 564 472 }; 565 473 566 /// ImplicitCopyCtorExpr represents the application of a function to a set of parameters, 567 /// along with a set of copy constructor calls, one for each argument. 568 class ImplicitCopyCtorExpr : public Expression { 569 public: 570 ImplicitCopyCtorExpr( ApplicationExpr * callExpr ); 571 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ); 572 virtual ~ImplicitCopyCtorExpr(); 573 574 ApplicationExpr *get_callExpr() const { return callExpr; } 575 void set_callExpr( ApplicationExpr *newValue ) { callExpr = newValue; } 576 577 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; } 578 void set_tempDecls( std::list< ObjectDecl * > newValue ) { tempDecls = newValue; } 579 580 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; } 581 void set_returnDecls( std::list< ObjectDecl * > newValue ) { returnDecls = newValue; } 582 583 std::list< Expression * > & get_dtors() { return dtors; } 584 void set_dtors( std::list< Expression * > newValue ) { dtors = newValue; } 585 586 virtual ImplicitCopyCtorExpr *clone() const { return new ImplicitCopyCtorExpr( *this ); } 587 virtual void accept( Visitor &v ) { v.visit( this ); } 588 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 589 virtual void print( std::ostream &os, int indent = 0 ) const; 590 private: 591 ApplicationExpr * callExpr; 592 std::list< ObjectDecl * > tempDecls; 593 std::list< ObjectDecl * > returnDecls; 594 std::list< Expression * > dtors; 595 }; 596 597 /// ValofExpr represents a GCC 'lambda expression' 474 // ValofExpr represents a GCC 'lambda expression' 598 475 class UntypedValofExpr : public Expression { 599 476 public: 600 477 UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {} 601 UntypedValofExpr( const UntypedValofExpr & other ); 602 virtual ~UntypedValofExpr(); 478 virtual ~UntypedValofExpr() {} 603 479 604 480 Expression *get_value(); … … 612 488 Statement *body; 613 489 }; 614 615 /// CompoundLiteralExpr represents a C99 'compound literal'616 class CompoundLiteralExpr : public Expression {617 public:618 CompoundLiteralExpr( Type * type, Initializer * initializer );619 CompoundLiteralExpr( const CompoundLiteralExpr &other );620 ~CompoundLiteralExpr();621 622 Type * get_type() const { return type; }623 void set_type( Type * t ) { type = t; }624 625 Initializer * get_initializer() const { return initializer; }626 void set_initializer( Initializer * i ) { initializer = i; }627 628 virtual CompoundLiteralExpr *clone() const { return new CompoundLiteralExpr( *this ); }629 virtual void accept( Visitor &v ) { v.visit( this ); }630 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }631 virtual void print( std::ostream &os, int indent = 0 ) const;632 private:633 Type * type;634 Initializer * initializer;635 };636 637 class RangeExpr : public Expression {638 public:639 RangeExpr( ConstantExpr *low, ConstantExpr *high );640 RangeExpr( const RangeExpr &other );641 642 ConstantExpr * get_low() const { return low.get(); }643 ConstantExpr * get_high() const { return high.get(); }644 RangeExpr * set_low( ConstantExpr *low ) { RangeExpr::low.reset( low ); return this; }645 RangeExpr * set_high( ConstantExpr *high ) { RangeExpr::high.reset( high ); return this; }646 647 virtual RangeExpr *clone() const { return new RangeExpr( *this ); }648 virtual void accept( Visitor &v ) { v.visit( this ); }649 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }650 virtual void print( std::ostream &os, int indent = 0 ) const;651 private:652 std::unique_ptr<ConstantExpr> low, high;653 };654 655 std::ostream & operator<<( std::ostream & out, Expression * expr );656 490 657 491 #endif // EXPRESSION_H
Note:
See TracChangeset
for help on using the changeset viewer.