Skip to content

Commit 629f6a0

Browse files
committed
---
yaml --- r: 210827 b: refs/heads/try c: c8ddb0f h: refs/heads/master i: 210825: 225f14c 210823: eda2009 v: v3
1 parent a94b3ab commit 629f6a0

File tree

3 files changed

+69
-57
lines changed

3 files changed

+69
-57
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3e561f05c00cd180ec02db4ccab2840a4aba93d2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
5-
refs/heads/try: cea73bfb1596f1e5e1f3a6faa9863d2983a3ccea
5+
refs/heads/try: c8ddb0f070db3bebfdc4f581cee1dc212a86bb80
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/librustc_trans/save/dump_csv.rs

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
//! the format of the output away from extracting it from the compiler.
2828
//! DumpCsvVisitor walks the AST and processes it.
2929
30-
use super::{escape, generated_code, recorder, SaveContext};
30+
31+
use super::{escape, generated_code, recorder, SaveContext, PathCollector};
3132

3233
use session::Session;
3334

@@ -59,9 +60,6 @@ pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
5960
sess: &'l Session,
6061
analysis: &'l ty::CrateAnalysis<'tcx>,
6162

62-
collected_paths: Vec<(NodeId, ast::Path, bool, recorder::Row)>,
63-
collecting: bool,
64-
6563
span: SpanUtils<'l>,
6664
fmt: FmtStrs<'l>,
6765

@@ -79,8 +77,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
7977
err_count: Cell::new(0)
8078
}),
8179
analysis: analysis,
82-
collected_paths: vec![],
83-
collecting: false,
8480
span: SpanUtils {
8581
sess: sess,
8682
err_count: Cell::new(0)
@@ -281,12 +277,11 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
281277

282278
fn process_formals(&mut self, formals: &Vec<ast::Arg>, qualname: &str) {
283279
for arg in formals {
284-
assert!(self.collected_paths.is_empty() && !self.collecting);
285-
self.collecting = true;
286-
self.visit_pat(&*arg.pat);
287-
self.collecting = false;
280+
self.visit_pat(&arg.pat);
281+
let mut collector = PathCollector::new();
282+
collector.visit_pat(&arg.pat);
288283
let span_utils = self.span.clone();
289-
for &(id, ref p, _, _) in &self.collected_paths {
284+
for &(id, ref p, _, _) in &collector.collected_paths {
290285
let typ =
291286
ppaux::ty_to_string(
292287
&self.analysis.ty_cx,
@@ -300,7 +295,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
300295
&path_to_string(p),
301296
&typ[..]);
302297
}
303-
self.collected_paths.clear();
304298
}
305299
}
306300

@@ -1026,7 +1020,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
10261020

10271021
match p.node {
10281022
ast::PatStruct(ref path, ref fields, _) => {
1029-
self.collected_paths.push((p.id, path.clone(), false, recorder::StructRef));
10301023
visit::walk_path(self, path);
10311024

10321025
let def = self.analysis.ty_cx.def_map.borrow().get(&p.id).unwrap().full_def();
@@ -1063,32 +1056,6 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
10631056
}
10641057
}
10651058
}
1066-
ast::PatEnum(ref path, _) |
1067-
ast::PatQPath(_, ref path) => {
1068-
self.collected_paths.push((p.id, path.clone(), false, recorder::VarRef));
1069-
visit::walk_pat(self, p);
1070-
}
1071-
ast::PatIdent(bm, ref path1, ref optional_subpattern) => {
1072-
let immut = match bm {
1073-
// Even if the ref is mut, you can't change the ref, only
1074-
// the data pointed at, so showing the initialising expression
1075-
// is still worthwhile.
1076-
ast::BindByRef(_) => true,
1077-
ast::BindByValue(mt) => {
1078-
match mt {
1079-
ast::MutMutable => false,
1080-
ast::MutImmutable => true,
1081-
}
1082-
}
1083-
};
1084-
// collect path for either visit_local or visit_arm
1085-
let path = ast_util::ident_to_path(path1.span,path1.node);
1086-
self.collected_paths.push((p.id, path, immut, recorder::VarRef));
1087-
match *optional_subpattern {
1088-
None => {}
1089-
Some(ref subpattern) => self.visit_pat(&**subpattern)
1090-
}
1091-
}
10921059
_ => visit::walk_pat(self, p)
10931060
}
10941061
}
@@ -1421,23 +1388,20 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
14211388

14221389
fn visit_pat(&mut self, p: &ast::Pat) {
14231390
self.process_pat(p);
1424-
if !self.collecting {
1425-
self.collected_paths.clear();
1426-
}
14271391
}
14281392

