proc_macro: move the rustc server to syntax_ext.
This commit is contained in:
parent
38fee305da
commit
8cf463bcff
7 changed files with 33 additions and 33 deletions
|
@ -1599,12 +1599,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc_macro"
|
name = "proc_macro"
|
||||||
version = "0.0.0"
|
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]]
|
[[package]]
|
||||||
name = "profiler_builtins"
|
name = "profiler_builtins"
|
||||||
|
|
|
@ -7,8 +7,3 @@ version = "0.0.0"
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
crate-type = ["dylib"]
|
crate-type = ["dylib"]
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
syntax = { path = "../libsyntax" }
|
|
||||||
syntax_pos = { path = "../libsyntax_pos" }
|
|
||||||
rustc_errors = { path = "../librustc_errors" }
|
|
||||||
rustc_data_structures = { path = "../librustc_data_structures" }
|
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
|
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
|
||||||
|
|
||||||
#![feature(nll)]
|
#![feature(nll)]
|
||||||
#![feature(rustc_private)]
|
|
||||||
#![feature(staged_api)]
|
#![feature(staged_api)]
|
||||||
#![feature(const_fn)]
|
#![feature(const_fn)]
|
||||||
#![feature(extern_types)]
|
#![feature(extern_types)]
|
||||||
|
@ -39,19 +38,10 @@
|
||||||
|
|
||||||
#![recursion_limit="256"]
|
#![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")]
|
#[unstable(feature = "proc_macro_internals", issue = "27812")]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod bridge;
|
pub mod bridge;
|
||||||
|
|
||||||
#[unstable(feature = "proc_macro_internals", issue = "27812")]
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub mod rustc;
|
|
||||||
|
|
||||||
mod diagnostic;
|
mod diagnostic;
|
||||||
|
|
||||||
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
|
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
|
||||||
|
|
|
@ -78,7 +78,7 @@ impl MultiItemModifier for ProcMacroDerive {
|
||||||
let token = Token::interpolated(token::NtItem(item));
|
let token = Token::interpolated(token::NtItem(item));
|
||||||
let input = tokenstream::TokenTree::Token(DUMMY_SP, token).into();
|
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) {
|
let stream = match self.client.run(&EXEC_STRATEGY, server, input) {
|
||||||
Ok(stream) => stream,
|
Ok(stream) => stream,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
|
@ -14,7 +14,10 @@
|
||||||
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
||||||
html_root_url = "https://doc.rust-lang.org/nightly/")]
|
html_root_url = "https://doc.rust-lang.org/nightly/")]
|
||||||
|
|
||||||
|
#![feature(in_band_lifetimes)]
|
||||||
|
#![feature(proc_macro_diagnostic)]
|
||||||
#![feature(proc_macro_internals)]
|
#![feature(proc_macro_internals)]
|
||||||
|
#![feature(proc_macro_span)]
|
||||||
#![feature(decl_macro)]
|
#![feature(decl_macro)]
|
||||||
#![feature(nll)]
|
#![feature(nll)]
|
||||||
#![feature(str_escape)]
|
#![feature(str_escape)]
|
||||||
|
@ -57,6 +60,7 @@ mod test_case;
|
||||||
|
|
||||||
pub mod proc_macro_decls;
|
pub mod proc_macro_decls;
|
||||||
pub mod proc_macro_impl;
|
pub mod proc_macro_impl;
|
||||||
|
mod proc_macro_server;
|
||||||
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl base::AttrProcMacro for AttrProcMacro {
|
||||||
annotation: TokenStream,
|
annotation: TokenStream,
|
||||||
annotated: TokenStream)
|
annotated: TokenStream)
|
||||||
-> 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) {
|
match self.client.run(&EXEC_STRATEGY, server, annotation, annotated) {
|
||||||
Ok(stream) => stream,
|
Ok(stream) => stream,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -61,7 +61,7 @@ impl base::ProcMacro for BangProcMacro {
|
||||||
span: Span,
|
span: Span,
|
||||||
input: TokenStream)
|
input: TokenStream)
|
||||||
-> 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) {
|
match self.client.run(&EXEC_STRATEGY, server, input) {
|
||||||
Ok(stream) => stream,
|
Ok(stream) => stream,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
|
@ -8,11 +8,13 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use bridge::{server, TokenTree};
|
use errors::{self, Diagnostic, DiagnosticBuilder};
|
||||||
use {Delimiter, Level, LineColumn, Spacing};
|
use std::panic;
|
||||||
|
|
||||||
|
use proc_macro::bridge::{server, TokenTree};
|
||||||
|
use proc_macro::{Delimiter, Level, LineColumn, Spacing};
|
||||||
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::{self as errors, Diagnostic, DiagnosticBuilder};
|
|
||||||
use std::ascii;
|
use std::ascii;
|
||||||
use std::ops::Bound;
|
use std::ops::Bound;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
@ -24,7 +26,15 @@ use syntax_pos::hygiene::{SyntaxContext, Transparency};
|
||||||
use syntax_pos::symbol::{keywords, Symbol};
|
use syntax_pos::symbol::{keywords, Symbol};
|
||||||
use syntax_pos::{BytePos, FileName, MultiSpan, Pos, SourceFile, Span};
|
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 {
|
fn from_internal(delim: token::DelimToken) -> Delimiter {
|
||||||
match delim {
|
match delim {
|
||||||
token::Paren => Delimiter::Parenthesis,
|
token::Paren => Delimiter::Parenthesis,
|
||||||
|
@ -33,7 +43,9 @@ impl Delimiter {
|
||||||
token::NoDelim => Delimiter::None,
|
token::NoDelim => Delimiter::None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToInternal<token::DelimToken> for Delimiter {
|
||||||
fn to_internal(self) -> token::DelimToken {
|
fn to_internal(self) -> token::DelimToken {
|
||||||
match self {
|
match self {
|
||||||
Delimiter::Parenthesis => token::Paren,
|
Delimiter::Parenthesis => token::Paren,
|
||||||
|
@ -44,8 +56,10 @@ impl Delimiter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TokenTree<Group, Punct, Ident, Literal> {
|
impl FromInternal<(TokenStream, &'_ ParseSess, &'_ mut Vec<Self>)>
|
||||||
fn from_internal(stream: TokenStream, sess: &ParseSess, stack: &mut Vec<Self>) -> Self {
|
for TokenTree<Group, Punct, Ident, Literal>
|
||||||
|
{
|
||||||
|
fn from_internal((stream, sess, stack): (TokenStream, &ParseSess, &mut Vec<Self>)) -> Self {
|
||||||
use syntax::parse::token::*;
|
use syntax::parse::token::*;
|
||||||
|
|
||||||
let (tree, joint) = stream.as_tree();
|
let (tree, joint) = stream.as_tree();
|
||||||
|
@ -204,7 +218,9 @@ impl TokenTree<Group, Punct, Ident, Literal> {
|
||||||
Whitespace | Comment | Shebang(..) | Eof => unreachable!(),
|
Whitespace | Comment | Shebang(..) | Eof => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
|
||||||
fn to_internal(self) -> TokenStream {
|
fn to_internal(self) -> TokenStream {
|
||||||
use syntax::parse::token::*;
|
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 {
|
fn to_internal(self) -> errors::Level {
|
||||||
match self {
|
match self {
|
||||||
Level::Error => errors::Level::Error,
|
Level::Error => errors::Level::Error,
|
||||||
Level::Warning => errors::Level::Warning,
|
Level::Warning => errors::Level::Warning,
|
||||||
Level::Note => errors::Level::Note,
|
Level::Note => errors::Level::Note,
|
||||||
Level::Help => errors::Level::Help,
|
Level::Help => errors::Level::Help,
|
||||||
|
_ => unreachable!("unknown proc_macro::Level variant: {:?}", self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,7 +356,7 @@ pub struct Literal {
|
||||||
span: Span,
|
span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Rustc<'a> {
|
pub(crate) struct Rustc<'a> {
|
||||||
sess: &'a ParseSess,
|
sess: &'a ParseSess,
|
||||||
def_site: Span,
|
def_site: Span,
|
||||||
call_site: Span,
|
call_site: Span,
|
||||||
|
@ -429,7 +446,7 @@ impl server::TokenStreamIter for Rustc<'_> {
|
||||||
loop {
|
loop {
|
||||||
let tree = iter.stack.pop().or_else(|| {
|
let tree = iter.stack.pop().or_else(|| {
|
||||||
let next = iter.cursor.next_as_stream()?;
|
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
|
// HACK: The condition "dummy span + group with empty delimiter" represents an AST
|
||||||
// fragment approximately converted into a token stream. This may happen, for
|
// fragment approximately converted into a token stream. This may happen, for
|
Loading…
Add table
Add a link
Reference in a new issue