Skip to content

Commit 62c26f8

Browse files
committed
Swift: add diagnostics to dbscheme
1 parent e01cbb2 commit 62c26f8

File tree

11 files changed

+82
-1
lines changed

11 files changed

+82
-1
lines changed

swift/ql/lib/codeql/swift/elements.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import codeql.swift.elements.Callable
44
import codeql.swift.elements.Comment
55
import codeql.swift.elements.DbFile
66
import codeql.swift.elements.DbLocation
7+
import codeql.swift.elements.Diagnostics
78
import codeql.swift.elements.Element
89
import codeql.swift.elements.File
910
import codeql.swift.elements.Locatable
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
2+
private import codeql.swift.generated.Diagnostics
3+
4+
class Diagnostics extends Generated::Diagnostics { }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
2+
private import codeql.swift.generated.Raw
3+
4+
predicate constructDiagnostics(Raw::Diagnostics id) { any() }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// generated by codegen/codegen.py
2+
private import codeql.swift.generated.Synth
3+
private import codeql.swift.generated.Raw
4+
import codeql.swift.elements.Locatable
5+
6+
module Generated {
7+
class Diagnostics extends Synth::TDiagnostics, Locatable {
8+
override string getAPrimaryQlClass() { result = "Diagnostics" }
9+
10+
/**
11+
* Gets the text of this diagnostics.
12+
*/
13+
string getText() { result = Synth::convertDiagnosticsToRaw(this).(Raw::Diagnostics).getText() }
14+
15+
/**
16+
* Gets the kind of this diagnostics.
17+
*/
18+
int getKind() { result = Synth::convertDiagnosticsToRaw(this).(Raw::Diagnostics).getKind() }
19+
}
20+
}

swift/ql/lib/codeql/swift/generated/ParentChild.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ private module Impl {
135135
)
136136
}
137137

138+
private Element getImmediateChildOfDiagnostics(
139+
Diagnostics e, int index, string partialPredicateCall
140+
) {
141+
exists(int b, int bLocatable, int n |
142+
b = 0 and
143+
bLocatable = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfLocatable(e, i, _)) | i) and
144+
n = bLocatable and
145+
(
146+
none()
147+
or
148+
result = getImmediateChildOfLocatable(e, index - b, partialPredicateCall)
149+
)
150+
)
151+
}
152+
138153
private Element getImmediateChildOfUnknownFile(
139154
UnknownFile e, int index, string partialPredicateCall
140155
) {
@@ -4882,6 +4897,8 @@ private module Impl {
48824897
or
48834898
result = getImmediateChildOfDbLocation(e, index, partialAccessor)
48844899
or
4900+
result = getImmediateChildOfDiagnostics(e, index, partialAccessor)
4901+
or
48854902
result = getImmediateChildOfUnknownFile(e, index, partialAccessor)
48864903
or
48874904
result = getImmediateChildOfUnknownLocation(e, index, partialAccessor)

swift/ql/lib/codeql/swift/generated/Raw.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ module Raw {
5151
override string toString() { result = "DbLocation" }
5252
}
5353

54+
class Diagnostics extends @diagnostics, Locatable {
55+
override string toString() { result = "Diagnostics" }
56+
57+
string getText() { diagnostics(this, result, _) }
58+
59+
int getKind() { diagnostics(this, _, result) }
60+
}
61+
5462
class UnspecifiedElement extends @unspecified_element, Locatable {
5563
override string toString() { result = "UnspecifiedElement" }
5664

swift/ql/lib/codeql/swift/generated/Synth.qll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Synth {
88
TComment(Raw::Comment id) { constructComment(id) } or
99
TDbFile(Raw::DbFile id) { constructDbFile(id) } or
1010
TDbLocation(Raw::DbLocation id) { constructDbLocation(id) } or
11+
TDiagnostics(Raw::Diagnostics id) { constructDiagnostics(id) } or
1112
TUnknownFile() or
1213
TUnknownLocation() or
1314
TUnspecifiedElement(Raw::UnspecifiedElement id) { constructUnspecifiedElement(id) } or
@@ -322,7 +323,7 @@ module Synth {
322323

323324
class TFile = TDbFile or TUnknownFile;
324325

325-
class TLocatable = TArgument or TAstNode or TComment or TUnspecifiedElement;
326+
class TLocatable = TArgument or TAstNode or TComment or TDiagnostics or TUnspecifiedElement;
326327

327328
class TLocation = TDbLocation or TUnknownLocation;
328329

@@ -494,6 +495,9 @@ module Synth {
494495
cached
495496
TDbLocation convertDbLocationFromRaw(Raw::Element e) { result = TDbLocation(e) }
496497

498+
cached
499+
TDiagnostics convertDiagnosticsFromRaw(Raw::Element e) { result = TDiagnostics(e) }
500+
497501
cached
498502
TUnknownFile convertUnknownFileFromRaw(Raw::Element e) { none() }
499503

@@ -1471,6 +1475,8 @@ module Synth {
14711475
or
14721476
result = convertCommentFromRaw(e)
14731477
or
1478+
result = convertDiagnosticsFromRaw(e)
1479+
or
14741480
result = convertUnspecifiedElementFromRaw(e)
14751481
}
14761482

@@ -2201,6 +2207,9 @@ module Synth {
22012207
cached
22022208
Raw::Element convertDbLocationToRaw(TDbLocation e) { e = TDbLocation(result) }
22032209

2210+
cached
2211+
Raw::Element convertDiagnosticsToRaw(TDiagnostics e) { e = TDiagnostics(result) }
2212+
22042213
cached
22052214
Raw::Element convertUnknownFileToRaw(TUnknownFile e) { none() }
22062215

@@ -3176,6 +3185,8 @@ module Synth {
31763185
or
31773186
result = convertCommentToRaw(e)
31783187
or
3188+
result = convertDiagnosticsToRaw(e)
3189+
or
31793190
result = convertUnspecifiedElementToRaw(e)
31803191
}
31813192

swift/ql/lib/codeql/swift/generated/SynthConstructors.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import codeql.swift.elements.CommentConstructor
33
import codeql.swift.elements.DbFileConstructor
44
import codeql.swift.elements.DbLocationConstructor
5+
import codeql.swift.elements.DiagnosticsConstructor
56
import codeql.swift.elements.UnspecifiedElementConstructor
67
import codeql.swift.elements.decl.AccessorDeclConstructor
78
import codeql.swift.elements.decl.AssociatedTypeDeclConstructor

swift/ql/lib/swift.dbscheme

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ files(
6666
@argument
6767
| @ast_node
6868
| @comment
69+
| @diagnostics
6970
| @unspecified_element
7071
;
7172

@@ -125,6 +126,12 @@ db_locations(
125126
unique int id: @db_location
126127
);
127128

129+
diagnostics(
130+
unique int id: @diagnostics,
131+
string text: string ref,
132+
int kind: int ref
133+
);
134+
128135
unknown_files(
129136
unique int id: @unknown_file
130137
);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// generated by codegen/codegen.py
2+
3+
After a swift source file is added in this directory and codegen/codegen.py is run again, test queries
4+
will appear and this file will be deleted

0 commit comments

Comments
 (0)