From e469ce171de743dbcfa1887b75a5d3c2fb6a660c Mon Sep 17 00:00:00 2001 From: Erik Krogh Kristensen Date: Wed, 26 May 2021 13:12:15 +0000 Subject: [PATCH] don't print LineComment (they were disconnected from the root), and a bit of printAst performance --- ql/src/codeql_ql/printAst.qll | 36 +++++++++++++---------- ql/src/ide-contextual-queries/printAst.ql | 1 + 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/ql/src/codeql_ql/printAst.qll b/ql/src/codeql_ql/printAst.qll index f0e44f5b994..cef70deca5c 100644 --- a/ql/src/codeql_ql/printAst.qll +++ b/ql/src/codeql_ql/printAst.qll @@ -18,14 +18,15 @@ class PrintAstConfiguration extends string { /** * Holds if the given node should be printed. */ - predicate shouldPrintNode(AstNode n) { any() } + predicate shouldPrintNode(AstNode n) { not n instanceof LineComment } } /** * Gets the `i`th child of parent. * The ordering is location based and pretty arbitary. */ -AstNode getAstChild(AstNode parent, int i) { +AstNode getAstChild(PrintAstNode parent, int i) { + parent.shouldPrint() and result = rank[i](AstNode child, Location l | child.getParent() = parent and @@ -42,20 +43,23 @@ AstNode getAstChild(AstNode parent, int i) { */ 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, Location l, File f | - l = p.getLocation() and - f = l.getFile() - | - p order by f.getBaseName(), f.getAbsolutePath(), l.getStartLine(), l.getStartColumn() - ) - ).toString() + this.shouldPrint() and + ( + key = "semmle.label" and + result = "[" + concat(this.getAPrimaryQlClass(), ", ") + "] " + this.toString() + or + key = "semmle.order" and + result = + any(int i | + this = + rank[i](AstNode p, Location l, File f | + l = p.getLocation() and + f = l.getFile() + | + p order by f.getBaseName(), f.getAbsolutePath(), l.getStartLine(), l.getStartColumn() + ) + ).toString() + ) } /** diff --git a/ql/src/ide-contextual-queries/printAst.ql b/ql/src/ide-contextual-queries/printAst.ql index deb73cad62d..da0dd6ecd87 100644 --- a/ql/src/ide-contextual-queries/printAst.ql +++ b/ql/src/ide-contextual-queries/printAst.ql @@ -20,6 +20,7 @@ external string selectedSourceFile(); */ class Cfg extends PrintAstConfiguration { override predicate shouldPrintNode(AstNode n) { + super.shouldPrintNode(n) and n.getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile()) } }