diff options
Diffstat (limited to 'crates/ra_hir/src/expr.rs')
-rw-r--r-- | crates/ra_hir/src/expr.rs | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index a85422955..280746761 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -10,7 +10,7 @@ use ra_syntax::{ | |||
10 | }; | 10 | }; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | Path, Name, HirDatabase, Function, Resolver, | 13 | Path, Name, HirDatabase, Function, Resolver,DefWithBody, |
14 | name::AsName, | 14 | name::AsName, |
15 | type_ref::{Mutability, TypeRef}, | 15 | type_ref::{Mutability, TypeRef}, |
16 | }; | 16 | }; |
@@ -29,7 +29,7 @@ impl_arena_id!(ExprId); | |||
29 | pub struct Body { | 29 | pub struct Body { |
30 | // FIXME: this should be more general, consts & statics also have bodies | 30 | // FIXME: this should be more general, consts & statics also have bodies |
31 | /// The Function of the item this body belongs to | 31 | /// The Function of the item this body belongs to |
32 | owner: Function, | 32 | owner: DefWithBody, |
33 | exprs: Arena<ExprId, Expr>, | 33 | exprs: Arena<ExprId, Expr>, |
34 | pats: Arena<PatId, Pat>, | 34 | pats: Arena<PatId, Pat>, |
35 | /// The patterns for the function's parameters. While the parameter types are | 35 | /// The patterns for the function's parameters. While the parameter types are |
@@ -66,7 +66,7 @@ impl Body { | |||
66 | self.body_expr | 66 | self.body_expr |
67 | } | 67 | } |
68 | 68 | ||
69 | pub fn owner(&self) -> Function { | 69 | pub fn owner(&self) -> DefWithBody { |
70 | self.owner | 70 | self.owner |
71 | } | 71 | } |
72 | 72 | ||
@@ -464,7 +464,7 @@ impl Pat { | |||
464 | // Queries | 464 | // Queries |
465 | 465 | ||
466 | struct ExprCollector { | 466 | struct ExprCollector { |
467 | owner: Function, | 467 | owner: DefWithBody, |
468 | exprs: Arena<ExprId, Expr>, | 468 | exprs: Arena<ExprId, Expr>, |
469 | pats: Arena<PatId, Pat>, | 469 | pats: Arena<PatId, Pat>, |
470 | source_map: BodySourceMap, | 470 | source_map: BodySourceMap, |
@@ -473,7 +473,7 @@ struct ExprCollector { | |||
473 | } | 473 | } |
474 | 474 | ||
475 | impl ExprCollector { | 475 | impl ExprCollector { |
476 | fn new(owner: Function) -> Self { | 476 | fn new(owner: DefWithBody) -> Self { |
477 | ExprCollector { | 477 | ExprCollector { |
478 | owner, | 478 | owner, |
479 | exprs: Arena::default(), | 479 | exprs: Arena::default(), |
@@ -503,6 +503,9 @@ impl ExprCollector { | |||
503 | self.exprs.alloc(block) | 503 | self.exprs.alloc(block) |
504 | } | 504 | } |
505 | 505 | ||
506 | |||
507 | |||
508 | |||
506 | fn collect_expr(&mut self, expr: &ast::Expr) -> ExprId { | 509 | fn collect_expr(&mut self, expr: &ast::Expr) -> ExprId { |
507 | let syntax_ptr = SyntaxNodePtr::new(expr.syntax()); | 510 | let syntax_ptr = SyntaxNodePtr::new(expr.syntax()); |
508 | match expr.kind() { | 511 | match expr.kind() { |
@@ -871,6 +874,15 @@ impl ExprCollector { | |||
871 | } | 874 | } |
872 | } | 875 | } |
873 | 876 | ||
877 | |||
878 | fn collect_const_body(&mut self,node:&ast::ConstDef) { | ||
879 | |||
880 | } | ||
881 | |||
882 | fn collect_static_body(&mut self,node:&ast::StaticDef) { | ||
883 | |||
884 | } | ||
885 | |||
874 | fn collect_fn_body(&mut self, node: &ast::FnDef) { | 886 | fn collect_fn_body(&mut self, node: &ast::FnDef) { |
875 | if let Some(param_list) = node.param_list() { | 887 | if let Some(param_list) = node.param_list() { |
876 | if let Some(self_param) = param_list.self_param() { | 888 | if let Some(self_param) = param_list.self_param() { |
@@ -917,19 +929,25 @@ impl ExprCollector { | |||
917 | 929 | ||
918 | pub(crate) fn body_with_source_map_query( | 930 | pub(crate) fn body_with_source_map_query( |
919 | db: &impl HirDatabase, | 931 | db: &impl HirDatabase, |
920 | func: Function, | 932 | def: DefWithBody, |
921 | ) -> (Arc<Body>, Arc<BodySourceMap>) { | 933 | ) -> (Arc<Body>, Arc<BodySourceMap>) { |
922 | let mut collector = ExprCollector::new(func); | ||
923 | 934 | ||
924 | // FIXME: consts, etc. | 935 | let mut collector = ExprCollector::new(def); |
925 | collector.collect_fn_body(&func.source(db).1); | ||
926 | 936 | ||
937 | // FIXME: do can this be turned into a method | ||
938 | |||
939 | match def { | ||
940 | DefWithBody::Const(ref c) => collector.collect_const_body(&def.const_source(db).1), | ||
941 | DefWithBody::Func(ref f) => collector.collect_fn_body(&def.func_source(db).1), | ||
942 | DefWithBody::Static(ref s) => collector.collect_static_body(&def.static_source(db).1) | ||
943 | } | ||
944 | |||
927 | let (body, source_map) = collector.finish(); | 945 | let (body, source_map) = collector.finish(); |
928 | (Arc::new(body), Arc::new(source_map)) | 946 | (Arc::new(body), Arc::new(source_map)) |
929 | } | 947 | } |
930 | 948 | ||
931 | pub(crate) fn body_hir_query(db: &impl HirDatabase, func: Function) -> Arc<Body> { | 949 | pub(crate) fn body_hir_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<Body> { |
932 | db.body_with_source_map(func).0 | 950 | db.body_with_source_map(def).0 |
933 | } | 951 | } |
934 | 952 | ||
935 | #[cfg(test)] | 953 | #[cfg(test)] |