14291393
fn visit_arm(&mut self, arm: &ast::Arm) {
1430-
assert!(self.collected_paths.is_empty() && !self.collecting);
1431-
self.collecting = true;
1394+
let mut collector = PathCollector::new();
14321395
for pattern in &arm.pats {
14331396
// collect paths from the arm's patterns
1434-
self.visit_pat(&**pattern);
1397+
collector.visit_pat(&pattern);
1398+
self.visit_pat(&pattern);
14351399
}
14361400

14371401
// This is to get around borrow checking, because we need mut self to call process_path.
14381402
let mut paths_to_process = vec![];
14391403
// process collected paths
1440-
for &(id, ref p, ref immut, ref_kind) in &self.collected_paths {
1404+
for &(id, ref p, ref immut, ref_kind) in &collector.collected_paths {
14411405
let def_map = self.analysis.ty_cx.def_map.borrow();
14421406
if !def_map.contains_key(&id) {
14431407
self.sess.span_bug(p.span,
@@ -1475,8 +1439,6 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
14751439
for &(id, ref path, ref_kind) in &paths_to_process {
14761440
self.process_path(id, path.span, path, ref_kind);
14771441
}
1478-
self.collecting = false;
1479-
self.collected_paths.clear();
14801442
visit::walk_expr_opt(self, &arm.guard);
14811443
self.visit_expr(&*arm.body);
14821444
}
@@ -1496,14 +1458,13 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
14961458

14971459
// The local could declare multiple new vars, we must walk the
14981460
// pattern and collect them all.
1499-
assert!(self.collected_paths.is_empty() && !self.collecting);
1500-
self.collecting = true;
1501-
self.visit_pat(&*l.pat);
1502-
self.collecting = false;
1461+
let mut collector = PathCollector::new();
1462+
collector.visit_pat(&l.pat);
1463+
self.visit_pat(&l.pat);
15031464

15041465
let value = self.span.snippet(l.span);
15051466

1506-
for &(id, ref p, ref immut, _) in &self.collected_paths {
1467+
for &(id, ref p, ref immut, _) in &collector.collected_paths {
15071468
let value = if *immut { value.to_string() } else { "<mutable>".to_string() };
15081469
let types = self.analysis.ty_cx.node_types();
15091470
let typ = ppaux::ty_to_string(&self.analysis.ty_cx, *types.get(&id).unwrap());
@@ -1518,7 +1479,6 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
15181479
&value[..],
15191480
&typ[..]);
15201481
}
1521-
self.collected_paths.clear();
15221482

15231483
// Just walk the initialiser and type (don't want to walk the pattern again).
15241484
visit::walk_ty_opt(self, &l.ty);

branches/try/src/librustc_trans/save/mod.rs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ use std::env;
1515
use std::fs::{self, File};
1616
use std::path::{Path, PathBuf};
1717

18-
use syntax::{attr, visit};
18+
use syntax::{attr};
1919
use syntax::ast::{self, NodeId, DefId};
20-
use syntax::parse::token::keywords;
20+
use syntax::ast_util;
2121
use syntax::codemap::*;
22+
use syntax::parse::token::keywords;
23+
use syntax::visit::{self, Visitor};
2224

2325
use self::span_utils::SpanUtils;
2426

@@ -94,10 +96,60 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
9496
}
9597

9698
pub fn get_data_for_id(&self, id: &NodeId) -> Data {
99+
// TODO
97100
unimplemented!();
98101
}
99102
}
100103

104+
// An AST visitor for collecting paths from patterns.
105+
struct PathCollector {
106+
// TODO bool -> ast::mutable
107+
// TODO recorder -> var kind new enum
108+
// The Row field identifies the kind of formal variable.
109+
collected_paths: Vec<(NodeId, ast::Path, bool, recorder::Row)>,
110+
}
111+
112+
impl PathCollector {
113+
fn new() -> PathCollector {
114+
PathCollector {
115+
collected_paths: vec![],
116+
}
117+
}
118+
}
119+
120+
impl<'v> Visitor<'v> for PathCollector {
121+
fn visit_pat(&mut self, p: &ast::Pat) {
122+
match p.node {
123+
ast::PatStruct(ref path, _, _) => {
124+
self.collected_paths.push((p.id, path.clone(), false, recorder::StructRef));
125+
}
126+
ast::PatEnum(ref path, _) |
127+
ast::PatQPath(_, ref path) => {
128+
self.collected_paths.push((p.id, path.clone(), false, recorder::VarRef));
129+
}
130+
ast::PatIdent(bm, ref path1, _) => {
131+
let immut = match bm {
132+
// Even if the ref is mut, you can't change the ref, only
133+
// the data pointed at, so showing the initialising expression
134+
// is still worthwhile.
135+
ast::BindByRef(_) => true,
136+
ast::BindByValue(mt) => {
137+
match mt {
138+
ast::MutMutable => false,
139+
ast::MutImmutable => true,
140+
}
141+
}
142+
};
143+
// collect path for either visit_local or visit_arm
144+
let path = ast_util::ident_to_path(path1.span,path1.node);
145+
self.collected_paths.push((p.id, path, immut, recorder::VarRef));
146+
}
147+
_ => {}
148+
}
149+
visit::walk_pat(self, p);
150+
}
151+
}
152+
101153
#[allow(deprecated)]
102154
pub fn process_crate(sess: &Session,
103155
krate: &ast::Crate,

0 commit comments

Comments
 (0)