1
1
use ast:: token:: IdentIsRaw ;
2
2
use lint:: BuiltinLintDiag ;
3
- use rustc_ast:: AsmMacro ;
4
3
use rustc_ast:: ptr:: P ;
5
- use rustc_ast:: token:: { self , Delimiter } ;
6
4
use rustc_ast:: tokenstream:: TokenStream ;
5
+ use rustc_ast:: { AsmMacro , token} ;
7
6
use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
8
7
use rustc_errors:: PResult ;
9
8
use rustc_expand:: base:: * ;
10
9
use rustc_index:: bit_set:: GrowableBitSet ;
11
- use rustc_parse:: parser:: Parser ;
10
+ use rustc_parse:: exp;
11
+ use rustc_parse:: parser:: { ExpKeywordPair , Parser } ;
12
12
use rustc_session:: lint;
13
- use rustc_span:: { ErrorGuaranteed , Ident , InnerSpan , Span , Symbol , kw, sym } ;
13
+ use rustc_span:: { ErrorGuaranteed , Ident , InnerSpan , Span , Symbol , kw} ;
14
14
use rustc_target:: asm:: InlineAsmArch ;
15
15
use smallvec:: smallvec;
16
16
use { rustc_ast as ast, rustc_parse_format as parse} ;
@@ -38,16 +38,16 @@ pub struct AsmArgs {
38
38
/// - `Err(_)` if the current token matches the keyword, but was not expected
39
39
fn eat_operand_keyword < ' a > (
40
40
p : & mut Parser < ' a > ,
41
- symbol : Symbol ,
41
+ exp : ExpKeywordPair ,
42
42
asm_macro : AsmMacro ,
43
43
) -> PResult < ' a , bool > {
44
44
if matches ! ( asm_macro, AsmMacro :: Asm ) {
45
- Ok ( p. eat_keyword ( symbol ) )
45
+ Ok ( p. eat_keyword ( exp ) )
46
46
} else {
47
47
let span = p. token . span ;
48
- if p. eat_keyword_noexpect ( symbol ) {
48
+ if p. eat_keyword_noexpect ( exp . kw ) {
49
49
// in gets printed as `r#in` otherwise
50
- let symbol = if symbol == kw:: In { "in" } else { symbol . as_str ( ) } ;
50
+ let symbol = if exp . kw == kw:: In { "in" } else { exp . kw . as_str ( ) } ;
51
51
Err ( p. dcx ( ) . create_err ( errors:: AsmUnsupportedOperand {
52
52
span,
53
53
symbol,
@@ -95,28 +95,28 @@ pub fn parse_asm_args<'a>(
95
95
96
96
let mut allow_templates = true ;
97
97
while p. token != token:: Eof {
98
- if !p. eat ( & token :: Comma ) {
98
+ if !p. eat ( exp ! ( Comma ) ) {
99
99
if allow_templates {
100
100
// After a template string, we always expect *only* a comma...
101
101
return Err ( dcx. create_err ( errors:: AsmExpectedComma { span : p. token . span } ) ) ;
102
102
} else {
103
103
// ...after that delegate to `expect` to also include the other expected tokens.
104
- return Err ( p. expect ( & token :: Comma ) . err ( ) . unwrap ( ) ) ;
104
+ return Err ( p. expect ( exp ! ( Comma ) ) . err ( ) . unwrap ( ) ) ;
105
105
}
106
106
}
107
107
if p. token == token:: Eof {
108
108
break ;
109
109
} // accept trailing commas
110
110
111
111
// Parse clobber_abi
112
- if p. eat_keyword ( sym :: clobber_abi ) {
112
+ if p. eat_keyword ( exp ! ( ClobberAbi ) ) {
113
113
parse_clobber_abi ( p, & mut args) ?;
114
114
allow_templates = false ;
115
115
continue ;
116
116
}
117
117
118
118
// Parse options
119
- if p. eat_keyword ( sym :: options ) {
119
+ if p. eat_keyword ( exp ! ( Options ) ) {
120
120
parse_options ( p, & mut args, asm_macro) ?;
121
121
allow_templates = false ;
122
122
continue ;
@@ -128,65 +128,65 @@ pub fn parse_asm_args<'a>(
128
128
let name = if p. token . is_ident ( ) && p. look_ahead ( 1 , |t| * t == token:: Eq ) {
129
129
let ( ident, _) = p. token . ident ( ) . unwrap ( ) ;
130
130
p. bump ( ) ;
131
- p. expect ( & token :: Eq ) ?;
131
+ p. expect ( exp ! ( Eq ) ) ?;
132
132
allow_templates = false ;
133
133
Some ( ident. name )
134
134
} else {
135
135
None
136
136
} ;
137
137
138
138
let mut explicit_reg = false ;
139
- let op = if eat_operand_keyword ( p, kw :: In , asm_macro) ? {
139
+ let op = if eat_operand_keyword ( p, exp ! ( In ) , asm_macro) ? {
140
140
let reg = parse_reg ( p, & mut explicit_reg) ?;
141
- if p. eat_keyword ( kw :: Underscore ) {
141
+ if p. eat_keyword ( exp ! ( Underscore ) ) {
142
142
let err = dcx. create_err ( errors:: AsmUnderscoreInput { span : p. token . span } ) ;
143
143
return Err ( err) ;
144
144
}
145
145
let expr = p. parse_expr ( ) ?;
146
146
ast:: InlineAsmOperand :: In { reg, expr }
147
- } else if eat_operand_keyword ( p, sym :: out , asm_macro) ? {
147
+ } else if eat_operand_keyword ( p, exp ! ( Out ) , asm_macro) ? {
148
148
let reg = parse_reg ( p, & mut explicit_reg) ?;
149
- let expr = if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
149
+ let expr = if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
150
150
ast:: InlineAsmOperand :: Out { reg, expr, late : false }
151
- } else if eat_operand_keyword ( p, sym :: lateout , asm_macro) ? {
151
+ } else if eat_operand_keyword ( p, exp ! ( Lateout ) , asm_macro) ? {
152
152
let reg = parse_reg ( p, & mut explicit_reg) ?;
153
- let expr = if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
153
+ let expr = if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
154
154
ast:: InlineAsmOperand :: Out { reg, expr, late : true }
155
- } else if eat_operand_keyword ( p, sym :: inout , asm_macro) ? {
155
+ } else if eat_operand_keyword ( p, exp ! ( Inout ) , asm_macro) ? {
156
156
let reg = parse_reg ( p, & mut explicit_reg) ?;
157
- if p. eat_keyword ( kw :: Underscore ) {
157
+ if p. eat_keyword ( exp ! ( Underscore ) ) {
158
158
let err = dcx. create_err ( errors:: AsmUnderscoreInput { span : p. token . span } ) ;
159
159
return Err ( err) ;
160
160
}
161
161
let expr = p. parse_expr ( ) ?;
162
- if p. eat ( & token :: FatArrow ) {
162
+ if p. eat ( exp ! ( FatArrow ) ) {
163
163
let out_expr =
164
- if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
164
+ if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
165
165
ast:: InlineAsmOperand :: SplitInOut { reg, in_expr : expr, out_expr, late : false }
166
166
} else {
167
167
ast:: InlineAsmOperand :: InOut { reg, expr, late : false }
168
168
}
169
- } else if eat_operand_keyword ( p, sym :: inlateout , asm_macro) ? {
169
+ } else if eat_operand_keyword ( p, exp ! ( Inlateout ) , asm_macro) ? {
170
170
let reg = parse_reg ( p, & mut explicit_reg) ?;
171
- if p. eat_keyword ( kw :: Underscore ) {
171
+ if p. eat_keyword ( exp ! ( Underscore ) ) {
172
172
let err = dcx. create_err ( errors:: AsmUnderscoreInput { span : p. token . span } ) ;
173
173
return Err ( err) ;
174
174
}
175
175
let expr = p. parse_expr ( ) ?;
176
- if p. eat ( & token :: FatArrow ) {
176
+ if p. eat ( exp ! ( FatArrow ) ) {
177
177
let out_expr =
178
- if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
178
+ if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
179
179
ast:: InlineAsmOperand :: SplitInOut { reg, in_expr : expr, out_expr, late : true }
180
180
} else {
181
181
ast:: InlineAsmOperand :: InOut { reg, expr, late : true }
182
182
}
183
- } else if eat_operand_keyword ( p, sym :: label , asm_macro) ? {
183
+ } else if eat_operand_keyword ( p, exp ! ( Label ) , asm_macro) ? {
184
184
let block = p. parse_block ( ) ?;
185
185
ast:: InlineAsmOperand :: Label { block }
186
- } else if p. eat_keyword ( kw :: Const ) {
186
+ } else if p. eat_keyword ( exp ! ( Const ) ) {
187
187
let anon_const = p. parse_expr_anon_const ( ) ?;
188
188
ast:: InlineAsmOperand :: Const { anon_const }
189
- } else if p. eat_keyword ( sym :: sym ) {
189
+ } else if p. eat_keyword ( exp ! ( Sym ) ) {
190
190
let expr = p. parse_expr ( ) ?;
191
191
let ast:: ExprKind :: Path ( qself, path) = & expr. kind else {
192
192
let err = dcx. create_err ( errors:: AsmSymNoPath { span : expr. span } ) ;
@@ -389,31 +389,31 @@ fn parse_options<'a>(
389
389
) -> PResult < ' a , ( ) > {
390
390
let span_start = p. prev_token . span ;
391
391
392
- p. expect ( & token :: OpenDelim ( Delimiter :: Parenthesis ) ) ?;
393
-
394
- while !p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
395
- const OPTIONS : [ ( Symbol , ast:: InlineAsmOptions ) ; ast:: InlineAsmOptions :: COUNT ] = [
396
- ( sym :: pure , ast:: InlineAsmOptions :: PURE ) ,
397
- ( sym :: nomem , ast:: InlineAsmOptions :: NOMEM ) ,
398
- ( sym :: readonly , ast:: InlineAsmOptions :: READONLY ) ,
399
- ( sym :: preserves_flags , ast:: InlineAsmOptions :: PRESERVES_FLAGS ) ,
400
- ( sym :: noreturn , ast:: InlineAsmOptions :: NORETURN ) ,
401
- ( sym :: nostack , ast:: InlineAsmOptions :: NOSTACK ) ,
402
- ( sym :: may_unwind , ast:: InlineAsmOptions :: MAY_UNWIND ) ,
403
- ( sym :: att_syntax , ast:: InlineAsmOptions :: ATT_SYNTAX ) ,
404
- ( kw :: Raw , ast:: InlineAsmOptions :: RAW ) ,
392
+ p. expect ( exp ! ( OpenParen ) ) ?;
393
+
394
+ while !p. eat ( exp ! ( CloseParen ) ) {
395
+ const OPTIONS : [ ( ExpKeywordPair , ast:: InlineAsmOptions ) ; ast:: InlineAsmOptions :: COUNT ] = [
396
+ ( exp ! ( Pure ) , ast:: InlineAsmOptions :: PURE ) ,
397
+ ( exp ! ( Nomem ) , ast:: InlineAsmOptions :: NOMEM ) ,
398
+ ( exp ! ( Readonly ) , ast:: InlineAsmOptions :: READONLY ) ,
399
+ ( exp ! ( PreservesFlags ) , ast:: InlineAsmOptions :: PRESERVES_FLAGS ) ,
400
+ ( exp ! ( Noreturn ) , ast:: InlineAsmOptions :: NORETURN ) ,
401
+ ( exp ! ( Nostack ) , ast:: InlineAsmOptions :: NOSTACK ) ,
402
+ ( exp ! ( MayUnwind ) , ast:: InlineAsmOptions :: MAY_UNWIND ) ,
403
+ ( exp ! ( AttSyntax ) , ast:: InlineAsmOptions :: ATT_SYNTAX ) ,
404
+ ( exp ! ( Raw ) , ast:: InlineAsmOptions :: RAW ) ,
405
405
] ;
406
406
407
407
' blk: {
408
- for ( symbol , option) in OPTIONS {
408
+ for ( exp , option) in OPTIONS {
409
409
let kw_matched = if asm_macro. is_supported_option ( option) {
410
- p. eat_keyword ( symbol )
410
+ p. eat_keyword ( exp )
411
411
} else {
412
- p. eat_keyword_noexpect ( symbol )
412
+ p. eat_keyword_noexpect ( exp . kw )
413
413
} ;
414
414
415
415
if kw_matched {
416
- try_set_option ( p, args, asm_macro, symbol , option) ;
416
+ try_set_option ( p, args, asm_macro, exp . kw , option) ;
417
417
break ' blk;
418
418
}
419
419
}
@@ -422,10 +422,10 @@ fn parse_options<'a>(
422
422
}
423
423
424
424
// Allow trailing commas
425
- if p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
425
+ if p. eat ( exp ! ( CloseParen ) ) {
426
426
break ;
427
427
}
428
- p. expect ( & token :: Comma ) ?;
428
+ p. expect ( exp ! ( Comma ) ) ?;
429
429
}
430
430
431
431
let new_span = span_start. to ( p. prev_token . span ) ;
@@ -437,14 +437,14 @@ fn parse_options<'a>(
437
437
fn parse_clobber_abi < ' a > ( p : & mut Parser < ' a > , args : & mut AsmArgs ) -> PResult < ' a , ( ) > {
438
438
let span_start = p. prev_token . span ;
439
439
440
- p. expect ( & token :: OpenDelim ( Delimiter :: Parenthesis ) ) ?;
440
+ p. expect ( exp ! ( OpenParen ) ) ?;
441
441
442
- if p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
442
+ if p. eat ( exp ! ( CloseParen ) ) {
443
443
return Err ( p. dcx ( ) . create_err ( errors:: NonABI { span : p. token . span } ) ) ;
444
444
}
445
445
446
446
let mut new_abis = Vec :: new ( ) ;
447
- while !p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
447
+ while !p. eat ( exp ! ( CloseParen ) ) {
448
448
match p. parse_str_lit ( ) {
449
449
Ok ( str_lit) => {
450
450
new_abis. push ( ( str_lit. symbol_unescaped , str_lit. span ) ) ;
@@ -456,10 +456,10 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
456
456
} ;
457
457
458
458
// Allow trailing commas
459
- if p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
459
+ if p. eat ( exp ! ( CloseParen ) ) {
460
460
break ;
461
461
}
462
- p. expect ( & token :: Comma ) ?;
462
+ p. expect ( exp ! ( Comma ) ) ?;
463
463
}
464
464
465
465
let full_span = span_start. to ( p. prev_token . span ) ;
@@ -482,7 +482,7 @@ fn parse_reg<'a>(
482
482
p : & mut Parser < ' a > ,
483
483
explicit_reg : & mut bool ,
484
484
) -> PResult < ' a , ast:: InlineAsmRegOrRegClass > {
485
- p. expect ( & token :: OpenDelim ( Delimiter :: Parenthesis ) ) ?;
485
+ p. expect ( exp ! ( OpenParen ) ) ?;
486
486
let result = match p. token . uninterpolate ( ) . kind {
487
487
token:: Ident ( name, IdentIsRaw :: No ) => ast:: InlineAsmRegOrRegClass :: RegClass ( name) ,
488
488
token:: Literal ( token:: Lit { kind : token:: LitKind :: Str , symbol, suffix : _ } ) => {
@@ -496,7 +496,7 @@ fn parse_reg<'a>(
496
496
}
497
497
} ;
498
498
p. bump ( ) ;
499
- p. expect ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) ?;
499
+ p. expect ( exp ! ( CloseParen ) ) ?;
500
500
Ok ( result)
501
501
}
502
502
0 commit comments