mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Rust: make printAst work
This commit is contained in:
16
rust/ql/lib/codeql/IDEContextual.qll
Normal file
16
rust/ql/lib/codeql/IDEContextual.qll
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Provides shared predicates related to contextual queries in the code viewer.
|
||||
*/
|
||||
|
||||
private import codeql.rust.elements.File
|
||||
private import codeql.util.FileSystem
|
||||
|
||||
/**
|
||||
* Returns an appropriately encoded version of a filename `name`
|
||||
* passed by the VS Code extension in order to coincide with the
|
||||
* output of `.getFile()` on locatable entities.
|
||||
*/
|
||||
cached
|
||||
File getFileBySourceArchiveName(string name) {
|
||||
result = IdeContextual<File>::getFileBySourceArchiveName(name)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Provides queries to pretty-print a Swift AST as a graph.
|
||||
* Provides queries to pretty-print a Rust AST as a graph.
|
||||
*/
|
||||
|
||||
import PrintAstNode
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Provides classes used to pretty-print a Swift AST as a graph.
|
||||
* Provides classes used to pretty-print a Rust AST as a graph.
|
||||
* This is factored out of `PrintAst.qll` for testing purposes.
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,7 @@ class PrintAstConfiguration extends TPrintAstConfiguration {
|
||||
/**
|
||||
* Holds if the AST for `e` should be printed. By default, holds for all.
|
||||
*/
|
||||
predicate shouldPrint(Locatable e) { not e instanceof Diagnostics and not e instanceof MacroRole }
|
||||
predicate shouldPrint(Locatable e) { any() }
|
||||
}
|
||||
|
||||
private predicate shouldPrint(Locatable e) { any(PrintAstConfiguration config).shouldPrint(e) }
|
||||
@@ -88,21 +88,7 @@ class PrintLocatable extends PrintAstNode, TPrintLocatable {
|
||||
final override predicate shouldBePrinted() { shouldPrint(ast) }
|
||||
|
||||
override predicate hasChild(PrintAstNode child, int index, string label) {
|
||||
exists(Locatable c, int i, string accessor |
|
||||
c = getChildAndAccessor(ast, i, accessor) and
|
||||
(
|
||||
// use even indexes for normal children, leaving odd slots for conversions if any
|
||||
child = TPrintLocatable(c) and index = 2 * i and label = accessor
|
||||
or
|
||||
child = TPrintLocatable(c.getFullyUnresolved().(Unresolved)) and
|
||||
index = 2 * i + 1 and
|
||||
(
|
||||
if c instanceof Expr
|
||||
then label = accessor + ".getFullyConverted()"
|
||||
else label = accessor + ".getFullyUnresolved()"
|
||||
)
|
||||
)
|
||||
)
|
||||
child = TPrintLocatable(any(Locatable c | c = getChildAndAccessor(ast, index, label)))
|
||||
}
|
||||
|
||||
final override Locatable getAstNode() { result = ast }
|
||||
@@ -122,8 +108,3 @@ class PrintUnresolved extends PrintLocatable {
|
||||
child = TPrintLocatable(getImmediateChildAndAccessor(ast, index, label).(Unresolved))
|
||||
}
|
||||
}
|
||||
|
||||
private predicate hasPropertyWrapperElement(VarDecl d, Locatable a) {
|
||||
a = [d.getPropertyWrapperBackingVar(), d.getPropertyWrapperProjectionVar()] or
|
||||
a = [d.getPropertyWrapperBackingVarBinding(), d.getPropertyWrapperProjectionVarBinding()]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user