Skip to content

Commit 036a36a

Browse files
authored
Merge pull request #4317 from max-schaefer/js/api-node-depth
Approved by asgerf
2 parents 717ea23 + dafd45f commit 036a36a

File tree

6 files changed

+75
-0
lines changed

6 files changed

+75
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @name API-graph edges
3+
* @description The number of edges (other than points-to edges) in the API graph.
4+
* @kind metric
5+
* @metricType project
6+
* @metricAggregate sum
7+
* @tags meta
8+
* @id js/meta/api-graph-edges
9+
*/
10+
11+
import javascript
12+
import meta.MetaMetrics
13+
14+
select projectRoot(),
15+
count(API::Node pred, string lbl, API::Node succ | succ = pred.getASuccessor(lbl))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @name API-graph nodes
3+
* @description The number of nodes in the API graph.
4+
* @kind metric
5+
* @metricType project
6+
* @metricAggregate sum
7+
* @tags meta
8+
* @id js/meta/api-graph-nodes
9+
*/
10+
11+
import javascript
12+
import meta.MetaMetrics
13+
14+
select projectRoot(), count(API::Node nd)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @name API-graph points-to edges
3+
* @description The number of points-to edges in the API graph.
4+
* @kind metric
5+
* @metricType project
6+
* @metricAggregate sum
7+
* @tags meta
8+
* @id js/meta/api-graph-points-to-edges
9+
*/
10+
11+
import javascript
12+
import meta.MetaMetrics
13+
14+
select projectRoot(), count(API::Node pred, API::Node succ | pred.refersTo(succ))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @name API-graph right-hand-side nodes
3+
* @description The number of data-flow nodes corresponding to a right-hand side of
4+
* a definition of an API-graph node.
5+
* @kind metric
6+
* @metricType project
7+
* @metricAggregate sum
8+
* @tags meta
9+
* @id js/meta/api-graph-rhs-nodes
10+
*/
11+
12+
import javascript
13+
import meta.MetaMetrics
14+
15+
select projectRoot(), count(any(API::Node nd).getARhs())
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @name API-graph use nodes
3+
* @description The number of data-flow nodes corresponding to a use of an API-graph node.
4+
* @kind metric
5+
* @metricType project
6+
* @metricAggregate sum
7+
* @tags meta
8+
* @id js/meta/api-graph-use-nodes
9+
*/
10+
11+
import javascript
12+
import meta.MetaMetrics
13+
14+
select projectRoot(), count(any(API::Node nd).getAUse())

javascript/ql/src/semmle/javascript/ApiGraphs.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ module API {
223223
) and
224224
length in [1 .. Impl::distanceFromRoot(this)]
225225
}
226+
227+
/** Gets the shortest distance from the root to this node in the API graph. */
228+
int getDepth() { result = Impl::distanceFromRoot(this) }
226229
}
227230

228231
/** The root node of an API graph. */

0 commit comments

Comments
 (0)