Auto merge of #23405 - Eijebong:weedle, r=jdm

Switch from webidl to weedle in script_plugins

This removes the dependency on lalrpop and should speed up compilation
quite a bit.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23405)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-05-20 21:13:33 -04:00 committed by GitHub
commit 6fb7a8cdc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 149 deletions

View file

@ -14,4 +14,4 @@ unrooted_must_root_lint = []
webidl_lint = []
[dependencies]
webidl = "0.8"
weedle = "0.9"

View file

@ -25,7 +25,7 @@ extern crate rustc;
extern crate rustc_plugin;
extern crate syntax;
extern crate webidl;
extern crate weedle;
use rustc_plugin::Registry;
use syntax::feature_gate::AttributeType::Whitelisted;

View file

@ -13,9 +13,7 @@ use std::fs;
use std::io;
use std::path;
use syntax::ast;
use webidl::ast::*;
use webidl::visitor::*;
use webidl::*;
use weedle;
declare_lint!(
WEBIDL_INHERIT_CORRECT,
@ -96,10 +94,22 @@ fn is_webidl_ty(symbols: &crate::Symbols, cx: &LateContext, ty: &ty::TyS) -> boo
}
fn check_inherits(code: &str, name: &str, parent_name: &str) -> Result<(), Box<Error>> {
let idl = parse_string(code)?;
let mut visitor = InterfaceVisitor::new(name.to_string());
visitor.visit(&idl);
let inherits = visitor.get_inherits();
let idl = weedle::parse(code).expect("Invalid webidl provided");
let mut inherits = "";
for def in idl {
if let weedle::Definition::Interface(def) = def {
if let Some(parent) = def.inheritance {
inherits = parent.identifier.0;
break;
}
} else if let weedle::Definition::CallbackInterface(def) = def {
if let Some(parent) = def.inheritance {
inherits = parent.identifier.0;
break;
}
}
}
if inherits == parent_name {
return Ok(());
@ -186,39 +196,3 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WebIdlPass {
};
}
}
struct InterfaceVisitor {
name: String,
inherits: String,
}
impl InterfaceVisitor {
pub fn new(name: String) -> Self {
InterfaceVisitor {
name: name,
inherits: String::new(),
}
}
pub fn get_inherits(&self) -> &String {
&self.inherits
}
}
impl<'ast> ImmutableVisitor<'ast> for InterfaceVisitor {
fn visit_callback_interface(&mut self, callback_interface: &'ast CallbackInterface) {
if callback_interface.name == self.name {
if let Some(ref inherit) = callback_interface.inherits {
self.inherits = inherit.to_string()
}
}
}
fn visit_non_partial_interface(&mut self, non_partial_interface: &'ast NonPartialInterface) {
if non_partial_interface.name == self.name {
if let Some(ref inherit) = non_partial_interface.inherits {
self.inherits = inherit.to_string()
}
}
}
}