summaryrefslogtreecommitdiff
path: root/src/ident.cpp
blob: 63fe57edefb03a01f5af6157d798fe8c7217e47a (plain)
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
/*
 * MRustC - Rust Compiler
 * - By John Hodge (Mutabah/thePowersGang)
 *
 * include/ident.cpp
 * - Identifiers with hygiene
 */
#include <iostream>
#include <ident.hpp>
#include <debug.hpp>
#include <common.hpp>   // vector print

unsigned int Ident::Hygiene::g_next_scope = 0;

bool Ident::Hygiene::is_visible(const Hygiene& src) const
{
    // HACK: Disable hygiene for now
    //return true;

    if( this->contexts.size() == 0 ) {
        return src.contexts.size() == 0;
    }

    auto des = this->contexts.back();
    for(const auto& c : src.contexts)
        if( des == c )
            return true;
    return false;
}

::std::ostream& operator<<(::std::ostream& os, const Ident& x) {
    os << x.name << x.hygiene;
    return os;
}

::std::ostream& operator<<(::std::ostream& os, const Ident::Hygiene& x) {
    os << "{" << x.contexts;
    if( x.search_module )
        os << " " << x.search_module->ents;
    os << "}";
    return os;
}