From f2209c9d6952fcd970f718e4d85cb5ae2ddd33fc Mon Sep 17 00:00:00 2001 From: tengtengh Date: Tue, 26 Aug 2025 10:12:58 +0800 Subject: [PATCH] Cherry-pick sourceFileId bugFix to 0728 branch Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICVD5B Signed-off-by: tengtengh --- ets2panda/compiler/core/ETSemitter.cpp | 25 +++++++++++++++++-------- ets2panda/compiler/core/ETSemitter.h | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index 1151febda8..bc50bf4253 100644 --- a/ets2panda/compiler/core/ETSemitter.cpp +++ b/ets2panda/compiler/core/ETSemitter.cpp @@ -242,16 +242,9 @@ void FilterForSimultaneous(varbinder::ETSBinder *varbinder) functions.end()); } -void ETSEmitter::GenAnnotation() +void ETSEmitter::GenRecords(varbinder::RecordTable *globalRecordTable) { - Program()->lang = EXTENSION; auto *varbinder = static_cast(Context()->parserProgram->VarBinder()); - - if (Context()->config->options->GetCompilationMode() == CompilationMode::GEN_ABC_FOR_EXTERNAL_SOURCE) { - FilterForSimultaneous(varbinder); - } - - auto *globalRecordTable = varbinder->GetGlobalRecordTable(); auto baseName = varbinder->GetRecordTable()->RecordName().Mutf8(); for (auto *annoDecl : globalRecordTable->AnnotationDeclarations()) { std::string newBaseName = util::NameMangler::GetInstance()->CreateMangledNameForAnnotation( @@ -266,6 +259,19 @@ void ETSEmitter::GenAnnotation() for (auto *interfaceDecl : globalRecordTable->InterfaceDeclarations()) { GenInterfaceRecord(interfaceDecl, interfaceDecl->IsDeclare()); } +} + +void ETSEmitter::GenAnnotation() +{ + Program()->lang = EXTENSION; + auto *varbinder = static_cast(Context()->parserProgram->VarBinder()); + + if (Context()->config->options->GetCompilationMode() == CompilationMode::GEN_ABC_FOR_EXTERNAL_SOURCE) { + FilterForSimultaneous(varbinder); + } + + auto *globalRecordTable = varbinder->GetGlobalRecordTable(); + GenRecords(globalRecordTable); for (auto *signature : globalRecordTable->Signatures()) { auto *scriptFunc = signature->Node()->AsScriptFunction(); @@ -281,12 +287,15 @@ void ETSEmitter::GenAnnotation() Program()->AddToFunctionTable(std::move(func)); } + auto *saveProgram = varbinder->Program(); for (auto [extProg, recordTable] : varbinder->GetExternalRecordTable()) { if (recordTable == varbinder->GetRecordTable()) { continue; } + varbinder->SetProgram(extProg); GenExternalRecord(recordTable, extProg); } + varbinder->SetProgram(saveProgram); const auto *checker = static_cast(Context()->GetChecker()); diff --git a/ets2panda/compiler/core/ETSemitter.h b/ets2panda/compiler/core/ETSemitter.h index 084964321b..b56743c8ce 100644 --- a/ets2panda/compiler/core/ETSemitter.h +++ b/ets2panda/compiler/core/ETSemitter.h @@ -85,6 +85,7 @@ public: private: using DynamicCallNamesMap = ArenaMap, uint32_t>; + void GenRecords(varbinder::RecordTable *globalRecordTable); void GenExternalRecord(varbinder::RecordTable *recordTable, const parser::Program *extProg); void GenGlobalArrayRecord(const checker::ETSArrayType *arrayType, checker::Signature *signature); std::vector GenAnnotations(const ir::ClassDefinition *classDef); -- Gitee