Merge pull request #11654 from hvitved/ruby/stage-collapse

Ruby: Ensure `Node::{toString,getLocation}` are computed in data flow stage
This commit is contained in:
Tom Hvitved
2022-12-12 13:57:47 +01:00
committed by GitHub
3 changed files with 18 additions and 15 deletions

View File

@@ -340,6 +340,12 @@ private module Cached {
p.(KeywordParameter).getDefaultValue() = e.getExprNode().getExpr()
}
cached
Location getLocation(NodeImpl n) { result = n.getLocationImpl() }
cached
string toString(NodeImpl n) { result = n.toStringImpl() }
/**
* This is the local flow predicate that is used as a building block in global
* data flow.

View File

@@ -19,12 +19,10 @@ class Node extends TNode {
Parameter asParameter() { result = this.(ParameterNode).getParameter() }
/** Gets a textual representation of this node. */
cached
final string toString() { result = this.(NodeImpl).toStringImpl() }
final string toString() { result = toString(this) }
/** Gets the location of this node. */
cached
final Location getLocation() { result = this.(NodeImpl).getLocationImpl() }
final Location getLocation() { result = getLocation(this) }
/**
* Holds if this element is at the specified location.

View File

@@ -140,10 +140,9 @@ module Array {
}
}
private class SetDifferenceSummary extends SummarizedCallable {
SetDifferenceSummary() { this = "-" }
override SubExpr getACallSimple() { any() }
abstract private class DifferenceSummaryShared extends SummarizedCallable {
bindingset[this]
DifferenceSummaryShared() { any() }
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
input = "Argument[self].Element[any]" and
@@ -152,6 +151,12 @@ module Array {
}
}
private class SetDifferenceSummary extends DifferenceSummaryShared {
SetDifferenceSummary() { this = "-" }
override SubExpr getACallSimple() { any() }
}
/** Flow summary for `Array#<<`. For `Array#append`, see `PushSummary`. */
private class AppendOperatorSummary extends SummarizedCallable {
AppendOperatorSummary() { this = "<<" }
@@ -687,14 +692,8 @@ module Array {
}
}
private class DifferenceSummary extends SimpleSummarizedCallable {
private class DifferenceSummary extends DifferenceSummaryShared, SimpleSummarizedCallable {
DifferenceSummary() { this = "difference" }
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
// `Array#difference` and `Array#-` do not behave exactly the same way,
// but we model their flow the same way.
any(SetDifferenceSummary s).propagatesFlowExt(input, output, preservesValue)
}
}
private string getDigArg(MethodCall dig, int i) {