From fa1d8c2e84d45097f177f27df35ed2a84f8d9a79 Mon Sep 17 00:00:00 2001 From: Orlovsky Maxim Date: Fri, 19 Jul 2024 17:07:19 +0300 Subject: [PATCH] Title: Code check warnings ets2panda/compiler/core/emitter Description: Need to fix codecheck in ets2panda/compiler/core/emitter Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IAEAO3 Testing: ninja es2panda_tests Signed-off-by: Orlovsky Maxim --- ets2panda/compiler/core/emitter.cpp | 60 +++++++++++++++------------- ets2panda/compiler/core/emitter.h | 2 + ets2panda/es2panda.cpp | 1 - ets2panda/ir/base/methodDefinition.h | 3 +- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/ets2panda/compiler/core/emitter.cpp b/ets2panda/compiler/core/emitter.cpp index 8baf0c7432..7c6a71d131 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 b952a719d3..48717db674 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 6c42b535d4..f217db0a8f 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 50f23a6528..e186c32328 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 -- Gitee