Skip to content

Commit 2b8b6d3

Browse files
committed
Swift: ignore diagnostics for PrintAst
1 parent e9c4cb2 commit 2b8b6d3

File tree

4 files changed

+7
-58
lines changed

4 files changed

+7
-58
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.Diagnostics
32

4-
class Diagnostics extends Generated::Diagnostics { }
3+
class Diagnostics extends Generated::Diagnostics {
4+
override string toString() { result = getText() }
5+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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) { any() }
23+
predicate shouldPrint(Locatable e) { not e instanceof Diagnostics }
2424
}
2525

2626
private predicate shouldPrint(Locatable e) { any(PrintAstConfiguration config).shouldPrint(e) }
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| diags.swift:1:10:1:10 | Diagnostics | getText: | Hello, warning | getKind: | 2 |
2-
| error.swift:2:14:2:14 | Diagnostics | getText: | cannot convert value of type 'String' to specified type 'Int' | getKind: | 1 |
3-
| import-error.swift:2:8:2:8 | Diagnostics | getText: | no such module 'FooBar' | getKind: | 1 |
1+
| diags.swift:1:10:1:10 | Hello, warning | getText: | Hello, warning | getKind: | 2 |
2+
| error.swift:2:14:2:14 | cannot convert value of type 'String' to specified type 'Int' | getText: | cannot convert value of type 'String' to specified type 'Int' | getKind: | 1 |
3+
| import-error.swift:2:8:2:8 | no such module 'FooBar' | getText: | no such module 'FooBar' | getKind: | 1 |

