syntax: Add a source field to Local
for tracking if it comes from let
s or for
s.
This commit is contained in:
parent
6fad19e16b
commit
6ddd40d436
@ -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_>;
|
||||
|
@ -439,6 +439,7 @@ fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident, ex: @ast::Expr) ->
|
||||
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 @@ fn stmt_let_typed(&self,
|
||||
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))
|
||||
|
@ -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 {
|
||||
|
@ -288,6 +288,7 @@ fn fold_local(&mut self, l: @Local) -> @Local {
|
||||
pat: self.fold_pat(l.pat),
|
||||
init: l.init.map(|e| self.fold_expr(e)),
|
||||
span: self.new_span(l.span),
|
||||
source: l.source,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
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 @@ fn parse_local(&mut self) -> @Local {
|
||||
init: init,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: mk_sp(lo, self.last_span.hi),
|
||||
source: LocalLet,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user