Skip to content

Commit d6fb338

Browse files
committedSep 14, 2014
syntax: ast_map: use borrowed references into the AST.
·
1.88.00.12.0
1 parent 9259b02 commit d6fb338

File tree

6 files changed

+367
-269
lines changed

6 files changed

+367
-269
lines changed
 

‎mk/crates.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ DEPS_graphviz := std
7070
DEPS_green := std native:context_switch
7171
DEPS_rustuv := std native:uv native:uv_support
7272
DEPS_native := std
73-
DEPS_syntax := std term serialize log fmt_macros debug
73+
DEPS_syntax := std term serialize log fmt_macros debug arena
7474
DEPS_rustc := syntax flate arena serialize getopts rbml \
7575
time log graphviz debug rustc_llvm rustc_back
7676
DEPS_rustc_llvm := native:rustllvm libc std

‎src/libsyntax/ast.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,16 +1308,11 @@ pub enum UnboxedClosureKind {
13081308
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
13091309
pub enum InlinedItem {
13101310
IIItem(P<Item>),
1311-
IITraitItem(DefId /* impl id */, InlinedTraitItem),
1311+
IITraitItem(DefId /* impl id */, TraitItem),
1312+
IIImplItem(DefId /* impl id */, ImplItem),
13121313
IIForeign(P<ForeignItem>),
13131314
}
13141315

1315-
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
1316-
pub enum InlinedTraitItem {
1317-
ProvidedInlinedTraitItem(P<Method>),
1318-
RequiredInlinedTraitItem(P<Method>),
1319-
}
1320-
13211316
#[cfg(test)]
13221317
mod test {
13231318
use serialize::json;

‎src/libsyntax/ast_map/mod.rs

Lines changed: 343 additions & 251 deletions
Large diffs are not rendered by default.

‎src/libsyntax/ast_util.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,14 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
538538
}
539539
visit::walk_trait_item(self, tm);
540540
}
541+
542+
fn visit_lifetime_ref(&mut self, lifetime: &'v Lifetime) {
543+
self.operation.visit_id(lifetime.id);
544+
}
545+
546+
fn visit_lifetime_decl(&mut self, def: &'v LifetimeDef) {
547+
self.visit_lifetime_ref(&def.lifetime);
548+
}
541549
}
542550

543551
pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &InlinedItem,

‎src/libsyntax/fold.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ pub fn noop_fold_path<T: Folder>(Path {global, segments, span}: Path, fld: &mut
469469

470470
pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
471471
l.map(|Local {id, pat, ty, init, source, span}| Local {
472-
id: fld.new_id(id), // Needs to be first, for ast_map.
472+
id: fld.new_id(id),
473473
ty: fld.fold_ty(ty),
474474
pat: fld.fold_pat(pat),
475475
init: init.map(|e| fld.fold_expr(e)),
@@ -495,10 +495,12 @@ pub fn noop_fold_explicit_self_underscore<T: Folder>(es: ExplicitSelf_, fld: &mu
495495
-> ExplicitSelf_ {
496496
match es {
497497
SelfStatic | SelfValue(_) => es,
498-
SelfRegion(lifetime, m, id) => {
499-
SelfRegion(fld.fold_opt_lifetime(lifetime), m, id)
498+
SelfRegion(lifetime, m, ident) => {
499+
SelfRegion(fld.fold_opt_lifetime(lifetime), m, ident)
500+
}
501+
SelfExplicit(typ, ident) => {
502+
SelfExplicit(fld.fold_ty(typ), ident)
500503
}
501-
SelfExplicit(typ, id) => SelfExplicit(fld.fold_ty(typ), id),
502504
}
503505
}
504506

@@ -537,7 +539,7 @@ pub fn noop_fold_meta_item<T: Folder>(mi: P<MetaItem>, fld: &mut T) -> P<MetaIte
537539

538540
pub fn noop_fold_arg<T: Folder>(Arg {id, pat, ty}: Arg, fld: &mut T) -> Arg {
539541
Arg {
540-
id: fld.new_id(id), // Needs to be first, for ast_map.
542+
id: fld.new_id(id),
541543
pat: fld.fold_pat(pat),
542544
ty: fld.fold_ty(ty)
543545
}
@@ -808,7 +810,7 @@ pub fn noop_fold_view_item<T: Folder>(ViewItem {node, attrs, vis, span}: ViewIte
808810

809811
pub fn noop_fold_block<T: Folder>(b: P<Block>, folder: &mut T) -> P<Block> {
810812
b.map(|Block {id, view_items, stmts, expr, rules, span}| Block {
811-
id: folder.new_id(id), // Needs to be first, for ast_map.
813+
id: folder.new_id(id),
812814
view_items: view_items.move_map(|x| folder.fold_view_item(x)),
813815
stmts: stmts.move_iter().flat_map(|s| folder.fold_stmt(s).move_iter()).collect(),
814816
expr: expr.map(|x| folder.fold_expr(x)),
@@ -886,7 +888,7 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
886888
pub fn noop_fold_type_method<T: Folder>(m: TypeMethod, fld: &mut T) -> TypeMethod {
887889
let TypeMethod {id, ident, attrs, fn_style, abi, decl, generics, explicit_self, vis, span} = m;
888890
TypeMethod {
889-
id: fld.new_id(id), // Needs to be first, for ast_map.
891+
id: fld.new_id(id),
890892
ident: fld.fold_ident(ident),
891893
attrs: attrs.move_map(|a| fld.fold_attribute(a)),
892894
fn_style: fn_style,
@@ -926,7 +928,7 @@ pub fn noop_fold_item<T: Folder>(i: P<Item>, folder: &mut T) -> SmallVector<P<It
926928
// fold one item into exactly one item
927929
pub fn noop_fold_item_simple<T: Folder>(Item {id, ident, attrs, node, vis, span}: Item,
928930
folder: &mut T) -> Item {
929-
let id = folder.new_id(id); // Needs to be first, for ast_map.
931+
let id = folder.new_id(id);
930932
let node = folder.fold_item_underscore(node);
931933
let ident = match node {
932934
// The node may have changed, recompute the "pretty" impl name.
@@ -948,7 +950,7 @@ pub fn noop_fold_item_simple<T: Folder>(Item {id, ident, attrs, node, vis, span}
948950

949951
pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) -> P<ForeignItem> {
950952
ni.map(|ForeignItem {id, ident, attrs, node, span, vis}| ForeignItem {
951-
id: folder.new_id(id), // Needs to be first, for ast_map.
953+
id: folder.new_id(id),
952954
ident: folder.fold_ident(ident),
953955
attrs: attrs.move_map(|x| folder.fold_attribute(x)),
954956
node: match node {
@@ -973,7 +975,7 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) ->
973975
// Invariant: produces exactly one method.
974976
pub fn noop_fold_method<T: Folder>(m: P<Method>, folder: &mut T) -> SmallVector<P<Method>> {
975977
SmallVector::one(m.map(|Method {id, attrs, node, span}| Method {
976-
id: folder.new_id(id), // Needs to be first, for ast_map.
978+
id: folder.new_id(id),
977979
attrs: attrs.move_map(|a| folder.fold_attribute(a)),
978980
node: match node {
979981
MethDecl(ident,

‎src/libsyntax/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#![feature(quote, struct_variant, unsafe_destructor, import_shadowing)]
2828
#![allow(deprecated)]
2929

30+
extern crate arena;
3031
extern crate fmt_macros;
3132
extern crate debug;
3233
#[phase(plugin, link)] extern crate log;

0 commit comments

Comments
 (0)
Please sign in to comment.