Fix flag values

Enums/bitfields have a C identifier, a GLib nick, and a GIR name. The
last two are usually the same except the nick uses '-' and the GIR name
uses '_'. It is confusing.

Blueprint tries to use GIR names for everything, but GTK requires a C
identifier or GLib nick for enum and bitfield values. Blueprint was
sometimes passing the GIR name through instead of finding one of the
other names. Fixed by always emitting the C identifier for enums and
bitfields where the GIR type is known.
This commit is contained in:
James Westman 2022-06-10 13:20:44 -05:00
parent fac311d3c3
commit fd55a5abf2
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
8 changed files with 27 additions and 18 deletions

View file

@ -109,6 +109,13 @@ class LiteralValue(Value):
class Flag(AstNode):
grammar = UseIdent("value")
@property
def c_ident(self):
if isinstance(self.parent.parent.value_type, gir.Bitfield):
return self.parent.parent.value_type.members[self.tokens["value"]].c_ident
else:
return self.tokens["value"]
@docs()
def docs(self):
type = self.parent.parent.value_type
@ -137,15 +144,15 @@ class FlagsValue(Value):
raise CompileError(f"{type.full_name} is not a bitfield type")
def emit_xml(self, xml: XmlEmitter):
xml.put_text("|".join([flag.tokens["value"] for flag in self.children[Flag]]))
xml.put_text("|".join([flag.c_ident for flag in self.children[Flag]]))
class IdentValue(Value):
grammar = UseIdent("value")
def emit_xml(self, xml: XmlEmitter):
if isinstance(self.parent.value_type, gir.Enumeration):
xml.put_text(self.parent.value_type.members[self.tokens["value"]].nick)
if isinstance(self.parent.value_type, gir.Enumeration) or isinstance(self.parent.value_type, gir.Bitfield):
xml.put_text(self.parent.value_type.members[self.tokens["value"]].c_ident)
else:
xml.put_text(self.tokens["value"])