mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
Codegen: move ipa info from ql.Class to ql.Property
This commit is contained in:
@@ -110,7 +110,8 @@ def get_ql_property(cls: schema.Class, prop: schema.Property, prev_child: str =
|
||||
is_optional=prop.is_optional,
|
||||
is_predicate=prop.is_predicate,
|
||||
is_unordered=prop.is_unordered,
|
||||
description=prop.description
|
||||
description=prop.description,
|
||||
synth=bool(cls.ipa),
|
||||
)
|
||||
if prop.is_single:
|
||||
args.update(
|
||||
@@ -162,7 +163,6 @@ def get_ql_class(cls: schema.Class) -> ql.Class:
|
||||
final=not cls.derived,
|
||||
properties=properties,
|
||||
dir=pathlib.Path(cls.group or ""),
|
||||
ipa=bool(cls.ipa),
|
||||
doc=cls.doc,
|
||||
**pragmas,
|
||||
)
|
||||
@@ -342,7 +342,7 @@ def generate(opts, renderer):
|
||||
with renderer.manage(generated=generated, stubs=stubs, registry=opts.generated_registry,
|
||||
force=opts.force) as renderer:
|
||||
|
||||
db_classes = [cls for cls in classes.values() if not cls.ipa]
|
||||
db_classes = [cls for name, cls in classes.items() if not data.classes[name].ipa]
|
||||
renderer.render(ql.DbClasses(db_classes), out / "Raw.qll")
|
||||
|
||||
classes_by_dir_and_name = sorted(classes.values(), key=lambda cls: (cls.dir, cls.name))
|
||||
|
||||
@@ -42,6 +42,7 @@ class Property:
|
||||
description: List[str] = field(default_factory=list)
|
||||
doc: Optional[str] = None
|
||||
doc_plural: Optional[str] = None
|
||||
synth: bool = False
|
||||
|
||||
def __post_init__(self):
|
||||
if self.tableparams:
|
||||
@@ -111,7 +112,6 @@ class Class:
|
||||
qltest_collapse_hierarchy: bool = False
|
||||
qltest_uncollapse_hierarchy: bool = False
|
||||
ql_internal: bool = False
|
||||
ipa: bool = False
|
||||
doc: List[str] = field(default_factory=list)
|
||||
|
||||
def __post_init__(self):
|
||||
|
||||
@@ -67,12 +67,12 @@ module Generated {
|
||||
* behavior of both the `Immediate` and non-`Immediate` versions.
|
||||
*/
|
||||
{{type}} get{{#is_unordered}}An{{/is_unordered}}Immediate{{singular}}({{#is_indexed}}int index{{/is_indexed}}) {
|
||||
{{^ipa}}
|
||||
{{^synth}}
|
||||
result = Synth::convert{{type}}FromRaw(Synth::convert{{name}}ToRaw(this){{^root}}.(Raw::{{name}}){{/root}}.{{getter}}({{#is_indexed}}index{{/is_indexed}}))
|
||||
{{/ipa}}
|
||||
{{#ipa}}
|
||||
{{/synth}}
|
||||
{{#synth}}
|
||||
none()
|
||||
{{/ipa}}
|
||||
{{/synth}}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,12 +99,12 @@ module Generated {
|
||||
{{/has_description}}
|
||||
*/
|
||||
{{type}} {{getter}}({{#is_indexed}}int index{{/is_indexed}}) {
|
||||
{{^ipa}}
|
||||
{{^synth}}
|
||||
{{^is_predicate}}result = {{/is_predicate}}Synth::convert{{name}}ToRaw(this){{^root}}.(Raw::{{name}}){{/root}}.{{getter}}({{#is_indexed}}index{{/is_indexed}})
|
||||
{{/ipa}}
|
||||
{{#ipa}}
|
||||
{{/synth}}
|
||||
{{#synth}}
|
||||
none()
|
||||
{{/ipa}}
|
||||
{{/synth}}
|
||||
}
|
||||
|
||||
{{/type_is_class}}
|
||||
|
||||
@@ -861,25 +861,33 @@ def test_property_on_class_with_default_doc_name(generate_classes):
|
||||
|
||||
def test_stub_on_class_with_ipa_from_class(generate_classes):
|
||||
assert generate_classes([
|
||||
schema.Class("MyObject", ipa=schema.IpaInfo(from_class="A")),
|
||||
schema.Class("MyObject", ipa=schema.IpaInfo(from_class="A"),
|
||||
properties=[schema.SingleProperty("foo", "bar")]),
|
||||
]) == {
|
||||
"MyObject.qll": (a_ql_stub(name="MyObject", base_import=gen_import_prefix + "MyObject", ipa_accessors=[
|
||||
ql.IpaUnderlyingAccessor(argument="Entity", type="Raw::A", constructorparams=["result"]),
|
||||
]),
|
||||
a_ql_class(name="MyObject", final=True, ipa=True)),
|
||||
a_ql_class(name="MyObject", final=True, properties=[
|
||||
ql.Property(singular="Foo", type="bar", tablename="my_objects", synth=True,
|
||||
tableparams=["this", "result"], doc="foo of this my object"),
|
||||
])),
|
||||
}
|
||||
|
||||
|
||||
def test_stub_on_class_with_ipa_on_arguments(generate_classes):
|
||||
assert generate_classes([
|
||||
schema.Class("MyObject", ipa=schema.IpaInfo(on_arguments={"base": "A", "index": "int", "label": "string"})),
|
||||
schema.Class("MyObject", ipa=schema.IpaInfo(on_arguments={"base": "A", "index": "int", "label": "string"}),
|
||||
properties=[schema.SingleProperty("foo", "bar")]),
|
||||
]) == {
|
||||
"MyObject.qll": (a_ql_stub(name="MyObject", base_import=gen_import_prefix + "MyObject", ipa_accessors=[
|
||||
ql.IpaUnderlyingAccessor(argument="Base", type="Raw::A", constructorparams=["result", "_", "_"]),
|
||||
ql.IpaUnderlyingAccessor(argument="Index", type="int", constructorparams=["_", "result", "_"]),
|
||||
ql.IpaUnderlyingAccessor(argument="Label", type="string", constructorparams=["_", "_", "result"]),
|
||||
]),
|
||||
a_ql_class(name="MyObject", final=True, ipa=True)),
|
||||
a_ql_class(name="MyObject", final=True, properties=[
|
||||
ql.Property(singular="Foo", type="bar", tablename="my_objects", synth=True,
|
||||
tableparams=["this", "result"], doc="foo of this my object"),
|
||||
])),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user