summaryrefslogtreecommitdiff
path: root/src/ident.cpp
blob: 5d0fe00c4bc906298b4093144e832487f58dbb5c (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * MRustC - Rust Compiler
 * - By John Hodge (Mutabah/thePowersGang)
 *
 * include/ident.cpp
 * - Identifiers with hygine
 */
#include <iostream>
#include <ident.hpp>
#include <debug.hpp>
#include <common.hpp>   // vector print

bool Ident::Hygine::is_visible(const Hygine& src) const
{
    // HACK: Disable hygine for now
    return true;
    
    DEBUG("*this = " << *this << ", src=" << src);
    if( this->file_num != src.file_num ) {
        DEBUG("- Different file");
        return false;
    }
    
    // `this` is the item, `src` is the ident used to access it

    // If this is from a deeper point than the source, it won't work.
    if( this->indexes.size() > src.indexes.size() ) {
        DEBUG("- Not subset: len");
        return false;
    }
    
    // If this hygine list (barring the last) is a subset of the source
    for(unsigned int i = 0; i < this->indexes.size()-1 - 1; i ++)
    {
        if( this->indexes[i] != src.indexes[i] ) {
            DEBUG("- Not subset: " << i);
            return false;
        }
    }
    
    unsigned int end = this->indexes.size()-1-1;
    // Allow match if this ident is from before the addressing ident
    if( this->indexes[end] < src.indexes[end] ) {
        return true;
    }
    
    DEBUG("- Not before");
    return false;
}

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

::std::ostream& operator<<(::std::ostream& os, const Ident::Hygine& x) {
    os << "{" << x.file_num << ": [" << x.indexes << "]}";
    return os;
}