about summary refs log tree commit diff
path: root/src/librustdoc/rustdoc.rc
blob: bfbf8b40f300bed396a01d5f3e7f5159544a5ff7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//! Rustdoc - The Rust documentation generator

#[link(name = "rustdoc",
       vers = "0.5",
       uuid = "f8abd014-b281-484d-a0c3-26e3de8e2412",
       url = "https://github.com/mozilla/rust/tree/master/src/rustdoc")];

#[comment = "The Rust documentation generator"];
#[license = "MIT"];
#[crate_type = "lib"];

#[no_core];
#[legacy_modes];

#[allow(vecs_implicitly_copyable)];
#[allow(non_implicitly_copyable_typarams)];
#[allow(deprecated_mode)];
#[allow(deprecated_pattern)];

extern mod core(vers = "0.5");
extern mod std(vers = "0.5");
extern mod rustc(vers = "0.5");
extern mod syntax(vers = "0.5");

use core::*;
use std::par;

mod pass;
mod config;
mod parse;
mod extract;
mod attr_parser;
mod doc;
mod markdown_index_pass;
mod markdown_pass;
mod markdown_writer;
mod fold;
mod path_pass;
mod attr_pass;
mod tystr_pass;
mod prune_hidden_pass;
mod desc_to_brief_pass;
mod text_pass;
mod unindent_pass;
mod trim_pass;
mod astsrv;
mod demo;
mod sort_pass;
mod sort_item_name_pass;
mod sort_item_type_pass;
mod page_pass;
mod sectionalize_pass;
mod escape_pass;
mod prune_private_pass;
mod util;

use doc::ItemUtils;
use doc::Item;
use pass::Pass;
use config::Config;

fn main() {
    let args = os::args();

    if args.contains(&~"-h") || args.contains(&~"--help") {
        config::usage();
        return;
    }

    let config = match config::parse_config(args) {
      Ok(config) => config,
      Err(err) => {
        io::println(fmt!("error: %s", err));
        return;
      }
    };

    run(config);
}

/// Runs rustdoc over the given file
fn run(config: Config) {

    let source_file = config.input_crate;

    // Create an AST service from the source code
    do astsrv::from_file(source_file.to_str()) |srv| {

        // Just time how long it takes for the AST to become available
        do time(~"wait_ast") {
            do astsrv::exec(srv) |_ctxt| { }
        };

        // Extract the initial doc tree from the AST. This contains
        // just names and node ids.
        let doc = time(~"extract", || {
            let default_name = source_file;
            extract::from_srv(srv, default_name.to_str())
        });

        // Refine and publish the document
        pass::run_passes(srv, doc, ~[
            // Generate type and signature strings
            tystr_pass::mk_pass(),
            // Record the full paths to various nodes
            path_pass::mk_pass(),
            // Extract the docs attributes and attach them to doc nodes
            attr_pass::mk_pass(),
            // Perform various text escaping
            escape_pass::mk_pass(),
            // Remove things marked doc(hidden)
            prune_hidden_pass::mk_pass(),
            // Remove things that are private
            // XXX enable this after 'export' is removed in favor of 'pub'
            // prune_private_pass::mk_pass(),
            // Extract brief documentation from the full descriptions
            desc_to_brief_pass::mk_pass(),
            // Massage the text to remove extra indentation
            unindent_pass::mk_pass(),
            // Split text into multiple sections according to headers
            sectionalize_pass::mk_pass(),
            // Trim extra spaces from text
            trim_pass::mk_pass(),
            // Sort items by name
            sort_item_name_pass::mk_pass(),
            // Sort items again by kind
            sort_item_type_pass::mk_pass(),
            // Create indexes appropriate for markdown
            markdown_index_pass::mk_pass(config),
            // Break the document into pages if required by the
            // output format
            page_pass::mk_pass(config.output_style),
            // Render
            markdown_pass::mk_pass(
                markdown_writer::make_writer_factory(config)
            )
        ]);
    }
}

fn time<T>(what: ~str, f: fn() -> T) -> T {
    let start = std::time::precise_time_s();
    let rv = f();
    let end = std::time::precise_time_s();
    info!("time: %3.3f s    %s", end - start, what);
    move rv
}