Skip to content

Commit 405c616

Browse files
committed
Use consistent terminology for byte string literals
Avoid confusion with binary integer literals and binary operator expressions in libsyntax
1 parent 69c3b39 commit 405c616

File tree

25 files changed

+69
-69
lines changed

25 files changed

+69
-69
lines changed

src/grammar/RustLexer.g4

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ tokens {
1313
BINOPEQ, AT, DOT, DOTDOT, DOTDOTDOT, COMMA, SEMI, COLON,
1414
MOD_SEP, RARROW, FAT_ARROW, LPAREN, RPAREN, LBRACKET, RBRACKET,
1515
LBRACE, RBRACE, POUND, DOLLAR, UNDERSCORE, LIT_CHAR, LIT_BYTE,
16-
LIT_INTEGER, LIT_FLOAT, LIT_STR, LIT_STR_RAW, LIT_BINARY,
17-
LIT_BINARY_RAW, QUESTION, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT,
16+
LIT_INTEGER, LIT_FLOAT, LIT_STR, LIT_STR_RAW, LIT_BYTE_STR,
17+
LIT_BYTE_STR_RAW, QUESTION, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT,
1818
COMMENT, SHEBANG, UTF8_BOM
1919
}
2020

@@ -148,8 +148,8 @@ LIT_STR
148148
: '"' ('\\\n' | '\\\r\n' | '\\' CHAR_ESCAPE | .)*? '"' SUFFIX?
149149
;
150150

151-
LIT_BINARY : 'b' LIT_STR ;
152-
LIT_BINARY_RAW : 'b' LIT_STR_RAW ;
151+
LIT_BYTE_STR : 'b' LIT_STR ;
152+
LIT_BYTE_STR_RAW : 'b' LIT_STR_RAW ;
153153

154154
/* this is a bit messy */
155155

src/grammar/lexer.l

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ while { return WHILE; }
200200
<ltorchar><<EOF>> { BEGIN(INITIAL); return -1; }
201201

202202
b\x22 { BEGIN(bytestr); yymore(); }
203-
<bytestr>\x22 { BEGIN(suffix); return LIT_BINARY; }
203+
<bytestr>\x22 { BEGIN(suffix); return LIT_BYTE_STR; }
204204

205205
<bytestr><<EOF>> { return -1; }
206206
<bytestr>\\[n\nrt\\\x27\x220] { yymore(); }
@@ -210,7 +210,7 @@ b\x22 { BEGIN(bytestr); yymore(); }
210210
<bytestr>(.|\n) { yymore(); }
211211

212212
br\x22 { BEGIN(rawbytestr_nohash); yymore(); }
213-
<rawbytestr_nohash>\x22 { BEGIN(suffix); return LIT_BINARY_RAW; }
213+
<rawbytestr_nohash>\x22 { BEGIN(suffix); return LIT_BYTE_STR_RAW; }
214214
<rawbytestr_nohash>(.|\n) { yymore(); }
215215
<rawbytestr_nohash><<EOF>> { return -1; }
216216

@@ -228,7 +228,7 @@ br/# {
228228
end_hashes++;
229229
if (end_hashes == num_hashes) {
230230
BEGIN(INITIAL);
231-
return LIT_BINARY_RAW;
231+
return LIT_BYTE_STR_RAW;
232232
}
233233
}
234234
yymore();
@@ -237,7 +237,7 @@ br/# {
237237
end_hashes = 1;
238238
if (end_hashes == num_hashes) {
239239
BEGIN(INITIAL);
240-
return LIT_BINARY_RAW;
240+
return LIT_BYTE_STR_RAW;
241241
}
242242
yymore();
243243
}

src/grammar/parser-lalr.y

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ extern char *yytext;
5252
%token LIT_FLOAT
5353
%token LIT_STR
5454
%token LIT_STR_RAW
55-
%token LIT_BINARY
56-
%token LIT_BINARY_RAW
55+
%token LIT_BYTE_STR
56+
%token LIT_BYTE_STR_RAW
5757
%token IDENT
5858
%token UNDERSCORE
5959
%token LIFETIME
@@ -1772,8 +1772,8 @@ lit
17721772
str
17731773
: LIT_STR { $$ = mk_node("LitStr", 1, mk_atom(yytext), mk_atom("CookedStr")); }
17741774
| LIT_STR_RAW { $$ = mk_node("LitStr", 1, mk_atom(yytext), mk_atom("RawStr")); }
1775-
| LIT_BINARY { $$ = mk_node("LitBinary", 1, mk_atom(yytext), mk_atom("BinaryStr")); }
1776-
| LIT_BINARY_RAW { $$ = mk_node("LitBinary", 1, mk_atom(yytext), mk_atom("RawBinaryStr")); }
1775+
| LIT_BYTE_STR { $$ = mk_node("LitByteStr", 1, mk_atom(yytext), mk_atom("ByteStr")); }
1776+
| LIT_BYTE_STR_RAW { $$ = mk_node("LitByteStr", 1, mk_atom(yytext), mk_atom("RawByteStr")); }
17771777
;
17781778

