Skip to content

Commit 9d7b130

Browse files
committed
add new enum ast::StrStyle as field to ast::lit_str
For the benefit of the pretty printer we want to keep track of how string literals in the ast were originally represented in the source code. This commit changes parser functions so they don't extract strings from the token stream without at least also returning what style of string literal it was. This is stored in the resulting ast node for string literals, obviously, for the package id in `extern mod = r"package id"` view items, for the inline asm in `asm!()` invocations. For `asm!()`'s other arguments or for `extern "Rust" fn()` items, I just the style of string, because it seemed disproportionally cumbersome to thread that information through the string processing that happens with those string literals, given the limited advantage raw string literals would provide in these positions. The other syntax extensions don't seem to store passed string literals in the ast, so they also discard the style of strings they parse.
1 parent 9787872 commit 9d7b130

File tree

25 files changed

+92
-73
lines changed

25 files changed

+92
-73
lines changed

src/librustc/front/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr {
407407
debug2!("encoding {}", ast_util::path_name_i(path));
408408

409409
let name_lit: ast::lit =
410-
nospan(ast::lit_str(ast_util::path_name_i(path).to_managed()));
410+
nospan(ast::lit_str(ast_util::path_name_i(path).to_managed(), ast::CookedStr));
411411

412412
let name_expr = @ast::Expr {
413413
id: ast::DUMMY_NODE_ID,

src/librustc/metadata/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn visit_view_item(e: @mut Env, i: &ast::view_item) {
142142
let ident = token::ident_to_str(&ident);
143143
let meta_items = match path_opt {
144144
None => meta_items.clone(),
145-
Some(p) => {
145+
Some((p, _path_str_style)) => {
146146
let p_path = Path(p);
147147
match p_path.filestem() {
148148
Some(s) =>

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ fn encode_meta_item(ebml_w: &mut writer::Encoder, mi: @MetaItem) {
14461446
}
14471447
MetaNameValue(name, value) => {
14481448
match value.node {
1449-
lit_str(value) => {
1449+
lit_str(value, _) => {
14501450
ebml_w.start_tag(tag_meta_item_name_value);
14511451
ebml_w.start_tag(tag_meta_item_name);
14521452
ebml_w.writer.write(name.as_bytes());

src/librustc/middle/check_const.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn check_pat(v: &mut CheckCrateVisitor, p: @Pat, _is_const: bool) {
8686
match e.node {
8787
ExprVstore(
8888
@Expr { node: ExprLit(@codemap::Spanned {
89-
node: lit_str(_),
89+
node: lit_str(*),
9090
_}),
9191
_ },
9292
ExprVstoreUniq
@@ -120,7 +120,7 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
120120
"disallowed operator in constant expression");
121121
return;
122122
}
123-
ExprLit(@codemap::Spanned {node: lit_str(_), _}) => { }
123+
ExprLit(@codemap::Spanned {node: lit_str(*), _}) => { }
124124
ExprBinary(*) | ExprUnary(*) => {
125125
if method_map.contains_key(&e.id) {
126126
sess.span_err(e.span, "user-defined operators are not \

src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
475475

476476
pub fn lit_to_const(lit: &lit) -> const_val {
477477
match lit.node {
478-
lit_str(s) => const_str(s),
478+
lit_str(s, _) => const_str(s),
479479
lit_char(n) => const_uint(n as u64),
480480
lit_int(n, _) => const_int(n),
481481
lit_uint(n, _) => const_uint(n),

src/librustc/middle/trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn const_lit(cx: &mut CrateContext, e: &ast::Expr, lit: ast::lit)
7171
}
7272
ast::lit_bool(b) => C_bool(b),
7373
ast::lit_nil => C_nil(),
74-
ast::lit_str(s) => C_estr_slice(cx, s)
74+
ast::lit_str(s, _) => C_estr_slice(cx, s)
7575
}
7676
}
7777

src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ fn trans_rvalue_dps_unadjusted(bcx: @mut Block, expr: &ast::Expr,
705705
args.iter().enumerate().map(|(i, arg)| (i, *arg)).collect();
706706
return trans_adt(bcx, repr, 0, numbered_fields, None, dest);
707707
}
708-
ast::ExprLit(@codemap::Spanned {node: ast::lit_str(s), _}) => {
708+
ast::ExprLit(@codemap::Spanned {node: ast::lit_str(s, _), _}) => {
709709
return tvec::trans_lit_str(bcx, expr, s, dest);
710710
}
711711
ast::ExprVstore(contents, ast::ExprVstoreSlice) |

src/librustc/middle/trans/tvec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub fn trans_slice_vstore(bcx: @mut Block,
205205

206206
// Handle the &"..." case:
207207
match content_expr.node {
208-
ast::ExprLit(@codemap::Spanned {node: ast::lit_str(s), span: _}) => {
208+
ast::ExprLit(@codemap::Spanned {node: ast::lit_str(s, _), span: _}) => {
209209
return trans_lit_str(bcx, content_expr, s, dest);
210210
}
211211
_ => {}
@@ -296,7 +296,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: @mut Block, heap: heap, vstore_expr: &a
296296
heap_exchange => {
297297
match content_expr.node {
298298
ast::ExprLit(@codemap::Spanned {
299-
node: ast::lit_str(s), span
299+
node: ast::lit_str(s, _), span
300300
}) => {
301301
let llptrval = C_cstr(bcx.ccx(), s);
302302
let llptrval = PointerCast(bcx, llptrval, Type::i8p());
@@ -357,7 +357,7 @@ pub fn write_content(bcx: @mut Block,
357357
let _indenter = indenter();
358358

359359
match content_expr.node {
360-
ast::ExprLit(@codemap::Spanned { node: ast::lit_str(s), _ }) => {
360+
ast::ExprLit(@codemap::Spanned { node: ast::lit_str(s, _), _ }) => {
361361
match dest {
362362
Ignore => {
363363
return bcx;
@@ -490,7 +490,7 @@ pub fn elements_required(bcx: @mut Block, content_expr: &ast::Expr) -> uint {
490490
//! Figure out the number of elements we need to store this content
491491
492492
match content_expr.node {
493-
ast::ExprLit(@codemap::Spanned { node: ast::lit_str(s), _ }) => {
493+
ast::ExprLit(@codemap::Spanned { node: ast::lit_str(s, _), _ }) => {
494494
s.len()
495495
},
496496
ast::ExprVec(ref es, _) => es.len(),

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@ pub fn expr_kind(tcx: ctxt,
32663266
ast::ExprDoBody(*) |
32673267
ast::ExprBlock(*) |
32683268
ast::ExprRepeat(*) |
3269-
ast::ExprLit(@codemap::Spanned {node: lit_str(_), _}) |
3269+
ast::ExprLit(@codemap::Spanned {node: lit_str(*), _}) |
32703270
ast::ExprVstore(_, ast::ExprVstoreSlice) |
32713271
ast::ExprVstore(_, ast::ExprVstoreMutSlice) |
32723272
ast::ExprVec(*) => {

src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
22592259
match expr.node {
22602260
ast::ExprVstore(ev, vst) => {
22612261
let typ = match ev.node {
2262-
ast::ExprLit(@codemap::Spanned { node: ast::lit_str(_), _ }) => {
2262+
ast::ExprLit(@codemap::Spanned { node: ast::lit_str(*), _ }) => {
22632263
let tt = ast_expr_vstore_to_vstore(fcx, ev, vst);
22642264
ty::mk_estr(tcx, tt)
22652265
}

0 commit comments

Comments
 (0)