When a function is defined, set its symbol's position to the code position.

Before, if the function was declared before being defined, then the symbol's
SourcePos would be left set to the position of the declaration.  This ended
up getting the debugging symbols mixed up in this case, which was undesirable.
This commit is contained in:
Matt Pharr
2012-04-28 20:28:39 -07:00
parent a1a43cdfe0
commit c4b1d79c5c
2 changed files with 8 additions and 3 deletions

View File

@@ -792,11 +792,13 @@ void
Module::AddFunctionDefinition(const std::string &name, const FunctionType *type,
Stmt *code) {
Symbol *sym = symbolTable->LookupFunction(name.c_str(), type);
if (sym == NULL) {
if (sym == NULL || code == NULL) {
Assert(m->errorCount > 0);
return;
}
sym->pos = code->pos;
// FIXME: because we encode the parameter names in the function type,
// we need to override the function type here in case the function had
// earlier been declared with anonymous parameter names but is now

View File

@@ -1862,8 +1862,11 @@ function_definition
dynamic_cast<const FunctionType *>($2->type);
if (funcType == NULL)
Assert(m->errorCount > 0);
else
m->AddFunctionDefinition($2->name, funcType, $4);
else {
Stmt *code = $4;
if (code == NULL) code = new StmtList(@4);
m->AddFunctionDefinition($2->name, funcType, code);
}
}
m->symbolTable->PopScope(); // push in lAddFunctionParams();
}