Skip to content

Commit 04044d9

Browse files
committed
---
yaml --- r: 4110 b: refs/heads/master c: 552bff8 h: refs/heads/master v: v3
1 parent 554565a commit 04044d9

File tree

5 files changed

+38
-27
lines changed

5 files changed

+38
-27
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: 5749a2deac857e56b29ffb56b62dd383c3489eb3
2+
refs/heads/master: 552bff8a2155e9e404a3cd279a26a374188d65f7

trunk/src/comp/driver/rustc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ fn pretty_print_input(session::session sess, ast::crate_cfg cfg,
217217
ann = pprust::no_ann();
218218
}
219219
}
220-
pprust::print_crate(sess.get_codemap(), crate, input, ioivec::stdout(),
221-
ann);
220+
pprust::print_crate(sess.get_codemap(), crate, input,
221+
ioivec::file_reader(input),
222+
ioivec::stdout(), ann);
222223
}
223224

224225
fn version(str argv0) {

trunk/src/comp/syntax/parse/lexer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,9 @@ fn is_lit(&token::token t) -> bool {
736736

737737
type lit = rec(str lit, uint pos);
738738

739-
fn gather_comments_and_literals(&codemap::codemap cm, str path)
739+
fn gather_comments_and_literals(&codemap::codemap cm, str path,
740+
ioivec::reader srdr)
740741
-> rec(cmnt[] cmnts, lit[] lits) {
741-
auto srdr = ioivec::file_reader(path);
742742
auto src = str::unsafe_from_bytes_ivec(srdr.read_whole_stream());
743743
auto itr = @interner::mk[str](str::hash, str::eq);
744744
auto rdr = new_reader(cm, src, codemap::new_filemap(path, 0u, 0u), itr);

trunk/src/comp/syntax/print/pprust.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ const uint alt_indent_unit = 2u;
7373

7474
const uint default_columns = 78u;
7575

76-
fn print_crate(&codemap cm, @ast::crate crate, str filename,
76+
// Requires you to pass an input filename and reader so that
77+
// it can scan the input text for comments and literals to
78+
// copy forward.
79+
fn print_crate(&codemap cm, @ast::crate crate,
80+
str filename, ioivec::reader in,
7781
ioivec::writer out, &pp_ann ann) {
7882
let pp::breaks[] boxes = ~[];
79-
auto r = lexer::gather_comments_and_literals(cm, filename);
83+
auto r = lexer::gather_comments_and_literals(cm, filename, in);
8084
auto s =
8185
@rec(s=pp::mk_printer(out, default_columns),
8286
cm=some(cm),

trunk/src/fuzzer/fuzzer.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ fn read_whole_file(&str filename) -> str {
5050
}
5151

5252
fn write_file(&str filename, &str content) {
53-
ioivec::file_writer(filename, ~[ioivec::create]).write_str(content);
53+
ioivec::file_writer(filename, ~[ioivec::create,
54+
ioivec::truncate]).write_str(content);
5455
}
5556

5657
fn file_contains(&str filename, &str needle) -> bool {
@@ -149,6 +150,7 @@ fn devnull() -> ioivec::writer { std::ioivec::string_writer().get_writer() }
149150

150151
fn as_str(fn (ioivec::writer) f) -> str { auto w = std::ioivec::string_writer(); f(w.get_writer()); w.get_str() }
151152

153+
/*
152154
fn pp_variants(&ast::crate crate, &codemap::codemap cmap, &str filename) {
153155
auto exprs = steal_exprs(crate);
154156
auto exprsL = ivec::len(exprs);
@@ -163,26 +165,30 @@ fn pp_variants(&ast::crate crate, &codemap::codemap cmap, &str filename) {
163165
}
164166
}
165167
}
168+
*/
166169

167-
fn check_roundtrip(@ast::crate crate2, &codemap::codemap cmap, &str filename) {
168-
auto str3 = as_str(bind pprust::print_crate(cmap, crate2, filename, _, pprust::no_ann()));
170+
fn check_roundtrip(@ast::crate cr1, &codemap::codemap cm1, &str filename, &str str1) {
171+
auto str2 = as_str(bind pprust::print_crate(cm1, cr1, filename,
172+
ioivec::string_reader(str1), _,
173+
pprust::no_ann()));
169174
if (true
170-
&& !contains(str3, "][]") // https://github.com/graydon/rust/issues/669
171-
&& !contains(str3, "][mutable]") // https://github.com/graydon/rust/issues/669
172-
&& !contains(str3, "][mutable ]") // https://github.com/graydon/rust/issues/669
173-
&& !contains(str3, "self") // crazy rules enforced by parser rather than typechecker?
174-
&& !contains(str3, "spawn") // more precedence issues
175-
&& !contains(str3, "bind") // more precedence issues?
175+
&& !contains(str2, "][]") // https://github.com/graydon/rust/issues/669
176+
&& !contains(str2, "][mutable]") // https://github.com/graydon/rust/issues/669
177+
&& !contains(str2, "][mutable ]") // https://github.com/graydon/rust/issues/669
178+
&& !contains(str2, "self") // crazy rules enforced by parser rather than typechecker?
179+
&& !contains(str2, "spawn") // more precedence issues
180+
&& !contains(str2, "bind") // more precedence issues?
176181
) {
177-
auto cm4 = codemap::new_codemap();
178-
auto crate4 = parser::parse_crate_from_source_str(filename, str3, ~[], cm4);
182+
auto cm2 = codemap::new_codemap();
183+
auto cr2 = parser::parse_crate_from_source_str(filename, str2, ~[], cm2);
179184
// should compare crates at this point, but it's easier to compare strings
180-
auto str5 = as_str(bind pprust::print_crate(cm4, crate4, filename, _, pprust::no_ann()));
185+
auto str3 = as_str(bind pprust::print_crate(cm2, cr2, filename, ioivec::string_reader(str2),
186+
_, pprust::no_ann()));
181187
if (!str::is_ascii(str3)) {
182188
log_err "Non-ASCII in " + filename; // why does non-ASCII work correctly with "rustc --pretty normal" but not here???
183-
} else if (str3 != str5) {
184-
write_file("round-trip-a.rs", str3);
185-
write_file("round-trip-b.rs", str5);
189+
} else if (str2 != str3) {
190+
write_file("round-trip-a.rs", str2);
191+
write_file("round-trip-b.rs", str3);
186192
std::run::run_program("kdiff3", ["round-trip-a.rs", "round-trip-b.rs"]);
187193
fail "Mismatch";
188194
}
@@ -201,14 +207,14 @@ fn main(vec[str] args) {
201207

202208
for (str file in files) {
203209
log_err "=== " + file + " ===";
204-
auto cm = codemap::new_codemap();
205-
auto src = read_whole_file(file);
206-
auto crate = parser::parse_crate_from_source_str(file, src, ~[], cm);
207-
if (!contains(src, "#macro") // https://github.com/graydon/rust/issues/671
210+
auto cm1 = codemap::new_codemap();
211+
auto str1 = read_whole_file(file);
212+
auto cr1 = parser::parse_crate_from_source_str(file, str1, ~[], cm1);
213+
if (!contains(str1, "#macro") // https://github.com/graydon/rust/issues/671
208214
&& !str::ends_with(file, "block-expr-precedence.rs") // https://github.com/graydon/rust/issues/674
209215
&& !str::ends_with(file, "syntax-extension-fmt.rs") // an issue where -2147483648 gains an extra negative sign each time through, which i can't reproduce using "rustc --pretty normal"???
210216
) {
211-
check_roundtrip(crate, cm, file);
217+
check_roundtrip(cr1, cm1, file, str1);
212218
}
213219
//pprust::print_crate(cm, crate, file, devnull(), pprust::no_ann());
214220
// Currently hits https://github.com/graydon/rust/issues/675

0 commit comments

Comments
 (0)