diff --git a/es2panda/util/hotfix.cpp b/es2panda/util/hotfix.cpp index 1241548e805a5f0386e81600f97bd45ea047fcda..1994170652d94aebf75c6dee0a7cb5a09ad19d04 100644 --- a/es2panda/util/hotfix.cpp +++ b/es2panda/util/hotfix.cpp @@ -32,12 +32,6 @@ const std::string EXTERNAL_ATTRIBUTE = "external"; const uint32_t PATCH_ENV_VREG = 0; // reuse first param vreg const panda::panda_file::SourceLang SRC_LANG = panda::panda_file::SourceLang::ECMASCRIPT; -const std::string FUNC_MAIN = "func_main_0"; -// stores newly added function define ins, runtime will execute -const std::string PATCH_FUNC_MAIN_0 = "patch_main_0"; -// stores modified function and class define ins, runtime will scan but not execute -const std::string PATCH_FUNC_MAIN_1 = "patch_main_1"; - void Hotfix::ProcessFunction(const compiler::PandaGen *pg, panda::pandasm::Function *func, LiteralBuffers &literalBuffers) { @@ -219,7 +213,7 @@ bool Hotfix::IsScopeValidToPatchLexical(binder::VariableScope *scope) } auto funcName = scope->AsFunctionVariableScope()->InternalName(); - if (std::string(funcName) != (recordName_ + FUNC_MAIN)) { + if (std::string(funcName) != funcMain0_) { return false; } return true; @@ -234,7 +228,7 @@ void Hotfix::AllocSlotfromPatchEnv(const std::string &variableName) uint32_t Hotfix::GetSlotIdFromSymbolTable(const std::string &variableName) { - auto functionIter = originFunctionInfo_->find(recordName_ + FUNC_MAIN); + auto functionIter = originFunctionInfo_->find(funcMain0_); if (functionIter != originFunctionInfo_->end()) { auto lexenvIter = functionIter->second.lexenv.find(variableName); if (lexenvIter != functionIter->second.lexenv.end()) { @@ -374,8 +368,8 @@ void Hotfix::Finalize(panda::pandasm::Program **prog) return; } - panda::pandasm::Function patchFuncMain0(recordName_ + PATCH_FUNC_MAIN_0, SRC_LANG); - panda::pandasm::Function patchFuncMain1(recordName_ + PATCH_FUNC_MAIN_1, SRC_LANG); + panda::pandasm::Function patchFuncMain0(patchMain0_, SRC_LANG); + panda::pandasm::Function patchFuncMain1(patchMain1_, SRC_LANG); CreateFunctionPatchMain0AndMain1(patchFuncMain0, patchFuncMain1); (*prog)->function_table.emplace(patchFuncMain0.name, std::move(patchFuncMain0)); @@ -387,7 +381,7 @@ bool Hotfix::CompareLexenv(const std::string &funcName, const compiler::PandaGen { auto &lexicalVarNameAndTypes = pg->TopScope()->GetLexicalVarNameAndTypes(); auto &lexenv = bytecodeInfo.lexenv; - if (funcName != (recordName_ + FUNC_MAIN)) { + if (funcName != funcMain0_) { if (lexenv.size() != lexicalVarNameAndTypes.size()) { std::cerr << "Found lexenv size changed, not supported!" << std::endl; patchError_ = true; @@ -458,7 +452,7 @@ void Hotfix::HandleFunction(const compiler::PandaGen *pg, panda::pandasm::Functi } auto funcHash = std::to_string(hashList.back().second); - if (funcHash == bytecodeInfo.funcHash) { + if (funcHash == bytecodeInfo.funcHash || funcName == funcMain0_) { func->metadata->SetAttribute(EXTERNAL_ATTRIBUTE); } else { patchFuncNames_.insert(funcName); diff --git a/es2panda/util/hotfix.h b/es2panda/util/hotfix.h index 17b8d061a7bfd72da8ca66826a73d27a8b06515e..53bf7a043ed56fca4ece645e4c940ffb14f22e74 100644 --- a/es2panda/util/hotfix.h +++ b/es2panda/util/hotfix.h @@ -50,6 +50,9 @@ public: classMemberFunctions_(allocator_.Adapter()) { originFunctionInfo_ = symbolTable_->GetOriginFunctionInfo(); originModuleInfo_ = symbolTable_->GetOriginModuleInfo(); + patchMain0_ = recordName_ + "patch_main_0"; + patchMain1_ = recordName_ + "patch_main_1"; + funcMain0_ = recordName_ + "func_main_0"; } void Finalize(panda::pandasm::Program **prog); @@ -91,6 +94,9 @@ private: bool generateSymbolFile_ {false}; bool generatePatch_ {false}; std::string recordName_; + std::string funcMain0_; + std::string patchMain0_; // stores newly added function define ins, runtime will execute + std::string patchMain1_; // stores modified function and class define ins, runtime will scan but not execute util::SymbolTable* symbolTable_ {nullptr}; ArenaAllocator allocator_;