Skip to content

Commit d05b04c

Browse files
committed
---
yaml --- r: 2854 b: refs/heads/master c: cf57553 h: refs/heads/master v: v3
1 parent a5023be commit d05b04c

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
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: b48cab962a08e370af523d082ef8946dfcfd3059
2+
refs/heads/master: cf57553679b59bc90caa3632762b8beda1896f9d

trunk/src/comp/pretty/pprust.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import std::option;
55
import driver::session::session;
66
import front::ast;
77
import front::lexer;
8+
import front::codemap;
9+
import front::codemap::codemap;
810
import middle::ty;
911
import util::common;
1012
import pp;
@@ -34,6 +36,7 @@ tag mode {
3436
}
3537

3638
type ps = @rec(pp::printer s,
39+
option::t[codemap] cm,
3740
option::t[vec[lexer::cmnt]] comments,
3841
mutable uint cur_cmnt,
3942
mode mode);
@@ -42,6 +45,7 @@ fn print_file(session sess, ast::_mod _mod, str filename, io::writer out,
4245
mode mode) {
4346
auto cmnts = lexer::gather_comments(sess, filename);
4447
auto s = @rec(s=pp::mk_printer(out, default_columns),
48+
cm=option::some[codemap](sess.get_codemap()),
4549
comments=option::some[vec[lexer::cmnt]](cmnts),
4650
mutable cur_cmnt=0u,
4751
mode=mode);
@@ -52,6 +56,7 @@ fn print_file(session sess, ast::_mod _mod, str filename, io::writer out,
5256
fn ty_to_str(&@ast::ty ty) -> str {
5357
auto writer = io::string_writer();
5458
auto s = @rec(s=pp::mk_printer(writer.get_writer(), default_columns),
59+
cm=option::none[codemap],
5560
comments=option::none[vec[lexer::cmnt]],
5661
mutable cur_cmnt=0u,
5762
mode=mo_untyped);
@@ -63,6 +68,7 @@ fn ty_to_str(&@ast::ty ty) -> str {
6368
fn block_to_str(&ast::block blk) -> str {
6469
auto writer = io::string_writer();
6570
auto s = @rec(s=pp::mk_printer(writer.get_writer(), default_columns),
71+
cm=option::none[codemap],
6672
comments=option::none[vec[lexer::cmnt]],
6773
mutable cur_cmnt=0u,
6874
mode=mo_untyped);
@@ -76,6 +82,7 @@ fn block_to_str(&ast::block blk) -> str {
7682
fn pat_to_str(&@ast::pat p) -> str {
7783
auto writer = io::string_writer();
7884
auto s = @rec(s=pp::mk_printer(writer.get_writer(), default_columns),
85+
cm=option::none[codemap],
7986
comments=option::none[vec[lexer::cmnt]],
8087
mutable cur_cmnt=0u,
8188
mode=mo_untyped);
@@ -1099,9 +1106,22 @@ fn maybe_print_comment(ps s, uint pos) {
10991106
}
11001107

11011108
fn maybe_print_line_comment(ps s, common::span span) -> bool {
1109+
auto cm;
1110+
alt (s.cm) {
1111+
case (option::some[codemap](?ccm)) {
1112+
cm = ccm;
1113+
}
1114+
case (_) {
1115+
ret false;
1116+
}
1117+
}
11021118
alt (next_comment(s)) {
11031119
case (option::some[lexer::cmnt](?cmnt)) {
1104-
if (span.hi + 4u >= cmnt.pos) {
1120+
if (cmnt.style != lexer::trailing) { ret false; }
1121+
1122+
auto span_line = codemap::lookup_pos(cm, span.hi);
1123+
auto comment_line = codemap::lookup_pos(cm, cmnt.pos);
1124+
if (span_line.line == comment_line.line) {
11051125
word(s.s, " ");
11061126
print_comment(s, cmnt);
11071127
s.cur_cmnt += 1u;
@@ -1128,12 +1148,11 @@ fn print_remaining_comments(ps s) {
11281148
fn print_comment(ps s, lexer::cmnt cmnt) {
11291149
alt (cmnt.style) {
11301150
case (lexer::isolated) {
1131-
cbox(s.s, 0u);
1151+
zerobreak(s.s);
11321152
for (str line in cmnt.lines) {
1133-
zerobreak(s.s);
11341153
word_and_eol(s.s, line);
1154+
zerobreak(s.s);
11351155
}
1136-
end(s.s);
11371156
zerobreak(s.s);
11381157
}
11391158
case (lexer::trailing) {

trunk/src/comp/util/common.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import std::option::some;
88
import front::ast;
99
import front::ast::ty;
1010
import front::ast::pat;
11+
import front::codemap::codemap;
1112
import middle::walk;
1213

1314
import std::io::stdout;
@@ -129,6 +130,7 @@ fn expr_to_str(&@ast::expr e) -> str {
129130
let str_writer s = string_writer();
130131
auto out_ = mk_printer(s.get_writer(), 80u);
131132
auto out = @rec(s=out_,
133+
cm=none[codemap],
132134
comments=none[vec[front::lexer::cmnt]],
133135
mutable cur_cmnt=0u,
134136
mode=mo_untyped);
@@ -140,6 +142,7 @@ fn ty_to_str(&ty t) -> str {
140142
let str_writer s = string_writer();
141143
auto out_ = mk_printer(s.get_writer(), 80u);
142144
auto out = @rec(s=out_,
145+
cm=none[codemap],
143146
comments=none[vec[front::lexer::cmnt]],
144147
mutable cur_cmnt=0u,
145148
mode=mo_untyped);
@@ -167,6 +170,7 @@ fn block_to_str(&ast::block b) -> str {
167170
let str_writer s = string_writer();
168171
auto out_ = mk_printer(s.get_writer(), 80u);
169172
auto out = @rec(s=out_,
173+
cm=none[codemap],
170174
comments=none[vec[front::lexer::cmnt]],
171175
mutable cur_cmnt=0u,
172176
mode=mo_untyped);
@@ -179,6 +183,7 @@ fn item_to_str(&@ast::item i) -> str {
179183
let str_writer s = string_writer();
180184
auto out_ = mk_printer(s.get_writer(), 80u);
181185
auto out = @rec(s=out_,
186+
cm=none[codemap],
182187
comments=none[vec[front::lexer::cmnt]],
183188
mutable cur_cmnt=0u,
184189
mode=mo_untyped);
@@ -202,6 +207,7 @@ fn fun_to_str(&ast::_fn f, str name, vec[ast::ty_param] params) -> str {
202207
let str_writer s = string_writer();
203208
auto out_ = mk_printer(s.get_writer(), 80u);
204209
auto out = @rec(s=out_,
210+
cm=none[codemap],
205211
comments=none[vec[front::lexer::cmnt]],
206212
mutable cur_cmnt=0u,
207213
mode=mo_untyped);
@@ -222,6 +228,7 @@ fn stmt_to_str(&ast::stmt st) -> str {
222228
let str_writer s = string_writer();
223229
auto out_ = mk_printer(s.get_writer(), 80u);
224230
auto out = @rec(s=out_,
231+
cm=none[codemap],
225232
comments=none[vec[front::lexer::cmnt]],
226233
mutable cur_cmnt=0u,
227234
mode=mo_untyped);

0 commit comments

Comments
 (0)