Change const to static

This commit is contained in:
Sangeun Kim 2013-08-07 16:47:21 +09:00
parent cb3dd21301
commit caa41354c2
6 changed files with 43 additions and 43 deletions

View File

@ -54,7 +54,7 @@ pub struct CrateDoc {
pub enum ItemTag { pub enum ItemTag {
ModTag(ModDoc), ModTag(ModDoc),
NmodTag(NmodDoc), NmodTag(NmodDoc),
ConstTag(ConstDoc), StaticTag(StaticDoc),
FnTag(FnDoc), FnTag(FnDoc),
EnumTag(EnumDoc), EnumTag(EnumDoc),
TraitTag(TraitDoc), TraitTag(TraitDoc),
@ -95,7 +95,7 @@ pub struct NmodDoc {
index: Option<Index> index: Option<Index>
} }
pub type ConstDoc = SimpleItemDoc; pub type StaticDoc = SimpleItemDoc;
pub type FnDoc = SimpleItemDoc; pub type FnDoc = SimpleItemDoc;
@ -214,8 +214,8 @@ impl ModDoc {
md!(FnTag) md!(FnTag)
} }
pub fn consts(&self) -> ~[ConstDoc] { pub fn statics(&self) -> ~[StaticDoc] {
md!(ConstTag) md!(StaticTag)
} }
pub fn enums(&self) -> ~[EnumDoc] { pub fn enums(&self) -> ~[EnumDoc] {
@ -249,7 +249,7 @@ pub trait PageUtils {
fn mods(&self) -> ~[ModDoc]; fn mods(&self) -> ~[ModDoc];
fn nmods(&self) -> ~[NmodDoc]; fn nmods(&self) -> ~[NmodDoc];
fn fns(&self) -> ~[FnDoc]; fn fns(&self) -> ~[FnDoc];
fn consts(&self) -> ~[ConstDoc]; fn statics(&self) -> ~[StaticDoc];
fn enums(&self) -> ~[EnumDoc]; fn enums(&self) -> ~[EnumDoc];
fn traits(&self) -> ~[TraitDoc]; fn traits(&self) -> ~[TraitDoc];
fn impls(&self) -> ~[ImplDoc]; fn impls(&self) -> ~[ImplDoc];
@ -270,8 +270,8 @@ impl PageUtils for ~[Page] {
pu!(FnTag) pu!(FnTag)
} }
fn consts(&self) -> ~[ConstDoc] { fn statics(&self) -> ~[StaticDoc] {
pu!(ConstTag) pu!(StaticTag)
} }
fn enums(&self) -> ~[EnumDoc] { fn enums(&self) -> ~[EnumDoc] {
@ -301,7 +301,7 @@ impl Item for ItemTag {
&doc::ModTag(ref doc) => doc.item.clone(), &doc::ModTag(ref doc) => doc.item.clone(),
&doc::NmodTag(ref doc) => doc.item.clone(), &doc::NmodTag(ref doc) => doc.item.clone(),
&doc::FnTag(ref doc) => doc.item.clone(), &doc::FnTag(ref doc) => doc.item.clone(),
&doc::ConstTag(ref doc) => doc.item.clone(), &doc::StaticTag(ref doc) => doc.item.clone(),
&doc::EnumTag(ref doc) => doc.item.clone(), &doc::EnumTag(ref doc) => doc.item.clone(),
&doc::TraitTag(ref doc) => doc.item.clone(), &doc::TraitTag(ref doc) => doc.item.clone(),
&doc::ImplTag(ref doc) => doc.item.clone(), &doc::ImplTag(ref doc) => doc.item.clone(),

View File

@ -101,8 +101,8 @@ fn moddoc_from_mod(
)) ))
} }
ast::item_static(*) => { ast::item_static(*) => {
Some(doc::ConstTag( Some(doc::StaticTag(
constdoc_from_const(ItemDoc) staticdoc_from_static(ItemDoc)
)) ))
} }
ast::item_enum(enum_definition, _) => { ast::item_enum(enum_definition, _) => {
@ -165,7 +165,7 @@ fn fndoc_from_fn(itemdoc: doc::ItemDoc) -> doc::FnDoc {
} }
} }
fn constdoc_from_const(itemdoc: doc::ItemDoc) -> doc::ConstDoc { fn staticdoc_from_static(itemdoc: doc::ItemDoc) -> doc::StaticDoc {
doc::SimpleItemDoc { doc::SimpleItemDoc {
item: itemdoc, item: itemdoc,
sig: None sig: None
@ -356,10 +356,10 @@ mod test {
} }
#[test] #[test]
fn should_extract_const_name_and_id() { fn should_extract_static_name_and_id() {
let doc = mk_doc(@"static a: int = 0;"); let doc = mk_doc(@"static a: int = 0;");
assert!(doc.cratemod().consts()[0].id() != 0); assert!(doc.cratemod().statics()[0].id() != 0);
assert!(doc.cratemod().consts()[0].name_() == ~"a"); assert!(doc.cratemod().statics()[0].name_() == ~"a");
} }
#[test] #[test]

View File

@ -21,7 +21,7 @@ pub struct Fold<T> {
fold_mod: FoldMod<T>, fold_mod: FoldMod<T>,
fold_nmod: FoldNmod<T>, fold_nmod: FoldNmod<T>,
fold_fn: FoldFn<T>, fold_fn: FoldFn<T>,
fold_const: FoldConst<T>, fold_static: FoldStatic<T>,
fold_enum: FoldEnum<T>, fold_enum: FoldEnum<T>,
fold_trait: FoldTrait<T>, fold_trait: FoldTrait<T>,
fold_impl: FoldImpl<T>, fold_impl: FoldImpl<T>,
@ -39,7 +39,7 @@ impl<T:Clone> Clone for Fold<T> {
fold_mod: self.fold_mod, fold_mod: self.fold_mod,
fold_nmod: self.fold_nmod, fold_nmod: self.fold_nmod,
fold_fn: self.fold_fn, fold_fn: self.fold_fn,
fold_const: self.fold_const, fold_static: self.fold_static,
fold_enum: self.fold_enum, fold_enum: self.fold_enum,
fold_trait: self.fold_trait, fold_trait: self.fold_trait,
fold_impl: self.fold_impl, fold_impl: self.fold_impl,
@ -55,7 +55,7 @@ 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 FoldMod<T> = @fn(fold: &Fold<T>, doc: doc::ModDoc) -> doc::ModDoc;
type FoldNmod<T> = @fn(fold: &Fold<T>, doc: doc::NmodDoc) -> doc::NmodDoc; 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 FoldFn<T> = @fn(fold: &Fold<T>, doc: doc::FnDoc) -> doc::FnDoc;
type FoldConst<T> = @fn(fold: &Fold<T>, doc: doc::ConstDoc) -> doc::ConstDoc; type FoldStatic<T> = @fn(fold: &Fold<T>, doc: doc::StaticDoc) -> doc::StaticDoc;
type FoldEnum<T> = @fn(fold: &Fold<T>, doc: doc::EnumDoc) -> doc::EnumDoc; 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 FoldTrait<T> = @fn(fold: &Fold<T>, doc: doc::TraitDoc) -> doc::TraitDoc;
type FoldImpl<T> = @fn(fold: &Fold<T>, doc: doc::ImplDoc) -> doc::ImplDoc; type FoldImpl<T> = @fn(fold: &Fold<T>, doc: doc::ImplDoc) -> doc::ImplDoc;
@ -73,7 +73,7 @@ fn mk_fold<T>(
fold_mod: FoldMod<T>, fold_mod: FoldMod<T>,
fold_nmod: FoldNmod<T>, fold_nmod: FoldNmod<T>,
fold_fn: FoldFn<T>, fold_fn: FoldFn<T>,
fold_const: FoldConst<T>, fold_static: FoldStatic<T>,
fold_enum: FoldEnum<T>, fold_enum: FoldEnum<T>,
fold_trait: FoldTrait<T>, fold_trait: FoldTrait<T>,
fold_impl: FoldImpl<T>, fold_impl: FoldImpl<T>,
@ -88,7 +88,7 @@ fn mk_fold<T>(
fold_mod: fold_mod, fold_mod: fold_mod,
fold_nmod: fold_nmod, fold_nmod: fold_nmod,
fold_fn: fold_fn, fold_fn: fold_fn,
fold_const: fold_const, fold_static: fold_static,
fold_enum: fold_enum, fold_enum: fold_enum,
fold_trait: fold_trait, fold_trait: fold_trait,
fold_impl: fold_impl, fold_impl: fold_impl,
@ -106,7 +106,7 @@ pub fn default_any_fold<T:Clone>(ctxt: T) -> Fold<T> {
|f, d| default_any_fold_mod(f, d), |f, d| default_any_fold_mod(f, d),
|f, d| default_any_fold_nmod(f, d), |f, d| default_any_fold_nmod(f, d),
|f, d| default_seq_fold_fn(f, d), |f, d| default_seq_fold_fn(f, d),
|f, d| default_seq_fold_const(f, d), |f, d| default_seq_fold_static(f, d),
|f, d| default_seq_fold_enum(f, d), |f, d| default_seq_fold_enum(f, d),
|f, d| default_seq_fold_trait(f, d), |f, d| default_seq_fold_trait(f, d),
|f, d| default_seq_fold_impl(f, d), |f, d| default_seq_fold_impl(f, d),
@ -124,7 +124,7 @@ pub fn default_seq_fold<T:Clone>(ctxt: T) -> Fold<T> {
|f, d| default_seq_fold_mod(f, d), |f, d| default_seq_fold_mod(f, d),
|f, d| default_seq_fold_nmod(f, d), |f, d| default_seq_fold_nmod(f, d),
|f, d| default_seq_fold_fn(f, d), |f, d| default_seq_fold_fn(f, d),
|f, d| default_seq_fold_const(f, d), |f, d| default_seq_fold_static(f, d),
|f, d| default_seq_fold_enum(f, d), |f, d| default_seq_fold_enum(f, d),
|f, d| default_seq_fold_trait(f, d), |f, d| default_seq_fold_trait(f, d),
|f, d| default_seq_fold_impl(f, d), |f, d| default_seq_fold_impl(f, d),
@ -142,7 +142,7 @@ pub fn default_par_fold<T:Clone>(ctxt: T) -> Fold<T> {
|f, d| default_par_fold_mod(f, d), |f, d| default_par_fold_mod(f, d),
|f, d| default_par_fold_nmod(f, d), |f, d| default_par_fold_nmod(f, d),
|f, d| default_seq_fold_fn(f, d), |f, d| default_seq_fold_fn(f, d),
|f, d| default_seq_fold_const(f, d), |f, d| default_seq_fold_static(f, d),
|f, d| default_seq_fold_enum(f, d), |f, d| default_seq_fold_enum(f, d),
|f, d| default_seq_fold_trait(f, d), |f, d| default_seq_fold_trait(f, d),
|f, d| default_seq_fold_impl(f, d), |f, d| default_seq_fold_impl(f, d),
@ -272,8 +272,8 @@ pub fn fold_ItemTag<T>(fold: &Fold<T>, doc: doc::ItemTag) -> doc::ItemTag {
doc::FnTag(FnDoc) => { doc::FnTag(FnDoc) => {
doc::FnTag((fold.fold_fn)(fold, FnDoc)) doc::FnTag((fold.fold_fn)(fold, FnDoc))
} }
doc::ConstTag(ConstDoc) => { doc::StaticTag(StaticDoc) => {
doc::ConstTag((fold.fold_const)(fold, ConstDoc)) doc::StaticTag((fold.fold_static)(fold, StaticDoc))
} }
doc::EnumTag(EnumDoc) => { doc::EnumTag(EnumDoc) => {
doc::EnumTag((fold.fold_enum)(fold, EnumDoc)) doc::EnumTag((fold.fold_enum)(fold, EnumDoc))
@ -303,10 +303,10 @@ pub fn default_seq_fold_fn<T>(
} }
} }
pub fn default_seq_fold_const<T>( pub fn default_seq_fold_static<T>(
fold: &Fold<T>, fold: &Fold<T>,
doc: doc::ConstDoc doc: doc::StaticDoc
) -> doc::ConstDoc { ) -> doc::StaticDoc {
doc::SimpleItemDoc { doc::SimpleItemDoc {
item: (fold.fold_item)(fold, doc.item.clone()), item: (fold.fold_item)(fold, doc.item.clone()),
.. doc .. doc
@ -374,7 +374,7 @@ fn default_fold_should_produce_same_doc() {
} }
#[test] #[test]
fn default_fold_should_produce_same_consts() { fn default_fold_should_produce_same_statics() {
let source = @"static a: int = 0;"; let source = @"static a: int = 0;";
let ast = parse::from_str(source); let ast = parse::from_str(source);
let doc = extract::extract(ast, ~""); let doc = extract::extract(ast, ~"");

View File

@ -321,7 +321,7 @@ fn write_item_(ctxt: &Ctxt, doc: doc::ItemTag, write_header: bool) {
doc::ModTag(ModDoc) => write_mod(ctxt, ModDoc), doc::ModTag(ModDoc) => write_mod(ctxt, ModDoc),
doc::NmodTag(nModDoc) => write_nmod(ctxt, nModDoc), doc::NmodTag(nModDoc) => write_nmod(ctxt, nModDoc),
doc::FnTag(FnDoc) => write_fn(ctxt, FnDoc), doc::FnTag(FnDoc) => write_fn(ctxt, FnDoc),
doc::ConstTag(ConstDoc) => write_const(ctxt, ConstDoc), doc::StaticTag(StaticDoc) => write_static(ctxt, StaticDoc),
doc::EnumTag(EnumDoc) => write_enum(ctxt, EnumDoc), doc::EnumTag(EnumDoc) => write_enum(ctxt, EnumDoc),
doc::TraitTag(TraitDoc) => write_trait(ctxt, TraitDoc), doc::TraitTag(TraitDoc) => write_trait(ctxt, TraitDoc),
doc::ImplTag(ImplDoc) => write_impl(ctxt, ImplDoc), doc::ImplTag(ImplDoc) => write_impl(ctxt, ImplDoc),
@ -409,9 +409,9 @@ fn code_block(s: ~str) -> ~str {
~~~", s) ~~~", s)
} }
fn write_const( fn write_static(
ctxt: &Ctxt, ctxt: &Ctxt,
doc: doc::ConstDoc doc: doc::StaticDoc
) { ) {
write_sig(ctxt, doc.sig.clone()); write_sig(ctxt, doc.sig.clone());
write_common(ctxt, doc.desc(), doc.sections()); write_common(ctxt, doc.desc(), doc.sections());
@ -775,13 +775,13 @@ mod test {
} }
#[test] #[test]
fn should_write_const_header() { fn should_write_static_header() {
let markdown = render(~"static a: bool = true;"); let markdown = render(~"static a: bool = true;");
assert!(markdown.contains("## Static `a`\n\n")); assert!(markdown.contains("## Static `a`\n\n"));
} }
#[test] #[test]
fn should_write_const_description() { fn should_write_static_description() {
let markdown = render( let markdown = render(
~"#[doc = \"b\"]\ ~"#[doc = \"b\"]\
static a: bool = true;"); static a: bool = true;");

View File

@ -18,7 +18,7 @@ pub fn mk_pass() -> Pass {
fn by_score(item1: &doc::ItemTag, item2: &doc::ItemTag) -> bool { fn by_score(item1: &doc::ItemTag, item2: &doc::ItemTag) -> bool {
fn score(item: &doc::ItemTag) -> int { fn score(item: &doc::ItemTag) -> int {
match *item { match *item {
doc::ConstTag(_) => 0, doc::StaticTag(_) => 0,
doc::TyTag(_) => 1, doc::TyTag(_) => 1,
doc::EnumTag(_) => 2, doc::EnumTag(_) => 2,
doc::StructTag(_) => 3, doc::StructTag(_) => 3,
@ -43,7 +43,7 @@ fn test() {
let source = let source =
~"mod imod { } \ ~"mod imod { } \
static iconst: int = 0; \ static istatic: int = 0; \
fn ifn() { } \ fn ifn() { } \
enum ienum { ivar } \ enum ienum { ivar } \
trait itrait { fn a(); } \ trait itrait { fn a(); } \
@ -54,7 +54,7 @@ fn test() {
let doc = extract::from_srv(srv.clone(), ~""); let doc = extract::from_srv(srv.clone(), ~"");
let doc = (mk_pass().f)(srv.clone(), doc); let doc = (mk_pass().f)(srv.clone(), doc);
// hidden __std_macros module at the start. // hidden __std_macros module at the start.
assert_eq!(doc.cratemod().items[0].name_(), ~"iconst"); assert_eq!(doc.cratemod().items[0].name_(), ~"istatic");
assert_eq!(doc.cratemod().items[1].name_(), ~"itype"); assert_eq!(doc.cratemod().items[1].name_(), ~"itype");
assert_eq!(doc.cratemod().items[2].name_(), ~"ienum"); assert_eq!(doc.cratemod().items[2].name_(), ~"ienum");
assert_eq!(doc.cratemod().items[3].name_(), ~"istruct"); assert_eq!(doc.cratemod().items[3].name_(), ~"istruct");

View File

@ -39,7 +39,7 @@ pub fn run(
let fold = Fold { let fold = Fold {
ctxt: srv.clone(), ctxt: srv.clone(),
fold_fn: fold_fn, fold_fn: fold_fn,
fold_const: fold_const, fold_static: fold_static,
fold_enum: fold_enum, fold_enum: fold_enum,
fold_trait: fold_trait, fold_trait: fold_trait,
fold_impl: fold_impl, fold_impl: fold_impl,
@ -93,10 +93,10 @@ fn get_fn_sig(srv: astsrv::Srv, fn_id: doc::AstId) -> Option<~str> {
} }
} }
fn fold_const( fn fold_static(
fold: &fold::Fold<astsrv::Srv>, fold: &fold::Fold<astsrv::Srv>,
doc: doc::ConstDoc doc: doc::StaticDoc
) -> doc::ConstDoc { ) -> doc::StaticDoc {
let srv = fold.ctxt.clone(); let srv = fold.ctxt.clone();
doc::SimpleItemDoc { doc::SimpleItemDoc {
@ -109,7 +109,7 @@ fn fold_const(
}, _) => { }, _) => {
pprust::ty_to_str(ty, extract::interner()) pprust::ty_to_str(ty, extract::interner())
} }
_ => fail!("fold_const: id not bound to a const item") _ => fail!("fold_static: id not bound to a static item")
} }
}}), }}),
.. doc .. doc
@ -384,9 +384,9 @@ mod test {
} }
#[test] #[test]
fn should_add_const_types() { fn should_add_static_types() {
let doc = mk_doc(~"static a: bool = true;"); let doc = mk_doc(~"static a: bool = true;");
assert!(doc.cratemod().consts()[0].sig == Some(~"bool")); assert!(doc.cratemod().statics()[0].sig == Some(~"bool"));
} }
#[test] #[test]