make macro expansion into a proper query

This commit is contained in:
Aleksey Kladov 2019-05-04 18:01:43 +03:00
parent 87a1e276d5
commit bcf45371ff
3 changed files with 27 additions and 34 deletions

View file

@ -5,14 +5,13 @@ use rustc_hash::FxHashMap;
use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
use ra_syntax::{
SyntaxNodePtr, AstPtr, AstNode,TreeArc,
SyntaxNodePtr, AstPtr, AstNode,
ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind,ArrayExprKind, TypeAscriptionOwner}
};
use crate::{
Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId,
name::AsName,
ids::{MacroCallId},
type_ref::{Mutability, TypeRef},
};
use crate::{path::GenericArgs, ty::primitive::{IntTy, UncertainIntTy, FloatTy, UncertainFloatTy}};
@ -826,8 +825,8 @@ where
.with_file_id(self.current_file_id);
if let Some(call_id) = self.resolver.resolve_macro_call(self.db, path, ast_id) {
if let Some(arg) = self.db.macro_arg(call_id) {
if let Some(expr) = expand_macro_to_expr(self.db, call_id, &arg) {
if let Some(tt) = self.db.macro_expand(call_id).ok() {
if let Some(expr) = mbe::token_tree_to_expr(&tt).ok() {
log::debug!("macro expansion {}", expr.syntax().debug_dump());
let old_file_id =
std::mem::replace(&mut self.current_file_id, call_id.into());
@ -998,16 +997,6 @@ where
}
}
fn expand_macro_to_expr(
db: &impl HirDatabase,
macro_call: MacroCallId,
arg: &tt::Subtree,
) -> Option<TreeArc<ast::Expr>> {
let rules = db.macro_def(macro_call.loc(db).def)?;
let expanded = rules.expand(&arg).ok()?;
mbe::token_tree_to_expr(&expanded).ok()
}
pub(crate) fn body_with_source_map_query(
db: &impl HirDatabase,
def: DefWithBody,