summaryrefslogtreecommitdiff
path: root/src/convert/render.cpp
blob: 7f65945a324780f2a42f5e02d46184061bf19a8a (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
/*
 */
#include "../common.hpp"
#include "../ast/ast.hpp"
#include <iostream>

typedef ::std::vector< ::std::pair< ::std::string, TypeRef> >	item_vec_t;

void Render_Type(::std::ostream& os, const TypeRef& type, const char *name)
{
    /*
    switch(type.class())
    {
    case TYPECLASS_STRUCT:
        os << "struct " << type.struct().mangled_name() << " " << name;
        break;
    }
    */
}

void Render_CStruct(::std::ostream& os, const AST::CStruct& str)
{
    os << "struct " << str.name() << "{\n";
    FOREACH(item_vec_t, f, str.fields())
    {
        os << "\t";
        Render_Type(os, f->second, f->first.c_str());
        os << ";\n";
    }
    os << "}\n";
}

void Render_Crate(::std::ostream& os, const AST::Flat& crate)
{
    // First off, print forward declarations of all structs + enums
    FOREACH(::std::vector<AST::CStruct>, s, crate.structs())
        os << "struct " << s->mangled_name() << ";\n";

    FOREACH(::std::vector<AST::Function>, fcn, crate.functions())
    {
        Render_Type(os, fcn->rettype(), nullptr);
        os << " " << fcn->name() << "(";
        bool is_first = true;
        FOREACH(item_vec_t, f, fcn->args())
        {
            if( !is_first )
                os << ", ";
            is_first = false;
            Render_Type(os, f->second, f->first.c_str());
        }
        os << ")\n{\n";
        // Dump expression AST
        os << "}\n";
    }
}