mirror of
https://github.com/github/codeql.git
synced 2026-02-10 12:11:07 +01:00
don't print LineComment (they were disconnected from the root), and a bit of printAst performance
This commit is contained in:
committed by
GitHub
parent
80b508aa03
commit
e469ce171d
@@ -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()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user