Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
81d20156
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
81d20156
编写于
11月 15, 2012
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change spans to use byte offsets instead of char offsets
上级
8cba337c
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
161 addition
and
89 deletion
+161
-89
src/librustc/middle/trans/debuginfo.rs
src/librustc/middle/trans/debuginfo.rs
+1
-1
src/libsyntax/ast_util.rs
src/libsyntax/ast_util.rs
+4
-4
src/libsyntax/attr.rs
src/libsyntax/attr.rs
+2
-2
src/libsyntax/codemap.rs
src/libsyntax/codemap.rs
+106
-39
src/libsyntax/ext/qquote.rs
src/libsyntax/ext/qquote.rs
+7
-7
src/libsyntax/ext/tt/macro_parser.rs
src/libsyntax/ext/tt/macro_parser.rs
+3
-3
src/libsyntax/parse/attr.rs
src/libsyntax/parse/attr.rs
+2
-2
src/libsyntax/parse/comments.rs
src/libsyntax/parse/comments.rs
+6
-6
src/libsyntax/parse/common.rs
src/libsyntax/parse/common.rs
+1
-1
src/libsyntax/parse/lexer.rs
src/libsyntax/parse/lexer.rs
+13
-8
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+11
-11
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+5
-5
未找到文件。
src/librustc/middle/trans/debuginfo.rs
浏览文件 @
81d20156
...
...
@@ -112,7 +112,7 @@ fn update_cache(cache: metadata_cache, mdtag: int, val: debug_metadata) {
type
subprogram_md
=
{
id
:
ast
::
node_id
};
type
local_var_md
=
{
id
:
ast
::
node_id
};
type
tydesc_md
=
{
hash
:
uint
};
type
block_md
=
{
start
:
codemap
::
Loc
<
CharPos
>
,
end
:
codemap
::
Loc
<
CharPos
>
};
type
block_md
=
{
start
:
codemap
::
Loc
,
end
:
codemap
::
Loc
};
type
argument_md
=
{
id
:
ast
::
node_id
};
type
retval_md
=
{
id
:
ast
::
node_id
};
...
...
src/libsyntax/ast_util.rs
浏览文件 @
81d20156
use
codemap
::{
span
,
Char
Pos
};
use
codemap
::{
span
,
Byte
Pos
};
use
ast
::
*
;
pure
fn
spanned
<
T
>
(
+
lo
:
CharPos
,
+
hi
:
Char
Pos
,
+
t
:
T
)
->
spanned
<
T
>
{
pure
fn
spanned
<
T
>
(
+
lo
:
BytePos
,
+
hi
:
Byte
Pos
,
+
t
:
T
)
->
spanned
<
T
>
{
respan
(
mk_sp
(
lo
,
hi
),
move
t
)
}
...
...
@@ -14,12 +14,12 @@
}
/* assuming that we're not in macro expansion */
pure
fn
mk_sp
(
+
lo
:
CharPos
,
+
hi
:
Char
Pos
)
->
span
{
pure
fn
mk_sp
(
+
lo
:
BytePos
,
+
hi
:
Byte
Pos
)
->
span
{
span
{
lo
:
lo
,
hi
:
hi
,
expn_info
:
None
}
}
// make this a const, once the compiler supports it
pure
fn
dummy_sp
()
->
span
{
return
mk_sp
(
CharPos
(
0
),
Char
Pos
(
0
));
}
pure
fn
dummy_sp
()
->
span
{
return
mk_sp
(
BytePos
(
0
),
Byte
Pos
(
0
));
}
...
...
src/libsyntax/attr.rs
浏览文件 @
81d20156
...
...
@@ -6,7 +6,7 @@
use
diagnostic
::
span_handler
;
use
ast_util
::{
spanned
,
dummy_spanned
};
use
parse
::
comments
::{
doc_comment_style
,
strip_doc_comment_decoration
};
use
codemap
::
Char
Pos
;
use
codemap
::
Byte
Pos
;
// Constructors
export
mk_name_value_item_str
;
...
...
@@ -76,7 +76,7 @@ fn mk_attr(item: @ast::meta_item) -> ast::attribute {
}
fn
mk_sugared_doc_attr
(
text
:
~
str
,
+
lo
:
CharPos
,
+
hi
:
Char
Pos
)
->
ast
::
attribute
{
+
lo
:
BytePos
,
+
hi
:
Byte
Pos
)
->
ast
::
attribute
{
let
lit
=
spanned
(
lo
,
hi
,
ast
::
lit_str
(
@
text
));
let
attr
=
{
style
:
doc_comment_style
(
text
),
...
...
src/libsyntax/codemap.rs
浏览文件 @
81d20156
...
...
@@ -118,8 +118,8 @@ impl CharPos: to_bytes::IterBytes {
}
pub
struct
span
{
lo
:
Char
Pos
,
hi
:
Char
Pos
,
lo
:
Byte
Pos
,
hi
:
Byte
Pos
,
expn_info
:
Option
<@
ExpnInfo
>
}
...
...
@@ -141,8 +141,10 @@ impl<D: Deserializer> span: Deserializable<D> {
}
}
pub
struct
Loc
<
A
:
Pos
>
{
file
:
@
FileMap
,
line
:
uint
,
col
:
A
// XXX col shouldn't be CharPos because col is not an absolute location in the
// codemap, and BytePos and CharPos always represent absolute positions
pub
struct
Loc
{
file
:
@
FileMap
,
line
:
uint
,
col
:
CharPos
}
/// An absolute offset within the CodeMap (not a relative offset within a
...
...
@@ -178,12 +180,24 @@ pub enum FileSubstr {
pub
FssExternal
({
filename
:
~
str
,
line
:
uint
,
col
:
CharPos
})
}
/// Identifies an offset of a multi-byte character in a FileMap
pub
struct
MultiByteChar
{
/// The absolute offset of the character in the CodeMap
pos
:
BytePos
,
/// The number of bytes, >=2
bytes
:
uint
,
/// The complete number of 'extra' bytes through this character in the
/// FileMap
sum
:
uint
}
pub
struct
FileMap
{
name
:
FileName
,
substr
:
FileSubstr
,
src
:
@~
str
,
start_pos
:
FilePos
,
mut
lines
:
~
[
FilePos
]
mut
lines
:
~
[
FilePos
],
multibyte_chars
:
DVec
<
MultiByteChar
>
}
pub
impl
FileMap
{
...
...
@@ -194,7 +208,8 @@ pub impl FileMap {
return
FileMap
{
name
:
filename
,
substr
:
substr
,
src
:
src
,
start_pos
:
start_pos
,
mut
lines
:
~
[]
mut
lines
:
~
[],
multibyte_chars
:
DVec
()
};
}
...
...
@@ -219,6 +234,21 @@ pub fn get_line(&self, line: int) -> ~str unsafe {
str
::
slice
(
*
self
.src
,
begin
,
end
)
}
pub
fn
record_multibyte_char
(
&
self
,
pos
:
BytePos
,
bytes
:
uint
)
{
assert
bytes
>=
2
&&
bytes
<=
4
;
let
sum
=
if
self
.multibyte_chars
.len
()
>
0
{
self
.multibyte_chars
.last
()
.sum
}
else
{
0
};
let
sum
=
sum
+
bytes
;
let
mbc
=
MultiByteChar
{
pos
:
pos
,
bytes
:
bytes
,
sum
:
sum
};
self
.multibyte_chars
.push
(
mbc
);
}
}
pub
struct
CodeMap
{
...
...
@@ -254,12 +284,11 @@ pub fn mk_substr_filename(&self, sp: span) -> ~str {
pos
.line
,
pos
.col
.to_uint
());
}
pub
fn
lookup_char_pos
(
&
self
,
+
pos
:
CharPos
)
->
Loc
<
CharPos
>
{
pure
fn
lookup
(
pos
:
FilePos
)
->
uint
{
return
pos
.ch
.to_uint
();
}
return
self
.lookup_pos
(
pos
,
lookup
);
pub
fn
lookup_char_pos
(
&
self
,
+
pos
:
BytePos
)
->
Loc
{
return
self
.lookup_pos
(
pos
);
}
pub
fn
lookup_char_pos_adj
(
&
self
,
+
pos
:
Char
Pos
)
pub
fn
lookup_char_pos_adj
(
&
self
,
+
pos
:
Byte
Pos
)
->
{
filename
:
~
str
,
line
:
uint
,
col
:
CharPos
,
file
:
Option
<@
FileMap
>
}
{
let
loc
=
self
.lookup_char_pos
(
pos
);
...
...
@@ -272,7 +301,7 @@ pub fn lookup_char_pos_adj(&self, +pos: CharPos)
}
FssInternal
(
sp
)
=>
{
self
.lookup_char_pos_adj
(
sp
.lo
+
(
pos
-
loc
.file.start_pos.
ch
))
sp
.lo
+
(
pos
-
loc
.file.start_pos.
byte
))
}
FssExternal
(
eloc
)
=>
{
{
filename
:
/* FIXME (#2543) */
copy
eloc
.filename
,
...
...
@@ -284,14 +313,13 @@ pub fn lookup_char_pos_adj(&self, +pos: CharPos)
}
pub
fn
adjust_span
(
&
self
,
sp
:
span
)
->
span
{
pure
fn
lookup
(
pos
:
FilePos
)
->
uint
{
return
pos
.ch
.to_uint
();
}
let
line
=
self
.lookup_line
(
sp
.lo
,
lookup
);
let
line
=
self
.lookup_line
(
sp
.lo
);
match
(
line
.fm.substr
)
{
FssNone
=>
sp
,
FssInternal
(
s
)
=>
{
self
.adjust_span
(
span
{
lo
:
s
.lo
+
(
sp
.lo
-
line
.fm.start_pos.
ch
),
hi
:
s
.lo
+
(
sp
.hi
-
line
.fm.start_pos.
ch
),
lo
:
s
.lo
+
(
sp
.lo
-
line
.fm.start_pos.
byte
),
hi
:
s
.lo
+
(
sp
.hi
-
line
.fm.start_pos.
byte
),
expn_info
:
sp
.expn_info
})
}
...
...
@@ -321,18 +349,6 @@ pub fn span_to_lines(&self, sp: span) -> @FileLines {
return
@
FileLines
{
file
:
lo
.file
,
lines
:
lines
};
}
fn
lookup_byte_offset
(
&
self
,
+
chpos
:
CharPos
)
->
{
fm
:
@
FileMap
,
pos
:
BytePos
}
{
pure
fn
lookup
(
pos
:
FilePos
)
->
uint
{
return
pos
.ch
.to_uint
();
}
let
{
fm
,
line
}
=
self
.lookup_line
(
chpos
,
lookup
);
let
line_offset
=
fm
.lines
[
line
]
.byte
-
fm
.start_pos.byte
;
let
col
=
chpos
-
fm
.lines
[
line
]
.ch
;
let
col_offset
=
str
::
count_bytes
(
*
fm
.src
,
line_offset
.to_uint
(),
col
.to_uint
());
{
fm
:
fm
,
pos
:
line_offset
+
BytePos
(
col_offset
)}
}
pub
fn
span_to_snippet
(
&
self
,
sp
:
span
)
->
~
str
{
let
begin
=
self
.lookup_byte_offset
(
sp
.lo
);
let
end
=
self
.lookup_byte_offset
(
sp
.hi
);
...
...
@@ -351,15 +367,14 @@ pub fn get_filemap(&self, filename: ~str) -> @FileMap {
}
priv
impl
CodeMap
{
fn
lookup_line
<
A
:
Pos
>
(
&
self
,
pos
:
A
,
lookup
:
LookupFn
)
->
{
fm
:
@
FileMap
,
line
:
uint
}
{
fn
lookup_filemap_idx
(
&
self
,
+
pos
:
BytePos
)
->
uint
{
let
len
=
self
.files
.len
();
let
mut
a
=
0u
;
let
mut
b
=
len
;
while
b
-
a
>
1u
{
let
m
=
(
a
+
b
)
/
2u
;
if
lookup
(
self
.files
[
m
]
.start_pos
)
>
pos
.to_uint
()
{
if
self
.files
[
m
]
.start_pos.byte
>
pos
{
b
=
m
;
}
else
{
a
=
m
;
...
...
@@ -369,22 +384,40 @@ fn lookup_line<A: Pos>(&self, pos: A, lookup: LookupFn)
fail
fmt!
(
"position %u does not resolve to a source location"
,
pos
.to_uint
())
}
let
f
=
self
.files
[
a
];
a
=
0u
;
b
=
vec
::
len
(
f
.lines
);
return
a
;
}
fn
lookup_line
(
&
self
,
+
pos
:
BytePos
)
->
{
fm
:
@
FileMap
,
line
:
uint
}
{
let
idx
=
self
.lookup_filemap_idx
(
pos
);
let
f
=
self
.files
[
idx
];
let
mut
a
=
0u
;
let
mut
b
=
vec
::
len
(
f
.lines
);
while
b
-
a
>
1u
{
let
m
=
(
a
+
b
)
/
2u
;
if
lookup
(
f
.lines
[
m
])
>
pos
.to_uint
()
{
b
=
m
;
}
else
{
a
=
m
;
}
if
f
.lines
[
m
]
.byte
>
pos
{
b
=
m
;
}
else
{
a
=
m
;
}
}
return
{
fm
:
f
,
line
:
a
};
}
fn
lookup_pos
<
A
:
Pos
Num
>
(
&
self
,
pos
:
A
,
lookup
:
LookupFn
)
->
Loc
<
A
>
{
let
{
fm
:
f
,
line
:
a
}
=
self
.lookup_line
(
pos
,
lookup
);
fn
lookup_pos
(
&
self
,
+
pos
:
BytePos
)
->
Loc
{
let
{
fm
:
f
,
line
:
a
}
=
self
.lookup_line
(
pos
);
let
line
=
a
+
1u
;
// Line numbers start at 1
let
chpos
=
self
.bytepos_to_local_charpos
(
pos
);
let
linebpos
=
f
.lines
[
a
]
.byte
;
let
linechpos
=
self
.bytepos_to_local_charpos
(
linebpos
);
debug!
(
"codemap: byte pos %? is on the line at byte pos %?"
,
pos
,
linebpos
);
debug!
(
"codemap: char pos %? is on the line at char pos %?"
,
chpos
,
linechpos
);
debug!
(
"codemap: byte is on line: %?"
,
line
);
assert
chpos
>=
linechpos
;
return
Loc
{
file
:
f
,
line
:
a
+
1u
,
col
:
pos
-
from_uint
(
lookup
(
f
.lines
[
a
]))
line
:
line
,
col
:
chpos
-
linechpos
};
}
...
...
@@ -394,6 +427,40 @@ fn span_to_str_no_adj(&self, sp: span) -> ~str {
return
fmt!
(
"%s:%u:%u: %u:%u"
,
lo
.file.name
,
lo
.line
,
lo
.col
.to_uint
(),
hi
.line
,
hi
.col
.to_uint
())
}
fn
lookup_byte_offset
(
&
self
,
+
bpos
:
BytePos
)
->
{
fm
:
@
FileMap
,
pos
:
BytePos
}
{
let
idx
=
self
.lookup_filemap_idx
(
bpos
);
let
fm
=
self
.files
[
idx
];
let
offset
=
bpos
-
fm
.start_pos.byte
;
return
{
fm
:
fm
,
pos
:
offset
};
}
// Converts an absolute BytePos to a CharPos relative to the file it is
// located in
fn
bytepos_to_local_charpos
(
&
self
,
+
bpos
:
BytePos
)
->
CharPos
{
debug!
(
"codemap: converting %? to char pos"
,
bpos
);
let
idx
=
self
.lookup_filemap_idx
(
bpos
);
let
map
=
self
.files
[
idx
];
// The number of extra bytes due to multibyte chars in the FileMap
let
mut
total_extra_bytes
=
0
;
for
map
.multibyte_chars.each
|
mbc
|
{
debug!
(
"codemap: %?-byte char at %?"
,
mbc
.bytes
,
mbc
.pos
);
if
mbc
.pos
<
bpos
{
total_extra_bytes
+=
mbc
.bytes
;
// We should never see a byte position in the middle of a
// character
assert
bpos
==
mbc
.pos
||
bpos
.to_uint
()
>=
mbc
.pos
.to_uint
()
+
mbc
.bytes
;
}
else
{
break
;
}
}
CharPos
(
bpos
.to_uint
()
-
total_extra_bytes
)
}
}
//
...
...
src/libsyntax/ext/qquote.rs
浏览文件 @
81d20156
...
...
@@ -4,7 +4,7 @@
use
parse
::
parser
::{
Parser
,
parse_from_source_str
};
use
dvec
::
DVec
;
use
parse
::
token
::
ident_interner
;
use
codemap
::
CharPos
;
use
codemap
::
{
CharPos
,
BytePos
}
;
use
fold
::
*
;
use
visit
::
*
;
...
...
@@ -16,13 +16,13 @@
use
codemap
::
span
;
struct
gather_item
{
lo
:
Char
Pos
,
hi
:
Char
Pos
,
lo
:
Byte
Pos
,
hi
:
Byte
Pos
,
e
:
@
ast
::
expr
,
constr
:
~
str
}
type
aq_ctxt
=
@
{
lo
:
Char
Pos
,
gather
:
DVec
<
gather_item
>
};
type
aq_ctxt
=
@
{
lo
:
Byte
Pos
,
gather
:
DVec
<
gather_item
>
};
enum
fragment
{
from_expr
(
@
ast
::
expr
),
from_ty
(
@
ast
::
Ty
)
...
...
@@ -115,7 +115,7 @@ fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
fn
get_fold_fn
()
->
~
str
{
~
"fold_pat"
}
}
fn
gather_anti_quotes
<
N
:
qq_helper
>
(
lo
:
Char
Pos
,
node
:
N
)
->
aq_ctxt
fn
gather_anti_quotes
<
N
:
qq_helper
>
(
lo
:
Byte
Pos
,
node
:
N
)
->
aq_ctxt
{
let
v
=
@
{
visit_expr
:
|
node
,
&&
cx
,
v
|
visit_aq
(
node
,
~
"from_expr"
,
cx
,
v
),
visit_ty
:
|
node
,
&&
cx
,
v
|
visit_aq
(
node
,
~
"from_ty"
,
cx
,
v
),
...
...
@@ -227,7 +227,7 @@ fn finish<T: qq_helper>
let
mut
str2
=
~
""
;
enum
state
{
active
,
skip
(
uint
),
blank
};
let
mut
state
=
active
;
let
mut
i
=
Char
Pos
(
0u
);
let
mut
i
=
Byte
Pos
(
0u
);
let
mut
j
=
0u
;
let
g_len
=
cx
.gather
.len
();
for
str
::
chars_each
(
*
str
)
|
ch
|
{
...
...
@@ -244,7 +244,7 @@ fn finish<T: qq_helper>
blank
if
is_space
(
ch
)
=>
str
::
push_char
(
&
mut
str2
,
ch
),
blank
=>
str
::
push_char
(
&
mut
str2
,
' '
)
}
i
+=
Char
Pos
(
1u
);
i
+=
Byte
Pos
(
1u
);
if
(
j
<
g_len
&&
i
==
cx
.gather
[
j
]
.hi
)
{
assert
ch
==
')'
;
state
=
active
;
...
...
src/libsyntax/ext/tt/macro_parser.rs
浏览文件 @
81d20156
...
...
@@ -11,7 +11,7 @@
use
ast
::{
matcher
,
match_tok
,
match_seq
,
match_nonterminal
,
ident
};
use
ast_util
::
mk_sp
;
use
std
::
map
::
HashMap
;
use
codemap
::
Char
Pos
;
use
codemap
::
Byte
Pos
;
/* This is an Earley-like parser, without support for in-grammar nonterminals,
only by calling out to the main rust parser for named nonterminals (which it
...
...
@@ -103,7 +103,7 @@ fn is_some(&&mpu: matcher_pos_up) -> bool {
mut
up
:
matcher_pos_up
,
// mutable for swapping only
matches
:
~
[
DVec
<@
named_match
>
],
match_lo
:
uint
,
match_hi
:
uint
,
sp_lo
:
Char
Pos
,
sp_lo
:
Byte
Pos
,
};
fn
copy_up
(
&&
mpu
:
matcher_pos_up
)
->
matcher_pos
{
...
...
@@ -123,7 +123,7 @@ fn count_names(ms: &[matcher]) -> uint {
}
#[allow(non_implicitly_copyable_typarams)]
fn
initial_matcher_pos
(
ms
:
~
[
matcher
],
sep
:
Option
<
Token
>
,
lo
:
Char
Pos
)
fn
initial_matcher_pos
(
ms
:
~
[
matcher
],
sep
:
Option
<
Token
>
,
lo
:
Byte
Pos
)
->
matcher_pos
{
let
mut
match_idx_hi
=
0u
;
for
ms
.each
()
|
elt
|
{
...
...
src/libsyntax/parse/attr.rs
浏览文件 @
81d20156
...
...
@@ -14,7 +14,7 @@ fn parse_outer_attrs_or_ext(first_item_attrs: ~[ast::attribute])
->
attr_or_ext
;
fn
parse_outer_attributes
()
->
~
[
ast
::
attribute
];
fn
parse_attribute
(
style
:
ast
::
attr_style
)
->
ast
::
attribute
;
fn
parse_attribute_naked
(
style
:
ast
::
attr_style
,
lo
:
Char
Pos
)
->
fn
parse_attribute_naked
(
style
:
ast
::
attr_style
,
lo
:
Byte
Pos
)
->
ast
::
attribute
;
fn
parse_inner_attrs_and_next
()
->
{
inner
:
~
[
ast
::
attribute
],
next
:
~
[
ast
::
attribute
]};
...
...
@@ -85,7 +85,7 @@ fn parse_attribute(style: ast::attr_style) -> ast::attribute {
return
self
.parse_attribute_naked
(
style
,
lo
);
}
fn
parse_attribute_naked
(
style
:
ast
::
attr_style
,
lo
:
Char
Pos
)
->
fn
parse_attribute_naked
(
style
:
ast
::
attr_style
,
lo
:
Byte
Pos
)
->
ast
::
attribute
{
self
.expect
(
token
::
LBRACKET
);
let
meta_item
=
self
.parse_meta_item
();
...
...
src/libsyntax/parse/comments.rs
浏览文件 @
81d20156
...
...
@@ -28,7 +28,7 @@ impl cmnt_style : cmp::Eq {
}
}
type
cmnt
=
{
style
:
cmnt_style
,
lines
:
~
[
~
str
],
pos
:
Char
Pos
};
type
cmnt
=
{
style
:
cmnt_style
,
lines
:
~
[
~
str
],
pos
:
Byte
Pos
};
fn
is_doc_comment
(
s
:
~
str
)
->
bool
{
s
.starts_with
(
~
"///"
)
||
...
...
@@ -131,7 +131,7 @@ fn consume_non_eol_whitespace(rdr: string_reader) {
fn
push_blank_line_comment
(
rdr
:
string_reader
,
comments
:
&
mut
~
[
cmnt
])
{
debug!
(
">>> blank-line comment"
);
let
v
:
~
[
~
str
]
=
~
[];
comments
.push
({
style
:
blank_line
,
lines
:
v
,
pos
:
rdr
.last_pos.
ch
});
comments
.push
({
style
:
blank_line
,
lines
:
v
,
pos
:
rdr
.last_pos.
byte
});
}
fn
consume_whitespace_counting_blank_lines
(
rdr
:
string_reader
,
...
...
@@ -148,7 +148,7 @@ fn consume_whitespace_counting_blank_lines(rdr: string_reader,
fn
read_shebang_comment
(
rdr
:
string_reader
,
code_to_the_left
:
bool
,
comments
:
&
mut
~
[
cmnt
])
{
debug!
(
">>> shebang comment"
);
let
p
=
rdr
.last_pos.
ch
;
let
p
=
rdr
.last_pos.
byte
;
debug!
(
"<<< shebang comment"
);
comments
.push
({
style
:
if
code_to_the_left
{
trailing
}
else
{
isolated
},
...
...
@@ -160,7 +160,7 @@ fn read_shebang_comment(rdr: string_reader, code_to_the_left: bool,
fn
read_line_comments
(
rdr
:
string_reader
,
code_to_the_left
:
bool
,
comments
:
&
mut
~
[
cmnt
])
{
debug!
(
">>> line comments"
);
let
p
=
rdr
.last_pos.
ch
;
let
p
=
rdr
.last_pos.
byte
;
let
mut
lines
:
~
[
~
str
]
=
~
[];
while
rdr
.curr
==
'/'
&&
nextch
(
rdr
)
==
'/'
{
let
line
=
read_one_line_comment
(
rdr
);
...
...
@@ -209,7 +209,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str],
fn
read_block_comment
(
rdr
:
string_reader
,
code_to_the_left
:
bool
,
comments
:
&
mut
~
[
cmnt
])
{
debug!
(
">>> block comment"
);
let
p
=
rdr
.last_pos.
ch
;
let
p
=
rdr
.last_pos.
byte
;
let
mut
lines
:
~
[
~
str
]
=
~
[];
let
mut
col
:
CharPos
=
rdr
.col
;
bump
(
rdr
);
...
...
@@ -284,7 +284,7 @@ fn consume_comment(rdr: string_reader, code_to_the_left: bool,
debug!
(
"<<< consume comment"
);
}
type
lit
=
{
lit
:
~
str
,
pos
:
Char
Pos
};
type
lit
=
{
lit
:
~
str
,
pos
:
Byte
Pos
};
fn
gather_comments_and_literals
(
span_diagnostic
:
diagnostic
::
span_handler
,
path
:
~
str
,
...
...
src/libsyntax/parse/common.rs
浏览文件 @
81d20156
...
...
@@ -205,7 +205,7 @@ fn expect_gt() {
if
self
.token
==
token
::
GT
{
self
.bump
();
}
else
if
self
.token
==
token
::
BINOP
(
token
::
SHR
)
{
self
.swap
(
token
::
GT
,
self
.span.lo
+
Char
Pos
(
1u
),
self
.span.hi
);
self
.swap
(
token
::
GT
,
self
.span.lo
+
Byte
Pos
(
1u
),
self
.span.hi
);
}
else
{
let
mut
s
:
~
str
=
~
"expected `"
;
s
+=
token_to_str
(
self
.reader
,
token
::
GT
);
...
...
src/libsyntax/parse/lexer.rs
浏览文件 @
81d20156
...
...
@@ -23,7 +23,7 @@ trait reader {
src
:
@~
str
,
// The absolute offset within the codemap of the next character to read
mut
pos
:
FilePos
,
// The absolute offset within the codemap of the last character
to be read
(curr)
// The absolute offset within the codemap of the last character
read
(curr)
mut
last_pos
:
FilePos
,
// The column of the next character to read
mut
col
:
CharPos
,
...
...
@@ -123,9 +123,9 @@ fn string_advance_token(&&r: string_reader) {
if
is_eof
(
r
)
{
r
.peek_tok
=
token
::
EOF
;
}
else
{
let
start_
chpos
=
r
.last_pos.ch
;
let
start_
bytepos
=
r
.last_pos.byte
;
r
.peek_tok
=
next_token_inner
(
r
);
r
.peek_span
=
ast_util
::
mk_sp
(
start_
chpos
,
r
.last_pos.ch
);
r
.peek_span
=
ast_util
::
mk_sp
(
start_
bytepos
,
r
.last_pos.byte
);
};
}
...
...
@@ -158,6 +158,11 @@ fn bump(rdr: string_reader) {
rdr
.filemap
.next_line
(
rdr
.last_pos
);
rdr
.col
=
CharPos
(
0u
);
}
if
byte_offset_diff
>
1
{
rdr
.filemap
.record_multibyte_char
(
BytePos
(
current_byte_offset
),
byte_offset_diff
);
}
}
else
{
// XXX: What does this accomplish?
if
(
rdr
.curr
!=
-
1
as
char
)
{
...
...
@@ -233,7 +238,7 @@ fn consume_any_line_comment(rdr: string_reader)
bump
(
rdr
);
// line comments starting with "///" or "//!" are doc-comments
if
rdr
.curr
==
'/'
||
rdr
.curr
==
'!'
{
let
start_
chpos
=
rdr
.pos.ch
-
Char
Pos
(
2u
);
let
start_
bpos
=
rdr
.pos.byte
-
Byte
Pos
(
2u
);
let
mut
acc
=
~
"//"
;
while
rdr
.curr
!=
'\n'
&&
!
is_eof
(
rdr
)
{
str
::
push_char
(
&
mut
acc
,
rdr
.curr
);
...
...
@@ -241,7 +246,7 @@ fn consume_any_line_comment(rdr: string_reader)
}
return
Some
({
tok
:
token
::
DOC_COMMENT
(
rdr
.interner
.intern
(
@
acc
)),
sp
:
ast_util
::
mk_sp
(
start_
chpos
,
rdr
.pos.ch
)
sp
:
ast_util
::
mk_sp
(
start_
bpos
,
rdr
.pos.byte
)
});
}
else
{
while
rdr
.curr
!=
'\n'
&&
!
is_eof
(
rdr
)
{
bump
(
rdr
);
}
...
...
@@ -256,7 +261,7 @@ fn consume_any_line_comment(rdr: string_reader)
if
nextch
(
rdr
)
==
'!'
{
let
cmap
=
@
CodeMap
::
new
();
(
*
cmap
)
.files
.push
(
rdr
.filemap
);
let
loc
=
cmap
.lookup_char_pos_adj
(
rdr
.last_pos.
ch
);
let
loc
=
cmap
.lookup_char_pos_adj
(
rdr
.last_pos.
byte
);
if
loc
.line
==
1u
&&
loc
.col
==
CharPos
(
0u
)
{
while
rdr
.curr
!=
'\n'
&&
!
is_eof
(
rdr
)
{
bump
(
rdr
);
}
return
consume_whitespace_and_comments
(
rdr
);
...
...
@@ -272,7 +277,7 @@ fn consume_block_comment(rdr: string_reader)
// block comments starting with "/**" or "/*!" are doc-comments
if
rdr
.curr
==
'*'
||
rdr
.curr
==
'!'
{
let
start_
chpos
=
rdr
.pos.ch
-
Char
Pos
(
2u
);
let
start_
bpos
=
rdr
.pos.byte
-
Byte
Pos
(
2u
);
let
mut
acc
=
~
"/*"
;
while
!
(
rdr
.curr
==
'*'
&&
nextch
(
rdr
)
==
'/'
)
&&
!
is_eof
(
rdr
)
{
str
::
push_char
(
&
mut
acc
,
rdr
.curr
);
...
...
@@ -286,7 +291,7 @@ fn consume_block_comment(rdr: string_reader)
bump
(
rdr
);
return
Some
({
tok
:
token
::
DOC_COMMENT
(
rdr
.interner
.intern
(
@
acc
)),
sp
:
ast_util
::
mk_sp
(
start_
chpos
,
rdr
.pos.ch
)
sp
:
ast_util
::
mk_sp
(
start_
bpos
,
rdr
.pos.byte
)
});
}
}
else
{
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
81d20156
...
...
@@ -5,7 +5,7 @@
use
std
::
map
::
HashMap
;
use
token
::{
can_begin_expr
,
is_ident
,
is_ident_or_path
,
is_plain_ident
,
INTERPOLATED
,
special_idents
};
use
codemap
::{
span
,
FssNone
,
Char
Pos
};
use
codemap
::{
span
,
FssNone
,
Byte
Pos
};
use
util
::
interner
::
Interner
;
use
ast_util
::{
spanned
,
respan
,
mk_sp
,
ident_to_path
,
operator_prec
};
use
lexer
::
reader
;
...
...
@@ -244,7 +244,7 @@ fn bump() {
self
.token
=
next
.tok
;
self
.span
=
next
.sp
;
}
fn
swap
(
next
:
token
::
Token
,
+
lo
:
CharPos
,
+
hi
:
Char
Pos
)
{
fn
swap
(
next
:
token
::
Token
,
+
lo
:
BytePos
,
+
hi
:
Byte
Pos
)
{
self
.token
=
next
;
self
.span
=
mk_sp
(
lo
,
hi
);
}
...
...
@@ -904,12 +904,12 @@ fn parse_field(sep: token::Token) -> field {
return
spanned
(
lo
,
e
.span.hi
,
{
mutbl
:
m
,
ident
:
i
,
expr
:
e
});
}
fn
mk_expr
(
+
lo
:
CharPos
,
+
hi
:
Char
Pos
,
+
node
:
expr_
)
->
@
expr
{
fn
mk_expr
(
+
lo
:
BytePos
,
+
hi
:
Byte
Pos
,
+
node
:
expr_
)
->
@
expr
{
return
@
{
id
:
self
.get_id
(),
callee_id
:
self
.get_id
(),
node
:
node
,
span
:
mk_sp
(
lo
,
hi
)};
}
fn
mk_mac_expr
(
+
lo
:
CharPos
,
+
hi
:
Char
Pos
,
m
:
mac_
)
->
@
expr
{
fn
mk_mac_expr
(
+
lo
:
BytePos
,
+
hi
:
Byte
Pos
,
m
:
mac_
)
->
@
expr
{
return
@
{
id
:
self
.get_id
(),
callee_id
:
self
.get_id
(),
node
:
expr_mac
({
node
:
m
,
span
:
mk_sp
(
lo
,
hi
)}),
...
...
@@ -1134,7 +1134,7 @@ fn parse_bottom_expr() -> @expr {
return
self
.mk_expr
(
lo
,
hi
,
ex
);
}
fn
parse_block_expr
(
lo
:
Char
Pos
,
blk_mode
:
blk_check_mode
)
->
@
expr
{
fn
parse_block_expr
(
lo
:
Byte
Pos
,
blk_mode
:
blk_check_mode
)
->
@
expr
{
self
.expect
(
token
::
LBRACE
);
let
blk
=
self
.parse_block_tail
(
lo
,
blk_mode
);
return
self
.mk_expr
(
blk
.span.lo
,
blk
.span.hi
,
expr_block
(
blk
));
...
...
@@ -1146,7 +1146,7 @@ fn parse_syntax_ext() -> @expr {
return
self
.parse_syntax_ext_naked
(
lo
);
}
fn
parse_syntax_ext_naked
(
lo
:
Char
Pos
)
->
@
expr
{
fn
parse_syntax_ext_naked
(
lo
:
Byte
Pos
)
->
@
expr
{
match
self
.token
{
token
::
IDENT
(
_
,
_
)
=>
(),
_
=>
self
.fatal
(
~
"expected a syntax expander name"
)
...
...
@@ -2279,11 +2279,11 @@ fn parse_block_no_value() -> blk {
// I guess that also means "already parsed the 'impure'" if
// necessary, and this should take a qualifier.
// some blocks start with "#{"...
fn
parse_block_tail
(
lo
:
Char
Pos
,
s
:
blk_check_mode
)
->
blk
{
fn
parse_block_tail
(
lo
:
Byte
Pos
,
s
:
blk_check_mode
)
->
blk
{
self
.parse_block_tail_
(
lo
,
s
,
~
[])
}
fn
parse_block_tail_
(
lo
:
Char
Pos
,
s
:
blk_check_mode
,
fn
parse_block_tail_
(
lo
:
Byte
Pos
,
s
:
blk_check_mode
,
+
first_item_attrs
:
~
[
attribute
])
->
blk
{
let
mut
stmts
=
~
[];
let
mut
expr
=
None
;
...
...
@@ -2581,7 +2581,7 @@ fn parse_fn_header() -> {ident: ident, tps: ~[ty_param]} {
return
{
ident
:
id
,
tps
:
ty_params
};
}
fn
mk_item
(
+
lo
:
CharPos
,
+
hi
:
Char
Pos
,
+
ident
:
ident
,
fn
mk_item
(
+
lo
:
BytePos
,
+
hi
:
Byte
Pos
,
+
ident
:
ident
,
+
node
:
item_
,
vis
:
visibility
,
+
attrs
:
~
[
attribute
])
->
@
item
{
return
@
{
ident
:
ident
,
...
...
@@ -3037,7 +3037,7 @@ fn parse_foreign_mod_items(sort: ast::foreign_mod_sort,
items
:
items
};
}
fn
parse_item_foreign_mod
(
lo
:
Char
Pos
,
fn
parse_item_foreign_mod
(
lo
:
Byte
Pos
,
visibility
:
visibility
,
attrs
:
~
[
attribute
],
items_allowed
:
bool
)
...
...
@@ -3092,7 +3092,7 @@ fn parse_item_foreign_mod(lo: CharPos,
});
}
fn
parse_type_decl
()
->
{
lo
:
Char
Pos
,
ident
:
ident
}
{
fn
parse_type_decl
()
->
{
lo
:
Byte
Pos
,
ident
:
ident
}
{
let
lo
=
self
.last_span.lo
;
let
id
=
self
.parse_ident
();
return
{
lo
:
lo
,
ident
:
id
};
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
81d20156
use
parse
::{
comments
,
lexer
,
token
};
use
codemap
::{
CodeMap
,
Char
Pos
};
use
codemap
::{
CodeMap
,
Byte
Pos
};
use
pp
::{
break_offset
,
word
,
printer
,
space
,
zerobreak
,
hardbreak
,
breaks
};
use
pp
::{
consistent
,
inconsistent
,
eof
};
use
ast
::{
required
,
provided
};
...
...
@@ -1898,7 +1898,7 @@ fn print_ty_fn(s: ps,
}
fn
maybe_print_trailing_comment
(
s
:
ps
,
span
:
codemap
::
span
,
next_pos
:
Option
<
Char
Pos
>
)
{
next_pos
:
Option
<
Byte
Pos
>
)
{
let
mut
cm
;
match
s
.cm
{
Some
(
ccm
)
=>
cm
=
ccm
,
_
=>
return
}
match
next_comment
(
s
)
{
...
...
@@ -1906,7 +1906,7 @@ fn maybe_print_trailing_comment(s: ps, span: codemap::span,
if
cmnt
.style
!=
comments
::
trailing
{
return
;
}
let
span_line
=
cm
.lookup_char_pos
(
span
.hi
);
let
comment_line
=
cm
.lookup_char_pos
(
cmnt
.pos
);
let
mut
next
=
cmnt
.pos
+
Char
Pos
(
1u
);
let
mut
next
=
cmnt
.pos
+
Byte
Pos
(
1u
);
match
next_pos
{
None
=>
(),
Some
(
p
)
=>
next
=
p
}
if
span
.hi
<
cmnt
.pos
&&
cmnt
.pos
<
next
&&
span_line
.line
==
comment_line
.line
{
...
...
@@ -1981,7 +1981,7 @@ fn lit_to_str(l: @ast::lit) -> ~str {
return
to_str
(
l
,
print_literal
,
parse
::
token
::
mk_fake_ident_interner
());
}
fn
next_lit
(
s
:
ps
,
pos
:
Char
Pos
)
->
Option
<
comments
::
lit
>
{
fn
next_lit
(
s
:
ps
,
pos
:
Byte
Pos
)
->
Option
<
comments
::
lit
>
{
match
s
.literals
{
Some
(
lits
)
=>
{
while
s
.cur_lit
<
vec
::
len
(
lits
)
{
...
...
@@ -1996,7 +1996,7 @@ fn next_lit(s: ps, pos: CharPos) -> Option<comments::lit> {
}
}
fn
maybe_print_comment
(
s
:
ps
,
pos
:
Char
Pos
)
{
fn
maybe_print_comment
(
s
:
ps
,
pos
:
Byte
Pos
)
{
loop
{
match
next_comment
(
s
)
{
Some
(
cmnt
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录