Rollup merge of #66935 - petrochenkov:attrtok2, r=Centril
syntax: Unify macro and attribute arguments in AST The unified form (`ast::MacArgs`) represents parsed arguments instead of an unstructured token stream that was previously used for attributes. It also tracks some spans and delimiter kinds better for fn-like macros and macro definitions. I've been talking about implementing this with @nnethercote in https://github.com/rust-lang/rust/pull/65750#issuecomment-546517322. The parsed representation is closer to `MetaItem` and requires less token juggling during conversions, so it potentially may be faster. r? @Centril
This commit is contained in:
commit
cf937fa84d
40 changed files with 395 additions and 327 deletions
|
|
@ -1003,7 +1003,7 @@ impl<'a> LoweringContext<'a> {
|
|||
AttrKind::Normal(ref item) => {
|
||||
AttrKind::Normal(AttrItem {
|
||||
path: item.path.clone(),
|
||||
tokens: self.lower_token_stream(item.tokens.clone()),
|
||||
args: self.lower_mac_args(&item.args),
|
||||
})
|
||||
}
|
||||
AttrKind::DocComment(comment) => AttrKind::DocComment(comment)
|
||||
|
|
@ -1017,6 +1017,16 @@ impl<'a> LoweringContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn lower_mac_args(&mut self, args: &MacArgs) -> MacArgs {
|
||||
match *args {
|
||||
MacArgs::Empty => MacArgs::Empty,
|
||||
MacArgs::Delimited(dspan, delim, ref tokens) =>
|
||||
MacArgs::Delimited(dspan, delim, self.lower_token_stream(tokens.clone())),
|
||||
MacArgs::Eq(eq_span, ref tokens) =>
|
||||
MacArgs::Eq(eq_span, self.lower_token_stream(tokens.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
fn lower_token_stream(&mut self, tokens: TokenStream) -> TokenStream {
|
||||
tokens
|
||||
.into_trees()
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ impl LoweringContext<'_> {
|
|||
|
||||
if let ItemKind::MacroDef(ref def) = i.kind {
|
||||
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {
|
||||
let body = self.lower_token_stream(def.stream());
|
||||
let body = self.lower_token_stream(def.body.inner_tokens());
|
||||
let hir_id = self.lower_node_id(i.id);
|
||||
self.exported_macros.push(hir::MacroDef {
|
||||
name: ident.name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue