remove old macro support

This commit is contained in:
Aleksey Kladov 2019-03-16 19:40:41 +03:00
parent ee3cf6172b
commit 6955e392f8
8 changed files with 94 additions and 260 deletions

View file

@ -89,17 +89,31 @@ impl HirFileId {
) -> TreeArc<SourceFile> {
match file_id.0 {
HirFileIdRepr::File(file_id) => db.parse(file_id),
HirFileIdRepr::Macro(m) => {
if let Some(exp) = db.expand_macro_invocation(m) {
return exp.file();
}
HirFileIdRepr::Macro(macro_call_id) => {
// returning an empty string looks fishy...
SourceFile::parse("")
parse_macro(db, macro_call_id).unwrap_or_else(|| SourceFile::parse(""))
}
}
}
}
fn parse_macro(
db: &impl PersistentHirDatabase,
macro_call_id: MacroCallId,
) -> Option<TreeArc<SourceFile>> {
let loc = macro_call_id.loc(db);
let syntax = db.file_item(loc.source_item_id);
let macro_call = ast::MacroCall::cast(&syntax).unwrap();
let (macro_arg, _) = macro_call.token_tree().and_then(mbe::ast_to_token_tree)?;
let def_map = db.crate_def_map(loc.module.krate);
let (krate, macro_id) = def_map.resolve_macro(macro_call_id)?;
let def_map = db.crate_def_map(krate);
let macro_rules = &def_map[macro_id];
let tt = macro_rules.expand(&macro_arg).ok()?;
Some(mbe::token_tree_to_ast_item_list(&tt))
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum HirFileIdRepr {
File(FileId),
@ -373,7 +387,6 @@ impl SourceFileItems {
impl std::ops::Index<SourceFileItemId> for SourceFileItems {
type Output = SyntaxNodePtr;
fn index(&self, idx: SourceFileItemId) -> &SyntaxNodePtr {
eprintln!("invalid SourceFileItemId({:?}) for file({:?})", idx, self.file_id);
&self.arena[idx]
}
}