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 #ifndef ABC2PROGRAM_ABC_FILE_PROCESSOR_H 17 #define ABC2PROGRAM_ABC_FILE_PROCESSOR_H 18 19 #include "source_lang_enum.h" 20 #include "value.h" 21 #include "abc2program_key_data.h" 22 #include "annotation_data_accessor.h" 23 24 namespace ark::abc2program { 25 26 using AnnotationList = std::vector<std::pair<std::string, std::string>>; 27 28 struct RecordAnnotations { 29 AnnotationList annList; 30 std::map<std::string, AnnotationList> fieldAnnotations; 31 }; 32 33 struct ProgAnnotations { 34 std::map<std::string, AnnotationList> methodAnnotations; 35 std::map<std::string, RecordAnnotations> recordAnnotations; 36 }; 37 38 class AbcFileProcessor { 39 public: 40 explicit AbcFileProcessor(Abc2ProgramKeyData &keyData); 41 bool ProcessFile(); 42 43 private: 44 #include "abc2program_plugins.inc" 45 ark::panda_file::SourceLang GetRecordLanguage(panda_file::File::EntityId classId) const; 46 std::string ScalarValueToString(const panda_file::ScalarValue &value, const std::string &type); 47 std::string ArrayValueToString(const panda_file::ArrayValue &value, const std::string &type, const size_t idx); 48 std::string AnnotationTagToString(const char tag) const; 49 void FillExternalFieldsToRecords(); 50 void FillLiteralArrays(); 51 void ProcessClasses(); 52 void FillProgramStrings(); 53 void GetLanguageSpecificMetadata(); 54 Abc2ProgramKeyData &keyData_; 55 const panda_file::File *file_ = nullptr; 56 AbcStringTable *stringTable_ = nullptr; 57 pandasm::Program *program_ = nullptr; 58 ProgAnnotations progAnn_ {}; 59 }; 60 61 } // namespace ark::abc2program 62 63 #endif // ABC2PROGRAM_ABC_FILE_PROCESSOR_H 64