Skip to content

Commit c0f2cb8

Browse files
authored
Add documentation members to Query (#1090)
Example usage in the `query-database`: ``` object CopyLoops extends QueryBundle { @q def isCopyLoop(): Query = Query( name = "copy-loop", author = Crew.fabs, title = "Copy loop detected", description = """ |For (buf, indices) pairs, determine those inside control structures (for, while, if ...) |where any of the calls made outside of the body (block) are Inc operations. Determine |the first argument of that Inc operation and check if they are used as indices for |the write operation into the buffer. |""".stripMargin, score = 2, startLine = sourcecode.Line(), traversal = { cpg => cpg.assignment.target.isArrayAccess .map { access => (access.array, access.subscripts.code.toSet) } .filter { case (buf, subscripts) => val incIdentifiers = buf.inAst.isControlStructure.astChildren .filterNot(_.isBlock) .assignments .target .code .toSet (incIdentifiers & subscripts).nonEmpty } .map(_._1) }, endLine = sourcecode.Line(), fileName = sourcecode.FileName() ) } ```
1 parent ae192a5 commit c0f2cb8

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

console/src/main/scala/io/shiftleft/console/QueryDatabase.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ case class Query(name: String,
2020
title: String,
2121
description: String,
2222
score: Double,
23+
// intended to be filled by com.lihaoyi.sourcecode.Line
24+
docStartLine: Int = 0,
2325
traversal: Cpg => Traversal[nodes.StoredNode],
26+
// intended to be filled by com.lihaoyi.sourcecode.Line
27+
docEndLine: Int = 0,
28+
// intended to be filled by com.lihaoyi.sourcecode.FileName
29+
docFileName: String = "",
2430
tags: List[String] = List())
2531

2632
class QueryDatabase(defaultArgumentProvider: DefaultArgumentProvider = new DefaultArgumentProvider,

console/src/test/scala/io/shiftleft/console/QueryDatabaseTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object TestBundle extends QueryBundle {
1010
author = "an-author",
1111
title = "a-title",
1212
description = s"a-description $n",
13-
score = 2.0, { cpg =>
13+
score = 2.0, traversal = { cpg =>
1414
cpg.method
1515
}
1616
)

0 commit comments

Comments
 (0)