diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_impl')
-rw-r--r-- | crates/ra_hir/src/code_model_impl/function.rs | 50 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_impl/konst.rs | 34 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_impl/krate.rs | 22 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_impl/module.rs | 99 |
4 files changed, 0 insertions, 205 deletions
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs deleted file mode 100644 index f8bd0f784..000000000 --- a/crates/ra_hir/src/code_model_impl/function.rs +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
3 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | ||
4 | |||
5 | use crate::{ | ||
6 | Name, AsName, Function, FnSignature, | ||
7 | type_ref::{TypeRef, Mutability}, | ||
8 | DefDatabase, | ||
9 | }; | ||
10 | |||
11 | impl FnSignature { | ||
12 | pub(crate) fn fn_signature_query(db: &impl DefDatabase, func: Function) -> Arc<FnSignature> { | ||
13 | let (_, node) = func.source(db); | ||
14 | let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | ||
15 | let mut params = Vec::new(); | ||
16 | let mut has_self_param = false; | ||
17 | if let Some(param_list) = node.param_list() { | ||
18 | if let Some(self_param) = param_list.self_param() { | ||
19 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { | ||
20 | TypeRef::from_ast(type_ref) | ||
21 | } else { | ||
22 | let self_type = TypeRef::Path(Name::self_type().into()); | ||
23 | match self_param.kind() { | ||
24 | ast::SelfParamKind::Owned => self_type, | ||
25 | ast::SelfParamKind::Ref => { | ||
26 | TypeRef::Reference(Box::new(self_type), Mutability::Shared) | ||
27 | } | ||
28 | ast::SelfParamKind::MutRef => { | ||
29 | TypeRef::Reference(Box::new(self_type), Mutability::Mut) | ||
30 | } | ||
31 | } | ||
32 | }; | ||
33 | params.push(self_type); | ||
34 | has_self_param = true; | ||
35 | } | ||
36 | for param in param_list.params() { | ||
37 | let type_ref = TypeRef::from_ast_opt(param.ascribed_type()); | ||
38 | params.push(type_ref); | ||
39 | } | ||
40 | } | ||
41 | let ret_type = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) { | ||
42 | TypeRef::from_ast(type_ref) | ||
43 | } else { | ||
44 | TypeRef::unit() | ||
45 | }; | ||
46 | |||
47 | let sig = FnSignature { name, params, ret_type, has_self_param }; | ||
48 | Arc::new(sig) | ||
49 | } | ||
50 | } | ||
diff --git a/crates/ra_hir/src/code_model_impl/konst.rs b/crates/ra_hir/src/code_model_impl/konst.rs deleted file mode 100644 index db4e5ce5c..000000000 --- a/crates/ra_hir/src/code_model_impl/konst.rs +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
3 | use ra_syntax::ast::{NameOwner, TypeAscriptionOwner}; | ||
4 | |||
5 | use crate::{ | ||
6 | Name, AsName, Const, ConstSignature, Static, | ||
7 | type_ref::{TypeRef}, | ||
8 | DefDatabase, | ||
9 | }; | ||
10 | |||
11 | fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> { | ||
12 | let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | ||
13 | let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); | ||
14 | let sig = ConstSignature { name, type_ref }; | ||
15 | Arc::new(sig) | ||
16 | } | ||
17 | |||
18 | impl ConstSignature { | ||
19 | pub(crate) fn const_signature_query( | ||
20 | db: &impl DefDatabase, | ||
21 | konst: Const, | ||
22 | ) -> Arc<ConstSignature> { | ||
23 | let (_, node) = konst.source(db); | ||
24 | const_signature_for(&*node) | ||
25 | } | ||
26 | |||
27 | pub(crate) fn static_signature_query( | ||
28 | db: &impl DefDatabase, | ||
29 | konst: Static, | ||
30 | ) -> Arc<ConstSignature> { | ||
31 | let (_, node) = konst.source(db); | ||
32 | const_signature_for(&*node) | ||
33 | } | ||
34 | } | ||
diff --git a/crates/ra_hir/src/code_model_impl/krate.rs b/crates/ra_hir/src/code_model_impl/krate.rs deleted file mode 100644 index 914414fc3..000000000 --- a/crates/ra_hir/src/code_model_impl/krate.rs +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | use crate::{ | ||
2 | Crate, CrateDependency, AsName, Module, DefDatabase, | ||
3 | }; | ||
4 | |||
5 | impl Crate { | ||
6 | pub(crate) fn dependencies_impl(&self, db: &impl DefDatabase) -> Vec<CrateDependency> { | ||
7 | let crate_graph = db.crate_graph(); | ||
8 | crate_graph | ||
9 | .dependencies(self.crate_id) | ||
10 | .map(|dep| { | ||
11 | let krate = Crate { crate_id: dep.crate_id() }; | ||
12 | let name = dep.as_name(); | ||
13 | CrateDependency { krate, name } | ||
14 | }) | ||
15 | .collect() | ||
16 | } | ||
17 | pub(crate) fn root_module_impl(&self, db: &impl DefDatabase) -> Option<Module> { | ||
18 | let module_id = db.crate_def_map(*self).root(); | ||
19 | let module = Module { krate: *self, module_id }; | ||
20 | Some(module) | ||
21 | } | ||
22 | } | ||
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs deleted file mode 100644 index 5c2ea73ce..000000000 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | use ra_db::FileId; | ||
2 | use ra_syntax::{ast, TreeArc}; | ||
3 | |||
4 | use crate::{ | ||
5 | Module, ModuleSource, Name, AstId, | ||
6 | nameres::CrateModuleId, | ||
7 | HirDatabase, DefDatabase, | ||
8 | HirFileId, | ||
9 | }; | ||
10 | |||
11 | impl ModuleSource { | ||
12 | pub(crate) fn new( | ||
13 | db: &impl DefDatabase, | ||
14 | file_id: Option<FileId>, | ||
15 | decl_id: Option<AstId<ast::Module>>, | ||
16 | ) -> ModuleSource { | ||
17 | match (file_id, decl_id) { | ||
18 | (Some(file_id), _) => { | ||
19 | let source_file = db.parse(file_id); | ||
20 | ModuleSource::SourceFile(source_file) | ||
21 | } | ||
22 | (None, Some(item_id)) => { | ||
23 | let module = item_id.to_node(db); | ||
24 | assert!(module.item_list().is_some(), "expected inline module"); | ||
25 | ModuleSource::Module(module.to_owned()) | ||
26 | } | ||
27 | (None, None) => panic!(), | ||
28 | } | ||
29 | } | ||
30 | } | ||
31 | |||
32 | impl Module { | ||
33 | fn with_module_id(&self, module_id: CrateModuleId) -> Module { | ||
34 | Module { module_id, krate: self.krate } | ||
35 | } | ||
36 | |||
37 | pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Option<Name> { | ||
38 | let def_map = db.crate_def_map(self.krate); | ||
39 | let parent = def_map[self.module_id].parent?; | ||
40 | def_map[parent].children.iter().find_map(|(name, module_id)| { | ||
41 | if *module_id == self.module_id { | ||
42 | Some(name.clone()) | ||
43 | } else { | ||
44 | None | ||
45 | } | ||
46 | }) | ||
47 | } | ||
48 | |||
49 | pub(crate) fn definition_source_impl( | ||
50 | &self, | ||
51 | db: &impl DefDatabase, | ||
52 | ) -> (HirFileId, ModuleSource) { | ||
53 | let def_map = db.crate_def_map(self.krate); | ||
54 | let decl_id = def_map[self.module_id].declaration; | ||
55 | let file_id = def_map[self.module_id].definition; | ||
56 | let module_source = ModuleSource::new(db, file_id, decl_id); | ||
57 | let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id()); | ||
58 | (file_id, module_source) | ||
59 | } | ||
60 | |||
61 | pub(crate) fn declaration_source_impl( | ||
62 | &self, | ||
63 | db: &impl HirDatabase, | ||
64 | ) -> Option<(HirFileId, TreeArc<ast::Module>)> { | ||
65 | let def_map = db.crate_def_map(self.krate); | ||
66 | let decl = def_map[self.module_id].declaration?; | ||
67 | let ast = decl.to_node(db); | ||
68 | Some((decl.file_id(), ast)) | ||
69 | } | ||
70 | |||
71 | pub(crate) fn crate_root_impl(&self, db: &impl DefDatabase) -> Module { | ||
72 | let def_map = db.crate_def_map(self.krate); | ||
73 | self.with_module_id(def_map.root()) | ||
74 | } | ||
75 | |||
76 | /// Finds a child module with the specified name. | ||
77 | pub(crate) fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> { | ||
78 | let def_map = db.crate_def_map(self.krate); | ||
79 | let child_id = def_map[self.module_id].children.get(name)?; | ||
80 | Some(self.with_module_id(*child_id)) | ||
81 | } | ||
82 | |||
83 | /// Iterates over all child modules. | ||
84 | pub(crate) fn children_impl(&self, db: &impl DefDatabase) -> impl Iterator<Item = Module> { | ||
85 | let def_map = db.crate_def_map(self.krate); | ||
86 | let children = def_map[self.module_id] | ||
87 | .children | ||
88 | .iter() | ||
89 | .map(|(_, module_id)| self.with_module_id(*module_id)) | ||
90 | .collect::<Vec<_>>(); | ||
91 | children.into_iter() | ||
92 | } | ||
93 | |||
94 | pub(crate) fn parent_impl(&self, db: &impl DefDatabase) -> Option<Module> { | ||
95 | let def_map = db.crate_def_map(self.krate); | ||
96 | let parent_id = def_map[self.module_id].parent?; | ||
97 | Some(self.with_module_id(parent_id)) | ||
98 | } | ||
99 | } | ||