Skip to content

Commit

Permalink
ast: Mac/Macro -> MacCall
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Mar 6, 2020
1 parent 865b44a commit 5d308ae
Show file tree
Hide file tree
Showing 43 changed files with 200 additions and 197 deletions.
48 changes: 24 additions & 24 deletions src/librustc_ast/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! - [`Generics`], [`GenericParam`], [`WhereClause`]: Metadata associated with generic parameters.
//! - [`EnumDef`] and [`Variant`]: Enum declaration.
//! - [`Lit`] and [`LitKind`]: Literal expressions.
//! - [`MacroDef`], [`MacStmtStyle`], [`Mac`], [`MacDelimeter`]: Macro definition and invocation.
//! - [`MacroDef`], [`MacStmtStyle`], [`MacCall`], [`MacDelimeter`]: Macro definition and invocation.
//! - [`Attribute`]: Metadata associated with item.
//! - [`UnOp`], [`UnOpKind`], [`BinOp`], [`BinOpKind`]: Unary and binary operators.

Expand Down Expand Up @@ -513,7 +513,7 @@ impl Pat {
TyKind::Path(None, Path::from_ident(*ident))
}
PatKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()),
PatKind::Mac(mac) => TyKind::Mac(mac.clone()),
PatKind::MacCall(mac) => TyKind::MacCall(mac.clone()),
// `&mut? P` can be reinterpreted as `&mut? T` where `T` is `P` reparsed as a type.
PatKind::Ref(pat, mutbl) => {
pat.to_ty().map(|ty| TyKind::Rptr(None, MutTy { ty, mutbl: *mutbl }))?
Expand Down Expand Up @@ -567,7 +567,7 @@ impl Pat {
| PatKind::Range(..)
| PatKind::Ident(..)
| PatKind::Path(..)
| PatKind::Mac(_) => {}
| PatKind::MacCall(_) => {}
}
}

Expand Down Expand Up @@ -682,7 +682,7 @@ pub enum PatKind {
Paren(P<Pat>),

/// A macro pattern; pre-expansion.
Mac(Mac),
MacCall(MacCall),
}

