Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from webidl to weedle in script_plugins #23405

Merged
merged 1 commit into from May 21, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

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 {
This conversation was marked as resolved by CYBAI

This comment has been minimized.

Copy link
@CYBAI

CYBAI May 16, 2019

Collaborator

Depends on you to update! :)

How about using pattern matching here 👀?

for def in idl {
  match def {
    weedle::Definition::Interface(def) | weedle::Definition::CallbackInterface(def) => {
      if let Some(parent) = def.inheritance {
        inherits = parent.identifier.0;
        break;
      }
    },
    _ => continue
  }
}

Or, maybe we can use filter_map with take here? 🤔

let inherits =
  idl.iter().filter_map(|def| {
    match def {
      weedle::Definition::Interface(def) | weedle::Definition::CallbackInterface(def) => def.inheritance,
      _ => None
    }
  })
  .take(1)
  .map_or("", |parent| parent.identifier.0);

This comment has been minimized.

Copy link
@Eijebong

Eijebong May 16, 2019

Author Member

I don't think I can because the types of both dep is different

This comment has been minimized.

Copy link
@CYBAI

CYBAI May 16, 2019

Collaborator

Ah, I see; then please ignore me, thanks 🙇

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()
}
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.