diff --git a/mk/crates.mk b/mk/crates.mk index 7ad0a99aada..2b66baed45b 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -58,7 +58,7 @@ RUSTC_CRATES := rustc rustc_typeck rustc_mir rustc_borrowck rustc_resolve rustc_ rustc_trans rustc_back rustc_llvm rustc_privacy rustc_lint \ rustc_data_structures rustc_front rustc_platform_intrinsics \ rustc_plugin rustc_metadata -HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc fmt_macros +HOST_CRATES := syntax syntax_ext $(RUSTC_CRATES) rustdoc fmt_macros TOOLS := compiletest rustdoc rustc rustbook error-index-generator DEPS_core := @@ -86,9 +86,10 @@ DEPS_serialize := std log DEPS_term := std log DEPS_test := std getopts serialize rbml term native:rust_test_helpers -DEPS_syntax := std term serialize log fmt_macros arena libc rustc_bitflags +DEPS_syntax := std term serialize log arena libc rustc_bitflags +DEPS_syntax_ext := syntax fmt_macros -DEPS_rustc := syntax flate arena serialize getopts rbml rustc_front\ +DEPS_rustc := syntax fmt_macros flate arena serialize getopts rbml rustc_front\ log graphviz rustc_llvm rustc_back rustc_data_structures DEPS_rustc_back := std syntax rustc_llvm rustc_front flate log libc DEPS_rustc_borrowck := rustc rustc_front log graphviz syntax @@ -96,7 +97,7 @@ DEPS_rustc_data_structures := std log serialize DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \ rustc_typeck rustc_mir rustc_resolve log syntax serialize rustc_llvm \ rustc_trans rustc_privacy rustc_lint rustc_front rustc_plugin \ - rustc_metadata + rustc_metadata syntax_ext DEPS_rustc_front := std syntax log serialize DEPS_rustc_lint := rustc log syntax DEPS_rustc_llvm := native:rustllvm libc std rustc_bitflags diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 69e065b3e8f..5f2548a5504 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -54,6 +54,7 @@ use syntax::parse::token; use syntax::util::node_count::NodeCounter; use syntax::visit; use syntax; +use syntax_ext; pub fn compile_input(sess: Session, cstore: &CStore, @@ -563,12 +564,15 @@ pub fn phase_2_configure_and_expand(sess: &Session, recursion_limit: sess.recursion_limit.get(), trace_mac: sess.opts.debugging_opts.trace_macros, }; - let (ret, macro_names) = syntax::ext::expand::expand_crate(&sess.parse_sess, - cfg, - macros, - syntax_exts, - &mut feature_gated_cfgs, - krate); + let mut ecx = syntax::ext::base::ExtCtxt::new(&sess.parse_sess, + krate.config.clone(), + cfg, + &mut feature_gated_cfgs); + syntax_ext::register_builtins(&mut ecx.syntax_env); + let (ret, macro_names) = syntax::ext::expand::expand_crate(ecx, + macros, + syntax_exts, + krate); if cfg!(windows) { env::set_var("PATH", &_old_path); } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index e293a950687..fcbcdbacd33 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -57,6 +57,7 @@ extern crate rustc_llvm as llvm; extern crate log; #[macro_use] extern crate syntax; +extern crate syntax_ext; pub use syntax::diagnostic; diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 22315454f89..9d62e407cb9 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -464,26 +464,6 @@ fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>) let mut syntax_expanders = SyntaxEnv::new(); syntax_expanders.insert(intern("macro_rules"), MacroRulesTT); - syntax_expanders.insert(intern("format_args"), - // format_args uses `unstable` things internally. - NormalTT(Box::new(ext::format::expand_format_args), None, true)); - syntax_expanders.insert(intern("env"), - builtin_normal_expander( - ext::env::expand_env)); - syntax_expanders.insert(intern("option_env"), - builtin_normal_expander( - ext::env::expand_option_env)); - syntax_expanders.insert(intern("concat_idents"), - builtin_normal_expander( - ext::concat_idents::expand_syntax_ext)); - syntax_expanders.insert(intern("concat"), - builtin_normal_expander( - ext::concat::expand_syntax_ext)); - syntax_expanders.insert(intern("log_syntax"), - builtin_normal_expander( - ext::log_syntax::expand_syntax_ext)); - - ext::deriving::register_all(&mut syntax_expanders); if ecfg.enable_quotes() { // Quasi-quoting expanders @@ -552,15 +532,6 @@ fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>) syntax_expanders.insert(intern("module_path"), builtin_normal_expander( ext::source_util::expand_mod)); - syntax_expanders.insert(intern("asm"), - builtin_normal_expander( - ext::asm::expand_asm)); - syntax_expanders.insert(intern("cfg"), - builtin_normal_expander( - ext::cfg::expand_cfg)); - syntax_expanders.insert(intern("trace_macros"), - builtin_normal_expander( - ext::trace_macros::expand_trace_macros)); syntax_expanders } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 573f4cfe8fa..a67115e82bb 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -21,7 +21,7 @@ use attr::{AttrMetaMethods, WithAttrs}; use codemap; use codemap::{Span, Spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute}; use ext::base::*; -use feature_gate::{self, Features, GatedCfgAttr}; +use feature_gate::{self, Features}; use fold; use fold::*; use util::move_map::MoveMap; @@ -1276,15 +1276,11 @@ impl<'feat> ExpansionConfig<'feat> { } } -pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess, - cfg: ExpansionConfig<'feat>, - // these are the macros being imported to this crate: - imported_macros: Vec, - user_exts: Vec, - feature_gated_cfgs: &mut Vec, - c: Crate) -> (Crate, HashSet) { - let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg, - feature_gated_cfgs); +pub fn expand_crate(mut cx: ExtCtxt, + // these are the macros being imported to this crate: + imported_macros: Vec, + user_exts: Vec, + c: Crate) -> (Crate, HashSet) { if std_inject::no_core(&c) { cx.crate_root = None; } else if std_inject::no_std(&c) { @@ -1305,7 +1301,7 @@ pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess, let mut ret = expander.fold_crate(c); ret.exported_macros = expander.cx.exported_macros.clone(); - parse_sess.span_diagnostic.handler().abort_if_errors(); + cx.parse_sess.span_diagnostic.handler().abort_if_errors(); ret }; return (ret, cx.syntax_env.names); diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 4498120a78f..73d7025b4f1 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -37,7 +37,6 @@ #![feature(str_escape)] #![feature(unicode)] -extern crate fmt_macros; extern crate serialize; extern crate term; extern crate libc; @@ -110,21 +109,12 @@ pub mod print { } pub mod ext { - pub mod asm; pub mod base; pub mod build; - pub mod cfg; - pub mod concat; - pub mod concat_idents; - pub mod deriving; - pub mod env; pub mod expand; - pub mod format; - pub mod log_syntax; pub mod mtwt; pub mod quote; pub mod source_util; - pub mod trace_macros; pub mod tt { pub mod transcribe; diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax_ext/asm.rs similarity index 97% rename from src/libsyntax/ext/asm.rs rename to src/libsyntax_ext/asm.rs index b4f29f83726..072be571221 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -13,15 +13,15 @@ */ use self::State::*; -use ast; -use codemap; -use codemap::Span; -use ext::base; -use ext::base::*; -use feature_gate; -use parse::token::{intern, InternedString}; -use parse::token; -use ptr::P; +use syntax::ast; +use syntax::codemap; +use syntax::codemap::Span; +use syntax::ext::base; +use syntax::ext::base::*; +use syntax::feature_gate; +use syntax::parse::token::{intern, InternedString}; +use syntax::parse::token; +use syntax::ptr::P; use syntax::ast::AsmDialect; enum State { diff --git a/src/libsyntax/ext/cfg.rs b/src/libsyntax_ext/cfg.rs similarity index 85% rename from src/libsyntax/ext/cfg.rs rename to src/libsyntax_ext/cfg.rs index e100355e4f8..1e1bf538876 100644 --- a/src/libsyntax/ext/cfg.rs +++ b/src/libsyntax_ext/cfg.rs @@ -12,15 +12,15 @@ /// a literal `true` or `false` based on whether the given cfg matches the /// current compilation environment. -use ast; -use codemap::Span; -use ext::base::*; -use ext::base; -use ext::build::AstBuilder; -use attr; -use attr::*; -use parse::token; -use config::CfgDiagReal; +use syntax::ast; +use syntax::codemap::Span; +use syntax::ext::base::*; +use syntax::ext::base; +use syntax::ext::build::AstBuilder; +use syntax::attr; +use syntax::attr::*; +use syntax::parse::token; +use syntax::config::CfgDiagReal; pub fn expand_cfg<'cx>(cx: &mut ExtCtxt, sp: Span, diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax_ext/concat.rs similarity index 95% rename from src/libsyntax/ext/concat.rs rename to src/libsyntax_ext/concat.rs index 71430b7aad5..de913fe0431 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax_ext/concat.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast; -use codemap; -use ext::base; -use ext::build::AstBuilder; -use parse::token; +use syntax::ast; +use syntax::codemap; +use syntax::ext::base; +use syntax::ext::build::AstBuilder; +use syntax::parse::token; use std::string::String; diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs similarity index 91% rename from src/libsyntax/ext/concat_idents.rs rename to src/libsyntax_ext/concat_idents.rs index c2233202b2f..9702b24ffd4 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -8,14 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{self, TokenTree}; -use codemap::Span; -use ext::base::*; -use ext::base; -use feature_gate; -use parse::token; -use parse::token::str_to_ident; -use ptr::P; +use syntax::ast::{self, TokenTree}; +use syntax::codemap::Span; +use syntax::ext::base::*; +use syntax::ext::base; +use syntax::feature_gate; +use syntax::parse::token; +use syntax::parse::token::str_to_ident; +use syntax::ptr::P; pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box { diff --git a/src/libsyntax/ext/deriving/bounds.rs b/src/libsyntax_ext/deriving/bounds.rs similarity index 90% rename from src/libsyntax/ext/deriving/bounds.rs rename to src/libsyntax_ext/deriving/bounds.rs index 87a6d0805b5..9bc0e088110 100644 --- a/src/libsyntax/ext/deriving/bounds.rs +++ b/src/libsyntax_ext/deriving/bounds.rs @@ -8,11 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::MetaItem; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::MetaItem; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs similarity index 93% rename from src/libsyntax/ext/deriving/clone.rs rename to src/libsyntax_ext/deriving/clone.rs index f1a2983479c..1825c3d347e 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, Expr}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_clone(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs similarity index 90% rename from src/libsyntax/ext/deriving/cmp/eq.rs rename to src/libsyntax_ext/deriving/cmp/eq.rs index bd6b27fb44e..1b855c56a48 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, Expr}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_eq(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax_ext/deriving/cmp/ord.rs similarity index 94% rename from src/libsyntax/ext/deriving/cmp/ord.rs rename to src/libsyntax_ext/deriving/cmp/ord.rs index ff36e01d6cc..95a5d184d0e 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax_ext/deriving/cmp/ord.rs @@ -8,15 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast; -use ast::{MetaItem, Expr}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast; +use syntax::ast::{MetaItem, Expr}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_ord(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/cmp/partial_eq.rs b/src/libsyntax_ext/deriving/cmp/partial_eq.rs similarity index 92% rename from src/libsyntax/ext/deriving/cmp/partial_eq.rs rename to src/libsyntax_ext/deriving/cmp/partial_eq.rs index 495761c499b..29be5a7ddc3 100644 --- a/src/libsyntax/ext/deriving/cmp/partial_eq.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_eq.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, Expr, self}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr, self}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs similarity index 96% rename from src/libsyntax/ext/deriving/cmp/partial_ord.rs rename to src/libsyntax_ext/deriving/cmp/partial_ord.rs index 084e3ef3f91..bd825e5c8df 100644 --- a/src/libsyntax/ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -10,15 +10,16 @@ pub use self::OrderingOp::*; -use ast; -use ast::{MetaItem, Expr}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast; +use syntax::ast::{MetaItem, Expr}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs similarity index 95% rename from src/libsyntax/ext/deriving/debug.rs rename to src/libsyntax_ext/deriving/debug.rs index 9488cfb86fc..ed3f764c1d2 100644 --- a/src/libsyntax/ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -8,15 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast; -use ast::{MetaItem, Expr}; -use codemap::{Span, respan}; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast; +use syntax::ast::{MetaItem, Expr}; +use syntax::codemap::{Span, respan}; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token; +use syntax::ptr::P; pub fn expand_deriving_debug(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax_ext/deriving/decodable.rs similarity index 96% rename from src/libsyntax/ext/deriving/decodable.rs rename to src/libsyntax_ext/deriving/decodable.rs index 0fdcbec8447..4ea4f04623a 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax_ext/deriving/decodable.rs @@ -10,16 +10,17 @@ //! The compiler code necessary for `#[derive(Decodable)]`. See encodable.rs for more. -use ast; -use ast::{MetaItem, Expr, MutMutable}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use parse::token; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast; +use syntax::ast::{MetaItem, Expr, MutMutable}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::parse::token; +use syntax::ptr::P; pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/default.rs b/src/libsyntax_ext/deriving/default.rs similarity index 92% rename from src/libsyntax/ext/deriving/default.rs rename to src/libsyntax_ext/deriving/default.rs index 6a25088782a..bee63a98c25 100644 --- a/src/libsyntax/ext/deriving/default.rs +++ b/src/libsyntax_ext/deriving/default.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, Expr}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_default(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax_ext/deriving/encodable.rs similarity index 97% rename from src/libsyntax/ext/deriving/encodable.rs rename to src/libsyntax_ext/deriving/encodable.rs index 786739938e5..02747d38c00 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax_ext/deriving/encodable.rs @@ -88,14 +88,15 @@ //! } //! ``` -use ast::{MetaItem, Expr, ExprRet, MutMutable}; -use codemap::Span; -use ext::base::{ExtCtxt,Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr, ExprRet, MutMutable}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt,Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token; +use syntax::ptr::P; pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs similarity index 95% rename from src/libsyntax/ext/deriving/generic/mod.rs rename to src/libsyntax_ext/deriving/generic/mod.rs index bd89430d81d..5977144dae7 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -192,23 +192,23 @@ use std::cell::RefCell; use std::collections::HashSet; use std::vec; -use abi::Abi; -use abi; -use ast; -use ast::{EnumDef, Expr, Ident, Generics, VariantData}; -use ast_util; -use attr; -use attr::AttrMetaMethods; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use codemap::{self, DUMMY_SP}; -use codemap::Span; -use diagnostic::SpanHandler; -use util::move_map::MoveMap; -use owned_slice::OwnedSlice; -use parse::token::{intern, InternedString}; -use parse::token::special_idents; -use ptr::P; +use syntax::abi::Abi; +use syntax::abi; +use syntax::ast; +use syntax::ast::{EnumDef, Expr, Ident, Generics, VariantData}; +use syntax::ast_util; +use syntax::attr; +use syntax::attr::AttrMetaMethods; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::codemap::{self, DUMMY_SP}; +use syntax::codemap::Span; +use syntax::diagnostic::SpanHandler; +use syntax::util::move_map::MoveMap; +use syntax::owned_slice::OwnedSlice; +use syntax::parse::token::{intern, InternedString}; +use syntax::parse::token::special_idents; +use syntax::ptr::P; use self::ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty}; @@ -347,7 +347,7 @@ pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>) /// type. For a type parameter ``, it looks for either a `TyPath` that /// is not global and starts with `T`, or a `TyQPath`. fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name]) -> Vec> { - use visit; + use syntax::visit; struct Visitor<'a> { ty_param_names: &'a [ast::Name], @@ -1632,73 +1632,3 @@ pub fn cs_same_method(f: F, } } } - -/// Fold together the results of calling the derived method on all the -/// fields. `use_foldl` controls whether this is done left-to-right -/// (`true`) or right-to-left (`false`). -#[inline] -pub fn cs_same_method_fold(use_foldl: bool, - mut f: F, - base: P, - enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, - trait_span: Span, - substructure: &Substructure) - -> P where - F: FnMut(&mut ExtCtxt, Span, P, P) -> P, -{ - cs_same_method( - |cx, span, vals| { - if use_foldl { - vals.into_iter().fold(base.clone(), |old, new| { - f(cx, span, old, new) - }) - } else { - vals.into_iter().rev().fold(base.clone(), |old, new| { - f(cx, span, old, new) - }) - } - }, - enum_nonmatch_f, - cx, trait_span, substructure) -} - -/// Use a given binop to combine the result of calling the derived method -/// on all the fields. -#[inline] -pub fn cs_binop(binop: ast::BinOp_, base: P, - enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, trait_span: Span, - substructure: &Substructure) -> P { - cs_same_method_fold( - true, // foldl is good enough - |cx, span, old, new| { - cx.expr_binary(span, - binop, - old, new) - - }, - base, - enum_nonmatch_f, - cx, trait_span, substructure) -} - -/// cs_binop with binop == or -#[inline] -pub fn cs_or(enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, span: Span, - substructure: &Substructure) -> P { - cs_binop(ast::BiOr, cx.expr_bool(span, false), - enum_nonmatch_f, - cx, span, substructure) -} - -/// cs_binop with binop == and -#[inline] -pub fn cs_and(enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, span: Span, - substructure: &Substructure) -> P { - cs_binop(ast::BiAnd, cx.expr_bool(span, true), - enum_nonmatch_f, - cx, span, substructure) -} diff --git a/src/libsyntax/ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs similarity index 96% rename from src/libsyntax/ext/deriving/generic/ty.rs rename to src/libsyntax_ext/deriving/generic/ty.rs index 67826c9c6cd..0c4a81361ae 100644 --- a/src/libsyntax/ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -14,17 +14,18 @@ pub use self::PtrTy::*; pub use self::Ty::*; -use ast; -use ast::{Expr,Generics,Ident}; -use ext::base::ExtCtxt; -use ext::build::AstBuilder; -use codemap::{Span,respan}; -use owned_slice::OwnedSlice; -use parse::token::special_idents; -use ptr::P; +use syntax::ast; +use syntax::ast::{Expr,Generics,Ident}; +use syntax::ext::base::ExtCtxt; +use syntax::ext::build::AstBuilder; +use syntax::codemap::{Span,respan}; +use syntax::owned_slice::OwnedSlice; +use syntax::parse::token::special_idents; +use syntax::ptr::P; /// The types of pointers #[derive(Clone, Eq, PartialEq)] +#[allow(dead_code)] pub enum PtrTy<'a> { /// &'lifetime mut Borrowed(Option<&'a str>, ast::Mutability), diff --git a/src/libsyntax/ext/deriving/hash.rs b/src/libsyntax_ext/deriving/hash.rs similarity index 93% rename from src/libsyntax/ext/deriving/hash.rs rename to src/libsyntax_ext/deriving/hash.rs index 96be774ebdc..6bd21f7c0e0 100644 --- a/src/libsyntax/ext/deriving/hash.rs +++ b/src/libsyntax_ext/deriving/hash.rs @@ -8,13 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, Expr, MutMutable}; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr, MutMutable}; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::ptr::P; pub fn expand_deriving_hash(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs similarity index 92% rename from src/libsyntax/ext/deriving/mod.rs rename to src/libsyntax_ext/deriving/mod.rs index d26bb794c88..919540724ca 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -13,13 +13,14 @@ //! FIXME (#2810): hygiene. Search for "__" strings (in other files too). We also assume "extra" is //! the standard library, and "std" is the core library. -use ast::{MetaItem, MetaWord}; -use attr::AttrMetaMethods; -use ext::base::{ExtCtxt, SyntaxEnv, MultiDecorator, MultiItemDecorator, MultiModifier, Annotatable}; -use ext::build::AstBuilder; -use feature_gate; -use codemap::Span; -use parse::token::{intern, intern_and_get_ident}; +use syntax::ast::{MetaItem, MetaWord}; +use syntax::attr::AttrMetaMethods; +use syntax::ext::base::{ExtCtxt, SyntaxEnv, Annotatable}; +use syntax::ext::base::{MultiDecorator, MultiItemDecorator, MultiModifier}; +use syntax::ext::build::AstBuilder; +use syntax::feature_gate; +use syntax::codemap::Span; +use syntax::parse::token::{intern, intern_and_get_ident}; macro_rules! pathvec { ($($x:ident)::+) => ( @@ -35,7 +36,7 @@ macro_rules! path { macro_rules! path_local { ($x:ident) => ( - ::ext::deriving::generic::ty::Path::new_local(stringify!($x)) + ::deriving::generic::ty::Path::new_local(stringify!($x)) ) } @@ -51,7 +52,7 @@ macro_rules! pathvec_std { macro_rules! path_std { ($($x:tt)*) => ( - ::ext::deriving::generic::ty::Path::new( pathvec_std!( $($x)* ) ) + ::deriving::generic::ty::Path::new( pathvec_std!( $($x)* ) ) ) } diff --git a/src/libsyntax/ext/deriving/primitive.rs b/src/libsyntax_ext/deriving/primitive.rs similarity index 94% rename from src/libsyntax/ext/deriving/primitive.rs rename to src/libsyntax_ext/deriving/primitive.rs index 07b58778358..121fe01976e 100644 --- a/src/libsyntax/ext/deriving/primitive.rs +++ b/src/libsyntax_ext/deriving/primitive.rs @@ -8,15 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, Expr}; -use ast; -use codemap::Span; -use ext::base::{ExtCtxt, Annotatable}; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use ext::deriving::generic::ty::*; -use parse::token::InternedString; -use ptr::P; +use deriving::generic::*; +use deriving::generic::ty::*; + +use syntax::ast::{MetaItem, Expr}; +use syntax::ast; +use syntax::codemap::Span; +use syntax::ext::base::{ExtCtxt, Annotatable}; +use syntax::ext::build::AstBuilder; +use syntax::parse::token::InternedString; +use syntax::ptr::P; pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, span: Span, diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax_ext/env.rs similarity index 95% rename from src/libsyntax/ext/env.rs rename to src/libsyntax_ext/env.rs index d85071e78af..f1dd6854a3a 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -14,12 +14,12 @@ * interface. */ -use ast; -use codemap::Span; -use ext::base::*; -use ext::base; -use ext::build::AstBuilder; -use parse::token; +use syntax::ast; +use syntax::codemap::Span; +use syntax::ext::base::*; +use syntax::ext::base; +use syntax::ext::build::AstBuilder; +use syntax::parse::token; use std::env; diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax_ext/format.rs similarity index 99% rename from src/libsyntax/ext/format.rs rename to src/libsyntax_ext/format.rs index 904cf0c4776..24094f797e6 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -11,16 +11,17 @@ use self::ArgumentType::*; use self::Position::*; -use ast; -use codemap::{Span, respan}; -use ext::base::*; -use ext::base; -use ext::build::AstBuilder; use fmt_macros as parse; -use fold::Folder; -use parse::token::special_idents; -use parse::token; -use ptr::P; + +use syntax::ast; +use syntax::codemap::{Span, respan}; +use syntax::ext::base::*; +use syntax::ext::base; +use syntax::ext::build::AstBuilder; +use syntax::fold::Folder; +use syntax::parse::token::special_idents; +use syntax::parse::token; +use syntax::ptr::P; use std::collections::HashMap; diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs new file mode 100644 index 00000000000..49c2618d51b --- /dev/null +++ b/src/libsyntax_ext/lib.rs @@ -0,0 +1,82 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Syntax extensions in the Rust compiler. + +#![crate_name = "syntax_ext"] +#![crate_type = "dylib"] +#![crate_type = "rlib"] +#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", + html_favicon_url = "https://doc.rust-lang.org/favicon.ico", + html_root_url = "https://doc.rust-lang.org/nightly/")] + +#![feature(rustc_private)] +#![feature(str_char)] + +extern crate fmt_macros; +extern crate syntax; + +use syntax::ext::base::{MacroExpanderFn, NormalTT}; +use syntax::ext::base::{SyntaxEnv, SyntaxExtension}; +use syntax::parse::token::intern; + +// A variant of 'try!' that panics on Err(FatalError). This is used as a +// crutch on the way towards a non-panic!-prone parser. It should be used +// for fatal parsing errors; eventually we plan to convert all code using +// panictry to just use normal try +macro_rules! panictry { + ($e:expr) => ({ + use std::result::Result::{Ok, Err}; + use syntax::diagnostic::FatalError; + match $e { + Ok(e) => e, + Err(FatalError) => panic!(FatalError) + } + }) +} + +mod asm; +mod cfg; +mod concat; +mod concat_idents; +mod deriving; +mod env; +mod format; +mod log_syntax; +mod trace_macros; + +pub fn register_builtins(env: &mut SyntaxEnv) { + // utility function to simplify creating NormalTT syntax extensions + fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension { + NormalTT(Box::new(f), None, false) + } + + env.insert(intern("asm"), + builtin_normal_expander(asm::expand_asm)); + env.insert(intern("cfg"), + builtin_normal_expander(cfg::expand_cfg)); + env.insert(intern("concat"), + builtin_normal_expander(concat::expand_syntax_ext)); + env.insert(intern("concat_idents"), + builtin_normal_expander(concat_idents::expand_syntax_ext)); + env.insert(intern("env"), + builtin_normal_expander(env::expand_env)); + env.insert(intern("option_env"), + builtin_normal_expander(env::expand_option_env)); + env.insert(intern("format_args"), + // format_args uses `unstable` things internally. + NormalTT(Box::new(format::expand_format_args), None, true)); + env.insert(intern("log_syntax"), + builtin_normal_expander(log_syntax::expand_syntax_ext)); + env.insert(intern("trace_macros"), + builtin_normal_expander(trace_macros::expand_trace_macros)); + + deriving::register_all(env); +} diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax_ext/log_syntax.rs similarity index 92% rename from src/libsyntax/ext/log_syntax.rs rename to src/libsyntax_ext/log_syntax.rs index 5f7ce8d9941..ee944abb645 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax_ext/log_syntax.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast; -use codemap; -use ext::base; -use feature_gate; -use print; +use syntax::ast; +use syntax::codemap; +use syntax::ext::base; +use syntax::feature_gate; +use syntax::print; pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt, sp: codemap::Span, diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax_ext/trace_macros.rs similarity index 89% rename from src/libsyntax/ext/trace_macros.rs rename to src/libsyntax_ext/trace_macros.rs index 628b88d1353..7b1e985442a 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax_ext/trace_macros.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::TokenTree; -use codemap::Span; -use ext::base::ExtCtxt; -use ext::base; -use feature_gate; -use parse::token::keywords; +use syntax::ast::TokenTree; +use syntax::codemap::Span; +use syntax::ext::base::ExtCtxt; +use syntax::ext::base; +use syntax::feature_gate; +use syntax::parse::token::keywords; pub fn expand_trace_macros(cx: &mut ExtCtxt,