Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! 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`.
use base_db::{span::SyntaxContextId, CrateId};
use either::Either;
use syntax::{
    ast::{self},
    TextRange,
};
use triomphe::Arc;

use crate::{
    db::ExpandDatabase,
    name::{AsName, Name},
    HirFileId, InFile,
};

#[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)
}

// 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 {}

impl Hygiene {
    pub fn new(_: &dyn ExpandDatabase, _: HirFileId) -> Hygiene {
        Hygiene {}
    }

    pub fn new_unhygienic() -> Hygiene {
        Hygiene {}
    }

    // FIXME: this should just return name
    pub fn name_ref_to_name(
        &self,
        _: &dyn ExpandDatabase,
        name_ref: ast::NameRef,
    ) -> Either<Name, CrateId> {
        Either::Left(name_ref.as_name())
    }

    pub fn local_inner_macros(&self, _: &dyn ExpandDatabase, _: ast::Path) -> Option<CrateId> {
        None
    }
}

#[derive(Clone, Debug)]
struct HygieneFrames(Arc<HygieneFrame>);

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct HygieneFrame {}

#[derive(Debug, Clone, PartialEq, Eq)]
struct HygieneInfo {}

impl HygieneInfo {
    fn _map_ident_up(&self, _: &dyn ExpandDatabase, _: TextRange) -> Option<InFile<TextRange>> {
        None
    }
}

impl HygieneFrame {
    pub(crate) fn new(_: &dyn ExpandDatabase, _: HirFileId) -> HygieneFrame {
        HygieneFrame {}
    }
}