Skip to content
Snippets Groups Projects
Commit 30fd651e authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add the BuiltinModule base class in preparation to multiple modules

Now MathModule inherits from BuiltinModule and not directly from IModule

BuiltinModule defines filling mechanisms for concrete built-in modules
parent 854a4ddb
No related branches found
No related tags found
1 merge request!37Feature/language
#include <BuiltinModule.hpp>
#include <CFunctionEmbedder.hpp>
#include <iostream>
void
BuiltinModule::_addFunction(const std::string& name, std::shared_ptr<ICFunctionEmbedder> c_function_embedder)
{
auto [i_function, success] = m_name_cfunction_map.insert(std::make_pair(name, c_function_embedder));
// LCOV_EXCL_START
if (not success) {
std::cerr << "function " << name << " cannot be add!\n";
std::exit(1);
}
// LCOV_EXCL_STOP
}
#ifndef BUILTIN_MODULE_HPP
#define BUILTIN_MODULE_HPP
#include <PugsMacros.hpp>
#include <IModule.hpp>
class ICFunctionEmbedder;
class BuiltinModule : public IModule
{
protected:
NameCFunctionMap m_name_cfunction_map;
void _addFunction(const std::string& name, std::shared_ptr<ICFunctionEmbedder> c_function_embedder);
public:
const NameCFunctionMap&
getNameCFunctionsMap() const final
{
return m_name_cfunction_map;
}
BuiltinModule() = default;
~BuiltinModule() = default;
};
#endif // BUILTIN_MODULE_HPP
...@@ -31,6 +31,7 @@ add_library( ...@@ -31,6 +31,7 @@ add_library(
ASTPrinter.cpp ASTPrinter.cpp
ASTSymbolTableBuilder.cpp ASTSymbolTableBuilder.cpp
ASTSymbolInitializationChecker.cpp ASTSymbolInitializationChecker.cpp
BuiltinModule.cpp
MathModule.cpp MathModule.cpp
ModuleRepository.cpp ModuleRepository.cpp
PugsParser.cpp) PugsParser.cpp)
......
...@@ -2,20 +2,6 @@ ...@@ -2,20 +2,6 @@
#include <CFunctionEmbedder.hpp> #include <CFunctionEmbedder.hpp>
#include <iostream>
void
MathModule::_addFunction(const std::string& name, std::shared_ptr<ICFunctionEmbedder> c_function_embedder)
{
auto [i_function, success] = m_name_cfunction_map.insert(std::make_pair(name, c_function_embedder));
// LCOV_EXCL_START
if (not success) {
std::cerr << "function " << name << " cannot be add!\n";
std::exit(1);
}
// LCOV_EXCL_STOP
}
MathModule::MathModule() MathModule::MathModule()
{ {
this->_addFunction("sqrt", std::make_shared<CFunctionEmbedder<double, double>>( this->_addFunction("sqrt", std::make_shared<CFunctionEmbedder<double, double>>(
......
#ifndef MATH_MODULE_HPP #ifndef MATH_MODULE_HPP
#define MATH_MODULE_HPP #define MATH_MODULE_HPP
#include <IModule.hpp> #include <BuiltinModule.hpp>
class MathModule : public IModule class MathModule : public BuiltinModule
{ {
private:
NameCFunctionMap m_name_cfunction_map;
void _addFunction(const std::string& name, std::shared_ptr<ICFunctionEmbedder> c_function_embedder);
public: public:
std::string_view std::string_view
name() const final name() const final
...@@ -17,12 +12,6 @@ class MathModule : public IModule ...@@ -17,12 +12,6 @@ class MathModule : public IModule
return "math"; return "math";
} }
const NameCFunctionMap&
getNameCFunctionsMap() const final
{
return m_name_cfunction_map;
}
MathModule(); MathModule();
~MathModule() = default; ~MathModule() = default;
......
...@@ -48,8 +48,6 @@ ModuleRepository::populateSymbolTable(const ASTNode& module_name_node, SymbolTab ...@@ -48,8 +48,6 @@ ModuleRepository::populateSymbolTable(const ASTNode& module_name_node, SymbolTab
c_function_embedder_table.add(c_function); c_function_embedder_table.add(c_function);
} }
std::cout << "populating ...";
} else { } else {
throw parse_error(std::string{"could not find module "} + module_name, std::vector{module_name_node.begin()}); throw parse_error(std::string{"could not find module "} + module_name, std::vector{module_name_node.begin()});
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment