@@ -76,6 +76,13 @@ class TranslatedDeclStmt extends TranslatedStmt {
7676
7777 private int getChildCount ( ) { result = count ( getDeclarationEntry ( _) ) }
7878
79+ PseudoDeclarationEntry getPseudoDeclarationEntry ( int index ) {
80+ result .hasIndex ( index ) and
81+ result .getStmt ( ) = stmt
82+ }
83+
84+ PseudoDeclarationEntry getAPseudoDeclarationEntry ( ) { result = this .getPseudoDeclarationEntry ( _) }
85+
7986 /**
8087 * Gets the `TranslatedDeclarationEntry` child at zero-based index `index`. Since not all
8188 * `DeclarationEntry` objects have a `TranslatedDeclarationEntry` (e.g. extern functions), we map
@@ -85,7 +92,7 @@ class TranslatedDeclStmt extends TranslatedStmt {
8592 private TranslatedDeclarationEntry getDeclarationEntry ( int index ) {
8693 result =
8794 rank [ index + 1 ] ( TranslatedDeclarationEntry entry , int originalIndex |
88- entry = getTranslatedDeclarationEntry ( stmt . getDeclarationEntry ( originalIndex ) )
95+ entry = getTranslatedDeclarationEntry ( this . getPseudoDeclarationEntry ( originalIndex ) )
8996 |
9097 entry order by originalIndex
9198 )
@@ -597,36 +604,32 @@ class TranslatedRangeBasedForStmt extends TranslatedStmt, ConditionContext {
597604 override RangeBasedForStmt stmt ;
598605
599606 override TranslatedElement getChild ( int id ) {
600- id = 0 and result = getRangeVariableDeclaration ( )
607+ id = 0 and result = getRangeVariableDeclStmt ( )
601608 or
602- id = 1 and result = getBeginVariableDeclaration ( )
609+ // Note: `__begin` and `__end` are declared by the same `DeclStmt`
610+ id = 1 and result = getBeginEndVariableDeclStmt ( )
603611 or
604- id = 2 and result = getEndVariableDeclaration ( )
612+ id = 2 and result = getCondition ( )
605613 or
606- id = 3 and result = getCondition ( )
614+ id = 3 and result = getUpdate ( )
607615 or
608- id = 4 and result = getUpdate ( )
616+ id = 4 and result = getVariableDeclStmt ( )
609617 or
610- id = 5 and result = getVariableDeclaration ( )
611- or
612- id = 6 and result = getBody ( )
618+ id = 5 and result = getBody ( )
613619 }
614620
615621 override Instruction getFirstInstruction ( ) {
616- result = getRangeVariableDeclaration ( ) .getFirstInstruction ( )
622+ result = getRangeVariableDeclStmt ( ) .getFirstInstruction ( )
617623 }
618624
619625 override Instruction getChildSuccessor ( TranslatedElement child ) {
620- child = getRangeVariableDeclaration ( ) and
621- result = getBeginVariableDeclaration ( ) .getFirstInstruction ( )
622- or
623- child = getBeginVariableDeclaration ( ) and
624- result = getEndVariableDeclaration ( ) .getFirstInstruction ( )
626+ child = getRangeVariableDeclStmt ( ) and
627+ result = getBeginEndVariableDeclStmt ( ) .getFirstInstruction ( )
625628 or
626- child = getEndVariableDeclaration ( ) and
629+ child = getBeginEndVariableDeclStmt ( ) and
627630 result = getCondition ( ) .getFirstInstruction ( )
628631 or
629- child = getVariableDeclaration ( ) and
632+ child = getVariableDeclStmt ( ) and
630633 result = getBody ( ) .getFirstInstruction ( )
631634 or
632635 child = getBody ( ) and
@@ -643,23 +646,25 @@ class TranslatedRangeBasedForStmt extends TranslatedStmt, ConditionContext {
643646 override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) { none ( ) }
644647
645648 override Instruction getChildTrueSuccessor ( TranslatedCondition child ) {
646- child = getCondition ( ) and result = getVariableDeclaration ( ) .getFirstInstruction ( )
649+ child = getCondition ( ) and result = getVariableDeclStmt ( ) .getFirstInstruction ( )
647650 }
648651
649652 override Instruction getChildFalseSuccessor ( TranslatedCondition child ) {
650653 child = getCondition ( ) and result = getParent ( ) .getChildSuccessor ( this )
651654 }
652655
653- private TranslatedRangeBasedForVariableDeclaration getRangeVariableDeclaration ( ) {
654- result = getTranslatedRangeBasedForVariableDeclaration ( stmt .getRangeVariable ( ) )
655- }
656-
657- private TranslatedRangeBasedForVariableDeclaration getBeginVariableDeclaration ( ) {
658- result = getTranslatedRangeBasedForVariableDeclaration ( stmt .getBeginVariable ( ) )
656+ private TranslatedDeclStmt getRangeVariableDeclStmt ( ) {
657+ exists ( PseudoVariableDeclarationEntry entry |
658+ entry .getDeclaration ( ) = stmt .getRangeVariable ( ) and
659+ result .getAPseudoDeclarationEntry ( ) = entry
660+ )
659661 }
660662
661- private TranslatedRangeBasedForVariableDeclaration getEndVariableDeclaration ( ) {
662- result = getTranslatedRangeBasedForVariableDeclaration ( stmt .getEndVariable ( ) )
663+ private TranslatedDeclStmt getBeginEndVariableDeclStmt ( ) {
664+ exists ( PseudoVariableDeclarationEntry entry |
665+ entry .getStmt ( ) = stmt .getBeginEndDeclaration ( ) and
666+ result .getAPseudoDeclarationEntry ( ) = entry
667+ )
663668 }
664669
665670 // Public for getInstructionBackEdgeSuccessor
@@ -672,8 +677,11 @@ class TranslatedRangeBasedForStmt extends TranslatedStmt, ConditionContext {
672677 result = getTranslatedExpr ( stmt .getUpdate ( ) .getFullyConverted ( ) )
673678 }
674679
675- private TranslatedRangeBasedForVariableDeclaration getVariableDeclaration ( ) {
676- result = getTranslatedRangeBasedForVariableDeclaration ( stmt .getVariable ( ) )
680+ private TranslatedDeclStmt getVariableDeclStmt ( ) {
681+ exists ( PseudoVariableDeclarationEntry entry |
682+ entry .getDeclaration ( ) = stmt .getVariable ( ) and
683+ result .getAPseudoDeclarationEntry ( ) = entry
684+ )
677685 }
678686
679687 private TranslatedStmt getBody ( ) { result = getTranslatedStmt ( stmt .getStmt ( ) ) }
0 commit comments