mirror of
https://github.com/github/codeql.git
synced 2026-04-27 09:45:15 +02:00
C#: Correct printing of out and ref notes in the model generator.
This commit is contained in:
@@ -233,6 +233,10 @@ module ModelGeneratorInput implements ModelGeneratorInputSig<Location, CsharpDat
|
||||
result = ParamReturnNodeAsOutput<parameterContentAccess/1>::paramReturnNodeAsOutput(c, pos)
|
||||
}
|
||||
|
||||
ParameterPosition getReturnKindParamPosition(ReturnKind kind) {
|
||||
kind.(OutRefReturnKind).getPosition() = result.getPosition()
|
||||
}
|
||||
|
||||
Callable returnNodeEnclosingCallable(DataFlow::Node ret) {
|
||||
result = DataFlowImplCommon::getNodeEnclosingCallable(ret).asCallable(_)
|
||||
}
|
||||
|
||||
@@ -221,6 +221,11 @@ signature module ModelGeneratorInputSig<LocationSig Location, InputSig<Location>
|
||||
*/
|
||||
string printContent(Lang::ContentSet c);
|
||||
|
||||
/**
|
||||
* Gets the parameter position of the return kind, if any.
|
||||
*/
|
||||
default Lang::ParameterPosition getReturnKindParamPosition(Lang::ReturnKind node) { none() }
|
||||
|
||||
/**
|
||||
* Holds if it is irrelevant to generate models for `api` based on data flow analysis.
|
||||
*
|
||||
@@ -301,6 +306,14 @@ module MakeModelGenerator<
|
||||
* Gets the kind of the return node.
|
||||
*/
|
||||
DataFlow::ReturnKindExt getKind() { result = kind }
|
||||
|
||||
/**
|
||||
* Gets the parameter position of the return node, if any.
|
||||
*/
|
||||
DataFlow::ParameterPosition getPosition() {
|
||||
result = this.getKind().(DataFlow::ParamUpdateReturnKind).getPosition() or
|
||||
result = getReturnKindParamPosition(this.getKind().(DataFlow::ValueReturnKind).getKind())
|
||||
}
|
||||
}
|
||||
|
||||
bindingset[c]
|
||||
@@ -309,10 +322,11 @@ module MakeModelGenerator<
|
||||
private module PrintReturnNodeExt<printCallableParamSig/2 printCallableParam> {
|
||||
string getOutput(ReturnNodeExt node) {
|
||||
node.getKind() instanceof DataFlow::ValueReturnKind and
|
||||
not exists(node.getPosition()) and
|
||||
result = "ReturnValue"
|
||||
or
|
||||
exists(DataFlow::ParameterPosition pos |
|
||||
pos = node.getKind().(DataFlow::ParamUpdateReturnKind).getPosition() and
|
||||
pos = node.getPosition() and
|
||||
result = printCallableParam(returnNodeEnclosingCallable(node), pos)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user