17791779
maybe_ident
@@ -1815,8 +1815,8 @@ unpaired_token
18151815
| LIT_FLOAT { $$ = mk_atom(yytext); }
18161816
| LIT_STR { $$ = mk_atom(yytext); }
18171817
| LIT_STR_RAW { $$ = mk_atom(yytext); }
1818-
| LIT_BINARY { $$ = mk_atom(yytext); }
1819-
| LIT_BINARY_RAW { $$ = mk_atom(yytext); }
1818+
| LIT_BYTE_STR { $$ = mk_atom(yytext); }
1819+
| LIT_BYTE_STR_RAW { $$ = mk_atom(yytext); }
18201820
| IDENT { $$ = mk_atom(yytext); }
18211821
| UNDERSCORE { $$ = mk_atom(yytext); }
18221822
| LIFETIME { $$ = mk_atom(yytext); }

src/grammar/tokens.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ enum Token {
3838
LIT_FLOAT,
3939
LIT_STR,
4040
LIT_STR_RAW,
41-
LIT_BINARY,
42-
LIT_BINARY_RAW,
41+
LIT_BYTE_STR,
42+
LIT_BYTE_STR_RAW,
4343
IDENT,
4444
UNDERSCORE,
4545
LIFETIME,

src/grammar/verify.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
107107
"OR" => token::BinOp(token::Or),
108108
"GT" => token::Gt,
109109
"LE" => token::Le,
110-
"LIT_BINARY" => token::Literal(token::Binary(Name(0)), None),
111-
"LIT_BINARY_RAW" => token::Literal(token::BinaryRaw(Name(0), 0), None),
110+
"LIT_BYTE_STR" => token::Literal(token::ByteStr(Name(0)), None),
111+
"LIT_BYTE_STR_RAW" => token::Literal(token::ByteStrRaw(Name(0), 0), None),
112112
"QUESTION" => token::Question,
113113
"SHEBANG" => token::Shebang(Name(0)),
114114
_ => continue,
@@ -137,8 +137,8 @@ fn str_to_binop(s: &str) -> token::BinOpToken {
137137
}
138138
}
139139

