Skip to content

Commit 8f12b40

Browse files
committed
Swift: Fix AvailabilitySpec trap generation
1 parent 27b1b46 commit 8f12b40

22 files changed

+130
-321
lines changed

swift/extractor/translators/StmtTranslator.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@ void StmtTranslator::translateAndEmit(const swift::PoundAvailableInfo& availabil
3636
}
3737

3838
void StmtTranslator::translateAndEmit(const swift::AvailabilitySpec& spec) {
39-
// auto entry = dispatcher.createEntry(spec);
40-
// TODO: Swift 6.2 platform version/wildcard
41-
// dispatcher.emit(entry);
39+
auto entry = dispatcher.createEntry(spec);
40+
entry.is_wildcard = spec.isWildcard();
41+
if (!spec.isWildcard()) {
42+
auto domain = spec.getDomainOrIdentifier().getAsDomain();
43+
entry.platform =
44+
swift::platformString(domain ? domain->getPlatformKind() : swift::PlatformKind::none).str();
45+
entry.version = spec.getRawVersion().getAsString();
46+
}
47+
dispatcher.emit(entry);
4248
}
4349

4450
codeql::BraceStmt StmtTranslator::translateBraceStmt(const swift::BraceStmt& stmt) {

swift/ql/.generated.list

Lines changed: 8 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swift/ql/.gitattributes

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

swift/ql/lib/codeql/swift/elements/internal/OtherAvailabilitySpecConstructor.qll renamed to swift/ql/lib/codeql/swift/elements/internal/AvailabilitySpecConstructor.qll

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
2-
/**
3-
* This module provides a hand-modifiable wrapper around the generated class `AvailabilitySpec`.
4-
*
5-
* INTERNAL: Do not use.
6-
*/
7-
81
private import codeql.swift.generated.AvailabilitySpec
92

103
/**
114
* INTERNAL: This module contains the customizable definition of `AvailabilitySpec` and should not
125
* be referenced directly.
136
*/
147
module Impl {
8+
// the following QLdoc is generated: if you need to edit it, do it in the schema file
159
/**
1610
* An availability spec, that is, part of an `AvailabilityInfo` condition. For example `iOS 12` and `*` in:
1711
* ```
1812
* if #available(iOS 12, *)
1913
* ```
2014
*/
21-
class AvailabilitySpec extends Generated::AvailabilitySpec { }
15+
class AvailabilitySpec extends Generated::AvailabilitySpec {
16+
override string toStringImpl() {
17+
if this.isWildcard()
18+
then result = "*"
19+
else result = this.getPlatform() + " " + this.getVersion()
20+
}
21+
}
2222
}

0 commit comments

Comments
 (0)