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

Use utils/Exceptions and get rid of direct std::runtime_error

parent 9f47cbb0
No related branches found
No related tags found
1 merge request!37Feature/language
...@@ -2,16 +2,15 @@ ...@@ -2,16 +2,15 @@
#define BUILTIN_FUNCTION_EMBEDDER_HPP #define BUILTIN_FUNCTION_EMBEDDER_HPP
#include <language/ASTNodeDataType.hpp> #include <language/ASTNodeDataType.hpp>
#include <language/DataHandler.hpp> #include <language/DataHandler.hpp>
#include <language/DataVariant.hpp> #include <language/DataVariant.hpp>
#include <language/FunctionTable.hpp> #include <language/FunctionTable.hpp>
#include <utils/Demangle.hpp> #include <utils/Demangle.hpp>
#include <utils/Exceptions.hpp>
#include <utils/PugsTraits.hpp> #include <utils/PugsTraits.hpp>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <sstream>
#include <vector> #include <vector>
template <typename T> template <typename T>
...@@ -70,21 +69,19 @@ class BuiltinFunctionEmbedder : public IBuiltinFunctionEmbedder ...@@ -70,21 +69,19 @@ class BuiltinFunctionEmbedder : public IBuiltinFunctionEmbedder
auto data_handler = static_cast<const DataHandler<typename Ti_Type::element_type>&>(v_i.get()); auto data_handler = static_cast<const DataHandler<typename Ti_Type::element_type>&>(v_i.get());
std::get<I>(t) = data_handler.data_ptr(); std::get<I>(t) = data_handler.data_ptr();
} else { } else {
throw std::runtime_error("unexpected argument types while casting: expecting EmbeddedData"); throw UnexpectedError("unexpected argument types while casting: expecting EmbeddedData");
} }
} else if constexpr (std::is_same_v<Ti_Type, FunctionId>) { } else if constexpr (std::is_same_v<Ti_Type, FunctionId>) {
if constexpr (std::is_same_v<Vi_Type, uint64_t>) { if constexpr (std::is_same_v<Vi_Type, uint64_t>) {
std::get<I>(t) = FunctionId{v_i}; std::get<I>(t) = FunctionId{v_i};
throw std::runtime_error( throw NotImplementedError(
"WIP: should get better descriptor, FunctionId should at least refer to the symbol table."); "Should get better descriptor, FunctionId should at least refer to the symbol table.");
} else { } else {
throw std::runtime_error("unexpected argument types while casting: expecting uint64"); throw UnexpectedError("unexpected argument types while casting: expecting uint64");
} }
} else { } else {
std::ostringstream os; throw UnexpectedError("Unexpected argument types while casting " + demangle<Vi_Type>() + " -> " +
os << "unexpected argument types while casting " << demangle<Vi_Type>() << " -> " << demangle<Ti_Type>() demangle<Ti_Type>());
<< std::ends;
throw std::runtime_error(os.str());
} }
}, },
v[I]); v[I]);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <language/BuiltinFunctionEmbedder.hpp> #include <language/BuiltinFunctionEmbedder.hpp>
#include <language/TypeDescriptor.hpp> #include <language/TypeDescriptor.hpp>
#include <utils/Exceptions.hpp>
#include <iostream> #include <iostream>
...@@ -11,22 +12,16 @@ BuiltinModule::_addBuiltinFunction(const std::string& name, ...@@ -11,22 +12,16 @@ BuiltinModule::_addBuiltinFunction(const std::string& name,
{ {
auto [i_builtin_function, success] = auto [i_builtin_function, success] =
m_name_builtin_function_map.insert(std::make_pair(name, builtin_function_embedder)); m_name_builtin_function_map.insert(std::make_pair(name, builtin_function_embedder));
// LCOV_EXCL_START
if (not success) { if (not success) {
std::cerr << "builtin-function '" << name << "' cannot be added!\n"; throw NormalError("builtin-function '" + name + "' cannot be added!\n");
std::exit(1);
} }
// LCOV_EXCL_STOP
} }
void void
BuiltinModule::_addTypeDescriptor(std::shared_ptr<TypeDescriptor> type_descriptor) BuiltinModule::_addTypeDescriptor(std::shared_ptr<TypeDescriptor> type_descriptor)
{ {
auto [i_type, success] = m_name_type_map.insert(std::make_pair(type_descriptor->name(), type_descriptor)); auto [i_type, success] = m_name_type_map.insert(std::make_pair(type_descriptor->name(), type_descriptor));
// LCOV_EXCL_START
if (not success) { if (not success) {
std::cerr << "type '" << type_descriptor->name() << "' cannot be added!\n"; throw NormalError("type '" + type_descriptor->name() + "' cannot be added!\n");
std::exit(1);
} }
// LCOV_EXCL_STOP
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <mesh/Connectivity.hpp> #include <mesh/Connectivity.hpp>
#include <mesh/GmshReader.hpp> #include <mesh/GmshReader.hpp>
#include <mesh/Mesh.hpp> #include <mesh/Mesh.hpp>
#include <utils/Exceptions.hpp>
#include <output/VTKWriter.hpp> #include <output/VTKWriter.hpp>
...@@ -39,11 +40,11 @@ MeshModule::MeshModule() ...@@ -39,11 +40,11 @@ MeshModule::MeshModule()
[](std::shared_ptr<IMesh> p_mesh, FunctionId function_id) -> std::shared_ptr<IMesh> { [](std::shared_ptr<IMesh> p_mesh, FunctionId function_id) -> std::shared_ptr<IMesh> {
switch (p_mesh->dimension()) { switch (p_mesh->dimension()) {
case 1: { case 1: {
throw std::runtime_error("not implemented in 1d"); throw NotImplementedError("not implemented in 1d");
break; break;
} }
case 2: { case 2: {
throw std::runtime_error("not implemented in 2d"); throw NotImplementedError("not implemented in 2d");
break; break;
} }
case 3: { case 3: {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <language/ASTSymbolTableBuilder.hpp> #include <language/ASTSymbolTableBuilder.hpp>
#include <language/PEGGrammar.hpp> #include <language/PEGGrammar.hpp>
#include <language/SymbolTable.hpp> #include <language/SymbolTable.hpp>
#include <utils/Exceptions.hpp>
#include <utils/PugsAssert.hpp> #include <utils/PugsAssert.hpp>
#include <pegtl/contrib/analyze.hpp> #include <pegtl/contrib/analyze.hpp>
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <sstream>
#include <unordered_map> #include <unordered_map>
#include <variant> #include <variant>
...@@ -83,12 +85,14 @@ parser(const std::string& filename) ...@@ -83,12 +85,14 @@ parser(const std::string& filename)
} }
catch (const parse_error& e) { catch (const parse_error& e) {
const auto p = e.positions.front(); const auto p = e.positions.front();
std::cerr << rang::style::bold << p.source << ':' << p.line << ':' << p.byte_in_line << ": " << rang::style::reset
<< rang::fgB::red << "error: " << rang::fg::reset << rang::style::bold << e.what() << rang::style::reset std::ostringstream os;
<< '\n' os << rang::style::bold << p.source << ':' << p.line << ':' << p.byte_in_line << ": " << rang::style::reset
<< rang::fgB::red << "error: " << rang::fg::reset << rang::style::bold << e.what() << rang::style::reset << '\n'
<< input.line_at(p) << '\n' << input.line_at(p) << '\n'
<< std::string(p.byte_in_line, ' ') << rang::fgB::yellow << '^' << rang::fg::reset << std::endl; << std::string(p.byte_in_line, ' ') << rang::fgB::yellow << '^' << rang::fg::reset;
std::exit(1);
throw RawError(os.str());
} }
std::cout << "Parsed: " << filename << '\n'; std::cout << "Parsed: " << filename << '\n';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment