Line data Source code
1 : #include "../../../inc/tables/functionTable/functionTable.h"
2 :
3 : namespace nicole {
4 :
5 : std::vector<Function>
6 0 : FunctionTable::getFunctions(const std::string &id) const noexcept {
7 0 : if (table_.count(id)) {
8 0 : return table_.at(id);
9 0 : }
10 0 : return {};
11 0 : }
12 :
13 0 : void FunctionTable::insert(const Function &function) noexcept {
14 0 : table_[function.id()].push_back(function);
15 0 : }
16 :
17 0 : void FunctionTable::print() const noexcept {
18 0 : std::cout << "Functions:\n";
19 0 : for (const auto &functions : table_) {
20 0 : for (const auto &function : functions.second) {
21 0 : std::cout << function.id() << "\n";
22 0 : }
23 0 : }
24 0 : }
25 :
26 : std::expected<std::monostate, Error>
27 : FunctionTable::setFuncReturnType(const std::string &id,
28 0 : const std::shared_ptr<Type> &type) noexcept {
29 : // Comprobar que existe alguna función con ese id.
30 0 : if (table_.find(id) == table_.end() || table_.at(id).empty()) {
31 0 : return createError(ERROR_TYPE::FUNCTION, "Function not found: " + id);
32 0 : }
33 : // Actualizamos la última función insertada con ese id.
34 0 : table_[id].back().setReturnType(type);
35 0 : return std::expected<std::monostate, Error>{std::monostate{}};
36 0 : }
37 :
38 : std::expected<std::monostate, Error>
39 : FunctionTable::setFuncParameters(const std::string &id,
40 0 : const Parameters &type) noexcept {
41 : // Comprobar que existe alguna función con ese id.
42 0 : if (table_.find(id) == table_.end() || table_.at(id).empty()) {
43 0 : return createError(ERROR_TYPE::FUNCTION, "Function not found: " + id);
44 0 : }
45 : // Actualizamos los parámetros de la última función insertada con ese id.
46 : // Se asume que el setter de parámetros acepta un std::shared_ptr<Type>.
47 0 : table_[id].back().setParameters(type);
48 0 : return std::expected<std::monostate, Error>{std::monostate{}};
49 0 : }
50 :
51 : std::expected<std::string, Error>
52 0 : FunctionTable::nameMangling(const Function &type) const noexcept {
53 0 : std::string result{"$"};
54 0 : return nameManglingImpl(type, result);
55 0 : }
56 :
57 : std::expected<std::string, Error>
58 : FunctionTable::nameManglingImpl(const Function &type,
59 0 : std::string &result) const noexcept {
60 0 : if (type.returnType()) {
61 0 : }
62 0 : return result;
63 0 : }
64 :
65 : } // namespace nicole
|