From 32a738b0823cdf153b3d4ab01655d39b156ea397 Mon Sep 17 00:00:00 2001 From: Anders Schack-Mulligen Date: Wed, 26 Apr 2023 14:43:53 +0200 Subject: [PATCH] Dataflow: Add type to PathNode.toString. --- .../java/dataflow/internal/DataFlowImpl.qll | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImpl.qll b/java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImpl.qll index 6ea97954bdf..cd8e992c980 100644 --- a/java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImpl.qll +++ b/java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImpl.qll @@ -3031,6 +3031,17 @@ module Impl { this instanceof PathNodeSinkGroup } + private string ppType() { + this instanceof PathNodeSink and result = "" + or + this.(PathNodeMid).getAp() instanceof AccessPathNil and result = "" + or + exists(DataFlowType t | t = this.(PathNodeMid).getAp().getHead().getContainerType() | + // The `concat` becomes "" if `ppReprType` has no result. + result = concat(" : " + ppReprType(t)) + ) + } + private string ppAp() { this instanceof PathNodeSink and result = "" or @@ -3046,14 +3057,14 @@ module Impl { } /** Gets a textual representation of this element. */ - string toString() { result = this.getNodeEx().toString() + this.ppAp() } + string toString() { result = this.getNodeEx().toString() + this.ppType() + this.ppAp() } /** * Gets a textual representation of this element, including a textual * representation of the call context. */ string toStringWithContext() { - result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx() + result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx() } /** @@ -3998,14 +4009,14 @@ module Impl { */ class PartialPathNode extends TPartialPathNode { /** Gets a textual representation of this element. */ - string toString() { result = this.getNodeEx().toString() + this.ppAp() } + string toString() { result = this.getNodeEx().toString() + this.ppType() + this.ppAp() } /** * Gets a textual representation of this element, including a textual * representation of the call context. */ string toStringWithContext() { - result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx() + result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx() } /** @@ -4046,6 +4057,19 @@ module Impl { */ int getSinkDistance() { result = distSink(this.getNodeEx().getEnclosingCallable()) } + private string ppType() { + this instanceof PartialPathNodeRev and result = "" + or + this.(PartialPathNodeFwd).getAp() instanceof PartialAccessPathNil and result = "" + or + exists(DataFlowType t | + t = this.(PartialPathNodeFwd).getAp().(PartialAccessPathCons).getType() + | + // The `concat` becomes "" if `ppReprType` has no result. + result = concat(" : " + ppReprType(t)) + ) + } + private string ppAp() { exists(string s | s = this.(PartialPathNodeFwd).getAp().toString() or