1 /** 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "abc2program_key_data.h" 17 #include "method_data_accessor.h" 18 19 namespace ark::abc2program { 20 GetAbcFile() const21const panda_file::File &Abc2ProgramKeyData::GetAbcFile() const 22 { 23 return file_; 24 } 25 GetExternalFieldTable()26ExternalFieldTable &Abc2ProgramKeyData::GetExternalFieldTable() 27 { 28 return externalFieldTable_; 29 } 30 GetMethodNameToIdTable()31NameToIdTable &Abc2ProgramKeyData::GetMethodNameToIdTable() 32 { 33 return methodNameToId_; 34 } 35 GetRecordNameToIdTable()36NameToIdTable &Abc2ProgramKeyData::GetRecordNameToIdTable() 37 { 38 return recordNameToId_; 39 } 40 GetAbcStringTable() const41AbcStringTable &Abc2ProgramKeyData::GetAbcStringTable() const 42 { 43 return stringTable_; 44 } 45 GetProgram() const46pandasm::Program &Abc2ProgramKeyData::GetProgram() const 47 { 48 return program_; 49 } 50 GetFullRecordNameById(const panda_file::File::EntityId & classId) const51std::string Abc2ProgramKeyData::GetFullRecordNameById(const panda_file::File::EntityId &classId) const 52 { 53 std::string name = stringTable_.GetStringById(classId); 54 pandasm::Type type = pandasm::Type::FromDescriptor(name); 55 return type.GetPandasmName(); 56 } 57 GetFullFunctionNameById(const panda_file::File::EntityId & methodId) const58std::string Abc2ProgramKeyData::GetFullFunctionNameById(const panda_file::File::EntityId &methodId) const 59 { 60 ark::panda_file::MethodDataAccessor methodAccessor(file_, methodId); 61 62 const auto methodNameRaw = stringTable_.GetStringById(methodAccessor.GetNameId()); 63 64 std::string className = GetFullRecordNameById(methodAccessor.GetClassId()); 65 if (IsSystemType(className)) { 66 className = ""; 67 } else { 68 className += "."; 69 } 70 71 return className + methodNameRaw; 72 } 73 IsSystemType(const std::string & typeName) const74inline bool Abc2ProgramKeyData::IsSystemType(const std::string &typeName) const 75 { 76 bool isArrayType = typeName.back() == ']'; 77 bool isGlobal = typeName == "_GLOBAL"; 78 79 return isArrayType || isGlobal; 80 } 81 GetFileLanguage() const82ark::panda_file::SourceLang Abc2ProgramKeyData::GetFileLanguage() const 83 { 84 return fileLanguage_; 85 } 86 SetFileLanguage(ark::panda_file::SourceLang language)87void Abc2ProgramKeyData::SetFileLanguage(ark::panda_file::SourceLang language) 88 { 89 fileLanguage_ = language; 90 } 91 92 } // namespace ark::abc2program