aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2014-04-06 19:06:58 +0200
committerMs2ger <ms2ger@gmail.com>2014-04-06 19:06:58 +0200
commit3e0d4a25099a83f7d4631b4dc8309d92f97eba06 (patch)
treeb559306590cd5760915db7ce3b4de6b56935d7fa /src/components/script/dom/bindings/codegen/CodegenRust.py
parent4386bae5763802346012c308646d7c39606f68ea (diff)
downloadservo-3e0d4a25099a83f7d4631b4dc8309d92f97eba06.tar.gz
servo-3e0d4a25099a83f7d4631b4dc8309d92f97eba06.zip
Move all the generated code for enums into CGEnum.
Diffstat (limited to 'src/components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--src/components/script/dom/bindings/codegen/CodegenRust.py44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py
index cce35ffce82..ddf2e7bd9d6 100644
--- a/src/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/src/components/script/dom/bindings/codegen/CodegenRust.py
@@ -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
# don't want to indent empty lines. So only indent lines that have a
# non-newline character on them.
-lineStartDetector = re.compile("^(?=[^\n#])", re.MULTILINE)
+lineStartDetector = re.compile("^(?=[^\n])", re.MULTILINE)
class CGIndenter(CGThing):
"""
A class that takes another CGThing and generates code that indents that
@@ -2908,20 +2908,28 @@ def getEnumValueName(value):
class CGEnum(CGThing):
def __init__(self, enum):
CGThing.__init__(self)
- self.enum = enum
+ inner = """
+use dom::bindings::utils::EnumEntry;
+#[repr(uint)]
+pub enum valuelist {
+ %s
+}
- def define(self):
- return """
- #[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)),
+ ])
- 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 define(self):
+ return self.cgRoot.define()
def convertConstIDLValueToRust(value):
@@ -4656,15 +4664,7 @@ class CGBindingRoot(CGThing):
isCallback=True)
# Do codegen for all the enums
- def makeEnum(e):
- 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] ]
+ cgthings = [CGEnum(e) for e in config.getEnums(webIDLFile)]
# 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