Skip to content

Commit 6fd6fde

Browse files
committed
Move everything syntax-related to syntax/, break deps on rest of compiler
src/comp/syntax is currently just a sub-module of rustc, but it will, in the near future, be its own crate. This includes: - The AST data structure - The parser - The pretty-printer - Visit, walk, and fold - The syntax extension system - Some utility stuff that should be in the stdlib* *) Stdlib extensions currently require a snapshot before they can be used, and the win build is very broken right now. This is temporary and will be cleaned up when one of those problems goes away. A lot of code was moved by this patch, mostly towards a more organized layout. Some package paths did get longer, and I guess the new layout will take some getting used to. Sorry about that! Please try not to re-introduce any dependencies in syntax/ on any of the other src/comp/ subdirs.
1 parent c59ebf0 commit 6fd6fde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1254
-1203
lines changed

src/comp/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import option::none;
1313
import std::sha1::sha1;
1414
import std::sort;
1515
import trans::crate_ctxt;
16-
import front::ast;
16+
import syntax::ast;
1717
import lib::llvm::llvm::ModuleRef;
1818
import lib::llvm::llvm::ValueRef;
1919
import lib::llvm::mk_pass_manager;
@@ -436,7 +436,7 @@ fn mangle_exported_name(&@crate_ctxt ccx, &vec[str] path, &ty::t t) -> str {
436436

437437
fn mangle_internal_name_by_type_only(&@crate_ctxt ccx, &ty::t t, &str name) ->
438438
str {
439-
auto s = pretty::ppaux::ty_to_short_str(ccx.tcx, t);
439+
auto s = util::ppaux::ty_to_short_str(ccx.tcx, t);
440440
auto hash = get_symbol_hash(ccx, t);
441441
ret mangle([name, s, hash]);
442442
}

src/comp/back/x86.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import lib::llvm::llvm::ModuleRef;
44
import std::str;
55
import std::vec;
66
import std::os::target_os;
7-
import util::common::istr;
7+
import syntax::_std::istr;
88

99
fn get_module_asm() -> str { ret ""; }
1010

src/comp/driver/rustc.rs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
// -*- rust -*-
44
import metadata::creader;
5-
import front::parser;
6-
import front::token;
7-
import front::eval;
8-
import front::ast;
5+
import syntax::parse::parser;
6+
import syntax::parse::token;
7+
import syntax::ast;
8+
import syntax::codemap;
99
import front::attr;
1010
import middle::trans;
1111
import middle::resolve;
1212
import middle::ty;
1313
import middle::typeck;
1414
import middle::tstate::ck;
15-
import pretty::pp;
16-
import pretty::pprust;
17-
import pretty::ppaux;
15+
import syntax::print::pp;
16+
import syntax::print::pprust;
17+
import util::ppaux;
1818
import back::link;
1919
import lib::llvm;
2020
import util::common;
@@ -76,12 +76,14 @@ fn parse_cfgspecs(&vec[str] cfgspecs) -> ast::crate_cfg {
7676
ret vec::map(to_meta_word, cfgspecs);
7777
}
7878

79-
fn parse_input(session::session sess, parser::parser p, str input) ->
80-
@ast::crate {
79+
fn parse_input(session::session sess, &ast::crate_cfg cfg, str input)
80+
-> @ast::crate {
8181
ret if (str::ends_with(input, ".rc")) {
82-
parser::parse_crate_from_crate_file(p)
82+
parser::parse_crate_from_crate_file
83+
(input, cfg, sess.get_codemap())
8384
} else if (str::ends_with(input, ".rs")) {
84-
parser::parse_crate_from_source_file(p)
85+
parser::parse_crate_from_source_file
86+
(input, cfg, sess.get_codemap())
8587
} else { sess.fatal("unknown input file type: " + input); fail };
8688
}
8789

@@ -99,9 +101,8 @@ fn time[T](bool do_it, str what, fn() -> T thunk) -> T {
99101
fn compile_input(session::session sess, ast::crate_cfg cfg, str input,
100102
str output) {
101103
auto time_passes = sess.get_opts().time_passes;
102-
auto p = parser::new_parser(sess, cfg, input, 0u, 0);
103104
auto crate =
104-
time(time_passes, "parsing", bind parse_input(sess, p, input));
105+
time(time_passes, "parsing", bind parse_input(sess, cfg, input));
105106
if (sess.get_opts().output_type == link::output_type_none) { ret; }
106107
crate = time(time_passes, "configuration",
107108
bind front::config::strip_unconfigured_items(crate));
@@ -129,17 +130,17 @@ fn compile_input(session::session sess, ast::crate_cfg cfg, str input,
129130

130131
fn pretty_print_input(session::session sess, ast::crate_cfg cfg,
131132
str input, pp_mode ppm) {
132-
fn ann_paren_for_expr(&ppaux::ann_node node) {
133+
fn ann_paren_for_expr(&pprust::ann_node node) {
133134
alt (node) {
134-
case (ppaux::node_expr(?s, ?expr)) {
135+
case (pprust::node_expr(?s, ?expr)) {
135136
pprust::popen(s);
136137
}
137138
case (_) {}
138139
}
139140
}
140-
fn ann_typed_post(&ty::ctxt tcx, &ppaux::ann_node node) {
141+
fn ann_typed_post(&ty::ctxt tcx, &pprust::ann_node node) {
141142
alt (node) {
142-
case (ppaux::node_expr(?s, ?expr)) {
143+
case (pprust::node_expr(?s, ?expr)) {
143144
pp::space(s.s);
144145
pp::word(s.s, "as");
145146
pp::space(s.s);
@@ -149,18 +150,18 @@ fn pretty_print_input(session::session sess, ast::crate_cfg cfg,
149150
case (_) {}
150151
}
151152
}
152-
fn ann_identified_post(&ppaux::ann_node node) {
153+
fn ann_identified_post(&pprust::ann_node node) {
153154
alt (node) {
154-
case (ppaux::node_item(?s, ?item)) {
155+
case (pprust::node_item(?s, ?item)) {
155156
pp::space(s.s);
156157
pprust::synth_comment(s, int::to_str(item.id, 10u));
157158
}
158-
case (ppaux::node_block(?s, ?blk)) {
159+
case (pprust::node_block(?s, ?blk)) {
159160
pp::space(s.s);
160161
pprust::synth_comment(s, "block " +
161162
int::to_str(blk.node.id, 10u));
162163
}
163-
case (ppaux::node_expr(?s, ?expr)) {
164+
case (pprust::node_expr(?s, ?expr)) {
164165
pp::space(s.s);
165166
pprust::synth_comment(s, int::to_str(expr.id, 10u));
166167
pprust::pclose(s);
@@ -169,8 +170,7 @@ fn pretty_print_input(session::session sess, ast::crate_cfg cfg,
169170
}
170171
}
171172

172-
auto p = front::parser::new_parser(sess, cfg, input, 0u, 0);
173-
auto crate = parse_input(sess, p, input);
173+
auto crate = parse_input(sess, cfg, input);
174174
auto ann;
175175
alt (ppm) {
176176
case (ppm_typed) {
@@ -186,10 +186,11 @@ fn pretty_print_input(session::session sess, ast::crate_cfg cfg,
186186
post=ann_identified_post);
187187
}
188188
case (ppm_normal) {
189-
ann = ppaux::no_ann();
189+
ann = pprust::no_ann();
190190
}
191191
}
192-
pprust::print_crate(sess, crate, input, std::io::stdout(), ann);
192+
pprust::print_crate(sess.get_codemap(), crate, input,
193+
std::io::stdout(), ann);
193194
}
194195

195196
fn version(str argv0) {
@@ -268,9 +269,9 @@ fn build_target_config() -> @session::config {
268269
let @session::config target_cfg =
269270
@rec(os=get_os(triple),
270271
arch=get_arch(triple),
271-
int_type=common::ty_i32,
272-
uint_type=common::ty_u32,
273-
float_type=common::ty_f64);
272+
int_type=ast::ty_i32,
273+
uint_type=ast::ty_u32,
274+
float_type=ast::ty_f64);
274275
ret target_cfg;
275276
}
276277

@@ -342,11 +343,11 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
342343

343344
fn build_session(@session::options sopts) -> session::session {
344345
auto target_cfg = build_target_config();
345-
auto crate_cache = common::new_int_hash[session::crate_metadata]();
346+
auto crate_cache = syntax::_std::new_int_hash[session::crate_metadata]();
346347
auto target_crate_num = 0;
347348
auto sess =
348349
session::session(target_crate_num, target_cfg, sopts, crate_cache, [],
349-
[], [], front::codemap::new_codemap(), 0u);
350+
[], [], codemap::new_codemap(), 0u);
350351
ret sess;
351352
}
352353

src/comp/driver/session.rs

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11

2-
import front::ast;
3-
import front::codemap;
4-
import util::common::span;
5-
import util::common::ty_mach;
2+
import syntax::ast;
3+
import syntax::codemap;
4+
import codemap::span;
5+
import syntax::ast::ty_mach;
66
import std::uint;
7-
import std::term;
87
import std::io;
98
import std::map;
109
import std::option;
@@ -42,30 +41,6 @@ type options =
4241

4342
type crate_metadata = rec(str name, vec[u8] data);
4443

45-
fn span_to_str(span sp, codemap::codemap cm) -> str {
46-
auto lo = codemap::lookup_pos(cm, sp.lo);
47-
auto hi = codemap::lookup_pos(cm, sp.hi);
48-
ret #fmt("%s:%u:%u:%u:%u", lo.filename, lo.line, lo.col, hi.line, hi.col);
49-
}
50-
51-
fn emit_diagnostic(option::t[span] sp, str msg, str kind, u8 color,
52-
codemap::codemap cm) {
53-
auto ss = "<input>:0:0:0:0";
54-
alt (sp) {
55-
case (some(?ssp)) { ss = span_to_str(ssp, cm); }
56-
case (none) { }
57-
}
58-
io::stdout().write_str(ss + ": ");
59-
if (term::color_supported()) {
60-
term::fg(io::stdout().get_buf_writer(), color);
61-
}
62-
io::stdout().write_str(#fmt("%s:", kind));
63-
if (term::color_supported()) {
64-
term::reset(io::stdout().get_buf_writer());
65-
}
66-
io::stdout().write_str(#fmt(" %s\n", msg));
67-
}
68-
6944
obj session(ast::crate_num cnum,
7045
@config targ_cfg,
7146
@options opts,
@@ -80,20 +55,19 @@ obj session(ast::crate_num cnum,
8055
fn get_targ_crate_num() -> ast::crate_num { ret cnum; }
8156
fn span_fatal(span sp, str msg) -> ! {
8257
// FIXME: Use constants, but rustboot doesn't know how to export them.
83-
84-
emit_diagnostic(some(sp), msg, "error", 9u8, cm);
58+
codemap::emit_error(some(sp), msg, cm);
8559
fail;
8660
}
8761
fn fatal(str msg) -> ! {
88-
emit_diagnostic(none[span], msg, "error", 9u8, cm);
62+
codemap::emit_error(none, msg, cm);
8963
fail;
9064
}
9165
fn span_err(span sp, str msg) {
92-
emit_diagnostic(some(sp), msg, "error", 9u8, cm);
66+
codemap::emit_error(some(sp), msg, cm);
9367
err_count += 1u;
9468
}
9569
fn err(str msg) {
96-
emit_diagnostic(none, msg, "error", 9u8, cm);
70+
codemap::emit_error(none, msg, cm);
9771
err_count += 1u;
9872
}
9973
fn abort_if_errors() {
@@ -103,19 +77,17 @@ obj session(ast::crate_num cnum,
10377
}
10478
fn span_warn(span sp, str msg) {
10579
// FIXME: Use constants, but rustboot doesn't know how to export them.
106-
107-
emit_diagnostic(some(sp), msg, "warning", 11u8, cm);
80+
codemap::emit_warning(some(sp), msg, cm);
10881
}
10982
fn warn(str msg) {
110-
emit_diagnostic(none[span], msg, "warning", 11u8, cm);
83+
codemap::emit_warning(none, msg, cm);
11184
}
11285
fn span_note(span sp, str msg) {
11386
// FIXME: Use constants, but rustboot doesn't know how to export them.
114-
115-
emit_diagnostic(some(sp), msg, "note", 10u8, cm);
87+
codemap::emit_note(some(sp), msg, cm);
11688
}
11789
fn note(str msg) {
118-
emit_diagnostic(none, msg, "note", 10u8, cm);
90+
codemap::emit_note(none, msg, cm);
11991
}
12092
fn span_bug(span sp, str msg) -> ! {
12193
self.span_fatal(sp, #fmt("internal compiler error %s", msg));
@@ -172,7 +144,9 @@ obj session(ast::crate_num cnum,
172144
fn lookup_pos(uint pos) -> codemap::loc {
173145
ret codemap::lookup_pos(cm, pos);
174146
}
175-
fn span_str(span sp) -> str { ret span_to_str(sp, self.get_codemap()); }
147+
fn span_str(span sp) -> str {
148+
ret codemap::span_to_str(sp, self.get_codemap());
149+
}
176150
}
177151
// Local Variables:
178152
// fill-column: 78;

src/comp/front/attr.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import std::vec;
44
import std::option;
5-
import front::ast;
5+
import syntax::ast;
66
import util::common;
77

88
export attr_metas;
@@ -105,9 +105,11 @@ fn eq(@ast::meta_item a, @ast::meta_item b) -> bool {
105105
}
106106

107107
fn contains(&vec[@ast::meta_item] haystack, @ast::meta_item needle) -> bool {
108-
log #fmt("looking for %s", pretty::pprust::meta_item_to_str(*needle));
108+
log #fmt("looking for %s",
109+
syntax::print::pprust::meta_item_to_str(*needle));
109110
for (@ast::meta_item item in haystack) {
110-
log #fmt("looking in %s", pretty::pprust::meta_item_to_str(*item));
111+
log #fmt("looking in %s",
112+
syntax::print::pprust::meta_item_to_str(*item));
111113
if (eq(item, needle)) {
112114
log "found it!";
113115
ret true;
@@ -166,7 +168,7 @@ fn remove_meta_items_by_name(&vec[@ast::meta_item] items,
166168
ret vec::filter_map(filter, items);
167169
}
168170

169-
fn span[T](&T item) -> common::spanned[T] {
171+
fn span[T](&T item) -> ast::spanned[T] {
170172
ret rec(node=item, span=rec(lo=0u, hi=0u));
171173
}
172174

src/comp/front/codemap.rs

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/comp/front/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import std::option;
22
import std::vec;
3-
import ast;
4-
import fold;
3+
import syntax::ast;
4+
import syntax::fold;
55
import attr;
66

77
export strip_unconfigured_items;

0 commit comments

Comments
 (0)