#[derive(
Expand Down Expand Up @@ -881,9 +881,9 @@ impl Stmt {
pub fn add_trailing_semicolon(mut self) -> Self {
self.kind = match self.kind {
StmtKind::Expr(expr) => StmtKind::Semi(expr),
StmtKind::Mac(mac) => {
StmtKind::Mac(mac.map(|(mac, _style, attrs)| (mac, MacStmtStyle::Semicolon, attrs)))
}
StmtKind::MacCall(mac) => StmtKind::MacCall(
mac.map(|(mac, _style, attrs)| (mac, MacStmtStyle::Semicolon, attrs)),
),
kind => kind,
};
self
Expand Down Expand Up @@ -917,7 +917,7 @@ pub enum StmtKind {
/// Just a trailing semi-colon.
Empty,
/// Macro.
Mac(P<(Mac, MacStmtStyle, AttrVec)>),
MacCall(P<(MacCall, MacStmtStyle, AttrVec)>),
}

#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)]
Expand Down Expand Up @@ -1057,7 +1057,7 @@ impl Expr {
let kind = match &self.kind {
// Trivial conversions.
ExprKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()),
ExprKind::Mac(mac) => TyKind::Mac(mac.clone()),
ExprKind::MacCall(mac) => TyKind::MacCall(mac.clone()),

ExprKind::Paren(expr) => expr.to_ty().map(TyKind::Paren)?,

Expand Down Expand Up @@ -1127,7 +1127,7 @@ impl Expr {
ExprKind::Continue(..) => ExprPrecedence::Continue,
ExprKind::Ret(..) => ExprPrecedence::Ret,
ExprKind::InlineAsm(..) => ExprPrecedence::InlineAsm,
ExprKind::Mac(..) => ExprPrecedence::Mac,
ExprKind::MacCall(..) => ExprPrecedence::Mac,
ExprKind::Struct(..) => ExprPrecedence::Struct,
ExprKind::Repeat(..) => ExprPrecedence::Repeat,
ExprKind::Paren(..) => ExprPrecedence::Paren,
Expand Down Expand Up @@ -1259,7 +1259,7 @@ pub enum ExprKind {
InlineAsm(P<InlineAsm>),

/// A macro invocation; pre-expansion.
Mac(Mac),
MacCall(MacCall),

/// A struct literal expression.
///
Expand Down Expand Up @@ -1345,13 +1345,13 @@ pub enum Movability {
/// Represents a macro invocation. The `path` indicates which macro
/// is being invoked, and the `args` are arguments passed to it.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Mac {
pub struct MacCall {
pub path: Path,
pub args: P<MacArgs>,
pub prior_type_ascription: Option<(Span, bool)>,
}

impl Mac {
impl MacCall {
pub fn span(&self) -> Span {
self.path.span.to(self.args.span().unwrap_or(self.path.span))
}
Expand Down Expand Up @@ -1881,7 +1881,7 @@ pub enum TyKind {
/// Inferred type of a `self` or `&self` argument in a method.
ImplicitSelf,
/// A macro in the type position.
Mac(Mac),
MacCall(MacCall),
/// Placeholder for a kind that has failed to be defined.
Err,
/// Placeholder for a `va_list`.
Expand Down Expand Up @@ -2574,7 +2574,7 @@ pub enum ItemKind {
/// A macro invocation.
///
/// E.g., `foo!(..)`.
Mac(Mac),
MacCall(MacCall),

/// A macro definition.
MacroDef(MacroDef),
Expand All @@ -2586,7 +2586,7 @@ impl ItemKind {
match self {
Use(..) | Static(..) | Const(..) | Fn(..) | Mod(..) | GlobalAsm(..) | TyAlias(..)
| Struct(..) | Union(..) | Trait(..) | TraitAlias(..) | MacroDef(..) => "a",
ExternCrate(..) | ForeignMod(..) | Mac(..) | Enum(..) | Impl { .. } => "an",
ExternCrate(..) | ForeignMod(..) | MacCall(..) | Enum(..) | Impl { .. } => "an",
}
}

Expand All @@ -2606,7 +2606,7 @@ impl ItemKind {
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
ItemKind::Mac(..) => "item macro invocation",
ItemKind::MacCall(..) => "item macro invocation",
ItemKind::MacroDef(..) => "macro definition",
ItemKind::Impl { .. } => "implementation",
}
Expand Down Expand Up @@ -2648,14 +2648,14 @@ pub enum AssocItemKind {
/// An associated type.
TyAlias(Defaultness, Generics, GenericBounds, Option<P<Ty>>),
/// A macro expanding to associated items.
Macro(Mac),
MacCall(MacCall),
}

impl AssocItemKind {
pub fn defaultness(&self) -> Defaultness {
match *self {
Self::Const(def, ..) | Self::Fn(def, ..) | Self::TyAlias(def, ..) => def,
Self::Macro(..) => Defaultness::Final,
Self::MacCall(..) => Defaultness::Final,
}
}
}
Expand All @@ -2666,7 +2666,7 @@ impl From<AssocItemKind> for ItemKind {
AssocItemKind::Const(a, b, c) => ItemKind::Const(a, b, c),
AssocItemKind::Fn(a, b, c, d) => ItemKind::Fn(a, b, c, d),
AssocItemKind::TyAlias(a, b, c, d) => ItemKind::TyAlias(a, b, c, d),
AssocItemKind::Macro(a) => ItemKind::Mac(a),
AssocItemKind::MacCall(a) => ItemKind::MacCall(a),
}
}
}
Expand All @@ -2679,7 +2679,7 @@ impl TryFrom<ItemKind> for AssocItemKind {
ItemKind::Const(a, b, c) => AssocItemKind::Const(a, b, c),
ItemKind::Fn(a, b, c, d) => AssocItemKind::Fn(a, b, c, d),
ItemKind::TyAlias(a, b, c, d) => AssocItemKind::TyAlias(a, b, c, d),
ItemKind::Mac(a) => AssocItemKind::Macro(a),
ItemKind::MacCall(a) => AssocItemKind::MacCall(a),
_ => return Err(item_kind),
})
}
Expand All @@ -2695,7 +2695,7 @@ pub enum ForeignItemKind {
/// A foreign type.
TyAlias(Defaultness, Generics, GenericBounds, Option<P<Ty>>),
/// A macro expanding to foreign items.
Macro(Mac),
MacCall(MacCall),
}

impl From<ForeignItemKind> for ItemKind {
Expand All @@ -2704,7 +2704,7 @@ impl From<ForeignItemKind> for ItemKind {
ForeignItemKind::Static(a, b, c) => ItemKind::Static(a, b, c),
ForeignItemKind::Fn(a, b, c, d) => ItemKind::Fn(a, b, c, d),
ForeignItemKind::TyAlias(a, b, c, d) => ItemKind::TyAlias(a, b, c, d),
ForeignItemKind::Macro(a) => ItemKind::Mac(a),
ForeignItemKind::MacCall(a) => ItemKind::MacCall(a),
}
}
}
Expand All @@ -2717,7 +2717,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
ItemKind::Static(a, b, c) => ForeignItemKind::Static(a, b, c),
ItemKind::Fn(a, b, c, d) => ForeignItemKind::Fn(a, b, c, d),
ItemKind::TyAlias(a, b, c, d) => ForeignItemKind::TyAlias(a, b, c, d),
ItemKind::Mac(a) => ForeignItemKind::Macro(a),
ItemKind::MacCall(a) => ForeignItemKind::MacCall(a),
_ => return Err(item_kind),
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_ast/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ impl HasAttrs for StmtKind {
StmtKind::Local(ref local) => local.attrs(),
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.attrs(),
StmtKind::Empty | StmtKind::Item(..) => &[],
StmtKind::Mac(ref mac) => {
StmtKind::MacCall(ref mac) => {
let (_, _, ref attrs) = **mac;
attrs.attrs()
}
Expand All @@ -688,7 +688,7 @@ impl HasAttrs for StmtKind {
StmtKind::Local(local) => local.visit_attrs(f),
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.visit_attrs(f),
StmtKind::Empty | StmtKind::Item(..) => {}
StmtKind::Mac(mac) => {
StmtKind::MacCall(mac) => {
let (_mac, _style, attrs) = mac.deref_mut();
attrs.visit_attrs(f);
}
Expand Down
22 changes: 11 additions & 11 deletions src/librustc_ast/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub trait MutVisitor: Sized {
noop_visit_local(l, self);
}

fn visit_mac(&mut self, _mac: &mut Mac) {
fn visit_mac(&mut self, _mac: &mut MacCall) {
panic!("visit_mac disabled by default");
// N.B., see note about macros above. If you really want a visitor that
// works on macros, use this definition in your trait impl:
Expand Down Expand Up @@ -482,7 +482,7 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
vis.visit_id(id);
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
}
TyKind::Mac(mac) => vis.visit_mac(mac),
TyKind::MacCall(mac) => vis.visit_mac(mac),
}
vis.visit_span(span);
}
Expand Down Expand Up @@ -584,8 +584,8 @@ pub fn noop_visit_attribute<T: MutVisitor>(attr: &mut Attribute, vis: &mut T) {
vis.visit_span(span);
}

pub fn noop_visit_mac<T: MutVisitor>(mac: &mut Mac, vis: &mut T) {
let Mac { path, args, prior_type_ascription: _ } = mac;
pub fn noop_visit_mac<T: MutVisitor>(mac: &mut MacCall, vis: &mut T) {
let MacCall { path, args, prior_type_ascription: _ } = mac;
vis.visit_path(path);
visit_mac_args(args, vis);
}
Expand Down Expand Up @@ -926,7 +926,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
vis.visit_generics(generics);
visit_bounds(bounds, vis);
}
ItemKind::Mac(m) => vis.visit_mac(m),
ItemKind::MacCall(m) => vis.visit_mac(m),
ItemKind::MacroDef(def) => vis.visit_macro_def(def),
}
}
Expand Down Expand Up @@ -955,7 +955,7 @@ pub fn noop_flat_map_assoc_item<T: MutVisitor>(
visit_bounds(bounds, visitor);
visit_opt(ty, |ty| visitor.visit_ty(ty));
}
AssocItemKind::Macro(mac) => visitor.visit_mac(mac),
AssocItemKind::MacCall(mac) => visitor.visit_mac(mac),
}
visitor.visit_span(span);
smallvec![item]
Expand Down Expand Up @@ -1043,7 +1043,7 @@ pub fn noop_flat_map_foreign_item<T: MutVisitor>(
visit_bounds(bounds, visitor);
visit_opt(ty, |ty| visitor.visit_ty(ty));
}
ForeignItemKind::Macro(mac) => visitor.visit_mac(mac),
ForeignItemKind::MacCall(mac) => visitor.visit_mac(mac),
}
visitor.visit_span(span);
smallvec![item]
Expand Down Expand Up @@ -1082,7 +1082,7 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
visit_vec(elems, |elem| vis.visit_pat(elem))
}
PatKind::Paren(inner) => vis.visit_pat(inner),
PatKind::Mac(mac) => vis.visit_mac(mac),
PatKind::MacCall(mac) => vis.visit_mac(mac),
}
vis.visit_span(span);
}
Expand Down Expand Up @@ -1219,7 +1219,7 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { kind, id, span, attrs }: &mut Expr,
}
visit_vec(inputs, |(_c, expr)| vis.visit_expr(expr));
}
ExprKind::Mac(mac) => vis.visit_mac(mac),
ExprKind::MacCall(mac) => vis.visit_mac(mac),
ExprKind::Struct(path, fields, expr) => {
vis.visit_path(path);
fields.flat_map_in_place(|field| vis.flat_map_field(field));
Expand Down Expand Up @@ -1275,11 +1275,11 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(
StmtKind::Expr(expr) => vis.filter_map_expr(expr).into_iter().map(StmtKind::Expr).collect(),
StmtKind::Semi(expr) => vis.filter_map_expr(expr).into_iter().map(StmtKind::Semi).collect(),
StmtKind::Empty => smallvec![StmtKind::Empty],
StmtKind::Mac(mut mac) => {
StmtKind::MacCall(mut mac) => {
let (mac_, _semi, attrs) = mac.deref_mut();
vis.visit_mac(mac_);
visit_thin_attrs(attrs, vis);
smallvec![StmtKind::Mac(mac)]
smallvec![StmtKind::MacCall(mac)]
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_ast/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub trait Visitor<'ast>: Sized {
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) {
walk_lifetime(self, lifetime)
}
fn visit_mac(&mut self, _mac: &'ast Mac) {
fn visit_mac(&mut self, _mac: &'ast MacCall) {
panic!("visit_mac disabled by default");
// N.B., see note about macros above.
// if you really want a visitor that
Expand Down Expand Up @@ -350,7 +350,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds);
}
ItemKind::Mac(ref mac) => visitor.visit_mac(mac),
ItemKind::MacCall(ref mac) => visitor.visit_mac(mac),
ItemKind::MacroDef(ref ts) => visitor.visit_mac_def(ts, item.id),
}
walk_list!(visitor, visit_attribute, &item.attrs);
Expand Down Expand Up @@ -418,7 +418,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
}
TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
TyKind::Mac(ref mac) => visitor.visit_mac(mac),
TyKind::MacCall(ref mac) => visitor.visit_mac(mac),
TyKind::Never | TyKind::CVarArgs => {}
}
}
Expand Down Expand Up @@ -521,7 +521,7 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) {
PatKind::Tuple(ref elems) | PatKind::Slice(ref elems) | PatKind::Or(ref elems) => {
walk_list!(visitor, visit_pat, elems);
}
PatKind::Mac(ref mac) => visitor.visit_mac(mac),
PatKind::MacCall(ref mac) => visitor.visit_mac(mac),
}
}

