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

Forbid to reuse builtin functions' name for other symbols

parent 1209cded
No related branches found
No related tags found
1 merge request!82Feature/builtin function polymorphism
......@@ -22,11 +22,19 @@ ASTSymbolTableBuilder::buildSymbolTable(ASTNode& n, std::shared_ptr<SymbolTable>
n.m_symbol_table = local_symbol_table;
const std::string& symbol = n.children[0]->string();
if (symbol_table->getBuiltinFunctionSymbolList(symbol, n.children[0]->begin()).size() > 0) {
std::ostringstream error_message;
error_message << "symbol '" << rang::fg::red << symbol << rang::fg::reset
<< "' already denotes a builtin function!";
throw ParseError(error_message.str(), std::vector{n.children[0]->begin()});
}
auto [i_symbol, success] = symbol_table->add(symbol, n.children[0]->begin());
if (not success) {
std::ostringstream error_message;
error_message << "symbol '" << rang::fg::red << symbol << rang::fg::reset << "' was already defined!";
throw ParseError(error_message.str(), std::vector{n.begin()});
throw ParseError(error_message.str(), std::vector{n.children[0]->begin()});
}
for (auto& child : n.children) {
......@@ -42,6 +50,13 @@ ASTSymbolTableBuilder::buildSymbolTable(ASTNode& n, std::shared_ptr<SymbolTable>
if (n.has_content()) {
if (n.is_type<language::var_declaration>()) {
auto register_symbol = [&](const ASTNode& argument_node) {
if (symbol_table->getBuiltinFunctionSymbolList(argument_node.string(), argument_node.begin()).size() > 0) {
std::ostringstream error_message;
error_message << "symbol '" << rang::fg::red << argument_node.string() << rang::fg::reset
<< "' already denotes a builtin function!";
throw ParseError(error_message.str(), std::vector{argument_node.begin()});
}
auto [i_symbol, success] = symbol_table->add(argument_node.string(), argument_node.begin());
if (not success) {
std::ostringstream error_message;
......@@ -61,6 +76,13 @@ ASTSymbolTableBuilder::buildSymbolTable(ASTNode& n, std::shared_ptr<SymbolTable>
}
} else if (n.is_type<language::function_definition>()) {
auto register_and_initialize_symbol = [&](const ASTNode& argument_node) {
if (symbol_table->getBuiltinFunctionSymbolList(argument_node.string(), argument_node.begin()).size() > 0) {
std::ostringstream error_message;
error_message << "symbol '" << rang::fg::red << argument_node.string() << rang::fg::reset
<< "' already denotes a builtin function!";
throw ParseError(error_message.str(), std::vector{argument_node.begin()});
}
auto [i_symbol, success] = symbol_table->add(argument_node.string(), argument_node.begin());
if (not success) {
std::ostringstream error_message;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment