aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2015-09-27 17:52:37 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2015-10-14 22:04:20 +0200
commit617fc08783d2356e644266d9e9addcd720a7138a (patch)
treea6fc12bb589d06b41de50a6c2612bcec46ab029b /components/script/dom/bindings/codegen
parent32daa17d5cbcad02db0713e21e52410cdc60480e (diff)
downloadservo-617fc08783d2356e644266d9e9addcd720a7138a.tar.gz
servo-617fc08783d2356e644266d9e9addcd720a7138a.zip
Generate all Derived implementations in codegen
Diffstat (limited to 'components/script/dom/bindings/codegen')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 00df29230c3..163c59de95e 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -5880,6 +5880,20 @@ impl %(name)sCast {
hierarchy[descriptor.getParentName()].append(name)
# Define a `FooDerived` trait for superclasses to implement,
# as well as the `FooCast::to_*` methods that use it.
+ baseName = descriptor.prototypeChain[0]
+ typeIdPat = descriptor.prototypeChain[-1]
+ if upcast:
+ typeIdPat += "(_)"
+ for base in reversed(descriptor.prototypeChain[1:-1]):
+ typeIdPat = "%s(%sTypeId::%s)" % (base, base, typeIdPat)
+ typeIdPat = "%sTypeId::%s" % (baseName, typeIdPat)
+ args = {
+ 'baseName': baseName,
+ 'derivedTrait': name + 'Derived',
+ 'methodName': 'is_' + name.lower(),
+ 'name': name,
+ 'typeIdPat': typeIdPat,
+ }
allprotos.append(CGGeneric("""\
/// Types which `%(name)s` derives from
pub trait %(derivedTrait)s: Sized {
@@ -5917,7 +5931,16 @@ impl %(name)sCast {
}
}
-""" % {'derivedTrait': name + 'Derived', 'name': name, 'methodName': 'is_' + name.lower()}))
+impl %(derivedTrait)s for %(baseName)s {
+ fn %(methodName)s(&self) -> bool {
+ match *self.type_id() {
+ %(typeIdPat)s => true,
+ _ => false,
+ }
+ }
+}
+
+""" % args))
# Implement the `FooDerived` trait for non-root superclasses by deferring to
# the direct superclass. This leaves the implementation of the `FooDerived`