aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-05-23 19:13:22 +0100
committerAleksey Kladov <[email protected]>2019-05-23 19:13:22 +0100
commit0e57d58dd086e2d114ccc82261b5396a5f828901 (patch)
tree4eb635aabd5730c41b82bb7be3f461687283d52c
parentce82fbfc44edff633d7f6a2d383b64bfd10d21c4 (diff)
kill code_model_impl
-rw-r--r--crates/ra_hir/src/code_model_api.rs66
-rw-r--r--crates/ra_hir/src/code_model_impl.rs2
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs50
-rw-r--r--crates/ra_hir/src/code_model_impl/konst.rs34
-rw-r--r--crates/ra_hir/src/lib.rs1
5 files changed, 64 insertions, 89 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index b6834bc25..49030ce67 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -1,7 +1,7 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_db::{CrateId, SourceRootId, Edition, FileId}; 3use ra_db::{CrateId, SourceRootId, Edition, FileId};
4use ra_syntax::{ast::self, TreeArc}; 4use ra_syntax::{ast::{self, NameOwner, TypeAscriptionOwner}, TreeArc};
5 5
6use crate::{ 6use crate::{
7 Name, AsName, AstId, Ty, HirFileId, Either, 7 Name, AsName, AstId, Ty, HirFileId, Either,
@@ -9,7 +9,7 @@ use crate::{
9 type_ref::TypeRef, 9 type_ref::TypeRef,
10 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId}, 10 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId},
11 expr::{Body, BodySourceMap, validation::ExprValidator}, 11 expr::{Body, BodySourceMap, validation::ExprValidator},
12 ty::{ TraitRef, InferenceResult}, 12 ty::{TraitRef, InferenceResult},
13 adt::{EnumVariantId, StructFieldId, VariantDef}, 13 adt::{EnumVariantId, StructFieldId, VariantDef},
14 generics::HasGenericParams, 14 generics::HasGenericParams,
15 docs::{Documentation, Docs, docs_from_ast}, 15 docs::{Documentation, Docs, docs_from_ast},
@@ -18,6 +18,7 @@ use crate::{
18 resolve::Resolver, 18 resolve::Resolver,
19 diagnostics::{DiagnosticSink}, 19 diagnostics::{DiagnosticSink},
20 traits::{TraitItem, TraitData}, 20 traits::{TraitItem, TraitData},
21 type_ref::Mutability,
21}; 22};
22 23
23/// hir::Crate describes a single crate. It's the main interface with which 24/// hir::Crate describes a single crate. It's the main interface with which
@@ -572,6 +573,44 @@ pub struct FnSignature {
572} 573}
573 574
574impl FnSignature { 575impl FnSignature {
576 pub(crate) fn fn_signature_query(db: &impl DefDatabase, func: Function) -> Arc<FnSignature> {
577 let (_, node) = func.source(db);
578 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
579 let mut params = Vec::new();
580 let mut has_self_param = false;
581 if let Some(param_list) = node.param_list() {
582 if let Some(self_param) = param_list.self_param() {
583 let self_type = if let Some(type_ref) = self_param.ascribed_type() {
584 TypeRef::from_ast(type_ref)
585 } else {
586 let self_type = TypeRef::Path(Name::self_type().into());
587 match self_param.kind() {
588 ast::SelfParamKind::Owned => self_type,
589 ast::SelfParamKind::Ref => {
590 TypeRef::Reference(Box::new(self_type), Mutability::Shared)
591 }
592 ast::SelfParamKind::MutRef => {
593 TypeRef::Reference(Box::new(self_type), Mutability::Mut)
594 }
595 }
596 };
597 params.push(self_type);
598 has_self_param = true;
599 }
600 for param in param_list.params() {
601 let type_ref = TypeRef::from_ast_opt(param.ascribed_type());
602 params.push(type_ref);
603 }
604 }
605 let ret_type = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) {
606 TypeRef::from_ast(type_ref)
607 } else {
608 TypeRef::unit()
609 };
610
611 let sig = FnSignature { name, params, ret_type, has_self_param };
612 Arc::new(sig)
613 }
575 pub fn name(&self) -> &Name { 614 pub fn name(&self) -> &Name {
576 &self.name 615 &self.name
577 } 616 }
@@ -731,6 +770,29 @@ impl ConstSignature {
731 pub fn type_ref(&self) -> &TypeRef { 770 pub fn type_ref(&self) -> &TypeRef {
732 &self.type_ref 771 &self.type_ref
733 } 772 }
773
774 pub(crate) fn const_signature_query(
775 db: &impl DefDatabase,
776 konst: Const,
777 ) -> Arc<ConstSignature> {
778 let (_, node) = konst.source(db);
779 const_signature_for(&*node)
780 }
781
782 pub(crate) fn static_signature_query(
783 db: &impl DefDatabase,
784 konst: Static,
785 ) -> Arc<ConstSignature> {
786 let (_, node) = konst.source(db);
787 const_signature_for(&*node)
788 }
789}
790
791fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> {
792 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
793 let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
794 let sig = ConstSignature { name, type_ref };
795 Arc::new(sig)
734} 796}
735 797
736#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 798#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
diff --git a/crates/ra_hir/src/code_model_impl.rs b/crates/ra_hir/src/code_model_impl.rs
deleted file mode 100644
index 7bdd86eae..000000000
--- a/crates/ra_hir/src/code_model_impl.rs
+++ /dev/null
@@ -1,2 +0,0 @@
1mod konst; // `const` is invalid ident :(
2pub(crate) mod function;
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 @@
1use std::sync::Arc;
2
3use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
4
5use crate::{
6 Name, AsName, Function, FnSignature,
7 type_ref::{TypeRef, Mutability},
8 DefDatabase,
9};
10
11impl 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 @@
1use std::sync::Arc;
2
3use ra_syntax::ast::{NameOwner, TypeAscriptionOwner};
4
5use crate::{
6 Name, AsName, Const, ConstSignature, Static,
7 type_ref::{TypeRef},
8 DefDatabase,
9};
10
11fn 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
18impl 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/lib.rs b/crates/ra_hir/src/lib.rs
index 0135644db..556828946 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -43,7 +43,6 @@ mod resolve;
43pub mod diagnostics; 43pub mod diagnostics;
44 44
45mod code_model_api; 45mod code_model_api;
46mod code_model_impl;
47 46
48#[cfg(test)] 47#[cfg(test)]
49mod marks; 48mod marks;