diff options
| author | Stein Somers <git@steinsomers.be> | 2019-01-09 15:15:18 +0100 |
|---|---|---|
| committer | Stein Somers <git@steinsomers.be> | 2019-01-09 15:15:18 +0100 |
| commit | ccba43df81d5bda37c9e4d231ad4443e6f3a7e44 (patch) | |
| tree | efe674e2d5ae721f38fa8558385e0a2f12997227 /src/libsyntax_ext/global_asm.rs | |
| parent | f9f71cc32497ee4e3cbc7d9795bcf358a9268c13 (diff) | |
| parent | 664c7797f6bfddf9f5e67474c2fd8017f91d7110 (diff) | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/libsyntax_ext/global_asm.rs')
| -rw-r--r-- | src/libsyntax_ext/global_asm.rs | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/src/libsyntax_ext/global_asm.rs b/src/libsyntax_ext/global_asm.rs index 000bede7348..0a12e27c4fc 100644 --- a/src/libsyntax_ext/global_asm.rs +++ b/src/libsyntax_ext/global_asm.rs @@ -1,13 +1,3 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - /// Module-level assembly support. /// /// The macro defined here allows you to specify "top-level", @@ -18,11 +8,13 @@ /// LLVM's `module asm "some assembly here"`. All of LLVM's caveats /// therefore apply. +use errors::DiagnosticBuilder; use syntax::ast; use syntax::source_map::respan; use syntax::ext::base; use syntax::ext::base::*; use syntax::feature_gate; +use syntax::parse::token; use syntax::ptr::P; use syntax::symbol::Symbol; use syntax_pos::Span; @@ -39,27 +31,49 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt, sp, feature_gate::GateIssue::Language, feature_gate::EXPLAIN_GLOBAL_ASM); - return DummyResult::any(sp); } + match parse_global_asm(cx, sp, tts) { + Ok(Some(global_asm)) => { + MacEager::items(smallvec![P(ast::Item { + ident: ast::Ident::with_empty_ctxt(Symbol::intern("")), + attrs: Vec::new(), + id: ast::DUMMY_NODE_ID, + node: ast::ItemKind::GlobalAsm(P(global_asm)), + vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited), + span: sp, + tokens: None, + })]) + } + Ok(None) => DummyResult::any(sp), + Err(mut err) => { + err.emit(); + DummyResult::any(sp) + } + } +} + +fn parse_global_asm<'a>( + cx: &mut ExtCtxt<'a>, + sp: Span, + tts: &[tokenstream::TokenTree] +) -> Result<Option<ast::GlobalAsm>, DiagnosticBuilder<'a>> { let mut p = cx.new_parser_from_tts(tts); - let (asm, _) = match expr_to_string(cx, - panictry!(p.parse_expr()), - "inline assembly must be a string literal") { + + if p.token == token::Eof { + let mut err = cx.struct_span_err(sp, "macro requires a string literal as an argument"); + err.span_label(sp, "string literal required"); + return Err(err); + } + + let expr = p.parse_expr()?; + let (asm, _) = match expr_to_string(cx, expr, "inline assembly must be a string literal") { Some((s, st)) => (s, st), - None => return DummyResult::any(sp), + None => return Ok(None), }; - MacEager::items(smallvec![P(ast::Item { - ident: ast::Ident::with_empty_ctxt(Symbol::intern("")), - attrs: Vec::new(), - id: ast::DUMMY_NODE_ID, - node: ast::ItemKind::GlobalAsm(P(ast::GlobalAsm { - asm, - ctxt: cx.backtrace(), - })), - vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited), - span: sp, - tokens: None, - })]) + Ok(Some(ast::GlobalAsm { + asm, + ctxt: cx.backtrace(), + })) } |
