use the included file as the source of expanded include macro

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
This commit is contained in:
Yilin Chen 2021-03-21 23:02:01 +08:00
parent a0ed87ff56
commit 3bb9efb6b7
No known key found for this signature in database
GPG key ID: 353E7ED34BF326E0
5 changed files with 107 additions and 28 deletions

View file

@ -84,7 +84,11 @@ impl HirFileId {
}
MacroCallId::EagerMacro(id) => {
let loc = db.lookup_intern_eager_expansion(id);
loc.call.file_id
if let Some(included_file) = loc.included_file {
return included_file;
} else {
loc.call.file_id
}
}
};
file_id.original_file(db)
@ -188,6 +192,21 @@ impl HirFileId {
}
}
}
/// Return whether this file is an include macro
pub fn is_include_macro(&self, db: &dyn db::AstDatabase) -> bool {
match self.0 {
HirFileIdRepr::MacroFile(macro_file) => match macro_file.macro_call_id {
MacroCallId::EagerMacro(id) => {
let loc = db.lookup_intern_eager_expansion(id);
return loc.included_file.is_some();
}
_ => {}
},
_ => {}
}
false
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@ -315,6 +334,8 @@ pub struct EagerCallLoc {
pub(crate) subtree: Arc<tt::Subtree>,
pub(crate) krate: CrateId,
pub(crate) call: AstId<ast::MacroCall>,
// The included file ID of the include macro.
pub(crate) included_file: Option<FileId>,
}
/// ExpansionInfo mainly describes how to map text range between src and expanded macro