mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Auto merge of #15585 - servo:CGConstant, r=nox
Simplify CGConstant. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15585) <!-- Reviewable:end -->
This commit is contained in:
commit
e52eb2a5e3
1 changed files with 7 additions and 10 deletions
|
@ -4035,17 +4035,14 @@ def convertConstIDLValueToRust(value):
|
|||
|
||||
|
||||
class CGConstant(CGThing):
|
||||
def __init__(self, constants):
|
||||
def __init__(self, constant):
|
||||
CGThing.__init__(self)
|
||||
self.constants = constants
|
||||
self.constant = constant
|
||||
|
||||
def define(self):
|
||||
def stringDecl(const):
|
||||
name = const.identifier.name
|
||||
value = convertConstIDLValueToRust(const.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()
|
||||
name = self.constant.identifier.name
|
||||
value = convertConstIDLValueToRust(self.constant.value)
|
||||
return "pub const %s: %s = %s;\n" % (name, builtinNames[self.constant.value.type.tag()], value)
|
||||
|
||||
|
||||
def getUnionTypeTemplateVars(type, descriptorProvider):
|
||||
|
@ -5723,10 +5720,10 @@ class CGDescriptor(CGThing):
|
|||
cgThings.append(CGClassTraceHook(descriptor))
|
||||
|
||||
# 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:
|
||||
cgThings.append(CGNamespace.build([descriptor.name + "Constants"],
|
||||
CGConstant(constMembers),
|
||||
CGIndenter(CGList(constMembers)),
|
||||
public=True))
|
||||
reexports.append(descriptor.name + 'Constants')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue