Skip to content

Commit

Permalink
Rename *.node to *.kind in c2rust-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rinon committed Oct 2, 2019
1 parent 56e6d96 commit c4bdc2f
Show file tree
Hide file tree
Showing 58 changed files with 466 additions and 473 deletions.
22 changes: 11 additions & 11 deletions c2rust-refactor/gen/ast.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct Mod { inner, #[mac_table_seq] items, #[rewrite_ignore] inline }

#[rewrite_print_recover] #[rewrite_seq_item] #[rewrite_extra_strategies=item_header]
#[nonterminal] #[extend_span]
struct Item { ident, #[match=ignore] attrs, id, node, vis, span,
struct Item { ident, #[match=ignore] attrs, id, kind, vis, span,
#[match=ignore] #[rewrite_ignore] tokens }
enum ItemKind {
ExternCrate(name),
Expand Down Expand Up @@ -64,7 +64,7 @@ enum UseTreeKind {
struct UseTree { kind, prefix, span }

#[nonterminal] #[extend_span]
struct TraitItem { id, ident, #[match=ignore] attrs, generics, node, span,
struct TraitItem { id, ident, #[match=ignore] attrs, generics, kind, span,
#[match=ignore] #[rewrite_ignore] tokens }
enum TraitItemKind {
Const(ty, init),
Expand All @@ -74,7 +74,7 @@ enum TraitItemKind {
}

#[nonterminal] #[extend_span]
struct ImplItem { id, ident, vis, defaultness, #[match=ignore] attrs, generics, node, span,
struct ImplItem { id, ident, vis, defaultness, #[match=ignore] attrs, generics, kind, span,
#[match=ignore] #[rewrite_ignore] tokens }
enum ImplItemKind {
Const(ty, init),
Expand Down Expand Up @@ -102,7 +102,7 @@ struct MethodSig { header, decl }

struct ForeignMod { abi, #[mac_table_seq] items }
#[rewrite_print_recover] #[rewrite_seq_item] #[nonterminal] #[extend_span]
struct ForeignItem { ident, #[match=ignore] attrs, node, id, span, vis }
struct ForeignItem { ident, #[match=ignore] attrs, kind, id, span, vis }
enum ForeignItemKind {
Fn(decl, generics),
Static(ty, mutbl),
Expand Down Expand Up @@ -145,7 +145,7 @@ enum CrateSugar {
}

#[match=custom] #[rewrite_print_recover] #[mac_table_record] #[nonterminal]
struct Ty { id, node, span }
struct Ty { id, kind, span }
struct MutTy {ty, mutbl}
enum TyKind {
Slice(ty),
Expand Down Expand Up @@ -182,7 +182,7 @@ enum GenericBound {

struct PolyTraitRef { trait_ref, span, bound_generic_params }

struct FnDecl { inputs, output, c_variadic }
struct FnDecl { inputs, output }
struct FnHeader { unsafety, asyncness, constness, abi }
#[rewrite_print]
struct Param { attrs, ty, pat, id, span, is_placeholder }
Expand All @@ -193,7 +193,7 @@ enum FunctionRetTy {


#[match=custom] #[rewrite_print_recover] #[rewrite_seq_item] #[nonterminal]
struct Stmt { id, node, span }
struct Stmt { id, kind, span }
#[no_debug]
enum StmtKind {
Local(local),
Expand All @@ -208,7 +208,7 @@ struct Local { pat, ty, init, id, span, #[match=ignore] attrs }


#[match=custom] #[rewrite_print_recover] #[extend_span] #[mac_table_record] #[nonterminal]
struct Expr { id, node, span, #[match=ignore] attrs }
struct Expr { id, kind, span, #[match=ignore] attrs }
#[prec_contains_expr]
enum ExprKind {
Box(#[prec=PREFIX] expr),
Expand Down Expand Up @@ -281,7 +281,7 @@ struct Block { #[mac_table_seq] stmts, id, rules, span }


#[match=custom] #[mac_table_record] #[nonterminal]
struct Pat { id, node, span }
struct Pat { id, kind, span }
enum PatKind {
Wild,
Ident(mode, id, pat),
Expand All @@ -304,7 +304,7 @@ enum PatKind {
struct FieldPat { id, ident, pat, is_shorthand, attrs, span, is_placeholder }

#[match=custom]
struct Lit { token, node, span }
struct Lit { token, kind, span }

enum LitKind {
Str(sym, style),
Expand Down Expand Up @@ -455,7 +455,7 @@ struct DelimSpan { open, close }
flag DelimToken;
flag Token;

struct MetaItem { path, node, span }
struct MetaItem { path, kind, span }
enum MetaItemKind {
Word,
List(l),
Expand Down
6 changes: 3 additions & 3 deletions c2rust-refactor/src/analysis/labeled_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'lty, 'tcx: 'lty, L: Clone> LabeledTyCtxt<'lty, L> {
) -> LabeledTy<'lty, 'tcx, L> {
use rustc::ty::TyKind::*;
let label = f(ty);
match ty.sty {
match ty.kind {
// Types with no arguments
Bool | Char | Int(_) | Uint(_) | Float(_) | Str | Foreign(_) | Never => {
self.mk(ty, &[], label)
Expand Down Expand Up @@ -181,7 +181,7 @@ impl<'lty, 'tcx: 'lty, L: Clone> LabeledTyCtxt<'lty, L> {
lty: LabeledTy<'lty, 'tcx, L>,
substs: &[LabeledTy<'lty, 'tcx, L>],
) -> LabeledTy<'lty, 'tcx, L> {
match lty.ty.sty {
match lty.ty.kind {
TyKind::Param(ref tp) => substs[tp.index as usize],
_ => self.mk(
lty.ty,
Expand Down Expand Up @@ -238,7 +238,7 @@ impl<'lty, 'tcx: 'lty, L: Clone> LabeledTyCtxt<'lty, L> {

impl<'lty, 'tcx, L: fmt::Debug> type_map::Type for LabeledTy<'lty, 'tcx, L> {
fn sty(&self) -> &TyKind {
&self.ty.sty
&self.ty.kind
}

fn num_args(&self) -> usize {
Expand Down
12 changes: 6 additions & 6 deletions c2rust-refactor/src/analysis/ownership/annot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct AttrVisitor<'ast> {

impl<'ast> Visitor<'ast> for AttrVisitor<'ast> {
fn visit_item(&mut self, i: &'ast ast::Item) {
match i.node {
match i.kind {
ast::ItemKind::Fn(..) | ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => {
if i.attrs.len() > 0 {
self.def_attrs.push((i.id, &i.attrs));
Expand All @@ -136,7 +136,7 @@ impl<'ast> Visitor<'ast> for AttrVisitor<'ast> {
}

fn visit_impl_item(&mut self, i: &'ast ast::ImplItem) {
match i.node {
match i.kind {
ast::ImplItemKind::Method(..) | ast::ImplItemKind::Const(..) => {
if i.attrs.len() > 0 {
self.def_attrs.push((i.id, &i.attrs));
Expand All @@ -149,7 +149,7 @@ impl<'ast> Visitor<'ast> for AttrVisitor<'ast> {
}

fn visit_foreign_item(&mut self, i: &'ast ast::ForeignItem) {
match i.node {
match i.kind {
// TODO: Foreign statics?
ast::ForeignItemKind::Fn(..) => {
if !i.attrs.is_empty() {
Expand Down Expand Up @@ -288,14 +288,14 @@ pub fn handle_attrs<'a, 'hir, 'tcx, 'lty>(
}

fn meta_item_list(meta: &ast::MetaItem) -> Result<&[ast::NestedMetaItem], &'static str> {
match meta.node {
match meta.kind {
ast::MetaItemKind::List(ref xs) => Ok(xs),
_ => Err("expected MetaItemKind::List"),
}
}

fn meta_item_word(meta: &ast::MetaItem) -> Result<(), &'static str> {
match meta.node {
match meta.kind {
ast::MetaItemKind::Word => Ok(()),
_ => Err("expected MetaItemKind::List"),
}
Expand All @@ -310,7 +310,7 @@ fn nested_meta_item(nmeta: &ast::NestedMetaItem) -> Result<&ast::MetaItem, &'sta

fn nested_str(nmeta: &ast::NestedMetaItem) -> Result<Symbol, &'static str> {
match nmeta {
ast::NestedMetaItem::Literal(ref lit) => match lit.node {
ast::NestedMetaItem::Literal(ref lit) => match lit.kind {
ast::LitKind::Str(s, _) => Ok(s),
_ => Err("expected str"),
},
Expand Down
4 changes: 2 additions & 2 deletions c2rust-refactor/src/analysis/ownership/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<'lty, 'a: 'lty, 'tcx: 'a> Ctxt<'lty, 'tcx> {
Entry::Vacant(e) => {
*e.insert(
self.lcx
.label(self.tcx.type_of(did), &mut |ty| match ty.sty {
.label(self.tcx.type_of(did), &mut |ty| match ty.kind {
TyKind::Ref(_, _, _) | TyKind::RawPtr(_) => {
let v = assign.push(ConcretePerm::Move);
Some(PermVar::Static(v))
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<'lty, 'a: 'lty, 'tcx: 'a> Ctxt<'lty, 'tcx> {
let mut counter = 0;

let l_sig = {
let mut f = |ty: Ty<'tcx>| match ty.sty {
let mut f = |ty: Ty<'tcx>| match ty.kind {
TyKind::Ref(_, _, _) | TyKind::RawPtr(_) => {
let v = Var(counter);
counter += 1;
Expand Down
2 changes: 1 addition & 1 deletion c2rust-refactor/src/analysis/ownership/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ where
PrettyLabel<L>: fmt::Debug,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self.0.ty.sty {
match self.0.ty.kind {
TyKind::Ref(_, _, m) => write!(
fmt,
"&{}{:?} {:?}",
Expand Down
6 changes: 3 additions & 3 deletions c2rust-refactor/src/analysis/ownership/intra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'c, 'lty, 'a: 'lty, 'tcx: 'a> IntraCtxt<'c, 'lty, 'a, 'tcx> {
ref mut insts,
..
} = *self;
ilcx.label(ty, &mut |ty| match ty.sty {
ilcx.label(ty, &mut |ty| match ty.kind {
TyKind::Ref(_, _, _) | TyKind::RawPtr(_) => {
let v = Var(*next_local_var);
*next_local_var += 1;
Expand Down Expand Up @@ -290,7 +290,7 @@ impl<'c, 'lty, 'a: 'lty, 'tcx: 'a> IntraCtxt<'c, 'lty, 'a, 'tcx> {
}

fn field_lty(&mut self, base_ty: ITy<'lty, 'tcx>, v: VariantIdx, f: Field) -> ITy<'lty, 'tcx> {
match base_ty.ty.sty {
match base_ty.ty.kind {
TyKind::Adt(adt, _substs) => {
let field_def = &adt.variants[v].fields[f.index()];
let poly_ty = self.static_ty(field_def.did);
Expand Down Expand Up @@ -493,7 +493,7 @@ impl<'c, 'lty, 'a: 'lty, 'tcx: 'a> IntraCtxt<'c, 'lty, 'a, 'tcx> {
}

fn ty_fn_sig(&mut self, ty: ITy<'lty, 'tcx>) -> IFnSig<'lty, 'tcx> {
match ty.ty.sty {
match ty.ty.kind {
TyKind::FnDef(did, _substs) => {
let idx = expect!([ty.label] Label::FnDef(idx) => idx);
let var_base = self.insts[idx].first_inst_var;
Expand Down
18 changes: 9 additions & 9 deletions c2rust-refactor/src/analysis/ownership/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ fn is_fn(hir_map: &hir::map::Map, def_id: DefId) -> bool {
};

match n {
Node::Item(i) => match i.node {
Node::Item(i) => match i.kind {
hir::ItemKind::Fn(..) => true,
_ => false,
},
Node::ForeignItem(i) => match i.node {
Node::ForeignItem(i) => match i.kind {
hir::ForeignItemKind::Fn(..) => true,
_ => false,
},
Node::TraitItem(i) => match i.node {
Node::TraitItem(i) => match i.kind {
hir::TraitItemKind::Method(..) => true,
_ => false,
},
Node::ImplItem(i) => match i.node {
Node::ImplItem(i) => match i.kind {
hir::ImplItemKind::Method(..) => true,
_ => false,
},
Expand Down Expand Up @@ -198,7 +198,7 @@ fn analyze_externs<'a, 'tcx, 'lty>(cx: &mut Ctxt<'lty, 'tcx>, hir_map: &HirMap<'
continue;
}
match hir_map.get_if_local(*def_id) {
Some(Node::ForeignItem(i)) => match i.node {
Some(Node::ForeignItem(i)) => match i.kind {
// We only want to consider foreign functions
hir::ForeignItemKind::Fn(..) => {}
_ => continue,
Expand All @@ -207,7 +207,7 @@ fn analyze_externs<'a, 'tcx, 'lty>(cx: &mut Ctxt<'lty, 'tcx>, hir_map: &HirMap<'
}
for &input in func_summ.sig.inputs {
if let Some(p) = input.label {
match input.ty.sty {
match input.ty.kind {
TyKind::Ref(_, _, Mutability::MutMutable) => {
func_summ.sig_cset.add(Perm::Concrete(ConcretePerm::Move), Perm::var(p));
}
Expand All @@ -231,9 +231,9 @@ fn analyze_inter<'lty, 'tcx>(cx: &mut Ctxt<'lty, 'tcx>) {
}

fn is_mut_t(ty: &TyS) -> bool {
if let TyKind::RawPtr(mut_ty) = ty.sty {
if let TyKind::RawPtr(mut_ty) = ty.kind {
if mut_ty.mutbl == Mutability::MutMutable {
if let TyKind::Param(param_ty) = mut_ty.ty.sty {
if let TyKind::Param(param_ty) = mut_ty.ty.kind {
return param_ty.name.as_str() == "T";
}
}
Expand All @@ -257,7 +257,7 @@ fn register_std_constraints<'a, 'tcx, 'lty>(
// fn offset<T>(self: *mut T, _: isize) -> *mut T;
if func_summ.sig.inputs.len() == 2 && fn_name_path == "::ptr[0]::{{impl}}[1]::offset[0]" {
let param0_is_mut_t = is_mut_t(func_summ.sig.inputs[0].ty);
let param1_is_isize = if let TyKind::Int(int_ty) = func_summ.sig.inputs[1].ty.sty {
let param1_is_isize = if let TyKind::Int(int_ty) = func_summ.sig.inputs[1].ty.kind {
int_ty == IntTy::Isize
} else {
false
Expand Down
Loading

0 comments on commit c4bdc2f

Please sign in to comment.