Expand All @@ -545,7 +545,7 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_ty, ty);
}
ForeignItemKind::Macro(mac) => {
ForeignItemKind::MacCall(mac) => {
visitor.visit_mac(mac);
}
}
Expand Down Expand Up @@ -650,7 +650,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem,
walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_ty, ty);
}
AssocItemKind::Macro(mac) => {
AssocItemKind::MacCall(mac) => {
visitor.visit_mac(mac);
}
}
Expand Down Expand Up @@ -679,7 +679,7 @@ pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
StmtKind::Item(ref item) => visitor.visit_item(item),
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => visitor.visit_expr(expr),
StmtKind::Empty => {}
StmtKind::Mac(ref mac) => {
StmtKind::MacCall(ref mac) => {
let (ref mac, _, ref attrs) = **mac;
visitor.visit_mac(mac);
for attr in attrs.iter() {
Expand All @@ -689,7 +689,7 @@ pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
}
}

pub fn walk_mac<'a, V: Visitor<'a>>(visitor: &mut V, mac: &'a Mac) {
pub fn walk_mac<'a, V: Visitor<'a>>(visitor: &mut V, mac: &'a MacCall) {
visitor.visit_path(&mac.path, DUMMY_NODE_ID);
}

Expand Down Expand Up @@ -811,7 +811,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
ExprKind::Ret(ref optional_expression) => {
walk_list!(visitor, visit_expr, optional_expression);
}
ExprKind::Mac(ref mac) => visitor.visit_mac(mac),
ExprKind::MacCall(ref mac) => visitor.visit_mac(mac),
ExprKind::Paren(ref subexpression) => visitor.visit_expr(subexpression),
ExprKind::InlineAsm(ref ia) => {
for &(_, ref input) in &ia.inputs {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
return self.lower_expr_for(e, pat, head, body, opt_label);
}
ExprKind::Try(ref sub_expr) => self.lower_expr_try(e.span, sub_expr),
ExprKind::Mac(_) => panic!("Shouldn't exist here"),
ExprKind::MacCall(_) => panic!("Shouldn't exist here"),
};

hir::Expr {
Expand Down
Loading

0 comments on commit 5d308ae

Please sign in to comment.