Skip to content

Commit 242d263

Browse files
committed
Codegen: move ipa info from ql.Class to ql.Property
1 parent 5de8934 commit 242d263

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

misc/codegen/generators/qlgen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def get_ql_property(cls: schema.Class, prop: schema.Property, prev_child: str =
110110
is_optional=prop.is_optional,
111111
is_predicate=prop.is_predicate,
112112
is_unordered=prop.is_unordered,
113-
description=prop.description
113+
description=prop.description,
114+
synth=bool(cls.ipa),
114115
)
115116
if prop.is_single:
116117
args.update(
@@ -162,7 +163,6 @@ def get_ql_class(cls: schema.Class) -> ql.Class:
162163
final=not cls.derived,
163164
properties=properties,
164165
dir=pathlib.Path(cls.group or ""),
165-
ipa=bool(cls.ipa),
166166
doc=cls.doc,
167167
**pragmas,
168168
)
@@ -342,7 +342,7 @@ def generate(opts, renderer):
342342
with renderer.manage(generated=generated, stubs=stubs, registry=opts.generated_registry,
343343
force=opts.force) as renderer:
344344

345-
db_classes = [cls for cls in classes.values() if not cls.ipa]
345+
db_classes = [cls for name, cls in classes.items() if not data.classes[name].ipa]
346346
renderer.render(ql.DbClasses(db_classes), out / "Raw.qll")
347347

348348
classes_by_dir_and_name = sorted(classes.values(), key=lambda cls: (cls.dir, cls.name))

misc/codegen/lib/ql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Property:
4242
description: List[str] = field(default_factory=list)
4343
doc: Optional[str] = None
4444
doc_plural: Optional[str] = None
45+
synth: bool = False
4546

4647
def __post_init__(self):
4748
if self.tableparams:
@@ -111,7 +112,6 @@ class Class:
111112
qltest_collapse_hierarchy: bool = False
112113
qltest_uncollapse_hierarchy: bool = False
113114
ql_internal: bool = False
114-
ipa: bool = False
115115
doc: List[str] = field(default_factory=list)
116116

117117
def __post_init__(self):

misc/codegen/templates/ql_class.mustache

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ module Generated {
6767
* behavior of both the `Immediate` and non-`Immediate` versions.
6868
*/
6969
{{type}} get{{#is_unordered}}An{{/is_unordered}}Immediate{{singular}}({{#is_indexed}}int index{{/is_indexed}}) {
70-
{{^ipa}}
70+
{{^synth}}
7171
result = Synth::convert{{type}}FromRaw(Synth::convert{{name}}ToRaw(this){{^root}}.(Raw::{{name}}){{/root}}.{{getter}}({{#is_indexed}}index{{/is_indexed}}))
72-
{{/ipa}}
73-
{{#ipa}}
72+
{{/synth}}
73+
{{#synth}}
7474
none()
75-
{{/ipa}}
75+
{{/synth}}
7676
}
7777

7878
/**
@@ -99,12 +99,12 @@ module Generated {
9999
{{/has_description}}
100100
*/
101101
{{type}} {{getter}}({{#is_indexed}}int index{{/is_indexed}}) {
102-
{{^ipa}}
102+
{{^synth}}
103103
{{^is_predicate}}result = {{/is_predicate}}Synth::convert{{name}}ToRaw(this){{^root}}.(Raw::{{name}}){{/root}}.{{getter}}({{#is_indexed}}index{{/is_indexed}})
104-
{{/ipa}}
105-
{{#ipa}}
104+
{{/synth}}
105+
{{#synth}}
106106
none()
107-
{{/ipa}}
107+
{{/synth}}
108108
}
109109

110110
{{/type_is_class}}

misc/codegen/test/test_qlgen.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -861,25 +861,33 @@ def test_property_on_class_with_default_doc_name(generate_classes):
861861

862862
def test_stub_on_class_with_ipa_from_class(generate_classes):
863863
assert generate_classes([
864-
schema.Class("MyObject", ipa=schema.IpaInfo(from_class="A")),
864+
schema.Class("MyObject", ipa=schema.IpaInfo(from_class="A"),
865+
properties=[schema.SingleProperty("foo", "bar")]),
865866
]) == {
866867
"MyObject.qll": (a_ql_stub(name="MyObject", base_import=gen_import_prefix + "MyObject", ipa_accessors=[
867868
ql.IpaUnderlyingAccessor(argument="Entity", type="Raw::A", constructorparams=["result"]),
868869
]),
869-
a_ql_class(name="MyObject", final=True, ipa=True)),
870+
a_ql_class(name="MyObject", final=True, properties=[
871+
ql.Property(singular="Foo", type="bar", tablename="my_objects", synth=True,
872+
tableparams=["this", "result"], doc="foo of this my object"),
873+
])),
870874
}
871875

872876

873877
def test_stub_on_class_with_ipa_on_arguments(generate_classes):
874878
assert generate_classes([
875-
schema.Class("MyObject", ipa=schema.IpaInfo(on_arguments={"base": "A", "index": "int", "label": "string"})),
879+
schema.Class("MyObject", ipa=schema.IpaInfo(on_arguments={"base": "A", "index": "int", "label": "string"}),
880+
properties=[schema.SingleProperty("foo", "bar")]),
876881
]) == {
877882
"MyObject.qll": (a_ql_stub(name="MyObject", base_import=gen_import_prefix + "MyObject", ipa_accessors=[
878883
ql.IpaUnderlyingAccessor(argument="Base", type="Raw::A", constructorparams=["result", "_", "_"]),
879884
ql.IpaUnderlyingAccessor(argument="Index", type="int", constructorparams=["_", "result", "_"]),
880885
ql.IpaUnderlyingAccessor(argument="Label", type="string", constructorparams=["_", "_", "result"]),
881886
]),
882-
a_ql_class(name="MyObject", final=True, ipa=True)),
887+
a_ql_class(name="MyObject", final=True, properties=[
888+
ql.Property(singular="Foo", type="bar", tablename="my_objects", synth=True,
889+
tableparams=["this", "result"], doc="foo of this my object"),
890+
])),
883891
}
884892

885893

0 commit comments

Comments
 (0)