2016-05-03 12:54:29 +02:00
|
|
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2016-05-06 16:15:48 +12:00
|
|
|
use rustc::hir::def_id::{DefId, DefIndex};
|
2016-05-03 12:54:29 +02:00
|
|
|
use rustc::hir::map::Map;
|
|
|
|
use rustc::ty::TyCtxt;
|
|
|
|
use syntax::ast::{CrateNum, NodeId};
|
|
|
|
use syntax::codemap::{Span, CodeMap};
|
|
|
|
|
|
|
|
use super::data;
|
|
|
|
|
|
|
|
// FIXME: this should be pub(crate), but the current snapshot doesn't allow it yet
|
|
|
|
pub trait Lower {
|
|
|
|
type Target;
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> Self::Target;
|
|
|
|
}
|
|
|
|
|
2016-05-06 16:15:48 +12:00
|
|
|
fn make_def_id(id: NodeId, map: &Map) -> DefId {
|
|
|
|
map.opt_local_def_id(id).unwrap_or(null_def_id())
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
2016-05-06 16:15:48 +12:00
|
|
|
pub fn null_def_id() -> DefId {
|
|
|
|
DefId { krate: u32::max_value(), index: DefIndex::from_u32(u32::max_value()) }
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, RustcEncodable)]
|
|
|
|
pub struct SpanData {
|
|
|
|
pub file_name: String,
|
|
|
|
pub byte_start: u32,
|
|
|
|
pub byte_end: u32,
|
|
|
|
/// 1-based.
|
|
|
|
pub line_start: usize,
|
|
|
|
pub line_end: usize,
|
|
|
|
/// 1-based, character offset.
|
|
|
|
pub column_start: usize,
|
|
|
|
pub column_end: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SpanData {
|
|
|
|
pub fn from_span(span: Span, cm: &CodeMap) -> SpanData {
|
|
|
|
let start = cm.lookup_char_pos(span.lo);
|
|
|
|
let end = cm.lookup_char_pos(span.hi);
|
|
|
|
|
|
|
|
SpanData {
|
|
|
|
file_name: start.file.name.clone(),
|
|
|
|
byte_start: span.lo.0,
|
|
|
|
byte_end: span.hi.0,
|
|
|
|
line_start: start.line,
|
|
|
|
line_end: end.line,
|
|
|
|
column_start: start.col.0 + 1,
|
|
|
|
column_end: end.col.0 + 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct CratePreludeData {
|
|
|
|
pub crate_name: String,
|
|
|
|
pub crate_root: String,
|
|
|
|
pub external_crates: Vec<data::ExternalCrateData>,
|
|
|
|
pub span: SpanData,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::CratePreludeData {
|
|
|
|
type Target = CratePreludeData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> CratePreludeData {
|
|
|
|
CratePreludeData {
|
|
|
|
crate_name: self.crate_name,
|
|
|
|
crate_root: self.crate_root,
|
|
|
|
external_crates: self.external_crates,
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data for enum declarations.
|
|
|
|
#[derive(Clone, Debug, RustcEncodable)]
|
|
|
|
pub struct EnumData {
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub value: String,
|
|
|
|
pub qualname: String,
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::EnumData {
|
|
|
|
type Target = EnumData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> EnumData {
|
|
|
|
EnumData {
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
value: self.value,
|
|
|
|
qualname: self.qualname,
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data for extern crates.
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct ExternCrateData {
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub name: String,
|
|
|
|
pub crate_num: CrateNum,
|
|
|
|
pub location: String,
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::ExternCrateData {
|
|
|
|
type Target = ExternCrateData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> ExternCrateData {
|
|
|
|
ExternCrateData {
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
name: self.name,
|
|
|
|
crate_num: self.crate_num,
|
|
|
|
location: self.location,
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data about a function call.
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct FunctionCallData {
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
|
|
|
pub ref_id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::FunctionCallData {
|
|
|
|
type Target = FunctionCallData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> FunctionCallData {
|
|
|
|
FunctionCallData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
|
|
|
ref_id: self.ref_id,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data for all kinds of functions and methods.
|
|
|
|
#[derive(Clone, Debug, RustcEncodable)]
|
|
|
|
pub struct FunctionData {
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub name: String,
|
|
|
|
pub qualname: String,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub declaration: Option<DefId>,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::FunctionData {
|
|
|
|
type Target = FunctionData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> FunctionData {
|
|
|
|
FunctionData {
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
2016-05-06 16:15:48 +12:00
|
|
|
declaration: self.declaration,
|
2016-05-03 12:54:29 +02:00
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data about a function call.
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct FunctionRefData {
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
|
|
|
pub ref_id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::FunctionRefData {
|
|
|
|
type Target = FunctionRefData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> FunctionRefData {
|
|
|
|
FunctionRefData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
|
|
|
ref_id: self.ref_id,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct ImplData {
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
|
|
|
pub trait_ref: Option<DefId>,
|
|
|
|
pub self_ref: Option<DefId>,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::ImplData {
|
|
|
|
type Target = ImplData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> ImplData {
|
|
|
|
ImplData {
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
|
|
|
trait_ref: self.trait_ref,
|
|
|
|
self_ref: self.self_ref,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct InheritanceData {
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub base_id: DefId,
|
|
|
|
pub deriv_id: DefId
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::InheritanceData {
|
|
|
|
type Target = InheritanceData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> InheritanceData {
|
|
|
|
InheritanceData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
base_id: self.base_id,
|
|
|
|
deriv_id: make_def_id(self.deriv_id, &tcx.map)
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data about a macro declaration.
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct MacroData {
|
|
|
|
pub span: SpanData,
|
|
|
|
pub name: String,
|
|
|
|
pub qualname: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::MacroData {
|
|
|
|
type Target = MacroData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> MacroData {
|
|
|
|
MacroData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data about a macro use.
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct MacroUseData {
|
|
|
|
pub span: SpanData,
|
|
|
|
pub name: String,
|
|
|
|
pub qualname: String,
|
|
|
|
// Because macro expansion happens before ref-ids are determined,
|
|
|
|
// we use the callee span to reference the associated macro definition.
|
|
|
|
pub callee_span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub imported: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::MacroUseData {
|
|
|
|
type Target = MacroUseData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> MacroUseData {
|
|
|
|
MacroUseData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
callee_span: SpanData::from_span(self.callee_span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
imported: self.imported,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data about a method call.
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct MethodCallData {
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
|
|
|
pub ref_id: Option<DefId>,
|
|
|
|
pub decl_id: Option<DefId>,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::MethodCallData {
|
|
|
|
type Target = MethodCallData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> MethodCallData {
|
|
|
|
MethodCallData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
|
|
|
ref_id: self.ref_id,
|
|
|
|
decl_id: self.decl_id,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data for method declarations (methods with a body are treated as functions).
|
|
|
|
#[derive(Clone, Debug, RustcEncodable)]
|
|
|
|
pub struct MethodData {
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub qualname: String,
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::MethodData {
|
|
|
|
type Target = MethodData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> MethodData {
|
|
|
|
MethodData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
qualname: self.qualname,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data for modules.
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct ModData {
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub name: String,
|
|
|
|
pub qualname: String,
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub filename: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::ModData {
|
|
|
|
type Target = ModData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> ModData {
|
|
|
|
ModData {
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
filename: self.filename,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data for a reference to a module.
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct ModRefData {
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
|
|
|
pub ref_id: Option<DefId>,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub qualname: String
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::ModRefData {
|
|
|
|
type Target = ModRefData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> ModRefData {
|
|
|
|
ModRefData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
|
|
|
ref_id: self.ref_id,
|
2016-05-03 12:54:29 +02:00
|
|
|
qualname: self.qualname,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct StructData {
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
|
|
|
pub ctor_id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub qualname: String,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub value: String
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::StructData {
|
|
|
|
type Target = StructData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> StructData {
|
|
|
|
StructData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
|
|
|
ctor_id: make_def_id(self.ctor_id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
qualname: self.qualname,
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
value: self.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct StructVariantData {
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub qualname: String,
|
|
|
|
pub type_value: String,
|
|
|
|
pub value: String,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::StructVariantData {
|
|
|
|
type Target = StructVariantData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> StructVariantData {
|
|
|
|
StructVariantData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
qualname: self.qualname,
|
|
|
|
type_value: self.type_value,
|
|
|
|
value: self.value,
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct TraitData {
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub qualname: String,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub value: String
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::TraitData {
|
|
|
|
type Target = TraitData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> TraitData {
|
|
|
|
TraitData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
qualname: self.qualname,
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
value: self.value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct TupleVariantData {
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub name: String,
|
|
|
|
pub qualname: String,
|
|
|
|
pub type_value: String,
|
|
|
|
pub value: String,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::TupleVariantData {
|
|
|
|
type Target = TupleVariantData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> TupleVariantData {
|
|
|
|
TupleVariantData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
type_value: self.type_value,
|
|
|
|
value: self.value,
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data for a typedef.
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct TypedefData {
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub span: SpanData,
|
|
|
|
pub qualname: String,
|
|
|
|
pub value: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::TypedefData {
|
|
|
|
type Target = TypedefData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> TypedefData {
|
|
|
|
TypedefData {
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
|
|
|
qualname: self.qualname,
|
|
|
|
value: self.value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data for a reference to a type or trait.
|
|
|
|
#[derive(Clone, Debug, RustcEncodable)]
|
|
|
|
pub struct TypeRefData {
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
|
|
|
pub ref_id: Option<DefId>,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub qualname: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::TypeRefData {
|
|
|
|
type Target = TypeRefData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> TypeRefData {
|
|
|
|
TypeRefData {
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
|
|
|
ref_id: self.ref_id,
|
2016-05-03 12:54:29 +02:00
|
|
|
qualname: self.qualname,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct UseData {
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub span: SpanData,
|
|
|
|
pub name: String,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub mod_id: Option<DefId>,
|
|
|
|
pub scope: DefId
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::UseData {
|
|
|
|
type Target = UseData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> UseData {
|
|
|
|
UseData {
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
|
|
|
name: self.name,
|
2016-05-06 16:15:48 +12:00
|
|
|
mod_id: self.mod_id,
|
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct UseGlobData {
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub span: SpanData,
|
|
|
|
pub names: Vec<String>,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::UseGlobData {
|
|
|
|
type Target = UseGlobData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> UseGlobData {
|
|
|
|
UseGlobData {
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
|
|
|
names: self.names,
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data for local and global variables (consts and statics).
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct VariableData {
|
2016-05-06 16:15:48 +12:00
|
|
|
pub id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub name: String,
|
|
|
|
pub qualname: String,
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
pub value: String,
|
|
|
|
pub type_value: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::VariableData {
|
|
|
|
type Target = VariableData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> VariableData {
|
|
|
|
VariableData {
|
2016-05-06 16:15:48 +12:00
|
|
|
id: make_def_id(self.id, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
name: self.name,
|
|
|
|
qualname: self.qualname,
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
2016-05-03 12:54:29 +02:00
|
|
|
value: self.value,
|
|
|
|
type_value: self.type_value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Data for the use of some item (e.g., the use of a local variable, which
|
|
|
|
/// will refer to that variables declaration (by ref_id)).
|
|
|
|
#[derive(Debug, RustcEncodable)]
|
|
|
|
pub struct VariableRefData {
|
|
|
|
pub name: String,
|
|
|
|
pub span: SpanData,
|
2016-05-06 16:15:48 +12:00
|
|
|
pub scope: DefId,
|
|
|
|
pub ref_id: DefId,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lower for data::VariableRefData {
|
|
|
|
type Target = VariableRefData;
|
|
|
|
|
|
|
|
fn lower(self, tcx: &TyCtxt) -> VariableRefData {
|
|
|
|
VariableRefData {
|
|
|
|
name: self.name,
|
|
|
|
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
2016-05-06 16:15:48 +12:00
|
|
|
scope: make_def_id(self.scope, &tcx.map),
|
|
|
|
ref_id: self.ref_id,
|
2016-05-03 12:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|