diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index 1151febda86663cf246872e802c7f7cee77ad1ef..bc50bf42530185e9d9dbde8e93bd709affd12031 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 084964321b2986866214b96a02f85535201b31db..b56743c8ce004350369716c49546d16917671d11 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);