2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 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-05-17 17:28:44 -05:00
|
|
|
use core::prelude::*;
|
|
|
|
|
2012-12-23 16:41:37 -06:00
|
|
|
use doc;
|
2013-02-28 10:57:33 -06:00
|
|
|
#[cfg(test)] use extract;
|
|
|
|
#[cfg(test)] use parse;
|
2012-12-23 16:41:37 -06:00
|
|
|
|
2013-05-24 21:35:29 -05:00
|
|
|
use core::vec;
|
|
|
|
|
2012-12-05 17:06:54 -06:00
|
|
|
pub struct Fold<T> {
|
|
|
|
ctxt: T,
|
|
|
|
fold_doc: FoldDoc<T>,
|
|
|
|
fold_crate: FoldCrate<T>,
|
|
|
|
fold_item: FoldItem<T>,
|
|
|
|
fold_mod: FoldMod<T>,
|
|
|
|
fold_nmod: FoldNmod<T>,
|
|
|
|
fold_fn: FoldFn<T>,
|
|
|
|
fold_const: FoldConst<T>,
|
|
|
|
fold_enum: FoldEnum<T>,
|
|
|
|
fold_trait: FoldTrait<T>,
|
|
|
|
fold_impl: FoldImpl<T>,
|
|
|
|
fold_type: FoldType<T>,
|
|
|
|
fold_struct: FoldStruct<T>
|
|
|
|
}
|
2012-01-16 16:49:40 -06:00
|
|
|
|
2013-02-20 19:07:17 -06:00
|
|
|
impl<T:Clone> Clone for Fold<T> {
|
2012-11-26 20:03:36 -06:00
|
|
|
fn clone(&self) -> Fold<T> {
|
2012-12-05 17:06:54 -06:00
|
|
|
Fold {
|
2012-11-26 20:03:36 -06:00
|
|
|
ctxt: self.ctxt.clone(),
|
|
|
|
fold_doc: copy self.fold_doc,
|
|
|
|
fold_crate: copy self.fold_crate,
|
|
|
|
fold_item: copy self.fold_item,
|
|
|
|
fold_mod: copy self.fold_mod,
|
|
|
|
fold_nmod: copy self.fold_nmod,
|
|
|
|
fold_fn: copy self.fold_fn,
|
|
|
|
fold_const: copy self.fold_const,
|
|
|
|
fold_enum: copy self.fold_enum,
|
|
|
|
fold_trait: copy self.fold_trait,
|
|
|
|
fold_impl: copy self.fold_impl,
|
|
|
|
fold_type: copy self.fold_type,
|
|
|
|
fold_struct: copy self.fold_struct
|
2012-12-05 17:06:54 -06:00
|
|
|
}
|
2012-11-26 20:03:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-31 19:12:29 -06:00
|
|
|
type FoldDoc<T> = @fn(fold: &Fold<T>, doc: doc::Doc) -> doc::Doc;
|
|
|
|
type FoldCrate<T> = @fn(fold: &Fold<T>, doc: doc::CrateDoc) -> doc::CrateDoc;
|
|
|
|
type FoldItem<T> = @fn(fold: &Fold<T>, doc: doc::ItemDoc) -> doc::ItemDoc;
|
|
|
|
type FoldMod<T> = @fn(fold: &Fold<T>, doc: doc::ModDoc) -> doc::ModDoc;
|
|
|
|
type FoldNmod<T> = @fn(fold: &Fold<T>, doc: doc::NmodDoc) -> doc::NmodDoc;
|
|
|
|
type FoldFn<T> = @fn(fold: &Fold<T>, doc: doc::FnDoc) -> doc::FnDoc;
|
|
|
|
type FoldConst<T> = @fn(fold: &Fold<T>, doc: doc::ConstDoc) -> doc::ConstDoc;
|
|
|
|
type FoldEnum<T> = @fn(fold: &Fold<T>, doc: doc::EnumDoc) -> doc::EnumDoc;
|
|
|
|
type FoldTrait<T> = @fn(fold: &Fold<T>, doc: doc::TraitDoc) -> doc::TraitDoc;
|
|
|
|
type FoldImpl<T> = @fn(fold: &Fold<T>, doc: doc::ImplDoc) -> doc::ImplDoc;
|
|
|
|
type FoldType<T> = @fn(fold: &Fold<T>, doc: doc::TyDoc) -> doc::TyDoc;
|
|
|
|
type FoldStruct<T> = @fn(fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::StructDoc) -> doc::StructDoc;
|
2012-01-16 16:49:40 -06:00
|
|
|
|
|
|
|
// This exists because fn types don't infer correctly as record
|
|
|
|
// initializers, but they do as function arguments
|
2013-01-31 19:12:29 -06:00
|
|
|
fn mk_fold<T>(
|
2013-01-30 21:32:36 -06:00
|
|
|
ctxt: T,
|
|
|
|
fold_doc: FoldDoc<T>,
|
|
|
|
fold_crate: FoldCrate<T>,
|
|
|
|
fold_item: FoldItem<T>,
|
|
|
|
fold_mod: FoldMod<T>,
|
|
|
|
fold_nmod: FoldNmod<T>,
|
|
|
|
fold_fn: FoldFn<T>,
|
|
|
|
fold_const: FoldConst<T>,
|
|
|
|
fold_enum: FoldEnum<T>,
|
|
|
|
fold_trait: FoldTrait<T>,
|
|
|
|
fold_impl: FoldImpl<T>,
|
|
|
|
fold_type: FoldType<T>,
|
|
|
|
fold_struct: FoldStruct<T>
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> Fold<T> {
|
2012-12-05 17:06:54 -06:00
|
|
|
Fold {
|
2013-02-15 02:37:08 -06:00
|
|
|
ctxt: ctxt,
|
|
|
|
fold_doc: fold_doc,
|
|
|
|
fold_crate: fold_crate,
|
|
|
|
fold_item: fold_item,
|
|
|
|
fold_mod: fold_mod,
|
|
|
|
fold_nmod: fold_nmod,
|
|
|
|
fold_fn: fold_fn,
|
|
|
|
fold_const: fold_const,
|
|
|
|
fold_enum: fold_enum,
|
|
|
|
fold_trait: fold_trait,
|
|
|
|
fold_impl: fold_impl,
|
|
|
|
fold_type: fold_type,
|
|
|
|
fold_struct: fold_struct
|
2012-12-05 17:06:54 -06:00
|
|
|
}
|
2012-01-16 16:49:40 -06:00
|
|
|
}
|
|
|
|
|
2013-02-20 19:07:17 -06:00
|
|
|
pub fn default_any_fold<T:Clone>(ctxt: T) -> Fold<T> {
|
2012-02-27 00:38:35 -06:00
|
|
|
mk_fold(
|
2013-02-15 02:37:08 -06:00
|
|
|
ctxt,
|
2012-06-30 18:19:07 -05:00
|
|
|
|f, d| default_seq_fold_doc(f, d),
|
|
|
|
|f, d| default_seq_fold_crate(f, d),
|
|
|
|
|f, d| default_seq_fold_item(f, d),
|
|
|
|
|f, d| default_any_fold_mod(f, d),
|
|
|
|
|f, d| default_any_fold_nmod(f, d),
|
|
|
|
|f, d| default_seq_fold_fn(f, d),
|
|
|
|
|f, d| default_seq_fold_const(f, d),
|
|
|
|
|f, d| default_seq_fold_enum(f, d),
|
2012-07-03 18:30:42 -05:00
|
|
|
|f, d| default_seq_fold_trait(f, d),
|
2012-06-30 18:19:07 -05:00
|
|
|
|f, d| default_seq_fold_impl(f, d),
|
2012-09-19 16:37:43 -05:00
|
|
|
|f, d| default_seq_fold_type(f, d),
|
|
|
|
|f, d| default_seq_fold_struct(f, d)
|
2012-02-27 00:38:35 -06:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2013-02-20 19:07:17 -06:00
|
|
|
pub fn default_seq_fold<T:Clone>(ctxt: T) -> Fold<T> {
|
2012-01-16 16:49:40 -06:00
|
|
|
mk_fold(
|
2013-02-15 02:37:08 -06:00
|
|
|
ctxt,
|
2012-06-30 18:19:07 -05:00
|
|
|
|f, d| default_seq_fold_doc(f, d),
|
|
|
|
|f, d| default_seq_fold_crate(f, d),
|
|
|
|
|f, d| default_seq_fold_item(f, d),
|
|
|
|
|f, d| default_seq_fold_mod(f, d),
|
|
|
|
|f, d| default_seq_fold_nmod(f, d),
|
|
|
|
|f, d| default_seq_fold_fn(f, d),
|
|
|
|
|f, d| default_seq_fold_const(f, d),
|
|
|
|
|f, d| default_seq_fold_enum(f, d),
|
2012-07-03 18:30:42 -05:00
|
|
|
|f, d| default_seq_fold_trait(f, d),
|
2012-06-30 18:19:07 -05:00
|
|
|
|f, d| default_seq_fold_impl(f, d),
|
2012-09-19 16:37:43 -05:00
|
|
|
|f, d| default_seq_fold_type(f, d),
|
|
|
|
|f, d| default_seq_fold_struct(f, d)
|
2012-01-16 16:49:40 -06:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2013-02-20 19:07:17 -06:00
|
|
|
pub fn default_par_fold<T:Clone>(ctxt: T) -> Fold<T> {
|
2012-02-21 00:08:24 -06:00
|
|
|
mk_fold(
|
2013-02-15 02:37:08 -06:00
|
|
|
ctxt,
|
2012-06-30 18:19:07 -05:00
|
|
|
|f, d| default_seq_fold_doc(f, d),
|
|
|
|
|f, d| default_seq_fold_crate(f, d),
|
|
|
|
|f, d| default_seq_fold_item(f, d),
|
|
|
|
|f, d| default_par_fold_mod(f, d),
|
|
|
|
|f, d| default_par_fold_nmod(f, d),
|
|
|
|
|f, d| default_seq_fold_fn(f, d),
|
|
|
|
|f, d| default_seq_fold_const(f, d),
|
|
|
|
|f, d| default_seq_fold_enum(f, d),
|
2012-07-03 18:30:42 -05:00
|
|
|
|f, d| default_seq_fold_trait(f, d),
|
2012-06-30 18:19:07 -05:00
|
|
|
|f, d| default_seq_fold_impl(f, d),
|
2012-09-19 16:37:43 -05:00
|
|
|
|f, d| default_seq_fold_type(f, d),
|
|
|
|
|f, d| default_seq_fold_struct(f, d)
|
2012-02-21 00:08:24 -06:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2013-01-30 21:32:36 -06:00
|
|
|
pub fn default_seq_fold_doc<T>(fold: &Fold<T>, doc: doc::Doc) -> doc::Doc {
|
2013-01-29 21:45:53 -06:00
|
|
|
doc::Doc {
|
2012-07-13 12:36:35 -05:00
|
|
|
pages: do vec::map(doc.pages) |page| {
|
2013-01-30 15:14:35 -06:00
|
|
|
match copy *page {
|
2012-09-18 18:48:40 -05:00
|
|
|
doc::CratePage(doc) => {
|
2012-11-29 19:51:16 -06:00
|
|
|
doc::CratePage((fold.fold_crate)(fold, doc))
|
2012-03-02 20:33:25 -06:00
|
|
|
}
|
2012-09-18 18:48:40 -05:00
|
|
|
doc::ItemPage(doc) => {
|
|
|
|
doc::ItemPage(fold_ItemTag(fold, doc))
|
2012-03-02 20:33:25 -06:00
|
|
|
}
|
|
|
|
}
|
2012-09-04 15:29:32 -05:00
|
|
|
},
|
2013-01-29 21:45:53 -06:00
|
|
|
.. doc
|
|
|
|
}
|
2012-03-02 20:33:25 -06:00
|
|
|
}
|
|
|
|
|
2012-11-19 20:00:12 -06:00
|
|
|
pub fn default_seq_fold_crate<T>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::CrateDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::CrateDoc {
|
2013-01-25 18:57:39 -06:00
|
|
|
doc::CrateDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
topmod: (fold.fold_mod)(fold, copy doc.topmod)
|
2012-01-16 16:49:40 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-19 20:00:12 -06:00
|
|
|
pub fn default_seq_fold_item<T>(
|
2012-11-19 20:48:46 -06:00
|
|
|
_fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::ItemDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::ItemDoc {
|
2012-02-17 17:51:58 -06:00
|
|
|
doc
|
|
|
|
}
|
|
|
|
|
2013-01-31 19:12:29 -06:00
|
|
|
pub fn default_any_fold_mod<T:Clone>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::ModDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::ModDoc {
|
2013-01-29 21:45:53 -06:00
|
|
|
doc::ModDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2013-01-31 22:24:03 -06:00
|
|
|
items: vec::map(doc.items, |ItemTag| {
|
|
|
|
fold_ItemTag(fold, copy *ItemTag)
|
2012-09-04 15:29:32 -05:00
|
|
|
}),
|
2013-01-29 21:45:53 -06:00
|
|
|
.. doc
|
|
|
|
}
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|
|
|
|
|
2012-11-19 20:00:12 -06:00
|
|
|
pub fn default_seq_fold_mod<T>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::ModDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::ModDoc {
|
2013-01-29 21:45:53 -06:00
|
|
|
doc::ModDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2012-09-18 18:48:40 -05:00
|
|
|
items: vec::map(doc.items, |ItemTag| {
|
2013-01-30 15:14:35 -06:00
|
|
|
fold_ItemTag(fold, copy *ItemTag)
|
2012-09-04 15:29:32 -05:00
|
|
|
}),
|
2013-01-29 21:45:53 -06:00
|
|
|
.. doc
|
|
|
|
}
|
2012-02-24 15:34:35 -06:00
|
|
|
}
|
|
|
|
|
2013-01-31 19:12:29 -06:00
|
|
|
pub fn default_par_fold_mod<T:Clone>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::ModDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::ModDoc {
|
2013-01-29 21:45:53 -06:00
|
|
|
doc::ModDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2013-01-31 22:24:03 -06:00
|
|
|
items: vec::map(doc.items, |ItemTag| {
|
|
|
|
fold_ItemTag(fold, copy *ItemTag)
|
2012-09-04 15:29:32 -05:00
|
|
|
}),
|
2013-01-29 21:45:53 -06:00
|
|
|
.. doc
|
|
|
|
}
|
2012-01-16 16:49:40 -06:00
|
|
|
}
|
|
|
|
|
2013-01-31 19:12:29 -06:00
|
|
|
pub fn default_any_fold_nmod<T:Clone>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::NmodDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::NmodDoc {
|
2013-01-25 18:57:39 -06:00
|
|
|
doc::NmodDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2013-01-31 22:24:03 -06:00
|
|
|
fns: vec::map(doc.fns, |FnDoc| {
|
|
|
|
(fold.fold_fn)(fold, copy *FnDoc)
|
2012-09-04 15:29:32 -05:00
|
|
|
}),
|
|
|
|
.. doc
|
2012-02-27 00:58:24 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-19 20:00:12 -06:00
|
|
|
pub fn default_seq_fold_nmod<T>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::NmodDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::NmodDoc {
|
2013-01-25 18:57:39 -06:00
|
|
|
doc::NmodDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2012-09-18 18:48:40 -05:00
|
|
|
fns: vec::map(doc.fns, |FnDoc| {
|
2013-01-30 15:14:35 -06:00
|
|
|
(fold.fold_fn)(fold, copy *FnDoc)
|
2012-09-04 15:29:32 -05:00
|
|
|
}),
|
|
|
|
.. doc
|
2012-02-27 00:58:24 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-31 19:12:29 -06:00
|
|
|
pub fn default_par_fold_nmod<T:Clone>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::NmodDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::NmodDoc {
|
2013-01-25 18:57:39 -06:00
|
|
|
doc::NmodDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2013-01-31 22:24:03 -06:00
|
|
|
fns: vec::map(doc.fns, |FnDoc| {
|
|
|
|
(fold.fold_fn)(fold, copy *FnDoc)
|
2012-09-04 15:29:32 -05:00
|
|
|
}),
|
|
|
|
.. doc
|
2012-02-27 00:38:35 -06:00
|
|
|
}
|
2012-02-21 00:24:59 -06:00
|
|
|
}
|
|
|
|
|
2013-01-30 21:32:36 -06:00
|
|
|
pub fn fold_ItemTag<T>(fold: &Fold<T>, doc: doc::ItemTag) -> doc::ItemTag {
|
2012-08-06 14:34:08 -05:00
|
|
|
match doc {
|
2012-09-18 18:48:40 -05:00
|
|
|
doc::ModTag(ModDoc) => {
|
2012-11-29 19:51:16 -06:00
|
|
|
doc::ModTag((fold.fold_mod)(fold, ModDoc))
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|
2012-09-18 18:48:40 -05:00
|
|
|
doc::NmodTag(nModDoc) => {
|
2012-11-29 19:51:16 -06:00
|
|
|
doc::NmodTag((fold.fold_nmod)(fold, nModDoc))
|
2012-02-24 15:34:35 -06:00
|
|
|
}
|
2012-09-18 18:48:40 -05:00
|
|
|
doc::FnTag(FnDoc) => {
|
2012-11-29 19:51:16 -06:00
|
|
|
doc::FnTag((fold.fold_fn)(fold, FnDoc))
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|
2012-09-18 18:48:40 -05:00
|
|
|
doc::ConstTag(ConstDoc) => {
|
2012-11-29 19:51:16 -06:00
|
|
|
doc::ConstTag((fold.fold_const)(fold, ConstDoc))
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|
2012-09-18 18:48:40 -05:00
|
|
|
doc::EnumTag(EnumDoc) => {
|
2012-11-29 19:51:16 -06:00
|
|
|
doc::EnumTag((fold.fold_enum)(fold, EnumDoc))
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|
2012-09-18 18:48:40 -05:00
|
|
|
doc::TraitTag(TraitDoc) => {
|
2012-11-29 19:51:16 -06:00
|
|
|
doc::TraitTag((fold.fold_trait)(fold, TraitDoc))
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|
2012-09-18 18:48:40 -05:00
|
|
|
doc::ImplTag(ImplDoc) => {
|
2012-11-29 19:51:16 -06:00
|
|
|
doc::ImplTag((fold.fold_impl)(fold, ImplDoc))
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|
2012-09-18 18:48:40 -05:00
|
|
|
doc::TyTag(TyDoc) => {
|
2012-11-29 19:51:16 -06:00
|
|
|
doc::TyTag((fold.fold_type)(fold, TyDoc))
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|
2012-09-19 16:37:43 -05:00
|
|
|
doc::StructTag(StructDoc) => {
|
2012-11-29 19:51:16 -06:00
|
|
|
doc::StructTag((fold.fold_struct)(fold, StructDoc))
|
2012-09-19 16:37:43 -05:00
|
|
|
}
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-19 20:00:12 -06:00
|
|
|
pub fn default_seq_fold_fn<T>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::FnDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::FnDoc {
|
2013-01-25 18:57:39 -06:00
|
|
|
doc::SimpleItemDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2012-09-04 15:29:32 -05:00
|
|
|
.. doc
|
2012-02-17 17:51:58 -06:00
|
|
|
}
|
2012-01-16 16:49:40 -06:00
|
|
|
}
|
|
|
|
|
2012-11-19 20:00:12 -06:00
|
|
|
pub fn default_seq_fold_const<T>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::ConstDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::ConstDoc {
|
2013-01-25 18:57:39 -06:00
|
|
|
doc::SimpleItemDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2012-09-04 15:29:32 -05:00
|
|
|
.. doc
|
2012-02-17 17:51:58 -06:00
|
|
|
}
|
2012-01-24 01:40:30 -06:00
|
|
|
}
|
|
|
|
|
2012-11-19 20:00:12 -06:00
|
|
|
pub fn default_seq_fold_enum<T>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::EnumDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::EnumDoc {
|
2013-01-25 18:57:39 -06:00
|
|
|
doc::EnumDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2012-09-04 15:29:32 -05:00
|
|
|
.. doc
|
2012-02-17 17:51:58 -06:00
|
|
|
}
|
2012-01-25 18:56:28 -06:00
|
|
|
}
|
|
|
|
|
2012-11-19 20:00:12 -06:00
|
|
|
pub fn default_seq_fold_trait<T>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::TraitDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::TraitDoc {
|
2013-01-25 18:57:39 -06:00
|
|
|
doc::TraitDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2012-09-04 15:29:32 -05:00
|
|
|
.. doc
|
2012-02-17 17:51:58 -06:00
|
|
|
}
|
2012-01-30 16:11:35 -06:00
|
|
|
}
|
|
|
|
|
2012-11-19 20:00:12 -06:00
|
|
|
pub fn default_seq_fold_impl<T>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::ImplDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::ImplDoc {
|
2013-01-25 18:57:39 -06:00
|
|
|
doc::ImplDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2012-09-04 15:29:32 -05:00
|
|
|
.. doc
|
2012-02-17 17:51:58 -06:00
|
|
|
}
|
2012-01-31 17:28:09 -06:00
|
|
|
}
|
|
|
|
|
2012-11-19 20:00:12 -06:00
|
|
|
pub fn default_seq_fold_type<T>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::TyDoc
|
2012-09-18 18:48:40 -05:00
|
|
|
) -> doc::TyDoc {
|
2013-01-25 18:57:39 -06:00
|
|
|
doc::SimpleItemDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2012-09-04 15:29:32 -05:00
|
|
|
.. doc
|
2012-02-17 17:51:58 -06:00
|
|
|
}
|
2012-02-02 00:41:41 -06:00
|
|
|
}
|
|
|
|
|
2012-11-19 20:00:12 -06:00
|
|
|
pub fn default_seq_fold_struct<T>(
|
2012-11-19 20:48:46 -06:00
|
|
|
fold: &Fold<T>,
|
2013-01-30 21:32:36 -06:00
|
|
|
doc: doc::StructDoc
|
2012-09-19 16:37:43 -05:00
|
|
|
) -> doc::StructDoc {
|
2013-01-25 18:57:39 -06:00
|
|
|
doc::StructDoc {
|
2013-01-30 15:14:35 -06:00
|
|
|
item: (fold.fold_item)(fold, copy doc.item),
|
2012-09-19 16:37:43 -05:00
|
|
|
.. doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-24 01:40:30 -06:00
|
|
|
#[test]
|
|
|
|
fn default_fold_should_produce_same_doc() {
|
2012-07-14 00:57:48 -05:00
|
|
|
let source = ~"mod a { fn b() { } mod c { fn d() { } } }";
|
2012-04-30 13:52:07 -05:00
|
|
|
let ast = parse::from_str(source);
|
2012-07-14 00:57:48 -05:00
|
|
|
let doc = extract::extract(ast, ~"");
|
2012-01-24 01:40:30 -06:00
|
|
|
let fld = default_seq_fold(());
|
2013-01-30 15:14:35 -06:00
|
|
|
let folded = (fld.fold_doc)(&fld, copy doc);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(doc, folded);
|
2012-01-24 01:40:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_fold_should_produce_same_consts() {
|
2013-03-22 16:00:15 -05:00
|
|
|
let source = ~"static a: int = 0;";
|
2012-04-30 13:52:07 -05:00
|
|
|
let ast = parse::from_str(source);
|
2012-07-14 00:57:48 -05:00
|
|
|
let doc = extract::extract(ast, ~"");
|
2012-01-24 01:40:30 -06:00
|
|
|
let fld = default_seq_fold(());
|
2013-01-30 15:14:35 -06:00
|
|
|
let folded = (fld.fold_doc)(&fld, copy doc);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(doc, folded);
|
2012-01-25 18:56:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_fold_should_produce_same_enums() {
|
2012-07-14 00:57:48 -05:00
|
|
|
let source = ~"enum a { b }";
|
2012-04-30 13:52:07 -05:00
|
|
|
let ast = parse::from_str(source);
|
2012-07-14 00:57:48 -05:00
|
|
|
let doc = extract::extract(ast, ~"");
|
2012-01-25 18:56:28 -06:00
|
|
|
let fld = default_seq_fold(());
|
2013-01-30 15:14:35 -06:00
|
|
|
let folded = (fld.fold_doc)(&fld, copy doc);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(doc, folded);
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_parallel_fold_should_produce_same_doc() {
|
2012-07-14 00:57:48 -05:00
|
|
|
let source = ~"mod a { fn b() { } mod c { fn d() { } } }";
|
2012-04-30 13:52:07 -05:00
|
|
|
let ast = parse::from_str(source);
|
2012-07-14 00:57:48 -05:00
|
|
|
let doc = extract::extract(ast, ~"");
|
2012-02-21 00:08:24 -06:00
|
|
|
let fld = default_par_fold(());
|
2013-01-30 15:14:35 -06:00
|
|
|
let folded = (fld.fold_doc)(&fld, copy doc);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(doc, folded);
|
2012-02-21 00:08:24 -06:00
|
|
|
}
|