swift/ql/test/library-tests/ast/PrintAst.expected

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,7 +3403,6 @@ declarations.swift:
34033403
# 144| getElement(0): [CallExpr] call to id()
34043404
# 144| getFunction(): [MethodRefExpr] .id()
34053405
# 144| getBase(): [IntegerLiteralExpr] 42
3406-
# 144| [Diagnostics] Diagnostics
34073406
# 146| [ClassDecl] GenericClass
34083407
# 146| getGenericTypeParam(0): [GenericTypeParamDecl] A
34093408
# 146| getGenericTypeParam(1): [GenericTypeParamDecl] B
@@ -3482,11 +3481,6 @@ declarations.swift:
34823481
# 173| getElement(5): [IfConfigDecl] #if ...
34833482
# 174| getElement(6): [IntegerLiteralExpr] 9
34843483
# 175| getElement(7): [IntegerLiteralExpr] 10
3485-
# 163| [Diagnostics] Diagnostics
3486-
# 164| [Diagnostics] Diagnostics
3487-
# 165| [Diagnostics] Diagnostics
3488-
# 174| [Diagnostics] Diagnostics
3489-
# 175| [Diagnostics] Diagnostics
34903484
expressions.swift:
34913485
# 1| [TopLevelCodeDecl] { ... }
34923486
# 1| getBody(): [BraceStmt] { ... }
@@ -3652,7 +3646,6 @@ expressions.swift:
36523646
# 31| getDest(): [DiscardAssignmentExpr] _
36533647
# 31| getSource(): [IntegerLiteralExpr] 15
36543648
# 31| getSource().getFullyConverted(): [IsExpr] ... is ...
3655-
# 31| [Diagnostics] Diagnostics
36563649
# 32| [TopLevelCodeDecl] { ... }
36573650
# 32| getBody(): [BraceStmt] { ... }
36583651
# 32| getElement(0): [AssignExpr] ... = ...
@@ -3665,14 +3658,12 @@ expressions.swift:
36653658
# 33| getDest(): [DiscardAssignmentExpr] _
36663659
# 33| getSource(): [IntegerLiteralExpr] 15
36673660
# 33| getSource().getFullyConverted(): [ConditionalCheckedCastExpr] (Double?) ...
3668-
# 33| [Diagnostics] Diagnostics
36693661
# 34| [TopLevelCodeDecl] { ... }
36703662
# 34| getBody(): [BraceStmt] { ... }
36713663
# 34| getElement(0): [AssignExpr] ... = ...
36723664
# 34| getDest(): [DiscardAssignmentExpr] _
36733665
# 34| getSource(): [IntegerLiteralExpr] 15
36743666
# 34| getSource().getFullyConverted(): [ForcedCheckedCastExpr] (Double) ...
3675-
# 34| [Diagnostics] Diagnostics
36763667
# 35| [TopLevelCodeDecl] { ... }
36773668
# 35| getBody(): [BraceStmt] { ... }
36783669
# 35| getElement(0): [CallExpr] call to print(_:separator:terminator:)
@@ -3689,10 +3680,6 @@ expressions.swift:
36893680
# 35| getExpr(): [DefaultArgumentExpr] default separator
36903681
# 35| getArgument(2): [Argument] terminator: default terminator
36913682
# 35| getExpr(): [DefaultArgumentExpr] default terminator
3692-
# 35| [Diagnostics] Diagnostics
3693-
# 35| [Diagnostics] Diagnostics
3694-
# 35| [Diagnostics] Diagnostics
3695-
# 35| [Diagnostics] Diagnostics
36963683
# 37| [ConcreteFuncDecl] closured(closure:)
36973684
# 37| InterfaceType = ((Int, Int) -> Int) -> ()
36983685
# 37| getParam(0): [ParamDecl] closure
@@ -3704,7 +3691,6 @@ expressions.swift:
37043691
# 38| getExpr(): [IntegerLiteralExpr] 5
37053692
# 38| getArgument(1): [Argument] : 7
37063693
# 38| getExpr(): [IntegerLiteralExpr] 7
3707-
# 38| [Diagnostics] Diagnostics
37083694
# 41| [TopLevelCodeDecl] { ... }
37093695
# 41| getBody(): [BraceStmt] { ... }
37103696
# 41| getElement(0): [CallExpr] call to closured(closure:)
@@ -3970,15 +3956,13 @@ expressions.swift:
39703956
# 87| getBody(): [BraceStmt] { ... }
39713957
# 87| getElement(0): [ForceValueExpr] ...!
39723958
# 87| getSubExpr(): [DeclRefExpr] opt
3973-
# 87| [Diagnostics] Diagnostics
39743959
# 88| [TopLevelCodeDecl] { ... }
39753960
# 88| getBody(): [BraceStmt] { ... }
39763961
# 88| getElement(0): [ForceValueExpr] ...!
39773962
# 88| getSubExpr(): [SubscriptExpr] ...[...]
39783963
# 88| getBase(): [DeclRefExpr] d
39793964
# 88| getArgument(0): [Argument] : a
39803965
# 88| getExpr(): [StringLiteralExpr] a
3981-
# 88| [Diagnostics] Diagnostics
39823966
# 90| [ClassDecl] ToPtr
39833967
# 90| getMember(0): [DestructorDecl] deinit()
39843968
# 90| InterfaceType = (ToPtr) -> () -> ()
@@ -4019,7 +4003,6 @@ expressions.swift:
40194003
# 93| getArgument(0): [Argument] : opaque
40204004
# 93| getExpr(): [DeclRefExpr] opaque
40214005
# 93| getExpr().getFullyConverted(): [PointerToPointerExpr] (UnsafeRawPointer) ...
4022-
# 93| [Diagnostics] Diagnostics
40234006
# 95| [StructDecl] HasProperty
40244007
# 96| getMember(0): [PatternBindingDecl] var ... = ...
40254008
# 96| getPattern(0): [TypedPattern] ... as ...
@@ -4208,10 +4191,6 @@ expressions.swift:
42084191
# 138| getExpr(): [IntegerLiteralExpr] 3
42094192
# 138| getArgument(1): [Argument] : 4
42104193
# 138| getExpr(): [IntegerLiteralExpr] 4
4211-
# 132| [Diagnostics] Diagnostics
4212-
# 133| [Diagnostics] Diagnostics
4213-
# 134| [Diagnostics] Diagnostics
4214-
# 136| [Diagnostics] Diagnostics
42154194
# 141| [StructDecl] B
42164195
# 142| getMember(0): [PatternBindingDecl] var ... = ...
42174196
# 142| getPattern(0): [TypedPattern] ... as ...
@@ -4420,9 +4399,6 @@ expressions.swift:
44204399
# 163| getExpr(): [IntegerLiteralExpr] 1
44214400
# 163| getArgument(1): [Argument] : 0
44224401
# 163| getExpr(): [IntegerLiteralExpr] 0
4423-
# 152| [Diagnostics] Diagnostics
4424-
# 153| [Diagnostics] Diagnostics
4425-
# 154| [Diagnostics] Diagnostics
44264402
patterns.swift:
44274403
# 1| [ConcreteFuncDecl] basic_patterns()
44284404
# 1| InterfaceType = () -> ()
@@ -4461,11 +4437,6 @@ patterns.swift:
44614437
# 6| getInit(0): [StringLiteralExpr] paren
44624438
# 6| getPattern(0): [AnyPattern] _
44634439
# 6| getPattern(0).getFullyUnresolved(): [ParenPattern] (...)
4464-
# 2| [Diagnostics] Diagnostics
4465-
# 3| [Diagnostics] Diagnostics
4466-
# 4| [Diagnostics] Diagnostics
4467-
# 4| [Diagnostics] Diagnostics
4468-
# 4| [Diagnostics] Diagnostics
44694440
# 9| [ConcreteFuncDecl] switch_patterns()
44704441
# 9| InterfaceType = () -> ()
44714442
# 9| getBody(): [BraceStmt] { ... }
@@ -4604,38 +4575,16 @@ patterns.swift:
46044575
# 50| getPattern(): [BoolPattern] false
46054576
# 12| [ConcreteVarDecl] xx
46064577
# 12| Type = Int
4607-
# 12| [Diagnostics] Diagnostics
46084578
# 12| [ConcreteVarDecl] yy
46094579
# 12| Type = Int
4610-
# 12| [Diagnostics] Diagnostics
4611-
# 12| [Diagnostics] Diagnostics
4612-
# 15| [Diagnostics] Diagnostics
4613-
# 16| [Diagnostics] Diagnostics
4614-
# 17| [Diagnostics] Diagnostics
4615-
# 17| [Diagnostics] Diagnostics
4616-
# 26| [Diagnostics] Diagnostics
4617-
# 27| [Diagnostics] Diagnostics
4618-
# 28| [Diagnostics] Diagnostics
46194580
# 28| [ConcreteVarDecl] i
46204581
# 28| Type = Int
46214582
# 28| [ConcreteVarDecl] s
46224583
# 28| Type = String
4623-
# 28| [Diagnostics] Diagnostics
4624-
# 28| [Diagnostics] Diagnostics
4625-
# 33| [Diagnostics] Diagnostics
46264584
# 34| [ConcreteVarDecl] n
46274585
# 34| Type = Int
4628-
# 34| [Diagnostics] Diagnostics
4629-
# 34| [Diagnostics] Diagnostics
4630-
# 35| [Diagnostics] Diagnostics
4631-
# 41| [Diagnostics] Diagnostics
46324586
# 42| [ConcreteVarDecl] x
46334587
# 42| Type = String
4634-
# 42| [Diagnostics] Diagnostics
4635-
# 42| [Diagnostics] Diagnostics
4636-
# 43| [Diagnostics] Diagnostics
4637-
# 49| [Diagnostics] Diagnostics
4638-
# 50| [Diagnostics] Diagnostics
46394588
statements.swift:
46404589
# 1| [ConcreteFuncDecl] loop()
46414590
# 1| InterfaceType = () -> ()
@@ -4928,7 +4877,6 @@ statements.swift:
49284877
# 65| getSubPattern(): [NamedPattern] xx
49294878
# 65| getInitializer(): [DeclRefExpr] x
49304879
# 65| getThen(): [BraceStmt] { ... }
4931-
# 65| [Diagnostics] Diagnostics
49324880
# 67| [TopLevelCodeDecl] { ... }
49334881
# 67| getBody(): [BraceStmt] { ... }
49344882
# 67| getElement(0): [IfStmt] if ... then { ... }

0 commit comments

Comments
 (0)