(index<- )        ./librustc/metadata/tydecode.rs

    git branch:    * master           5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
    modified:    Fri May  9 13:02:28 2014
   1  // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
   2  // file at the top-level directory of this distribution and at
   3  // http://rust-lang.org/COPYRIGHT.
   4  //
   5  // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
   6  // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
   7  // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
   8  // option. This file may not be copied, modified, or distributed
   9  // except according to those terms.
  10  
  11  
  12  // Type decoding
  13  
  14  // tjc note: Would be great to have a `match check` macro equivalent
  15  // for some of these
  16  
  17  #![allow(non_camel_case_types)]
  18  
  19  use middle::ty;
  20  
  21  use std::rc::Rc;
  22  use std::str;
  23  use std::strbuf::StrBuf;
  24  use std::uint;
  25  use syntax::abi;
  26  use syntax::ast;
  27  use syntax::ast::*;
  28  use syntax::owned_slice::OwnedSlice;
  29  use syntax::parse::token;
  30  
  31  // Compact string representation for ty::t values. API ty_str &
  32  // parse_from_str. Extra parameters are for converting to/from def_ids in the
  33  // data buffer. Whatever format you choose should not contain pipe characters.
  34  
  35  // Def id conversion: when we encounter def-ids, they have to be translated.
  36  // For example, the crate number must be converted from the crate number used
  37  // in the library we are reading from into the local crate numbers in use
  38  // here.  To perform this translation, the type decoder is supplied with a
  39  // conversion function of type `conv_did`.
  40  //
  41  // Sometimes, particularly when inlining, the correct translation of the
  42  // def-id will depend on where it originated from.  Therefore, the conversion
  43  // function is given an indicator of the source of the def-id.  See
  44  // astencode.rs for more information.
  45  pub enum DefIdSource {
  46      // Identifies a struct, trait, enum, etc.
  47      NominalType,
  48  
  49      // Identifies a type alias (`type X = ...`).
  50      TypeWithId,
  51  
  52      // Identifies a type parameter (`fn foo<X>() { ... }`).
  53      TypeParameter,
  54  
  55      // Identifies a region parameter (`fn foo<'X>() { ... }`).
  56      RegionParameter,
  57  }
  58  pub type conv_did<'a> =
  59      |source: DefIdSource, ast::DefId|: 'a -> ast::DefId;
  60  
  61  pub struct PState<'a> {
  62      data: &'a [u8],
  63      krate: ast::CrateNum,
  64      pos: uint,
  65      tcx: &'a ty::ctxt
  66  }
  67  
  68  fn peek(st: &PState) -> char {
  69      st.data[st.pos] as char
  70  }
  71  
  72  fn next(st: &mut PState) -> char {
  73      let ch = st.data[st.pos] as char;
  74      st.pos = st.pos + 1u;
  75      return ch;
  76  }
  77  
  78  fn next_byte(st: &mut PState) -> u8 {
  79      let b = st.data[st.pos];
  80      st.pos = st.pos + 1u;
  81      return b;
  82  }
  83  
  84  fn scan<R>(st: &mut PState, is_last: |char| -> bool, op: |&[u8]-> R) -> R {
  85      let start_pos = st.pos;
  86      debug!("scan: '{}(start)", st.data[st.pos] as char);
  87      while !is_last(st.data[st.pos] as char) {
  88          st.pos += 1;
  89          debug!("scan: '{}'", st.data[st.pos] as char);
  90      }
  91      let end_pos = st.pos;
  92      st.pos += 1;
  93      return op(st.data.slice(start_pos, end_pos));
  94  }
  95  
  96  pub fn parse_ident(st: &mut PState, last: char) -> ast::Ident {
  97      fn is_last(bchar, cchar) -> bool { return c == b; }
  98      return parse_ident_(st, |a| is_last(last, a) );
  99  }
 100  
 101  fn parse_ident_(st: &mut PState, is_last: |char| -> bool) -> ast::Ident {
 102      scan(st, is_last, |bytes| {
 103          token::str_to_ident(str::from_utf8(bytes).unwrap())
 104      })
 105  }
 106  
 107  pub fn parse_state_from_data<'a>(data: &'a [u8], crate_numast::CrateNum,
 108                               pos: uint, tcx: &'a ty::ctxt) -> PState<'a> {
 109      PState {
 110          data: data,
 111          krate: crate_num,
 112          pos: pos,
 113          tcx: tcx
 114      }
 115  }
 116  
 117  pub fn parse_ty_data(data: &[u8], crate_numast::CrateNum, pos: uint, tcx: &ty::ctxt,
 118                       convconv_did) -> ty::t {
 119      let mut st = parse_state_from_data(data, crate_num, pos, tcx);
 120      parse_ty(&mut st, conv)
 121  }
 122  
 123  pub fn parse_bare_fn_ty_data(data: &[u8], crate_numast::CrateNum, pos: uint, tcx: &ty::ctxt,
 124                               convconv_did) -> ty::BareFnTy {
 125      let mut st = parse_state_from_data(data, crate_num, pos, tcx);
 126      parse_bare_fn_ty(&mut st, conv)
 127  }
 128  
 129  pub fn parse_trait_ref_data(data: &[u8], crate_numast::CrateNum, pos: uint, tcx: &ty::ctxt,
 130                              convconv_did) -> ty::TraitRef {
 131      let mut st = parse_state_from_data(data, crate_num, pos, tcx);
 132      parse_trait_ref(&mut st, conv)
 133  }
 134  
 135  pub fn parse_substs_data(data: &[u8], crate_numast::CrateNum, pos: uint, tcx: &ty::ctxt,
 136                           convconv_did) -> ty::substs {
 137      let mut st = parse_state_from_data(data, crate_num, pos, tcx);
 138      parse_substs(&mut st, conv)
 139  }
 140  
 141  fn parse_size(st: &mut PState) -> Option<uint> {
 142      assert_eq!(next(st), '/');
 143  
 144      if peek(st) == '|' {
 145          assert_eq!(next(st), '|');
 146          None
 147      } else {
 148          let n = parse_uint(st);
 149          assert_eq!(next(st), '|');
 150          Some(n)
 151      }
 152  }
 153  
 154  fn parse_trait_store(st: &mut PState, convconv_did) -> ty::TraitStore {
 155      match next(st) {
 156          '~' => ty::UniqTraitStore,
 157          '&' => ty::RegionTraitStore(parse_region(st, conv), parse_mutability(st)),
 158          c => st.tcx.sess.bug(format!("parse_trait_store(): bad input '{}'", c))
 159      }
 160  }
 161  
 162  fn parse_substs(st: &mut PState, convconv_did) -> ty::substs {
 163      let regions = parse_region_substs(st, |x,y| conv(x,y));
 164  
 165      let self_ty = parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)) );
 166  
 167      assert_eq!(next(st), '[');
 168      let mut paramsVec<ty::t> = Vec::new();
 169      while peek(st) != ']' { params.push(parse_ty(st, |x,y| conv(x,y))); }
 170      st.pos = st.pos + 1u;
 171  
 172      return ty::substs {
 173          regions: regions,
 174          self_ty: self_ty,
 175          tps: params
 176      };
 177  }
 178  
 179  fn parse_region_substs(st: &mut PState, convconv_did) -> ty::RegionSubsts {
 180      match next(st) {
 181          'e' => ty::ErasedRegions,
 182          'n' => {
 183              let mut regions = vec!();
 184              while peek(st) != '.' {
 185                  let r = parse_region(st, |x,y| conv(x,y));
 186                  regions.push(r);
 187              }
 188              assert_eq!(next(st), '.');
 189              ty::NonerasedRegions(OwnedSlice::from_vec(regions))
 190          }
 191          _ => fail!("parse_bound_region: bad input")
 192      }
 193  }
 194  
 195  fn parse_bound_region(st: &mut PState, convconv_did) -> ty::BoundRegion {
 196      match next(st) {
 197          'a' => {
 198              let id = parse_uint(st);
 199              assert_eq!(next(st), '|');
 200              ty::BrAnon(id)
 201          }
 202          '[' => {
 203              let def = parse_def(st, RegionParameter, |x,y| conv(x,y));
 204              let ident = token::str_to_ident(parse_str(st, ']'));
 205              ty::BrNamed(def, ident.name)
 206          }
 207          'f' => {
 208              let id = parse_uint(st);
 209              assert_eq!(next(st), '|');
 210              ty::BrFresh(id)
 211          }
 212          _ => fail!("parse_bound_region: bad input")
 213      }
 214  }
 215  
 216  fn parse_region(st: &mut PState, convconv_did) -> ty::Region {
 217      match next(st) {
 218        'b' => {
 219          assert_eq!(next(st), '[');
 220          let id = parse_uint(st) as ast::NodeId;
 221          assert_eq!(next(st), '|');
 222          let br = parse_bound_region(st, |x,y| conv(x,y));
 223          assert_eq!(next(st), ']');
 224          ty::ReLateBound(id, br)
 225        }
 226        'B' => {
 227          assert_eq!(next(st), '[');
 228          let node_id = parse_uint(st) as ast::NodeId;
 229          assert_eq!(next(st), '|');
 230          let index = parse_uint(st);
 231          assert_eq!(next(st), '|');
 232          let nm = token::str_to_ident(parse_str(st, ']'));
 233          ty::ReEarlyBound(node_id, index, nm.name)
 234        }
 235        'f' => {
 236          assert_eq!(next(st), '[');
 237          let id = parse_uint(st) as ast::NodeId;
 238          assert_eq!(next(st), '|');
 239          let br = parse_bound_region(st, |x,y| conv(x,y));
 240          assert_eq!(next(st), ']');
 241          ty::ReFree(ty::FreeRegion {scope_id: id,
 242                                      bound_region: br})
 243        }
 244        's' => {
 245          let id = parse_uint(st) as ast::NodeId;
 246          assert_eq!(next(st), '|');
 247          ty::ReScope(id)
 248        }
 249        't' => {
 250          ty::ReStatic
 251        }
 252        'e' => {
 253          ty::ReStatic
 254        }
 255        _ => fail!("parse_region: bad input")
 256      }
 257  }
 258  
 259  fn parse_opt<T>(st: &mut PState, f: |&mut PState-> T) -> Option<T> {
 260      match next(st) {
 261        'n' => None,
 262        's' => Some(f(st)),
 263        _ => fail!("parse_opt: bad input")
 264      }
 265  }
 266  
 267  fn parse_str(st: &mut PState, term: char) -> ~str {
 268      let mut result = StrBuf::new();
 269      while peek(st) != term {
 270          unsafe {
 271              result.push_bytes([next_byte(st)])
 272          }
 273      }
 274      next(st);
 275      return result.into_owned();
 276  }
 277  
 278  fn parse_trait_ref(st: &mut PState, convconv_did) -> ty::TraitRef {
 279      let def = parse_def(st, NominalType, |x,y| conv(x,y));
 280      let substs = parse_substs(st, |x,y| conv(x,y));
 281      ty::TraitRef {def_id: def, substs: substs}
 282  }
 283  
 284  fn parse_ty(st: &mut PState, convconv_did) -> ty::t {
 285      match next(st) {
 286        'n' => return ty::mk_nil(),
 287        'z' => return ty::mk_bot(),
 288        'b' => return ty::mk_bool(),
 289        'i' => return ty::mk_int(),
 290        'u' => return ty::mk_uint(),
 291        'M' => {
 292          match next(st) {
 293            'b' => return ty::mk_mach_uint(ast::TyU8),
 294            'w' => return ty::mk_mach_uint(ast::TyU16),
 295            'l' => return ty::mk_mach_uint(ast::TyU32),
 296            'd' => return ty::mk_mach_uint(ast::TyU64),
 297            'B' => return ty::mk_mach_int(ast::TyI8),
 298            'W' => return ty::mk_mach_int(ast::TyI16),
 299            'L' => return ty::mk_mach_int(ast::TyI32),
 300            'D' => return ty::mk_mach_int(ast::TyI64),
 301            'f' => return ty::mk_mach_float(ast::TyF32),
 302            'F' => return ty::mk_mach_float(ast::TyF64),
 303            'Q' => return ty::mk_mach_float(ast::TyF128),
 304            _ => fail!("parse_ty: bad numeric type")
 305          }
 306        }
 307        'c' => return ty::mk_char(),
 308        't' => {
 309          assert_eq!(next(st), '[');
 310          let def = parse_def(st, NominalType, |x,y| conv(x,y));
 311          let substs = parse_substs(st, |x,y| conv(x,y));
 312          assert_eq!(next(st), ']');
 313          return ty::mk_enum(st.tcx, def, substs);
 314        }
 315        'x' => {
 316          assert_eq!(next(st), '[');
 317          let def = parse_def(st, NominalType, |x,y| conv(x,y));
 318          let substs = parse_substs(st, |x,y| conv(x,y));
 319          let store = parse_trait_store(st, |x,y| conv(x,y));
 320          let bounds = parse_bounds(st, |x,y| conv(x,y));
 321          assert_eq!(next(st), ']');
 322          return ty::mk_trait(st.tcx, def, substs, store, bounds.builtin_bounds);
 323        }
 324        'p' => {
 325          let did = parse_def(st, TypeParameter, |x,y| conv(x,y));
 326          debug!("parsed ty_param: did={:?}", did);
 327          return ty::mk_param(st.tcx, parse_uint(st), did);
 328        }
 329        's' => {
 330          let did = parse_def(st, TypeParameter, |x,y| conv(x,y));
 331          return ty::mk_self(st.tcx, did);
 332        }
 333        '@' => return ty::mk_box(st.tcx, parse_ty(st, |x,y| conv(x,y))),
 334        '~' => return ty::mk_uniq(st.tcx, parse_ty(st, |x,y| conv(x,y))),
 335        '*' => return ty::mk_ptr(st.tcx, parse_mt(st, |x,y| conv(x,y))),
 336        '&' => {
 337          let r = parse_region(st, |x,y| conv(x,y));
 338          let mt = parse_mt(st, |x,y| conv(x,y));
 339          return ty::mk_rptr(st.tcx, r, mt);
 340        }
 341        'V' => {
 342          let mt = parse_mt(st, |x,y| conv(x,y));
 343          let sz = parse_size(st);
 344          return ty::mk_vec(st.tcx, mt, sz);
 345        }
 346        'v' => {
 347          return ty::mk_str(st.tcx);
 348        }
 349        'T' => {
 350          assert_eq!(next(st), '[');
 351          let mut params = Vec::new();
 352          while peek(st) != ']' { params.push(parse_ty(st, |x,y| conv(x,y))); }
 353          st.pos = st.pos + 1u;
 354          return ty::mk_tup(st.tcx, params);
 355        }
 356        'f' => {
 357          return ty::mk_closure(st.tcx, parse_closure_ty(st, |x,y| conv(x,y)));
 358        }
 359        'F' => {
 360          return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, |x,y| conv(x,y)));
 361        }
 362        '#' => {
 363          let pos = parse_hex(st);
 364          assert_eq!(next(st), ':');
 365          let len = parse_hex(st);
 366          assert_eq!(next(st), '#');
 367          let key = ty::creader_cache_key {cnum: st.krate,
 368                                           pos: pos,
 369                                           len: len };
 370  
 371          match st.tcx.rcache.borrow().find_copy(&key) {
 372            Some(tt) => return tt,
 373            None => {}
 374          }
 375          let mut ps = PState {
 376              pos: pos,
 377              .. *st
 378          };
 379          let tt = parse_ty(&mut ps, |x,y| conv(x,y));
 380          st.tcx.rcache.borrow_mut().insert(key, tt);
 381          return tt;
 382        }
 383        '"' => {
 384          let _ = parse_def(st, TypeWithId, |x,y| conv(x,y));
 385          let inner = parse_ty(st, |x,y| conv(x,y));
 386          inner
 387        }
 388        'a' => {
 389            assert_eq!(next(st), '[');
 390            let did = parse_def(st, NominalType, |x,y| conv(x,y));
 391            let substs = parse_substs(st, |x,y| conv(x,y));
 392            assert_eq!(next(st), ']');
 393            return ty::mk_struct(st.tcx, did, substs);
 394        }
 395        c => { fail!("unexpected char in type string: {}", c);}
 396      }
 397  }
 398  
 399  fn parse_mutability(st: &mut PState) -> ast::Mutability {
 400      match peek(st) {
 401        'm' => { next(st); ast::MutMutable }
 402        _ => { ast::MutImmutable }
 403      }
 404  }
 405  
 406  fn parse_mt(st: &mut PState, convconv_did) -> ty::mt {
 407      let m = parse_mutability(st);
 408      ty::mt { ty: parse_ty(st, |x,y| conv(x,y)), mutbl: m }
 409  }
 410  
 411  fn parse_def(st: &mut PState, sourceDefIdSource,
 412               convconv_did) -> ast::DefId {
 413      return conv(source, scan(st, |c| { c == '|' }, parse_def_id));
 414  }
 415  
 416  fn parse_uint(st: &mut PState) -> uint {
 417      let mut n = 0;
 418      loop {
 419          let cur = peek(st);
 420          if cur < '0' || cur > '9' { return n; }
 421          st.pos = st.pos + 1u;
 422          n *= 10;
 423          n += (cur as uint) - ('0' as uint);
 424      };
 425  }
 426  
 427  fn parse_hex(st: &mut PState) -> uint {
 428      let mut n = 0u;
 429      loop {
 430          let cur = peek(st);
 431          if (cur < '0' || cur > '9') && (cur < 'a' || cur > 'f') { return n; }
 432          st.pos = st.pos + 1u;
 433          n *= 16u;
 434          if '0' <= cur && cur <= '9' {
 435              n += (cur as uint) - ('0' as uint);
 436          } else { n += 10u + (cur as uint) - ('a' as uint); }
 437      };
 438  }
 439  
 440  fn parse_fn_style(c: char) -> FnStyle {
 441      match c {
 442          'u' => UnsafeFn,
 443          'n' => NormalFn,
 444          _ => fail!("parse_fn_style: bad fn_style {}", c)
 445      }
 446  }
 447  
 448  fn parse_abi_set(st: &mut PState) -> abi::Abi {
 449      assert_eq!(next(st), '[');
 450      scan(st, |c| c == ']', |bytes| {
 451          let abi_str = str::from_utf8(bytes).unwrap().to_owned();
 452          abi::lookup(abi_str).expect(abi_str)
 453      })
 454  }
 455  
 456  fn parse_onceness(c: char) -> ast::Onceness {
 457      match c {
 458          'o' => ast::Once,
 459          'm' => ast::Many,
 460          _ => fail!("parse_onceness: bad onceness")
 461      }
 462  }
 463  
 464  fn parse_closure_ty(st: &mut PState, convconv_did) -> ty::ClosureTy {
 465      let fn_style = parse_fn_style(next(st));
 466      let onceness = parse_onceness(next(st));
 467      let store = parse_trait_store(st, |x,y| conv(x,y));
 468      let bounds = parse_bounds(st, |x,y| conv(x,y));
 469      let sig = parse_sig(st, |x,y| conv(x,y));
 470      ty::ClosureTy {
 471          fn_style: fn_style,
 472          onceness: onceness,
 473          store: store,
 474          bounds: bounds.builtin_bounds,
 475          sig: sig
 476      }
 477  }
 478  
 479  fn parse_bare_fn_ty(st: &mut PState, convconv_did) -> ty::BareFnTy {
 480      let fn_style = parse_fn_style(next(st));
 481      let abi = parse_abi_set(st);
 482      let sig = parse_sig(st, |x,y| conv(x,y));
 483      ty::BareFnTy {
 484          fn_style: fn_style,
 485          abi: abi,
 486          sig: sig
 487      }
 488  }
 489  
 490  fn parse_sig(st: &mut PState, convconv_did) -> ty::FnSig {
 491      assert_eq!(next(st), '[');
 492      let id = parse_uint(st) as ast::NodeId;
 493      assert_eq!(next(st), '|');
 494      let mut inputs = Vec::new();
 495      while peek(st) != ']' {
 496          inputs.push(parse_ty(st, |x,y| conv(x,y)));
 497      }
 498      st.pos += 1u; // eat the ']'
 499      let variadic = match next(st) {
 500          'V' => true,
 501          'N' => false,
 502          r => fail!(format!("bad variadic: {}", r)),
 503      };
 504      let ret_ty = parse_ty(st, |x,y| conv(x,y));
 505      ty::FnSig {binder_id: id,
 506                 inputs: inputs,
 507                 output: ret_ty,
 508                 variadic: variadic}
 509  }
 510  
 511  // Rust metadata parsing
 512  pub fn parse_def_id(buf: &[u8]) -> ast::DefId {
 513      let mut colon_idx = 0u;
 514      let len = buf.len();
 515      while colon_idx < len && buf[colon_idx] != ':' as u8 { colon_idx += 1u; }
 516      if colon_idx == len {
 517          error!("didn't find ':' when parsing def id");
 518          fail!();
 519      }
 520  
 521      let crate_part = buf.slice(0u, colon_idx);
 522      let def_part = buf.slice(colon_idx + 1u, len);
 523  
 524      let crate_num = match uint::parse_bytes(crate_part, 10u) {
 525         Some(cn) => cn as ast::CrateNum,
 526         None => fail!("internal error: parse_def_id: crate number expected, but found {:?}",
 527                       crate_part)
 528      };
 529      let def_num = match uint::parse_bytes(def_part, 10u) {
 530         Some(dn) => dn as ast::NodeId,
 531         None => fail!("internal error: parse_def_id: id expected, but found {:?}",
 532                       def_part)
 533      };
 534      ast::DefId { krate: crate_num, node: def_num }
 535  }
 536  
 537  pub fn parse_type_param_def_data(data: &[u8], start: uint,
 538                                   crate_numast::CrateNum, tcx: &ty::ctxt,
 539                                   convconv_did) -> ty::TypeParameterDef
 540  {
 541      let mut st = parse_state_from_data(data, crate_num, start, tcx);
 542      parse_type_param_def(&mut st, conv)
 543  }
 544  
 545  fn parse_type_param_def(st: &mut PState, convconv_did) -> ty::TypeParameterDef {
 546      ty::TypeParameterDef {
 547          ident: parse_ident(st, ':'),
 548          def_id: parse_def(st, NominalType, |x,y| conv(x,y)),
 549          bounds: Rc::new(parse_bounds(st, |x,y| conv(x,y))),
 550          default: parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)))
 551      }
 552  }
 553  
 554  fn parse_bounds(st: &mut PState, convconv_did) -> ty::ParamBounds {
 555      let mut param_bounds = ty::ParamBounds {
 556          builtin_bounds: ty::EmptyBuiltinBounds(),
 557          trait_bounds: Vec::new()
 558      };
 559      loop {
 560          match next(st) {
 561              'S' => {
 562                  param_bounds.builtin_bounds.add(ty::BoundSend);
 563              }
 564              'O' => {
 565                  param_bounds.builtin_bounds.add(ty::BoundStatic);
 566              }
 567              'Z' => {
 568                  param_bounds.builtin_bounds.add(ty::BoundSized);
 569              }
 570              'P' => {
 571                  param_bounds.builtin_bounds.add(ty::BoundCopy);
 572              }
 573              'T' => {
 574                  param_bounds.builtin_bounds.add(ty::BoundShare);
 575              }
 576              'I' => {
 577                  param_bounds.trait_bounds.push(Rc::new(parse_trait_ref(st, |x,y| conv(x,y))));
 578              }
 579              '.' => {
 580                  return param_bounds;
 581              }
 582              c => {
 583                  fail!("parse_bounds: bad bounds ('{}')", c)
 584              }
 585          }
 586      }
 587  }


