@@ -389,7 +389,7 @@ class Node extends TIRDataFlowNode {
389
389
index = 0 and
390
390
result = this .( ExplicitParameterNode ) .getParameter ( )
391
391
or
392
- this .( IndirectParameterNode ) .hasInstructionAndIndirectionIndex ( _ , index ) and
392
+ this .( IndirectParameterNode ) .getIndirectionIndex ( ) = index and
393
393
result = this .( IndirectParameterNode ) .getParameter ( )
394
394
}
395
395
@@ -767,42 +767,6 @@ class FlowSummaryNode extends Node, TFlowSummaryNode {
767
767
override string toStringImpl ( ) { result = this .getSummaryNode ( ) .toString ( ) }
768
768
}
769
769
770
- /**
771
- * INTERNAL: do not use.
772
- *
773
- * A node representing an indirection of a parameter.
774
- */
775
- class IndirectParameterNode extends Node instanceof IndirectInstruction {
776
- InitializeParameterInstruction init ;
777
-
778
- IndirectParameterNode ( ) { IndirectInstruction .super .hasInstructionAndIndirectionIndex ( init , _) }
779
-
780
- int getArgumentIndex ( ) { init .hasIndex ( result ) }
781
-
782
- /** Gets the parameter whose indirection is initialized. */
783
- Parameter getParameter ( ) { result = init .getParameter ( ) }
784
-
785
- override Declaration getEnclosingCallable ( ) { result = this .getFunction ( ) }
786
-
787
- override Declaration getFunction ( ) { result = init .getEnclosingFunction ( ) }
788
-
789
- /** Gets the underlying operand and the underlying indirection index. */
790
- predicate hasInstructionAndIndirectionIndex ( Instruction instr , int index ) {
791
- IndirectInstruction .super .hasInstructionAndIndirectionIndex ( instr , index )
792
- }
793
-
794
- override Location getLocationImpl ( ) { result = this .getParameter ( ) .getLocation ( ) }
795
-
796
- override string toStringImpl ( ) {
797
- exists ( string prefix | prefix = stars ( this ) |
798
- result = prefix + this .getParameter ( ) .toString ( )
799
- or
800
- not exists ( this .getParameter ( ) ) and
801
- result = prefix + "this"
802
- )
803
- }
804
- }
805
-
806
770
/**
807
771
* INTERNAL: do not use.
808
772
*
@@ -1655,6 +1619,89 @@ class IndirectExprNode extends Node instanceof IndirectExprNodeBase {
1655
1619
}
1656
1620
}
1657
1621
1622
+ abstract private class AbstractParameterNode extends Node {
1623
+ /**
1624
+ * Holds if this node is the parameter of `f` at the specified position. The
1625
+ * implicit `this` parameter is considered to have position `-1`, and
1626
+ * pointer-indirection parameters are at further negative positions.
1627
+ */
1628
+ abstract predicate isParameterOf ( DataFlowCallable f , ParameterPosition pos ) ;
1629
+
1630
+ /** Gets the `Parameter` associated with this node, if it exists. */
1631
+ Parameter getParameter ( ) { none ( ) } // overridden by subclasses
1632
+ }
1633
+
1634
+ abstract private class AbstractIndirectParameterNode extends AbstractParameterNode {
1635
+ abstract int getIndirectionIndex ( ) ;
1636
+ }
1637
+
1638
+ /**
1639
+ * INTERNAL: do not use.
1640
+ *
1641
+ * A node representing an indirection of a parameter.
1642
+ */
1643
+ final class IndirectParameterNode = AbstractIndirectParameterNode ;
1644
+
1645
+ pragma [ noinline]
1646
+ private predicate indirectParameterNodeHasArgumentIndexAndIndex (
1647
+ IndirectInstructionParameterNode node , int argumentIndex , int indirectionIndex
1648
+ ) {
1649
+ node .hasInstructionAndIndirectionIndex ( _, indirectionIndex ) and
1650
+ node .getArgumentIndex ( ) = argumentIndex
1651
+ }
1652
+
1653
+ pragma [ noinline]
1654
+ private predicate indirectPositionHasArgumentIndexAndIndex (
1655
+ IndirectionPosition pos , int argumentIndex , int indirectionIndex
1656
+ ) {
1657
+ pos .getArgumentIndex ( ) = argumentIndex and
1658
+ pos .getIndirectionIndex ( ) = indirectionIndex
1659
+ }
1660
+
1661
+ private class IndirectInstructionParameterNode extends AbstractIndirectParameterNode instanceof IndirectInstruction
1662
+ {
1663
+ InitializeParameterInstruction init ;
1664
+
1665
+ IndirectInstructionParameterNode ( ) {
1666
+ IndirectInstruction .super .hasInstructionAndIndirectionIndex ( init , _)
1667
+ }
1668
+
1669
+ int getArgumentIndex ( ) { init .hasIndex ( result ) }
1670
+
1671
+ override Location getLocationImpl ( ) { result = IndirectInstruction .super .getLocationImpl ( ) }
1672
+
1673
+ override string toStringImpl ( ) {
1674
+ exists ( string prefix | prefix = stars ( this ) |
1675
+ result = prefix + this .getParameter ( ) .toString ( )
1676
+ or
1677
+ not exists ( this .getParameter ( ) ) and
1678
+ result = prefix + "this"
1679
+ )
1680
+ }
1681
+
1682
+ /** Gets the parameter whose indirection is initialized. */
1683
+ override Parameter getParameter ( ) { result = init .getParameter ( ) }
1684
+
1685
+ override Declaration getEnclosingCallable ( ) { result = this .getFunction ( ) }
1686
+
1687
+ override Declaration getFunction ( ) { result = init .getEnclosingFunction ( ) }
1688
+
1689
+ override predicate isParameterOf ( DataFlowCallable f , ParameterPosition pos ) {
1690
+ this .getEnclosingCallable ( ) = f .getUnderlyingCallable ( ) and
1691
+ exists ( int argumentIndex , int indirectionIndex |
1692
+ indirectPositionHasArgumentIndexAndIndex ( pos , argumentIndex , indirectionIndex ) and
1693
+ indirectParameterNodeHasArgumentIndexAndIndex ( this , argumentIndex , indirectionIndex )
1694
+ )
1695
+ }
1696
+
1697
+ /** Gets the underlying operand and the underlying indirection index. */
1698
+ predicate hasInstructionAndIndirectionIndex ( Instruction instr , int index ) {
1699
+ IndirectInstruction .super .hasInstructionAndIndirectionIndex ( instr , index )
1700
+ }
1701
+
1702
+ final override int getIndirectionIndex ( ) { this .hasInstructionAndIndirectionIndex ( init , result ) }
1703
+ }
1704
+
1658
1705
/**
1659
1706
* The value of a parameter at function entry, viewed as a node in a data
1660
1707
* flow graph. This includes both explicit parameters such as `x` in `f(x)`
@@ -1664,42 +1711,33 @@ class IndirectExprNode extends Node instanceof IndirectExprNodeBase {
1664
1711
* `ExplicitParameterNode`, `ThisParameterNode`, or
1665
1712
* `ParameterIndirectionNode`.
1666
1713
*/
1667
- class ParameterNode extends Node {
1668
- ParameterNode ( ) {
1669
- // To avoid making this class abstract, we enumerate its values here
1670
- this .asInstruction ( ) instanceof InitializeParameterInstruction
1671
- or
1672
- this instanceof IndirectParameterNode
1673
- or
1674
- FlowSummaryImpl:: Private:: summaryParameterNode ( this .( FlowSummaryNode ) .getSummaryNode ( ) , _)
1675
- }
1714
+ final class ParameterNode = AbstractParameterNode ;
1676
1715
1677
- /**
1678
- * Holds if this node is the parameter of `f` at the specified position. The
1679
- * implicit `this` parameter is considered to have position `-1`, and
1680
- * pointer-indirection parameters are at further negative positions.
1681
- */
1682
- predicate isParameterOf ( DataFlowCallable f , ParameterPosition pos ) { none ( ) } // overridden by subclasses
1683
-
1684
- /** Gets the `Parameter` associated with this node, if it exists. */
1685
- Parameter getParameter ( ) { none ( ) } // overridden by subclasses
1686
- }
1716
+ abstract private class AbstractDirectParameterNode extends AbstractParameterNode { }
1687
1717
1688
1718
/** An explicit positional parameter, including `this`, but not `...`. */
1689
- class DirectParameterNode extends InstructionNode {
1690
- override InitializeParameterInstruction instr ;
1719
+ final class DirectParameterNode = AbstractDirectParameterNode ;
1720
+
1721
+ abstract class InstructionDirectParameterNode extends InstructionNode , AbstractDirectParameterNode {
1722
+ final override InitializeParameterInstruction instr ;
1691
1723
1692
1724
/**
1693
1725
* INTERNAL: Do not use.
1694
1726
*
1695
1727
* Gets the `IRVariable` that this parameter references.
1696
1728
*/
1697
- IRVariable getIRVariable ( ) { result = instr .getIRVariable ( ) }
1729
+ final IRVariable getIRVariable ( ) { result = instr .getIRVariable ( ) }
1698
1730
}
1699
1731
1732
+ abstract private class AbstractExplicitParameterNode extends AbstractDirectParameterNode { }
1733
+
1734
+ final class ExplicitParameterNode = AbstractExplicitParameterNode ;
1735
+
1700
1736
/** An explicit positional parameter, not including `this` or `...`. */
1701
- private class ExplicitParameterNode extends ParameterNode , DirectParameterNode {
1702
- ExplicitParameterNode ( ) { exists ( instr .getParameter ( ) ) }
1737
+ private class ExplicitParameterInstructionNode extends AbstractExplicitParameterNode ,
1738
+ InstructionDirectParameterNode
1739
+ {
1740
+ ExplicitParameterInstructionNode ( ) { exists ( instr .getParameter ( ) ) }
1703
1741
1704
1742
override predicate isParameterOf ( DataFlowCallable f , ParameterPosition pos ) {
1705
1743
f .getUnderlyingCallable ( ) .( Function ) .getParameter ( pos .( DirectPosition ) .getIndex ( ) ) =
@@ -1712,8 +1750,10 @@ private class ExplicitParameterNode extends ParameterNode, DirectParameterNode {
1712
1750
}
1713
1751
1714
1752
/** An implicit `this` parameter. */
1715
- class ThisParameterNode extends ParameterNode , DirectParameterNode {
1716
- ThisParameterNode ( ) { instr .getIRVariable ( ) instanceof IRThisVariable }
1753
+ class ThisParameterInstructionNode extends AbstractExplicitParameterNode ,
1754
+ InstructionDirectParameterNode
1755
+ {
1756
+ ThisParameterInstructionNode ( ) { instr .getIRVariable ( ) instanceof IRThisVariable }
1717
1757
1718
1758
override predicate isParameterOf ( DataFlowCallable f , ParameterPosition pos ) {
1719
1759
pos .( DirectPosition ) .getIndex ( ) = - 1 and
@@ -1726,7 +1766,7 @@ class ThisParameterNode extends ParameterNode, DirectParameterNode {
1726
1766
/**
1727
1767
* A parameter node that is part of a summary.
1728
1768
*/
1729
- class SummaryParameterNode extends ParameterNode , FlowSummaryNode {
1769
+ class SummaryParameterNode extends AbstractParameterNode , FlowSummaryNode {
1730
1770
SummaryParameterNode ( ) {
1731
1771
FlowSummaryImpl:: Private:: summaryParameterNode ( this .getSummaryNode ( ) , _)
1732
1772
}
0 commit comments