mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
reorganization: Move decompilers
This commit is contained in:
parent
ee5f32622f
commit
1150ae1a09
11 changed files with 138 additions and 140 deletions
|
@ -21,6 +21,8 @@
|
|||
from .. import gir
|
||||
from ..ast_utils import AstNode, validate, docs
|
||||
from ..completions_utils import *
|
||||
from .. import decompiler as decompile
|
||||
from ..decompiler import DecompileCtx, decompiler
|
||||
from ..gir import StringType, BoolType, IntType, FloatType, GirType
|
||||
from ..lsp_utils import Completion, CompletionItemKind, SemanticToken, SemanticTokenType
|
||||
from ..parse_tree import *
|
||||
|
|
|
@ -95,3 +95,14 @@ def validate_parent_type(node, ns: str, name: str, err_msg: str):
|
|||
container_type = node.parent_by_type(Object).gir_class
|
||||
if container_type and not container_type.assignable_to(parent):
|
||||
raise CompileError(f"{container_type.full_name} is not a {parent.full_name}, so it doesn't have {err_msg}")
|
||||
|
||||
|
||||
@decompiler("object")
|
||||
def decompile_object(ctx, gir, klass, id=None):
|
||||
gir_class = ctx.type_by_cname(klass)
|
||||
klass_name = decompile.full_name(gir_class) if gir_class is not None else "." + klass
|
||||
if id is None:
|
||||
ctx.print(f"{klass_name} {{")
|
||||
else:
|
||||
ctx.print(f"{klass_name} {id} {{")
|
||||
return gir_class
|
||||
|
|
|
@ -100,3 +100,14 @@ class Signal(AstNode):
|
|||
swapped="true" if self.tokens["swapped"] else None,
|
||||
object=self.tokens["object"]
|
||||
)
|
||||
|
||||
|
||||
@decompiler("signal")
|
||||
def decompile_signal(ctx, gir, name, handler, swapped="false", object=None):
|
||||
object_name = object or ""
|
||||
name = name.replace("_", "-")
|
||||
if decompile.truthy(swapped):
|
||||
ctx.print(f"{name} => {handler}({object_name}) swapped;")
|
||||
else:
|
||||
ctx.print(f"{name} => {handler}({object_name});")
|
||||
return gir
|
||||
|
|
|
@ -177,3 +177,19 @@ def a11y_completer(ast_node, match_variables):
|
|||
def a11y_name_completer(ast_node, match_variables):
|
||||
for name, type in get_types(ast_node.root.gir).items():
|
||||
yield Completion(name, CompletionItemKind.Property, docs=_get_docs(ast_node.root.gir, type))
|
||||
|
||||
|
||||
@decompiler("relation", cdata=True)
|
||||
def decompile_relation(ctx, gir, name, cdata):
|
||||
ctx.print_attribute(name, cdata, get_types(ctx.gir).get(name))
|
||||
|
||||
@decompiler("state", cdata=True)
|
||||
def decompile_state(ctx, gir, name, cdata, translatable="false"):
|
||||
if decompile.truthy(translatable):
|
||||
ctx.print(f"{name}: _(\"{_escape_quote(cdata)}\");")
|
||||
else:
|
||||
ctx.print_attribute(name, cdata, get_types(ctx.gir).get(name))
|
||||
|
||||
@decompiler("accessibility")
|
||||
def decompile_accessibility(ctx, gir):
|
||||
ctx.print("accessibility {")
|
||||
|
|
|
@ -78,3 +78,27 @@ def file_filter_completer(ast_node, match_variables):
|
|||
yield Completion("patterns", CompletionItemKind.Snippet, snippet="patterns [\"$0\"]")
|
||||
yield Completion("suffixes", CompletionItemKind.Snippet, snippet="suffixes [\"$0\"]")
|
||||
|
||||
|
||||
@decompiler("mime-types")
|
||||
def decompile_mime_types(ctx, gir):
|
||||
ctx.print("mime-types [")
|
||||
|
||||
@decompiler("mime-type", cdata=True)
|
||||
def decompile_mime_type(ctx, gir, cdata):
|
||||
ctx.print(f'"{cdata}",')
|
||||
|
||||
@decompiler("patterns")
|
||||
def decompile_patterns(ctx, gir):
|
||||
ctx.print("patterns [")
|
||||
|
||||
@decompiler("pattern", cdata=True)
|
||||
def decompile_pattern(ctx, gir, cdata):
|
||||
ctx.print(f'"{cdata}",')
|
||||
|
||||
@decompiler("suffixes")
|
||||
def decompile_suffixes(ctx, gir):
|
||||
ctx.print("suffixes [")
|
||||
|
||||
@decompiler("suffix", cdata=True)
|
||||
def decompile_suffix(ctx, gir, cdata):
|
||||
ctx.print(f'"{cdata}",')
|
||||
|
|
|
@ -71,3 +71,8 @@ def layout_completer(ast_node, match_variables):
|
|||
"layout", CompletionItemKind.Snippet,
|
||||
snippet="layout {\n $0\n}"
|
||||
)
|
||||
|
||||
|
||||
@decompiler("layout")
|
||||
def decompile_layout(ctx, gir):
|
||||
ctx.print("layout {")
|
||||
|
|
|
@ -185,3 +185,31 @@ def menu_content_completer(ast_node, match_variables):
|
|||
snippet='icon: "$0";'
|
||||
)
|
||||
|
||||
|
||||
@decompiler("menu")
|
||||
def decompile_menu(ctx, gir, id=None):
|
||||
if id:
|
||||
ctx.print(f"menu {id} {{")
|
||||
else:
|
||||
ctx.print("menu {")
|
||||
|
||||
@decompiler("submenu")
|
||||
def decompile_submenu(ctx, gir, id=None):
|
||||
if id:
|
||||
ctx.print(f"submenu {id} {{")
|
||||
else:
|
||||
ctx.print("submenu {")
|
||||
|
||||
@decompiler("item")
|
||||
def decompile_item(ctx, gir, id=None):
|
||||
if id:
|
||||
ctx.print(f"item {id} {{")
|
||||
else:
|
||||
ctx.print("item {")
|
||||
|
||||
@decompiler("section")
|
||||
def decompile_section(ctx, gir, id=None):
|
||||
if id:
|
||||
ctx.print(f"section {id} {{")
|
||||
else:
|
||||
ctx.print("section {")
|
||||
|
|
|
@ -56,3 +56,11 @@ class Styles(AstNode):
|
|||
def style_completer(ast_node, match_variables):
|
||||
yield Completion("styles", CompletionItemKind.Keyword, snippet="styles [\"$0\"]")
|
||||
|
||||
|
||||
@decompiler("style")
|
||||
def decompile_style(ctx, gir):
|
||||
ctx.print(f"styles [")
|
||||
|
||||
@decompiler("class")
|
||||
def decompile_style_class(ctx, gir, name):
|
||||
ctx.print(f'"{name}",')
|
||||
|
|
|
@ -43,3 +43,12 @@ class Child(AstNode):
|
|||
for child in self.children:
|
||||
child.emit_xml(xml)
|
||||
xml.end_tag()
|
||||
|
||||
|
||||
@decompiler("child")
|
||||
def decompile_child(ctx, gir, type=None, internal_child=None):
|
||||
if type is not None:
|
||||
ctx.print(f"[{type}]")
|
||||
elif internal_child is not None:
|
||||
ctx.print(f"[internal-child {internal_child}]")
|
||||
return gir
|
||||
|
|
|
@ -44,3 +44,13 @@ class Template(Object):
|
|||
for child in self.children:
|
||||
child.emit_xml(xml)
|
||||
xml.end_tag()
|
||||
|
||||
|
||||
@decompiler("template")
|
||||
def decompile_template(ctx: DecompileCtx, gir, klass, parent="Widget"):
|
||||
gir_class = ctx.type_by_cname(parent)
|
||||
if gir_class is None:
|
||||
ctx.print(f"template {klass} : .{parent} {{")
|
||||
else:
|
||||
ctx.print(f"template {klass} : {decompile.full_name(gir_class)} {{")
|
||||
return gir_class
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue