Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3798b6f7
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,发现更多精彩内容 >>
提交
3798b6f7
编写于
9月 15, 2011
作者:
M
Marijn Haverbeke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove maybe_protect_block kludge from pretty-printer
It is no longer needed.
上级
0b34e0e6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
1 addition
and
121 deletion
+1
-121
src/comp/syntax/print/pprust.rs
src/comp/syntax/print/pprust.rs
+0
-86
src/test/pretty/block-disambig.rs
src/test/pretty/block-disambig.rs
+0
-35
src/test/run-pass/block-expr-precedence.rs
src/test/run-pass/block-expr-precedence.rs
+1
-0
未找到文件。
src/comp/syntax/print/pprust.rs
浏览文件 @
3798b6f7
...
...
@@ -576,15 +576,11 @@ fn print_possibly_embedded_block(s: ps, blk: ast::blk, embedded: embed_type,
block_normal
.
{
bopen
(
s
);
}
}
let
last_stmt
=
option
::
none
;
for
st
:
@
ast
::
stmt
in
blk
.node.stmts
{
maybe_protect_block
(
s
,
last_stmt
,
stmt_
(
st
));
print_stmt
(
s
,
*
st
);
last_stmt
=
option
::
some
(
st
);
}
alt
blk
.node.expr
{
some
(
expr
)
{
maybe_protect_block
(
s
,
last_stmt
,
expr_
(
expr
));
space_if_not_bol
(
s
);
print_expr
(
s
,
expr
);
maybe_print_trailing_comment
(
s
,
expr
.span
,
some
(
blk
.span.hi
));
...
...
@@ -593,88 +589,6 @@ fn print_possibly_embedded_block(s: ps, blk: ast::blk, embedded: embed_type,
}
bclose_
(
s
,
blk
.span
,
indented
);
s
.ann
.post
(
ann_node
);
tag
expr_or_stmt
{
stmt_
(
@
ast
::
stmt
);
expr_
(
@
ast
::
expr
);
}
// The Rust syntax has an ambiguity when an if, alt, or block statement is
// followed by a unary op, square bracket, or paren. In those cases we
// have to add an extra semi to make sure the output retains the same
// meaning.
fn
maybe_protect_block
(
s
:
ps
,
last
:
option
::
t
<@
ast
::
stmt
>
,
next
:
expr_or_stmt
)
{
let
last_expr_is_block
=
alt
last
{
option
::
some
(
@
{
node
:
ast
::
stmt_expr
(
e
,
_
),
_
})
{
alt
e
.node
{
ast
::
expr_if
(
_
,
_
,
_
)
|
ast
::
expr_alt
(
_
,
_
)
|
ast
::
expr_block
(
_
)
{
true
}
_
{
false
}
}
}
_
{
false
}
};
if
!
last_expr_is_block
{
ret
;
}
let
next_expr_is_ambig
=
alt
next
{
expr_
(
e
)
{
expr_is_ambig
(
e
)
}
stmt_
(
@
{
node
:
ast
::
stmt_expr
(
e
,
_
),
_
})
{
expr_is_ambig
(
e
)
}
_
{
false
}
};
if
last_expr_is_block
&&
next_expr_is_ambig
{
word
(
s
.s
,
";"
);
}
fn
expr_is_ambig
(
ex
:
@
ast
::
expr
)
->
bool
{
// We're going to walk the expression to the 'left' looking for
// various properties that might indicate ambiguity
type
env
=
@
mutable
bool
;
let
visitor
=
visit
::
mk_vt
(
@
{
visit_expr
:
visit_expr
with
*
visit
::
default_visitor
()});
let
env
=
@
mutable
false
;
visit_expr
(
ex
,
env
,
visitor
);
ret
*
env
;
fn
visit_expr
(
ex
:
@
ast
::
expr
,
e
:
env
,
v
:
visit
::
vt
<
env
>
)
{
assert
(
*
e
==
false
);
if
expr_is_ambig
(
ex
)
{
*
e
=
true
;
ret
;
}
alt
ex
.node
{
ast
::
expr_assign
(
x
,
_
)
{
v
.visit_expr
(
x
,
e
,
v
);
}
ast
::
expr_assign_op
(
_
,
x
,
_
)
{
visit_expr
(
x
,
e
,
v
);
}
ast
::
expr_move
(
x
,
_
)
{
v
.visit_expr
(
x
,
e
,
v
);
}
ast
::
expr_field
(
x
,
_
)
{
v
.visit_expr
(
x
,
e
,
v
);
}
ast
::
expr_index
(
x
,
_
)
{
v
.visit_expr
(
x
,
e
,
v
);
}
ast
::
expr_binary
(
op
,
x
,
_
)
{
if
need_parens
(
x
,
operator_prec
(
op
))
{
*
e
=
true
;
ret
;
}
v
.visit_expr
(
x
,
e
,
v
);
}
ast
::
expr_cast
(
x
,
_
)
{
if
need_parens
(
x
,
parse
::
parser
::
as_prec
)
{
*
e
=
true
;
ret
;
}
}
ast
::
expr_ternary
(
x
,
_
,
_
)
{
v
.visit_expr
(
x
,
e
,
v
);
}
_
{
}
}
}
fn
expr_is_ambig
(
ex
:
@
ast
::
expr
)
->
bool
{
alt
ex
.node
{
ast
::
expr_unary
(
_
,
_
)
{
true
}
ast
::
expr_tup
(
_
)
{
true
}
ast
::
expr_vec
(
_
,
_
)
{
true
}
_
{
false
}
}
}
}
}
}
// ret and fail, without arguments cannot appear is the discriminant of if,
...
...
src/test/pretty/block-disambig.rs
已删除
100644 → 0
浏览文件 @
0b34e0e6
// Tests that the pretty printer correctly disambiguates various scenarios
// involving block statements by ending them with a semi-colon
fn
test1
()
{
let
val
=
@
0
;
{
};
*
val
;
}
fn
test2
()
->
int
{
let
val
=
@
0
;
{
};
*
val
}
fn
test3
()
{
let
regs
=
@
{
mutable
eax
:
0
};
alt
true
{
true
{
}
};
(
*
regs
)
.eax
=
1
;
}
fn
test4
()
->
bool
{
let
regs
=
@
true
;
if
true
{
};
*
regs
||
false
}
fn
test5
()
->
(
int
,
int
)
{
{
};
(
0
,
1
)
}
fn
test6
()
->
bool
{
{
};
(
true
||
false
)
&&
true
}
fn
test7
()
->
uint
{
let
regs
=
@
0
;
alt
true
{
true
{
}
};
(
*
regs
<
2
)
as
uint
}
fn
test8
()
->
int
{
let
val
=
@
0
;
alt
true
{
true
{
}
};
*
val
<
1
?
0
:
1
}
fn
test9
()
{
let
regs
=
@
mutable
0
;
alt
true
{
true
{
}
};
*
regs
+=
1
;
}
fn
test10
()
->
int
{
let
regs
=
@
mutable
[
0
];
alt
true
{
true
{
}
};
(
*
regs
)[
0
]
}
fn
test11
()
->
[
int
]
{
if
true
{
};
[
1
,
2
]
}
src/test/run-pass/block-expr-precedence.rs
浏览文件 @
3798b6f7
...
...
@@ -2,6 +2,7 @@
// reproduce so we don't want to automatically reformat it
// no-reformat
// xfail-pretty
/*
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录