Add an intital HIR and lowering step
This commit is contained in:
parent
cfd76b364c
commit
facdf2ebb1
160 changed files with 13917 additions and 4451 deletions
|
|
@ -20,9 +20,9 @@ use std::iter::repeat;
|
|||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::visit;
|
||||
use syntax::visit::Visitor;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::visit::Visitor;
|
||||
|
||||
// The name of the associated type for `Fn` return types
|
||||
pub const FN_OUTPUT_NAME: &'static str = "Output";
|
||||
|
|
@ -152,18 +152,18 @@ pub fn indenter() -> Indenter {
|
|||
Indenter { _cannot_construct_outside_of_this_module: () }
|
||||
}
|
||||
|
||||
struct LoopQueryVisitor<P> where P: FnMut(&ast::Expr_) -> bool {
|
||||
struct LoopQueryVisitor<P> where P: FnMut(&hir::Expr_) -> bool {
|
||||
p: P,
|
||||
flag: bool,
|
||||
}
|
||||
|
||||
impl<'v, P> Visitor<'v> for LoopQueryVisitor<P> where P: FnMut(&ast::Expr_) -> bool {
|
||||
fn visit_expr(&mut self, e: &ast::Expr) {
|
||||
impl<'v, P> Visitor<'v> for LoopQueryVisitor<P> where P: FnMut(&hir::Expr_) -> bool {
|
||||
fn visit_expr(&mut self, e: &hir::Expr) {
|
||||
self.flag |= (self.p)(&e.node);
|
||||
match e.node {
|
||||
// Skip inner loops, since a break in the inner loop isn't a
|
||||
// break inside the outer loop
|
||||
ast::ExprLoop(..) | ast::ExprWhile(..) => {}
|
||||
hir::ExprLoop(..) | hir::ExprWhile(..) => {}
|
||||
_ => visit::walk_expr(self, e)
|
||||
}
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ impl<'v, P> Visitor<'v> for LoopQueryVisitor<P> where P: FnMut(&ast::Expr_) -> b
|
|||
|
||||
// Takes a predicate p, returns true iff p is true for any subexpressions
|
||||
// of b -- skipping any inner loops (loop, while, loop_body)
|
||||
pub fn loop_query<P>(b: &ast::Block, p: P) -> bool where P: FnMut(&ast::Expr_) -> bool {
|
||||
pub fn loop_query<P>(b: &hir::Block, p: P) -> bool where P: FnMut(&hir::Expr_) -> bool {
|
||||
let mut v = LoopQueryVisitor {
|
||||
p: p,
|
||||
flag: false,
|
||||
|
|
@ -180,13 +180,13 @@ pub fn loop_query<P>(b: &ast::Block, p: P) -> bool where P: FnMut(&ast::Expr_) -
|
|||
return v.flag;
|
||||
}
|
||||
|
||||
struct BlockQueryVisitor<P> where P: FnMut(&ast::Expr) -> bool {
|
||||
struct BlockQueryVisitor<P> where P: FnMut(&hir::Expr) -> bool {
|
||||
p: P,
|
||||
flag: bool,
|
||||
}
|
||||
|
||||
impl<'v, P> Visitor<'v> for BlockQueryVisitor<P> where P: FnMut(&ast::Expr) -> bool {
|
||||
fn visit_expr(&mut self, e: &ast::Expr) {
|
||||
impl<'v, P> Visitor<'v> for BlockQueryVisitor<P> where P: FnMut(&hir::Expr) -> bool {
|
||||
fn visit_expr(&mut self, e: &hir::Expr) {
|
||||
self.flag |= (self.p)(e);
|
||||
visit::walk_expr(self, e)
|
||||
}
|
||||
|
|
@ -194,7 +194,7 @@ impl<'v, P> Visitor<'v> for BlockQueryVisitor<P> where P: FnMut(&ast::Expr) -> b
|
|||
|
||||
// Takes a predicate p, returns true iff p is true for any subexpressions
|
||||
// of b -- skipping any inner loops (loop, while, loop_body)
|
||||
pub fn block_query<P>(b: &ast::Block, p: P) -> bool where P: FnMut(&ast::Expr) -> bool {
|
||||
pub fn block_query<P>(b: &hir::Block, p: P) -> bool where P: FnMut(&hir::Expr) -> bool {
|
||||
let mut v = BlockQueryVisitor {
|
||||
p: p,
|
||||
flag: false,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ use middle::ty_fold::{self, TypeFoldable};
|
|||
use std::fmt;
|
||||
use syntax::abi;
|
||||
use syntax::parse::token;
|
||||
use syntax::{ast, ast_util};
|
||||
use syntax::ast::DUMMY_NODE_ID;
|
||||
use rustc_front::hir as ast;
|
||||
|
||||
pub fn verbose() -> bool {
|
||||
ty::tls::with(|tcx| tcx.sess.verbose())
|
||||
|
|
@ -230,7 +231,7 @@ fn in_binder<'tcx, T, U>(f: &mut fmt::Formatter,
|
|||
ty::BrEnv => {
|
||||
let name = token::intern("'r");
|
||||
let _ = write!(f, "{}", name);
|
||||
ty::BrNamed(DefId::local(ast::DUMMY_NODE_ID), name)
|
||||
ty::BrNamed(DefId::local(DUMMY_NODE_ID), name)
|
||||
}
|
||||
})
|
||||
}).0;
|
||||
|
|
@ -623,14 +624,55 @@ impl<'tcx> fmt::Display for ty::TraitRef<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn int_ty_to_string(t: ast::IntTy, val: Option<i64>) -> String {
|
||||
let s = match t {
|
||||
ast::TyIs => "isize",
|
||||
ast::TyI8 => "i8",
|
||||
ast::TyI16 => "i16",
|
||||
ast::TyI32 => "i32",
|
||||
ast::TyI64 => "i64"
|
||||
};
|
||||
|
||||
match val {
|
||||
// cast to a u64 so we can correctly print INT64_MIN. All integral types
|
||||
// are parsed as u64, so we wouldn't want to print an extra negative
|
||||
// sign.
|
||||
Some(n) => format!("{}{}", n as u64, s),
|
||||
None => s.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn uint_ty_to_string(t: ast::UintTy, val: Option<u64>) -> String {
|
||||
let s = match t {
|
||||
ast::TyUs => "usize",
|
||||
ast::TyU8 => "u8",
|
||||
ast::TyU16 => "u16",
|
||||
ast::TyU32 => "u32",
|
||||
ast::TyU64 => "u64"
|
||||
};
|
||||
|
||||
match val {
|
||||
Some(n) => format!("{}{}", n, s),
|
||||
None => s.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn float_ty_to_string(t: ast::FloatTy) -> String {
|
||||
match t {
|
||||
ast::TyF32 => "f32".to_string(),
|
||||
ast::TyF64 => "f64".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
TyBool => write!(f, "bool"),
|
||||
TyChar => write!(f, "char"),
|
||||
TyInt(t) => write!(f, "{}", ast_util::int_ty_to_string(t, None)),
|
||||
TyUint(t) => write!(f, "{}", ast_util::uint_ty_to_string(t, None)),
|
||||
TyFloat(t) => write!(f, "{}", ast_util::float_ty_to_string(t)),
|
||||
TyInt(t) => write!(f, "{}", int_ty_to_string(t, None)),
|
||||
TyUint(t) => write!(f, "{}", uint_ty_to_string(t, None)),
|
||||
TyFloat(t) => write!(f, "{}", float_ty_to_string(t)),
|
||||
TyBox(typ) => write!(f, "Box<{}>", typ),
|
||||
TyRawPtr(ref tm) => {
|
||||
write!(f, "*{} {}", match tm.mutbl {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue