From a491eb0f39f3443cd34871aabe379cc9ea958965 Mon Sep 17 00:00:00 2001 From: Zelentsov Dmitry Date: Thu, 25 Jul 2024 11:15:14 +0300 Subject: [PATCH] Move identifier resolving to lowering Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IAFDDS?from=project-issue Tests: Test-u-runner and CI Signed-off-by: Zelentsov Dmitry --- ets2panda/BUILD.gn | 1 + ets2panda/CMakeLists.txt | 1 + ets2panda/checker/ETSchecker.cpp | 14 +----- ets2panda/compiler/lowering/phase.cpp | 12 ++--- .../compiler/lowering/resolveIdentifiers.cpp | 45 +++++++++++++++++++ .../compiler/lowering/resolveIdentifiers.h | 33 ++++++++++++++ 6 files changed, 84 insertions(+), 22 deletions(-) create mode 100644 ets2panda/compiler/lowering/resolveIdentifiers.cpp create mode 100644 ets2panda/compiler/lowering/resolveIdentifiers.h diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 14a3b74899..7a4e8f8028 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -199,6 +199,7 @@ libes2panda_sources = [ "compiler/lowering/ets/unionLowering.cpp", "compiler/lowering/phase.cpp", "compiler/lowering/plugin_phase.cpp", + "compiler/lowering/resolveIdentifiers.cpp", "compiler/lowering/scopesInit/savedBindingsCtx.cpp", "compiler/lowering/scopesInit/scopesInitPhase.cpp", "compiler/lowering/util.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 270899a6b5..875d72c8b0 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -165,6 +165,7 @@ set(ES2PANDA_LIB_SRC compiler/lowering/scopesInit/scopesInitPhase.cpp compiler/lowering/phase.cpp compiler/lowering/plugin_phase.cpp + compiler/lowering/resolveIdentifiers.cpp compiler/lowering/util.cpp compiler/lowering/ets/topLevelStmts/importExportDecls.cpp compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp diff --git a/ets2panda/checker/ETSchecker.cpp b/ets2panda/checker/ETSchecker.cpp index 8556428fab..df65144b1d 100644 --- a/ets2panda/checker/ETSchecker.cpp +++ b/ets2panda/checker/ETSchecker.cpp @@ -138,26 +138,14 @@ void ETSChecker::InitializeBuiltin(varbinder::Variable *var, const util::StringV GetGlobalTypesHolder()->InitializeBuiltin(name, type); } -bool ETSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, const CompilerOptions &options) +bool ETSChecker::StartChecker(varbinder::VarBinder *varbinder, const CompilerOptions &options) { Initialize(varbinder); - if (options.dumpAst) { - std::cout << Program()->Dump() << std::endl; - } - - if (options.opDumpAstOnlySilent) { - Program()->DumpSilent(); - return false; - } - if (options.parseOnly) { return false; } - varbinder->SetGenStdLib(options.compilationMode == CompilationMode::GEN_STD_LIB); - varbinder->IdentifierAnalysis(); - auto *etsBinder = varbinder->AsETSBinder(); InitializeBuiltins(etsBinder); diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index 99fb42aae5..2767fef520 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -15,10 +15,10 @@ #include "phase.h" #include "checker/checker.h" -#include "compiler/core/ASTVerifier.h" #include "ets/ambientLowering.h" #include "ets/defaultParameterLowering.h" #include "lexer/token/sourceLocation.h" +#include "compiler/lowering/resolveIdentifiers.h" #include "compiler/lowering/checkerPhase.h" #include "compiler/lowering/ets/constStringToCharLowering.h" #include "compiler/lowering/ets/defaultParameterLowering.h" @@ -52,14 +52,7 @@ namespace ark::es2panda::compiler { static CheckerPhase g_checkerPhase; - -std::vector GetTrivialPhaseList() -{ - return std::vector { - &g_checkerPhase, - }; -} - +static ResolveIdentifiers g_resolveIdentifiers {}; static AmbientLowering g_ambientLowering; static BigIntLowering g_bigintLowering; static StringConstructorLowering g_stringConstructorLowering; @@ -117,6 +110,7 @@ std::vector GetETSPhaseList() &g_expressionLambdaConstructionPhase, &g_interfacePropDeclPhase, &g_enumLoweringPhase, + &g_resolveIdentifiers, &g_checkerPhase, &g_spreadConstructionPhase, &g_pluginsAfterCheck, diff --git a/ets2panda/compiler/lowering/resolveIdentifiers.cpp b/ets2panda/compiler/lowering/resolveIdentifiers.cpp new file mode 100644 index 0000000000..944c828acb --- /dev/null +++ b/ets2panda/compiler/lowering/resolveIdentifiers.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "resolveIdentifiers.h" + +#include "varbinder/ETSBinder.h" + +namespace ark::es2panda::compiler { +bool ResolveIdentifiers::Perform(public_lib::Context *ctx, [[maybe_unused]] parser::Program *program) +{ + auto const &options = ctx->config->options->CompilerOptions(); + auto *varbinder = ctx->parserProgram->VarBinder()->AsETSBinder(); + + if (options.dumpAst) { + std::cout << varbinder->Program()->Dump() << std::endl; + } + + if (options.opDumpAstOnlySilent) { + varbinder->Program()->DumpSilent(); + return false; + } + + if (options.parseOnly) { + return false; + } + + varbinder->SetGenStdLib(options.compilationMode == CompilationMode::GEN_STD_LIB); + varbinder->IdentifierAnalysis(); + + return true; +} + +} // namespace ark::es2panda::compiler diff --git a/ets2panda/compiler/lowering/resolveIdentifiers.h b/ets2panda/compiler/lowering/resolveIdentifiers.h new file mode 100644 index 0000000000..d7f97078bf --- /dev/null +++ b/ets2panda/compiler/lowering/resolveIdentifiers.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ES2PANDA_COMPILER_LOWERING_RESOLVE_IDENT_H +#define ES2PANDA_COMPILER_LOWERING_RESOLVE_IDENT_H + +#include "compiler/lowering/phase.h" + +namespace ark::es2panda::compiler { +class ResolveIdentifiers : public Phase { +public: + std::string_view Name() const override + { + return "ResolveIdentifiers"; + } + + bool Perform(public_lib::Context *ctx, parser::Program *program) override; +}; +} // namespace ark::es2panda::compiler + +#endif -- Gitee