diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-06-24 19:24:51 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-06-30 01:53:32 +0300 |
| commit | 09856c85b73feff1db93990cd3d80f2c585b40c4 (patch) | |
| tree | fb0ad936c77b081e9b99160e78be675faa7c9844 /src/libsyntax | |
| parent | 1328bdeef8451779831d3ddc26e16ee64c3d65b5 (diff) | |
| download | rust-09856c85b73feff1db93990cd3d80f2c585b40c4.tar.gz rust-09856c85b73feff1db93990cd3d80f2c585b40c4.zip | |
expansion: Give names to some fields of `SyntaxExtension`
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 30 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 6 |
3 files changed, 26 insertions, 20 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 9afce74f53c..78fa3f326d6 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -597,11 +597,11 @@ pub enum SyntaxExtension { MultiModifier(Box<MultiItemModifier + sync::Sync + sync::Send>), /// A function-like procedural macro. TokenStream -> TokenStream. - ProcMacro( - /* expander: */ Box<ProcMacro + sync::Sync + sync::Send>, - /* allow_internal_unstable: */ bool, - /* edition: */ Edition, - ), + ProcMacro { + expander: Box<ProcMacro + sync::Sync + sync::Send>, + allow_internal_unstable: bool, + edition: Edition, + }, /// An attribute-like procedural macro. TokenStream, TokenStream -> TokenStream. /// The first TokenSteam is the attribute, the second is the annotated item. @@ -646,19 +646,21 @@ pub enum SyntaxExtension { BuiltinDerive(BuiltinDeriveFn), /// A declarative macro, e.g. `macro m() {}`. - /// - /// The second element is the definition site span. - DeclMacro(Box<TTMacroExpander + sync::Sync + sync::Send>, Option<(ast::NodeId, Span)>, Edition), + DeclMacro { + expander: Box<TTMacroExpander + sync::Sync + sync::Send>, + def_info: Option<(ast::NodeId, Span)>, + edition: Edition, + } } impl SyntaxExtension { /// Return which kind of macro calls this syntax extension. pub fn kind(&self) -> MacroKind { match *self { - SyntaxExtension::DeclMacro(..) | + SyntaxExtension::DeclMacro { .. } | SyntaxExtension::NormalTT { .. } | SyntaxExtension::IdentTT(..) | - SyntaxExtension::ProcMacro(..) => + SyntaxExtension::ProcMacro { .. } => MacroKind::Bang, SyntaxExtension::MultiDecorator(..) | SyntaxExtension::MultiModifier(..) | @@ -672,8 +674,8 @@ impl SyntaxExtension { pub fn is_modern(&self) -> bool { match *self { - SyntaxExtension::DeclMacro(..) | - SyntaxExtension::ProcMacro(..) | + SyntaxExtension::DeclMacro { .. } | + SyntaxExtension::ProcMacro { .. } | SyntaxExtension::AttrProcMacro(..) | SyntaxExtension::ProcMacroDerive(..) => true, _ => false, @@ -683,8 +685,8 @@ impl SyntaxExtension { pub fn edition(&self) -> Edition { match *self { SyntaxExtension::NormalTT { edition, .. } | - SyntaxExtension::DeclMacro(.., edition) | - SyntaxExtension::ProcMacro(.., edition) | + SyntaxExtension::DeclMacro { edition, .. } | + SyntaxExtension::ProcMacro { edition, .. } | SyntaxExtension::AttrProcMacro(.., edition) | SyntaxExtension::ProcMacroDerive(.., edition) => edition, // Unstable legacy stuff diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 9cd410d4243..38fa92f2c93 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -738,13 +738,13 @@ impl<'a, 'b> MacroExpander<'a, 'b> { }; let opt_expanded = match *ext { - DeclMacro(ref expand, def_span, edition) => { - if let Err(dummy_span) = validate_and_set_expn_info(self, def_span.map(|(_, s)| s), + DeclMacro { ref expander, def_info, edition } => { + if let Err(dummy_span) = validate_and_set_expn_info(self, def_info.map(|(_, s)| s), false, false, false, None, edition) { dummy_span } else { - kind.make_from(expand.expand(self.cx, span, mac.node.stream())) + kind.make_from(expander.expand(self.cx, span, mac.node.stream())) } } @@ -804,7 +804,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { kind.dummy(span) } - ProcMacro(ref expandfun, allow_internal_unstable, edition) => { + SyntaxExtension::ProcMacro { ref expander, allow_internal_unstable, edition } => { if ident.name != keywords::Invalid.name() { let msg = format!("macro {}! expects no ident argument, given '{}'", path, ident); @@ -826,7 +826,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { edition, }); - let tok_result = expandfun.expand(self.cx, span, mac.node.stream()); + let tok_result = expander.expand(self.cx, span, mac.node.stream()); let result = self.parse_ast_fragment(tok_result, kind, path, span); self.gate_proc_macro_expansion(span, &result); result diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 3b3892729d9..0c81a68e999 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -312,7 +312,11 @@ pub fn compile(sess: &ParseSess, features: &Features, def: &ast::Item, edition: edition, } } else { - SyntaxExtension::DeclMacro(expander, Some((def.id, def.span)), edition) + SyntaxExtension::DeclMacro { + expander, + def_info: Some((def.id, def.span)), + edition, + } } } |