140-
/// Assuming a string/binary literal, strip out the leading/trailing
141-
/// hashes and surrounding quotes/raw/binary prefix.
140+
/// Assuming a string/byte string literal, strip out the leading/trailing
141+
/// hashes and surrounding quotes/raw/byte prefix.
142142
fn fix(mut lit: &str) -> ast::Name {
143143
if lit.char_at(0) == 'r' {
144144
if lit.char_at(1) == 'b' {
@@ -205,8 +205,8 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, token::Token>, surrogate_
205205
token::DocComment(..) => token::DocComment(nm),
206206
token::Literal(token::Integer(..), n) => token::Literal(token::Integer(nm), n),
207207
token::Literal(token::Float(..), n) => token::Literal(token::Float(nm), n),
208-
token::Literal(token::Binary(..), n) => token::Literal(token::Binary(nm), n),
209-
token::Literal(token::BinaryRaw(..), n) => token::Literal(token::BinaryRaw(fix(content),
208+
token::Literal(token::ByteStr(..), n) => token::Literal(token::ByteStr(nm), n),
209+
token::Literal(token::ByteStrRaw(..), n) => token::Literal(token::ByteStrRaw(fix(content),
210210
count(content)), n),
211211
token::Ident(..) => token::Ident(ast::Ident { name: nm, ctxt: 0 },
212212
token::ModName),
@@ -340,8 +340,8 @@ fn main() {
340340
token::Literal(token::Float(..), _),
341341
token::Literal(token::Str_(..), _),
342342
token::Literal(token::StrRaw(..), _),
343-
token::Literal(token::Binary(..), _),
344-
token::Literal(token::BinaryRaw(..), _),
343+
token::Literal(token::ByteStr(..), _),
344+
token::Literal(token::ByteStrRaw(..), _),
345345
token::Ident(..),
346346
token::Lifetime(..),
347347
token::Interpolated(..),

src/librustc/middle/const_eval.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub enum ConstVal {
269269
Int(i64),
270270
Uint(u64),
271271
Str(InternedString),
272-
Binary(Rc<Vec<u8>>),
272+
ByteStr(Rc<Vec<u8>>),
273273
Bool(bool),
274274
Struct(ast::NodeId),
275275
Tuple(ast::NodeId),
@@ -283,7 +283,7 @@ impl ConstVal {
283283
Int(_) => "positive integer",
284284
Uint(_) => "unsigned integer",
285285
Str(_) => "string literal",
286-
Binary(_) => "binary array",
286+
ByteStr(_) => "byte string literal",
287287
Bool(_) => "boolean",
288288
Struct(_) => "struct",
289289
Tuple(_) => "tuple",
@@ -1175,8 +1175,8 @@ fn cast_const<'tcx>(tcx: &ty::ctxt<'tcx>, val: ConstVal, ty: Ty) -> CastResult {
11751175
fn lit_to_const(lit: &hir::Lit, ty_hint: Option<Ty>) -> ConstVal {
11761176
match lit.node {
11771177
hir::LitStr(ref s, _) => Str((*s).clone()),
1178-
hir::LitBinary(ref data) => {
1179-
Binary(data.clone())
1178+
hir::LitByteStr(ref data) => {
1179+
ByteStr(data.clone())
11801180
}
11811181
hir::LitByte(n) => Uint(n as u64),
11821182
hir::LitChar(n) => Uint(n as u64),
@@ -1214,7 +1214,7 @@ pub fn compare_const_vals(a: &ConstVal, b: &ConstVal) -> Option<Ordering> {
12141214
}
12151215
(&Str(ref a), &Str(ref b)) => a.cmp(b),
12161216
(&Bool(a), &Bool(b)) => a.cmp(&b),
1217-
(&Binary(ref a), &Binary(ref b)) => a.cmp(b),
1217+
(&ByteStr(ref a), &ByteStr(ref b)) => a.cmp(b),
12181218
_ => return None
12191219
})
12201220
}

src/librustc_front/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ pub enum Lit_ {
838838
/// A string literal (`"foo"`)
839839
LitStr(InternedString, StrStyle),
840840
/// A byte string (`b"foo"`)
841-
LitBinary(Rc<Vec<u8>>),
841+
LitByteStr(Rc<Vec<u8>>),
842842
/// A byte char (`b'f'`)
843843
LitByte(u8),
844844
/// A character literal (`'a'`)

src/librustc_front/lowering.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ pub fn lower_lit(l: &Lit) -> hir::Lit {
664664
Spanned {
665665
node: match l.node {
666666
LitStr(ref i, s) => hir::LitStr(i.clone(), lower_string_style(s)),
667-
LitBinary(ref b) => hir::LitBinary(b.clone()),
667+
LitByteStr(ref b) => hir::LitByteStr(b.clone()),
668668
LitByte(u) => hir::LitByte(u),
669669
LitChar(c) => hir::LitChar(c),
670670
LitInt(u, ref t) => hir::LitInt(u, lower_lit_int_type(t)),
@@ -680,7 +680,7 @@ pub fn unlower_lit(l: &hir::Lit) -> Lit {
680680
Spanned {
681681
node: match l.node {
682682
hir::LitStr(ref i, s) => LitStr(i.clone(), unlower_string_style(s)),
683-
hir::LitBinary(ref b) => LitBinary(b.clone()),
683+
hir::LitByteStr(ref b) => LitByteStr(b.clone()),
684684
hir::LitByte(u) => LitByte(u),
685685
hir::LitChar(c) => LitChar(c),
686686
hir::LitInt(u, ref t) => LitInt(u, unlower_lit_int_type(t)),

src/librustc_front/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,7 @@ impl<'a> State<'a> {
25492549
hir::LitBool(val) => {
25502550
if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") }
25512551
}
2552-
hir::LitBinary(ref v) => {
2552+
hir::LitByteStr(ref v) => {
25532553
let mut escaped: String = String::new();
25542554
for &ch in v.iter() {
25552555
escaped.extend(ascii::escape_default(ch)

src/librustc_trans/trans/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &hir::Lit)
9494
}
9595
hir::LitBool(b) => C_bool(cx, b),
9696
hir::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
97-
hir::LitBinary(ref data) => {
98-
addr_of(cx, C_bytes(cx, &data[..]), "binary")
97+
hir::LitByteStr(ref data) => {
98+
addr_of(cx, C_bytes(cx, &data[..]), "byte_str")
9999
}
100100
}
101101
}

0 commit comments

Comments
 (0)