Simplify CGConstant.

This commit is contained in:
Ms2ger 2017-02-16 12:03:43 +01:00
parent 84a44a4014
commit 890273e846

View file

@ -4011,17 +4011,14 @@ def convertConstIDLValueToRust(value):
class CGConstant(CGThing): class CGConstant(CGThing):
def __init__(self, constants): def __init__(self, constant):
CGThing.__init__(self) CGThing.__init__(self)
self.constants = constants self.constant = constant
def define(self): def define(self):
def stringDecl(const): name = self.constant.identifier.name
name = const.identifier.name value = convertConstIDLValueToRust(self.constant.value)
value = convertConstIDLValueToRust(const.value) return "pub const %s: %s = %s;\n" % (name, builtinNames[self.constant.value.type.tag()], value)
return CGGeneric("pub const %s: %s = %s;\n" % (name, builtinNames[const.value.type.tag()], value))
return CGIndenter(CGList(stringDecl(m) for m in self.constants)).define()
def getUnionTypeTemplateVars(type, descriptorProvider): def getUnionTypeTemplateVars(type, descriptorProvider):
@ -5696,10 +5693,10 @@ class CGDescriptor(CGThing):
cgThings.append(CGClassTraceHook(descriptor)) cgThings.append(CGClassTraceHook(descriptor))
# If there are no constant members, don't make a module for constants # If there are no constant members, don't make a module for constants
constMembers = [m for m in descriptor.interface.members if m.isConst()] constMembers = [CGConstant(m) for m in descriptor.interface.members if m.isConst()]
if constMembers: if constMembers:
cgThings.append(CGNamespace.build([descriptor.name + "Constants"], cgThings.append(CGNamespace.build([descriptor.name + "Constants"],
CGConstant(constMembers), CGIndenter(CGList(constMembers)),
public=True)) public=True))
reexports.append(descriptor.name + 'Constants') reexports.append(descriptor.name + 'Constants')