diff options
| author | John Clements <clements@racket-lang.org> | 2014-07-11 21:22:11 -0700 |
|---|---|---|
| committer | John Clements <clements@racket-lang.org> | 2014-07-13 10:08:27 -0700 |
| commit | b0b4b3122a4af7bf9b361c8f646da4a120e7ba38 (patch) | |
| tree | d3e0fcb19160fcdc2f2977bebc647af9587cf512 /src/libsyntax/ext | |
| parent | e178ebf681d532c1c965883ae34788713f748960 (diff) | |
| download | rust-b0b4b3122a4af7bf9b361c8f646da4a120e7ba38.tar.gz rust-b0b4b3122a4af7bf9b361c8f646da4a120e7ba38.zip | |
refactor Method definition to make space for macros
This change propagates to many locations, but because of the Macro Exterminator (or, more properly, the invariant that it protects), macro invocations can't occur downstream of expansion. This means that in librustc and librustdoc, extracting the desired field can simply assume that it can't be a macro invocation. Functions in ast_util abstract over this check.
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/deriving/generic/mod.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 28 |
2 files changed, 23 insertions, 19 deletions
diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 7d454016d60..46efdccadec 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -648,16 +648,16 @@ impl<'a> MethodDef<'a> { // Create the method. box(GC) ast::Method { - ident: method_ident, attrs: self.attributes.clone(), - generics: fn_generics, - explicit_self: explicit_self, - fn_style: ast::NormalFn, - decl: fn_decl, - body: body_block, id: ast::DUMMY_NODE_ID, span: trait_.span, - vis: ast::Inherited, + node: ast::MethDecl(method_ident, + fn_generics, + explicit_self, + ast::NormalFn, + fn_decl, + body_block, + ast::Inherited) } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 6e44bfa6747..81309181bc0 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -941,21 +941,25 @@ impl<'a> Folder for PatIdentRenamer<'a> { // expand a method fn expand_method(m: &ast::Method, fld: &mut MacroExpander) -> Gc<ast::Method> { let id = fld.new_id(m.id); - let (rewritten_fn_decl, rewritten_body) - = expand_and_rename_fn_decl_and_block(m.decl,m.body,fld); - - // all of the other standard stuff: box(GC) ast::Method { - id: id, - ident: fld.fold_ident(m.ident), attrs: m.attrs.iter().map(|a| fld.fold_attribute(*a)).collect(), - generics: fold_generics(&m.generics, fld), - explicit_self: fld.fold_explicit_self(&m.explicit_self), - fn_style: m.fn_style, - decl: rewritten_fn_decl, - body: rewritten_body, + id: id, span: fld.new_span(m.span), - vis: m.vis + node: match m.node { + ast::MethDecl(ident, ref generics, ref explicit_self, fn_style, decl, body, vis) => { + let (rewritten_fn_decl, rewritten_body) + = expand_and_rename_fn_decl_and_block(decl,body,fld); + + ast::MethDecl(fld.fold_ident(ident), + fold_generics(generics, fld), + fld.fold_explicit_self(explicit_self), + fn_style, + rewritten_fn_decl, + rewritten_body, + vis) + }, + ast::MethMac(ref _mac) => fail!("expansion in method position not implemented yet!") + } } } |
