13af6ab5fSopenharmony_ci/*
23af6ab5fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License.
53af6ab5fSopenharmony_ci * You may obtain a copy of the License at
63af6ab5fSopenharmony_ci *
73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
83af6ab5fSopenharmony_ci *
93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and
133af6ab5fSopenharmony_ci * limitations under the License.
143af6ab5fSopenharmony_ci */
153af6ab5fSopenharmony_ci
163af6ab5fSopenharmony_ci#ifndef ES2PANDA_EVALUATE_DEBUG_INFO_DESERIALIZER_H
173af6ab5fSopenharmony_ci#define ES2PANDA_EVALUATE_DEBUG_INFO_DESERIALIZER_H
183af6ab5fSopenharmony_ci
193af6ab5fSopenharmony_ci#include "libpandabase/utils/arena_containers.h"
203af6ab5fSopenharmony_ci#include "libpandafile/debug_info_extractor.h"
213af6ab5fSopenharmony_ci#include "libpandafile/file.h"
223af6ab5fSopenharmony_ci
233af6ab5fSopenharmony_cinamespace ark::es2panda::varbinder {
243af6ab5fSopenharmony_ciclass Variable;
253af6ab5fSopenharmony_ci}  // namespace ark::es2panda::varbinder
263af6ab5fSopenharmony_ci
273af6ab5fSopenharmony_cinamespace ark::es2panda::parser {
283af6ab5fSopenharmony_ciclass Program;
293af6ab5fSopenharmony_ci}  // namespace ark::es2panda::parser
303af6ab5fSopenharmony_ci
313af6ab5fSopenharmony_cinamespace ark::es2panda::ir {
323af6ab5fSopenharmony_ciclass ETSTypeReference;
333af6ab5fSopenharmony_ci}  // namespace ark::es2panda::ir
343af6ab5fSopenharmony_ci
353af6ab5fSopenharmony_cinamespace ark::panda_file {
363af6ab5fSopenharmony_ciclass ClassDataAccessor;
373af6ab5fSopenharmony_ci}  // namespace ark::panda_file
383af6ab5fSopenharmony_ci
393af6ab5fSopenharmony_cinamespace ark::es2panda::evaluate {
403af6ab5fSopenharmony_ci
413af6ab5fSopenharmony_cistruct ChainEntryInfo;
423af6ab5fSopenharmony_cistruct FileDebugInfo;
433af6ab5fSopenharmony_ciclass ScopedDebugInfoPlugin;
443af6ab5fSopenharmony_ci
453af6ab5fSopenharmony_ciclass DebugInfoDeserializer final {
463af6ab5fSopenharmony_cipublic:
473af6ab5fSopenharmony_ci    using RegisterNumber = int32_t;
483af6ab5fSopenharmony_ci
493af6ab5fSopenharmony_cipublic:
503af6ab5fSopenharmony_ci    NO_COPY_SEMANTIC(DebugInfoDeserializer);
513af6ab5fSopenharmony_ci    NO_MOVE_SEMANTIC(DebugInfoDeserializer);
523af6ab5fSopenharmony_ci
533af6ab5fSopenharmony_ci    explicit DebugInfoDeserializer(ScopedDebugInfoPlugin &debugInfoPlugin);
543af6ab5fSopenharmony_ci    ~DebugInfoDeserializer() = default;
553af6ab5fSopenharmony_ci
563af6ab5fSopenharmony_ci    varbinder::Variable *CreateIrClass(panda_file::File::EntityId classId, parser::Program *classProgram,
573af6ab5fSopenharmony_ci                                       util::StringView pathToSource, util::StringView classDeclName);
583af6ab5fSopenharmony_ci
593af6ab5fSopenharmony_ci    varbinder::Variable *CreateIrLocalVariable(ir::Identifier *ident,
603af6ab5fSopenharmony_ci                                               const panda_file::LocalVariableTable &localVariableTable,
613af6ab5fSopenharmony_ci                                               size_t bytecodeOffset);
623af6ab5fSopenharmony_ci
633af6ab5fSopenharmony_ci    varbinder::Variable *CreateIrGlobalVariable(parser::Program *program, util::StringView pathToSource,
643af6ab5fSopenharmony_ci                                                util::StringView varDeclName);
653af6ab5fSopenharmony_ci
663af6ab5fSopenharmony_ci    varbinder::Variable *CreateIrGlobalMethods(ArenaVector<ir::AstNode *> &createdMethods, parser::Program *program,
673af6ab5fSopenharmony_ci                                               util::StringView pathToSource, util::StringView methodDeclName);
683af6ab5fSopenharmony_ci
693af6ab5fSopenharmony_ciprivate:
703af6ab5fSopenharmony_ci    // Methods for resolving inheritance.
713af6ab5fSopenharmony_ci    ir::ETSTypeReference *GetSuperClass(panda_file::ClassDataAccessor &cda);
723af6ab5fSopenharmony_ci
733af6ab5fSopenharmony_ci    /**
743af6ab5fSopenharmony_ci     * @brief Creates and checks all entries in inheritance chain.
753af6ab5fSopenharmony_ci     * @returns TypeReference to the last super class in resolved chain.
763af6ab5fSopenharmony_ci     */
773af6ab5fSopenharmony_ci    ir::ETSTypeReference *ResolveInheritanceChain(util::StringView abcSuperName, FileDebugInfo *debugInfo);
783af6ab5fSopenharmony_ci
793af6ab5fSopenharmony_ci    ir::ETSTypeReference *ResolveInheritanceChainImpl(util::StringView abcSuperName, FileDebugInfo *debugInfo);
803af6ab5fSopenharmony_ci
813af6ab5fSopenharmony_ci    /**
823af6ab5fSopenharmony_ci     * @brief Fills information required for inheritance chain recreation.
833af6ab5fSopenharmony_ci     * @returns declaration name of the first already created class in chain,
843af6ab5fSopenharmony_ci     * empty string if algorithm has reached std.core.Object.
853af6ab5fSopenharmony_ci     */
863af6ab5fSopenharmony_ci    util::StringView CollectChainInfo(ArenaVector<ChainEntryInfo> &chainEntryList, util::StringView abcSuperName,
873af6ab5fSopenharmony_ci                                      FileDebugInfo *debugInfo);
883af6ab5fSopenharmony_ci
893af6ab5fSopenharmony_ci    varbinder::Variable *CreateLocalVarDecl(ir::Identifier *ident, RegisterNumber regNumber,
903af6ab5fSopenharmony_ci                                            const std::string &typeSignature);
913af6ab5fSopenharmony_ci
923af6ab5fSopenharmony_ci    ir::ClassDeclaration *CreateClassDeclaration(util::StringView identName, panda_file::ClassDataAccessor &cda,
933af6ab5fSopenharmony_ci                                                 ir::ETSTypeReference *superClass, parser::Program *program);
943af6ab5fSopenharmony_ci
953af6ab5fSopenharmony_ciprivate:
963af6ab5fSopenharmony_ci    ScopedDebugInfoPlugin &debugInfoPlugin_;
973af6ab5fSopenharmony_ci};
983af6ab5fSopenharmony_ci
993af6ab5fSopenharmony_ci}  // namespace ark::es2panda::evaluate
1003af6ab5fSopenharmony_ci
1013af6ab5fSopenharmony_ci#endif  // ES2PANDA_EVALUATE_DEBUG_INFO_DESERIALIZER_H
102