Changeset c5f3c68
- Timestamp:
- Dec 1, 2017, 10:08:37 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 027c496
- Parents:
- 0a6aad4
- git-author:
- Rob Schluntz <rschlunt@…> (11/30/17 17:42:47)
- git-committer:
- Rob Schluntz <rschlunt@…> (12/01/17 10:08:37)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
r0a6aad4 rc5f3c68 539 539 } 540 540 541 class ConstExprChecker : public Visitor { 542 public: 543 ConstExprChecker() : isConstExpr( true ) {} 544 545 using Visitor::visit; 546 547 virtual void visit( ApplicationExpr * ) { isConstExpr = false; } 548 virtual void visit( UntypedExpr * ) { isConstExpr = false; } 549 virtual void visit( NameExpr * ) { isConstExpr = false; } 550 // virtual void visit( CastExpr *castExpr ) { isConstExpr = false; } 551 virtual void visit( AddressExpr *addressExpr ) { 541 struct ConstExprChecker : public WithShortCircuiting { 542 // most expressions are not const expr 543 void previsit( Expression * ) { isConstExpr = false; visit_children = false; } 544 545 void previsit( AddressExpr *addressExpr ) { 546 visit_children = false; 547 552 548 // address of a variable or member expression is constexpr 553 549 Expression * arg = addressExpr->get_arg(); 554 550 if ( ! dynamic_cast< NameExpr * >( arg) && ! dynamic_cast< VariableExpr * >( arg ) && ! dynamic_cast< MemberExpr * >( arg ) && ! dynamic_cast< UntypedMemberExpr * >( arg ) ) isConstExpr = false; 555 551 } 556 virtual void visit( UntypedMemberExpr * ) { isConstExpr = false; } 557 virtual void visit( MemberExpr * ) { isConstExpr = false; } 558 virtual void visit( VariableExpr * ) { isConstExpr = false; } 559 // these might be okay? 560 // virtual void visit( SizeofExpr *sizeofExpr ); 561 // virtual void visit( AlignofExpr *alignofExpr ); 562 // virtual void visit( UntypedOffsetofExpr *offsetofExpr ); 563 // virtual void visit( OffsetofExpr *offsetofExpr ); 564 // virtual void visit( OffsetPackExpr *offsetPackExpr ); 565 // virtual void visit( AttrExpr *attrExpr ); 566 // virtual void visit( CommaExpr *commaExpr ); 567 // virtual void visit( LogicalExpr *logicalExpr ); 568 // virtual void visit( ConditionalExpr *conditionalExpr ); 569 virtual void visit( TypeExpr * ) { isConstExpr = false; } 570 virtual void visit( AsmExpr * ) { isConstExpr = false; } 571 virtual void visit( UntypedValofExpr * ) { isConstExpr = false; } 572 virtual void visit( CompoundLiteralExpr * ) { isConstExpr = false; } 573 virtual void visit( UntypedTupleExpr * ) { isConstExpr = false; } 574 virtual void visit( TupleExpr * ) { isConstExpr = false; } 575 virtual void visit( TupleAssignExpr * ) { isConstExpr = false; } 576 577 bool isConstExpr; 552 553 // these expressions may be const expr, depending on their children 554 void previsit( SizeofExpr * ) {} 555 void previsit( AlignofExpr * ) {} 556 void previsit( UntypedOffsetofExpr * ) {} 557 void previsit( OffsetofExpr * ) {} 558 void previsit( OffsetPackExpr * ) {} 559 void previsit( AttrExpr * ) {} 560 void previsit( CommaExpr * ) {} 561 void previsit( LogicalExpr * ) {} 562 void previsit( ConditionalExpr * ) {} 563 void previsit( CastExpr * ) {} 564 void previsit( ConstantExpr * ) {} 565 566 bool isConstExpr = true; 578 567 }; 579 568 580 569 bool isConstExpr( Expression * expr ) { 581 570 if ( expr ) { 582 ConstExprCheckerchecker;571 PassVisitor<ConstExprChecker> checker; 583 572 expr->accept( checker ); 584 return checker. isConstExpr;573 return checker.pass.isConstExpr; 585 574 } 586 575 return true; … … 589 578 bool isConstExpr( Initializer * init ) { 590 579 if ( init ) { 591 ConstExprCheckerchecker;580 PassVisitor<ConstExprChecker> checker; 592 581 init->accept( checker ); 593 return checker. isConstExpr;582 return checker.pass.isConstExpr; 594 583 } // if 595 584 // for all intents and purposes, no initializer means const expr
Note: See TracChangeset
for help on using the changeset viewer.