2013-09-12 21:10:51 -04:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
//! This module contains the "cleaned" pieces of the AST, and the functions
|
|
|
|
//! that clean them.
|
|
|
|
|
|
|
|
use syntax;
|
|
|
|
use syntax::ast;
|
2013-09-24 13:55:22 -07:00
|
|
|
use syntax::ast_util;
|
2013-09-26 12:53:06 -07:00
|
|
|
use syntax::attr;
|
2013-09-18 22:18:38 -07:00
|
|
|
use syntax::attr::AttributeMethods;
|
2013-11-01 18:06:31 -07:00
|
|
|
use syntax::codemap::Pos;
|
2014-01-08 10:35:15 -08:00
|
|
|
use syntax::parse::token::InternedString;
|
|
|
|
use syntax::parse::token;
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-05-02 16:15:12 -07:00
|
|
|
use rustc::back::link;
|
|
|
|
use rustc::driver::driver;
|
2013-10-02 15:39:32 -07:00
|
|
|
use rustc::metadata::cstore;
|
|
|
|
use rustc::metadata::csearch;
|
|
|
|
use rustc::metadata::decoder;
|
|
|
|
|
2014-04-02 16:54:22 -07:00
|
|
|
use std::strbuf::StrBuf;
|
2013-10-02 15:39:32 -07:00
|
|
|
|
2014-03-05 16:36:01 +02:00
|
|
|
use core;
|
2013-08-15 16:28:54 -04:00
|
|
|
use doctree;
|
|
|
|
use visit_ast;
|
|
|
|
|
2014-04-26 22:45:50 +09:00
|
|
|
/// A stable identifier to the particular version of JSON output.
|
|
|
|
/// Increment this when the `Crate` and related structures change.
|
|
|
|
pub static SCHEMA_VERSION: &'static str = "0.8.2";
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
pub trait Clean<T> {
|
|
|
|
fn clean(&self) -> T;
|
|
|
|
}
|
|
|
|
|
2014-02-28 17:46:09 -08:00
|
|
|
impl<T: Clean<U>, U> Clean<Vec<U>> for Vec<T> {
|
|
|
|
fn clean(&self) -> Vec<U> {
|
|
|
|
self.iter().map(|x| x.clean()).collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
impl<T: Clean<U>, U> Clean<U> for @T {
|
|
|
|
fn clean(&self) -> U {
|
|
|
|
(**self).clean()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Clean<U>, U> Clean<Option<U>> for Option<T> {
|
|
|
|
fn clean(&self) -> Option<U> {
|
|
|
|
match self {
|
|
|
|
&None => None,
|
|
|
|
&Some(ref v) => Some(v.clean())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 01:52:37 +11:00
|
|
|
impl<T: Clean<U>, U> Clean<Vec<U>> for syntax::owned_slice::OwnedSlice<T> {
|
2014-02-28 17:46:09 -08:00
|
|
|
fn clean(&self) -> Vec<U> {
|
2014-03-20 01:52:37 +11:00
|
|
|
self.iter().map(|x| x.clean()).collect()
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Crate {
|
2014-05-12 13:44:59 -07:00
|
|
|
pub name: StrBuf,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub module: Option<Item>,
|
|
|
|
pub externs: Vec<(ast::CrateNum, ExternalCrate)>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-07 18:46:16 -08:00
|
|
|
impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> Crate {
|
2014-04-28 20:36:08 -07:00
|
|
|
let cx = super::ctxtkey.get().unwrap();
|
2013-10-02 15:39:32 -07:00
|
|
|
|
2014-03-05 15:28:08 -08:00
|
|
|
let mut externs = Vec::new();
|
2014-03-05 16:36:01 +02:00
|
|
|
cx.sess().cstore.iter_crate_data(|n, meta| {
|
2014-02-16 22:31:05 -08:00
|
|
|
externs.push((n, meta.clean()));
|
2013-11-21 15:42:55 -08:00
|
|
|
});
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-05-02 16:15:12 -07:00
|
|
|
let input = driver::FileInput(cx.src.clone());
|
|
|
|
let t_outputs = driver::build_output_filenames(&input,
|
|
|
|
&None,
|
|
|
|
&None,
|
|
|
|
self.attrs.as_slice(),
|
|
|
|
cx.sess());
|
|
|
|
let id = link::find_crate_id(self.attrs.as_slice(),
|
2014-05-09 18:45:36 -07:00
|
|
|
t_outputs.out_filestem.as_slice());
|
2013-08-15 16:28:54 -04:00
|
|
|
Crate {
|
2014-05-12 13:44:59 -07:00
|
|
|
name: id.name.to_strbuf(),
|
2013-08-15 16:28:54 -04:00
|
|
|
module: Some(self.module.clean()),
|
2013-10-02 15:39:32 -07:00
|
|
|
externs: externs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct ExternalCrate {
|
2014-05-12 13:44:59 -07:00
|
|
|
pub name: StrBuf,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub attrs: Vec<Attribute>,
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<ExternalCrate> for cstore::crate_metadata {
|
|
|
|
fn clean(&self) -> ExternalCrate {
|
|
|
|
ExternalCrate {
|
2014-05-12 13:44:59 -07:00
|
|
|
name: self.name.to_strbuf(),
|
2013-12-18 14:10:28 -08:00
|
|
|
attrs: decoder::get_crate_attributes(self.data()).clean()
|
2014-03-05 11:04:36 -08:00
|
|
|
.move_iter()
|
|
|
|
.collect(),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Anything with a source location and set of attributes and, optionally, a
|
|
|
|
/// name. That is, anything that can be documented. This doesn't correspond
|
|
|
|
/// directly to the AST's concept of an item; it's a strict superset.
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Item {
|
|
|
|
/// Stringified span
|
2014-03-28 10:27:24 -07:00
|
|
|
pub source: Span,
|
2013-08-15 16:28:54 -04:00
|
|
|
/// Not everything has a name. E.g., impls
|
2014-05-12 13:44:59 -07:00
|
|
|
pub name: Option<StrBuf>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub attrs: Vec<Attribute> ,
|
|
|
|
pub inner: ItemEnum,
|
|
|
|
pub visibility: Option<Visibility>,
|
|
|
|
pub id: ast::NodeId,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2013-09-18 22:18:38 -07:00
|
|
|
impl Item {
|
|
|
|
/// Finds the `doc` attribute as a List and returns the list of attributes
|
|
|
|
/// nested inside.
|
|
|
|
pub fn doc_list<'a>(&'a self) -> Option<&'a [Attribute]> {
|
|
|
|
for attr in self.attrs.iter() {
|
|
|
|
match *attr {
|
2014-05-12 13:44:59 -07:00
|
|
|
List(ref x, ref list) if "doc" == x.as_slice() => {
|
|
|
|
return Some(list.as_slice());
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Finds the `doc` attribute as a NameValue and returns the corresponding
|
|
|
|
/// value found.
|
|
|
|
pub fn doc_value<'a>(&'a self) -> Option<&'a str> {
|
|
|
|
for attr in self.attrs.iter() {
|
|
|
|
match *attr {
|
2014-05-12 13:44:59 -07:00
|
|
|
NameValue(ref x, ref v) if "doc" == x.as_slice() => {
|
|
|
|
return Some(v.as_slice());
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2014-04-29 03:59:48 +09:00
|
|
|
pub fn is_hidden_from_doc(&self) -> bool {
|
|
|
|
match self.doc_list() {
|
|
|
|
Some(ref l) => {
|
|
|
|
for innerattr in l.iter() {
|
|
|
|
match *innerattr {
|
2014-05-12 13:44:59 -07:00
|
|
|
Word(ref s) if "hidden" == s.as_slice() => {
|
|
|
|
return true
|
|
|
|
}
|
2014-04-29 03:59:48 +09:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
None => ()
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-18 22:18:38 -07:00
|
|
|
pub fn is_mod(&self) -> bool {
|
2013-11-28 12:22:53 -08:00
|
|
|
match self.inner { ModuleItem(..) => true, _ => false }
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
pub fn is_trait(&self) -> bool {
|
2013-11-28 12:22:53 -08:00
|
|
|
match self.inner { TraitItem(..) => true, _ => false }
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
pub fn is_struct(&self) -> bool {
|
2013-11-28 12:22:53 -08:00
|
|
|
match self.inner { StructItem(..) => true, _ => false }
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
pub fn is_enum(&self) -> bool {
|
2013-11-28 12:22:53 -08:00
|
|
|
match self.inner { EnumItem(..) => true, _ => false }
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
pub fn is_fn(&self) -> bool {
|
2013-11-28 12:22:53 -08:00
|
|
|
match self.inner { FunctionItem(..) => true, _ => false }
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum ItemEnum {
|
|
|
|
StructItem(Struct),
|
|
|
|
EnumItem(Enum),
|
|
|
|
FunctionItem(Function),
|
|
|
|
ModuleItem(Module),
|
|
|
|
TypedefItem(Typedef),
|
|
|
|
StaticItem(Static),
|
|
|
|
TraitItem(Trait),
|
|
|
|
ImplItem(Impl),
|
2014-03-16 19:12:00 -04:00
|
|
|
/// `use` and `extern crate`
|
2013-08-15 16:28:54 -04:00
|
|
|
ViewItemItem(ViewItem),
|
2014-03-16 19:12:00 -04:00
|
|
|
/// A method signature only. Used for required methods in traits (ie,
|
|
|
|
/// non-default-methods).
|
2013-08-15 16:28:54 -04:00
|
|
|
TyMethodItem(TyMethod),
|
2014-03-16 19:12:00 -04:00
|
|
|
/// A method with a body.
|
2013-08-15 16:28:54 -04:00
|
|
|
MethodItem(Method),
|
|
|
|
StructFieldItem(StructField),
|
|
|
|
VariantItem(Variant),
|
2014-03-16 19:12:00 -04:00
|
|
|
/// `fn`s from an extern block
|
2013-09-26 11:57:25 -07:00
|
|
|
ForeignFunctionItem(Function),
|
2014-03-16 19:12:00 -04:00
|
|
|
/// `static`s from an extern block
|
2013-09-26 11:57:25 -07:00
|
|
|
ForeignStaticItem(Static),
|
2014-02-16 21:40:26 -08:00
|
|
|
MacroItem(Macro),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Module {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub items: Vec<Item>,
|
|
|
|
pub is_crate: bool,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Module {
|
|
|
|
fn clean(&self) -> Item {
|
|
|
|
let name = if self.name.is_some() {
|
|
|
|
self.name.unwrap().clean()
|
|
|
|
} else {
|
2014-05-12 13:44:59 -07:00
|
|
|
"".to_strbuf()
|
2013-08-15 16:28:54 -04:00
|
|
|
};
|
2014-03-05 15:28:08 -08:00
|
|
|
let mut foreigns = Vec::new();
|
2014-02-28 17:46:09 -08:00
|
|
|
for subforeigns in self.foreigns.clean().move_iter() {
|
|
|
|
for foreign in subforeigns.move_iter() {
|
|
|
|
foreigns.push(foreign)
|
|
|
|
}
|
|
|
|
}
|
2014-03-05 15:28:08 -08:00
|
|
|
let items: Vec<Vec<Item> > = vec!(
|
2014-02-28 17:46:09 -08:00
|
|
|
self.structs.clean().move_iter().collect(),
|
|
|
|
self.enums.clean().move_iter().collect(),
|
|
|
|
self.fns.clean().move_iter().collect(),
|
|
|
|
foreigns,
|
|
|
|
self.mods.clean().move_iter().collect(),
|
|
|
|
self.typedefs.clean().move_iter().collect(),
|
|
|
|
self.statics.clean().move_iter().collect(),
|
|
|
|
self.traits.clean().move_iter().collect(),
|
|
|
|
self.impls.clean().move_iter().collect(),
|
|
|
|
self.view_items.clean().move_iter().collect(),
|
|
|
|
self.macros.clean().move_iter().collect()
|
2014-03-05 15:28:08 -08:00
|
|
|
);
|
2014-04-27 05:08:36 +09:00
|
|
|
|
|
|
|
// determine if we should display the inner contents or
|
|
|
|
// the outer `mod` item for the source code.
|
|
|
|
let where = {
|
2014-04-28 20:36:08 -07:00
|
|
|
let ctxt = super::ctxtkey.get().unwrap();
|
2014-04-27 05:08:36 +09:00
|
|
|
let cm = ctxt.sess().codemap();
|
|
|
|
let outer = cm.lookup_char_pos(self.where_outer.lo);
|
|
|
|
let inner = cm.lookup_char_pos(self.where_inner.lo);
|
|
|
|
if outer.file.start_pos == inner.file.start_pos {
|
|
|
|
// mod foo { ... }
|
|
|
|
self.where_outer
|
|
|
|
} else {
|
|
|
|
// mod foo; (and a separate FileMap for the contents)
|
|
|
|
self.where_inner
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
|
|
|
name: Some(name),
|
|
|
|
attrs: self.attrs.clean(),
|
2014-04-27 05:08:36 +09:00
|
|
|
source: where.clean(),
|
2013-08-15 16:28:54 -04:00
|
|
|
visibility: self.vis.clean(),
|
|
|
|
id: self.id,
|
|
|
|
inner: ModuleItem(Module {
|
2014-02-28 22:33:45 +01:00
|
|
|
is_crate: self.is_crate,
|
2014-03-05 15:28:08 -08:00
|
|
|
items: items.iter()
|
|
|
|
.flat_map(|x| x.iter().map(|x| (*x).clone()))
|
|
|
|
.collect(),
|
2013-08-15 16:28:54 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum Attribute {
|
2014-05-12 13:44:59 -07:00
|
|
|
Word(StrBuf),
|
|
|
|
List(StrBuf, Vec<Attribute> ),
|
|
|
|
NameValue(StrBuf, StrBuf)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Attribute> for ast::MetaItem {
|
|
|
|
fn clean(&self) -> Attribute {
|
|
|
|
match self.node {
|
2014-05-12 13:44:59 -07:00
|
|
|
ast::MetaWord(ref s) => Word(s.get().to_strbuf()),
|
2014-01-08 10:35:15 -08:00
|
|
|
ast::MetaList(ref s, ref l) => {
|
2014-05-12 13:44:59 -07:00
|
|
|
List(s.get().to_strbuf(), l.clean().move_iter().collect())
|
2014-01-08 10:35:15 -08:00
|
|
|
}
|
|
|
|
ast::MetaNameValue(ref s, ref v) => {
|
2014-05-12 13:44:59 -07:00
|
|
|
NameValue(s.get().to_strbuf(), lit_to_str(v))
|
2014-01-08 10:35:15 -08:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Attribute> for ast::Attribute {
|
|
|
|
fn clean(&self) -> Attribute {
|
2013-09-18 22:18:38 -07:00
|
|
|
self.desugar_doc().node.value.clean()
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:53:06 -07:00
|
|
|
// This is a rough approximation that gets us what we want.
|
2013-12-09 23:16:18 -08:00
|
|
|
impl<'a> attr::AttrMetaMethods for &'a Attribute {
|
2014-01-08 10:35:15 -08:00
|
|
|
fn name(&self) -> InternedString {
|
2013-09-26 12:53:06 -07:00
|
|
|
match **self {
|
2014-01-08 10:35:15 -08:00
|
|
|
Word(ref n) | List(ref n, _) | NameValue(ref n, _) => {
|
2014-05-12 13:44:59 -07:00
|
|
|
token::intern_and_get_ident(n.as_slice())
|
2014-01-08 10:35:15 -08:00
|
|
|
}
|
2013-09-26 12:53:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 14:02:36 -08:00
|
|
|
fn value_str(&self) -> Option<InternedString> {
|
2013-09-26 12:53:06 -07:00
|
|
|
match **self {
|
2014-05-12 13:44:59 -07:00
|
|
|
NameValue(_, ref v) => {
|
|
|
|
Some(token::intern_and_get_ident(v.as_slice()))
|
|
|
|
}
|
2013-09-26 12:53:06 -07:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
|
2014-01-10 14:02:36 -08:00
|
|
|
fn name_str_pair(&self) -> Option<(InternedString, InternedString)> {
|
|
|
|
None
|
|
|
|
}
|
2013-09-26 12:53:06 -07:00
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct TyParam {
|
2014-05-12 13:44:59 -07:00
|
|
|
pub name: StrBuf,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub id: ast::NodeId,
|
|
|
|
pub bounds: Vec<TyParamBound>,
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
|
|
|
impl Clean<TyParam> for ast::TyParam {
|
|
|
|
fn clean(&self) -> TyParam {
|
|
|
|
TyParam {
|
|
|
|
name: self.ident.clean(),
|
|
|
|
id: self.id,
|
2014-02-28 17:46:09 -08:00
|
|
|
bounds: self.bounds.clean().move_iter().collect(),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum TyParamBound {
|
|
|
|
RegionBound,
|
|
|
|
TraitBound(Type)
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<TyParamBound> for ast::TyParamBound {
|
|
|
|
fn clean(&self) -> TyParamBound {
|
|
|
|
match *self {
|
2014-05-02 14:04:26 -04:00
|
|
|
ast::StaticRegionTyParamBound => RegionBound,
|
|
|
|
ast::OtherRegionTyParamBound(_) => RegionBound,
|
2013-08-15 16:28:54 -04:00
|
|
|
ast::TraitTyParamBound(ref t) => TraitBound(t.clean()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
2014-05-12 13:44:59 -07:00
|
|
|
pub struct Lifetime(StrBuf);
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2013-11-01 18:06:31 -07:00
|
|
|
impl Lifetime {
|
|
|
|
pub fn get_ref<'a>(&'a self) -> &'a str {
|
|
|
|
let Lifetime(ref s) = *self;
|
2014-05-12 13:44:59 -07:00
|
|
|
let s: &'a str = s.as_slice();
|
2013-11-01 18:06:31 -07:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
impl Clean<Lifetime> for ast::Lifetime {
|
|
|
|
fn clean(&self) -> Lifetime {
|
2014-05-12 13:44:59 -07:00
|
|
|
Lifetime(token::get_name(self.name).get().to_strbuf())
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// maybe use a Generic enum and use ~[Generic]?
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Generics {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub lifetimes: Vec<Lifetime>,
|
|
|
|
pub type_params: Vec<TyParam>,
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
|
|
|
impl Clean<Generics> for ast::Generics {
|
|
|
|
fn clean(&self) -> Generics {
|
|
|
|
Generics {
|
2014-02-28 17:46:09 -08:00
|
|
|
lifetimes: self.lifetimes.clean().move_iter().collect(),
|
|
|
|
type_params: self.ty_params.clean().move_iter().collect(),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Method {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub generics: Generics,
|
|
|
|
pub self_: SelfTy,
|
2014-04-06 18:04:40 -07:00
|
|
|
pub fn_style: ast::FnStyle,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub decl: FnDecl,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Item> for ast::Method {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> Item {
|
2014-01-27 14:18:36 +02:00
|
|
|
let inputs = match self.explicit_self.node {
|
|
|
|
ast::SelfStatic => self.decl.inputs.as_slice(),
|
|
|
|
_ => self.decl.inputs.slice_from(1)
|
|
|
|
};
|
|
|
|
let decl = FnDecl {
|
2014-02-13 06:41:34 +11:00
|
|
|
inputs: Arguments {
|
|
|
|
values: inputs.iter().map(|x| x.clean()).collect(),
|
|
|
|
},
|
2014-01-27 14:18:36 +02:00
|
|
|
output: (self.decl.output.clean()),
|
|
|
|
cf: self.decl.cf.clean(),
|
2014-03-05 15:28:08 -08:00
|
|
|
attrs: Vec::new()
|
2014-01-27 14:18:36 +02:00
|
|
|
};
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
|
|
|
name: Some(self.ident.clean()),
|
2014-02-28 17:46:09 -08:00
|
|
|
attrs: self.attrs.clean().move_iter().collect(),
|
2013-08-15 16:28:54 -04:00
|
|
|
source: self.span.clean(),
|
2013-10-18 18:16:38 -07:00
|
|
|
id: self.id.clone(),
|
2013-09-24 13:55:22 -07:00
|
|
|
visibility: self.vis.clean(),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: MethodItem(Method {
|
|
|
|
generics: self.generics.clean(),
|
|
|
|
self_: self.explicit_self.clean(),
|
2014-04-06 18:04:40 -07:00
|
|
|
fn_style: self.fn_style.clone(),
|
2014-01-27 14:18:36 +02:00
|
|
|
decl: decl,
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct TyMethod {
|
2014-04-06 18:04:40 -07:00
|
|
|
pub fn_style: ast::FnStyle,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub decl: FnDecl,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub self_: SelfTy,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for ast::TypeMethod {
|
|
|
|
fn clean(&self) -> Item {
|
2014-01-27 14:18:36 +02:00
|
|
|
let inputs = match self.explicit_self.node {
|
|
|
|
ast::SelfStatic => self.decl.inputs.as_slice(),
|
|
|
|
_ => self.decl.inputs.slice_from(1)
|
|
|
|
};
|
|
|
|
let decl = FnDecl {
|
2014-02-13 06:41:34 +11:00
|
|
|
inputs: Arguments {
|
|
|
|
values: inputs.iter().map(|x| x.clean()).collect(),
|
|
|
|
},
|
2014-01-27 14:18:36 +02:00
|
|
|
output: (self.decl.output.clean()),
|
|
|
|
cf: self.decl.cf.clean(),
|
2014-03-05 15:28:08 -08:00
|
|
|
attrs: Vec::new()
|
2014-01-27 14:18:36 +02:00
|
|
|
};
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
|
|
|
name: Some(self.ident.clean()),
|
2014-02-28 17:46:09 -08:00
|
|
|
attrs: self.attrs.clean().move_iter().collect(),
|
2013-08-15 16:28:54 -04:00
|
|
|
source: self.span.clean(),
|
|
|
|
id: self.id,
|
|
|
|
visibility: None,
|
|
|
|
inner: TyMethodItem(TyMethod {
|
2014-04-06 18:04:40 -07:00
|
|
|
fn_style: self.fn_style.clone(),
|
2014-01-27 14:18:36 +02:00
|
|
|
decl: decl,
|
2013-08-15 16:28:54 -04:00
|
|
|
self_: self.explicit_self.clean(),
|
|
|
|
generics: self.generics.clean(),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum SelfTy {
|
|
|
|
SelfStatic,
|
|
|
|
SelfValue,
|
|
|
|
SelfBorrowed(Option<Lifetime>, Mutability),
|
|
|
|
SelfOwned,
|
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<SelfTy> for ast::ExplicitSelf {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> SelfTy {
|
|
|
|
match self.node {
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::SelfStatic => SelfStatic,
|
2014-01-27 14:18:36 +02:00
|
|
|
ast::SelfValue => SelfValue,
|
|
|
|
ast::SelfUniq => SelfOwned,
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::SelfRegion(lt, mt) => SelfBorrowed(lt.clean(), mt.clean()),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Function {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub decl: FnDecl,
|
|
|
|
pub generics: Generics,
|
2014-04-06 18:04:40 -07:00
|
|
|
pub fn_style: ast::FnStyle,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Function {
|
|
|
|
fn clean(&self) -> Item {
|
|
|
|
Item {
|
|
|
|
name: Some(self.name.clean()),
|
|
|
|
attrs: self.attrs.clean(),
|
|
|
|
source: self.where.clean(),
|
|
|
|
visibility: self.vis.clean(),
|
|
|
|
id: self.id,
|
|
|
|
inner: FunctionItem(Function {
|
|
|
|
decl: self.decl.clean(),
|
|
|
|
generics: self.generics.clean(),
|
2014-04-06 18:04:40 -07:00
|
|
|
fn_style: self.fn_style,
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct ClosureDecl {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub lifetimes: Vec<Lifetime>,
|
|
|
|
pub decl: FnDecl,
|
|
|
|
pub onceness: ast::Onceness,
|
2014-04-06 18:04:40 -07:00
|
|
|
pub fn_style: ast::FnStyle,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub bounds: Vec<TyParamBound>,
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<ClosureDecl> for ast::ClosureTy {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> ClosureDecl {
|
|
|
|
ClosureDecl {
|
2014-02-28 17:46:09 -08:00
|
|
|
lifetimes: self.lifetimes.clean().move_iter().collect(),
|
2013-08-15 16:28:54 -04:00
|
|
|
decl: self.decl.clean(),
|
|
|
|
onceness: self.onceness,
|
2014-04-06 18:04:40 -07:00
|
|
|
fn_style: self.fn_style,
|
2013-08-15 16:28:54 -04:00
|
|
|
bounds: match self.bounds {
|
2014-02-28 17:46:09 -08:00
|
|
|
Some(ref x) => x.clean().move_iter().collect(),
|
2014-03-05 15:28:08 -08:00
|
|
|
None => Vec::new()
|
2013-08-15 16:28:54 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct FnDecl {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub inputs: Arguments,
|
|
|
|
pub output: Type,
|
|
|
|
pub cf: RetStyle,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-02-13 06:41:34 +11:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Arguments {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub values: Vec<Argument>,
|
2014-02-13 06:41:34 +11:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<FnDecl> for ast::FnDecl {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> FnDecl {
|
|
|
|
FnDecl {
|
2014-02-13 06:41:34 +11:00
|
|
|
inputs: Arguments {
|
|
|
|
values: self.inputs.iter().map(|x| x.clean()).collect(),
|
|
|
|
},
|
2013-08-15 16:28:54 -04:00
|
|
|
output: (self.output.clean()),
|
|
|
|
cf: self.cf.clean(),
|
2014-03-05 15:28:08 -08:00
|
|
|
attrs: Vec::new()
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Argument {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub type_: Type,
|
2014-05-12 13:44:59 -07:00
|
|
|
pub name: StrBuf,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub id: ast::NodeId,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Argument> for ast::Arg {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> Argument {
|
|
|
|
Argument {
|
|
|
|
name: name_from_pat(self.pat),
|
|
|
|
type_: (self.ty.clean()),
|
|
|
|
id: self.id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum RetStyle {
|
|
|
|
NoReturn,
|
|
|
|
Return
|
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<RetStyle> for ast::RetStyle {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> RetStyle {
|
|
|
|
match *self {
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::Return => Return,
|
|
|
|
ast::NoReturn => NoReturn
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Trait {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub methods: Vec<TraitMethod>,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub parents: Vec<Type>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Trait {
|
|
|
|
fn clean(&self) -> Item {
|
|
|
|
Item {
|
|
|
|
name: Some(self.name.clean()),
|
|
|
|
attrs: self.attrs.clean(),
|
|
|
|
source: self.where.clean(),
|
|
|
|
id: self.id,
|
|
|
|
visibility: self.vis.clean(),
|
|
|
|
inner: TraitItem(Trait {
|
|
|
|
methods: self.methods.clean(),
|
|
|
|
generics: self.generics.clean(),
|
|
|
|
parents: self.parents.clean(),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Type> for ast::TraitRef {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> Type {
|
2013-09-24 13:53:09 -07:00
|
|
|
resolve_type(self.path.clean(), None, self.ref_id)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum TraitMethod {
|
|
|
|
Required(Item),
|
|
|
|
Provided(Item),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TraitMethod {
|
2013-09-18 22:18:38 -07:00
|
|
|
pub fn is_req(&self) -> bool {
|
2013-08-15 16:28:54 -04:00
|
|
|
match self {
|
2013-11-28 12:22:53 -08:00
|
|
|
&Required(..) => true,
|
2013-08-15 16:28:54 -04:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
pub fn is_def(&self) -> bool {
|
2013-08-15 16:28:54 -04:00
|
|
|
match self {
|
2013-11-28 12:22:53 -08:00
|
|
|
&Provided(..) => true,
|
2013-08-15 16:28:54 -04:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
pub fn item<'a>(&'a self) -> &'a Item {
|
|
|
|
match *self {
|
|
|
|
Required(ref item) => item,
|
|
|
|
Provided(ref item) => item,
|
|
|
|
}
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<TraitMethod> for ast::TraitMethod {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> TraitMethod {
|
|
|
|
match self {
|
2014-01-09 15:05:33 +02:00
|
|
|
&ast::Required(ref t) => Required(t.clean()),
|
|
|
|
&ast::Provided(ref t) => Provided(t.clean()),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A representation of a Type suitable for hyperlinking purposes. Ideally one can get the original
|
|
|
|
/// type out of the AST/ty::ctxt given one of these, if more information is needed. Most importantly
|
|
|
|
/// it does not preserve mutability or boxes.
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum Type {
|
2014-01-09 15:05:33 +02:00
|
|
|
/// structs/enums/traits (anything that'd be an ast::TyPath)
|
2013-09-27 18:23:57 -07:00
|
|
|
ResolvedPath {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub path: Path,
|
|
|
|
pub typarams: Option<Vec<TyParamBound>>,
|
2014-05-09 13:52:17 -07:00
|
|
|
pub did: ast::DefId,
|
2013-09-27 18:23:57 -07:00
|
|
|
},
|
2013-08-15 16:28:54 -04:00
|
|
|
// I have no idea how to usefully use this.
|
|
|
|
TyParamBinder(ast::NodeId),
|
|
|
|
/// For parameterized types, so the consumer of the JSON don't go looking
|
|
|
|
/// for types which don't exist anywhere.
|
|
|
|
Generic(ast::NodeId),
|
|
|
|
/// For references to self
|
|
|
|
Self(ast::NodeId),
|
|
|
|
/// Primitives are just the fixed-size numeric types (plus int/uint/float), and char.
|
2014-01-09 15:05:33 +02:00
|
|
|
Primitive(ast::PrimTy),
|
2014-05-05 18:56:44 -07:00
|
|
|
Closure(Box<ClosureDecl>, Option<Lifetime>),
|
|
|
|
Proc(Box<ClosureDecl>),
|
2013-08-15 16:28:54 -04:00
|
|
|
/// extern "ABI" fn
|
2014-05-05 18:56:44 -07:00
|
|
|
BareFunction(Box<BareFunctionDecl>),
|
2014-04-19 22:24:52 -07:00
|
|
|
Tuple(Vec<Type>),
|
2014-05-05 18:56:44 -07:00
|
|
|
Vector(Box<Type>),
|
2014-05-12 13:44:59 -07:00
|
|
|
FixedVector(Box<Type>, StrBuf),
|
2013-08-15 16:28:54 -04:00
|
|
|
String,
|
|
|
|
Bool,
|
2014-01-09 22:25:09 +02:00
|
|
|
/// aka TyNil
|
2013-08-15 16:28:54 -04:00
|
|
|
Unit,
|
2014-01-09 22:25:09 +02:00
|
|
|
/// aka TyBot
|
2013-08-15 16:28:54 -04:00
|
|
|
Bottom,
|
2014-05-05 18:56:44 -07:00
|
|
|
Unique(Box<Type>),
|
|
|
|
Managed(Box<Type>),
|
|
|
|
RawPointer(Mutability, Box<Type>),
|
2014-03-28 10:27:24 -07:00
|
|
|
BorrowedRef {
|
|
|
|
pub lifetime: Option<Lifetime>,
|
|
|
|
pub mutability: Mutability,
|
2014-05-05 18:56:44 -07:00
|
|
|
pub type_: Box<Type>,
|
2014-03-28 10:27:24 -07:00
|
|
|
},
|
2013-08-15 16:28:54 -04:00
|
|
|
// region, raw, other boxes, mutable
|
|
|
|
}
|
|
|
|
|
2013-10-02 15:39:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum TypeKind {
|
|
|
|
TypeEnum,
|
|
|
|
TypeFunction,
|
2014-05-09 13:52:17 -07:00
|
|
|
TypeModule,
|
|
|
|
TypeStatic,
|
|
|
|
TypeStruct,
|
|
|
|
TypeTrait,
|
|
|
|
TypeVariant,
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
impl Clean<Type> for ast::Ty {
|
|
|
|
fn clean(&self) -> Type {
|
|
|
|
use syntax::ast::*;
|
2013-09-24 13:53:09 -07:00
|
|
|
match self.node {
|
2014-01-09 22:25:09 +02:00
|
|
|
TyNil => Unit,
|
2014-04-25 01:08:02 -07:00
|
|
|
TyPtr(ref m) => RawPointer(m.mutbl.clean(), box m.ty.clean()),
|
2014-01-09 22:25:09 +02:00
|
|
|
TyRptr(ref l, ref m) =>
|
2013-08-15 16:28:54 -04:00
|
|
|
BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(),
|
2014-04-25 01:08:02 -07:00
|
|
|
type_: box m.ty.clean()},
|
|
|
|
TyBox(ty) => Managed(box ty.clean()),
|
|
|
|
TyUniq(ty) => Unique(box ty.clean()),
|
|
|
|
TyVec(ty) => Vector(box ty.clean()),
|
|
|
|
TyFixedLengthVec(ty, ref e) => FixedVector(box ty.clean(),
|
2014-01-09 22:25:09 +02:00
|
|
|
e.span.to_src()),
|
|
|
|
TyTup(ref tys) => Tuple(tys.iter().map(|x| x.clean()).collect()),
|
2014-02-28 17:46:09 -08:00
|
|
|
TyPath(ref p, ref tpbs, id) => {
|
|
|
|
resolve_type(p.clean(),
|
|
|
|
tpbs.clean().map(|x| x.move_iter().collect()),
|
|
|
|
id)
|
|
|
|
}
|
2014-04-25 01:08:02 -07:00
|
|
|
TyClosure(ref c, region) => Closure(box c.clean(), region.clean()),
|
|
|
|
TyProc(ref c) => Proc(box c.clean()),
|
|
|
|
TyBareFn(ref barefn) => BareFunction(box barefn.clean()),
|
2014-01-09 22:25:09 +02:00
|
|
|
TyBot => Bottom,
|
2013-10-21 13:08:31 -07:00
|
|
|
ref x => fail!("Unimplemented type {:?}", x),
|
2013-09-24 13:53:09 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
2014-04-19 22:24:52 -07:00
|
|
|
pub enum StructField {
|
2014-04-29 03:59:48 +09:00
|
|
|
HiddenStructField, // inserted later by strip passes
|
2014-04-19 22:24:52 -07:00
|
|
|
TypedStructField(Type),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Item> for ast::StructField {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> Item {
|
|
|
|
let (name, vis) = match self.node.kind {
|
2014-04-19 22:24:52 -07:00
|
|
|
ast::NamedField(id, vis) => (Some(id), vis),
|
|
|
|
ast::UnnamedField(vis) => (None, vis)
|
2013-08-15 16:28:54 -04:00
|
|
|
};
|
|
|
|
Item {
|
|
|
|
name: name.clean(),
|
2014-02-28 17:46:09 -08:00
|
|
|
attrs: self.node.attrs.clean().move_iter().collect(),
|
2013-08-15 16:28:54 -04:00
|
|
|
source: self.span.clean(),
|
2014-04-19 22:24:52 -07:00
|
|
|
visibility: Some(vis),
|
2013-08-15 16:28:54 -04:00
|
|
|
id: self.node.id,
|
2014-04-19 22:24:52 -07:00
|
|
|
inner: StructFieldItem(TypedStructField(self.node.ty.clean())),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
pub type Visibility = ast::Visibility;
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Option<Visibility>> for ast::Visibility {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> Option<Visibility> {
|
|
|
|
Some(*self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Struct {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub struct_type: doctree::StructType,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub fields: Vec<Item>,
|
|
|
|
pub fields_stripped: bool,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Struct {
|
|
|
|
fn clean(&self) -> Item {
|
|
|
|
Item {
|
|
|
|
name: Some(self.name.clean()),
|
|
|
|
attrs: self.attrs.clean(),
|
|
|
|
source: self.where.clean(),
|
|
|
|
id: self.id,
|
|
|
|
visibility: self.vis.clean(),
|
|
|
|
inner: StructItem(Struct {
|
|
|
|
struct_type: self.struct_type,
|
|
|
|
generics: self.generics.clean(),
|
|
|
|
fields: self.fields.clean(),
|
2013-10-13 20:37:43 -07:00
|
|
|
fields_stripped: false,
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-06 16:35:12 +09:00
|
|
|
/// This is a more limited form of the standard Struct, different in that
|
2013-08-15 16:28:54 -04:00
|
|
|
/// it lacks the things most items have (name, id, parameterization). Found
|
|
|
|
/// only as a variant in an enum.
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct VariantStruct {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub struct_type: doctree::StructType,
|
|
|
|
pub fields: Vec<Item>,
|
|
|
|
pub fields_stripped: bool,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<VariantStruct> for syntax::ast::StructDef {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> VariantStruct {
|
|
|
|
VariantStruct {
|
|
|
|
struct_type: doctree::struct_type_from_def(self),
|
2014-02-28 17:46:09 -08:00
|
|
|
fields: self.fields.clean().move_iter().collect(),
|
2013-10-13 20:37:43 -07:00
|
|
|
fields_stripped: false,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Enum {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub variants: Vec<Item>,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub variants_stripped: bool,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Enum {
|
|
|
|
fn clean(&self) -> Item {
|
|
|
|
Item {
|
|
|
|
name: Some(self.name.clean()),
|
|
|
|
attrs: self.attrs.clean(),
|
|
|
|
source: self.where.clean(),
|
|
|
|
id: self.id,
|
|
|
|
visibility: self.vis.clean(),
|
|
|
|
inner: EnumItem(Enum {
|
|
|
|
variants: self.variants.clean(),
|
|
|
|
generics: self.generics.clean(),
|
2013-10-13 20:37:43 -07:00
|
|
|
variants_stripped: false,
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Variant {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub kind: VariantKind,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Variant {
|
|
|
|
fn clean(&self) -> Item {
|
|
|
|
Item {
|
|
|
|
name: Some(self.name.clean()),
|
|
|
|
attrs: self.attrs.clean(),
|
|
|
|
source: self.where.clean(),
|
|
|
|
visibility: self.vis.clean(),
|
|
|
|
id: self.id,
|
|
|
|
inner: VariantItem(Variant {
|
|
|
|
kind: self.kind.clean(),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum VariantKind {
|
|
|
|
CLikeVariant,
|
2014-04-19 22:24:52 -07:00
|
|
|
TupleVariant(Vec<Type>),
|
2013-08-15 16:28:54 -04:00
|
|
|
StructVariant(VariantStruct),
|
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<VariantKind> for ast::VariantKind {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> VariantKind {
|
|
|
|
match self {
|
2014-01-09 15:05:33 +02:00
|
|
|
&ast::TupleVariantKind(ref args) => {
|
2013-08-15 16:28:54 -04:00
|
|
|
if args.len() == 0 {
|
|
|
|
CLikeVariant
|
|
|
|
} else {
|
|
|
|
TupleVariant(args.iter().map(|x| x.ty.clean()).collect())
|
|
|
|
}
|
|
|
|
},
|
2014-01-09 15:05:33 +02:00
|
|
|
&ast::StructVariantKind(ref sd) => StructVariant(sd.clean()),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 15:12:23 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Span {
|
2014-05-12 13:44:59 -07:00
|
|
|
pub filename: StrBuf,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub loline: uint,
|
|
|
|
pub locol: uint,
|
|
|
|
pub hiline: uint,
|
|
|
|
pub hicol: uint,
|
2013-09-27 15:12:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Span> for syntax::codemap::Span {
|
|
|
|
fn clean(&self) -> Span {
|
2014-04-28 20:36:08 -07:00
|
|
|
let ctxt = super::ctxtkey.get().unwrap();
|
2014-04-23 23:29:38 -04:00
|
|
|
let cm = ctxt.sess().codemap();
|
2013-09-27 15:12:23 -07:00
|
|
|
let filename = cm.span_to_filename(*self);
|
|
|
|
let lo = cm.lookup_char_pos(self.lo);
|
|
|
|
let hi = cm.lookup_char_pos(self.hi);
|
|
|
|
Span {
|
2014-05-12 13:44:59 -07:00
|
|
|
filename: filename.to_strbuf(),
|
2013-09-27 15:12:23 -07:00
|
|
|
loline: lo.line,
|
2013-11-01 18:06:31 -07:00
|
|
|
locol: lo.col.to_uint(),
|
2013-09-27 15:12:23 -07:00
|
|
|
hiline: hi.line,
|
2013-11-01 18:06:31 -07:00
|
|
|
hicol: hi.col.to_uint(),
|
2013-09-27 15:12:23 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Path {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub global: bool,
|
|
|
|
pub segments: Vec<PathSegment>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Path> for ast::Path {
|
|
|
|
fn clean(&self) -> Path {
|
|
|
|
Path {
|
2013-09-12 15:11:06 -04:00
|
|
|
global: self.global,
|
2014-02-28 17:46:09 -08:00
|
|
|
segments: self.segments.clean().move_iter().collect(),
|
2013-09-12 15:11:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct PathSegment {
|
2014-05-12 13:44:59 -07:00
|
|
|
pub name: StrBuf,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub lifetimes: Vec<Lifetime>,
|
|
|
|
pub types: Vec<Type>,
|
2013-09-12 15:11:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<PathSegment> for ast::PathSegment {
|
|
|
|
fn clean(&self) -> PathSegment {
|
|
|
|
PathSegment {
|
|
|
|
name: self.identifier.clean(),
|
2014-02-28 17:46:09 -08:00
|
|
|
lifetimes: self.lifetimes.clean().move_iter().collect(),
|
|
|
|
types: self.types.clean().move_iter().collect()
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-12 13:44:59 -07:00
|
|
|
fn path_to_str(p: &ast::Path) -> StrBuf {
|
2014-01-31 18:25:08 -08:00
|
|
|
use syntax::parse::token;
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-04-02 16:54:22 -07:00
|
|
|
let mut s = StrBuf::new();
|
2013-08-15 16:28:54 -04:00
|
|
|
let mut first = true;
|
2014-02-14 07:07:09 +02:00
|
|
|
for i in p.segments.iter().map(|x| token::get_ident(x.identifier)) {
|
2013-08-15 16:28:54 -04:00
|
|
|
if !first || p.global {
|
|
|
|
s.push_str("::");
|
|
|
|
} else {
|
|
|
|
first = false;
|
|
|
|
}
|
2014-02-02 02:53:26 +11:00
|
|
|
s.push_str(i.get());
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
2014-05-12 13:44:59 -07:00
|
|
|
s
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-05-12 13:44:59 -07:00
|
|
|
impl Clean<StrBuf> for ast::Ident {
|
|
|
|
fn clean(&self) -> StrBuf {
|
|
|
|
token::get_ident(*self).get().to_strbuf()
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Typedef {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub type_: Type,
|
|
|
|
pub generics: Generics,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Typedef {
|
|
|
|
fn clean(&self) -> Item {
|
|
|
|
Item {
|
|
|
|
name: Some(self.name.clean()),
|
|
|
|
attrs: self.attrs.clean(),
|
|
|
|
source: self.where.clean(),
|
|
|
|
id: self.id.clone(),
|
|
|
|
visibility: self.vis.clean(),
|
|
|
|
inner: TypedefItem(Typedef {
|
|
|
|
type_: self.ty.clean(),
|
|
|
|
generics: self.gen.clean(),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct BareFunctionDecl {
|
2014-04-06 18:04:40 -07:00
|
|
|
pub fn_style: ast::FnStyle,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub generics: Generics,
|
|
|
|
pub decl: FnDecl,
|
2014-05-12 13:44:59 -07:00
|
|
|
pub abi: StrBuf,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<BareFunctionDecl> for ast::BareFnTy {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> BareFunctionDecl {
|
|
|
|
BareFunctionDecl {
|
2014-04-06 18:04:40 -07:00
|
|
|
fn_style: self.fn_style,
|
2013-08-15 16:28:54 -04:00
|
|
|
generics: Generics {
|
2014-02-28 17:46:09 -08:00
|
|
|
lifetimes: self.lifetimes.clean().move_iter().collect(),
|
2014-03-05 15:28:08 -08:00
|
|
|
type_params: Vec::new(),
|
2013-08-15 16:28:54 -04:00
|
|
|
},
|
|
|
|
decl: self.decl.clean(),
|
2014-05-12 13:44:59 -07:00
|
|
|
abi: self.abi.to_str().to_strbuf(),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Static {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub type_: Type,
|
|
|
|
pub mutability: Mutability,
|
2013-08-15 16:28:54 -04:00
|
|
|
/// It's useful to have the value of a static documented, but I have no
|
|
|
|
/// desire to represent expressions (that'd basically be all of the AST,
|
|
|
|
/// which is huge!). So, have a string.
|
2014-05-12 13:44:59 -07:00
|
|
|
pub expr: StrBuf,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Static {
|
|
|
|
fn clean(&self) -> Item {
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("claning static {}: {:?}", self.name.clean(), self);
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
|
|
|
name: Some(self.name.clean()),
|
|
|
|
attrs: self.attrs.clean(),
|
|
|
|
source: self.where.clean(),
|
|
|
|
id: self.id,
|
|
|
|
visibility: self.vis.clean(),
|
|
|
|
inner: StaticItem(Static {
|
|
|
|
type_: self.type_.clean(),
|
|
|
|
mutability: self.mutability.clean(),
|
|
|
|
expr: self.expr.span.to_src(),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 18:56:33 -08:00
|
|
|
#[deriving(Show, Clone, Encodable, Decodable)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub enum Mutability {
|
|
|
|
Mutable,
|
|
|
|
Immutable,
|
|
|
|
}
|
|
|
|
|
2013-09-05 10:14:35 -04:00
|
|
|
impl Clean<Mutability> for ast::Mutability {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> Mutability {
|
|
|
|
match self {
|
2013-09-05 10:14:35 -04:00
|
|
|
&ast::MutMutable => Mutable,
|
|
|
|
&ast::MutImmutable => Immutable,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Impl {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub generics: Generics,
|
|
|
|
pub trait_: Option<Type>,
|
|
|
|
pub for_: Type,
|
|
|
|
pub methods: Vec<Item>,
|
|
|
|
pub derived: bool,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Impl {
|
|
|
|
fn clean(&self) -> Item {
|
2014-03-16 20:00:56 -04:00
|
|
|
let mut derived = false;
|
|
|
|
for attr in self.attrs.iter() {
|
|
|
|
match attr.node.value.node {
|
|
|
|
ast::MetaWord(ref s) => {
|
|
|
|
if s.get() == "automatically_derived" {
|
|
|
|
derived = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
|
|
|
name: None,
|
|
|
|
attrs: self.attrs.clean(),
|
|
|
|
source: self.where.clean(),
|
|
|
|
id: self.id,
|
|
|
|
visibility: self.vis.clean(),
|
|
|
|
inner: ImplItem(Impl {
|
|
|
|
generics: self.generics.clean(),
|
|
|
|
trait_: self.trait_.clean(),
|
|
|
|
for_: self.for_.clean(),
|
|
|
|
methods: self.methods.clean(),
|
2014-03-16 20:00:56 -04:00
|
|
|
derived: derived,
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct ViewItem {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub inner: ViewItemInner,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Item> for ast::ViewItem {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> Item {
|
|
|
|
Item {
|
|
|
|
name: None,
|
2014-02-28 17:46:09 -08:00
|
|
|
attrs: self.attrs.clean().move_iter().collect(),
|
2013-08-15 16:28:54 -04:00
|
|
|
source: self.span.clean(),
|
|
|
|
id: 0,
|
|
|
|
visibility: self.vis.clean(),
|
|
|
|
inner: ViewItemItem(ViewItem {
|
|
|
|
inner: self.node.clean()
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum ViewItemInner {
|
2014-05-12 13:44:59 -07:00
|
|
|
ExternCrate(StrBuf, Option<StrBuf>, ast::NodeId),
|
2014-04-26 22:33:45 +09:00
|
|
|
Import(ViewPath)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<ViewItemInner> for ast::ViewItem_ {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> ViewItemInner {
|
|
|
|
match self {
|
2014-03-07 15:57:45 +08:00
|
|
|
&ast::ViewItemExternCrate(ref i, ref p, ref id) => {
|
2014-01-21 10:08:10 -08:00
|
|
|
let string = match *p {
|
|
|
|
None => None,
|
2014-05-12 13:44:59 -07:00
|
|
|
Some((ref x, _)) => Some(x.get().to_strbuf()),
|
2014-01-21 10:08:10 -08:00
|
|
|
};
|
2014-03-07 15:57:45 +08:00
|
|
|
ExternCrate(i.clean(), string, *id)
|
2014-01-21 10:08:10 -08:00
|
|
|
}
|
2014-02-28 17:46:09 -08:00
|
|
|
&ast::ViewItemUse(ref vp) => {
|
2014-04-26 22:33:45 +09:00
|
|
|
Import(vp.clean())
|
2014-02-28 17:46:09 -08:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum ViewPath {
|
2013-09-24 13:56:52 -07:00
|
|
|
// use str = source;
|
2014-05-12 13:44:59 -07:00
|
|
|
SimpleImport(StrBuf, ImportSource),
|
2013-09-24 13:56:52 -07:00
|
|
|
// use source::*;
|
|
|
|
GlobImport(ImportSource),
|
|
|
|
// use source::{a, b, c};
|
2014-05-09 13:52:17 -07:00
|
|
|
ImportList(ImportSource, Vec<ViewListIdent>),
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct ImportSource {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub path: Path,
|
|
|
|
pub did: Option<ast::DefId>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<ViewPath> for ast::ViewPath {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> ViewPath {
|
|
|
|
match self.node {
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::ViewPathSimple(ref i, ref p, id) =>
|
2013-09-24 13:56:52 -07:00
|
|
|
SimpleImport(i.clean(), resolve_use_source(p.clean(), id)),
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::ViewPathGlob(ref p, id) =>
|
2013-09-24 13:56:52 -07:00
|
|
|
GlobImport(resolve_use_source(p.clean(), id)),
|
2014-02-28 17:46:09 -08:00
|
|
|
ast::ViewPathList(ref p, ref pl, id) => {
|
|
|
|
ImportList(resolve_use_source(p.clean(), id),
|
|
|
|
pl.clean().move_iter().collect())
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-24 13:56:52 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct ViewListIdent {
|
2014-05-12 13:44:59 -07:00
|
|
|
pub name: StrBuf,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub source: Option<ast::DefId>,
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<ViewListIdent> for ast::PathListIdent {
|
2013-08-15 16:28:54 -04:00
|
|
|
fn clean(&self) -> ViewListIdent {
|
2013-09-24 13:56:52 -07:00
|
|
|
ViewListIdent {
|
|
|
|
name: self.node.name.clean(),
|
|
|
|
source: resolve_def(self.node.id),
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 17:46:09 -08:00
|
|
|
impl Clean<Vec<Item>> for ast::ForeignMod {
|
|
|
|
fn clean(&self) -> Vec<Item> {
|
2013-09-26 11:57:25 -07:00
|
|
|
self.items.clean()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Item> for ast::ForeignItem {
|
2013-09-26 11:57:25 -07:00
|
|
|
fn clean(&self) -> Item {
|
|
|
|
let inner = match self.node {
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::ForeignItemFn(ref decl, ref generics) => {
|
2013-09-26 11:57:25 -07:00
|
|
|
ForeignFunctionItem(Function {
|
|
|
|
decl: decl.clean(),
|
|
|
|
generics: generics.clean(),
|
2014-05-06 18:43:56 -07:00
|
|
|
fn_style: ast::NormalFn,
|
2013-09-26 11:57:25 -07:00
|
|
|
})
|
|
|
|
}
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::ForeignItemStatic(ref ty, mutbl) => {
|
2013-09-26 11:57:25 -07:00
|
|
|
ForeignStaticItem(Static {
|
|
|
|
type_: ty.clean(),
|
|
|
|
mutability: if mutbl {Mutable} else {Immutable},
|
2014-05-12 13:44:59 -07:00
|
|
|
expr: "".to_strbuf(),
|
2013-09-26 11:57:25 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Item {
|
|
|
|
name: Some(self.ident.clean()),
|
2014-02-28 17:46:09 -08:00
|
|
|
attrs: self.attrs.clean().move_iter().collect(),
|
2013-09-26 11:57:25 -07:00
|
|
|
source: self.span.clean(),
|
|
|
|
id: self.id,
|
|
|
|
visibility: self.vis.clean(),
|
|
|
|
inner: inner,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
// Utilities
|
|
|
|
|
|
|
|
trait ToSource {
|
2014-05-12 13:44:59 -07:00
|
|
|
fn to_src(&self) -> StrBuf;
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2013-09-05 10:14:35 -04:00
|
|
|
impl ToSource for syntax::codemap::Span {
|
2014-05-12 13:44:59 -07:00
|
|
|
fn to_src(&self) -> StrBuf {
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("converting span {:?} to snippet", self.clean());
|
2014-04-28 20:36:08 -07:00
|
|
|
let ctxt = super::ctxtkey.get().unwrap();
|
2014-04-23 23:29:38 -04:00
|
|
|
let cm = ctxt.sess().codemap().clone();
|
2013-08-15 16:28:54 -04:00
|
|
|
let sn = match cm.span_to_snippet(*self) {
|
2014-05-12 13:44:59 -07:00
|
|
|
Some(x) => x.to_strbuf(),
|
|
|
|
None => "".to_strbuf()
|
2013-08-15 16:28:54 -04:00
|
|
|
};
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("got snippet {}", sn);
|
2013-08-15 16:28:54 -04:00
|
|
|
sn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-12 13:44:59 -07:00
|
|
|
fn lit_to_str(lit: &ast::Lit) -> StrBuf {
|
2013-08-15 16:28:54 -04:00
|
|
|
match lit.node {
|
2014-05-12 13:44:59 -07:00
|
|
|
ast::LitStr(ref st, _) => st.get().to_strbuf(),
|
|
|
|
ast::LitBinary(ref data) => format_strbuf!("{:?}", data.as_slice()),
|
|
|
|
ast::LitChar(c) => format_strbuf!("'{}'", c),
|
|
|
|
ast::LitInt(i, _t) => i.to_str().to_strbuf(),
|
|
|
|
ast::LitUint(u, _t) => u.to_str().to_strbuf(),
|
|
|
|
ast::LitIntUnsuffixed(i) => i.to_str().to_strbuf(),
|
|
|
|
ast::LitFloat(ref f, _t) => f.get().to_strbuf(),
|
|
|
|
ast::LitFloatUnsuffixed(ref f) => f.get().to_strbuf(),
|
|
|
|
ast::LitBool(b) => b.to_str().to_strbuf(),
|
|
|
|
ast::LitNil => "".to_strbuf(),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-12 13:44:59 -07:00
|
|
|
fn name_from_pat(p: &ast::Pat) -> StrBuf {
|
2013-08-15 16:28:54 -04:00
|
|
|
use syntax::ast::*;
|
2013-12-29 00:13:29 -05:00
|
|
|
debug!("Trying to get a name from pattern: {:?}", p);
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
match p.node {
|
2014-05-12 13:44:59 -07:00
|
|
|
PatWild => "_".to_strbuf(),
|
|
|
|
PatWildMulti => "..".to_strbuf(),
|
2013-09-05 10:14:35 -04:00
|
|
|
PatIdent(_, ref p, _) => path_to_str(p),
|
|
|
|
PatEnum(ref p, _) => path_to_str(p),
|
2013-11-28 12:22:53 -08:00
|
|
|
PatStruct(..) => fail!("tried to get argument name from pat_struct, \
|
2013-09-05 10:14:35 -04:00
|
|
|
which is not allowed in function arguments"),
|
2014-05-12 13:44:59 -07:00
|
|
|
PatTup(..) => "(tuple arg NYI)".to_strbuf(),
|
2013-09-05 10:14:35 -04:00
|
|
|
PatUniq(p) => name_from_pat(p),
|
|
|
|
PatRegion(p) => name_from_pat(p),
|
2013-12-29 00:13:29 -05:00
|
|
|
PatLit(..) => {
|
|
|
|
warn!("tried to get argument name from PatLit, \
|
|
|
|
which is silly in function arguments");
|
2014-05-12 13:44:59 -07:00
|
|
|
"()".to_strbuf()
|
2013-12-29 00:13:29 -05:00
|
|
|
},
|
|
|
|
PatRange(..) => fail!("tried to get argument name from PatRange, \
|
2013-09-05 10:14:35 -04:00
|
|
|
which is not allowed in function arguments"),
|
2013-11-28 12:22:53 -08:00
|
|
|
PatVec(..) => fail!("tried to get argument name from pat_vec, \
|
2013-08-15 16:28:54 -04:00
|
|
|
which is not allowed in function arguments")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Given a Type, resolve it using the def_map
|
2014-03-05 15:28:08 -08:00
|
|
|
fn resolve_type(path: Path, tpbs: Option<Vec<TyParamBound> >,
|
2013-09-24 13:53:09 -07:00
|
|
|
id: ast::NodeId) -> Type {
|
2014-04-28 20:36:08 -07:00
|
|
|
let cx = super::ctxtkey.get().unwrap();
|
2014-03-05 16:36:01 +02:00
|
|
|
let tycx = match cx.maybe_typed {
|
|
|
|
core::Typed(ref tycx) => tycx,
|
2013-12-22 11:23:04 -08:00
|
|
|
// If we're extracting tests, this return value doesn't matter.
|
2014-03-05 16:36:01 +02:00
|
|
|
core::NotTyped(_) => return Bool
|
2013-12-22 11:23:04 -08:00
|
|
|
};
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("searching for {:?} in defmap", id);
|
2014-05-09 13:52:17 -07:00
|
|
|
let def = match tycx.def_map.borrow().find(&id) {
|
2014-03-20 21:52:59 -07:00
|
|
|
Some(&k) => k,
|
2014-05-09 13:52:17 -07:00
|
|
|
None => fail!("unresolved id not in defmap")
|
2013-08-15 16:28:54 -04:00
|
|
|
};
|
|
|
|
|
2014-05-09 13:52:17 -07:00
|
|
|
match def {
|
2014-01-27 14:18:36 +02:00
|
|
|
ast::DefSelfTy(i) => return Self(i),
|
2013-10-02 15:39:32 -07:00
|
|
|
ast::DefPrimTy(p) => match p {
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::TyStr => return String,
|
|
|
|
ast::TyBool => return Bool,
|
2013-08-15 16:28:54 -04:00
|
|
|
_ => return Primitive(p)
|
|
|
|
},
|
2013-10-02 15:39:32 -07:00
|
|
|
ast::DefTyParam(i, _) => return Generic(i.node),
|
2014-05-09 13:52:17 -07:00
|
|
|
ast::DefTyParamBinder(i) => return TyParamBinder(i),
|
|
|
|
_ => {}
|
|
|
|
};
|
|
|
|
let did = register_def(&**cx, def);
|
|
|
|
ResolvedPath { path: path, typarams: tpbs, did: did }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn register_def(cx: &core::DocContext, def: ast::Def) -> ast::DefId {
|
|
|
|
let (did, kind) = match def {
|
|
|
|
ast::DefFn(i, _) => (i, TypeFunction),
|
|
|
|
ast::DefTy(i) => (i, TypeEnum),
|
|
|
|
ast::DefTrait(i) => (i, TypeTrait),
|
2013-10-02 15:39:32 -07:00
|
|
|
ast::DefStruct(i) => (i, TypeStruct),
|
2014-05-09 13:52:17 -07:00
|
|
|
ast::DefMod(i) => (i, TypeModule),
|
|
|
|
ast::DefStatic(i, _) => (i, TypeStatic),
|
|
|
|
ast::DefVariant(i, _, _) => (i, TypeEnum),
|
|
|
|
_ => return ast_util::def_id_of_def(def),
|
2013-08-15 16:28:54 -04:00
|
|
|
};
|
2014-05-09 13:52:17 -07:00
|
|
|
if ast_util::is_local(did) { return did }
|
|
|
|
let tcx = match cx.maybe_typed {
|
|
|
|
core::Typed(ref t) => t,
|
|
|
|
core::NotTyped(_) => return did
|
|
|
|
};
|
|
|
|
let fqn = csearch::get_item_path(tcx, did);
|
2014-05-12 13:44:59 -07:00
|
|
|
let fqn = fqn.move_iter().map(|i| i.to_str().to_strbuf()).collect();
|
2014-05-09 13:52:17 -07:00
|
|
|
debug!("recording {} => {}", did, fqn);
|
|
|
|
cx.external_paths.borrow_mut().get_mut_ref().insert(did, (fqn, kind));
|
|
|
|
return did;
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
2013-09-24 13:56:52 -07:00
|
|
|
|
|
|
|
fn resolve_use_source(path: Path, id: ast::NodeId) -> ImportSource {
|
|
|
|
ImportSource {
|
|
|
|
path: path,
|
|
|
|
did: resolve_def(id),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn resolve_def(id: ast::NodeId) -> Option<ast::DefId> {
|
2014-04-28 20:36:08 -07:00
|
|
|
let cx = super::ctxtkey.get().unwrap();
|
2014-03-05 16:36:01 +02:00
|
|
|
match cx.maybe_typed {
|
|
|
|
core::Typed(ref tcx) => {
|
2014-05-09 13:52:17 -07:00
|
|
|
tcx.def_map.borrow().find(&id).map(|&def| register_def(&**cx, def))
|
2013-12-22 11:23:04 -08:00
|
|
|
}
|
2014-03-05 16:36:01 +02:00
|
|
|
core::NotTyped(_) => None
|
2013-12-22 11:23:04 -08:00
|
|
|
}
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2014-02-16 21:40:26 -08:00
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Macro {
|
2014-05-12 13:44:59 -07:00
|
|
|
pub source: StrBuf,
|
2014-02-16 21:40:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Macro {
|
|
|
|
fn clean(&self) -> Item {
|
|
|
|
Item {
|
2014-05-12 13:44:59 -07:00
|
|
|
name: Some(format_strbuf!("{}!", self.name.clean())),
|
2014-02-16 21:40:26 -08:00
|
|
|
attrs: self.attrs.clean(),
|
|
|
|
source: self.where.clean(),
|
|
|
|
visibility: ast::Public.clean(),
|
|
|
|
id: self.id,
|
|
|
|
inner: MacroItem(Macro {
|
|
|
|
source: self.where.to_src(),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|