At the same time, migrate statics to constants.
ModuleItem(Module),
TypedefItem(Typedef),
StaticItem(Static),
+ ConstantItem(Constant),
TraitItem(Trait),
ImplItem(Impl),
/// `use` and `extern crate`
self.mods.clean(cx),
self.typedefs.clean(cx),
self.statics.clean(cx),
+ self.constants.clean(cx),
self.traits.clean(cx),
self.impls.clean(cx),
self.view_items.clean(cx).into_iter()
}
}
+#[deriving(Clone, Encodable, Decodable)]
+pub struct Constant {
+ pub type_: Type,
+ pub expr: String,
+}
+
+impl Clean<Item> for doctree::Constant {
+ fn clean(&self, cx: &DocContext) -> Item {
+ Item {
+ name: Some(self.name.clean(cx)),
+ attrs: self.attrs.clean(cx),
+ source: self.whence.clean(cx),
+ def_id: ast_util::local_def(self.id),
+ visibility: self.vis.clean(cx),
+ stability: self.stab.clean(cx),
+ inner: ConstantItem(Constant {
+ type_: self.type_.clean(cx),
+ expr: self.expr.span.to_src(cx),
+ }),
+ }
+ }
+}
+
#[deriving(Show, Clone, Encodable, Decodable, PartialEq)]
pub enum Mutability {
Mutable,
pub id: NodeId,
pub typedefs: Vec<Typedef>,
pub statics: Vec<Static>,
+ pub constants: Vec<Constant>,
pub traits: Vec<Trait>,
pub vis: ast::Visibility,
pub stab: Option<attr::Stability>,
mods : Vec::new(),
typedefs : Vec::new(),
statics : Vec::new(),
+ constants : Vec::new(),
traits : Vec::new(),
impls : Vec::new(),
view_items : Vec::new(),
pub whence: Span,
}
+pub struct Constant {
+ pub type_: P<ast::Ty>,
+ pub expr: P<ast::Expr>,
+ pub name: Ident,
+ pub attrs: Vec<ast::Attribute>,
+ pub vis: ast::Visibility,
+ pub stab: Option<attr::Stability>,
+ pub id: ast::NodeId,
+ pub whence: Span,
+}
+
pub struct Trait {
pub name: Ident,
pub items: Vec<ast::TraitItem>, //should be TraitItem
pub l_sysid: libc::c_int,
}
- pub static F_WRLCK: libc::c_short = 1;
- pub static F_UNLCK: libc::c_short = 2;
- pub static F_SETLK: libc::c_int = 6;
- pub static F_SETLKW: libc::c_int = 7;
+ pub const F_WRLCK: libc::c_short = 1;
+ pub const F_UNLCK: libc::c_short = 2;
+ pub const F_SETLK: libc::c_int = 6;
+ pub const F_SETLKW: libc::c_int = 7;
}
#[cfg(target_os = "freebsd")]
pub l_sysid: libc::c_int,
}
- pub static F_UNLCK: libc::c_short = 2;
- pub static F_WRLCK: libc::c_short = 3;
- pub static F_SETLK: libc::c_int = 12;
- pub static F_SETLKW: libc::c_int = 13;
+ pub const F_UNLCK: libc::c_short = 2;
+ pub const F_WRLCK: libc::c_short = 3;
+ pub const F_SETLK: libc::c_int = 12;
+ pub const F_SETLKW: libc::c_int = 13;
}
#[cfg(target_os = "dragonfly")]
pub l_sysid: libc::c_int,
}
- pub static F_UNLCK: libc::c_short = 2;
- pub static F_WRLCK: libc::c_short = 3;
- pub static F_SETLK: libc::c_int = 8;
- pub static F_SETLKW: libc::c_int = 9;
+ pub const F_UNLCK: libc::c_short = 2;
+ pub const F_WRLCK: libc::c_short = 3;
+ pub const F_SETLK: libc::c_int = 8;
+ pub const F_SETLKW: libc::c_int = 9;
}
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub l_sysid: libc::c_int,
}
- pub static F_UNLCK: libc::c_short = 2;
- pub static F_WRLCK: libc::c_short = 3;
- pub static F_SETLK: libc::c_int = 8;
- pub static F_SETLKW: libc::c_int = 9;
+ pub const F_UNLCK: libc::c_short = 2;
+ pub const F_WRLCK: libc::c_short = 3;
+ pub const F_SETLK: libc::c_int = 8;
+ pub const F_SETLKW: libc::c_int = 9;
}
pub struct Lock {
Macro = 15,
Primitive = 16,
AssociatedType = 17,
+ Constant = 18,
}
impl ItemType {
Macro => "macro",
Primitive => "primitive",
AssociatedType => "associatedtype",
+ Constant => "constant",
}
}
}
clean::FunctionItem(..) => Function,
clean::TypedefItem(..) => Typedef,
clean::StaticItem(..) => Static,
+ clean::ConstantItem(..) => Constant,
clean::TraitItem(..) => Trait,
clean::ImplItem(..) => Impl,
clean::ViewItemItem(..) => ViewItem,
/// table of contents.
pub struct MarkdownWithToc<'a>(pub &'a str);
-static DEF_OUNIT: libc::size_t = 64;
-static HOEDOWN_EXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 10;
-static HOEDOWN_EXT_TABLES: libc::c_uint = 1 << 0;
-static HOEDOWN_EXT_FENCED_CODE: libc::c_uint = 1 << 1;
-static HOEDOWN_EXT_AUTOLINK: libc::c_uint = 1 << 3;
-static HOEDOWN_EXT_STRIKETHROUGH: libc::c_uint = 1 << 4;
-static HOEDOWN_EXT_SUPERSCRIPT: libc::c_uint = 1 << 8;
-static HOEDOWN_EXT_FOOTNOTES: libc::c_uint = 1 << 2;
-
-static HOEDOWN_EXTENSIONS: libc::c_uint =
+const DEF_OUNIT: libc::size_t = 64;
+const HOEDOWN_EXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 10;
+const HOEDOWN_EXT_TABLES: libc::c_uint = 1 << 0;
+const HOEDOWN_EXT_FENCED_CODE: libc::c_uint = 1 << 1;
+const HOEDOWN_EXT_AUTOLINK: libc::c_uint = 1 << 3;
+const HOEDOWN_EXT_STRIKETHROUGH: libc::c_uint = 1 << 4;
+const HOEDOWN_EXT_SUPERSCRIPT: libc::c_uint = 1 << 8;
+const HOEDOWN_EXT_FOOTNOTES: libc::c_uint = 1 << 2;
+
+const HOEDOWN_EXTENSIONS: libc::c_uint =
HOEDOWN_EXT_NO_INTRA_EMPHASIS | HOEDOWN_EXT_TABLES |
HOEDOWN_EXT_FENCED_CODE | HOEDOWN_EXT_AUTOLINK |
HOEDOWN_EXT_STRIKETHROUGH | HOEDOWN_EXT_SUPERSCRIPT |
(_, &clean::StructItem(..)) => Greater,
(&clean::EnumItem(..), _) => Less,
(_, &clean::EnumItem(..)) => Greater,
+ (&clean::ConstantItem(..), _) => Less,
+ (_, &clean::ConstantItem(..)) => Greater,
(&clean::StaticItem(..), _) => Less,
(_, &clean::StaticItem(..)) => Greater,
(&clean::ForeignFunctionItem(..), _) => Less,
clean::FunctionItem(..) => ("functions", "Functions"),
clean::TypedefItem(..) => ("types", "Type Definitions"),
clean::StaticItem(..) => ("statics", "Statics"),
+ clean::ConstantItem(..) => ("constants", "Constants"),
clean::TraitItem(..) => ("traits", "Traits"),
clean::ImplItem(..) => ("impls", "Implementations"),
clean::ViewItemItem(..) => ("reexports", "Reexports"),
id = short, name = name));
}
- match myitem.inner {
- clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => {
- struct Initializer<'a>(&'a str, Item<'a>);
- impl<'a> fmt::Show for Initializer<'a> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let Initializer(s, item) = *self;
- if s.len() == 0 { return Ok(()); }
- try!(write!(f, "<code> = </code>"));
- if s.contains("\n") {
- match item.href() {
- Some(url) => {
- write!(f, "<a href='{}'>[definition]</a>",
- url)
- }
- None => Ok(()),
- }
- } else {
- write!(f, "<code>{}</code>", s.as_slice())
+ struct Initializer<'a>(&'a str, Item<'a>);
+ impl<'a> fmt::Show for Initializer<'a> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let Initializer(s, item) = *self;
+ if s.len() == 0 { return Ok(()); }
+ try!(write!(f, "<code> = </code>"));
+ if s.contains("\n") {
+ match item.href() {
+ Some(url) => {
+ write!(f, "<a href='{}'>[definition]</a>",
+ url)
}
+ None => Ok(()),
}
+ } else {
+ write!(f, "<code>{}</code>", s.as_slice())
}
+ }
+ }
+ match myitem.inner {
+ clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => {
try!(write!(w, "
<tr>
<td>{}<code>{}static {}{}: {}</code>{}</td>
Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }),
Markdown(blank(myitem.doc_value()))));
}
+ clean::ConstantItem(ref s) => {
+ try!(write!(w, "
+ <tr>
+ <td>{}<code>{}const {}: {}</code>{}</td>
+ <td class='docblock'>{} </td>
+ </tr>
+ ",
+ ConciseStability(&myitem.stability),
+ VisSpace(myitem.visibility),
+ *myitem.name.get_ref(),
+ s.type_,
+ Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }),
+ Markdown(blank(myitem.doc_value()))));
+ }
clean::ViewItemItem(ref item) => {
match item.inner {
"ffi",
"ffs",
"macro",
- "primitive"];
+ "primitive",
+ "associatedtype",
+ "constant"];
function itemTypeFromName(typename) {
for (var i = 0; i < itemTypes.length; ++i) {
clean::StructItem(..) | clean::EnumItem(..) |
clean::TraitItem(..) | clean::FunctionItem(..) |
clean::VariantItem(..) | clean::MethodItem(..) |
- clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) => {
+ clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) |
+ clean::ConstantItem(..) => {
if ast_util::is_local(i.def_id) &&
!self.exported_items.contains(&i.def_id.node) {
return None;
};
om.statics.push(s);
},
+ ast::ItemConst(ref ty, ref exp) => {
+ let s = Constant {
+ type_: ty.clone(),
+ expr: exp.clone(),
+ id: item.id,
+ name: name,
+ attrs: item.attrs.clone(),
+ whence: item.span,
+ vis: item.vis,
+ stab: self.stability(item.id),
+ };
+ om.constants.push(s);
+ },
ast::ItemTrait(ref gen, _, ref b, ref items) => {
let t = Trait {
name: name,