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


// Function definition

Function::Function(const std::string& _id, Declaration* _parameter_list, Statement* _statement)
    : id(_id), parameter_list(_parameter_list), statement(_statement)
{}

void Function::print() const
{
    std::cout << id << std::endl;
    
    if(parameter_list != nullptr)
	parameter_list->print();
    
    if(statement != nullptr)
	statement->print();
}

void Function::printxml() const
{
    std::cout << "<Function id=\"" << id << "\">" << std::endl;

    Declaration* parameter = parameter_list;
    std::vector<std::string> parameter_vec;
    
    while(parameter != nullptr) {
	if(parameter->getId() != "")
	    parameter_vec.push_back(parameter->getId());
	parameter = parameter->getNext();
    }

    for(std::vector<std::string>::reverse_iterator itr = parameter_vec.rbegin();
	itr != parameter_vec.rend(); ++itr) {
	
	std::cout << "<Parameter id=\"" << *itr << "\" />" << std::endl;	
    }
    
    if(statement != nullptr)
	statement->printxml();

    std::cout << "</Function>" << std::endl;
}

void Function::printasm() const
{}