librustc/metadata/tydecode.rs:405:1-405:1 -fn- definition:
fn parse_mt(st: &mut PState, conv: conv_did) -> ty::mt {
    let m = parse_mutability(st);
    ty::mt { ty: parse_ty(st, |x,y| conv(x,y)), mutbl: m }
references:- 3
337:         let r = parse_region(st, |x,y| conv(x,y));
338:         let mt = parse_mt(st, |x,y| conv(x,y));
339:         return ty::mk_rptr(st.tcx, r, mt);
--
341:       'V' => {
342:         let mt = parse_mt(st, |x,y| conv(x,y));
343:         let sz = parse_size(st);


librustc/metadata/tydecode.rs:71:1-71:1 -fn- definition:
fn next(st: &mut PState) -> char {
    let ch = st.data[st.pos] as char;
    st.pos = st.pos + 1u;
references:- 43


librustc/metadata/tydecode.rs:489:1-489:1 -fn- definition:
fn parse_sig(st: &mut PState, conv: conv_did) -> ty::FnSig {
    assert_eq!(next(st), '[');
    let id = parse_uint(st) as ast::NodeId;
references:- 2
468:     let bounds = parse_bounds(st, |x,y| conv(x,y));
469:     let sig = parse_sig(st, |x,y| conv(x,y));
470:     ty::ClosureTy {
--
481:     let abi = parse_abi_set(st);
482:     let sig = parse_sig(st, |x,y| conv(x,y));
483:     ty::BareFnTy {


librustc/metadata/tydecode.rs:536:1-536:1 -fn- definition:
pub fn parse_type_param_def_data(data: &[u8], start: uint,
                                 crate_num: ast::CrateNum, tcx: &ty::ctxt,
                                 conv: conv_did) -> ty::TypeParameterDef
references:- 2
librustc/metadata/decoder.rs:
260:     reader::tagged_docs(item, tag, |p| {
261:         let bd = parse_type_param_def_data(
262:             p.data, p.start, cdata.cnum, tcx,
librustc/middle/astencode.rs:
1152:         self.read_opaque(|this, doc| {
1153:             Ok(tydecode::parse_type_param_def_data(
1154:                 doc.data,


librustc/metadata/tydecode.rs:426:1-426:1 -fn- definition:
fn parse_hex(st: &mut PState) -> uint {
    let mut n = 0u;
    loop {
references:- 2
362:       '#' => {
363:         let pos = parse_hex(st);
364:         assert_eq!(next(st), ':');
365:         let len = parse_hex(st);
366:         assert_eq!(next(st), '#');


librustc/metadata/tydecode.rs:478:1-478:1 -fn- definition:
fn parse_bare_fn_ty(st: &mut PState, conv: conv_did) -> ty::BareFnTy {
    let fn_style = parse_fn_style(next(st));
    let abi = parse_abi_set(st);
references:- 2
125:     let mut st = parse_state_from_data(data, crate_num, pos, tcx);
126:     parse_bare_fn_ty(&mut st, conv)
127: }
--
359:       'F' => {
360:         return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, |x,y| conv(x,y)));
361:       }


librustc/metadata/tydecode.rs:398:1-398:1 -fn- definition:
fn parse_mutability(st: &mut PState) -> ast::Mutability {
    match peek(st) {
      'm' => { next(st); ast::MutMutable }
references:- 2
156:         '~' => ty::UniqTraitStore,
157:         '&' => ty::RegionTraitStore(parse_region(st, conv), parse_mutability(st)),
158:         c => st.tcx.sess.bug(format!("parse_trait_store(): bad input '{}'", c))
--
406: fn parse_mt(st: &mut PState, conv: conv_did) -> ty::mt {
407:     let m = parse_mutability(st);
408:     ty::mt { ty: parse_ty(st, |x,y| conv(x,y)), mutbl: m }


librustc/metadata/tydecode.rs:283:1-283:1 -fn- definition:
fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
    match next(st) {
      'n' => return ty::mk_nil(),
references:- 12
495:     while peek(st) != ']' {
496:         inputs.push(parse_ty(st, |x,y| conv(x,y)));
497:     }
--
549:         bounds: Rc::new(parse_bounds(st, |x,y| conv(x,y))),
550:         default: parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)))
551:     }


librustc/metadata/tydecode.rs:153:1-153:1 -fn- definition:
fn parse_trait_store(st: &mut PState, conv: conv_did) -> ty::TraitStore {
    match next(st) {
        '~' => ty::UniqTraitStore,
references:- 2
318:         let substs = parse_substs(st, |x,y| conv(x,y));
319:         let store = parse_trait_store(st, |x,y| conv(x,y));
320:         let bounds = parse_bounds(st, |x,y| conv(x,y));
--
466:     let onceness = parse_onceness(next(st));
467:     let store = parse_trait_store(st, |x,y| conv(x,y));
468:     let bounds = parse_bounds(st, |x,y| conv(x,y));


librustc/metadata/tydecode.rs:116:1-116:1 -fn- definition:
pub fn parse_ty_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt,
                     conv: conv_did) -> ty::t {
    let mut st = parse_state_from_data(data, crate_num, pos, tcx);
references:- 3
librustc/middle/astencode.rs:
1127:             let ty = tydecode::parse_ty_data(
1128:                 doc.data,
librustc/metadata/decoder.rs:
228:     let tp = reader::get_doc(doc, tag_items_data_item_type);
229:     parse_ty_data(tp.data, cdata.cnum, tp.start, tcx,
230:                   |_, did| translate_def_id(cdata, did))


librustc/metadata/tydecode.rs:83:1-83:1 -fn- definition:
fn scan<R>(st: &mut PState, is_last: |char| -> bool, op: |&[u8]| -> R) -> R {
    let start_pos = st.pos;
    debug!("scan: '{}' (start)", st.data[st.pos] as char);
references:- 3
412:              conv: conv_did) -> ast::DefId {
413:     return conv(source, scan(st, |c| { c == '|' }, parse_def_id));
414: }
--
449:     assert_eq!(next(st), '[');
450:     scan(st, |c| c == ']', |bytes| {
451:         let abi_str = str::from_utf8(bytes).unwrap().to_owned();


librustc/metadata/tydecode.rs:439:1-439:1 -fn- definition:
fn parse_fn_style(c: char) -> FnStyle {
    match c {
        'u' => UnsafeFn,
references:- 2
464: fn parse_closure_ty(st: &mut PState, conv: conv_did) -> ty::ClosureTy {
465:     let fn_style = parse_fn_style(next(st));
466:     let onceness = parse_onceness(next(st));
--
479: fn parse_bare_fn_ty(st: &mut PState, conv: conv_did) -> ty::BareFnTy {
480:     let fn_style = parse_fn_style(next(st));
481:     let abi = parse_abi_set(st);


librustc/metadata/tydecode.rs:67:1-67:1 -fn- definition:
fn peek(st: &PState) -> char {
    st.data[st.pos] as char
}
references:- 9
351:         let mut params = Vec::new();
352:         while peek(st) != ']' { params.push(parse_ty(st, |x,y| conv(x,y))); }
353:         st.pos = st.pos + 1u;
--
399: fn parse_mutability(st: &mut PState) -> ast::Mutability {
400:     match peek(st) {
401:       'm' => { next(st); ast::MutMutable }
--
418:     loop {
419:         let cur = peek(st);
420:         if cur < '0' || cur > '9' { return n; }
--
494:     let mut inputs = Vec::new();
495:     while peek(st) != ']' {
496:         inputs.push(parse_ty(st, |x,y| conv(x,y)));


librustc/metadata/tydecode.rs:106:1-106:1 -fn- definition:
pub fn parse_state_from_data<'a>(data: &'a [u8], crate_num: ast::CrateNum,
                             pos: uint, tcx: &'a ty::ctxt) -> PState<'a> {
    PState {
references:- 5
130:                             conv: conv_did) -> ty::TraitRef {
131:     let mut st = parse_state_from_data(data, crate_num, pos, tcx);
132:     parse_trait_ref(&mut st, conv)
--
540: {
541:     let mut st = parse_state_from_data(data, crate_num, start, tcx);
542:     parse_type_param_def(&mut st, conv)


librustc/metadata/tydecode.rs:60:1-60:1 -struct- definition:
pub struct PState<'a> {
    data: &'a [u8],
    krate: ast::CrateNum,
references:- 31


librustc/metadata/tydecode.rs:57:2-57:2 -NK_AS_STR_TODO- definition:
}
pub type conv_did<'a> =
    |source: DefIdSource, ast::DefId|: 'a -> ast::DefId;
references:- 19
490: fn parse_sig(st: &mut PState, conv: conv_did) -> ty::FnSig {
491:     assert_eq!(next(st), '[');
--
538:                                  crate_num: ast::CrateNum, tcx: &ty::ctxt,
539:                                  conv: conv_did) -> ty::TypeParameterDef
540: {
--
554: fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds {
555:     let mut param_bounds = ty::ParamBounds {


librustc/metadata/tydecode.rs:277:1-277:1 -fn- definition:
fn parse_trait_ref(st: &mut PState, conv: conv_did) -> ty::TraitRef {
    let def = parse_def(st, NominalType, |x,y| conv(x,y));
    let substs = parse_substs(st, |x,y| conv(x,y));
references:- 2
131:     let mut st = parse_state_from_data(data, crate_num, pos, tcx);
132:     parse_trait_ref(&mut st, conv)
133: }
--
576:             'I' => {
577:                 param_bounds.trait_bounds.push(Rc::new(parse_trait_ref(st, |x,y| conv(x,y))));
578:             }


librustc/metadata/tydecode.rs:44:38-44:38 -enum- definition:
// astencode.rs for more information.
pub enum DefIdSource {
    // Identifies a struct, trait, enum, etc.
references:- 4
411: fn parse_def(st: &mut PState, source: DefIdSource,
412:              conv: conv_did) -> ast::DefId {
librustc/middle/astencode.rs:
1082:                       xcx: &ExtendedDecodeContext,
1083:                       source: DefIdSource,
1084:                       did: ast::DefId)
--
1241:                       xcx: &ExtendedDecodeContext,
1242:                       source: tydecode::DefIdSource,
1243:                       did: ast::DefId)
librustc/metadata/tydecode.rs:
58: pub type conv_did<'a> =
59:     |source: DefIdSource, ast::DefId|: 'a -> ast::DefId;


librustc/metadata/tydecode.rs:215:1-215:1 -fn- definition:
fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region {
    match next(st) {
      'b' => {
references:- 3
336:       '&' => {
337:         let r = parse_region(st, |x,y| conv(x,y));
338:         let mt = parse_mt(st, |x,y| conv(x,y));


librustc/metadata/tydecode.rs:415:1-415:1 -fn- definition:
fn parse_uint(st: &mut PState) -> uint {
    let mut n = 0;
    loop {
references:- 10
147:     } else {
148:         let n = parse_uint(st);
149:         assert_eq!(next(st), '|');
--
219:         assert_eq!(next(st), '[');
220:         let id = parse_uint(st) as ast::NodeId;
221:         assert_eq!(next(st), '|');
--
229:         assert_eq!(next(st), '|');
230:         let index = parse_uint(st);
231:         assert_eq!(next(st), '|');
--
244:       's' => {
245:         let id = parse_uint(st) as ast::NodeId;
246:         assert_eq!(next(st), '|');
--
326:         debug!("parsed ty_param: did={:?}", did);
327:         return ty::mk_param(st.tcx, parse_uint(st), did);
328:       }
--
491:     assert_eq!(next(st), '[');
492:     let id = parse_uint(st) as ast::NodeId;
493:     assert_eq!(next(st), '|');


librustc/metadata/tydecode.rs:511:25-511:25 -fn- definition:
// Rust metadata parsing
pub fn parse_def_id(buf: &[u8]) -> ast::DefId {
    let mut colon_idx = 0u;
references:- 13
librustc/metadata/decoder.rs:
492:         let child_def_id = reader::with_doc_data(child_info_doc,
493:                                                  parse_def_id);
494:         let child_def_id = translate_def_id(cdata, child_def_id);
--
990:             let tagdoc = reader::get_doc(an_item, tag_item_field_origin);
991:             let origin_id =  translate_def_id(cdata, reader::with_doc_data(tagdoc, parse_def_id));
992:             result.push(ty::field_ty {
--
1004:         let f = item_family(an_item);
1005:         let origin_id =  translate_def_id(cdata, reader::with_doc_data(tagdoc, parse_def_id));
1006:         result.push(ty::field_ty {
librustc/metadata/tydecode.rs:
412:              conv: conv_did) -> ast::DefId {
413:     return conv(source, scan(st, |c| { c == '|' }, parse_def_id));
414: }


librustc/metadata/tydecode.rs:258:1-258:1 -fn- definition:
fn parse_opt<T>(st: &mut PState, f: |&mut PState| -> T) -> Option<T> {
    match next(st) {
      'n' => None,
references:- 2
165:     let self_ty = parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)) );
--
549:         bounds: Rc::new(parse_bounds(st, |x,y| conv(x,y))),
550:         default: parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)))
551:     }


librustc/metadata/tydecode.rs:266:1-266:1 -fn- definition:
fn parse_str(st: &mut PState, term: char) -> ~str {
    let mut result = StrBuf::new();
    while peek(st) != term {
references:- 2
231:         assert_eq!(next(st), '|');
232:         let nm = token::str_to_ident(parse_str(st, ']'));
233:         ty::ReEarlyBound(node_id, index, nm.name)


librustc/metadata/tydecode.rs:553:1-553:1 -fn- definition:
fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds {
    let mut param_bounds = ty::ParamBounds {
        builtin_bounds: ty::EmptyBuiltinBounds(),
references:- 3
548:         def_id: parse_def(st, NominalType, |x,y| conv(x,y)),
549:         bounds: Rc::new(parse_bounds(st, |x,y| conv(x,y))),
550:         default: parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)))


librustc/metadata/tydecode.rs:194:1-194:1 -fn- definition:
fn parse_bound_region(st: &mut PState, conv: conv_did) -> ty::BoundRegion {
    match next(st) {
        'a' => {
references:- 2
221:         assert_eq!(next(st), '|');
222:         let br = parse_bound_region(st, |x,y| conv(x,y));
223:         assert_eq!(next(st), ']');
--
238:         assert_eq!(next(st), '|');
239:         let br = parse_bound_region(st, |x,y| conv(x,y));
240:         assert_eq!(next(st), ']');


librustc/metadata/tydecode.rs:410:1-410:1 -fn- definition:
fn parse_def(st: &mut PState, source: DefIdSource,
             conv: conv_did) -> ast::DefId {
    return conv(source, scan(st, |c| { c == '|' }, parse_def_id));
references:- 9
324:       'p' => {
325:         let did = parse_def(st, TypeParameter, |x,y| conv(x,y));
326:         debug!("parsed ty_param: did={:?}", did);
--
329:       's' => {
330:         let did = parse_def(st, TypeParameter, |x,y| conv(x,y));
331:         return ty::mk_self(st.tcx, did);
--
389:           assert_eq!(next(st), '[');
390:           let did = parse_def(st, NominalType, |x,y| conv(x,y));
391:           let substs = parse_substs(st, |x,y| conv(x,y));
--
547:         ident: parse_ident(st, ':'),
548:         def_id: parse_def(st, NominalType, |x,y| conv(x,y)),
549:         bounds: Rc::new(parse_bounds(st, |x,y| conv(x,y))),


librustc/metadata/tydecode.rs:161:1-161:1 -fn- definition:
fn parse_substs(st: &mut PState, conv: conv_did) -> ty::substs {
    let regions = parse_region_substs(st, |x,y| conv(x,y));
    let self_ty = parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)) );
references:- 5
137:     let mut st = parse_state_from_data(data, crate_num, pos, tcx);
138:     parse_substs(&mut st, conv)
139: }
--
317:         let def = parse_def(st, NominalType, |x,y| conv(x,y));
318:         let substs = parse_substs(st, |x,y| conv(x,y));
319:         let store = parse_trait_store(st, |x,y| conv(x,y));
--
390:           let did = parse_def(st, NominalType, |x,y| conv(x,y));
391:           let substs = parse_substs(st, |x,y| conv(x,y));
392:           assert_eq!(next(st), ']');