Skip to content

Commit 7873f07

Browse files
committed
Swift: define ImportDecl:imported_module optional
1 parent 623d87a commit 7873f07

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

swift/codegen/schema.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ IfConfigClause:
311311
ImportDecl:
312312
_extends: Decl
313313
is_exported: predicate
314-
imported_module: ModuleDecl
314+
imported_module: ModuleDecl? # may be none in inactive #if clauses
315315
declarations: ValueDecl*
316316

317317
MissingMemberDecl:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ module Raw {
607607

608608
predicate isExported() { import_decl_is_exported(this) }
609609

610-
ModuleDecl getImportedModule() { import_decls(this, result) }
610+
ModuleDecl getImportedModule() { import_decl_imported_modules(this, result) }
611611

612612
ValueDecl getDeclaration(int index) { import_decl_declarations(this, index, result) }
613613
}

swift/ql/lib/codeql/swift/generated/decl/ImportDecl.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class ImportDeclBase extends Synth::TImportDecl, Decl {
1919

2020
final ModuleDecl getImportedModule() { result = getImmediateImportedModule().resolve() }
2121

22+
final predicate hasImportedModule() { exists(getImportedModule()) }
23+
2224
ValueDecl getImmediateDeclaration(int index) {
2325
result =
2426
Synth::convertValueDeclFromRaw(Synth::convertImportDeclToRaw(this)

swift/ql/lib/swift.dbscheme

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,15 +703,20 @@ if_config_clause_is_active( //dir=decl
703703
);
704704

705705
import_decls( //dir=decl
706-
unique int id: @import_decl,
707-
int imported_module: @module_decl ref
706+
unique int id: @import_decl
708707
);
709708

710709
#keyset[id]
711710
import_decl_is_exported( //dir=decl
712711
int id: @import_decl ref
713712
);
714713

714+
#keyset[id]
715+
import_decl_imported_modules( //dir=decl
716+
int id: @import_decl ref,
717+
int imported_module: @module_decl ref
718+
);
719+
715720
#keyset[id, index]
716721
import_decl_declarations( //dir=decl
717722
int id: @import_decl ref,

swift/ql/test/extractor-tests/generated/decl/ImportDecl/ImportDecl.ql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
import codeql.swift.elements
33
import TestUtils
44

5-
from ImportDecl x, ModuleDecl getModule, string isExported, ModuleDecl getImportedModule
5+
from ImportDecl x, ModuleDecl getModule, string isExported
66
where
77
toBeTested(x) and
88
not x.isUnknown() and
99
getModule = x.getModule() and
10-
(if x.isExported() then isExported = "yes" else isExported = "no") and
11-
getImportedModule = x.getImportedModule()
12-
select x, "getModule:", getModule, "isExported:", isExported, "getImportedModule:",
13-
getImportedModule
10+
if x.isExported() then isExported = "yes" else isExported = "no"
11+
select x, "getModule:", getModule, "isExported:", isExported
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from ImportDecl x
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, x.getImportedModule()

0 commit comments

Comments
 (0)