Skip to content

Commit 2e9d9cf

Browse files
committed
Swift: add imported modules properties to ModuleDecl
1 parent a5a58d3 commit 2e9d9cf

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-0
lines changed

swift/codegen/schema.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,8 @@ ModuleDecl:
11211121
_extends: TypeDecl
11221122
is_builtin_module: predicate
11231123
is_system_module: predicate
1124+
imported_modules: ModuleDecl*
1125+
exported_modules: ModuleDecl*
11241126

11251127
ConstructorRefCallExpr:
11261128
_extends: SelfApplyExpr

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,10 @@ module Raw {
13981398
predicate isBuiltinModule() { module_decl_is_builtin_module(this) }
13991399

14001400
predicate isSystemModule() { module_decl_is_system_module(this) }
1401+
1402+
ModuleDecl getImportedModule(int index) { module_decl_imported_modules(this, index, result) }
1403+
1404+
ModuleDecl getExportedModule(int index) { module_decl_exported_modules(this, index, result) }
14011405
}
14021406

14031407
class NumberLiteralExpr extends @number_literal_expr, BuiltinLiteralExpr { }

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// generated by codegen/codegen.py
22
private import codeql.swift.generated.Synth
33
private import codeql.swift.generated.Raw
4+
import codeql.swift.elements.decl.ModuleDecl
45
import codeql.swift.elements.decl.TypeDecl
56

67
class ModuleDeclBase extends Synth::TModuleDecl, TypeDecl {
@@ -13,4 +14,34 @@ class ModuleDeclBase extends Synth::TModuleDecl, TypeDecl {
1314
predicate isSystemModule() {
1415
Synth::convertModuleDeclToRaw(this).(Raw::ModuleDecl).isSystemModule()
1516
}
17+
18+
ModuleDecl getImmediateImportedModule(int index) {
19+
result =
20+
Synth::convertModuleDeclFromRaw(Synth::convertModuleDeclToRaw(this)
21+
.(Raw::ModuleDecl)
22+
.getImportedModule(index))
23+
}
24+
25+
final ModuleDecl getImportedModule(int index) {
26+
result = getImmediateImportedModule(index).resolve()
27+
}
28+
29+
final ModuleDecl getAnImportedModule() { result = getImportedModule(_) }
30+
31+
final int getNumberOfImportedModules() { result = count(getAnImportedModule()) }
32+
33+
ModuleDecl getImmediateExportedModule(int index) {
34+
result =
35+
Synth::convertModuleDeclFromRaw(Synth::convertModuleDeclToRaw(this)
36+
.(Raw::ModuleDecl)
37+
.getExportedModule(index))
38+
}
39+
40+
final ModuleDecl getExportedModule(int index) {
41+
result = getImmediateExportedModule(index).resolve()
42+
}
43+
44+
final ModuleDecl getAnExportedModule() { result = getExportedModule(_) }
45+
46+
final int getNumberOfExportedModules() { result = count(getAnExportedModule()) }
1647
}

swift/ql/lib/swift.dbscheme

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,6 +2116,20 @@ module_decl_is_system_module( //dir=decl
21162116
int id: @module_decl ref
21172117
);
21182118

2119+
#keyset[id, index]
2120+
module_decl_imported_modules( //dir=decl
2121+
int id: @module_decl ref,
2122+
int index: int ref,
2123+
int imported_module: @module_decl ref
2124+
);
2125+
2126+
#keyset[id, index]
2127+
module_decl_exported_modules( //dir=decl
2128+
int id: @module_decl ref,
2129+
int index: int ref,
2130+
int exported_module: @module_decl ref
2131+
);
2132+
21192133
constructor_ref_call_exprs( //dir=expr
21202134
unique int id: @constructor_ref_call_expr
21212135
);
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 ModuleDecl x, int index
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, index, x.getExportedModule(index)
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 ModuleDecl x, int index
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, index, x.getImportedModule(index)

0 commit comments

Comments
 (0)