mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
types: Add UncheckedType
This allows us to remember information about an external type, such as its name, while still marking it as unchecked.
This commit is contained in:
parent
f7aa7d0be2
commit
2033bd9e16
7 changed files with 55 additions and 11 deletions
|
@ -24,7 +24,15 @@ from ..errors import CompileError, MultipleErrors
|
|||
from ..completions_utils import *
|
||||
from .. import decompiler as decompile
|
||||
from ..decompiler import DecompileCtx, decompiler
|
||||
from ..gir import StringType, BoolType, IntType, FloatType, GirType, Enumeration
|
||||
from ..gir import (
|
||||
StringType,
|
||||
BoolType,
|
||||
IntType,
|
||||
FloatType,
|
||||
GirType,
|
||||
Enumeration,
|
||||
UncheckedType,
|
||||
)
|
||||
from ..lsp_utils import Completion, CompletionItemKind, SemanticToken, SemanticTokenType
|
||||
from ..parse_tree import *
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class Property(AstNode):
|
|||
|
||||
@property
|
||||
def gir_property(self):
|
||||
if self.gir_class is not None:
|
||||
if self.gir_class is not None and not isinstance(self.gir_class, UncheckedType):
|
||||
return self.gir_class.properties.get(self.tokens["name"])
|
||||
|
||||
@property
|
||||
|
@ -79,7 +79,7 @@ class Property(AstNode):
|
|||
|
||||
@validate("name")
|
||||
def property_exists(self):
|
||||
if self.gir_class is None:
|
||||
if self.gir_class is None or isinstance(self.gir_class, UncheckedType):
|
||||
# Objects that we have no gir data on should not be validated
|
||||
# This happens for classes defined by the app itself
|
||||
return
|
||||
|
|
|
@ -71,7 +71,7 @@ class Signal(AstNode):
|
|||
|
||||
@property
|
||||
def gir_signal(self):
|
||||
if self.gir_class is not None:
|
||||
if self.gir_class is not None and not isinstance(self.gir_class, UncheckedType):
|
||||
return self.gir_class.signals.get(self.tokens["name"])
|
||||
|
||||
@property
|
||||
|
@ -80,7 +80,7 @@ class Signal(AstNode):
|
|||
|
||||
@validate("name")
|
||||
def signal_exists(self):
|
||||
if self.gir_class is None:
|
||||
if self.gir_class is None or isinstance(self.gir_class, UncheckedType):
|
||||
# Objects that we have no gir data on should not be validated
|
||||
# This happens for classes defined by the app itself
|
||||
return
|
||||
|
|
|
@ -53,6 +53,8 @@ class Template(Object):
|
|||
# Templates might not have a parent class defined
|
||||
if class_name := self.class_name:
|
||||
return class_name.gir_type
|
||||
else:
|
||||
return gir.UncheckedType(self.id)
|
||||
|
||||
@validate("id")
|
||||
def unique_in_parent(self):
|
||||
|
|
|
@ -56,12 +56,13 @@ class TypeName(AstNode):
|
|||
return self.root.gir.namespaces.get(self.tokens["namespace"] or "Gtk")
|
||||
|
||||
@property
|
||||
def gir_type(self) -> T.Optional[gir.Class]:
|
||||
def gir_type(self) -> gir.GirType:
|
||||
if self.tokens["class_name"] and not self.tokens["ignore_gir"]:
|
||||
return self.root.gir.get_type(
|
||||
self.tokens["class_name"], self.tokens["namespace"]
|
||||
)
|
||||
return None
|
||||
|
||||
return gir.UncheckedType(self.tokens["class_name"])
|
||||
|
||||
@property
|
||||
def glib_type_name(self) -> str:
|
||||
|
@ -84,7 +85,11 @@ class TypeName(AstNode):
|
|||
class ClassName(TypeName):
|
||||
@validate("namespace", "class_name")
|
||||
def gir_class_exists(self):
|
||||
if self.gir_type is not None and not isinstance(self.gir_type, Class):
|
||||
if (
|
||||
self.gir_type
|
||||
and not isinstance(self.gir_type, UncheckedType)
|
||||
and not isinstance(self.gir_type, Class)
|
||||
):
|
||||
if isinstance(self.gir_type, Interface):
|
||||
raise CompileError(
|
||||
f"{self.gir_type.full_name} is an interface, not a class"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue