proc_macro: move the rustc server to syntax_ext.

This commit is contained in:
Eduard-Mihai Burtescu 2018-03-20 16:41:14 +02:00
parent 38fee305da
commit 8cf463bcff
7 changed files with 33 additions and 33 deletions

View File

@ -1599,12 +1599,6 @@ dependencies = [
[[package]]
name = "proc_macro"
version = "0.0.0"
dependencies = [
"rustc_data_structures 0.0.0",
"rustc_errors 0.0.0",
"syntax 0.0.0",
"syntax_pos 0.0.0",
]
[[package]]
name = "profiler_builtins"

View File

@ -7,8 +7,3 @@ version = "0.0.0"
path = "lib.rs"
crate-type = ["dylib"]
[dependencies]
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_errors = { path = "../librustc_errors" }
rustc_data_structures = { path = "../librustc_data_structures" }

View File

@ -28,7 +28,6 @@
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
#![feature(nll)]
#![feature(rustc_private)]
#![feature(staged_api)]
#![feature(const_fn)]
#![feature(extern_types)]
@ -39,19 +38,10 @@
#![recursion_limit="256"]
extern crate syntax;
extern crate syntax_pos;
extern crate rustc_errors;
extern crate rustc_data_structures;
#[unstable(feature = "proc_macro_internals", issue = "27812")]
#[doc(hidden)]
pub mod bridge;
#[unstable(feature = "proc_macro_internals", issue = "27812")]
#[doc(hidden)]
pub mod rustc;
mod diagnostic;
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]

View File

@ -78,7 +78,7 @@ impl MultiItemModifier for ProcMacroDerive {
let token = Token::interpolated(token::NtItem(item));
let input = tokenstream::TokenTree::Token(DUMMY_SP, token).into();
let server = ::proc_macro::rustc::Rustc::new(ecx);
let server = ::proc_macro_server::Rustc::new(ecx);
let stream = match self.client.run(&EXEC_STRATEGY, server, input) {
Ok(stream) => stream,
Err(e) => {

View File

@ -14,7 +14,10 @@
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(in_band_lifetimes)]
#![feature(proc_macro_diagnostic)]
#![feature(proc_macro_internals)]
#![feature(proc_macro_span)]
#![feature(decl_macro)]
#![feature(nll)]
#![feature(str_escape)]
@ -57,6 +60,7 @@ mod test_case;
pub mod proc_macro_decls;
pub mod proc_macro_impl;
mod proc_macro_server;
use rustc_data_structures::sync::Lrc;
use syntax::ast;

View File

@ -32,7 +32,7 @@ impl base::AttrProcMacro for AttrProcMacro {
annotation: TokenStream,
annotated: TokenStream)
-> TokenStream {
let server = ::proc_macro::rustc::Rustc::new(ecx);
let server = ::proc_macro_server::Rustc::new(ecx);
match self.client.run(&EXEC_STRATEGY, server, annotation, annotated) {
Ok(stream) => stream,
Err(e) => {
@ -61,7 +61,7 @@ impl base::ProcMacro for BangProcMacro {
span: Span,
input: TokenStream)
-> TokenStream {
let server = ::proc_macro::rustc::Rustc::new(ecx);
let server = ::proc_macro_server::Rustc::new(ecx);
match self.client.run(&EXEC_STRATEGY, server, input) {
Ok(stream) => stream,
Err(e) => {

View File

@ -8,11 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use bridge::{server, TokenTree};
use {Delimiter, Level, LineColumn, Spacing};
use errors::{self, Diagnostic, DiagnosticBuilder};
use std::panic;
use proc_macro::bridge::{server, TokenTree};
use proc_macro::{Delimiter, Level, LineColumn, Spacing};
use rustc_data_structures::sync::Lrc;
use rustc_errors::{self as errors, Diagnostic, DiagnosticBuilder};
use std::ascii;
use std::ops::Bound;
use syntax::ast;
@ -24,7 +26,15 @@ use syntax_pos::hygiene::{SyntaxContext, Transparency};
use syntax_pos::symbol::{keywords, Symbol};
use syntax_pos::{BytePos, FileName, MultiSpan, Pos, SourceFile, Span};
impl Delimiter {
trait FromInternal<T> {
fn from_internal(x: T) -> Self;
}
trait ToInternal<T> {
fn to_internal(self) -> T;
}
impl FromInternal<token::DelimToken> for Delimiter {
fn from_internal(delim: token::DelimToken) -> Delimiter {
match delim {
token::Paren => Delimiter::Parenthesis,
@ -33,7 +43,9 @@ impl Delimiter {
token::NoDelim => Delimiter::None,
}
}
}
impl ToInternal<token::DelimToken> for Delimiter {
fn to_internal(self) -> token::DelimToken {
match self {
Delimiter::Parenthesis => token::Paren,
@ -44,8 +56,10 @@ impl Delimiter {
}
}
impl TokenTree<Group, Punct, Ident, Literal> {
fn from_internal(stream: TokenStream, sess: &ParseSess, stack: &mut Vec<Self>) -> Self {
impl FromInternal<(TokenStream, &'_ ParseSess, &'_ mut Vec<Self>)>
for TokenTree<Group, Punct, Ident, Literal>
{
fn from_internal((stream, sess, stack): (TokenStream, &ParseSess, &mut Vec<Self>)) -> Self {
use syntax::parse::token::*;
let (tree, joint) = stream.as_tree();
@ -204,7 +218,9 @@ impl TokenTree<Group, Punct, Ident, Literal> {
Whitespace | Comment | Shebang(..) | Eof => unreachable!(),
}
}
}
impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
fn to_internal(self) -> TokenStream {
use syntax::parse::token::*;
@ -292,13 +308,14 @@ impl TokenTree<Group, Punct, Ident, Literal> {
}
}
impl Level {
impl ToInternal<errors::Level> for Level {
fn to_internal(self) -> errors::Level {
match self {
Level::Error => errors::Level::Error,
Level::Warning => errors::Level::Warning,
Level::Note => errors::Level::Note,
Level::Help => errors::Level::Help,
_ => unreachable!("unknown proc_macro::Level variant: {:?}", self),
}
}
}
@ -339,7 +356,7 @@ pub struct Literal {
span: Span,
}
pub struct Rustc<'a> {
pub(crate) struct Rustc<'a> {
sess: &'a ParseSess,
def_site: Span,
call_site: Span,
@ -429,7 +446,7 @@ impl server::TokenStreamIter for Rustc<'_> {
loop {
let tree = iter.stack.pop().or_else(|| {
let next = iter.cursor.next_as_stream()?;
Some(TokenTree::from_internal(next, self.sess, &mut iter.stack))
Some(TokenTree::from_internal((next, self.sess, &mut iter.stack)))
})?;
// HACK: The condition "dummy span + group with empty delimiter" represents an AST
// fragment approximately converted into a token stream. This may happen, for