Skip to content
Permalink
Browse files

Switch from webidl to weedle in script_plugins

This removes the dependency on lalrpop and should speed up compilation
quite a bit.
  • Loading branch information...
Eijebong committed May 15, 2019
1 parent 965f57e commit 13c632e739c030243bf7295b54597657be17ef79

Some generated files are not rendered by default. Learn more.

@@ -14,4 +14,4 @@ unrooted_must_root_lint = []
webidl_lint = []

[dependencies]
webidl = "0.8"
weedle = "0.9"
@@ -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;
@@ -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,
@@ -94,10 +92,22 @@ fn is_webidl_ty(cx: &LateContext, ty: &ty::TyS) -> bool {
}

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(());
@@ -184,39 +194,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()
}
}
}
}

0 comments on commit 13c632e

Please sign in to comment.
You can’t perform that action at this time.