Skip to content

Commit 6d2f7e7

Browse files
committed
---
yaml --- r: 2914 b: refs/heads/master c: 3a6b557 h: refs/heads/master v: v3
1 parent 97ff960 commit 6d2f7e7

28 files changed

+789
-365
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 1377e9b341a03915c48a564fb30e70022d04c78f
2+
refs/heads/master: 3a6b5576acbcd0ee2ae3e28847d0b41e2b82ed32

trunk/mk/pp.mk

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
2+
PP_INPUTS := $(wildcard $(addprefix $(S)src/lib/,*.rs */*.rs)) \
3+
$(wildcard $(addprefix $(S)src/comp/,*.rs */*.rs */*/*.rs))
4+
15
reformat: $(SREQ1)
26
@$(call E, reformat [stage1]: $@)
3-
for i in $(wildcard $(addprefix $(S)src/comp/, \
4-
*.rs */*.rs */*/*.rs)); \
7+
for i in $(PP_INPUTS); \
58
do $(call CFG_RUN_TARG,stage1, stage1/rustc$(X)) \
69
--pretty $$i >$$i.tmp && mv $$i.tmp $$i; \
710
done

trunk/src/comp/driver/rustc.rs

Lines changed: 63 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,17 @@ import std::getopts;
2929
import std::getopts::optopt;
3030
import std::getopts::optmulti;
3131
import std::getopts::optflag;
32+
import std::getopts::optflagopt;
3233
import std::getopts::opt_present;
3334

3435
import back::link::output_type;
3536

37+
tag pp_mode {
38+
ppm_normal;
39+
ppm_typed;
40+
ppm_identified;
41+
}
42+
3643
fn default_environment(session::session sess,
3744
str argv0,
3845
str input) -> eval::env {
@@ -112,19 +119,21 @@ fn compile_input(session::session sess,
112119
}
113120

114121
fn pretty_print_input(session::session sess, eval::env env, str input,
115-
bool typed) {
122+
pp_mode ppm) {
116123
auto def = tup(ast::local_crate, 0);
117124
auto p = front::parser::new_parser(sess, env, def, input, 0u, 0u);
118125
auto crate = front::parser::parse_crate_from_source_file(p);
119126

120127
auto mode;
121-
if (typed) {
122-
auto def_map = resolve::resolve_crate(sess, crate);
123-
auto ty_cx = ty::mk_ctxt(sess, def_map);
124-
typeck::check_crate(ty_cx, crate);
125-
mode = pprust::mo_typed(ty_cx);
126-
} else {
127-
mode = pprust::mo_untyped;
128+
alt (ppm) {
129+
case (ppm_typed) {
130+
auto def_map = resolve::resolve_crate(sess, crate);
131+
auto ty_cx = ty::mk_ctxt(sess, def_map);
132+
typeck::check_crate(ty_cx, crate);
133+
mode = pprust::mo_typed(ty_cx);
134+
}
135+
case (ppm_normal) { mode = pprust::mo_untyped; }
136+
case (ppm_identified) { mode = pprust::mo_identified; }
128137
}
129138

130139
pprust::print_file(sess, crate.node.module, input, std::io::stdout(),
@@ -150,8 +159,7 @@ options:
150159
-o <filename> write output to <filename>
151160
--glue generate glue.bc file
152161
--shared compile a shared-library crate
153-
--pretty pretty-print the input instead of compiling
154-
--typed-pretty pretty-print the input with types instead of compiling
162+
--pretty [type] pretty-print the input instead of compiling
155163
--ls list the symbols defined by a crate file
156164
-L <path> add a directory to the library search path
157165
--noverify suppress LLVM verification step (slight speedup)
@@ -304,12 +312,21 @@ fn build_session(@session::options sopts) -> session::session {
304312
ret sess;
305313
}
306314

315+
fn parse_pretty(session::session sess, &str name) -> pp_mode {
316+
if (str::eq(name, "normal")) { ret ppm_normal; }
317+
else if (str::eq(name, "typed")) { ret ppm_typed; }
318+
else if (str::eq(name, "identified")) { ret ppm_identified; }
319+
320+
sess.err("argument to `pretty` must be one of `normal`, `typed`, or " +
321+
"`identified`");
322+
}
323+
307324
fn main(vec[str] args) {
308325

309326
auto opts = [optflag("h"), optflag("help"),
310327
optflag("v"), optflag("version"),
311328
optflag("glue"), optflag("emit-llvm"),
312-
optflag("pretty"), optflag("typed-pretty"),
329+
optflagopt("pretty"),
313330
optflag("ls"), optflag("parse-only"),
314331
optflag("O"), optopt("OptLevel"),
315332
optflag("shared"), optmulti("L"),
@@ -365,42 +382,50 @@ fn main(vec[str] args) {
365382
auto ifile = match.free.(0);
366383
let str saved_out_filename = "";
367384
auto env = default_environment(sess, binary, ifile);
368-
auto pretty = opt_present(match, "pretty");
369-
auto typed_pretty = opt_present(match, "typed-pretty");
385+
auto pretty = option::map[str,pp_mode](bind parse_pretty(sess, _),
386+
getopts::opt_default(match, "pretty", "normal"));
370387
auto ls = opt_present(match, "ls");
371-
if (pretty || typed_pretty) {
372-
pretty_print_input(sess, env, ifile, typed_pretty);
373-
ret;
374-
} else if (ls) {
388+
389+
alt (pretty) {
390+
case (some[pp_mode](?ppm)) {
391+
pretty_print_input(sess, env, ifile, ppm);
392+
ret;
393+
}
394+
case (none[pp_mode]) { /* continue */ }
395+
}
396+
397+
if (ls) {
375398
front::creader::list_file_metadata(ifile, std::io::stdout());
376399
ret;
377-
} else {
378-
alt (output_file) {
379-
case (none) {
380-
let vec[str] parts = str::split(ifile, '.' as u8);
381-
vec::pop[str](parts);
382-
saved_out_filename = parts.(0);
383-
alt (sopts.output_type) {
384-
case (link::output_type_none) { parts += ["pp"]; }
385-
case (link::output_type_bitcode) { parts += ["bc"]; }
386-
case (link::output_type_assembly) { parts += ["s"]; }
387-
388-
// Object and exe output both use the '.o' extension here
389-
case (link::output_type_object) { parts += ["o"]; }
390-
case (link::output_type_exe) { parts += ["o"]; }
391-
}
392-
auto ofile = str::connect(parts, ".");
393-
compile_input(sess, env, ifile, ofile);
394-
}
395-
case (some(?ofile)) {
396-
saved_out_filename = ofile;
397-
compile_input(sess, env, ifile, ofile);
400+
}
401+
402+
alt (output_file) {
403+
case (none) {
404+
let vec[str] parts = str::split(ifile, '.' as u8);
405+
vec::pop[str](parts);
406+
saved_out_filename = parts.(0);
407+
alt (sopts.output_type) {
408+
case (link::output_type_none) { parts += ["pp"]; }
409+
case (link::output_type_bitcode) { parts += ["bc"]; }
410+
case (link::output_type_assembly) { parts += ["s"]; }
411+
412+
// Object and exe output both use the '.o' extension here
413+
case (link::output_type_object) { parts += ["o"]; }
414+
case (link::output_type_exe) { parts += ["o"]; }
398415
}
416+
auto ofile = str::connect(parts, ".");
417+
compile_input(sess, env, ifile, ofile);
418+
}
419+
case (some(?ofile)) {
420+
saved_out_filename = ofile;
421+
compile_input(sess, env, ifile, ofile);
399422
}
400423
}
401424

402425
// If the user wants an exe generated we need to invoke
403426
// gcc to link the object file with some libs
427+
//
428+
// TODO: Factor this out of main.
404429
if (sopts.output_type == link::output_type_exe) {
405430

406431
//FIXME: Should we make the 'stage3's variable here?

trunk/src/comp/front/ast.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ tag ty_ {
338338
tag constr_arg_ {
339339
carg_base;
340340
carg_ident(ident);
341+
carg_lit(@lit);
341342
}
342343
type constr_arg = spanned[constr_arg_];
343344
type constr_ = rec(path path, vec[@constr_arg] args);
@@ -503,14 +504,6 @@ fn is_constraint_arg(@expr e) -> bool {
503504
}
504505
}
505506

506-
fn eq_ty(&@ty a, &@ty b) -> bool {
507-
ret std::box::ptr_eq(a,b);
508-
}
509-
510-
fn hash_ty(&@ty t) -> uint {
511-
ret t.span.lo << 16u + t.span.hi;
512-
}
513-
514507
//
515508
// Local Variables:
516509
// mode: rust

0 commit comments

Comments
 (0)