From d54db292f73139f005d5ac32d48ee06708b20cd8 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Mon, 15 Mar 2021 10:27:55 +0100 Subject: [PATCH] Move semmle.order property to printAst.qll --- ql/src/codeql_ruby/printAst.qll | 22 +++++++++++++++++++-- ql/test/library-tests/ast/Ast.ql | 33 +------------------------------- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/ql/src/codeql_ruby/printAst.qll b/ql/src/codeql_ruby/printAst.qll index 3556e20d45c..07cb40e180d 100644 --- a/ql/src/codeql_ruby/printAst.qll +++ b/ql/src/codeql_ruby/printAst.qll @@ -27,6 +27,19 @@ class PrintAstNode extends AstNode { string getProperty(string key) { key = "semmle.label" and result = "[" + concat(this.getAPrimaryQlClass(), ", ") + "] " + this.toString() + or + key = "semmle.order" and + result = + any(int i | + this = + rank[i](AstNode p | + | + p + order by + p.getLocation().getFile().getBaseName(), p.getLocation().getFile().getAbsolutePath(), + p.getLocation().getStartLine(), p.getLocation().getStartColumn() + ) + ).toString() } /** @@ -62,9 +75,14 @@ query predicate nodes(PrintAstNode node, string key, string value) { query predicate edges(PrintAstNode source, PrintAstNode target, string key, string value) { source.shouldPrint() and target.shouldPrint() and - key = "semmle.label" and target = source.getAChild() and - value = concat(string name | source.getChild(name) = target | name, "/") + ( + key = "semmle.label" and + value = concat(string name | source.getChild(name) = target | name, "/") + or + key = "semmle.order" and + value = target.getProperty("semmle.order") + ) } /** diff --git a/ql/test/library-tests/ast/Ast.ql b/ql/test/library-tests/ast/Ast.ql index 9784cdc7d05..babafaac548 100644 --- a/ql/test/library-tests/ast/Ast.ql +++ b/ql/test/library-tests/ast/Ast.ql @@ -2,35 +2,4 @@ * @kind graph */ -import codeql_ruby.printAst as P - -query predicate nodes = P::nodes/3; - -query predicate graphProperties = P::graphProperties/2; - -query predicate edges(P::PrintAstNode source, P::PrintAstNode target, string key, string value) { - P::edges(source, target, key, value) - or - P::edges(source, target, _, _) and - key = "semmle.order" and - value = target.(OrderedAstNode).getProperty("semmle.order") -} - -class OrderedAstNode extends P::PrintAstNode { - override string getProperty(string key) { - result = super.getProperty(key) - or - key = "semmle.order" and - result = - any(int i | - this = - rank[i](P::AstNode p | - | - p - order by - p.getLocation().getFile().getBaseName(), p.getLocation().getFile().getAbsolutePath(), - p.getLocation().getStartLine(), p.getLocation().getStartColumn() - ) - ).toString() - } -} +import codeql_ruby.printAst