diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-05-26 22:00:08 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-05-26 22:44:38 +1000 |
| commit | 6ddd40d4368b1dbbc6bfa18d73d47beb05a55447 (patch) | |
| tree | 8c6174fc1eb31872755870db27f6c60423e74627 /src/libsyntax | |
| parent | 6fad19e16b2770c6641d7a457415d4c4c65e1f8d (diff) | |
| download | rust-6ddd40d4368b1dbbc6bfa18d73d47beb05a55447.tar.gz rust-6ddd40d4368b1dbbc6bfa18d73d47beb05a55447.zip | |
syntax: Add a source field to `Local` for tracking if it comes from `let`s or `for`s.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 3 |
5 files changed, 17 insertions, 2 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e77d1faf05d..69a92a87185 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -417,6 +417,14 @@ pub enum Stmt_ { StmtMac(Mac, bool), } +/// Where a local declaration came from: either a true `let ... = +/// ...;`, or one desugared from the pattern of a for loop. +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] +pub enum LocalSource { + LocalLet, + LocalFor, +} + // FIXME (pending discussion of #1697, #2178...): local should really be // a refinement on pat. /// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;` @@ -427,6 +435,7 @@ pub struct Local { pub init: Option<@Expr>, pub id: NodeId, pub span: Span, + pub source: LocalSource, } pub type Decl = Spanned<Decl_>; diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 449feb3afbf..bb7b73c5f81 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -439,6 +439,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { init: Some(ex), id: ast::DUMMY_NODE_ID, span: sp, + source: ast::LocalLet, }; let decl = respan(sp, ast::DeclLocal(local)); @respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID)) @@ -462,6 +463,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { init: Some(ex), id: ast::DUMMY_NODE_ID, span: sp, + source: ast::LocalLet, }; let decl = respan(sp, ast::DeclLocal(local)); @respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID)) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 6c6bf520104..762363f3abe 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -669,7 +669,8 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander) pat: pat, init: init, id: id, - span: span + span: span, + source: source, } = **local; // expand the pat (it might contain exprs... #:(o)> let expanded_pat = fld.fold_pat(pat); @@ -703,6 +704,7 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander) init: new_init_opt, id: id, span: span, + source: source }; SmallVector::one(@Spanned { node: StmtDecl(@Spanned { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index ae5cf550bb9..6a9f26ae83d 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -288,6 +288,7 @@ pub trait Folder { pat: self.fold_pat(l.pat), init: l.init.map(|e| self.fold_expr(e)), span: self.new_span(l.span), + source: l.source, } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ae5f16c2580..65687ce4d94 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -34,7 +34,7 @@ use ast::{Ident, NormalFn, Inherited, Item, Item_, ItemStatic}; use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl}; use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, Lit, Lit_}; use ast::{LitBool, LitFloat, LitFloatUnsuffixed, LitInt, LitChar}; -use ast::{LitIntUnsuffixed, LitNil, LitStr, LitUint, Local}; +use ast::{LitIntUnsuffixed, LitNil, LitStr, LitUint, Local, LocalLet}; use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, Matcher, MatchNonterminal}; use ast::{MatchSeq, MatchTok, Method, MutTy, BiMul, Mutability}; use ast::{NamedField, UnNeg, NoReturn, UnNot, P, Pat, PatEnum}; @@ -3034,6 +3034,7 @@ impl<'a> Parser<'a> { init: init, id: ast::DUMMY_NODE_ID, span: mk_sp(lo, self.last_span.hi), + source: LocalLet, } } |
