Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
496996c2
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
496996c2
编写于
3月 16, 2017
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove code in `syntax::codemap`.
上级
1979f965
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
0 addition
and
189 deletion
+0
-189
src/libsyntax/codemap.rs
src/libsyntax/codemap.rs
+0
-185
src/libsyntax_pos/lib.rs
src/libsyntax_pos/lib.rs
+0
-4
未找到文件。
src/libsyntax/codemap.rs
浏览文件 @
496996c2
...
...
@@ -409,101 +409,6 @@ pub fn span_to_string(&self, sp: Span) -> String {
hi
.col
.to_usize
()
+
1
))
.to_string
()
}
// Returns true if two spans have the same callee
// (Assumes the same ExpnFormat implies same callee)
fn
match_callees
(
&
self
,
sp_a
:
&
Span
,
sp_b
:
&
Span
)
->
bool
{
let
fmt_a
=
self
.with_expn_info
(
sp_a
.expn_id
,
|
ei
|
ei
.map
(|
ei
|
ei
.callee.format
.clone
()));
let
fmt_b
=
self
.with_expn_info
(
sp_b
.expn_id
,
|
ei
|
ei
.map
(|
ei
|
ei
.callee.format
.clone
()));
fmt_a
==
fmt_b
}
/// Returns a formatted string showing the expansion chain of a span
///
/// Spans are printed in the following format:
///
/// filename:start_line:col: end_line:col
/// snippet
/// Callee:
/// Callee span
/// Callsite:
/// Callsite span
///
/// Callees and callsites are printed recursively (if available, otherwise header
/// and span is omitted), expanding into their own callee/callsite spans.
/// Each layer of recursion has an increased indent, and snippets are truncated
/// to at most 50 characters. Finally, recursive calls to the same macro are squashed,
/// with '...' used to represent any number of recursive calls.
pub
fn
span_to_expanded_string
(
&
self
,
sp
:
Span
)
->
String
{
self
.span_to_expanded_string_internal
(
sp
,
""
)
}
fn
span_to_expanded_string_internal
(
&
self
,
sp
:
Span
,
indent
:
&
str
)
->
String
{
let
mut
indent
=
indent
.to_owned
();
let
mut
output
=
""
.to_owned
();
let
span_str
=
self
.span_to_string
(
sp
);
let
mut
span_snip
=
self
.span_to_snippet
(
sp
)
.unwrap_or
(
"Snippet unavailable"
.to_owned
());
// Truncate by code points - in worst case this will be more than 50 characters,
// but ensures at least 50 characters and respects byte boundaries.
let
char_vec
:
Vec
<
(
usize
,
char
)
>
=
span_snip
.char_indices
()
.collect
();
if
char_vec
.len
()
>
50
{
span_snip
.truncate
(
char_vec
[
49
]
.0
);
span_snip
.push_str
(
"..."
);
}
output
.push_str
(
&
format!
(
"{}{}
\n
{}`{}`
\n
"
,
indent
,
span_str
,
indent
,
span_snip
));
if
sp
.expn_id
==
NO_EXPANSION
||
sp
.expn_id
==
COMMAND_LINE_EXPN
{
return
output
;
}
let
mut
callee
=
self
.with_expn_info
(
sp
.expn_id
,
|
ei
|
ei
.and_then
(|
ei
|
ei
.callee.span
.clone
()));
let
mut
callsite
=
self
.with_expn_info
(
sp
.expn_id
,
|
ei
|
ei
.map
(|
ei
|
ei
.call_site
.clone
()));
indent
.push_str
(
" "
);
let
mut
is_recursive
=
false
;
while
callee
.is_some
()
&&
self
.match_callees
(
&
sp
,
&
callee
.unwrap
())
{
callee
=
self
.with_expn_info
(
callee
.unwrap
()
.expn_id
,
|
ei
|
ei
.and_then
(|
ei
|
ei
.callee.span
.clone
()));
is_recursive
=
true
;
}
if
let
Some
(
span
)
=
callee
{
output
.push_str
(
&
indent
);
output
.push_str
(
"Callee:
\n
"
);
if
is_recursive
{
output
.push_str
(
&
indent
);
output
.push_str
(
"...
\n
"
);
}
output
.push_str
(
&
(
self
.span_to_expanded_string_internal
(
span
,
&
indent
)));
}
is_recursive
=
false
;
while
callsite
.is_some
()
&&
self
.match_callees
(
&
sp
,
&
callsite
.unwrap
())
{
callsite
=
self
.with_expn_info
(
callsite
.unwrap
()
.expn_id
,
|
ei
|
ei
.map
(|
ei
|
ei
.call_site
.clone
()));
is_recursive
=
true
;
}
if
let
Some
(
span
)
=
callsite
{
output
.push_str
(
&
indent
);
output
.push_str
(
"Callsite:
\n
"
);
if
is_recursive
{
output
.push_str
(
&
indent
);
output
.push_str
(
"...
\n
"
);
}
output
.push_str
(
&
(
self
.span_to_expanded_string_internal
(
span
,
&
indent
)));
}
output
}
/// Return the source span - this is either the supplied span, or the span for
/// the macro callsite that expanded to it.
pub
fn
source_callsite
(
&
self
,
sp
:
Span
)
->
Span
{
...
...
@@ -1069,59 +974,6 @@ fn t9() {
assert_eq!
(
sstr
,
"blork.rs:2:1: 2:12"
);
}
#[test]
fn
t10
()
{
// Test span_to_expanded_string works in base case (no expansion)
let
cm
=
init_code_map
();
let
span
=
Span
{
lo
:
BytePos
(
0
),
hi
:
BytePos
(
11
),
expn_id
:
NO_EXPANSION
};
let
sstr
=
cm
.span_to_expanded_string
(
span
);
assert_eq!
(
sstr
,
"blork.rs:1:1: 1:12
\n
`first line.`
\n
"
);
let
span
=
Span
{
lo
:
BytePos
(
12
),
hi
:
BytePos
(
23
),
expn_id
:
NO_EXPANSION
};
let
sstr
=
cm
.span_to_expanded_string
(
span
);
assert_eq!
(
sstr
,
"blork.rs:2:1: 2:12
\n
`second line`
\n
"
);
}
#[test]
fn
t11
()
{
// Test span_to_expanded_string works with expansion
let
cm
=
init_code_map
();
let
root
=
Span
{
lo
:
BytePos
(
0
),
hi
:
BytePos
(
11
),
expn_id
:
NO_EXPANSION
};
let
format
=
ExpnFormat
::
MacroBang
(
keywords
::
Invalid
.name
());
let
callee
=
NameAndSpan
{
format
:
format
,
allow_internal_unstable
:
false
,
span
:
None
};
let
info
=
ExpnInfo
{
call_site
:
root
,
callee
:
callee
};
let
id
=
cm
.record_expansion
(
info
);
let
sp
=
Span
{
lo
:
BytePos
(
12
),
hi
:
BytePos
(
23
),
expn_id
:
id
};
let
sstr
=
cm
.span_to_expanded_string
(
sp
);
assert_eq!
(
sstr
,
"blork.rs:2:1: 2:12
\n
`second line`
\n
Callsite:
\n
\
blork.rs:1:1: 1:12
\n
`first line.`
\n
"
);
}
/// Test merging two spans on the same line
#[test]
fn
span_merging
()
{
let
cm
=
CodeMap
::
new
();
let
inputtext
=
"bbbb BB bb CCC
\n
"
;
let
selection1
=
" ~~
\n
"
;
let
selection2
=
" ~~~
\n
"
;
cm
.new_filemap_and_lines
(
"blork.rs"
,
None
,
inputtext
);
let
span1
=
span_from_selection
(
inputtext
,
selection1
);
let
span2
=
span_from_selection
(
inputtext
,
selection2
);
if
let
Some
(
sp
)
=
cm
.merge_spans
(
span1
,
span2
)
{
let
sstr
=
cm
.span_to_expanded_string
(
sp
);
assert_eq!
(
sstr
,
"blork.rs:1:6: 1:15
\n
`BB bb CCC`
\n
"
);
}
else
{
assert
!
(
false
);
}
}
/// Test failing to merge two spans on different lines
#[test]
fn
span_merging_fail
()
{
...
...
@@ -1221,41 +1073,4 @@ fn init_expansion_chain(cm: &CodeMap) -> Span {
let
id_end
=
cm
.record_expansion
(
info_end
);
Span
{
lo
:
BytePos
(
37
),
hi
:
BytePos
(
48
),
expn_id
:
id_end
}
}
#[test]
fn
t12
()
{
// Test span_to_expanded_string collapses recursive macros and handles
// recursive callsite and callee expansions
let
cm
=
init_code_map
();
let
end
=
init_expansion_chain
(
&
cm
);
let
sstr
=
cm
.span_to_expanded_string
(
end
);
let
res_str
=
r"blork2.rs:2:1: 2:12
`second line`
Callsite:
...
blork2.rs:1:1: 1:12
`first line.`
Callee:
blork.rs:2:1: 2:12
`second line`
Callee:
blork.rs:1:1: 1:12
`first line.`
Callsite:
blork.rs:1:1: 1:12
`first line.`
Callsite:
...
blork.rs:2:1: 2:12
`second line`
Callee:
blork.rs:1:1: 1:12
`first line.`
Callsite:
blork.rs:1:1: 1:12
`first line.`
"
;
assert_eq!
(
sstr
,
res_str
);
}
}
src/libsyntax_pos/lib.rs
浏览文件 @
496996c2
...
...
@@ -263,10 +263,6 @@ fn from(span: Span) -> MultiSpan {
// For code appearing from the command line
pub
const
COMMAND_LINE_EXPN
:
ExpnId
=
ExpnId
(
!
1
);
// For code generated by a procedural macro, without knowing which
// Used in `qquote!`
pub
const
PROC_EXPN
:
ExpnId
=
ExpnId
(
!
2
);
impl
ExpnId
{
pub
fn
from_u32
(
id
:
u32
)
->
ExpnId
{
ExpnId
(
id
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录