mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Move all the generated code for enums into CGEnum.
This commit is contained in:
parent
4386bae576
commit
3e0d4a2509
1 changed files with 22 additions and 22 deletions
|
@ -1549,7 +1549,7 @@ static NativeHooks: NativePropertyHooks = NativePropertyHooks { resolve_own_prop
|
||||||
# We'll want to insert the indent at the beginnings of lines, but we
|
# We'll want to insert the indent at the beginnings of lines, but we
|
||||||
# don't want to indent empty lines. So only indent lines that have a
|
# don't want to indent empty lines. So only indent lines that have a
|
||||||
# non-newline character on them.
|
# non-newline character on them.
|
||||||
lineStartDetector = re.compile("^(?=[^\n#])", re.MULTILINE)
|
lineStartDetector = re.compile("^(?=[^\n])", re.MULTILINE)
|
||||||
class CGIndenter(CGThing):
|
class CGIndenter(CGThing):
|
||||||
"""
|
"""
|
||||||
A class that takes another CGThing and generates code that indents that
|
A class that takes another CGThing and generates code that indents that
|
||||||
|
@ -2908,20 +2908,28 @@ def getEnumValueName(value):
|
||||||
class CGEnum(CGThing):
|
class CGEnum(CGThing):
|
||||||
def __init__(self, enum):
|
def __init__(self, enum):
|
||||||
CGThing.__init__(self)
|
CGThing.__init__(self)
|
||||||
self.enum = enum
|
inner = """
|
||||||
|
use dom::bindings::utils::EnumEntry;
|
||||||
|
#[repr(uint)]
|
||||||
|
pub enum valuelist {
|
||||||
|
%s
|
||||||
|
}
|
||||||
|
|
||||||
|
pub static strings: &'static [EnumEntry] = &[
|
||||||
|
%s,
|
||||||
|
];
|
||||||
|
""" % (",\n ".join(map(getEnumValueName, enum.values())),
|
||||||
|
",\n ".join(['EnumEntry {value: &"' + val + '", length: ' + str(len(val)) + '}' for val in enum.values()]))
|
||||||
|
|
||||||
|
self.cgRoot = CGList([
|
||||||
|
CGNamespace.build([enum.identifier.name + "Values"],
|
||||||
|
CGIndenter(CGGeneric(inner)), public=True),
|
||||||
|
CGGeneric("pub type %s = self::%sValues::valuelist;\n" %
|
||||||
|
(enum.identifier.name, enum.identifier.name)),
|
||||||
|
])
|
||||||
|
|
||||||
def define(self):
|
def define(self):
|
||||||
return """
|
return self.cgRoot.define()
|
||||||
#[repr(uint)]
|
|
||||||
pub enum valuelist {
|
|
||||||
%s
|
|
||||||
}
|
|
||||||
|
|
||||||
pub static strings: &'static [EnumEntry] = &[
|
|
||||||
%s,
|
|
||||||
];
|
|
||||||
""" % (",\n ".join(map(getEnumValueName, self.enum.values())),
|
|
||||||
",\n ".join(['EnumEntry {value: &"' + val + '", length: ' + str(len(val)) + '}' for val in self.enum.values()]))
|
|
||||||
|
|
||||||
|
|
||||||
def convertConstIDLValueToRust(value):
|
def convertConstIDLValueToRust(value):
|
||||||
|
@ -4656,15 +4664,7 @@ class CGBindingRoot(CGThing):
|
||||||
isCallback=True)
|
isCallback=True)
|
||||||
|
|
||||||
# Do codegen for all the enums
|
# Do codegen for all the enums
|
||||||
def makeEnum(e):
|
cgthings = [CGEnum(e) for e in config.getEnums(webIDLFile)]
|
||||||
return CGNamespace.build([e.identifier.name + "Values"],
|
|
||||||
CGList([CGGeneric(" use dom::bindings::utils::EnumEntry;"),
|
|
||||||
CGEnum(e)]), public=True)
|
|
||||||
def makeEnumTypedef(e):
|
|
||||||
return CGGeneric("pub type %s = self::%sValues::valuelist;\n" %
|
|
||||||
(e.identifier.name, e.identifier.name))
|
|
||||||
cgthings = [ fun(e) for e in config.getEnums(webIDLFile)
|
|
||||||
for fun in [makeEnum, makeEnumTypedef] ]
|
|
||||||
|
|
||||||
# Do codegen for all the dictionaries. We have to be a bit careful
|
# Do codegen for all the dictionaries. We have to be a bit careful
|
||||||
# here, because we have to generate these in order from least derived
|
# here, because we have to generate these in order from least derived
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue