mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
decompiler: Support Adw.Breakpoint syntax
Also, improve handling of translated strings.
This commit is contained in:
parent
078ce2f5b8
commit
a12ac1b976
9 changed files with 141 additions and 48 deletions
|
@ -195,3 +195,42 @@ class AdwBreakpointSetters(AstNode):
|
|||
@validate()
|
||||
def unique(self):
|
||||
self.validate_unique_in_parent("Duplicate setters block")
|
||||
|
||||
|
||||
@decompiler("condition", cdata=True)
|
||||
def decompile_condition(ctx: DecompileCtx, gir, cdata):
|
||||
ctx.print(f"condition({escape_quote(cdata)})")
|
||||
|
||||
|
||||
@decompiler("setter", element=True)
|
||||
def decompile_setter(ctx: DecompileCtx, gir, element):
|
||||
assert ctx.parent_node is not None
|
||||
# only run for the first setter
|
||||
for child in ctx.parent_node.children:
|
||||
if child.tag == "setter":
|
||||
if child != element:
|
||||
# already decompiled
|
||||
return
|
||||
else:
|
||||
break
|
||||
|
||||
ctx.print("setters {")
|
||||
for child in ctx.parent_node.children:
|
||||
if child.tag == "setter":
|
||||
object_id = child["object"]
|
||||
property_name = child["property"]
|
||||
obj = ctx.find_object(object_id)
|
||||
if obj is not None:
|
||||
gir_class = ctx.type_by_cname(obj["class"])
|
||||
else:
|
||||
gir_class = None
|
||||
|
||||
if object_id == ctx.template_class:
|
||||
object_id = "template"
|
||||
|
||||
comments, string = ctx.decompile_value(
|
||||
child.cdata,
|
||||
gir_class,
|
||||
(child["translatable"], child["context"], child["comments"]),
|
||||
)
|
||||
ctx.print(f"{comments} {object_id}.{property_name}: {string};")
|
||||
|
|
|
@ -319,7 +319,8 @@ def decompile_constant(
|
|||
else:
|
||||
ctx.print(cdata)
|
||||
else:
|
||||
ctx.print_value(cdata, ctx.type_by_cname(type))
|
||||
_, string = ctx.decompile_value(cdata, ctx.type_by_cname(type))
|
||||
ctx.print(string)
|
||||
|
||||
|
||||
@decompiler("closure", skip_children=True)
|
||||
|
|
|
@ -249,17 +249,12 @@ def a11y_name_completer(lsp, ast_node, match_variables):
|
|||
)
|
||||
|
||||
|
||||
def decompile_attr(ctx: DecompileCtx, attr):
|
||||
if attr["translatable"] is not None and decompile.truthy(attr["translatable"]):
|
||||
ctx.print(f"_({escape_quote(attr.cdata)})")
|
||||
else:
|
||||
ctx.print_value(attr.cdata, get_types(ctx.gir).get(attr["name"]))
|
||||
|
||||
|
||||
@decompiler("accessibility", skip_children=True, element=True)
|
||||
def decompile_accessibility(ctx: DecompileCtx, _gir, element):
|
||||
ctx.print("accessibility {")
|
||||
already_printed = set()
|
||||
types = get_types(ctx.gir)
|
||||
|
||||
for child in element.children:
|
||||
name = child["name"]
|
||||
|
||||
|
@ -270,13 +265,20 @@ def decompile_accessibility(ctx: DecompileCtx, _gir, element):
|
|||
ctx.print(f"{name}: [")
|
||||
for value in element.children:
|
||||
if value["name"] == name:
|
||||
decompile_attr(ctx, value)
|
||||
ctx.print(", ")
|
||||
comments, string = ctx.decompile_value(
|
||||
value.cdata,
|
||||
types.get(value["name"]),
|
||||
(value["translatable"], value["context"], value["comments"]),
|
||||
)
|
||||
ctx.print(f"{comments} {string},")
|
||||
ctx.print("];")
|
||||
else:
|
||||
ctx.print(f"{name}:")
|
||||
decompile_attr(ctx, child)
|
||||
ctx.print(";")
|
||||
comments, string = ctx.decompile_value(
|
||||
child.cdata,
|
||||
types.get(child["name"]),
|
||||
(child["translatable"], child["context"], child["comments"]),
|
||||
)
|
||||
ctx.print(f"{comments} {name}: {string};")
|
||||
|
||||
already_printed.add(name)
|
||||
ctx.print("}")
|
||||
|
|
|
@ -102,6 +102,4 @@ def decompile_template(ctx: DecompileCtx, gir, klass, parent=None):
|
|||
else:
|
||||
ctx.print(f"template {class_name(klass)} : {class_name(parent)} {{")
|
||||
|
||||
ctx.template_class = klass
|
||||
|
||||
return ctx.type_by_cname(klass) or ctx.type_by_cname(parent)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue