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_FUNCTION_H 17 #define LIBARK_DEFECT_SCAN_AUX_INCLUDE_FUNCTION_H 18 19 #include <string> 20 #include <vector> 21 #include "libpandabase/macros.h" 22 #include "libpandafile/file.h" 23 #include "graph.h" 24 25 namespace panda::defect_scan_aux { 26 class AbcFile; 27 class Class; 28 class Function; 29 class CalleeInfo; 30 31 class Function final { 32 public: Function(std::string_view record_name, std::string_view func_name, panda_file::File::EntityId m_id, uint32_t arg_count, const Graph &graph, const AbcFile *abc_file)33 Function(std::string_view record_name, std::string_view func_name, panda_file::File::EntityId m_id, 34 uint32_t arg_count, const Graph &graph, const AbcFile *abc_file) 35 : func_name_(func_name), record_name_(record_name), m_id_(m_id), 36 arg_count_(arg_count), graph_(graph), abc_file_(abc_file) 37 { 38 } 39 ~Function() = default; 40 NO_COPY_SEMANTIC(Function); 41 NO_MOVE_SEMANTIC(Function); 42 43 const std::string &GetRecordName() const; 44 const std::string &GetFunctionName() const; 45 const AbcFile *GetAbcFileInstance() const; 46 const Graph &GetGraph() const; 47 const Class *GetClass() const; 48 Function *GetParentFunction() const; 49 uint32_t GetArgCount() const; 50 size_t GetDefinedClassCount() const; 51 size_t GetDefinedFunctionCount() const; 52 size_t GetCalleeInfoCount() const; 53 const Class *GetDefinedClassByIndex(size_t index) const; 54 const Function *GetDefinedFunctionByIndex(size_t index) const; 55 const CalleeInfo *GetCalleeInfoByIndex(size_t index) const; 56 std::vector<Inst> GetReturnInstList() const; 57 const CalleeInfo *GetCalleeInfoByCallInst(const Inst &call_inst) const; 58 uint32_t GetAndUpdateToVisitInputForInst(const Inst &inst); 59 60 private: 61 panda_file::File::EntityId GetMethodId() const; 62 void SetParentFunction(Function *parent_func); 63 void SetClass(const Class *clazz); 64 void AddDefinedClass(const Class *def_class); 65 void AddDefinedFunction(const Function *def_func); 66 void AddCalleeInfo(const CalleeInfo *callee_info); 67 68 const std::string func_name_; 69 const std::string record_name_; 70 panda_file::File::EntityId m_id_; 71 uint32_t arg_count_; 72 const Graph graph_; 73 const AbcFile *abc_file_ {nullptr}; 74 // the class which current function belongs to 75 const Class *class_ {nullptr}; 76 // the function where current function is defined 77 Function *parent_func_ {nullptr}; 78 std::vector<const Class *> def_class_list_; 79 std::vector<const Function *> def_func_list_; 80 std::vector<const CalleeInfo *> callee_info_list_; 81 std::unordered_map<uint32_t, uint32_t> to_visit_inputs_; 82 83 friend class AbcFile; 84 }; 85 } // namespace panda::defect_scan_aux 86 87 #endif // LIBARK_DEFECT_SCAN_AUX_INCLUDE_FUNCTION_H 88