88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- /*
12- * Inline assembly support.
13- */
11+ // Inline assembly support.
12+ //
1413use self :: State :: * ;
1514
1615use syntax:: ast;
@@ -31,43 +30,48 @@ enum State {
3130 Inputs ,
3231 Clobbers ,
3332 Options ,
34- StateNone
33+ StateNone ,
3534}
3635
3736impl State {
3837 fn next ( & self ) -> State {
3938 match * self {
40- Asm => Outputs ,
41- Outputs => Inputs ,
42- Inputs => Clobbers ,
43- Clobbers => Options ,
44- Options => StateNone ,
45- StateNone => StateNone
39+ Asm => Outputs ,
40+ Outputs => Inputs ,
41+ Inputs => Clobbers ,
42+ Clobbers => Options ,
43+ Options => StateNone ,
44+ StateNone => StateNone ,
4645 }
4746 }
4847}
4948
5049const OPTIONS : & ' static [ & ' static str ] = & [ "volatile" , "alignstack" , "intel" ] ;
5150
52- pub fn expand_asm < ' cx > ( cx : & ' cx mut ExtCtxt , sp : Span , tts : & [ tokenstream:: TokenTree ] )
53- -> Box < base:: MacResult +' cx > {
51+ pub fn expand_asm < ' cx > ( cx : & ' cx mut ExtCtxt ,
52+ sp : Span ,
53+ tts : & [ tokenstream:: TokenTree ] )
54+ -> Box < base:: MacResult + ' cx > {
5455 if !cx. ecfg . enable_asm ( ) {
55- feature_gate:: emit_feature_err (
56- & cx. parse_sess . span_diagnostic , "asm" , sp,
57- feature_gate:: GateIssue :: Language ,
58- feature_gate:: EXPLAIN_ASM ) ;
56+ feature_gate:: emit_feature_err ( & cx. parse_sess . span_diagnostic ,
57+ "asm" ,
58+ sp,
59+ feature_gate:: GateIssue :: Language ,
60+ feature_gate:: EXPLAIN_ASM ) ;
5961 return DummyResult :: expr ( sp) ;
6062 }
6163
6264 // Split the tts before the first colon, to avoid `asm!("x": y)` being
6365 // parsed as `asm!(z)` with `z = "x": y` which is type ascription.
64- let first_colon = tts. iter ( ) . position ( |tt| {
65- match * tt {
66- tokenstream:: TokenTree :: Token ( _, token:: Colon ) |
67- tokenstream:: TokenTree :: Token ( _, token:: ModSep ) => true ,
68- _ => false
69- }
70- } ) . unwrap_or ( tts. len ( ) ) ;
66+ let first_colon = tts. iter ( )
67+ . position ( |tt| {
68+ match * tt {
69+ tokenstream:: TokenTree :: Token ( _, token:: Colon ) |
70+ tokenstream:: TokenTree :: Token ( _, token:: ModSep ) => true ,
71+ _ => false ,
72+ }
73+ } )
74+ . unwrap_or ( tts. len ( ) ) ;
7175 let mut p = cx. new_parser_from_tts ( & tts[ first_colon..] ) ;
7276 let mut asm = token:: InternedString :: new ( "" ) ;
7377 let mut asm_str_style = None ;
@@ -91,8 +95,9 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::Token
9195 }
9296 // Nested parser, stop before the first colon (see above).
9397 let mut p2 = cx. new_parser_from_tts ( & tts[ ..first_colon] ) ;
94- let ( s, style) = match expr_to_string ( cx, panictry ! ( p2. parse_expr( ) ) ,
95- "inline assembly must be a string literal" ) {
98+ let ( s, style) = match expr_to_string ( cx,
99+ panictry ! ( p2. parse_expr( ) ) ,
100+ "inline assembly must be a string literal" ) {
96101 Some ( ( s, st) ) => ( s, st) ,
97102 // let compilation continue
98103 None => return DummyResult :: expr ( sp) ,
@@ -109,9 +114,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::Token
109114 asm_str_style = Some ( style) ;
110115 }
111116 Outputs => {
112- while p. token != token:: Eof &&
113- p. token != token:: Colon &&
114- p. token != token:: ModSep {
117+ while p. token != token:: Eof && p. token != token:: Colon && p. token != token:: ModSep {
115118
116119 if !outputs. is_empty ( ) {
117120 p. eat ( & token:: Comma ) ;
@@ -136,8 +139,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::Token
136139 let output = match ch. next ( ) {
137140 Some ( '=' ) => None ,
138141 Some ( '+' ) => {
139- Some ( token:: intern_and_get_ident ( & format ! (
140- "={}" , ch. as_str( ) ) ) )
142+ Some ( token:: intern_and_get_ident ( & format ! ( "={}" , ch. as_str( ) ) ) )
141143 }
142144 _ => {
143145 cx. span_err ( span, "output operand constraint lacks '=' or '+'" ) ;
@@ -156,9 +158,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::Token
156158 }
157159 }
158160 Inputs => {
159- while p. token != token:: Eof &&
160- p. token != token:: Colon &&
161- p. token != token:: ModSep {
161+ while p. token != token:: Eof && p. token != token:: Colon && p. token != token:: ModSep {
162162
163163 if !inputs. is_empty ( ) {
164164 p. eat ( & token:: Comma ) ;
@@ -180,9 +180,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::Token
180180 }
181181 }
182182 Clobbers => {
183- while p. token != token:: Eof &&
184- p. token != token:: Colon &&
185- p. token != token:: ModSep {
183+ while p. token != token:: Eof && p. token != token:: Colon && p. token != token:: ModSep {
186184
187185 if !clobs. is_empty ( ) {
188186 p. eat ( & token:: Comma ) ;
@@ -218,25 +216,25 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::Token
218216 p. eat ( & token:: Comma ) ;
219217 }
220218 }
221- StateNone => ( )
219+ StateNone => ( ) ,
222220 }
223221
224222 loop {
225223 // MOD_SEP is a double colon '::' without space in between.
226224 // When encountered, the state must be advanced twice.
227225 match ( & p. token , state. next ( ) , state. next ( ) . next ( ) ) {
228- ( & token:: Colon , StateNone , _) |
226+ ( & token:: Colon , StateNone , _) |
229227 ( & token:: ModSep , _, StateNone ) => {
230228 p. bump ( ) ;
231229 break ' statement;
232230 }
233- ( & token:: Colon , st, _) |
231+ ( & token:: Colon , st, _) |
234232 ( & token:: ModSep , _, st) => {
235233 p. bump ( ) ;
236234 state = st;
237235 }
238236 ( & token:: Eof , _, _) => break ' statement,
239- _ => break
237+ _ => break ,
240238 }
241239 }
242240 }
0 commit comments