Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7c72fd89
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,发现更多精彩内容 >>
提交
7c72fd89
编写于
11月 16, 2012
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add some docs to codemap
上级
2af08852
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
13 deletion
+48
-13
src/libsyntax/codemap.rs
src/libsyntax/codemap.rs
+48
-13
未找到文件。
src/libsyntax/codemap.rs
浏览文件 @
7c72fd89
/*! A codemap is a thing that maps uints to file/line/column positions
* in a crate. This to make it possible to represent the positions
* with single-word things, rather than passing records all over the
* compiler.
*
* All represented positions are *absolute* positions within the codemap,
* not relative positions within a single file.
*/
/*!
The CodeMap tracks all the source code used within a single crate, mapping
from integer byte positions to the original source code location. Each bit of
source parsed during crate parsing (typically files, in-memory strings, or
various bits of macro expansion) cover a continuous range of bytes in the
CodeMap and are represented by FileMaps. Byte positions are stored in `spans`
and used pervasively in the compiler. They are absolute positions within the
CodeMap, which upon request can be converted to line and column information,
source code snippets, etc.
*/
use
dvec
::
DVec
;
use
std
::
serialization
::{
Serializable
,
...
...
@@ -18,9 +22,16 @@ trait Pos {
pure
fn
to_uint
(
&
self
)
->
uint
;
}
/// A byte offset
pub
enum
BytePos
=
uint
;
/// A character offset. Because of multibyte utf8 characters, a byte offset
/// is not equivalent to a character offset. The CodeMap will convert BytePos
/// values to CharPos values as necessary.
pub
enum
CharPos
=
uint
;
// XXX: Lots of boilerplate in these impls, but so far my attempts to fix
// have been unsuccessful
impl
BytePos
:
Pos
{
static
pure
fn
from_uint
(
n
:
uint
)
->
BytePos
{
BytePos
(
n
)
}
pure
fn
to_uint
(
&
self
)
->
uint
{
**
self
}
...
...
@@ -117,6 +128,12 @@ impl CharPos: to_bytes::IterBytes {
}
}
/**
Spans represent a region of code, used for error reporting. Positions in spans
are *absolute* positions from the beginning of the codemap, not positions
relative to FileMaps. Methods on the CodeMap can be used to relate spans back
to the original source.
*/
pub
struct
span
{
lo
:
BytePos
,
hi
:
BytePos
,
...
...
@@ -141,10 +158,17 @@ impl<D: Deserializer> span: Deserializable<D> {
}
}
/// A source code location used for error reporting
pub
struct
Loc
{
file
:
@
FileMap
,
line
:
uint
,
col
:
CharPos
/// Information about the original source
file
:
@
FileMap
,
/// The (1-based) line number
line
:
uint
,
/// The (0-based) column offset
col
:
CharPos
}
/// Extra information for tracking macro expansion of spans
pub
enum
ExpnInfo
{
ExpandedFrom
({
call_site
:
span
,
callie
:
{
name
:
~
str
,
span
:
Option
<
span
>
}})
...
...
@@ -174,12 +198,21 @@ pub struct MultiByteChar {
sum
:
uint
}
/// A single source in the CodeMap
pub
struct
FileMap
{
/// The name of the file that the source came from, source that doesn't
/// originate from files has names between angle brackets by convention,
/// e.g. `<anon>`
name
:
FileName
,
/// Extra information used by qquote
substr
:
FileSubstr
,
/// The complete source code
src
:
@~
str
,
/// The start position of this source in the CodeMap
start_pos
:
BytePos
,
/// Locations of lines beginnings in the source code
mut
lines
:
~
[
BytePos
],
/// Locations of multi-byte characters in the source code
multibyte_chars
:
DVec
<
MultiByteChar
>
}
...
...
@@ -226,6 +259,11 @@ pub impl CodeMap {
}
}
/// Add a new FileMap to the CodeMap and return it
fn
new_filemap
(
+
filename
:
FileName
,
src
:
@~
str
)
->
@
FileMap
{
return
self
.new_filemap_w_substr
(
filename
,
FssNone
,
src
);
}
fn
new_filemap_w_substr
(
+
filename
:
FileName
,
+
substr
:
FileSubstr
,
src
:
@~
str
)
->
@
FileMap
{
let
start_pos
=
if
self
.files
.len
()
==
0
{
...
...
@@ -248,16 +286,13 @@ fn new_filemap_w_substr(+filename: FileName, +substr: FileSubstr,
return
filemap
;
}
fn
new_filemap
(
+
filename
:
FileName
,
src
:
@~
str
)
->
@
FileMap
{
return
self
.new_filemap_w_substr
(
filename
,
FssNone
,
src
);
}
pub
fn
mk_substr_filename
(
&
self
,
sp
:
span
)
->
~
str
{
let
pos
=
self
.lookup_char_pos
(
sp
.lo
);
return
fmt!
(
"<%s:%u:%u>"
,
pos
.file.name
,
pos
.line
,
pos
.col
.to_uint
());
}
/// Lookup source information about a BytePos
pub
fn
lookup_char_pos
(
&
self
,
+
pos
:
BytePos
)
->
Loc
{
return
self
.lookup_pos
(
pos
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录