Skip to content

Commit

Permalink
fix(Parser): rollback when signature not found
Browse files Browse the repository at this point in the history
  • Loading branch information
berdal84 committed Apr 5, 2022
1 parent fe6563b commit c8c6197
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/core/src/Language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const IInvokable* Language::find_function(const Signature* _signature) const

const IInvokable* Language::find_operator_fct_exact(const Signature* _signature) const
{
if(!_signature)
{
return nullptr;
}

auto is_exactly = [&](const IInvokable* _invokable)
{
Expand All @@ -53,6 +57,10 @@ const IInvokable* Language::find_operator_fct_exact(const Signature* _signature)

const IInvokable* Language::find_operator_fct(const Signature* _signature) const
{
if(!_signature)
{
return nullptr;
}
auto exact = find_operator_fct_exact(_signature);
if( !exact) return find_operator_fct_fallback(_signature);
return exact;
Expand Down
26 changes: 19 additions & 7 deletions src/core/src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,18 @@ Member* Parser::parse_binary_operator_expression(unsigned short _precedence, Mem
component = binary_op->get<InvokableComponent>();
delete signature;
}
else
else if(signature)
{
// abstract operator
binary_op = m_graph->create_abstract_function(signature);
component = binary_op->get<InvokableComponent>();
}
else
{
LOG_VERBOSE("Parser", "parse binary operation expr... " KO " no signature\n")
rollback_transaction();
return nullptr;
}

component->set_source_token(operatorToken);
m_graph->connect(_left, component->get_l_handed_val());
Expand Down Expand Up @@ -339,29 +345,35 @@ Member* Parser::parse_unary_operator_expression(unsigned short _precedence)

if ( value == nullptr )
{
LOG_VERBOSE("Parser", "parseUnaryOperationExpression... " KO " (right expression is nullptr)\n")
rollback_transaction();
return nullptr;
}
LOG_VERBOSE("Parser", "parseUnaryOperationExpression... " KO " (right expression is nullptr)\n")
rollback_transaction();
return nullptr;
}

// Create a function signature

const Operator* ope = m_language->find_operator(operatorToken->m_word, Operator_t::Unary );
const Signature* sig = Signature::new_operator(R::MetaType::s_any, ope, value->get_meta_type());
const IInvokable* invokable = m_language->find_operator_fct(sig);

InvokableComponent* component;
InvokableComponent* component;
Node* node;

if (invokable)
{
node = m_graph->create_function(invokable);
delete sig;
}
else
else if(sig)
{
node = m_graph->create_abstract_function(sig);
}
else
{
LOG_VERBOSE("Parser", "parseUnaryOperationExpression... " KO " (no signature found)\n")
rollback_transaction();
return nullptr;
}

component = node->get<InvokableComponent>();
component->set_source_token(operatorToken);
Expand Down
10 changes: 10 additions & 0 deletions src/core/src/Signature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ const Signature* Signature::new_operator(
Meta_t _rtype
)
{
if(!_op)
{
return nullptr;
}

auto signature = new Signature(_op);
signature->set_return_type(_type);
signature->push_args(_ltype, _rtype);
Expand All @@ -137,6 +142,11 @@ const Signature* Signature::new_operator(
const Operator* _op,
Meta_t _ltype)
{
if(!_op)
{
return nullptr;
}

auto signature = new Signature(_op);
signature->set_return_type(_type);
signature->push_arg(_ltype);
Expand Down

0 comments on commit c8c6197

Please sign in to comment.