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