Changeset 6a036eb
- Timestamp:
- Oct 30, 2020, 5:15:47 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- ea3fa25
- Parents:
- 0e707bd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInitNew.cpp
r0e707bd r6a036eb 357 357 // if two expressions are "the same" (used to determine if self assignment occurs) 358 358 struct StructuralChecker { 359 const ast::Expr * stripCasts( const ast::Expr * expr ) { 359 // Strip all casts and then dynamic_cast. 360 template<typename T> 361 static const T * cast( const ast::Expr * expr ) { 360 362 // this might be too permissive. It's possible that only particular casts are relevant. 361 363 while ( auto cast = dynamic_cast< const ast::CastExpr * >( expr ) ) { 362 364 expr = cast->arg; 363 365 } 364 return expr;366 return dynamic_cast< const T * >( expr ); 365 367 } 366 368 367 369 void previsit( const ast::Expr * ) { 368 370 // anything else does not qualify 369 isSimilar = false; 370 } 371 372 template<typename T> 373 T * cast( const ast::Expr * node ) { 374 // all expressions need to ignore casts, so this bit has been factored out 375 return dynamic_cast< T * >( stripCasts( node ) ); 371 result = false; 376 372 } 377 373 … … 380 376 381 377 void previsit( const ast::MemberExpr * memExpr ) { 382 if ( auto otherMember = cast< constast::MemberExpr >( other ) ) {378 if ( auto otherMember = cast< ast::MemberExpr >( other ) ) { 383 379 if ( otherMember->member == memExpr->member ) { 384 380 other = otherMember->aggregate; … … 386 382 } 387 383 } 388 isSimilar= false;384 result = false; 389 385 } 390 386 391 387 void previsit( const ast::VariableExpr * varExpr ) { 392 if ( auto otherVar = cast< constast::VariableExpr >( other ) ) {388 if ( auto otherVar = cast< ast::VariableExpr >( other ) ) { 393 389 if ( otherVar->var == varExpr->var ) { 394 390 return; 395 391 } 396 392 } 397 isSimilar= false;393 result = false; 398 394 } 399 395 400 396 void previsit( const ast::AddressExpr * ) { 401 if ( auto addrExpr = cast< constast::AddressExpr >( other ) ) {397 if ( auto addrExpr = cast< ast::AddressExpr >( other ) ) { 402 398 other = addrExpr->arg; 403 399 return; 404 400 } 405 isSimilar = false; 406 } 407 408 const ast::Expr * other = nullptr; 409 bool isSimilar = true; 401 result = false; 402 } 403 404 const ast::Expr * other; 405 bool result = true; 406 StructuralChecker( const ast::Expr * other ) : other(other) {} 410 407 }; 411 408 412 409 bool structurallySimilar( const ast::Expr * e1, const ast::Expr * e2 ) { 413 ast::Pass<StructuralChecker> checker; 414 checker.core.other = e2; 415 e1->accept( checker ); 416 return checker.core.isSimilar; 410 return ast::Pass<StructuralChecker>::read( e1, e2 ); 417 411 } 418 412
Note: See TracChangeset
for help on using the changeset viewer.