mirror of
https://github.com/github/codeql.git
synced 2026-05-04 05:05:12 +02:00
Codegen: improve implementation of generated parent/child relationship
This improves the implementation of the generated parent/child relationship by adding a new `all_children` field to `ql.Class` which lists all children (both direct and inherited) of a class, carefully avoiding duplicating children in case of diamond inheritance. This: * simplifies the generated code, * avoid children ambiguities in case of diamond inheritance. This only comes with some changes in the order of children in the generated tests (we were previously sorting bases alphabetically there). For the rest this should be a non-functional change.
This commit is contained in:
@@ -133,22 +133,10 @@ def test_non_root_class():
|
||||
assert not cls.root
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"prev_child,is_child", [(None, False), ("", True), ("x", True)]
|
||||
)
|
||||
def test_is_child(prev_child, is_child):
|
||||
p = ql.Property("Foo", "int", prev_child=prev_child)
|
||||
assert p.is_child is is_child
|
||||
|
||||
|
||||
def test_empty_class_no_children():
|
||||
cls = ql.Class("Class", properties=[])
|
||||
assert cls.has_children is False
|
||||
|
||||
|
||||
def test_class_no_children():
|
||||
cls = ql.Class(
|
||||
"Class", properties=[ql.Property("Foo", "int"), ql.Property("Bar", "string")]
|
||||
"Class",
|
||||
all_children=[],
|
||||
)
|
||||
assert cls.has_children is False
|
||||
|
||||
@@ -156,11 +144,7 @@ def test_class_no_children():
|
||||
def test_class_with_children():
|
||||
cls = ql.Class(
|
||||
"Class",
|
||||
properties=[
|
||||
ql.Property("Foo", "int"),
|
||||
ql.Property("Child", "x", prev_child=""),
|
||||
ql.Property("Bar", "string"),
|
||||
],
|
||||
all_children=[ql.Child(ql.Property("Foo", "int"))],
|
||||
)
|
||||
assert cls.has_children is True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user