aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/expr.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-05-04 16:01:43 +0100
committerAleksey Kladov <[email protected]>2019-05-04 16:01:43 +0100
commitbcf45371ff19882e67300cc483b481450ee129fb (patch)
tree616d3e4dd5fa15228ac2ea85a93d76df0c3b8581 /crates/ra_hir/src/expr.rs
parent87a1e276d56a3cb5f9d9c59f8c52c5573e19982b (diff)
make macro expansion into a proper query
Diffstat (limited to 'crates/ra_hir/src/expr.rs')
-rw-r--r--crates/ra_hir/src/expr.rs17
1 files changed, 3 insertions, 14 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index f9b3f5443..692da2895 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -5,14 +5,13 @@ use rustc_hash::FxHashMap;
5 5
6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; 6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
7use ra_syntax::{ 7use ra_syntax::{
8 SyntaxNodePtr, AstPtr, AstNode,TreeArc, 8 SyntaxNodePtr, AstPtr, AstNode,
9 ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind,ArrayExprKind, TypeAscriptionOwner} 9 ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind,ArrayExprKind, TypeAscriptionOwner}
10}; 10};
11 11
12use crate::{ 12use crate::{
13 Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, 13 Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId,
14 name::AsName, 14 name::AsName,
15 ids::{MacroCallId},
16 type_ref::{Mutability, TypeRef}, 15 type_ref::{Mutability, TypeRef},
17}; 16};
18use crate::{path::GenericArgs, ty::primitive::{IntTy, UncertainIntTy, FloatTy, UncertainFloatTy}}; 17use crate::{path::GenericArgs, ty::primitive::{IntTy, UncertainIntTy, FloatTy, UncertainFloatTy}};
@@ -826,8 +825,8 @@ where
826 .with_file_id(self.current_file_id); 825 .with_file_id(self.current_file_id);
827 826
828 if let Some(call_id) = self.resolver.resolve_macro_call(self.db, path, ast_id) { 827 if let Some(call_id) = self.resolver.resolve_macro_call(self.db, path, ast_id) {
829 if let Some(arg) = self.db.macro_arg(call_id) { 828 if let Some(tt) = self.db.macro_expand(call_id).ok() {
830 if let Some(expr) = expand_macro_to_expr(self.db, call_id, &arg) { 829 if let Some(expr) = mbe::token_tree_to_expr(&tt).ok() {
831 log::debug!("macro expansion {}", expr.syntax().debug_dump()); 830 log::debug!("macro expansion {}", expr.syntax().debug_dump());
832 let old_file_id = 831 let old_file_id =
833 std::mem::replace(&mut self.current_file_id, call_id.into()); 832 std::mem::replace(&mut self.current_file_id, call_id.into());
@@ -998,16 +997,6 @@ where
998 } 997 }
999} 998}
1000 999
1001fn expand_macro_to_expr(
1002 db: &impl HirDatabase,
1003 macro_call: MacroCallId,
1004 arg: &tt::Subtree,
1005) -> Option<TreeArc<ast::Expr>> {
1006 let rules = db.macro_def(macro_call.loc(db).def)?;
1007 let expanded = rules.expand(&arg).ok()?;
1008 mbe::token_tree_to_expr(&expanded).ok()
1009}
1010
1011pub(crate) fn body_with_source_map_query( 1000pub(crate) fn body_with_source_map_query(
1012 db: &impl HirDatabase, 1001 db: &impl HirDatabase,
1013 def: DefWithBody, 1002 def: DefWithBody,