@@ -76,6 +76,13 @@ class TranslatedDeclStmt extends TranslatedStmt {
76
76
77
77
private int getChildCount ( ) { result = count ( getDeclarationEntry ( _) ) }
78
78
79
+ PseudoDeclarationEntry getPseudoDeclarationEntry ( int index ) {
80
+ result .hasIndex ( index ) and
81
+ result .getStmt ( ) = stmt
82
+ }
83
+
84
+ PseudoDeclarationEntry getAPseudoDeclarationEntry ( ) { result = this .getPseudoDeclarationEntry ( _) }
85
+
79
86
/**
80
87
* Gets the `TranslatedDeclarationEntry` child at zero-based index `index`. Since not all
81
88
* `DeclarationEntry` objects have a `TranslatedDeclarationEntry` (e.g. extern functions), we map
@@ -85,7 +92,7 @@ class TranslatedDeclStmt extends TranslatedStmt {
85
92
private TranslatedDeclarationEntry getDeclarationEntry ( int index ) {
86
93
result =
87
94
rank [ index + 1 ] ( TranslatedDeclarationEntry entry , int originalIndex |
88
- entry = getTranslatedDeclarationEntry ( stmt . getDeclarationEntry ( originalIndex ) )
95
+ entry = getTranslatedDeclarationEntry ( this . getPseudoDeclarationEntry ( originalIndex ) )
89
96
|
90
97
entry order by originalIndex
91
98
)
@@ -597,36 +604,32 @@ class TranslatedRangeBasedForStmt extends TranslatedStmt, ConditionContext {
597
604
override RangeBasedForStmt stmt ;
598
605
599
606
override TranslatedElement getChild ( int id ) {
600
- id = 0 and result = getRangeVariableDeclaration ( )
607
+ id = 0 and result = getRangeVariableDeclStmt ( )
601
608
or
602
- id = 1 and result = getBeginVariableDeclaration ( )
609
+ // Note: `__begin` and `__end` are declared by the same `DeclStmt`
610
+ id = 1 and result = getBeginEndVariableDeclStmt ( )
603
611
or
604
- id = 2 and result = getEndVariableDeclaration ( )
612
+ id = 2 and result = getCondition ( )
605
613
or
606
- id = 3 and result = getCondition ( )
614
+ id = 3 and result = getUpdate ( )
607
615
or
608
- id = 4 and result = getUpdate ( )
616
+ id = 4 and result = getVariableDeclStmt ( )
609
617
or
610
- id = 5 and result = getVariableDeclaration ( )
611
- or
612
- id = 6 and result = getBody ( )
618
+ id = 5 and result = getBody ( )
613
619
}
614
620
615
621
override Instruction getFirstInstruction ( ) {
616
- result = getRangeVariableDeclaration ( ) .getFirstInstruction ( )
622
+ result = getRangeVariableDeclStmt ( ) .getFirstInstruction ( )
617
623
}
618
624
619
625
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 ( )
625
628
or
626
- child = getEndVariableDeclaration ( ) and
629
+ child = getBeginEndVariableDeclStmt ( ) and
627
630
result = getCondition ( ) .getFirstInstruction ( )
628
631
or
629
- child = getVariableDeclaration ( ) and
632
+ child = getVariableDeclStmt ( ) and
630
633
result = getBody ( ) .getFirstInstruction ( )
631
634
or
632
635
child = getBody ( ) and
@@ -643,23 +646,25 @@ class TranslatedRangeBasedForStmt extends TranslatedStmt, ConditionContext {
643
646
override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) { none ( ) }
644
647
645
648
override Instruction getChildTrueSuccessor ( TranslatedCondition child ) {
646
- child = getCondition ( ) and result = getVariableDeclaration ( ) .getFirstInstruction ( )
649
+ child = getCondition ( ) and result = getVariableDeclStmt ( ) .getFirstInstruction ( )
647
650
}
648
651
649
652
override Instruction getChildFalseSuccessor ( TranslatedCondition child ) {
650
653
child = getCondition ( ) and result = getParent ( ) .getChildSuccessor ( this )
651
654
}
652
655
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
+ )
659
661
}
660
662
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
+ )
663
668
}
664
669
665
670
// Public for getInstructionBackEdgeSuccessor
@@ -672,8 +677,11 @@ class TranslatedRangeBasedForStmt extends TranslatedStmt, ConditionContext {
672
677
result = getTranslatedExpr ( stmt .getUpdate ( ) .getFullyConverted ( ) )
673
678
}
674
679
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
+ )
677
685
}
678
686
679
687
private TranslatedStmt getBody ( ) { result = getTranslatedStmt ( stmt .getStmt ( ) ) }
0 commit comments