mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
gir: Allow looking up basic types by name
This commit is contained in:
parent
78960fcd11
commit
762a29b705
1 changed files with 14 additions and 0 deletions
|
@ -106,30 +106,41 @@ class BasicType(GirType):
|
||||||
|
|
||||||
class BoolType(BasicType):
|
class BoolType(BasicType):
|
||||||
name = "bool"
|
name = "bool"
|
||||||
|
glib_type_name = "gboolean"
|
||||||
|
|
||||||
def assignable_to(self, other) -> bool:
|
def assignable_to(self, other) -> bool:
|
||||||
return isinstance(other, BoolType)
|
return isinstance(other, BoolType)
|
||||||
|
|
||||||
class IntType(BasicType):
|
class IntType(BasicType):
|
||||||
name = "int"
|
name = "int"
|
||||||
|
glib_type_name = "gint"
|
||||||
|
|
||||||
def assignable_to(self, other) -> bool:
|
def assignable_to(self, other) -> bool:
|
||||||
return isinstance(other, IntType) or isinstance(other, UIntType) or isinstance(other, FloatType)
|
return isinstance(other, IntType) or isinstance(other, UIntType) or isinstance(other, FloatType)
|
||||||
|
|
||||||
class UIntType(BasicType):
|
class UIntType(BasicType):
|
||||||
name = "uint"
|
name = "uint"
|
||||||
|
glib_type_name = "guint"
|
||||||
|
|
||||||
def assignable_to(self, other) -> bool:
|
def assignable_to(self, other) -> bool:
|
||||||
return isinstance(other, IntType) or isinstance(other, UIntType) or isinstance(other, FloatType)
|
return isinstance(other, IntType) or isinstance(other, UIntType) or isinstance(other, FloatType)
|
||||||
|
|
||||||
class FloatType(BasicType):
|
class FloatType(BasicType):
|
||||||
name = "float"
|
name = "float"
|
||||||
|
glib_type_name = "gfloat"
|
||||||
|
|
||||||
def assignable_to(self, other) -> bool:
|
def assignable_to(self, other) -> bool:
|
||||||
return isinstance(other, FloatType)
|
return isinstance(other, FloatType)
|
||||||
|
|
||||||
class StringType(BasicType):
|
class StringType(BasicType):
|
||||||
name = "string"
|
name = "string"
|
||||||
|
glib_type_name = "gchararray"
|
||||||
|
|
||||||
def assignable_to(self, other) -> bool:
|
def assignable_to(self, other) -> bool:
|
||||||
return isinstance(other, StringType)
|
return isinstance(other, StringType)
|
||||||
|
|
||||||
_BASIC_TYPES = {
|
_BASIC_TYPES = {
|
||||||
|
"bool": BoolType,
|
||||||
"gboolean": BoolType,
|
"gboolean": BoolType,
|
||||||
"int": IntType,
|
"int": IntType,
|
||||||
"gint": IntType,
|
"gint": IntType,
|
||||||
|
@ -623,6 +634,9 @@ class GirContext:
|
||||||
|
|
||||||
|
|
||||||
def get_type(self, name: str, ns: str) -> T.Optional[GirNode]:
|
def get_type(self, name: str, ns: str) -> T.Optional[GirNode]:
|
||||||
|
if ns is None and name in _BASIC_TYPES:
|
||||||
|
return _BASIC_TYPES[name]()
|
||||||
|
|
||||||
ns = ns or "Gtk"
|
ns = ns or "Gtk"
|
||||||
|
|
||||||
if ns not in self.namespaces:
|
if ns not in self.namespaces:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue