aboutsummaryrefslogtreecommitdiffstats
path: root/c_compiler/src/declaration.cpp
blob: 0f125b0cee78de026d803335fd1e74c50adb6526 (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
#include "ast.hpp"


// Declaration definition

Declaration::Declaration(const std::string& _id)
    : id(_id)
{}

void Declaration::print() const
{
    if(next_decl != nullptr)
	next_decl->print();
    
    if(id != "")
	std::cout << id << std::endl;
}

void Declaration::printxml() const
{    
    if(next_decl != nullptr)
	next_decl->printxml();

    if(list_next_decl != nullptr) {
	list_next_decl->printxml();
    }

    if(id != "")
	std::cout << "<Variable id=\""<< id << "\" />" << std::endl;
}

void Declaration::printasm(VariableStackBindings bindings, int32_t& var_count) const
{
    if(init == nullptr)
	std::cout << "\t.comm\t" << id << ",4,4" << std::endl;
    else {
	std::cout << "\t.data\n\t.globl\t" << id << std::endl;
	std::cout << id << ":\n\t.word\t" << std::endl;
    }
}

void Declaration::addDeclaration(Declaration* _next_decl)
{
    next_decl = _next_decl;
}

void Declaration::addList(Declaration* _next_decl)
{
    list_next_decl = _next_decl;
}

void Declaration::setType(Type* _type)
{
    type = _type;
}

Declaration* Declaration::getNext() const
{
    return next_decl;
}

Declaration* Declaration::getNextListItem() const
{
    return list_next_decl;
}

std::string Declaration::getId() const
{
    return id;
}

std::string Declaration::getType() const
{
    return type->getType();
}