2019-10-30 15:41:50 +00:00
|
|
|
//! This modules handles hygiene information.
|
|
|
|
//!
|
|
|
|
//! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at
|
|
|
|
//! this moment, this is horribly incomplete and handles only `$crate`.
|
2023-10-06 12:47:11 +00:00
|
|
|
use base_db::{span::SyntaxContextId, CrateId};
|
2019-12-03 16:07:56 +00:00
|
|
|
use either::Either;
|
2021-08-22 17:12:45 +00:00
|
|
|
use syntax::{
|
2023-10-06 12:47:11 +00:00
|
|
|
ast::{self},
|
|
|
|
TextRange,
|
2021-08-22 17:12:45 +00:00
|
|
|
};
|
2023-05-02 14:12:22 +00:00
|
|
|
use triomphe::Arc;
|
2019-10-30 15:41:50 +00:00
|
|
|
|
2019-10-30 16:10:53 +00:00
|
|
|
use crate::{
|
2023-10-06 12:47:11 +00:00
|
|
|
db::ExpandDatabase,
|
2019-10-30 15:56:20 +00:00
|
|
|
name::{AsName, Name},
|
2023-10-06 12:47:11 +00:00
|
|
|
HirFileId, InFile,
|
2019-10-30 15:56:20 +00:00
|
|
|
};
|
2019-10-30 15:41:50 +00:00
|
|
|
|
2023-10-06 12:47:11 +00:00
|
|
|
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct SyntaxContextData {
|
|
|
|
// FIXME: This might only need to be Option<MacroCallId>?
|
|
|
|
outer_expn: HirFileId,
|
|
|
|
outer_transparency: Transparency,
|
|
|
|
parent: SyntaxContextId,
|
|
|
|
/// This context, but with all transparent and semi-transparent expansions filtered away.
|
|
|
|
opaque: SyntaxContextId,
|
|
|
|
/// This context, but with all transparent expansions filtered away.
|
|
|
|
opaque_and_semitransparent: SyntaxContextId,
|
|
|
|
/// Name of the crate to which `$crate` with this context would resolve.
|
|
|
|
dollar_crate_name: Name,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A property of a macro expansion that determines how identifiers
|
|
|
|
/// produced by that expansion are resolved.
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Debug)]
|
|
|
|
pub enum Transparency {
|
|
|
|
/// Identifier produced by a transparent expansion is always resolved at call-site.
|
|
|
|
/// Call-site spans in procedural macros, hygiene opt-out in `macro` should use this.
|
|
|
|
Transparent,
|
|
|
|
/// Identifier produced by a semi-transparent expansion may be resolved
|
|
|
|
/// either at call-site or at definition-site.
|
|
|
|
/// If it's a local variable, label or `$crate` then it's resolved at def-site.
|
|
|
|
/// Otherwise it's resolved at call-site.
|
|
|
|
/// `macro_rules` macros behave like this, built-in macros currently behave like this too,
|
|
|
|
/// but that's an implementation detail.
|
|
|
|
SemiTransparent,
|
|
|
|
/// Identifier produced by an opaque expansion is always resolved at definition-site.
|
|
|
|
/// Def-site spans in procedural macros, identifiers from `macro` by default use this.
|
|
|
|
Opaque,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn apply_mark(
|
|
|
|
_db: &dyn ExpandDatabase,
|
|
|
|
_ctxt: SyntaxContextData,
|
|
|
|
_file_id: HirFileId,
|
|
|
|
_transparency: Transparency,
|
|
|
|
) -> SyntaxContextId {
|
|
|
|
_db.intern_syntax_context(_ctxt)
|
2019-10-30 15:41:50 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 12:47:11 +00:00
|
|
|
// pub(super) fn with_ctxt_from_mark(db: &ExpandDatabase, file_id: HirFileId) {
|
|
|
|
// self.with_ctxt_from_mark(expn_id, Transparency::Transparent)
|
|
|
|
// }
|
|
|
|
// pub(super) fn with_call_site_ctxt(db: &ExpandDatabase, file_id: HirFileId) {
|
|
|
|
// self.with_ctxt_from_mark(expn_id, Transparency::Transparent)
|
|
|
|
// }
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct Hygiene {}
|
|
|
|
|
2021-01-03 10:47:57 +00:00
|
|
|
impl Hygiene {
|
2023-10-06 12:47:11 +00:00
|
|
|
pub fn new(_: &dyn ExpandDatabase, _: HirFileId) -> Hygiene {
|
|
|
|
Hygiene {}
|
2019-10-30 15:41:50 +00:00
|
|
|
}
|
|
|
|
|
2021-01-03 10:47:57 +00:00
|
|
|
pub fn new_unhygienic() -> Hygiene {
|
2023-10-06 12:47:11 +00:00
|
|
|
Hygiene {}
|
2019-10-30 15:41:50 +00:00
|
|
|
}
|
2020-05-01 03:23:03 +00:00
|
|
|
|
2021-01-03 10:47:57 +00:00
|
|
|
// FIXME: this should just return name
|
2021-05-06 17:59:54 +00:00
|
|
|
pub fn name_ref_to_name(
|
|
|
|
&self,
|
2023-10-06 12:47:11 +00:00
|
|
|
_: &dyn ExpandDatabase,
|
2021-05-06 17:59:54 +00:00
|
|
|
name_ref: ast::NameRef,
|
|
|
|
) -> Either<Name, CrateId> {
|
2021-01-03 10:47:57 +00:00
|
|
|
Either::Left(name_ref.as_name())
|
|
|
|
}
|
2021-01-02 12:25:05 +00:00
|
|
|
|
2023-10-06 12:47:11 +00:00
|
|
|
pub fn local_inner_macros(&self, _: &dyn ExpandDatabase, _: ast::Path) -> Option<CrateId> {
|
|
|
|
None
|
2021-01-04 02:53:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
struct HygieneFrames(Arc<HygieneFrame>);
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
2023-10-06 12:47:11 +00:00
|
|
|
pub struct HygieneFrame {}
|
2021-01-04 02:53:31 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
2023-10-06 12:47:11 +00:00
|
|
|
struct HygieneInfo {}
|
2021-01-04 02:53:31 +00:00
|
|
|
|
|
|
|
impl HygieneInfo {
|
2023-10-06 12:47:11 +00:00
|
|
|
fn _map_ident_up(&self, _: &dyn ExpandDatabase, _: TextRange) -> Option<InFile<TextRange>> {
|
2023-09-29 10:37:57 +00:00
|
|
|
None
|
2021-01-04 02:53:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HygieneFrame {
|
2023-10-06 12:47:11 +00:00
|
|
|
pub(crate) fn new(_: &dyn ExpandDatabase, _: HirFileId) -> HygieneFrame {
|
|
|
|
HygieneFrame {}
|
2020-05-01 03:23:03 +00:00
|
|
|
}
|
2019-10-30 15:41:50 +00:00
|
|
|
}
|