Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c6ed4472
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c6ed4472
编写于
9月 19, 2012
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustdoc: Begin support for structs
上级
bd4365f1
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
159 addition
and
20 deletion
+159
-20
src/rustdoc/doc.rs
src/rustdoc/doc.rs
+38
-2
src/rustdoc/extract.rs
src/rustdoc/extract.rs
+33
-0
src/rustdoc/fold.rs
src/rustdoc/fold.rs
+28
-6
src/rustdoc/markdown_pass.rs
src/rustdoc/markdown_pass.rs
+19
-1
src/rustdoc/sort_item_type_pass.rs
src/rustdoc/sort_item_type_pass.rs
+14
-11
src/rustdoc/tystr_pass.rs
src/rustdoc/tystr_pass.rs
+27
-0
未找到文件。
src/rustdoc/doc.rs
浏览文件 @
c6ed4472
...
...
@@ -98,7 +98,8 @@ enum ItemTag {
EnumTag
(
EnumDoc
),
TraitTag
(
TraitDoc
),
ImplTag
(
ImplDoc
),
TyTag
(
TyDoc
)
TyTag
(
TyDoc
),
StructTag
(
StructDoc
)
}
impl
ItemTag
:
cmp
::
Eq
{
...
...
@@ -152,6 +153,12 @@ impl ItemTag : cmp::Eq {
_
=>
false
}
}
StructTag
(
e0a
)
=>
{
match
other
{
StructTag
(
e0b
)
=>
e0a
==
e0b
,
_
=>
false
}
}
}
}
pure
fn
ne
(
&&
other
:
ItemTag
)
->
bool
{
!
self
.eq
(
other
)
}
...
...
@@ -315,6 +322,21 @@ impl ImplDoc : cmp::Eq {
type
TyDoc
=
SimpleItemDoc
;
type
StructDoc
=
{
item
:
ItemDoc
,
fields
:
~
[
~
str
],
sig
:
Option
<~
str
>
};
impl
StructDoc
:
cmp
::
Eq
{
pure
fn
eq
(
&&
other
:
StructDoc
)
->
bool
{
return
self
.item
==
other
.item
&&
self
.fields
==
other
.fields
&&
self
.sig
==
other
.sig
;
}
pure
fn
ne
(
&&
other
:
StructDoc
)
->
bool
{
!
self
.eq
(
other
)
}
}
type
Index
=
{
entries
:
~
[
IndexEntry
]
};
...
...
@@ -442,6 +464,15 @@ fn types() -> ~[TyDoc] {
}
}
}
fn
structs
()
->
~
[
StructDoc
]
{
do
vec
::
filter_map
(
self
.items
)
|
itemtag
|
{
match
itemtag
{
StructTag
(
StructDoc
)
=>
Some
(
StructDoc
),
_
=>
None
}
}
}
}
trait
PageUtils
{
...
...
@@ -544,7 +575,8 @@ impl ItemTag: Item {
doc
::
EnumTag
(
doc
)
=>
doc
.item
,
doc
::
TraitTag
(
doc
)
=>
doc
.item
,
doc
::
ImplTag
(
doc
)
=>
doc
.item
,
doc
::
TyTag
(
doc
)
=>
doc
.item
doc
::
TyTag
(
doc
)
=>
doc
.item
,
doc
::
StructTag
(
doc
)
=>
doc
.item
}
}
}
...
...
@@ -573,6 +605,10 @@ impl ImplDoc: Item {
pure
fn
item
()
->
ItemDoc
{
self
.item
}
}
impl
StructDoc
:
Item
{
pure
fn
item
()
->
ItemDoc
{
self
.item
}
}
trait
ItemUtils
{
pure
fn
id
()
->
AstId
;
pure
fn
name
()
->
~
str
;
...
...
src/rustdoc/extract.rs
浏览文件 @
c6ed4472
...
...
@@ -119,6 +119,11 @@ fn moddoc_from_mod(
tydoc_from_ty
(
ItemDoc
)
))
}
ast
::
item_class
(
def
,
_
)
=>
{
Some
(
doc
::
StructTag
(
structdoc_from_struct
(
ItemDoc
,
def
)
))
}
_
=>
None
}
},
...
...
@@ -293,6 +298,34 @@ fn should_extract_tys() {
assert
doc
.cratemod
()
.types
()[
0
]
.name
()
==
~
"a"
;
}
fn
structdoc_from_struct
(
itemdoc
:
doc
::
ItemDoc
,
struct_def
:
@
ast
::
struct_def
)
->
doc
::
StructDoc
{
{
item
:
itemdoc
,
fields
:
do
struct_def
.fields.map
|
field
|
{
match
field
.node.kind
{
ast
::
named_field
(
ident
,
_
,
_
)
=>
to_str
(
ident
),
ast
::
unnamed_field
=>
fail
~
"what is an unnamed struct field?"
}
},
sig
:
None
}
}
#[test]
fn
should_extract_structs
()
{
let
doc
=
test
::
mk_doc
(
~
"struct Foo { field: () }"
);
assert
doc
.cratemod
()
.structs
()[
0
]
.name
()
==
~
"Foo"
;
}
#[test]
fn
should_extract_struct_fields
()
{
let
doc
=
test
::
mk_doc
(
~
"struct Foo { field: () }"
);
assert
doc
.cratemod
()
.structs
()[
0
]
.fields
[
0
]
==
~
"field"
;
}
#[cfg(test)]
mod
test
{
...
...
src/rustdoc/fold.rs
浏览文件 @
c6ed4472
...
...
@@ -11,6 +11,7 @@
export
default_seq_fold_trait
;
export
default_seq_fold_impl
;
export
default_seq_fold_type
;
export
default_seq_fold_struct
;
export
default_par_fold
;
export
default_par_fold_mod
;
export
default_par_fold_nmod
;
...
...
@@ -31,6 +32,8 @@
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
>
,
doc
:
doc
::
StructDoc
)
->
doc
::
StructDoc
;
type
Fold_
<
T
>
=
{
ctxt
:
T
,
...
...
@@ -44,7 +47,8 @@
fold_enum
:
FoldEnum
<
T
>
,
fold_trait
:
FoldTrait
<
T
>
,
fold_impl
:
FoldImpl
<
T
>
,
fold_type
:
FoldType
<
T
>
fold_type
:
FoldType
<
T
>
,
fold_struct
:
FoldStruct
<
T
>
};
...
...
@@ -62,7 +66,8 @@ fn mk_fold<T:Copy>(
+
fold_enum
:
FoldEnum
<
T
>
,
+
fold_trait
:
FoldTrait
<
T
>
,
+
fold_impl
:
FoldImpl
<
T
>
,
+
fold_type
:
FoldType
<
T
>
+
fold_type
:
FoldType
<
T
>
,
+
fold_struct
:
FoldStruct
<
T
>
)
->
Fold
<
T
>
{
Fold
({
ctxt
:
ctxt
,
...
...
@@ -76,7 +81,8 @@ fn mk_fold<T:Copy>(
fold_enum
:
fold_enum
,
fold_trait
:
fold_trait
,
fold_impl
:
fold_impl
,
fold_type
:
fold_type
fold_type
:
fold_type
,
fold_struct
:
fold_struct
,
})
}
...
...
@@ -93,7 +99,8 @@ fn default_any_fold<T:Send Copy>(ctxt: T) -> Fold<T> {
|
f
,
d
|
default_seq_fold_enum
(
f
,
d
),
|
f
,
d
|
default_seq_fold_trait
(
f
,
d
),
|
f
,
d
|
default_seq_fold_impl
(
f
,
d
),
|
f
,
d
|
default_seq_fold_type
(
f
,
d
)
|
f
,
d
|
default_seq_fold_type
(
f
,
d
),
|
f
,
d
|
default_seq_fold_struct
(
f
,
d
)
)
}
...
...
@@ -110,7 +117,8 @@ fn default_seq_fold<T:Copy>(ctxt: T) -> Fold<T> {
|
f
,
d
|
default_seq_fold_enum
(
f
,
d
),
|
f
,
d
|
default_seq_fold_trait
(
f
,
d
),
|
f
,
d
|
default_seq_fold_impl
(
f
,
d
),
|
f
,
d
|
default_seq_fold_type
(
f
,
d
)
|
f
,
d
|
default_seq_fold_type
(
f
,
d
),
|
f
,
d
|
default_seq_fold_struct
(
f
,
d
)
)
}
...
...
@@ -127,7 +135,8 @@ fn default_par_fold<T:Send Copy>(ctxt: T) -> Fold<T> {
|
f
,
d
|
default_seq_fold_enum
(
f
,
d
),
|
f
,
d
|
default_seq_fold_trait
(
f
,
d
),
|
f
,
d
|
default_seq_fold_impl
(
f
,
d
),
|
f
,
d
|
default_seq_fold_type
(
f
,
d
)
|
f
,
d
|
default_seq_fold_type
(
f
,
d
),
|
f
,
d
|
default_seq_fold_struct
(
f
,
d
)
)
}
...
...
@@ -267,6 +276,9 @@ fn fold_ItemTag<T>(fold: Fold<T>, doc: doc::ItemTag) -> doc::ItemTag {
doc
::
TyTag
(
TyDoc
)
=>
{
doc
::
TyTag
(
fold
.fold_type
(
fold
,
TyDoc
))
}
doc
::
StructTag
(
StructDoc
)
=>
{
doc
::
StructTag
(
fold
.fold_struct
(
fold
,
StructDoc
))
}
}
}
...
...
@@ -330,6 +342,16 @@ fn default_seq_fold_type<T>(
}
}
fn
default_seq_fold_struct
<
T
>
(
fold
:
Fold
<
T
>
,
doc
:
doc
::
StructDoc
)
->
doc
::
StructDoc
{
{
item
:
fold
.fold_item
(
fold
,
doc
.item
),
..
doc
}
}
#[test]
fn
default_fold_should_produce_same_doc
()
{
let
source
=
~
"mod a { fn b() { } mod c { fn d() { } } }"
;
...
...
src/rustdoc/markdown_pass.rs
浏览文件 @
c6ed4472
...
...
@@ -210,6 +210,9 @@ fn header_kind(doc: doc::ItemTag) -> ~str {
doc
::
TyTag
(
_
)
=>
{
~
"Type"
}
doc
::
StructTag
(
_
)
=>
{
~
"Struct"
}
}
}
...
...
@@ -370,7 +373,8 @@ fn write_item_(ctxt: Ctxt, doc: doc::ItemTag, write_header: bool) {
doc
::
EnumTag
(
EnumDoc
)
=>
write_enum
(
ctxt
,
EnumDoc
),
doc
::
TraitTag
(
TraitDoc
)
=>
write_trait
(
ctxt
,
TraitDoc
),
doc
::
ImplTag
(
ImplDoc
)
=>
write_impl
(
ctxt
,
ImplDoc
),
doc
::
TyTag
(
TyDoc
)
=>
write_type
(
ctxt
,
TyDoc
)
doc
::
TyTag
(
TyDoc
)
=>
write_type
(
ctxt
,
TyDoc
),
doc
::
StructTag
(
StructDoc
)
=>
write_struct
(
ctxt
,
StructDoc
),
}
}
...
...
@@ -775,6 +779,20 @@ fn should_write_type_signature() {
assert
str
::
contains
(
markdown
,
~
"
\n\n
type t = int
\n\n
"
);
}
fn
write_struct
(
ctxt
:
Ctxt
,
doc
:
doc
::
StructDoc
)
{
write_sig
(
ctxt
,
doc
.sig
);
write_common
(
ctxt
,
doc
.desc
(),
doc
.sections
());
}
#[test]
fn
should_write_struct_header
()
{
let
markdown
=
test
::
render
(
~
"struct S { field: () }"
);
assert
str
::
contains
(
markdown
,
~
"## Struct `S`
\n\n
"
);
}
#[cfg(test)]
mod
test
{
fn
render
(
source
:
~
str
)
->
~
str
{
...
...
src/rustdoc/sort_item_type_pass.rs
浏览文件 @
c6ed4472
...
...
@@ -11,11 +11,12 @@ fn mk_pass() -> Pass {
doc
::
ConstTag
(
_
)
=>
0
,
doc
::
TyTag
(
_
)
=>
1
,
doc
::
EnumTag
(
_
)
=>
2
,
doc
::
TraitTag
(
_
)
=>
3
,
doc
::
ImplTag
(
_
)
=>
4
,
doc
::
FnTag
(
_
)
=>
5
,
doc
::
ModTag
(
_
)
=>
6
,
doc
::
NmodTag
(
_
)
=>
7
doc
::
StructTag
(
_
)
=>
3
,
doc
::
TraitTag
(
_
)
=>
4
,
doc
::
ImplTag
(
_
)
=>
5
,
doc
::
FnTag
(
_
)
=>
6
,
doc
::
ModTag
(
_
)
=>
7
,
doc
::
NmodTag
(
_
)
=>
8
}
}
...
...
@@ -35,17 +36,19 @@ fn ifn() { } \
enum ienum { ivar }
\
trait itrait { fn a(); }
\
impl int { fn a() { } }
\
type itype = int;"
;
type itype = int;
\
struct istruct { f: () }"
;
do
astsrv
::
from_str
(
source
)
|
srv
|
{
let
doc
=
extract
::
from_srv
(
srv
,
~
""
);
let
doc
=
mk_pass
()
.f
(
srv
,
doc
);
assert
doc
.cratemod
()
.items
[
0
]
.name
()
==
~
"iconst"
;
assert
doc
.cratemod
()
.items
[
1
]
.name
()
==
~
"itype"
;
assert
doc
.cratemod
()
.items
[
2
]
.name
()
==
~
"ienum"
;
assert
doc
.cratemod
()
.items
[
3
]
.name
()
==
~
"itrait"
;
assert
doc
.cratemod
()
.items
[
4
]
.name
()
==
~
"__extensions__"
;
assert
doc
.cratemod
()
.items
[
5
]
.name
()
==
~
"ifn"
;
assert
doc
.cratemod
()
.items
[
6
]
.name
()
==
~
"imod"
;
assert
doc
.cratemod
()
.items
[
7
]
.name
()
==
~
"inmod"
;
assert
doc
.cratemod
()
.items
[
3
]
.name
()
==
~
"istruct"
;
assert
doc
.cratemod
()
.items
[
4
]
.name
()
==
~
"itrait"
;
assert
doc
.cratemod
()
.items
[
5
]
.name
()
==
~
"__extensions__"
;
assert
doc
.cratemod
()
.items
[
6
]
.name
()
==
~
"ifn"
;
assert
doc
.cratemod
()
.items
[
7
]
.name
()
==
~
"imod"
;
assert
doc
.cratemod
()
.items
[
8
]
.name
()
==
~
"inmod"
;
}
}
src/rustdoc/tystr_pass.rs
浏览文件 @
c6ed4472
...
...
@@ -27,6 +27,7 @@ fn run(
fold_trait
:
fold_trait
,
fold_impl
:
fold_impl
,
fold_type
:
fold_type
,
fold_struct
:
fold_struct
,
..
*
fold
::
default_any_fold
(
srv
)
});
fold
.fold_doc
(
fold
,
doc
)
...
...
@@ -322,6 +323,32 @@ fn should_add_type_signatures() {
assert
doc
.cratemod
()
.types
()[
0
]
.sig
==
Some
(
~
"type t<T> = int"
);
}
fn
fold_struct
(
fold
:
fold
::
Fold
<
astsrv
::
Srv
>
,
doc
:
doc
::
StructDoc
)
->
doc
::
StructDoc
{
let
srv
=
fold
.ctxt
;
{
sig
:
do
astsrv
::
exec
(
srv
)
|
ctxt
|
{
match
ctxt
.ast_map
.get
(
doc
.id
())
{
ast_map
::
node_item
(
item
,
_
)
=>
{
Some
(
pprust
::
item_to_str
(
item
,
extract
::
interner
()))
}
_
=>
fail
~
"not an item"
}
},
..
doc
}
}
#[test]
fn
should_add_struct_defs
()
{
let
doc
=
test
::
mk_doc
(
~
"struct S { field: () }"
);
assert
doc
.cratemod
()
.structs
()[
0
]
.sig
.get
()
.contains
(
"struct S {"
);
}
#[cfg(test)]
mod
test
{
fn
mk_doc
(
source
:
~
str
)
->
doc
::
Doc
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录