diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 14a3b74899ba38ec3d58bc74ee972a6d2b95b551..7a4e8f8028cfbd63da94ec97af845115fa192b2a 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 270899a6b50bbf9379e0c090245d70ead6b8e745..875d72c8b0a21169d476b25d27082bb065f65c0b 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 8556428fab368b58762f763e3be2ecde65e43204..df65144b1d9fe7fd74b501f8cc7c583cce9b18a1 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 99fb42aae557c4579432b0f1957483ffb742968c..2767fef52002d86edefdb111aa73753adb7a2c40 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 0000000000000000000000000000000000000000..944c828acbc383c329b187149e92de6bafc270b3 --- /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 0000000000000000000000000000000000000000..d7f97078bfc115cc868b5fd62914dde3713fd5dc --- /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