mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Merge branch 'main' of https://gitlab.gnome.org/jwestman/blueprint-compiler into formatter
This commit is contained in:
commit
2d5891f2e6
4 changed files with 32 additions and 23 deletions
|
@ -638,29 +638,35 @@ class Namespace(GirNode):
|
||||||
def __init__(self, repo: "Repository", tl: typelib.Typelib) -> None:
|
def __init__(self, repo: "Repository", tl: typelib.Typelib) -> None:
|
||||||
super().__init__(repo, tl)
|
super().__init__(repo, tl)
|
||||||
|
|
||||||
self.entries: T.Dict[str, GirType] = {}
|
@cached_property
|
||||||
|
def entries(self) -> T.Mapping[str, GirType]:
|
||||||
|
entries: dict[str, GirType] = {}
|
||||||
|
|
||||||
|
n_local_entries: int = self.tl.HEADER_N_ENTRIES
|
||||||
|
directory: typelib.Typelib = self.tl.HEADER_DIRECTORY
|
||||||
|
blob_size: int = self.tl.header.HEADER_ENTRY_BLOB_SIZE
|
||||||
|
|
||||||
n_local_entries: int = tl.HEADER_N_ENTRIES
|
|
||||||
directory: typelib.Typelib = tl.HEADER_DIRECTORY
|
|
||||||
for i in range(n_local_entries):
|
for i in range(n_local_entries):
|
||||||
entry = directory[i * tl.HEADER_ENTRY_BLOB_SIZE]
|
entry = directory[i * blob_size]
|
||||||
entry_name: str = entry.DIR_ENTRY_NAME
|
entry_name: str = entry.DIR_ENTRY_NAME
|
||||||
entry_type: int = entry.DIR_ENTRY_BLOB_TYPE
|
entry_type: int = entry.DIR_ENTRY_BLOB_TYPE
|
||||||
entry_blob: typelib.Typelib = entry.DIR_ENTRY_OFFSET
|
entry_blob: typelib.Typelib = entry.DIR_ENTRY_OFFSET
|
||||||
|
|
||||||
if entry_type == typelib.BLOB_TYPE_ENUM:
|
if entry_type == typelib.BLOB_TYPE_ENUM:
|
||||||
self.entries[entry_name] = Enumeration(self, entry_blob)
|
entries[entry_name] = Enumeration(self, entry_blob)
|
||||||
elif entry_type == typelib.BLOB_TYPE_FLAGS:
|
elif entry_type == typelib.BLOB_TYPE_FLAGS:
|
||||||
self.entries[entry_name] = Bitfield(self, entry_blob)
|
entries[entry_name] = Bitfield(self, entry_blob)
|
||||||
elif entry_type == typelib.BLOB_TYPE_OBJECT:
|
elif entry_type == typelib.BLOB_TYPE_OBJECT:
|
||||||
self.entries[entry_name] = Class(self, entry_blob)
|
entries[entry_name] = Class(self, entry_blob)
|
||||||
elif entry_type == typelib.BLOB_TYPE_INTERFACE:
|
elif entry_type == typelib.BLOB_TYPE_INTERFACE:
|
||||||
self.entries[entry_name] = Interface(self, entry_blob)
|
entries[entry_name] = Interface(self, entry_blob)
|
||||||
elif (
|
elif (
|
||||||
entry_type == typelib.BLOB_TYPE_BOXED
|
entry_type == typelib.BLOB_TYPE_BOXED
|
||||||
or entry_type == typelib.BLOB_TYPE_STRUCT
|
or entry_type == typelib.BLOB_TYPE_STRUCT
|
||||||
):
|
):
|
||||||
self.entries[entry_name] = Boxed(self, entry_blob)
|
entries[entry_name] = Boxed(self, entry_blob)
|
||||||
|
|
||||||
|
return entries
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def xml(self):
|
def xml(self):
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
|
from functools import cached_property
|
||||||
|
|
||||||
from .. import gir
|
from .. import gir
|
||||||
from .imports import GtkDirective, Import
|
from .imports import GtkDirective, Import
|
||||||
from .gtkbuilder_template import Template
|
from .gtkbuilder_template import Template
|
||||||
|
@ -42,7 +44,7 @@ class UI(AstNode):
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def gir(self) -> gir.GirContext:
|
def gir(self) -> gir.GirContext:
|
||||||
gir_ctx = gir.GirContext()
|
gir_ctx = gir.GirContext()
|
||||||
self._gir_errors = []
|
self._gir_errors = []
|
||||||
|
|
|
@ -292,7 +292,10 @@ class LanguageServer:
|
||||||
def decompile(self, id, params):
|
def decompile(self, id, params):
|
||||||
text = params.get("text")
|
text = params.get("text")
|
||||||
blp = None
|
blp = None
|
||||||
|
if text.strip() == "":
|
||||||
|
blp = ""
|
||||||
|
printerr("Decompiled to empty blueprint because input was empty")
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
blp = decompiler.decompile_string(text)
|
blp = decompiler.decompile_string(text)
|
||||||
except decompiler.UnsupportedError as e:
|
except decompiler.UnsupportedError as e:
|
||||||
|
|
|
@ -237,9 +237,7 @@ class Typelib:
|
||||||
if loc == 0:
|
if loc == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
end = loc
|
end = self._typelib_file.find(b"\0", loc)
|
||||||
while self._typelib_file[end] != 0:
|
|
||||||
end += 1
|
|
||||||
return self._typelib_file[loc:end].decode("utf-8")
|
return self._typelib_file[loc:end].decode("utf-8")
|
||||||
|
|
||||||
def _int(self, size, signed) -> int:
|
def _int(self, size, signed) -> int:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue