1 /* 2 * Copyright (c) 2022 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 LIBARK_DEFECT_SCAN_AUX_INCLUDE_CLASS_H 17 #define LIBARK_DEFECT_SCAN_AUX_INCLUDE_CLASS_H 18 19 #include <string> 20 #include <vector> 21 #include "libpandabase/macros.h" 22 23 namespace panda::defect_scan_aux { 24 class Class; 25 class Function; 26 class AbcFile; 27 28 struct ParentClassInfo { 29 const Class *class_ {nullptr}; 30 std::string class_name_; 31 std::string external_module_name_; 32 std::string global_var_name_; 33 }; 34 35 class Class final { 36 public: Class(std::string_view class_name, std::string_view record_name, const AbcFile *abc_file, Function *def_func)37 Class(std::string_view class_name, std::string_view record_name, 38 const AbcFile *abc_file, Function *def_func) 39 : class_name_(class_name), record_name_(record_name), abc_file_(abc_file), def_func_(def_func) 40 { 41 } 42 ~Class() = default; 43 NO_COPY_SEMANTIC(Class); 44 NO_MOVE_SEMANTIC(Class); 45 46 const std::string &GetClassName() const; 47 const std::string &GetRecordName() const; 48 const AbcFile *GetAbcFileInstance() const; 49 Function *GetDefiningFunction() const; 50 size_t GetMemberFunctionCount() const; 51 const Function *GetMemberFunctionByName(std::string_view func_name) const; 52 const Function *GetMemberFunctionByIndex(size_t index) const; 53 const std::vector<const Function *> &GetMemberFunctionList() const; 54 const Class *GetParentClass() const; 55 const std::string &GetParentClassName() const; 56 const std::string &GetParClassExternalModuleName() const; 57 const std::string &GetParClassGlobalVarName() const; 58 59 private: 60 void SetParentClass(const Class *parent_class); 61 void SetParentClassName(std::string_view par_class_name); 62 void SetParClassExternalModuleName(std::string_view external_module_name); 63 void SetParClassGlobalVarName(std::string global_var_name); 64 void AddMemberFunction(const Function *func); 65 66 std::string class_name_; 67 std::string record_name_; 68 const AbcFile *abc_file_ {nullptr}; 69 Function *def_func_ {nullptr}; 70 std::vector<const Function *> member_func_list_; 71 ParentClassInfo par_class_info_; 72 73 friend class AbcFile; 74 }; 75 } // namespace panda::defect_scan_aux 76 77 #endif // LIBARK_DEFECT_SCAN_AUX_INCLUDE_CLASS_H 78