diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2015-07-31 00:04:06 -0700 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2015-09-03 10:02:36 +1200 |
| commit | facdf2ebb1dce9400a8c8ef0d85d7d278654effb (patch) | |
| tree | 3ba46bd98df35b4b5d1bc5f1ba491d14adb6f373 /src/librustc_back | |
| parent | cfd76b364cd01695517467299618ef63f1c0cc07 (diff) | |
| download | rust-facdf2ebb1dce9400a8c8ef0d85d7d278654effb.tar.gz rust-facdf2ebb1dce9400a8c8ef0d85d7d278654effb.zip | |
Add an intital HIR and lowering step
Diffstat (limited to 'src/librustc_back')
| -rw-r--r-- | src/librustc_back/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_back/svh.rs | 75 |
2 files changed, 15 insertions, 61 deletions
diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 9f503c0c33c..4a6646bca1b 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -48,6 +48,7 @@ extern crate syntax; extern crate libc; extern crate serialize; extern crate rustc_llvm; +extern crate rustc_front; #[macro_use] extern crate log; pub mod abi; diff --git a/src/librustc_back/svh.rs b/src/librustc_back/svh.rs index db0a291efbd..9f527341bcd 100644 --- a/src/librustc_back/svh.rs +++ b/src/librustc_back/svh.rs @@ -48,8 +48,8 @@ use std::fmt; use std::hash::{Hash, SipHasher, Hasher}; -use syntax::ast; -use syntax::visit; +use rustc_front::hir; +use rustc_front::visit; #[derive(Clone, PartialEq, Debug)] pub struct Svh { @@ -66,7 +66,7 @@ impl Svh { &self.hash } - pub fn calculate(metadata: &Vec<String>, krate: &ast::Crate) -> Svh { + pub fn calculate(metadata: &Vec<String>, krate: &hir::Crate) -> Svh { // FIXME (#14132): This is better than it used to be, but it still not // ideal. We now attempt to hash only the relevant portions of the // Crate AST as well as the top-level crate attributes. (However, @@ -131,13 +131,13 @@ mod svh_visitor { pub use self::SawExprComponent::*; pub use self::SawStmtComponent::*; use self::SawAbiComponent::*; - use syntax::ast; - use syntax::ast::*; + use syntax::ast::{self, NodeId, Ident}; use syntax::codemap::Span; use syntax::parse::token; - use syntax::print::pprust; - use syntax::visit; - use syntax::visit::{Visitor, FnKind}; + use rustc_front::visit; + use rustc_front::visit::{Visitor, FnKind}; + use rustc_front::hir::*; + use rustc_front::hir; use std::hash::{Hash, SipHasher}; @@ -230,9 +230,9 @@ mod svh_visitor { SawExprCall, SawExprMethodCall, SawExprTup, - SawExprBinary(ast::BinOp_), - SawExprUnary(ast::UnOp), - SawExprLit(ast::Lit_), + SawExprBinary(hir::BinOp_), + SawExprUnary(hir::UnOp), + SawExprLit(hir::Lit_), SawExprCast, SawExprIf, SawExprWhile, @@ -240,13 +240,13 @@ mod svh_visitor { SawExprClosure, SawExprBlock, SawExprAssign, - SawExprAssignOp(ast::BinOp_), + SawExprAssignOp(hir::BinOp_), SawExprIndex, SawExprRange, SawExprPath(Option<usize>), - SawExprAddrOf(ast::Mutability), + SawExprAddrOf(hir::Mutability), SawExprRet, - SawExprInlineAsm(&'a ast::InlineAsm), + SawExprInlineAsm(&'a hir::InlineAsm), SawExprStruct, SawExprRepeat, SawExprParen, @@ -284,12 +284,6 @@ mod svh_visitor { ExprStruct(..) => SawExprStruct, ExprRepeat(..) => SawExprRepeat, ExprParen(..) => SawExprParen, - - // just syntactic artifacts, expanded away by time of SVH. - ExprForLoop(..) => unreachable!(), - ExprIfLet(..) => unreachable!(), - ExprWhileLet(..) => unreachable!(), - ExprMac(..) => unreachable!(), } } @@ -306,51 +300,10 @@ mod svh_visitor { StmtDecl(..) => SawStmtDecl, StmtExpr(..) => SawStmtExpr, StmtSemi(..) => SawStmtSemi, - StmtMac(..) => unreachable!(), } } impl<'a, 'v> Visitor<'v> for StrictVersionHashVisitor<'a> { - - fn visit_mac(&mut self, mac: &Mac) { - // macro invocations, namely macro_rules definitions, - // *can* appear as items, even in the expanded crate AST. - - if ¯o_name(mac)[..] == "macro_rules" { - // Pretty-printing definition to a string strips out - // surface artifacts (currently), such as the span - // information, yielding a content-based hash. - - // FIXME (#14132): building temporary string is - // expensive; a direct content-based hash on token - // trees might be faster. Implementing this is far - // easier in short term. - let macro_defn_as_string = pprust::to_string(|pp_state| { - pp_state.print_mac(mac, token::Paren) - }); - macro_defn_as_string.hash(self.st); - } else { - // It is not possible to observe any kind of macro - // invocation at this stage except `macro_rules!`. - panic!("reached macro somehow: {}", - pprust::to_string(|pp_state| { - pp_state.print_mac(mac, token::Paren) - })); - } - - visit::walk_mac(self, mac); - - fn macro_name(mac: &Mac) -> token::InternedString { - match &mac.node { - &MacInvocTT(ref path, ref _tts, ref _stx_ctxt) => { - let s = &path.segments; - assert_eq!(s.len(), 1); - s[0].identifier.name.as_str() - } - } - } - } - fn visit_struct_def(&mut self, s: &StructDef, ident: Ident, g: &Generics, _: NodeId) { SawStructDef(ident.name.as_str()).hash(self.st); |
