diff --git a/ets2panda/compiler/core/emitter.cpp b/ets2panda/compiler/core/emitter.cpp index 8baf0c743215fa5be4e92f2f7da1c09e6a319c38..7c6a71d13170ff33d6f4a4eef8eaf35ae3aa4410 100644 --- a/ets2panda/compiler/core/emitter.cpp +++ b/ets2panda/compiler/core/emitter.cpp @@ -268,9 +268,10 @@ void FunctionEmitter::GenSourceFileDebugInfo(pandasm::Function *func) } static void GenLocalVariableInfo(pandasm::debuginfo::LocalVariable &variableDebug, varbinder::Variable *var, - uint32_t start, uint32_t varsLength, uint32_t totalRegsNum, - const ScriptExtension extension) + std::tuple info, const ScriptExtension extension) { + const auto [start, varsLength, totalRegsNum] = info; + variableDebug.name = var->Name().Mutf8(); if (extension == ScriptExtension::JS) { @@ -289,6 +290,35 @@ static void GenLocalVariableInfo(pandasm::debuginfo::LocalVariable &variableDebu variableDebug.length = static_cast(varsLength); } +void FunctionEmitter::GenScopeVariableInfoEnd(pandasm::Function *func, const varbinder::Scope *scope, uint32_t count, + uint32_t start) const +{ + const auto extension = cg_->VarBinder()->Program()->Extension(); + auto varsLength = static_cast(count - start + 1); + + if (scope->IsFunctionScope()) { + for (auto *param : scope->AsFunctionScope()->ParamScope()->Params()) { + auto &variableDebug = func->localVariableDebug.emplace_back(); + GenLocalVariableInfo(variableDebug, param, std::make_tuple(start, varsLength, cg_->TotalRegsNum()), + extension); + } + } + const auto &unsortedBindings = scope->Bindings(); + std::map bindings(unsortedBindings.begin(), + unsortedBindings.end()); + for (const auto &[_, variable] : bindings) { + (void)_; + if (!variable->IsLocalVariable() || variable->LexicalBound() || variable->Declaration()->IsParameterDecl() || + variable->Declaration()->IsTypeAliasDecl()) { + continue; + } + + auto &variableDebug = func->localVariableDebug.emplace_back(); + GenLocalVariableInfo(variableDebug, variable, std::make_tuple(start, varsLength, cg_->TotalRegsNum()), + extension); + } +} + void FunctionEmitter::GenScopeVariableInfo(pandasm::Function *func, const varbinder::Scope *scope) const { const auto *startIns = scope->ScopeStart(); @@ -297,35 +327,11 @@ void FunctionEmitter::GenScopeVariableInfo(pandasm::Function *func, const varbin uint32_t start = 0; uint32_t count = 0; - const auto extension = cg_->VarBinder()->Program()->Extension(); - for (const auto *it : cg_->Insns()) { if (startIns == it) { start = count; } else if (endIns == it) { - auto varsLength = static_cast(count - start + 1); - - if (scope->IsFunctionScope()) { - for (auto *param : scope->AsFunctionScope()->ParamScope()->Params()) { - auto &variableDebug = func->localVariableDebug.emplace_back(); - GenLocalVariableInfo(variableDebug, param, start, varsLength, cg_->TotalRegsNum(), extension); - } - } - const auto &unsortedBindings = scope->Bindings(); - std::map bindings(unsortedBindings.begin(), - unsortedBindings.end()); - for (const auto &[_, variable] : bindings) { - (void)_; - if (!variable->IsLocalVariable() || variable->LexicalBound() || - variable->Declaration()->IsParameterDecl() || variable->Declaration()->IsTypeAliasDecl()) { - continue; - } - - auto &variableDebug = func->localVariableDebug.emplace_back(); - GenLocalVariableInfo(variableDebug, variable, start, varsLength, cg_->TotalRegsNum(), extension); - } - - break; + GenScopeVariableInfoEnd(func, scope, count, start); } count++; diff --git a/ets2panda/compiler/core/emitter.h b/ets2panda/compiler/core/emitter.h index b952a719d30c4d0db855a580a73efed790b53e94..48717db674cad8eec36705da2d87c9c52bae1913 100644 --- a/ets2panda/compiler/core/emitter.h +++ b/ets2panda/compiler/core/emitter.h @@ -75,6 +75,8 @@ protected: void GenInstructionDebugInfo(const IRNode *ins, ark::pandasm::Ins *pandaIns); void GenFunctionInstructions(pandasm::Function *func); void GenScopeVariableInfo(pandasm::Function *func, const varbinder::Scope *scope) const; + void GenScopeVariableInfoEnd(pandasm::Function *func, const varbinder::Scope *scope, uint32_t count, + uint32_t start) const; void GenSourceFileDebugInfo(pandasm::Function *func); void GenFunctionCatchTables(ark::pandasm::Function *func); void GenVariablesDebugInfo(pandasm::Function *func); diff --git a/ets2panda/es2panda.cpp b/ets2panda/es2panda.cpp index 6c42b535d4d7449eafe5f3daa93587275bf80823..f217db0a8fdef248272bce9eb05827e06550b399 100644 --- a/ets2panda/es2panda.cpp +++ b/ets2panda/es2panda.cpp @@ -28,7 +28,6 @@ template T DirName(T const &path, T const &delims = ark::os::file::File::GetPathDelim()) { std::size_t pos = path.find_last_of(delims); - if (pos == std::string::npos) { return "./"; } diff --git a/ets2panda/ir/base/methodDefinition.h b/ets2panda/ir/base/methodDefinition.h index 50f23a652814df42b937108720589b8f4c620956..e186c323281a4e60243a9d4ddd877580d697a568 100644 --- a/ets2panda/ir/base/methodDefinition.h +++ b/ets2panda/ir/base/methodDefinition.h @@ -47,7 +47,8 @@ public: baseOverloadMethod_(nullptr), asyncPairMethod_(nullptr) { - ASSERT(key_ != nullptr && value_ != nullptr); + ASSERT(key_ != nullptr); + ASSERT(value != nullptr); } // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields