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 // Decoding metadata from a single crate's metadata
12
13 #![allow(non_camel_case_types)]
14
15 use back::svh::Svh;
16 use metadata::cstore::crate_metadata;
17 use metadata::common::*;
18 use metadata::csearch::StaticMethodInfo;
19 use metadata::csearch;
20 use metadata::cstore;
21 use metadata::tydecode::{parse_ty_data, parse_def_id,
22 parse_type_param_def_data,
23 parse_bare_fn_ty_data, parse_trait_ref_data};
24 use middle::ty::{ImplContainer, TraitContainer};
25 use middle::ty;
26 use middle::typeck;
27 use middle::astencode::vtable_decoder_helpers;
28
29 use std::u64;
30 use std::hash;
31 use std::hash::Hash;
32 use std::io;
33 use std::io::extensions::u64_from_be_bytes;
34 use std::option;
35 use std::rc::Rc;
36 use serialize::ebml::reader;
37 use serialize::ebml;
38 use serialize::Decodable;
39 use syntax::ast_map;
40 use syntax::attr;
41 use syntax::parse::token::{IdentInterner, special_idents};
42 use syntax::parse::token;
43 use syntax::print::pprust;
44 use syntax::ast;
45 use syntax::codemap;
46 use syntax::crateid::CrateId;
47
48 pub type Cmd<'a> = &'a crate_metadata;
49
50 // A function that takes a def_id relative to the crate being searched and
51 // returns a def_id relative to the compilation environment, i.e. if we hit a
52 // def_id for an item defined in another crate, somebody needs to figure out
53 // what crate that's in and give us a def_id that makes sense for the current
54 // build.
55
56 fn lookup_hash<'a>(d: ebml::Doc<'a>, eq_fn: |&[u8]| -> bool,
57 hash: u64) -> Option<ebml::Doc<'a>> {
58 let index = reader::get_doc(d, tag_index);
59 let table = reader::get_doc(index, tag_index_table);
60 let hash_pos = table.start + (hash % 256 * 4) as uint;
61 let pos = u64_from_be_bytes(d.data, hash_pos, 4) as uint;
62 let tagged_doc = reader::doc_at(d.data, pos).unwrap();
63
64 let belt = tag_index_buckets_bucket_elt;
65
66 let mut ret = None;
67 reader::tagged_docs(tagged_doc.doc, belt, |elt| {
68 let pos = u64_from_be_bytes(elt.data, elt.start, 4) as uint;
69 if eq_fn(elt.data.slice(elt.start + 4, elt.end)) {
70 ret = Some(reader::doc_at(d.data, pos).unwrap().doc);
71 false
72 } else {
73 true
74 }
75 });
76 ret
77 }
78
79 pub fn maybe_find_item<'a>(item_id: ast::NodeId,
80 items: ebml::Doc<'a>) -> Option<ebml::Doc<'a>> {
81 fn eq_item(bytes: &[u8], item_id: ast::NodeId) -> bool {
82 return u64_from_be_bytes(
83 bytes.slice(0u, 4u), 0u, 4u) as ast::NodeId
84 == item_id;
85 }
86 lookup_hash(items,
87 |a| eq_item(a, item_id),
88 hash::hash(&(item_id as i64)))
89 }
90
91 fn find_item<'a>(item_id: ast::NodeId, items: ebml::Doc<'a>) -> ebml::Doc<'a> {
92 match maybe_find_item(item_id, items) {
93 None => fail!("lookup_item: id not found: {}", item_id),
94 Some(d) => d
95 }
96 }
97
98 // Looks up an item in the given metadata and returns an ebml doc pointing
99 // to the item data.
100 fn lookup_item<'a>(item_id: ast::NodeId, data: &'a [u8]) -> ebml::Doc<'a> {
101 let items = reader::get_doc(reader::Doc(data), tag_items);
102 find_item(item_id, items)
103 }
104
105 #[deriving(Eq)]
106 enum Family {
107 ImmStatic, // c
108 MutStatic, // b
109 Fn, // f
110 UnsafeFn, // u
111 StaticMethod, // F
112 UnsafeStaticMethod, // U
113 Type, // y
114 ForeignType, // T
115 Mod, // m
116 ForeignMod, // n
117 Enum, // t
118 TupleVariant, // v
119 StructVariant, // V
120 Impl, // i
121 Trait, // I
122 Struct, // S
123 PublicField, // g
124 InheritedField // N
125 }
126
127 fn item_family(item: ebml::Doc) -> Family {
128 let fam = reader::get_doc(item, tag_items_data_item_family);
129 match reader::doc_as_u8(fam) as char {
130 'c' => ImmStatic,
131 'b' => MutStatic,
132 'f' => Fn,
133 'u' => UnsafeFn,
134 'F' => StaticMethod,
135 'U' => UnsafeStaticMethod,
136 'y' => Type,
137 'T' => ForeignType,
138 'm' => Mod,
139 'n' => ForeignMod,
140 't' => Enum,
141 'v' => TupleVariant,
142 'V' => StructVariant,
143 'i' => Impl,
144 'I' => Trait,
145 'S' => Struct,
146 'g' => PublicField,
147 'N' => InheritedField,
148 c => fail!("unexpected family char: {}", c)
149 }
150 }
151
152 fn item_visibility(item: ebml::Doc) -> ast::Visibility {
153 match reader::maybe_get_doc(item, tag_items_data_item_visibility) {
154 None => ast::Public,
155 Some(visibility_doc) => {
156 match reader::doc_as_u8(visibility_doc) as char {
157 'y' => ast::Public,
158 'i' => ast::Inherited,
159 _ => fail!("unknown visibility character")
160 }
161 }
162 }
163 }
164
165 fn item_sized(item: ebml::Doc) -> ast::Sized {
166 match reader::maybe_get_doc(item, tag_items_data_item_sized) {
167 None => ast::StaticSize,
168 Some(sized_doc) => {
169 match reader::doc_as_u8(sized_doc) as char {
170 'd' => ast::DynSize,
171 's' => ast::StaticSize,
172 _ => fail!("unknown sized-ness character")
173 }
174 }
175 }
176 }
177
178 fn item_method_sort(item: ebml::Doc) -> char {
179 let mut ret = 'r';
180 reader::tagged_docs(item, tag_item_trait_method_sort, |doc| {
181 ret = doc.as_str_slice()[0] as char;
182 false
183 });
184 ret
185 }
186
187 fn item_symbol(item: ebml::Doc) -> ~str {
188 reader::get_doc(item, tag_items_data_item_symbol).as_str()
189 }
190
191 fn item_parent_item(d: ebml::Doc) -> Option<ast::DefId> {
192 let mut ret = None;
193 reader::tagged_docs(d, tag_items_data_parent_item, |did| {
194 ret = Some(reader::with_doc_data(did, parse_def_id));
195 false
196 });
197 ret
198 }
199
200 fn item_reqd_and_translated_parent_item(cnum: ast::CrateNum,
201 d: ebml::Doc) -> ast::DefId {
202 let trait_did = item_parent_item(d).expect("item without parent");
203 ast::DefId { krate: cnum, node: trait_did.node }
204 }
205
206 fn item_def_id(d: ebml::Doc, cdata: Cmd) -> ast::DefId {
207 let tagdoc = reader::get_doc(d, tag_def_id);
208 return translate_def_id(cdata, reader::with_doc_data(tagdoc, parse_def_id));
209 }
210
211 fn get_provided_source(d: ebml::Doc, cdata: Cmd) -> Option<ast::DefId> {
212 reader::maybe_get_doc(d, tag_item_method_provided_source).map(|doc| {
213 translate_def_id(cdata, reader::with_doc_data(doc, parse_def_id))
214 })
215 }
216
217 fn each_reexport(d: ebml::Doc, f: |ebml::Doc| -> bool) -> bool {
218 reader::tagged_docs(d, tag_items_data_item_reexport, f)
219 }
220
221 fn variant_disr_val(d: ebml::Doc) -> Option<ty::Disr> {
222 reader::maybe_get_doc(d, tag_disr_val).and_then(|val_doc| {
223 reader::with_doc_data(val_doc, |data| u64::parse_bytes(data, 10u))
224 })
225 }
226
227 fn doc_type(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::t {
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))
231 }
232
233 fn doc_method_fty(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::BareFnTy {
234 let tp = reader::get_doc(doc, tag_item_method_fty);
235 parse_bare_fn_ty_data(tp.data, cdata.cnum, tp.start, tcx,
236 |_, did| translate_def_id(cdata, did))
237 }
238
239 pub fn item_type(_item_id: ast::DefId, item: ebml::Doc,
240 tcx: &ty::ctxt, cdata: Cmd) -> ty::t {
241 doc_type(item, tcx, cdata)
242 }
243
244 fn doc_trait_ref(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef {
245 parse_trait_ref_data(doc.data, cdata.cnum, doc.start, tcx,
246 |_, did| translate_def_id(cdata, did))
247 }
248
249 fn item_trait_ref(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef {
250 let tp = reader::get_doc(doc, tag_item_trait_ref);
251 doc_trait_ref(tp, tcx, cdata)
252 }
253
254 fn item_ty_param_defs(item: ebml::Doc,
255 tcx: &ty::ctxt,
256 cdata: Cmd,
257 tag: uint)
258 -> Rc<Vec<ty::TypeParameterDef> > {
259 let mut bounds = Vec::new();
260 reader::tagged_docs(item, tag, |p| {
261 let bd = parse_type_param_def_data(
262 p.data, p.start, cdata.cnum, tcx,
263 |_, did| translate_def_id(cdata, did));
264 bounds.push(bd);
265 true
266 });
267 Rc::new(bounds)
268 }
269
270 fn item_region_param_defs(item_doc: ebml::Doc, cdata: Cmd)
271 -> Rc<Vec<ty::RegionParameterDef> > {
272 let mut v = Vec::new();
273 reader::tagged_docs(item_doc, tag_region_param_def, |rp_doc| {
274 let ident_str_doc = reader::get_doc(rp_doc,
275 tag_region_param_def_ident);
276 let ident = item_name(&*token::get_ident_interner(), ident_str_doc);
277 let def_id_doc = reader::get_doc(rp_doc,
278 tag_region_param_def_def_id);
279 let def_id = reader::with_doc_data(def_id_doc, parse_def_id);
280 let def_id = translate_def_id(cdata, def_id);
281 v.push(ty::RegionParameterDef { name: ident.name,
282 def_id: def_id });
283 true
284 });
285 Rc::new(v)
286 }
287
288 fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> Vec<ast::DefId> {
289 let mut ids: Vec<ast::DefId> = Vec::new();
290 let v = tag_items_data_item_variant;
291 reader::tagged_docs(item, v, |p| {
292 let ext = reader::with_doc_data(p, parse_def_id);
293 ids.push(ast::DefId { krate: cdata.cnum, node: ext.node });
294 true
295 });
296 return ids;
297 }
298
299 fn item_path(item_doc: ebml::Doc) -> Vec<ast_map::PathElem> {
300 let path_doc = reader::get_doc(item_doc, tag_path);
301
302 let len_doc = reader::get_doc(path_doc, tag_path_len);
303 let len = reader::doc_as_u32(len_doc) as uint;
304
305 let mut result = Vec::with_capacity(len);
306 reader::docs(path_doc, |tag, elt_doc| {
307 if tag == tag_path_elem_mod {
308 let s = elt_doc.as_str_slice();
309 result.push(ast_map::PathMod(token::intern(s)));
310 } else if tag == tag_path_elem_name {
311 let s = elt_doc.as_str_slice();
312 result.push(ast_map::PathName(token::intern(s)));
313 } else {
314 // ignore tag_path_len element
315 }
316 true
317 });
318
319 result
320 }
321
322 fn item_name(intr: &IdentInterner, item: ebml::Doc) -> ast::Ident {
323 let name = reader::get_doc(item, tag_paths_data_name);
324 let string = name.as_str_slice();
325 match intr.find_equiv(&string) {
326 None => token::str_to_ident(string),
327 Some(val) => ast::Ident::new(val as ast::Name),
328 }
329 }
330
331 fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
332 -> DefLike {
333 let fam = item_family(item);
334 match fam {
335 ImmStatic => DlDef(ast::DefStatic(did, false)),
336 MutStatic => DlDef(ast::DefStatic(did, true)),
337 Struct => DlDef(ast::DefStruct(did)),
338 UnsafeFn => DlDef(ast::DefFn(did, ast::UnsafeFn)),
339 Fn => DlDef(ast::DefFn(did, ast::NormalFn)),
340 StaticMethod | UnsafeStaticMethod => {
341 let fn_style = if fam == UnsafeStaticMethod { ast::UnsafeFn } else
342 { ast::NormalFn };
343 // def_static_method carries an optional field of its enclosing
344 // trait or enclosing impl (if this is an inherent static method).
345 // So we need to detect whether this is in a trait or not, which
346 // we do through the mildly hacky way of checking whether there is
347 // a trait_method_sort.
348 let provenance = if reader::maybe_get_doc(
349 item, tag_item_trait_method_sort).is_some() {
350 ast::FromTrait(item_reqd_and_translated_parent_item(cnum,
351 item))
352 } else {
353 ast::FromImpl(item_reqd_and_translated_parent_item(cnum,
354 item))
355 };
356 DlDef(ast::DefStaticMethod(did, provenance, fn_style))
357 }
358 Type | ForeignType => DlDef(ast::DefTy(did)),
359 Mod => DlDef(ast::DefMod(did)),
360 ForeignMod => DlDef(ast::DefForeignMod(did)),
361 StructVariant => {
362 let enum_did = item_reqd_and_translated_parent_item(cnum, item);
363 DlDef(ast::DefVariant(enum_did, did, true))
364 }
365 TupleVariant => {
366 let enum_did = item_reqd_and_translated_parent_item(cnum, item);
367 DlDef(ast::DefVariant(enum_did, did, false))
368 }
369 Trait => DlDef(ast::DefTrait(did)),
370 Enum => DlDef(ast::DefTy(did)),
371 Impl => DlImpl(did),
372 PublicField | InheritedField => DlField,
373 }
374 }
375
376 pub fn get_trait_def(cdata: Cmd,
377 item_id: ast::NodeId,
378 tcx: &ty::ctxt) -> ty::TraitDef
379 {
380 let item_doc = lookup_item(item_id, cdata.data());
381 let tp_defs = item_ty_param_defs(item_doc, tcx, cdata,
382 tag_items_data_item_ty_param_bounds);
383 let rp_defs = item_region_param_defs(item_doc, cdata);
384 let sized = item_sized(item_doc);
385 let mut bounds = ty::EmptyBuiltinBounds();
386 // Collect the builtin bounds from the encoded supertraits.
387 // FIXME(#8559): They should be encoded directly.
388 reader::tagged_docs(item_doc, tag_item_super_trait_ref, |trait_doc| {
389 // NB. Bypasses real supertraits. See get_supertraits() if you wanted them.
390 let trait_ref = doc_trait_ref(trait_doc, tcx, cdata);
391 tcx.lang_items.to_builtin_kind(trait_ref.def_id).map(|bound| {
392 bounds.add(bound);
393 });
394 true
395 });
396 // Turn sized into a bound, FIXME(#8559).
397 if sized == ast::StaticSize {
398 tcx.lang_items.to_builtin_kind(tcx.lang_items.sized_trait().unwrap()).map(|bound| {
399 bounds.add(bound);
400 });
401 }
402
403 ty::TraitDef {
404 generics: ty::Generics {type_param_defs: tp_defs,
405 region_param_defs: rp_defs},
406 bounds: bounds,
407 trait_ref: Rc::new(item_trait_ref(item_doc, tcx, cdata))
408 }
409 }
410
411 pub fn get_type(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt)
412 -> ty::ty_param_bounds_and_ty {
413
414 let item = lookup_item(id, cdata.data());
415
416 let t = item_type(ast::DefId { krate: cdata.cnum, node: id }, item, tcx,
417 cdata);
418
419 let tp_defs = item_ty_param_defs(item, tcx, cdata, tag_items_data_item_ty_param_bounds);
420 let rp_defs = item_region_param_defs(item, cdata);
421
422 ty::ty_param_bounds_and_ty {
423 generics: ty::Generics {type_param_defs: tp_defs,
424 region_param_defs: rp_defs},
425 ty: t
426 }
427 }
428
429 pub fn get_impl_trait(cdata: Cmd,
430 id: ast::NodeId,
431 tcx: &ty::ctxt) -> Option<Rc<ty::TraitRef>>
432 {
433 let item_doc = lookup_item(id, cdata.data());
434 reader::maybe_get_doc(item_doc, tag_item_trait_ref).map(|tp| {
435 Rc::new(doc_trait_ref(tp, tcx, cdata))
436 })
437 }
438
439 pub fn get_impl_vtables(cdata: Cmd,
440 id: ast::NodeId,
441 tcx: &ty::ctxt) -> typeck::impl_res
442 {
443 let item_doc = lookup_item(id, cdata.data());
444 let vtables_doc = reader::get_doc(item_doc, tag_item_impl_vtables);
445 let mut decoder = reader::Decoder(vtables_doc);
446
447 typeck::impl_res {
448 trait_vtables: decoder.read_vtable_res(tcx, cdata),
449 self_vtables: decoder.read_vtable_param_res(tcx, cdata)
450 }
451 }
452
453
454 pub fn get_symbol(data: &[u8], id: ast::NodeId) -> ~str {
455 return item_symbol(lookup_item(id, data));
456 }
457
458 // Something that a name can resolve to.
459 #[deriving(Clone)]
460 pub enum DefLike {
461 DlDef(ast::Def),
462 DlImpl(ast::DefId),
463 DlField
464 }
465
466 /// Iterates over the language items in the given crate.
467 pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool {
468 let root = reader::Doc(cdata.data());
469 let lang_items = reader::get_doc(root, tag_lang_items);
470 reader::tagged_docs(lang_items, tag_lang_items_item, |item_doc| {
471 let id_doc = reader::get_doc(item_doc, tag_lang_items_item_id);
472 let id = reader::doc_as_u32(id_doc) as uint;
473 let node_id_doc = reader::get_doc(item_doc,
474 tag_lang_items_item_node_id);
475 let node_id = reader::doc_as_u32(node_id_doc) as ast::NodeId;
476
477 f(node_id, id)
478 })
479 }
480
481 pub type GetCrateDataCb<'a> = |ast::CrateNum|: 'a -> Rc<crate_metadata>;
482
483 fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
484 cdata: Cmd,
485 item_doc: ebml::Doc,
486 get_crate_data: GetCrateDataCb,
487 callback: |DefLike,
488 ast::Ident,
489 ast::Visibility|) {
490 // Iterate over all children.
491 let _ = reader::tagged_docs(item_doc, tag_mod_child, |child_info_doc| {
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);
495
496 // This item may be in yet another crate if it was the child of a
497 // reexport.
498 let crate_data = if child_def_id.krate == cdata.cnum {
499 None
500 } else {
501 Some(get_crate_data(child_def_id.krate))
502 };
503 let crate_data = match crate_data {
504 Some(ref cdata) => &**cdata,
505 None => cdata
506 };
507
508 let other_crates_items = reader::get_doc(reader::Doc(crate_data.data()), tag_items);
509
510 // Get the item.
511 match maybe_find_item(child_def_id.node, other_crates_items) {
512 None => {}
513 Some(child_item_doc) => {
514 // Hand off the item to the callback.
515 let child_name = item_name(&*intr, child_item_doc);
516 let def_like = item_to_def_like(child_item_doc,
517 child_def_id,
518 cdata.cnum);
519 let visibility = item_visibility(child_item_doc);
520 callback(def_like, child_name, visibility);
521
522 }
523 }
524
525 true
526 });
527
528 // As a special case, iterate over all static methods of
529 // associated implementations too. This is a bit of a botch.
530 // --pcwalton
531 let _ = reader::tagged_docs(item_doc,
532 tag_items_data_item_inherent_impl,
533 |inherent_impl_def_id_doc| {
534 let inherent_impl_def_id = item_def_id(inherent_impl_def_id_doc,
535 cdata);
536 let items = reader::get_doc(reader::Doc(cdata.data()), tag_items);
537 match maybe_find_item(inherent_impl_def_id.node, items) {
538 None => {}
539 Some(inherent_impl_doc) => {
540 let _ = reader::tagged_docs(inherent_impl_doc,
541 tag_item_impl_method,
542 |impl_method_def_id_doc| {
543 let impl_method_def_id =
544 reader::with_doc_data(impl_method_def_id_doc,
545 parse_def_id);
546 let impl_method_def_id =
547 translate_def_id(cdata, impl_method_def_id);
548 match maybe_find_item(impl_method_def_id.node, items) {
549 None => {}
550 Some(impl_method_doc) => {
551 match item_family(impl_method_doc) {
552 StaticMethod | UnsafeStaticMethod => {
553 // Hand off the static method
554 // to the callback.
555 let static_method_name =
556 item_name(&*intr, impl_method_doc);
557 let static_method_def_like =
558 item_to_def_like(impl_method_doc,
559 impl_method_def_id,
560 cdata.cnum);
561 callback(static_method_def_like,
562 static_method_name,
563 item_visibility(impl_method_doc));
564 }
565 _ => {}
566 }
567 }
568 }
569
570 true
571 });
572 }
573 }
574
575 true
576 });
577
578 // Iterate over all reexports.
579 let _ = each_reexport(item_doc, |reexport_doc| {
580 let def_id_doc = reader::get_doc(reexport_doc,
581 tag_items_data_item_reexport_def_id);
582 let child_def_id = reader::with_doc_data(def_id_doc,
583 parse_def_id);
584 let child_def_id = translate_def_id(cdata, child_def_id);
585
586 let name_doc = reader::get_doc(reexport_doc,
587 tag_items_data_item_reexport_name);
588 let name = name_doc.as_str_slice();
589
590 // This reexport may be in yet another crate.
591 let crate_data = if child_def_id.krate == cdata.cnum {
592 None
593 } else {
594 Some(get_crate_data(child_def_id.krate))
595 };
596 let crate_data = match crate_data {
597 Some(ref cdata) => &**cdata,
598 None => cdata
599 };
600
601 let other_crates_items = reader::get_doc(reader::Doc(crate_data.data()), tag_items);
602
603 // Get the item.
604 match maybe_find_item(child_def_id.node, other_crates_items) {
605 None => {}
606 Some(child_item_doc) => {
607 // Hand off the item to the callback.
608 let def_like = item_to_def_like(child_item_doc,
609 child_def_id,
610 child_def_id.krate);
611 // These items have a public visibility because they're part of
612 // a public re-export.
613 callback(def_like, token::str_to_ident(name), ast::Public);
614 }
615 }
616
617 true
618 });
619 }
620
621 /// Iterates over each child of the given item.
622 pub fn each_child_of_item(intr: Rc<IdentInterner>,
623 cdata: Cmd,
624 id: ast::NodeId,
625 get_crate_data: GetCrateDataCb,
626 callback: |DefLike, ast::Ident, ast::Visibility|) {
627 // Find the item.
628 let root_doc = reader::Doc(cdata.data());
629 let items = reader::get_doc(root_doc, tag_items);
630 let item_doc = match maybe_find_item(id, items) {
631 None => return,
632 Some(item_doc) => item_doc,
633 };
634
635 each_child_of_item_or_crate(intr,
636 cdata,
637 item_doc,
638 get_crate_data,
639 callback)
640 }
641
642 /// Iterates over all the top-level crate items.
643 pub fn each_top_level_item_of_crate(intr: Rc<IdentInterner>,
644 cdata: Cmd,
645 get_crate_data: GetCrateDataCb,
646 callback: |DefLike,
647 ast::Ident,
648 ast::Visibility|) {
649 let root_doc = reader::Doc(cdata.data());
650 let misc_info_doc = reader::get_doc(root_doc, tag_misc_info);
651 let crate_items_doc = reader::get_doc(misc_info_doc,
652 tag_misc_info_crate_items);
653
654 each_child_of_item_or_crate(intr,
655 cdata,
656 crate_items_doc,
657 get_crate_data,
658 callback)
659 }
660
661 pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> Vec<ast_map::PathElem> {
662 item_path(lookup_item(id, cdata.data()))
663 }
664
665 pub type DecodeInlinedItem<'a> = |cdata: Cmd,
666 tcx: &ty::ctxt,
667 path: Vec<ast_map::PathElem>,
668 par_doc: ebml::Doc|: 'a
669 -> Result<ast::InlinedItem, Vec<ast_map::PathElem> >;
670
671 pub fn maybe_get_item_ast(cdata: Cmd, tcx: &ty::ctxt, id: ast::NodeId,
672 decode_inlined_item: DecodeInlinedItem)
673 -> csearch::found_ast {
674 debug!("Looking up item: {}", id);
675 let item_doc = lookup_item(id, cdata.data());
676 let path = Vec::from_slice(item_path(item_doc).init());
677 match decode_inlined_item(cdata, tcx, path, item_doc) {
678 Ok(ref ii) => csearch::found(*ii),
679 Err(path) => {
680 match item_parent_item(item_doc) {
681 Some(did) => {
682 let did = translate_def_id(cdata, did);
683 let parent_item = lookup_item(did.node, cdata.data());
684 match decode_inlined_item(cdata, tcx, path, parent_item) {
685 Ok(ref ii) => csearch::found_parent(did, *ii),
686 Err(_) => csearch::not_found
687 }
688 }
689 None => csearch::not_found
690 }
691 }
692 }
693 }
694
695 pub fn get_enum_variants(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
696 tcx: &ty::ctxt) -> Vec<Rc<ty::VariantInfo>> {
697 let data = cdata.data();
698 let items = reader::get_doc(reader::Doc(data), tag_items);
699 let item = find_item(id, items);
700 let mut disr_val = 0;
701 enum_variant_ids(item, cdata).iter().map(|did| {
702 let item = find_item(did.node, items);
703 let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
704 item, tcx, cdata);
705 let name = item_name(&*intr, item);
706 let arg_tys = match ty::get(ctor_ty).sty {
707 ty::ty_bare_fn(ref f) => f.sig.inputs.clone(),
708 _ => Vec::new(), // Nullary enum variant.
709 };
710 match variant_disr_val(item) {
711 Some(val) => { disr_val = val; }
712 _ => { /* empty */ }
713 }
714 let old_disr_val = disr_val;
715 disr_val += 1;
716 Rc::new(ty::VariantInfo {
717 args: arg_tys,
718 arg_names: None,
719 ctor_ty: ctor_ty,
720 name: name,
721 // I'm not even sure if we encode visibility
722 // for variants -- TEST -- tjc
723 id: *did,
724 disr_val: old_disr_val,
725 vis: ast::Inherited
726 })
727 }).collect()
728 }
729
730 fn get_explicit_self(item: ebml::Doc) -> ast::ExplicitSelf_ {
731 fn get_mutability(ch: u8) -> ast::Mutability {
732 match ch as char {
733 'i' => ast::MutImmutable,
734 'm' => ast::MutMutable,
735 _ => fail!("unknown mutability character: `{}`", ch as char),
736 }
737 }
738
739 let explicit_self_doc = reader::get_doc(item, tag_item_trait_method_explicit_self);
740 let string = explicit_self_doc.as_str_slice();
741
742 let explicit_self_kind = string[0];
743 match explicit_self_kind as char {
744 's' => ast::SelfStatic,
745 'v' => ast::SelfValue,
746 '~' => ast::SelfUniq,
747 // FIXME(#4846) expl. region
748 '&' => ast::SelfRegion(None, get_mutability(string[1])),
749 _ => fail!("unknown self type code: `{}`", explicit_self_kind as char)
750 }
751 }
752
753 /// Returns information about the given implementation.
754 pub fn get_impl_methods(cdata: Cmd, impl_id: ast::NodeId) -> Vec<ast::DefId> {
755 let mut methods = Vec::new();
756 reader::tagged_docs(lookup_item(impl_id, cdata.data()),
757 tag_item_impl_method, |doc| {
758 let m_did = reader::with_doc_data(doc, parse_def_id);
759 methods.push(translate_def_id(cdata, m_did));
760 true
761 });
762
763 methods
764 }
765
766 pub fn get_method_name_and_explicit_self(
767 intr: Rc<IdentInterner>,
768 cdata: Cmd,
769 id: ast::NodeId) -> (ast::Ident, ast::ExplicitSelf_)
770 {
771 let method_doc = lookup_item(id, cdata.data());
772 let name = item_name(&*intr, method_doc);
773 let explicit_self = get_explicit_self(method_doc);
774 (name, explicit_self)
775 }
776
777 pub fn get_method(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
778 tcx: &ty::ctxt) -> ty::Method
779 {
780 let method_doc = lookup_item(id, cdata.data());
781 let def_id = item_def_id(method_doc, cdata);
782
783 let container_id = item_reqd_and_translated_parent_item(cdata.cnum,
784 method_doc);
785 let container_doc = lookup_item(container_id.node, cdata.data());
786 let container = match item_family(container_doc) {
787 Trait => TraitContainer(container_id),
788 _ => ImplContainer(container_id),
789 };
790
791 let name = item_name(&*intr, method_doc);
792 let type_param_defs = item_ty_param_defs(method_doc, tcx, cdata,
793 tag_item_method_tps);
794 let rp_defs = item_region_param_defs(method_doc, cdata);
795 let fty = doc_method_fty(method_doc, tcx, cdata);
796 let vis = item_visibility(method_doc);
797 let explicit_self = get_explicit_self(method_doc);
798 let provided_source = get_provided_source(method_doc, cdata);
799
800 ty::Method::new(
801 name,
802 ty::Generics {
803 type_param_defs: type_param_defs,
804 region_param_defs: rp_defs,
805 },
806 fty,
807 explicit_self,
808 vis,
809 def_id,
810 container,
811 provided_source
812 )
813 }
814
815 pub fn get_trait_method_def_ids(cdata: Cmd,
816 id: ast::NodeId) -> Vec<ast::DefId> {
817 let data = cdata.data();
818 let item = lookup_item(id, data);
819 let mut result = Vec::new();
820 reader::tagged_docs(item, tag_item_trait_method, |mth| {
821 result.push(item_def_id(mth, cdata));
822 true
823 });
824 result
825 }
826
827 pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances {
828 let data = cdata.data();
829 let item_doc = lookup_item(id, data);
830 let variance_doc = reader::get_doc(item_doc, tag_item_variances);
831 let mut decoder = reader::Decoder(variance_doc);
832 Decodable::decode(&mut decoder).unwrap()
833 }
834
835 pub fn get_provided_trait_methods(intr: Rc<IdentInterner>, cdata: Cmd,
836 id: ast::NodeId, tcx: &ty::ctxt)
837 -> Vec<Rc<ty::Method>> {
838 let data = cdata.data();
839 let item = lookup_item(id, data);
840 let mut result = Vec::new();
841
842 reader::tagged_docs(item, tag_item_trait_method, |mth_id| {
843 let did = item_def_id(mth_id, cdata);
844 let mth = lookup_item(did.node, data);
845
846 if item_method_sort(mth) == 'p' {
847 result.push(Rc::new(get_method(intr.clone(), cdata, did.node, tcx)));
848 }
849 true
850 });
851
852 return result;
853 }
854
855 /// Returns the supertraits of the given trait.
856 pub fn get_supertraits(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt)
857 -> Vec<Rc<ty::TraitRef>> {
858 let mut results = Vec::new();
859 let item_doc = lookup_item(id, cdata.data());
860 reader::tagged_docs(item_doc, tag_item_super_trait_ref, |trait_doc| {
861 // NB. Only reads the ones that *aren't* builtin-bounds. See also
862 // get_trait_def() for collecting the builtin bounds.
863 // FIXME(#8559): The builtin bounds shouldn't be encoded in the first place.
864 let trait_ref = doc_trait_ref(trait_doc, tcx, cdata);
865 if tcx.lang_items.to_builtin_kind(trait_ref.def_id).is_none() {
866 results.push(Rc::new(trait_ref));
867 }
868 true
869 });
870 return results;
871 }
872
873 pub fn get_type_name_if_impl(cdata: Cmd,
874 node_id: ast::NodeId) -> Option<ast::Ident> {
875 let item = lookup_item(node_id, cdata.data());
876 if item_family(item) != Impl {
877 return None;
878 }
879
880 let mut ret = None;
881 reader::tagged_docs(item, tag_item_impl_type_basename, |doc| {
882 ret = Some(token::str_to_ident(doc.as_str_slice()));
883 false
884 });
885
886 ret
887 }
888
889 pub fn get_static_methods_if_impl(intr: Rc<IdentInterner>,
890 cdata: Cmd,
891 node_id: ast::NodeId)
892 -> Option<Vec<StaticMethodInfo> > {
893 let item = lookup_item(node_id, cdata.data());
894 if item_family(item) != Impl {
895 return None;
896 }
897
898 // If this impl implements a trait, don't consider it.
899 let ret = reader::tagged_docs(item, tag_item_trait_ref, |_doc| {
900 false
901 });
902
903 if !ret { return None }
904
905 let mut impl_method_ids = Vec::new();
906 reader::tagged_docs(item, tag_item_impl_method, |impl_method_doc| {
907 impl_method_ids.push(reader::with_doc_data(impl_method_doc, parse_def_id));
908 true
909 });
910
911 let mut static_impl_methods = Vec::new();
912 for impl_method_id in impl_method_ids.iter() {
913 let impl_method_doc = lookup_item(impl_method_id.node, cdata.data());
914 let family = item_family(impl_method_doc);
915 match family {
916 StaticMethod | UnsafeStaticMethod => {
917 let fn_style;
918 match item_family(impl_method_doc) {
919 StaticMethod => fn_style = ast::NormalFn,
920 UnsafeStaticMethod => fn_style = ast::UnsafeFn,
921 _ => fail!()
922 }
923
924 static_impl_methods.push(StaticMethodInfo {
925 ident: item_name(&*intr, impl_method_doc),
926 def_id: item_def_id(impl_method_doc, cdata),
927 fn_style: fn_style,
928 vis: item_visibility(impl_method_doc),
929 });
930 }
931 _ => {}
932 }
933 }
934
935 return Some(static_impl_methods);
936 }
937
938 /// If node_id is the constructor of a tuple struct, retrieve the NodeId of
939 /// the actual type definition, otherwise, return None
940 pub fn get_tuple_struct_definition_if_ctor(cdata: Cmd,
941 node_id: ast::NodeId)
942 -> Option<ast::DefId>
943 {
944 let item = lookup_item(node_id, cdata.data());
945 let mut ret = None;
946 reader::tagged_docs(item, tag_items_data_item_is_tuple_struct_ctor, |_| {
947 ret = Some(item_reqd_and_translated_parent_item(cdata.cnum, item));
948 false
949 });
950 ret
951 }
952
953 pub fn get_item_attrs(cdata: Cmd,
954 orig_node_id: ast::NodeId,
955 f: |Vec<@ast::MetaItem> |) {
956 // The attributes for a tuple struct are attached to the definition, not the ctor;
957 // we assume that someone passing in a tuple struct ctor is actually wanting to
958 // look at the definition
959 let node_id = get_tuple_struct_definition_if_ctor(cdata, orig_node_id);
960 let node_id = node_id.map(|x| x.node).unwrap_or(orig_node_id);
961 let item = lookup_item(node_id, cdata.data());
962 reader::tagged_docs(item, tag_attributes, |attributes| {
963 reader::tagged_docs(attributes, tag_attribute, |attribute| {
964 f(get_meta_items(attribute));
965 true
966 });
967 true
968 });
969 }
970
971 fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
972 match family {
973 PublicField => ast::Public,
974 InheritedField => ast::Inherited,
975 _ => fail!()
976 }
977 }
978
979 pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
980 -> Vec<ty::field_ty> {
981 let data = cdata.data();
982 let item = lookup_item(id, data);
983 let mut result = Vec::new();
984 reader::tagged_docs(item, tag_item_field, |an_item| {
985 let f = item_family(an_item);
986 if f == PublicField || f == InheritedField {
987 // FIXME #6993: name should be of type Name, not Ident
988 let name = item_name(&*intr, an_item);
989 let did = item_def_id(an_item, cdata);
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 {
993 name: name.name,
994 id: did,
995 vis: struct_field_family_to_visibility(f),
996 origin: origin_id,
997 });
998 }
999 true
1000 });
1001 reader::tagged_docs(item, tag_item_unnamed_field, |an_item| {
1002 let did = item_def_id(an_item, cdata);
1003 let tagdoc = reader::get_doc(an_item, tag_item_field_origin);
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 {
1007 name: special_idents::unnamed_field.name,
1008 id: did,
1009 vis: struct_field_family_to_visibility(f),
1010 origin: origin_id,
1011 });
1012 true
1013 });
1014 result
1015 }
1016
1017 fn get_meta_items(md: ebml::Doc) -> Vec<@ast::MetaItem> {
1018 let mut items: Vec<@ast::MetaItem> = Vec::new();
1019 reader::tagged_docs(md, tag_meta_item_word, |meta_item_doc| {
1020 let nd = reader::get_doc(meta_item_doc, tag_meta_item_name);
1021 let n = token::intern_and_get_ident(nd.as_str_slice());
1022 items.push(attr::mk_word_item(n));
1023 true
1024 });
1025 reader::tagged_docs(md, tag_meta_item_name_value, |meta_item_doc| {
1026 let nd = reader::get_doc(meta_item_doc, tag_meta_item_name);
1027 let vd = reader::get_doc(meta_item_doc, tag_meta_item_value);
1028 let n = token::intern_and_get_ident(nd.as_str_slice());
1029 let v = token::intern_and_get_ident(vd.as_str_slice());
1030 // FIXME (#623): Should be able to decode MetaNameValue variants,
1031 // but currently the encoder just drops them
1032 items.push(attr::mk_name_value_item_str(n, v));
1033 true
1034 });
1035 reader::tagged_docs(md, tag_meta_item_list, |meta_item_doc| {
1036 let nd = reader::get_doc(meta_item_doc, tag_meta_item_name);
1037 let n = token::intern_and_get_ident(nd.as_str_slice());
1038 let subitems = get_meta_items(meta_item_doc);
1039 items.push(attr::mk_list_item(n, subitems.move_iter().collect()));
1040 true
1041 });
1042 return items;
1043 }
1044
1045 fn get_attributes(md: ebml::Doc) -> Vec<ast::Attribute> {
1046 let mut attrs: Vec<ast::Attribute> = Vec::new();
1047 match reader::maybe_get_doc(md, tag_attributes) {
1048 option::Some(attrs_d) => {
1049 reader::tagged_docs(attrs_d, tag_attribute, |attr_doc| {
1050 let meta_items = get_meta_items(attr_doc);
1051 // Currently it's only possible to have a single meta item on
1052 // an attribute
1053 assert_eq!(meta_items.len(), 1u);
1054 let meta_item = *meta_items.get(0);
1055 attrs.push(
1056 codemap::Spanned {
1057 node: ast::Attribute_ {
1058 style: ast::AttrOuter,
1059 value: meta_item,
1060 is_sugared_doc: false,
1061 },
1062 span: codemap::DUMMY_SP
1063 });
1064 true
1065 });
1066 }
1067 option::None => ()
1068 }
1069 return attrs;
1070 }
1071
1072 fn list_crate_attributes(md: ebml::Doc, hash: &Svh,
1073 out: &mut io::Writer) -> io::IoResult<()> {
1074 try!(write!(out, "=Crate Attributes ({})=\n", *hash));
1075
1076 let r = get_attributes(md);
1077 for attr in r.iter() {
1078 try!(write!(out, "{}\n", pprust::attribute_to_str(attr)));
1079 }
1080
1081 write!(out, "\n\n")
1082 }
1083
1084 pub fn get_crate_attributes(data: &[u8]) -> Vec<ast::Attribute> {
1085 get_attributes(reader::Doc(data))
1086 }
1087
1088 #[deriving(Clone)]
1089 pub struct CrateDep {
1090 pub cnum: ast::CrateNum,
1091 pub crate_id: CrateId,
1092 pub hash: Svh,
1093 }
1094
1095 pub fn get_crate_deps(data: &[u8]) -> Vec<CrateDep> {
1096 let mut deps: Vec<CrateDep> = Vec::new();
1097 let cratedoc = reader::Doc(data);
1098 let depsdoc = reader::get_doc(cratedoc, tag_crate_deps);
1099 let mut crate_num = 1;
1100 fn docstr(doc: ebml::Doc, tag_: uint) -> ~str {
1101 let d = reader::get_doc(doc, tag_);
1102 d.as_str_slice().to_str()
1103 }
1104 reader::tagged_docs(depsdoc, tag_crate_dep, |depdoc| {
1105 let crate_id = from_str(docstr(depdoc, tag_crate_dep_crateid)).unwrap();
1106 let hash = Svh::new(docstr(depdoc, tag_crate_dep_hash));
1107 deps.push(CrateDep {
1108 cnum: crate_num,
1109 crate_id: crate_id,
1110 hash: hash,
1111 });
1112 crate_num += 1;
1113 true
1114 });
1115 return deps;
1116 }
1117
1118 fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
1119 try!(write!(out, "=External Dependencies=\n"));
1120 for dep in get_crate_deps(data).iter() {
1121 try!(write!(out, "{} {}-{}\n", dep.cnum, dep.crate_id, dep.hash));
1122 }
1123 try!(write!(out, "\n"));
1124 Ok(())
1125 }
1126
1127 pub fn maybe_get_crate_hash(data: &[u8]) -> Option<Svh> {
1128 let cratedoc = reader::Doc(data);
1129 reader::maybe_get_doc(cratedoc, tag_crate_hash).map(|doc| {
1130 Svh::new(doc.as_str_slice())
1131 })
1132 }
1133
1134 pub fn get_crate_hash(data: &[u8]) -> Svh {
1135 let cratedoc = reader::Doc(data);
1136 let hashdoc = reader::get_doc(cratedoc, tag_crate_hash);
1137 Svh::new(hashdoc.as_str_slice())
1138 }
1139
1140 pub fn maybe_get_crate_id(data: &[u8]) -> Option<CrateId> {
1141 let cratedoc = reader::Doc(data);
1142 reader::maybe_get_doc(cratedoc, tag_crate_crateid).map(|doc| {
1143 from_str(doc.as_str_slice()).unwrap()
1144 })
1145 }
1146
1147 pub fn get_crate_triple(data: &[u8]) -> ~str {
1148 let cratedoc = reader::Doc(data);
1149 let triple_doc = reader::maybe_get_doc(cratedoc, tag_crate_triple);
1150 triple_doc.expect("No triple in crate").as_str()
1151 }
1152
1153 pub fn get_crate_id(data: &[u8]) -> CrateId {
1154 let cratedoc = reader::Doc(data);
1155 let hashdoc = reader::get_doc(cratedoc, tag_crate_crateid);
1156 from_str(hashdoc.as_str_slice()).unwrap()
1157 }
1158
1159 pub fn list_crate_metadata(bytes: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
1160 let hash = get_crate_hash(bytes);
1161 let md = reader::Doc(bytes);
1162 try!(list_crate_attributes(md, &hash, out));
1163 list_crate_deps(bytes, out)
1164 }
1165
1166 // Translates a def_id from an external crate to a def_id for the current
1167 // compilation environment. We use this when trying to load types from
1168 // external crates - if those types further refer to types in other crates
1169 // then we must translate the crate number from that encoded in the external
1170 // crate to the correct local crate number.
1171 pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId {
1172 if did.krate == ast::LOCAL_CRATE {
1173 return ast::DefId { krate: cdata.cnum, node: did.node };
1174 }
1175
1176 match cdata.cnum_map.find(&did.krate) {
1177 Some(&n) => {
1178 ast::DefId {
1179 krate: n,
1180 node: did.node,
1181 }
1182 }
1183 None => fail!("didn't find a crate in the cnum_map")
1184 }
1185 }
1186
1187 pub fn each_impl(cdata: Cmd, callback: |ast::DefId|) {
1188 let impls_doc = reader::get_doc(reader::Doc(cdata.data()), tag_impls);
1189 let _ = reader::tagged_docs(impls_doc, tag_impls_impl, |impl_doc| {
1190 callback(item_def_id(impl_doc, cdata));
1191 true
1192 });
1193 }
1194
1195 pub fn each_implementation_for_type(cdata: Cmd,
1196 id: ast::NodeId,
1197 callback: |ast::DefId|) {
1198 let item_doc = lookup_item(id, cdata.data());
1199 reader::tagged_docs(item_doc,
1200 tag_items_data_item_inherent_impl,
1201 |impl_doc| {
1202 let implementation_def_id = item_def_id(impl_doc, cdata);
1203 callback(implementation_def_id);
1204 true
1205 });
1206 }
1207
1208 pub fn each_implementation_for_trait(cdata: Cmd,
1209 id: ast::NodeId,
1210 callback: |ast::DefId|) {
1211 let item_doc = lookup_item(id, cdata.data());
1212
1213 let _ = reader::tagged_docs(item_doc,
1214 tag_items_data_item_extension_impl,
1215 |impl_doc| {
1216 let implementation_def_id = item_def_id(impl_doc, cdata);
1217 callback(implementation_def_id);
1218 true
1219 });
1220 }
1221
1222 pub fn get_trait_of_method(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt)
1223 -> Option<ast::DefId> {
1224 let item_doc = lookup_item(id, cdata.data());
1225 let parent_item_id = match item_parent_item(item_doc) {
1226 None => return None,
1227 Some(item_id) => item_id,
1228 };
1229 let parent_item_id = translate_def_id(cdata, parent_item_id);
1230 let parent_item_doc = lookup_item(parent_item_id.node, cdata.data());
1231 match item_family(parent_item_doc) {
1232 Trait => Some(item_def_id(parent_item_doc, cdata)),
1233 Impl => {
1234 reader::maybe_get_doc(parent_item_doc, tag_item_trait_ref)
1235 .map(|_| item_trait_ref(parent_item_doc, tcx, cdata).def_id)
1236 }
1237 _ => None
1238 }
1239 }
1240
1241
1242 pub fn get_native_libraries(cdata: Cmd) -> Vec<(cstore::NativeLibaryKind, ~str)> {
1243 let libraries = reader::get_doc(reader::Doc(cdata.data()),
1244 tag_native_libraries);
1245 let mut result = Vec::new();
1246 reader::tagged_docs(libraries, tag_native_libraries_lib, |lib_doc| {
1247 let kind_doc = reader::get_doc(lib_doc, tag_native_libraries_kind);
1248 let name_doc = reader::get_doc(lib_doc, tag_native_libraries_name);
1249 let kind: cstore::NativeLibaryKind =
1250 FromPrimitive::from_u32(reader::doc_as_u32(kind_doc)).unwrap();
1251 let name = name_doc.as_str();
1252 result.push((kind, name));
1253 true
1254 });
1255 return result;
1256 }
1257
1258 pub fn get_macro_registrar_fn(data: &[u8]) -> Option<ast::NodeId> {
1259 reader::maybe_get_doc(reader::Doc(data), tag_macro_registrar_fn)
1260 .map(|doc| FromPrimitive::from_u32(reader::doc_as_u32(doc)).unwrap())
1261 }
1262
1263 pub fn get_exported_macros(data: &[u8]) -> Vec<~str> {
1264 let macros = reader::get_doc(reader::Doc(data),
1265 tag_exported_macros);
1266 let mut result = Vec::new();
1267 reader::tagged_docs(macros, tag_macro_def, |macro_doc| {
1268 result.push(macro_doc.as_str());
1269 true
1270 });
1271 result
1272 }
1273
1274 pub fn get_dylib_dependency_formats(cdata: Cmd)
1275 -> Vec<(ast::CrateNum, cstore::LinkagePreference)>
1276 {
1277 let formats = reader::get_doc(reader::Doc(cdata.data()),
1278 tag_dylib_dependency_formats);
1279 let mut result = Vec::new();
1280
1281 debug!("found dylib deps: {}", formats.as_str_slice());
1282 for spec in formats.as_str_slice().split(',') {
1283 if spec.len() == 0 { continue }
1284 let cnum = spec.split(':').nth(0).unwrap();
1285 let link = spec.split(':').nth(1).unwrap();
1286 let cnum = from_str(cnum).unwrap();
1287 let cnum = match cdata.cnum_map.find(&cnum) {
1288 Some(&n) => n,
1289 None => fail!("didn't find a crate in the cnum_map")
1290 };
1291 result.push((cnum, if link == "d" {
1292 cstore::RequireDynamic
1293 } else {
1294 cstore::RequireStatic
1295 }));
1296 }
1297 return result;
1298 }
librustc/metadata/decoder.rs:970:1-970:1 -fn- definition:
fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
match family {
PublicField => ast::Public,
references:- 2994: id: did,
995: vis: struct_field_family_to_visibility(f),
996: origin: origin_id,
--
1008: id: did,
1009: vis: struct_field_family_to_visibility(f),
1010: origin: origin_id,
librustc/metadata/decoder.rs:298:1-298:1 -fn- definition:
fn item_path(item_doc: ebml::Doc) -> Vec<ast_map::PathElem> {
let path_doc = reader::get_doc(item_doc, tag_path);
let len_doc = reader::get_doc(path_doc, tag_path_len);
references:- 2661: pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> Vec<ast_map::PathElem> {
662: item_path(lookup_item(id, cdata.data()))
663: }
--
675: let item_doc = lookup_item(id, cdata.data());
676: let path = Vec::from_slice(item_path(item_doc).init());
677: match decode_inlined_item(cdata, tcx, path, item_doc) {
librustc/metadata/decoder.rs:1257:1-1257:1 -fn- definition:
pub fn get_macro_registrar_fn(data: &[u8]) -> Option<ast::NodeId> {
reader::maybe_get_doc(reader::Doc(data), tag_macro_registrar_fn)
.map(|doc| FromPrimitive::from_u32(reader::doc_as_u32(doc)).unwrap())
references:- 2librustc/metadata/creader.rs:
413: let lib = load_ctxt.load_library_crate();
414: if decoder::get_macro_registrar_fn(lib.metadata.as_slice()).is_some() {
415: let message = format!("crate `{}` contains a macro_registrar fn but \
--
429: let macros = decoder::get_exported_macros(library.metadata.as_slice());
430: let registrar = decoder::get_macro_registrar_fn(library.metadata.as_slice()).map(|id| {
431: decoder::get_symbol(library.metadata.as_slice(), id).to_strbuf()
librustc/metadata/decoder.rs:253:1-253:1 -fn- definition:
fn item_ty_param_defs(item: ebml::Doc,
tcx: &ty::ctxt,
cdata: Cmd,
references:- 3419: let tp_defs = item_ty_param_defs(item, tcx, cdata, tag_items_data_item_ty_param_bounds);
420: let rp_defs = item_region_param_defs(item, cdata);
--
791: let name = item_name(&*intr, method_doc);
792: let type_param_defs = item_ty_param_defs(method_doc, tcx, cdata,
793: tag_item_method_tps);
librustc/metadata/decoder.rs:459:19-459:19 -enum- definition:
pub enum DefLike {
DlDef(ast::Def),
DlImpl(ast::DefId),
references:- 13486: get_crate_data: GetCrateDataCb,
487: callback: |DefLike,
488: ast::Ident,
--
625: get_crate_data: GetCrateDataCb,
626: callback: |DefLike, ast::Ident, ast::Visibility|) {
627: // Find the item.
--
645: get_crate_data: GetCrateDataCb,
646: callback: |DefLike,
647: ast::Ident,
librustc/metadata/csearch.rs:
51: def_id: ast::DefId,
52: callback: |decoder::DefLike,
53: ast::Ident,
--
68: cnum: ast::CrateNum,
69: callback: |decoder::DefLike,
70: ast::Ident,
librustc/middle/resolve.rs:
3381: rib_index: uint,
3382: def_like: DefLike,
3383: span: Span)
--
3498: span: Span)
3499: -> Option<DefLike> {
3500: // FIXME #4950: This should not use a while loop.
librustc/metadata/decoder.rs:
458: // Something that a name can resolve to.
460: pub enum DefLike {
librustc/metadata/decoder.rs:1170:44-1170:44 -fn- definition:
// crate to the correct local crate number.
pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId {
if did.krate == ast::LOCAL_CRATE {
references:- 18235: parse_bare_fn_ty_data(tp.data, cdata.cnum, tp.start, tcx,
236: |_, did| translate_def_id(cdata, did))
237: }
--
546: let impl_method_def_id =
547: translate_def_id(cdata, impl_method_def_id);
548: match maybe_find_item(impl_method_def_id.node, items) {
--
583: parse_def_id);
584: let child_def_id = translate_def_id(cdata, child_def_id);
--
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/middle/astencode.rs:
207: decoder::translate_def_id(self.dcx.cdata, did)
208: }
--
273: let did: ast::DefId = Decodable::decode(self).ok().unwrap();
274: decoder::translate_def_id(cdata, did)
275: }
--
1104: tcx,
1105: |_, id| decoder::translate_def_id(cdata, id)))
1106: }).unwrap()
librustc/metadata/decoder.rs:
1228: };
1229: let parent_item_id = translate_def_id(cdata, parent_item_id);
1230: let parent_item_doc = lookup_item(parent_item_id.node, cdata.data());
librustc/metadata/decoder.rs:664:1-664:1 -NK_AS_STR_TODO- definition:
pub type DecodeInlinedItem<'a> = |cdata: Cmd,
tcx: &ty::ctxt,
path: Vec<ast_map::PathElem>,
references:- 2librustc/metadata/csearch.rs:
101: pub fn maybe_get_item_ast(tcx: &ty::ctxt, def: ast::DefId,
102: decode_inlined_item: decoder::DecodeInlinedItem)
103: -> found_ast {
librustc/metadata/decoder.rs:
671: pub fn maybe_get_item_ast(cdata: Cmd, tcx: &ty::ctxt, id: ast::NodeId,
672: decode_inlined_item: DecodeInlinedItem)
673: -> csearch::found_ast {
librustc/metadata/decoder.rs:1152:1-1152:1 -fn- definition:
pub fn get_crate_id(data: &[u8]) -> CrateId {
let cratedoc = reader::Doc(data);
let hashdoc = reader::get_doc(cratedoc, tag_crate_crateid);
references:- 3librustc/metadata/cstore.rs:
214: pub fn data<'a>(&'a self) -> &'a [u8] { self.data.as_slice() }
215: pub fn crate_id(&self) -> CrateId { decoder::get_crate_id(self.data()) }
216: pub fn hash(&self) -> Svh { decoder::get_crate_hash(self.data()) }
librustc/metadata/encoder.rs:
1459: cnum: key,
1460: crate_id: decoder::get_crate_id(val.data()),
1461: hash: decoder::get_crate_hash(val.data())
librustc/metadata/loader.rs:
289: let data = lib.metadata.as_slice();
290: let crate_id = decoder::get_crate_id(data);
291: note_crateid_attr(self.sess.diagnostic(), &crate_id);
librustc/metadata/decoder.rs:47:1-47:1 -NK_AS_STR_TODO- definition:
pub type Cmd<'a> = &'a crate_metadata;
// A function that takes a def_id relative to the crate being searched and
// returns a def_id relative to the compilation environment, i.e. if we hit a
references:- 41librustc/metadata/decoder.rs:238:1-238:1 -fn- definition:
pub fn item_type(_item_id: ast::DefId, item: ebml::Doc,
tcx: &ty::ctxt, cdata: Cmd) -> ty::t {
doc_type(item, tcx, cdata)
references:- 3702: let item = find_item(did.node, items);
703: let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
704: item, tcx, cdata);
librustc/metadata/csearch.rs:
220: });
221: let ty = decoder::item_type(def, the_field, tcx, &*cdata);
222: ty::ty_param_bounds_and_ty {
librustc/metadata/decoder.rs:
416: let t = item_type(ast::DefId { krate: cdata.cnum, node: id }, item, tcx,
417: cdata);
librustc/metadata/decoder.rs:729:1-729:1 -fn- definition:
fn get_explicit_self(item: ebml::Doc) -> ast::ExplicitSelf_ {
fn get_mutability(ch: u8) -> ast::Mutability {
match ch as char {
references:- 2796: let vis = item_visibility(method_doc);
797: let explicit_self = get_explicit_self(method_doc);
798: let provided_source = get_provided_source(method_doc, cdata);
librustc/metadata/decoder.rs:126:1-126:1 -fn- definition:
fn item_family(item: ebml::Doc) -> Family {
let fam = reader::get_doc(item, tag_items_data_item_family);
match reader::doc_as_u8(fam) as char {
references:- 10893: let item = lookup_item(node_id, cdata.data());
894: if item_family(item) != Impl {
895: return None;
--
984: reader::tagged_docs(item, tag_item_field, |an_item| {
985: let f = item_family(an_item);
986: if f == PublicField || f == InheritedField {
--
1230: let parent_item_doc = lookup_item(parent_item_id.node, cdata.data());
1231: match item_family(parent_item_doc) {
1232: Trait => Some(item_def_id(parent_item_doc, cdata)),
librustc/metadata/decoder.rs:1094:1-1094:1 -fn- definition:
pub fn get_crate_deps(data: &[u8]) -> Vec<CrateDep> {
let mut deps: Vec<CrateDep> = Vec::new();
let cratedoc = reader::Doc(data);
references:- 2librustc/metadata/creader.rs:
356: // numbers
357: decoder::get_crate_deps(cdata).iter().map(|dep| {
358: debug!("resolving dep crate {} hash: `{}`", dep.crate_id, dep.hash);
librustc/metadata/decoder.rs:
1119: try!(write!(out, "=External Dependencies=\n"));
1120: for dep in get_crate_deps(data).iter() {
1121: try!(write!(out, "{} {}-{}\n", dep.cnum, dep.crate_id, dep.hash));
librustc/metadata/decoder.rs:453:1-453:1 -fn- definition:
pub fn get_symbol(data: &[u8], id: ast::NodeId) -> ~str {
return item_symbol(lookup_item(id, data));
}
references:- 2librustc/metadata/csearch.rs:
36: let cdata = cstore.get_crate_data(def.krate);
37: decoder::get_symbol(cdata.data(), def.node)
38: }
librustc/metadata/creader.rs:
430: let registrar = decoder::get_macro_registrar_fn(library.metadata.as_slice()).map(|id| {
431: decoder::get_symbol(library.metadata.as_slice(), id).to_strbuf()
432: });
librustc/metadata/decoder.rs:330:1-330:1 -fn- definition:
fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
-> DefLike {
let fam = item_family(item);
references:- 3557: let static_method_def_like =
558: item_to_def_like(impl_method_doc,
559: impl_method_def_id,
--
607: // Hand off the item to the callback.
608: let def_like = item_to_def_like(child_item_doc,
609: child_def_id,
librustc/metadata/decoder.rs:939:55-939:55 -fn- definition:
/// the actual type definition, otherwise, return None
pub fn get_tuple_struct_definition_if_ctor(cdata: Cmd,
node_id: ast::NodeId)
references:- 2librustc/metadata/csearch.rs:
289: let cdata = cstore.get_crate_data(def_id.krate);
290: decoder::get_tuple_struct_definition_if_ctor(&*cdata, def_id.node)
291: }
librustc/metadata/decoder.rs:
958: // look at the definition
959: let node_id = get_tuple_struct_definition_if_ctor(cdata, orig_node_id);
960: let node_id = node_id.map(|x| x.node).unwrap_or(orig_node_id);
librustc/metadata/decoder.rs:776:1-776:1 -fn- definition:
pub fn get_method(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
tcx: &ty::ctxt) -> ty::Method
{
references:- 2846: if item_method_sort(mth) == 'p' {
847: result.push(Rc::new(get_method(intr.clone(), cdata, did.node, tcx)));
848: }
librustc/metadata/csearch.rs:
124: let cdata = tcx.sess.cstore.get_crate_data(def.krate);
125: decoder::get_method(tcx.sess.cstore.intr.clone(), &*cdata, def.node, tcx)
126: }
librustc/metadata/decoder.rs:105:16-105:16 -enum- definition:
enum Family {
ImmStatic, // c
MutStatic, // b
references:- 5106: enum Family {
--
971: fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
972: match family {
librustc/metadata/decoder.rs:321:1-321:1 -fn- definition:
fn item_name(intr: &IdentInterner, item: ebml::Doc) -> ast::Ident {
let name = reader::get_doc(item, tag_paths_data_name);
let string = name.as_str_slice();
references:- 8987: // FIXME #6993: name should be of type Name, not Ident
988: let name = item_name(&*intr, an_item);
989: let did = item_def_id(an_item, cdata);
librustc/metadata/decoder.rs:190:1-190:1 -fn- definition:
fn item_parent_item(d: ebml::Doc) -> Option<ast::DefId> {
let mut ret = None;
reader::tagged_docs(d, tag_items_data_parent_item, |did| {
references:- 3201: d: ebml::Doc) -> ast::DefId {
202: let trait_did = item_parent_item(d).expect("item without parent");
203: ast::DefId { krate: cnum, node: trait_did.node }
--
1224: let item_doc = lookup_item(id, cdata.data());
1225: let parent_item_id = match item_parent_item(item_doc) {
1226: None => return None,
librustc/metadata/decoder.rs:1133:1-1133:1 -fn- definition:
pub fn get_crate_hash(data: &[u8]) -> Svh {
let cratedoc = reader::Doc(data);
let hashdoc = reader::get_doc(cratedoc, tag_crate_hash);
references:- 4librustc/metadata/cstore.rs:
215: pub fn crate_id(&self) -> CrateId { decoder::get_crate_id(self.data()) }
216: pub fn hash(&self) -> Svh { decoder::get_crate_hash(self.data()) }
217: }
librustc/metadata/encoder.rs:
1460: crate_id: decoder::get_crate_id(val.data()),
1461: hash: decoder::get_crate_hash(val.data())
1462: };
librustc/metadata/decoder.rs:
1159: pub fn list_crate_metadata(bytes: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
1160: let hash = get_crate_hash(bytes);
1161: let md = reader::Doc(bytes);
librustc/metadata/decoder.rs:205:1-205:1 -fn- definition:
fn item_def_id(d: ebml::Doc, cdata: Cmd) -> ast::DefId {
let tagdoc = reader::get_doc(d, tag_def_id);
return translate_def_id(cdata, reader::with_doc_data(tagdoc, parse_def_id));
references:- 111189: let _ = reader::tagged_docs(impls_doc, tag_impls_impl, |impl_doc| {
1190: callback(item_def_id(impl_doc, cdata));
1191: true
--
1215: |impl_doc| {
1216: let implementation_def_id = item_def_id(impl_doc, cdata);
1217: callback(implementation_def_id);
--
1231: match item_family(parent_item_doc) {
1232: Trait => Some(item_def_id(parent_item_doc, cdata)),
1233: Impl => {
librustc/metadata/decoder.rs:151:1-151:1 -fn- definition:
fn item_visibility(item: ebml::Doc) -> ast::Visibility {
match reader::maybe_get_doc(item, tag_items_data_item_visibility) {
None => ast::Public,
references:- 4927: fn_style: fn_style,
928: vis: item_visibility(impl_method_doc),
929: });
librustc/metadata/decoder.rs:1088:19-1088:19 -struct- definition:
pub struct CrateDep {
pub cnum: ast::CrateNum,
pub crate_id: CrateId,
references:- 101089: pub struct CrateDep {
--
1106: let hash = Svh::new(docstr(depdoc, tag_crate_dep_hash));
1107: deps.push(CrateDep {
1108: cnum: crate_num,
librustc/metadata/encoder.rs:
1453: fn encode_crate_deps(ebml_w: &mut Encoder, cstore: &cstore::CStore) {
1454: fn get_ordered_deps(cstore: &cstore::CStore) -> Vec<decoder::CrateDep> {
1455: // Pull the cnums and name,vers,hash out of cstore
--
1668: fn encode_crate_dep(ebml_w: &mut Encoder,
1669: dep: decoder::CrateDep) {
1670: ebml_w.start_tag(tag_crate_dep);
librustc/metadata/decoder.rs:1016:1-1016:1 -fn- definition:
fn get_meta_items(md: ebml::Doc) -> Vec<@ast::MetaItem> {
let mut items: Vec<@ast::MetaItem> = Vec::new();
reader::tagged_docs(md, tag_meta_item_word, |meta_item_doc| {
references:- 31049: reader::tagged_docs(attrs_d, tag_attribute, |attr_doc| {
1050: let meta_items = get_meta_items(attr_doc);
1051: // Currently it's only possible to have a single meta item on
librustc/metadata/decoder.rs:482:1-482:1 -fn- definition:
fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
cdata: Cmd,
item_doc: ebml::Doc,
references:- 2635: each_child_of_item_or_crate(intr,
636: cdata,
--
654: each_child_of_item_or_crate(intr,
655: cdata,
librustc/metadata/decoder.rs:99:21-99:21 -fn- definition:
// to the item data.
fn lookup_item<'a>(item_id: ast::NodeId, data: &'a [u8]) -> ebml::Doc<'a> {
let items = reader::get_doc(reader::Doc(data), tag_items);
references:- 27892: -> Option<Vec<StaticMethodInfo> > {
893: let item = lookup_item(node_id, cdata.data());
894: if item_family(item) != Impl {
--
943: {
944: let item = lookup_item(node_id, cdata.data());
945: let mut ret = None;
--
1210: callback: |ast::DefId|) {
1211: let item_doc = lookup_item(id, cdata.data());
--
1223: -> Option<ast::DefId> {
1224: let item_doc = lookup_item(id, cdata.data());
1225: let parent_item_id = match item_parent_item(item_doc) {
--
1229: let parent_item_id = translate_def_id(cdata, parent_item_id);
1230: let parent_item_doc = lookup_item(parent_item_id.node, cdata.data());
1231: match item_family(parent_item_doc) {
librustc/metadata/decoder.rs:1044:1-1044:1 -fn- definition:
fn get_attributes(md: ebml::Doc) -> Vec<ast::Attribute> {
let mut attrs: Vec<ast::Attribute> = Vec::new();
match reader::maybe_get_doc(md, tag_attributes) {
references:- 21076: let r = get_attributes(md);
1077: for attr in r.iter() {
--
1084: pub fn get_crate_attributes(data: &[u8]) -> Vec<ast::Attribute> {
1085: get_attributes(reader::Doc(data))
1086: }
librustc/metadata/decoder.rs:1100:4-1100:4 -fn- definition:
fn docstr(doc: ebml::Doc, tag_: uint) -> ~str {
let d = reader::get_doc(doc, tag_);
d.as_str_slice().to_str()
references:- 21105: let crate_id = from_str(docstr(depdoc, tag_crate_dep_crateid)).unwrap();
1106: let hash = Svh::new(docstr(depdoc, tag_crate_dep_hash));
1107: deps.push(CrateDep {
librustc/metadata/decoder.rs:90:1-90:1 -fn- definition:
fn find_item<'a>(item_id: ast::NodeId, items: ebml::Doc<'a>) -> ebml::Doc<'a> {
match maybe_find_item(item_id, items) {
None => fail!("lookup_item: id not found: {}", item_id),
references:- 3701: enum_variant_ids(item, cdata).iter().map(|did| {
702: let item = find_item(did.node, items);
703: let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
librustc/metadata/decoder.rs:78:1-78:1 -fn- definition:
pub fn maybe_find_item<'a>(item_id: ast::NodeId,
items: ebml::Doc<'a>) -> Option<ebml::Doc<'a>> {
fn eq_item(bytes: &[u8], item_id: ast::NodeId) -> bool {
references:- 8629: let items = reader::get_doc(root_doc, tag_items);
630: let item_doc = match maybe_find_item(id, items) {
631: None => return,
librustc/metadata/csearch.rs:
214: let the_field = expect(tcx.sess.diagnostic(),
215: decoder::maybe_find_item(def.node, class_doc),
216: || {
librustc/metadata/decoder.rs:
91: fn find_item<'a>(item_id: ast::NodeId, items: ebml::Doc<'a>) -> ebml::Doc<'a> {
92: match maybe_find_item(item_id, items) {
93: None => fail!("lookup_item: id not found: {}", item_id),
librustc/metadata/decoder.rs:248:1-248:1 -fn- definition:
fn item_trait_ref(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef {
let tp = reader::get_doc(doc, tag_item_trait_ref);
doc_trait_ref(tp, tcx, cdata)
references:- 2406: bounds: bounds,
407: trait_ref: Rc::new(item_trait_ref(item_doc, tcx, cdata))
408: }
--
1234: reader::maybe_get_doc(parent_item_doc, tag_item_trait_ref)
1235: .map(|_| item_trait_ref(parent_item_doc, tcx, cdata).def_id)
1236: }
librustc/metadata/decoder.rs:199:1-199:1 -fn- definition:
fn item_reqd_and_translated_parent_item(cnum: ast::CrateNum,
d: ebml::Doc) -> ast::DefId {
let trait_did = item_parent_item(d).expect("item without parent");
references:- 6365: TupleVariant => {
366: let enum_did = item_reqd_and_translated_parent_item(cnum, item);
367: DlDef(ast::DefVariant(enum_did, did, false))
--
783: let container_id = item_reqd_and_translated_parent_item(cdata.cnum,
784: method_doc);
--
946: reader::tagged_docs(item, tag_items_data_item_is_tuple_struct_ctor, |_| {
947: ret = Some(item_reqd_and_translated_parent_item(cdata.cnum, item));
948: false
librustc/metadata/decoder.rs:243:1-243:1 -fn- definition:
fn doc_trait_ref(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef {
parse_trait_ref_data(doc.data, cdata.cnum, doc.start, tcx,
|_, did| translate_def_id(cdata, did))
references:- 4250: let tp = reader::get_doc(doc, tag_item_trait_ref);
251: doc_trait_ref(tp, tcx, cdata)
252: }
--
863: // FIXME(#8559): The builtin bounds shouldn't be encoded in the first place.
864: let trait_ref = doc_trait_ref(trait_doc, tcx, cdata);
865: if tcx.lang_items.to_builtin_kind(trait_ref.def_id).is_none() {
librustc/metadata/decoder.rs:480:1-480:1 -NK_AS_STR_TODO- definition:
pub type GetCrateDataCb<'a> = |ast::CrateNum|: 'a -> Rc<crate_metadata>;
fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
cdata: Cmd,
references:- 5624: id: ast::NodeId,
625: get_crate_data: GetCrateDataCb,
626: callback: |DefLike, ast::Ident, ast::Visibility|) {
--
644: cdata: Cmd,
645: get_crate_data: GetCrateDataCb,
646: callback: |DefLike,
librustc/metadata/csearch.rs:
55: let crate_data = cstore.get_crate_data(def_id.krate);
56: let get_crate_data: decoder::GetCrateDataCb = |cnum| {
57: cstore.get_crate_data(cnum)
--
72: let crate_data = cstore.get_crate_data(cnum);
73: let get_crate_data: decoder::GetCrateDataCb = |cnum| {
74: cstore.get_crate_data(cnum)
librustc/metadata/decoder.rs:269:1-269:1 -fn- definition:
fn item_region_param_defs(item_doc: ebml::Doc, cdata: Cmd)
-> Rc<Vec<ty::RegionParameterDef> > {
let mut v = Vec::new();
references:- 3793: tag_item_method_tps);
794: let rp_defs = item_region_param_defs(method_doc, cdata);
795: let fty = doc_method_fty(method_doc, tcx, cdata);