mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
Codegen: implement set in cppgen
This commit is contained in:
@@ -49,6 +49,7 @@ def _get_field(cls: schema.Class, p: schema.Property, add_or_none_except: typing
|
|||||||
is_optional=p.is_optional,
|
is_optional=p.is_optional,
|
||||||
is_repeated=p.is_repeated,
|
is_repeated=p.is_repeated,
|
||||||
is_predicate=p.is_predicate,
|
is_predicate=p.is_predicate,
|
||||||
|
is_unordered=p.is_unordered,
|
||||||
trap_name=trap_name,
|
trap_name=trap_name,
|
||||||
)
|
)
|
||||||
args.update(cpp.get_field_override(p.name))
|
args.update(cpp.get_field_override(p.name))
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class Field:
|
|||||||
base_type: str
|
base_type: str
|
||||||
is_optional: bool = False
|
is_optional: bool = False
|
||||||
is_repeated: bool = False
|
is_repeated: bool = False
|
||||||
|
is_unordered: bool = False
|
||||||
is_predicate: bool = False
|
is_predicate: bool = False
|
||||||
trap_name: str = None
|
trap_name: str = None
|
||||||
first: bool = False
|
first: bool = False
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ void {{name}}::emit({{^final}}TrapLabel<{{name}}Tag> id, {{/final}}std::ostream&
|
|||||||
{{#is_repeated}}
|
{{#is_repeated}}
|
||||||
for (auto i = 0u; i < {{field_name}}.size(); ++i) {
|
for (auto i = 0u; i < {{field_name}}.size(); ++i) {
|
||||||
{{^is_optional}}
|
{{^is_optional}}
|
||||||
out << {{trap_name}}Trap{id, i, {{field_name}}[i]} << '\n';
|
out << {{trap_name}}Trap{id, {{^is_unordered}}i, {{/is_unordered}}{{field_name}}[i]} << '\n';
|
||||||
{{/is_optional}}
|
{{/is_optional}}
|
||||||
{{#is_optional}}
|
{{#is_optional}}
|
||||||
if ({{field_name}}[i]) out << {{trap_name}}Trap{id, i, *{{field_name}}[i]} << '\n';
|
if ({{field_name}}[i]) out << {{trap_name}}Trap{id, i, *{{field_name}}[i]} << '\n';
|
||||||
|
|||||||
@@ -62,19 +62,20 @@ def test_two_class_hierarchy(generate):
|
|||||||
("boolean", "bool"),
|
("boolean", "bool"),
|
||||||
("MyClass", "TrapLabel<MyClassTag>"),
|
("MyClass", "TrapLabel<MyClassTag>"),
|
||||||
])
|
])
|
||||||
@pytest.mark.parametrize("property_cls,optional,repeated,trap_name", [
|
@pytest.mark.parametrize("property_cls,optional,repeated,unordered,trap_name", [
|
||||||
(schema.SingleProperty, False, False, None),
|
(schema.SingleProperty, False, False, False, None),
|
||||||
(schema.OptionalProperty, True, False, "MyClassProps"),
|
(schema.OptionalProperty, True, False, False, "MyClassProps"),
|
||||||
(schema.RepeatedProperty, False, True, "MyClassProps"),
|
(schema.RepeatedProperty, False, True, False, "MyClassProps"),
|
||||||
(schema.RepeatedOptionalProperty, True, True, "MyClassProps"),
|
(schema.RepeatedOptionalProperty, True, True, False, "MyClassProps"),
|
||||||
|
(schema.RepeatedUnorderedProperty, False, True, True, "MyClassProps"),
|
||||||
])
|
])
|
||||||
def test_class_with_field(generate, type, expected, property_cls, optional, repeated, trap_name):
|
def test_class_with_field(generate, type, expected, property_cls, optional, repeated, unordered, trap_name):
|
||||||
assert generate([
|
assert generate([
|
||||||
schema.Class(name="MyClass", properties=[property_cls("prop", type)]),
|
schema.Class(name="MyClass", properties=[property_cls("prop", type)]),
|
||||||
]) == [
|
]) == [
|
||||||
cpp.Class(name="MyClass",
|
cpp.Class(name="MyClass",
|
||||||
fields=[cpp.Field("prop", expected, is_optional=optional,
|
fields=[cpp.Field("prop", expected, is_optional=optional,
|
||||||
is_repeated=repeated, trap_name=trap_name)],
|
is_repeated=repeated, is_unordered=unordered, trap_name=trap_name)],
|
||||||
trap_name="MyClasses",
|
trap_name="MyClasses",
|
||||||
final=True)
|
final=True)
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user