Add support for getters, setters and deleters

This commit is contained in:
Anton Danilkin
2018-08-05 23:32:31 +03:00
parent b4601295d0
commit fd2b2140a9
7 changed files with 213 additions and 44 deletions

View File

@ -38,7 +38,10 @@ pub(crate) struct InterfaceData {
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum OperationId {
Constructor,
Operation(Option<String>)
Operation(Option<String>),
SpecialGetter,
SpecialSetter,
SpecialDeleter,
}
#[derive(Default)]
@ -302,8 +305,9 @@ impl<'b> FirstPass<&'b str> for webidl::ast::Operation {
match self {
webidl::ast::Operation::Regular(op) => op.first_pass(record, self_name),
webidl::ast::Operation::Static(op) => op.first_pass(record, self_name),
webidl::ast::Operation::Special(op) => op.first_pass(record, self_name),
// TODO
webidl::ast::Operation::Special(_) | webidl::ast::Operation::Stringifier(_) => {
webidl::ast::Operation::Stringifier(_) => {
warn!("Unsupported WebIDL operation: {:?}", self);
Ok(())
}
@ -333,6 +337,28 @@ impl<'b> FirstPass<&'b str> for webidl::ast::StaticOperation {
}
}
impl<'b> FirstPass<&'b str> for webidl::ast::SpecialOperation {
fn first_pass<'a>(&'a self, record: &mut FirstPassRecord<'a>, self_name: &'b str) -> Result<()> {
first_pass_operation(
record,
self_name,
match self.name {
None => match self.special_keywords.iter().next() {
Some(webidl::ast::Special::Getter) => OperationId::SpecialGetter,
Some(webidl::ast::Special::Setter) => OperationId::SpecialSetter,
Some(webidl::ast::Special::Deleter) => OperationId::SpecialDeleter,
Some(webidl::ast::Special::LegacyCaller) => return Ok(()),
None => {
panic!("unsupported special operation: {:?} of {}", self, self_name);
}
},
Some(ref name) => OperationId::Operation(Some(name.clone())),
},
&self.arguments,
)
}
}
impl FirstPass<()> for webidl::ast::Mixin {
fn first_pass<'a>(&'a self, record: &mut FirstPassRecord<'a>, (): ()) -> Result<()> {
use webidl::ast::Mixin::*;