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