/* * Copyright (c) 2022 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_UTIL_SYMBOL_TABLE_H #define ES2PANDA_UTIL_SYMBOL_TABLE_H #include #include namespace panda::es2panda::util { class SymbolTable { public: static const std::string FIRST_LEVEL_SEPERATOR; static const std::string SECOND_LEVEL_SEPERATOR; struct OriginFunctionInfo { std::string recordName; std::string funcInternalName; std::string funcHash; ArenaMap> lexenv; // lexenv: > ArenaMap classHash; explicit OriginFunctionInfo(ArenaAllocator *allocator) : lexenv(allocator->Adapter()), classHash(allocator->Adapter()) {} }; SymbolTable(const std::string &inputSymbolTable, const std::string &dumpSymbolTable) : symbolTable_(inputSymbolTable), dumpSymbolTable_(dumpSymbolTable), allocator_(SpaceType::SPACE_TYPE_COMPILER, nullptr, true), originFunctionInfo_(allocator_.Adapter()), originModuleInfo_(allocator_.Adapter()), originRecordHashFunctionNames_(allocator_.Adapter()) {} bool Initialize(); void WriteSymbolTable(const std::string &content); ArenaUnorderedMap *GetOriginFunctionInfo() { return &originFunctionInfo_; } ArenaUnorderedMap *GetOriginModuleInfo() { return &originModuleInfo_; } ArenaUnorderedMap> *GetOriginRecordHashFunctionNames() { return &originRecordHashFunctionNames_; } private: bool ReadSymbolTable(const std::string &symbolTable); std::vector GetStringItems(std::string_view input, const std::string &separator); void ReadRecordHashFunctionNames(std::string recordName, std::string funcInternalName, std::string specialFuncIndex); std::mutex m_; std::string symbolTable_; std::string dumpSymbolTable_; ArenaAllocator allocator_; ArenaUnorderedMap originFunctionInfo_; ArenaUnorderedMap originModuleInfo_; // > ArenaUnorderedMap> originRecordHashFunctionNames_; }; } // namespace panda::es2panda::util #endif // ES2PANDA_UTIL_SYMBOL_TABLE_H