Skip to content

Commit

Permalink
deploy module path information for Method and sub-Abstract #2 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
adjivas committed Oct 22, 2017
1 parent 1fd42f2 commit 9e93fb4
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 50 deletions.
14 changes: 8 additions & 6 deletions src/core/item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pub mod state;
pub use self::state::ItemState;

use std::{slice, iter};
use std::ffi::OsString;
use std::rc::Rc;

use ::syntex_syntax::{ptr, ast};
use ::itertools::Itertools;
Expand All @@ -13,13 +15,13 @@ use ::itertools::Itertools;
#[derive(Debug, Clone)]
pub struct Item <'a> {
/// Iterator.
it: iter::Peekable<slice::Iter<'a, ptr::P<ast::Item>>>,
it: iter::Peekable<slice::Iter<'a, (ptr::P<ast::Item>, Rc<Vec<OsString>>)>>,
}

impl <'a>From<iter::Peekable<slice::Iter<'a, ptr::P<ast::Item>>>> for Item<'a> {
impl <'a>From<iter::Peekable<slice::Iter<'a, (ptr::P<ast::Item>, Rc<Vec<OsString>>)>>> for Item<'a> {

/// The constructor method `from` returns a typed and iterable collection of abstract element.
fn from(iter: iter::Peekable<slice::Iter<'a, ptr::P<ast::Item>>>) -> Item {
fn from(iter: iter::Peekable<slice::Iter<'a, (ptr::P<ast::Item>, Rc<Vec<OsString>>)>>) -> Item {
Item {
it: iter,
}
Expand All @@ -33,16 +35,16 @@ impl <'a>Iterator for Item<'a> {
/// enumeration or trait.
fn next(&mut self) -> Option<ItemState<'a>> {
self.it.next().and_then(|item| {
let mut list: Vec<&'a ptr::P<ast::Item>> = vec!(item);
let mut list: Vec<&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>)> = vec!(item);

list.extend(self.it.peeking_take_while(|ref item| {
list.extend(self.it.peeking_take_while(|&&(ref item, _): (&&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>))| {
if let ast::ItemKind::Impl(..) = item.node {
true
} else {
false
}
})
.collect::<Vec<&'a ptr::P<ast::Item>>>());
.collect::<Vec<&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>)>>());
Some(ItemState::from(list))
})
}
Expand Down
9 changes: 7 additions & 2 deletions src/core/item/state/abstraction/enumerate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::fmt;
use std::ffi::OsString;
use std::rc::Rc;

use ::syntex_syntax::print::pprust::ty_to_string;
use ::syntex_syntax::{codemap, symbol, ast};
Expand All @@ -9,15 +11,18 @@ use ::dot::escape_html;

#[derive(Debug, Eq, PartialEq, Clone)]
pub struct Enum<'a> {
pub path: Rc<Vec<OsString>>,
/// Visibility
pub vis: &'a ast::Visibility,
pub name: symbol::InternedString,
pub params: Vec<symbol::InternedString>,
pub variants: Vec<(symbol::InternedString, Vec<String>)>,
}

impl <'a>From<(&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::Variant>)> for Enum<'a> {
fn from((item, ty_params, variants): (&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::Variant>)) -> Enum<'a> {
impl <'a>From<((&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::Variant>), Rc<Vec<OsString>>)> for Enum<'a> {
fn from(((item, ty_params, variants), path): ((&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::Variant>), Rc<Vec<OsString>>)) -> Enum<'a> {
Enum {
path: path,
vis: &item.vis,
name: item.ident.name.as_str(),
params: ty_params.iter()
Expand Down
8 changes: 6 additions & 2 deletions src/core/item/state/abstraction/extend.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::fmt;
use std::ops::Deref;
use std::ffi::OsString;
use std::rc::Rc;

use ::syntex_syntax::print::pprust::ty_to_string;
use ::syntex_syntax::{symbol, ast};
Expand All @@ -8,16 +10,18 @@ use ::dot::escape_html;

#[derive(Debug, Eq, PartialEq, Clone)]
pub struct Trait<'a> {
pub path: Rc<Vec<OsString>>,
/// Visibility
pub vis: &'a ast::Visibility,
pub name: symbol::InternedString,
pub params: Vec<symbol::InternedString>,
pub items: Vec<(symbol::InternedString, Vec<String>, String)>,
}

impl <'a>From<(&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::TraitItem>)> for Trait<'a> {
fn from((item, ty_params, trait_item): (&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::TraitItem>)) -> Trait<'a> {
impl <'a>From<((&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::TraitItem>), Rc<Vec<OsString>>)> for Trait<'a> {
fn from(((item, ty_params, trait_item), path): ((&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::TraitItem>), Rc<Vec<OsString>>)) -> Trait<'a> {
Trait {
path: path,
vis: &item.vis,
name: item.ident.name.as_str(),
params: ty_params.iter()
Expand Down
18 changes: 10 additions & 8 deletions src/core/item/state/abstraction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pub mod enumerate;

use std::fmt;
use std::vec;
use std::ffi::OsString;
use std::rc::Rc;

use ::syntex_syntax::symbol;
use ::core::ast;
Expand Down Expand Up @@ -42,13 +44,13 @@ impl<'a> IntoIterator for &'a Abstract<'a> {

fn into_iter(self) -> Self::IntoIter {
match self {
&Abstract::Struct(Struct {vis: _, name: _, fields: ref ty_field}) => {
&Abstract::Struct(Struct {path: _, vis: _, name: _, fields: ref ty_field}) => {
ty_field.iter()
.map(|&(_, _, ref ty): &'a (&'a ast::Visibility, symbol::InternedString, String)| ty)
.collect::<Vec<&'a String>>()
.into_iter()
},
&Abstract::Enum(Enum {vis: _, name: _, params: _, variants: ref ty_multi_field}) => {
&Abstract::Enum(Enum {path: _, vis: _, name: _, params: _, variants: ref ty_multi_field}) => {
ty_multi_field.iter()
.map(|&(_, ref ty_field): &'a (symbol::InternedString, Vec<String>)|
ty_field.iter()
Expand All @@ -71,20 +73,20 @@ impl <'a> Default for Abstract<'a> {
}
}

impl <'a>From<(&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::TraitItem>)> for Abstract<'a> {
fn from(arguments: (&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::TraitItem>)) -> Abstract<'a> {
impl <'a>From<((&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::TraitItem>), Rc<Vec<OsString>>)> for Abstract<'a> {
fn from(arguments: ((&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::TraitItem>), Rc<Vec<OsString>>)) -> Abstract<'a> {
Abstract::Trait(Trait::from(arguments))
}
}

impl <'a>From<(&'a ast::Item, &'a Vec<ast::StructField>)> for Abstract<'a> {
fn from(arguments: (&'a ast::Item, &'a Vec<ast::StructField>)) -> Abstract<'a> {
impl <'a>From<((&'a ast::Item, &'a Vec<ast::StructField>), Rc<Vec<OsString>>)> for Abstract<'a> {
fn from(arguments: ((&'a ast::Item, &'a Vec<ast::StructField>), Rc<Vec<OsString>>)) -> Abstract<'a> {
Abstract::Struct(Struct::from(arguments))
}
}

impl <'a>From<(&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::Variant>)> for Abstract<'a> {
fn from(arguments: (&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::Variant>)) -> Abstract<'a> {
impl <'a>From<((&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::Variant>), Rc<Vec<OsString>>)> for Abstract<'a> {
fn from(arguments: ((&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::Variant>), Rc<Vec<OsString>>)) -> Abstract<'a> {
Abstract::Enum(Enum::from(arguments))
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/core/item/state/abstraction/structure.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::fmt;
use std::ffi::OsString;
use std::rc::Rc;

use ::syntex_syntax::print::pprust::ty_to_string;
use ::syntex_syntax::{symbol, ast};
Expand All @@ -9,14 +11,17 @@ use ::dot::escape_html;

#[derive(Debug, Eq, PartialEq, Clone)]
pub struct Struct<'a> {
pub path: Rc<Vec<OsString>>,
/// Visibility
pub vis: &'a ast::Visibility,
pub name: symbol::InternedString,
pub fields: Vec<(&'a ast::Visibility, symbol::InternedString, String)>,
}

impl <'a>From<(&'a ast::Item, &'a Vec<ast::StructField>)> for Struct<'a> {
fn from((item, struct_field): (&'a ast::Item, &'a Vec<ast::StructField>)) -> Struct<'a> {
impl <'a>From<((&'a ast::Item, &'a Vec<ast::StructField>), Rc<Vec<OsString>>)> for Struct<'a> {
fn from(((item, struct_field), path): ((&'a ast::Item, &'a Vec<ast::StructField>), Rc<Vec<OsString>>)) -> Struct<'a> {
Struct {
path: path,
vis: &item.vis,
name: item.ident.name.as_str(),
fields: struct_field.iter()
Expand Down
19 changes: 12 additions & 7 deletions src/core/item/state/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use super::DEFAULT_FUNC;

use std::ops::Deref;
use std::fmt;
use std::ffi::OsString;
use std::rc::Rc;

use ::syntex_syntax::print::pprust::{ty_to_string, arg_to_string};
use ::syntex_syntax::symbol::InternedString;
Expand All @@ -14,7 +16,8 @@ use ::dot::escape_html;
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct Method <'a> {
/// visibility, method's name, arguments, result.
func: Vec<(&'a ast::Visibility, InternedString, Vec<String>, Option<String>)>
func: Vec<(&'a ast::Visibility, InternedString, Vec<String>, Option<String>)>,
path: Rc<Vec<OsString>>,
}

impl <'a> Method <'a> {
Expand All @@ -37,17 +40,18 @@ impl <'a> Method <'a> {
}
}

impl <'a> From<Vec<(&'a ast::Visibility, InternedString, Vec<String>, Option<String>)>> for Method<'a> {
fn from(func: Vec<(&'a ast::Visibility, InternedString, Vec<String>, Option<String>)>) -> Method<'a> {
impl <'a> From<(Vec<(&'a ast::Visibility, InternedString, Vec<String>, Option<String>)>, Rc<Vec<OsString>>)> for Method<'a> {
fn from((func, path): (Vec<(&'a ast::Visibility, InternedString, Vec<String>, Option<String>)>, Rc<Vec<OsString>>)) -> Method<'a> {
Method {
func: func,
path: path,
}
}
}

impl <'a> From<&'a Vec<ast::ImplItem>> for Method<'a> {
fn from(impl_item: &'a Vec<ast::ImplItem>) -> Method<'a> {
Method::from(impl_item.iter()
impl <'a> From<(&'a Vec<ast::ImplItem>, Rc<Vec<OsString>>)> for Method<'a> {
fn from((impl_item, path): (&'a Vec<ast::ImplItem>, Rc<Vec<OsString>>)) -> Method<'a> {
Method::from((impl_item.iter()
.filter_map(|&ast::ImplItem {id: _, ident: ast::Ident { name, ..}, ref vis, defaultness: _, attrs: _, ref node, .. }| {
if let &ast::ImplItemKind::Method(ast::MethodSig {unsafety: _, constness: _, abi: _, ref decl, ..}, _) = node {
if let &ast::FnDecl {ref inputs, output: ast::FunctionRetTy::Ty(ref ty), ..} = decl.deref() {
Expand All @@ -61,7 +65,8 @@ impl <'a> From<&'a Vec<ast::ImplItem>> for Method<'a> {
None
}
})
.collect::<Vec<(&'a ast::Visibility, InternedString, Vec<String>, Option<String>)>>())
.collect::<Vec<(&'a ast::Visibility, InternedString, Vec<String>, Option<String>)>>(),
path))
}
}

Expand Down
24 changes: 13 additions & 11 deletions src/core/item/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use super::relation::Relation;

use std::ops::BitOr;
use std::fmt;
use std::ffi::OsString;
use std::rc::Rc;

use ::syntex_syntax::symbol::InternedString;
use ::syntex_syntax::{ptr, ast};
Expand Down Expand Up @@ -120,21 +122,21 @@ impl <'a> ItemState <'a> {
}
}

impl <'a>From<(Abstract<'a>, Vec<&'a ptr::P<ast::Item>>)> for ItemState<'a> {
fn from((node, properties): (Abstract<'a>, Vec<&'a ptr::P<ast::Item>>)) -> ItemState<'a> {
impl <'a>From<(Abstract<'a>, Vec<&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>)>)> for ItemState<'a> {
fn from((node, properties): (Abstract<'a>, Vec<&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>)>)) -> ItemState<'a> {
ItemState {
node: node,
method: properties.iter()
.filter_map(|item: (&&'a ptr::P<ast::Item>)|
.filter_map(|&&(ref item, ref path): (&&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>))|
if let ast::ItemKind::Impl(_, _, _, _, None, _, ref impl_item) = item.node {
Some(Method::from(impl_item))
Some(Method::from((impl_item, Rc::clone(path))))
} else {
None
}
)
.collect::<Vec<Method>>(),
implem: properties.iter()
.filter_map(|item: (&&'a ptr::P<ast::Item>)|
.filter_map(|&&(ref item, _): (&&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>))|
if let ast::ItemKind::Impl(_, _, _, _, Some(ast::TraitRef {path: ast::Path {span: _, ref segments}, ..}), _, ref impl_item) = item.node {
Some(Implem::from((segments, impl_item)))
} else {
Expand All @@ -146,26 +148,26 @@ impl <'a>From<(Abstract<'a>, Vec<&'a ptr::P<ast::Item>>)> for ItemState<'a> {
}
}

impl <'a>From<Vec<&'a ptr::P<ast::Item>>> for ItemState<'a> {
fn from(state: Vec<&'a ptr::P<ast::Item>>) -> ItemState<'a> {
state.split_first().and_then(|(ref item, properties): (&&'a ptr::P<ast::Item>, &[&'a ptr::P<ast::Item>])| {
impl <'a>From<Vec<&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>)>> for ItemState<'a> {
fn from(state: Vec<&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>)>) -> ItemState<'a> {
state.split_first().and_then(|(&&(ref item, ref path), properties): (&&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>), &[&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>)])| {
match &item.node {
/// Trait.
&ast::ItemKind::Trait(_, ast::Generics {lifetimes: _, ref ty_params, ..}, _, ref trait_item) => {
let kind: (&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::TraitItem>) = (item, ty_params, trait_item);
let kind: (Abstract, Vec<&'a ptr::P<ast::Item>>) = (Abstract::from(kind), properties.to_vec());
let kind: (Abstract, Vec<&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>)>) = (Abstract::from((kind, Rc::clone(path))), properties.to_vec());
Some(ItemState::from(kind))
},
/// Structure with variables.
&ast::ItemKind::Struct(ast::VariantData::Struct(ref struct_field, _), ..) => {
let kind: (&'a ast::Item, &'a Vec<ast::StructField>) = (item, struct_field);
let kind: (Abstract, Vec<&'a ptr::P<ast::Item>>) = (Abstract::from(kind), properties.to_vec());
let kind: (Abstract, Vec<&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>)>) = (Abstract::from((kind, Rc::clone(path))), properties.to_vec());
Some(ItemState::from(kind))
},
/// Enumeration with variables.
&ast::ItemKind::Enum(ast::EnumDef {ref variants}, ast::Generics {lifetimes: _, ref ty_params, ..}) => {
let kind: (&'a ast::Item, &'a Vec<ast::TyParam>, &'a Vec<ast::Variant>) = (item, ty_params, variants);
let kind: (Abstract, Vec<&'a ptr::P<ast::Item>>) = (Abstract::from(kind), properties.to_vec());
let kind: (Abstract, Vec<&'a (ptr::P<ast::Item>, Rc<Vec<OsString>>)>) = (Abstract::from((kind, Rc::clone(path))), properties.to_vec());
Some(ItemState::from(kind))
},
_ => None,
Expand Down
6 changes: 4 additions & 2 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use self::item::relation::Relation;
use std::{slice, iter};
use std::borrow::Cow;
use std::ops::BitOr;
use std::ffi::OsString;
use std::rc::Rc;

use ::syntex_syntax::{ptr, ast};
use ::dot::{Nodes, Edges, Arrow, Style, GraphWalk, Labeller, LabelText, Id};
Expand All @@ -28,8 +30,8 @@ impl <'a> From<Item<'a>> for ListItem <'a> {
}
}

impl <'a> From<iter::Peekable<slice::Iter<'a, ptr::P<ast::Item>>>> for ListItem <'a> {
fn from(list: iter::Peekable<slice::Iter<'a, ptr::P<ast::Item>>>) -> ListItem <'a> {
impl <'a> From<iter::Peekable<slice::Iter<'a, (ptr::P<ast::Item>, Rc<Vec<OsString>>)>>> for ListItem <'a> {
fn from(list: iter::Peekable<slice::Iter<'a, (ptr::P<ast::Item>, Rc<Vec<OsString>>)>>) -> ListItem <'a> {
ListItem::from(Item::from(list))
}
}
Expand Down
Loading

0 comments on commit 9e93fb4

Please sign in to comment.