Skip to content
Permalink
Browse files

Aul: Always reset the current function when a declaration ends (#1839)

When an error occurred during codegen of a function, the current
function pointer would not be reset to 0, leading to spurious warnings
about redeclaration of functions.
  • Loading branch information
isilkor committed Nov 3, 2016
1 parent 072e1dc commit ff0325dfaca029f7d0e66c3dc38e5aecd10a67ee
Showing with 22 additions and 4 deletions.
  1. +22 −4 src/script/C4AulCompiler.cpp
@@ -500,9 +500,16 @@ void C4AulCompiler::PreparseAstVisitor::visit(const ::aul::ast::FunctionDecl *n)
Fn->SetOverloaded(parent_func);
Parent->SetPropertyByS(Fn->Name, C4VFunction(Fn));

try
{
DefaultRecursiveVisitor::visit(n);

Fn = nullptr;
Fn = nullptr;
}
catch (...)
{
Fn = nullptr;
throw;
}
}

void C4AulCompiler::PreparseAstVisitor::visit(const ::aul::ast::CallExpr *n)
@@ -1551,6 +1558,10 @@ void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::VarDecl *n)

void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::FunctionDecl *n)
{
assert(!Fn && "CodegenAstVisitor: function declaration encountered within active function");
if (Fn)
throw Error(target_host, host, n, Fn, "internal error: function declaration for '%s' encountered within active function", n->name.c_str());

C4PropListStatic *Parent = n->is_global ? target_host->Engine->GetPropList() : target_host->GetPropList();

C4String *name = ::Strings.FindString(n->name.c_str());
@@ -1585,9 +1596,16 @@ void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::FunctionDecl *n)
Fn->SetOverloaded(global_parent);
}

try
{
EmitFunctionCode(n);

Fn = nullptr;
Fn = nullptr;
}
catch (...)
{
Fn = nullptr;
throw;
}
}

void C4AulCompiler::CodegenAstVisitor::visit(const::aul::ast::FunctionExpr * n)

0 comments on commit ff0325d

Please sign in to comment.
You can’t perform that action at this time.