Skip to content

Commit 457ce3d

Browse files
committed
Swift: fix derived IPA type properties
Also rename `IpaTypes.qll` to `Ipa.qll`
1 parent f81abe4 commit 457ce3d

File tree

295 files changed

+313
-317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

295 files changed

+313
-317
lines changed

swift/codegen/generators/qlgen.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ModifiedStubMarkedAsGeneratedError(Error):
2929
pass
3030

3131

32-
def get_ql_property(cls: schema.Class, source: schema.Class, prop: schema.Property) -> ql.Property:
32+
def get_ql_property(cls: schema.Class, prop: schema.Property) -> ql.Property:
3333
args = dict(
3434
type=prop.type if not prop.is_predicate else "predicate",
3535
qltest_skip="qltest_skip" in prop.pragmas,
@@ -40,30 +40,30 @@ def get_ql_property(cls: schema.Class, source: schema.Class, prop: schema.Proper
4040
if prop.is_single:
4141
args.update(
4242
singular=inflection.camelize(prop.name),
43-
tablename=inflection.tableize(source.name),
44-
tableparams=["this"] + ["result" if p is prop else "_" for p in source.properties if p.is_single],
43+
tablename=inflection.tableize(cls.name),
44+
tableparams=["this"] + ["result" if p is prop else "_" for p in cls.properties if p.is_single],
4545
)
4646
elif prop.is_repeated:
4747
args.update(
4848
singular=inflection.singularize(inflection.camelize(prop.name)),
4949
plural=inflection.pluralize(inflection.camelize(prop.name)),
50-
tablename=inflection.tableize(f"{source.name}_{prop.name}"),
50+
tablename=inflection.tableize(f"{cls.name}_{prop.name}"),
5151
tableparams=["this", "index", "result"],
5252
)
5353
elif prop.is_optional:
5454
args.update(
5555
singular=inflection.camelize(prop.name),
56-
tablename=inflection.tableize(f"{source.name}_{prop.name}"),
56+
tablename=inflection.tableize(f"{cls.name}_{prop.name}"),
5757
tableparams=["this", "result"],
5858
)
5959
elif prop.is_predicate:
6060
args.update(
6161
singular=inflection.camelize(prop.name, uppercase_first_letter=False),
62-
tablename=inflection.underscore(f"{source.name}_{prop.name}"),
62+
tablename=inflection.underscore(f"{cls.name}_{prop.name}"),
6363
tableparams=["this"],
6464
)
6565
else:
66-
raise ValueError(f"unknown property kind for {prop.name} from {source.name}")
66+
raise ValueError(f"unknown property kind for {prop.name} from {cls.name}")
6767
return ql.Property(**args)
6868

6969

@@ -73,10 +73,8 @@ def get_ql_class(cls: schema.Class, lookup: typing.Dict[str, schema.Class]):
7373
name=cls.name,
7474
bases=cls.bases,
7575
final=not cls.derived,
76-
77-
properties=[get_ql_property(cls, cls, p) for p in cls.properties],
76+
properties=[get_ql_property(cls, p) for p in cls.properties],
7877
dir=cls.dir,
79-
has_db_id=not cls.ipa or cls.ipa.from_class,
8078
ipa=bool(cls.ipa),
8179
**pragmas,
8280
)
@@ -179,7 +177,7 @@ def _get_all_properties_to_be_tested(cls: schema.Class, lookup: typing.Dict[str,
179177
for c, p in _get_all_properties(cls, lookup):
180178
if not ("qltest_skip" in c.pragmas or "qltest_skip" in p.pragmas):
181179
# TODO here operations are duplicated, but should be better if we split ql and qltest generation
182-
p = get_ql_property(cls, c, p)
180+
p = get_ql_property(c, p)
183181
yield ql.PropertyForTest(p.getter, p.type, p.is_single, p.is_predicate, p.is_repeated)
184182

185183

@@ -282,7 +280,7 @@ def generate(opts, renderer):
282280
else:
283281
non_final_ipa_types.append(ipa_type)
284282

285-
renderer.render(ql.Ipa.Types(schema.root_class_name, final_ipa_types, non_final_ipa_types), out / "IpaTypes.qll")
283+
renderer.render(ql.Ipa.Types(schema.root_class_name, final_ipa_types, non_final_ipa_types), out / "Ipa.qll")
286284
renderer.render(ql.ImportList(constructor_imports), out / "IpaConstructors.qll")
287285

288286
renderer.cleanup(existing)

swift/codegen/lib/ql.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class Class:
7979
qltest_skip: bool = False
8080
qltest_collapse_hierarchy: bool = False
8181
qltest_uncollapse_hierarchy: bool = False
82-
has_db_id: bool = True
8382
ipa: bool = False
8483

8584
def __post_init__(self):
@@ -96,9 +95,8 @@ def path(self) -> pathlib.Path:
9695
return self.dir / self.name
9796

9897
@property
99-
def db_id(self) -> Optional[str]:
100-
if self.has_db_id:
101-
return "@" + inflection.underscore(self.name)
98+
def db_id(self):
99+
return "@" + inflection.underscore(self.name)
102100

103101

104102
@dataclass

swift/codegen/templates/ql_class.mustache

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// generated by {{generator}}
2-
private import codeql.swift.generated.IpaTypes
2+
private import codeql.swift.generated.Ipa
33
private import codeql.swift.generated.Db
44
{{#imports}}
55
import {{.}}
@@ -28,12 +28,12 @@ class {{name}}Base extends Ipa::T{{name}}{{#bases}}, {{.}}{{/bases}} {
2828

2929
{{#type_is_class}}
3030
{{type}} getImmediate{{singular}}({{#is_repeated}}int index{{/is_repeated}}) {
31-
{{#has_db_id}}
31+
{{^ipa}}
3232
result = Ipa::convert{{type}}FromDb(Ipa::convert{{name}}ToDb(this){{^root}}.(Db::{{name}}){{/root}}.{{getter}}({{#is_repeated}}index{{/is_repeated}}))
33-
{{/has_db_id}}
34-
{{^has_db_id}}
33+
{{/ipa}}
34+
{{#ipa}}
3535
none()
36-
{{/has_db_id}}
36+
{{/ipa}}
3737
}
3838

3939
final {{type}} {{getter}}({{#is_repeated}}int index{{/is_repeated}}) {
@@ -43,12 +43,12 @@ class {{name}}Base extends Ipa::T{{name}}{{#bases}}, {{.}}{{/bases}} {
4343
{{/type_is_class}}
4444
{{^type_is_class}}
4545
{{type}} {{getter}}({{#is_repeated}}int index{{/is_repeated}}) {
46-
{{#has_db_id}}
46+
{{^ipa}}
4747
{{^is_predicate}}result = {{/is_predicate}}Ipa::convert{{name}}ToDb(this){{^root}}.(Db::{{name}}){{/root}}.{{getter}}({{#is_repeated}}index{{/is_repeated}})
48-
{{/has_db_id}}
49-
{{^has_db_id}}
48+
{{/ipa}}
49+
{{#ipa}}
5050
none()
51-
{{/has_db_id}}
51+
{{/ipa}}
5252
}
5353

5454
{{/type_is_class}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// generated by {{generator}}, remove this comment if you wish to edit this file
2-
import codeql.swift.generated.Db
2+
private import codeql.swift.generated.Db
33

44
predicate construct{{cls.name}}({{#cls.params}}{{^first}}, {{/first}}{{type}} {{param}}{{/cls.params}}) { none() }

swift/codegen/test/test_qlgen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _filter_generated_classes(ret, output_test_files=False):
101101
str(f): ret[ql_test_output_path() / f]
102102
for f in test_files
103103
}
104-
base_files -= {pathlib.Path(f"{name}.qll") for name in ("Db", "IpaTypes", "IpaConstructors")}
104+
base_files -= {pathlib.Path(f"{name}.qll") for name in ("Db", "Ipa", "IpaConstructors")}
105105
assert stub_files == base_files
106106
return {
107107
str(f): (ret[stub_path() / f], ret[ql_output_path() / f])
@@ -129,7 +129,7 @@ def test_empty(generate):
129129
assert generate([]) == {
130130
import_file(): ql.ImportList(),
131131
children_file(): ql.GetParentImplementation(),
132-
ql_output_path() / "IpaTypes.qll": ql.Ipa.Types(schema.root_class_name),
132+
ql_output_path() / "Ipa.qll": ql.Ipa.Types(schema.root_class_name),
133133
ql_output_path() / "IpaConstructors.qll": ql.ImportList(),
134134
ql_output_path() / "Db.qll": ql.DbClasses(),
135135
ql_output_path() / "Db.qll": ql.DbClasses(),

swift/ql/lib/codeql/swift/controlflow/BasicBlocks.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ private import internal.ControlFlowElements
77
private import CfgNodes
88
private import SuccessorTypes
99
private import codeql.swift.generated.Db
10-
private import codeql.swift.generated.IpaTypes
10+
private import codeql.swift.generated.Ipa
1111

1212
/**
1313
* A basic block, that is, a maximal straight-line sequence of control flow nodes

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
private import swift
3535
private import codeql.swift.controlflow.ControlFlowGraph
36-
private import codeql.swift.generated.IpaTypes
36+
private import codeql.swift.generated.Ipa
3737
private import Completion
3838
private import Scope
3939
import ControlFlowGraphImplShared

swift/ql/lib/codeql/swift/controlflow/internal/Scope.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
private import swift
22
private import codeql.swift.generated.GetImmediateParent
3-
private import codeql.swift.generated.IpaTypes
3+
private import codeql.swift.generated.Ipa
44

55
module CallableBase {
66
class TypeRange = Ipa::TAbstractFunctionDecl or Ipa::TKeyPathExpr or Ipa::TClosureExpr;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// generated by codegen/codegen.py
2-
private import codeql.swift.generated.IpaTypes
2+
private import codeql.swift.generated.Ipa
33
private import codeql.swift.generated.Db
44
import codeql.swift.elements.Locatable
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// generated by codegen/codegen.py
2-
private import codeql.swift.generated.IpaTypes
2+
private import codeql.swift.generated.Ipa
33
private import codeql.swift.generated.Db
44
import codeql.swift.elements.stmt.BraceStmt
55
import codeql.swift.elements.Element

0 commit comments

Comments
 (0)