summaryrefslogtreecommitdiff
path: root/src/mir/visit_crate_mir.cpp
blob: 22e772747ded0eedfa3c6d733eda7e505dbe30f1 (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
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
/*
 * MRustC - Rust Compiler
 * - By John Hodge (Mutabah/thePowersGang)
 *
 * mir/visit_crate_mir.cpp
 * - Visitor to visit all MIR blobs in a crate
 */
#include "visit_crate_mir.hpp"
#include <hir/expr.hpp>

// NOTE: This is left here to ensure that any expressions that aren't handled by higher code cause a failure
void MIR::OuterVisitor::visit_expr(::HIR::ExprPtr& exp)
{
    BUG(Span(), "visit_expr hit in OuterVisitor");
}

void MIR::OuterVisitor::visit_type(::HIR::TypeRef& ty)
{
    TU_IFLET(::HIR::TypeRef::Data, ty.m_data, Array, e,
        this->visit_type( *e.inner );
        DEBUG("Array size " << ty);
        if( e.size ) {
            m_cb(m_resolve, ::HIR::ItemPath(""), *e.size, {}, ::HIR::TypeRef(::HIR::CoreType::Usize));
        }
    )
    else {
        ::HIR::Visitor::visit_type(ty);
    }
}

void MIR::OuterVisitor::visit_function(::HIR::ItemPath p, ::HIR::Function& item)
{
    auto _ = this->m_resolve.set_item_generics(item.m_params);
    if( item.m_code )
    {
        DEBUG("Function code " << p);
        m_cb(m_resolve, p, item.m_code, item.m_args, item.m_return);
    }
}
void MIR::OuterVisitor::visit_static(::HIR::ItemPath p, ::HIR::Static& item)
{
    if( item.m_value ) {
        DEBUG("`static` value " << p);
        m_cb(m_resolve, p, item.m_value, {}, item.m_type);
    }
}
void MIR::OuterVisitor::visit_constant(::HIR::ItemPath p, ::HIR::Constant& item)
{
    if( item.m_value ) {
        DEBUG("`const` value " << p);
        m_cb(m_resolve, p, item.m_value, {}, item.m_type);
    }
}
void MIR::OuterVisitor::visit_enum(::HIR::ItemPath p, ::HIR::Enum& item)
{
    auto _ = this->m_resolve.set_item_generics(item.m_params);

    if( auto* e = item.m_data.opt_Value() )
    {
        auto enum_type = ::HIR::Enum::get_repr_type(e->repr);

        for(auto& var : e->variants)
        {
            if( var.expr ) {
                m_cb(m_resolve, p + var.name, var.expr, {}, enum_type);
            }
        }
    }
}

void MIR::OuterVisitor::visit_trait(::HIR::ItemPath p, ::HIR::Trait& item)
{
    auto _ = this->m_resolve.set_impl_generics(item.m_params);
    ::HIR::Visitor::visit_trait(p, item);
}
void MIR::OuterVisitor::visit_type_impl(::HIR::TypeImpl& impl)
{
    auto _ = this->m_resolve.set_impl_generics(impl.m_params);
    ::HIR::Visitor::visit_type_impl(impl);
}
void MIR::OuterVisitor::visit_trait_impl(const ::HIR::SimplePath& trait_path, ::HIR::TraitImpl& impl)
{
    auto _ = this->m_resolve.set_impl_generics(impl.m_params);
    ::HIR::Visitor::visit_trait_impl(trait_path, impl);
}