Skip to content

Commit d93330b

Browse files
committed
Rust: make printAst work
1 parent d8eb5d4 commit d93330b

3 files changed

Lines changed: 20 additions & 23 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Provides shared predicates related to contextual queries in the code viewer.
3+
*/
4+
5+
private import codeql.rust.elements.File
6+
private import codeql.util.FileSystem
7+
8+
/**
9+
* Returns an appropriately encoded version of a filename `name`
10+
* passed by the VS Code extension in order to coincide with the
11+
* output of `.getFile()` on locatable entities.
12+
*/
13+
cached
14+
File getFileBySourceArchiveName(string name) {
15+
result = IdeContextual<File>::getFileBySourceArchiveName(name)
16+
}

rust/ql/lib/codeql/rust/printast/PrintAst.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Provides queries to pretty-print a Swift AST as a graph.
2+
* Provides queries to pretty-print a Rust AST as a graph.
33
*/
44

55
import PrintAstNode

rust/ql/lib/codeql/rust/printast/PrintAstNode.qll

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Provides classes used to pretty-print a Swift AST as a graph.
2+
* Provides classes used to pretty-print a Rust AST as a graph.
33
* This is factored out of `PrintAst.qll` for testing purposes.
44
*/
55

@@ -20,7 +20,7 @@ class PrintAstConfiguration extends TPrintAstConfiguration {
2020
/**
2121
* Holds if the AST for `e` should be printed. By default, holds for all.
2222
*/
23-
predicate shouldPrint(Locatable e) { not e instanceof Diagnostics and not e instanceof MacroRole }
23+
predicate shouldPrint(Locatable e) { any() }
2424
}
2525

2626
private predicate shouldPrint(Locatable e) { any(PrintAstConfiguration config).shouldPrint(e) }
@@ -88,21 +88,7 @@ class PrintLocatable extends PrintAstNode, TPrintLocatable {
8888
final override predicate shouldBePrinted() { shouldPrint(ast) }
8989

9090
override predicate hasChild(PrintAstNode child, int index, string label) {
91-
exists(Locatable c, int i, string accessor |
92-
c = getChildAndAccessor(ast, i, accessor) and
93-
(
94-
// use even indexes for normal children, leaving odd slots for conversions if any
95-
child = TPrintLocatable(c) and index = 2 * i and label = accessor
96-
or
97-
child = TPrintLocatable(c.getFullyUnresolved().(Unresolved)) and
98-
index = 2 * i + 1 and
99-
(
100-
if c instanceof Expr
101-
then label = accessor + ".getFullyConverted()"
102-
else label = accessor + ".getFullyUnresolved()"
103-
)
104-
)
105-
)
91+
child = TPrintLocatable(any(Locatable c | c = getChildAndAccessor(ast, index, label)))
10692
}
10793

10894
final override Locatable getAstNode() { result = ast }
@@ -122,8 +108,3 @@ class PrintUnresolved extends PrintLocatable {
122108
child = TPrintLocatable(getImmediateChildAndAccessor(ast, index, label).(Unresolved))
123109
}
124110
}
125-
126-
private predicate hasPropertyWrapperElement(VarDecl d, Locatable a) {
127-
a = [d.getPropertyWrapperBackingVar(), d.getPropertyWrapperProjectionVar()] or
128-
a = [d.getPropertyWrapperBackingVarBinding(), d.getPropertyWrapperProjectionVarBinding()]
129-
}

0 commit comments

Comments
 (0)