mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-03 15:49:07 -04:00
decompile: Fix bug in lookup tags
A lookup tag with no type attribute would crash the decompiler, even if that was valid. This wasn't caught by the tests since blueprint never generates such XML. Also fixed a bug in the tests that caused decompiler-only tests not to run.
This commit is contained in:
parent
a83c7e936d
commit
a12d3f5c81
5 changed files with 39 additions and 13 deletions
|
@ -255,7 +255,11 @@ def decompile_element(
|
|||
|
||||
ctx._node_stack.append(xml)
|
||||
ctx.start_block()
|
||||
gir = decompiler(*args, **kwargs)
|
||||
|
||||
try:
|
||||
gir = decompiler(*args, **kwargs)
|
||||
except TypeError as e:
|
||||
raise UnsupportedError(tag=xml.tag)
|
||||
|
||||
if not decompiler._skip_children:
|
||||
for child in xml.children:
|
||||
|
@ -266,8 +270,6 @@ def decompile_element(
|
|||
|
||||
except UnsupportedError as e:
|
||||
raise e
|
||||
except TypeError as e:
|
||||
raise UnsupportedError(tag=xml.tag)
|
||||
|
||||
|
||||
def decompile(data: str) -> str:
|
||||
|
|
|
@ -302,12 +302,18 @@ expr.children = [
|
|||
|
||||
@decompiler("lookup", skip_children=True, cdata=True)
|
||||
def decompile_lookup(
|
||||
ctx: DecompileCtx, gir: gir.GirContext, cdata: str, name: str, type: str
|
||||
ctx: DecompileCtx,
|
||||
gir: gir.GirContext,
|
||||
cdata: str,
|
||||
name: str,
|
||||
type: T.Optional[str] = None,
|
||||
):
|
||||
if ctx.parent_node is not None and ctx.parent_node.tag == "property":
|
||||
ctx.print("expr ")
|
||||
|
||||
if t := ctx.type_by_cname(type):
|
||||
if type is None:
|
||||
type = ""
|
||||
elif t := ctx.type_by_cname(type):
|
||||
type = decompile.full_name(t)
|
||||
else:
|
||||
type = "$" + type
|
||||
|
@ -327,7 +333,7 @@ def decompile_lookup(
|
|||
if constant == ctx.template_class:
|
||||
ctx.print("template." + name)
|
||||
elif constant == "":
|
||||
ctx.print("item as <" + type + ">." + name)
|
||||
ctx.print(f"item as <{type}>.{name}")
|
||||
else:
|
||||
ctx.print(constant + "." + name)
|
||||
return
|
||||
|
|
15
tests/samples/issue_187.ui
Normal file
15
tests/samples/issue_187.ui
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<template class="GtkListItem">
|
||||
<property name="child">
|
||||
<object class="GtkLabel">
|
||||
<binding name="label">
|
||||
<lookup type="RecentObject" name="filename">
|
||||
<lookup name="item">GtkListItem</lookup>
|
||||
</lookup>
|
||||
</binding>
|
||||
</object>
|
||||
</property>
|
||||
</template>
|
||||
</interface>
|
7
tests/samples/issue_187_dec.blp
Normal file
7
tests/samples/issue_187_dec.blp
Normal file
|
@ -0,0 +1,7 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template ListItem {
|
||||
child: Label {
|
||||
label: bind template.item as <$RecentObject>.filename;
|
||||
};
|
||||
}
|
|
@ -181,11 +181,7 @@ class TestSamples(unittest.TestCase):
|
|||
|
||||
def test_samples(self):
|
||||
# list the samples directory
|
||||
samples = [
|
||||
f.stem
|
||||
for f in Path(__file__).parent.glob("samples/*.blp")
|
||||
if not f.stem.endswith("_dec")
|
||||
]
|
||||
samples = [f.stem for f in Path(__file__).parent.glob("samples/*.blp")]
|
||||
samples.sort()
|
||||
for sample in samples:
|
||||
REQUIRE_ADW_1_4 = ["adw_breakpoint"]
|
||||
|
@ -215,7 +211,7 @@ class TestSamples(unittest.TestCase):
|
|||
]
|
||||
|
||||
# Decompiler-only tests
|
||||
SKIP_COMPILE = ["issue_177", "translator_comments"]
|
||||
SKIP_COMPILE = ["issue_177", "issue_187", "translator_comments"]
|
||||
|
||||
SKIP_DECOMPILE = [
|
||||
# Comments are not preserved in either direction
|
||||
|
@ -228,7 +224,7 @@ class TestSamples(unittest.TestCase):
|
|||
continue
|
||||
|
||||
with self.subTest(sample):
|
||||
if sample not in SKIP_COMPILE:
|
||||
if sample not in SKIP_COMPILE and not sample.endswith("_dec"):
|
||||
self.assert_sample(sample, skip_run=sample in SKIP_RUN)
|
||||
|
||||
with self.subTest("decompile/" + sample):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue