From c4b1d79c5c25345ea6c696ff56c88e8612f08ac5 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Sat, 28 Apr 2012 20:28:39 -0700 Subject: [PATCH] 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. --- module.cpp | 4 +++- parse.yy | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/module.cpp b/module.cpp index 436791e6..17df7b86 100644 --- a/module.cpp +++ b/module.cpp @@ -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 diff --git a/parse.yy b/parse.yy index c4db2fa9..f7a468ad 100644 --- a/parse.yy +++ b/parse.yy @@ -1862,8 +1862,11 @@ function_definition dynamic_cast($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(); }