diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-10-15 12:53:08 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-10-15 12:53:08 -0600 |
commit | 417cf5738e4609f4b2e34e9e0c4f7ef68f087432 (patch) | |
tree | 2e6e92349e91af0c96966a0fa5d43f8853f2e07d /components/script/dom/bindings/codegen/CodegenRust.py | |
parent | 5a0a91eba794af027723051c7f039cb22088aa65 (diff) | |
parent | 7d6ea834790445d2ea71ca186484ef59ac2ac268 (diff) | |
download | servo-417cf5738e4609f4b2e34e9e0c4f7ef68f087432.tar.gz servo-417cf5738e4609f4b2e34e9e0c4f7ef68f087432.zip |
Auto merge of #8020 - nox:codegen-derived, r=Ms2ger
Generate all Derived implementations in codegen
Follow-up of #7873.
@Ms2ger r? :)
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8020)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 25 |
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 3378700ca99..1d054d03f14 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -5885,6 +5885,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 { @@ -5922,7 +5936,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` |