Started implementation of function parsing
This commit is contained in:
57
function.cpp
Normal file
57
function.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "function.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct t_parameter {
|
||||
std::string name;
|
||||
uint32_t type;
|
||||
};
|
||||
|
||||
struct t_function {
|
||||
std::string name;
|
||||
uint32_t address;
|
||||
uint32_t type;
|
||||
std::vector<t_parameter> parameters;
|
||||
};
|
||||
|
||||
static std::vector<t_function> functions;
|
||||
static int current_function = -1;
|
||||
|
||||
const bool function_register(const std::string name, const uint32_t address) {
|
||||
for (auto f : functions) if (f.name == name) return false;
|
||||
functions.push_back({name, address});
|
||||
current_function = functions.size()-1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void function_set_type(const uint32_t type) {
|
||||
functions[current_function].type = type;
|
||||
}
|
||||
|
||||
const int function_get_type() {
|
||||
return functions[current_function].type;
|
||||
}
|
||||
|
||||
const bool function_parameter_add(const std::string name, const uint32_t type) {
|
||||
for (auto p : functions[current_function].parameters) if (p.name == name) return false;
|
||||
functions[current_function].parameters.push_back({name, type});
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool function_exists(const std::string name) {
|
||||
for (auto f : functions) if (f.name == name) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint32_t function_get_address(const std::string name) {
|
||||
for (auto f : functions) if (f.name == name) return f.address;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const int function_get_num_parameters() {
|
||||
return functions[current_function].parameters.size();
|
||||
}
|
||||
|
||||
const int function_get_parameter_type(const int index) {
|
||||
return functions[current_function].parameters[index].type;
|
||||
}
|
||||
Reference in New Issue
Block a user