Merge pull request #261 from github/getPrimaryQlClasses

Implement getPrimaryQlClasses
This commit is contained in:
Nick Rolfe
2021-09-07 12:02:15 +01:00
committed by GitHub
6 changed files with 80 additions and 29 deletions

View File

@@ -1,17 +1,11 @@
import codeql.ruby.AST
import codeql.ruby.ast.internal.Synthesis
private string getAPrimaryQlClass(AstNode node) {
result = node.getAPrimaryQlClass()
or
not exists(node.getAPrimaryQlClass()) and result = "(none)"
}
query predicate missingParent(AstNode node, string cls) {
not exists(node.getParent()) and
node.getLocation().getFile().getExtension() != "erb" and
not node instanceof Toplevel and
cls = getAPrimaryQlClass(node)
cls = node.getPrimaryQlClasses()
}
pragma[noinline]
@@ -22,7 +16,7 @@ private AstNode parent(AstNode child, int desugarLevel) {
query predicate multipleParents(AstNode node, AstNode parent, string cls) {
parent = node.getParent() and
cls = getAPrimaryQlClass(parent) and
cls = parent.getPrimaryQlClasses() and
exists(AstNode one, AstNode two, int desugarLevel |
one = parent(node, desugarLevel) and
two = parent(node, desugarLevel) and

View File

@@ -32,6 +32,12 @@ class AstNode extends TAstNode {
*/
string getAPrimaryQlClass() { result = "???" }
/**
* Gets a comma-separated list of the names of the primary CodeQL classes to
* which this element belongs.
*/
final string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
/** Gets the enclosing module, if any. */
ModuleBase getEnclosingModule() {
exists(Scope::Range s |

View File

@@ -26,6 +26,9 @@ module Ruby {
/** Gets the name of the primary QL class for this element. */
string getAPrimaryQlClass() { result = "???" }
/** Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. */
string getPrimaryQlClasses() { result = concat(getAPrimaryQlClass(), ",") }
}
/** A token. */
@@ -1864,6 +1867,9 @@ module Erb {
/** Gets the name of the primary QL class for this element. */
string getAPrimaryQlClass() { result = "???" }
/** Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. */
string getPrimaryQlClasses() { result = concat(getAPrimaryQlClass(), ",") }
}
/** A token. */

View File

@@ -18,10 +18,15 @@ class RegExpParent extends TRegExpParent {
/**
* Gets the name of a primary CodeQL class to which this regular
* expression
* term belongs.
* expression term belongs.
*/
string getAPrimaryQlClass() { result = "RegExpParent" }
/**
* Gets a comma-separated list of the names of the primary CodeQL classes to
* which this regular expression term belongs.
*/
final string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
}
class RegExpLiteral extends TRegExpLiteral, RegExpParent {