summaryrefslogtreecommitdiff
path: root/src/convert/resolve.cpp
blob: edc649ccffcf7e9e97fe88f0a9ab58fe9c24d2b9 (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
/*
 */
#include "../common.hpp"
#include "../ast/ast.hpp"
#include "../parse/parseerror.hpp"

class CPathResolver
{
    const AST::Crate&   m_crate;
    const AST::Module&  m_module;
    
public:
    CPathResolver(const AST::Crate& crate, const AST::Module& mod);
    
    void resolve_type(TypeRef& type);
    
    void handle_function(AST::Function& fcn);
};

// Path resolution checking
void ResolvePaths(AST::Crate& crate);

class CResolvePaths_NodeVisitor:
    public AST::NodeVisitor
{
    const CPathResolver&    m_res;
public:
    CResolvePaths_NodeVisitor(const CPathResolver& res):
        m_res(res)
    {
    }

    void visit(AST::ExprNode_NamedValue& node) {
        // TODO: Convert into a real absolute path
        throw ParseError::Todo("CResolvePaths_NodeVisitor::visit(TagNamedValue)");
    }
};

CPathResolver::CPathResolver(const AST::Crate& crate, const AST::Module& mod):
    m_crate(crate),
    m_module(mod)
{
}

void CPathResolver::resolve_type(TypeRef& type)
{
    // TODO: Convert type into absolute
    throw ParseError::Todo("ResolvePaths_Type");
}

void CPathResolver::handle_function(AST::Function& fcn)
{
    CResolvePaths_NodeVisitor   node_visitor(*this);
    
    fcn.code().visit_nodes( node_visitor );

    resolve_type(fcn.rettype());

    FOREACH_M(AST::Function::Arglist, arg, fcn.args())
    {
        resolve_type(arg->second);
    }
}

void ResolvePaths_HandleFunction(const AST::Crate& crate, const AST::Module& mod, AST::Function& fcn)
{
	CPathResolver	pr(crate, mod);
	pr.handle_function(fcn);
}

void ResolvePaths(AST::Crate& crate)
{
    crate.iterate_functions(ResolvePaths_HandleFunction);
}