• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 func_name,panda_file::File::EntityId m_id,uint32_t arg_count,const Graph & graph,const AbcFile * abc_file)33     Function(std::string_view func_name, panda_file::File::EntityId m_id, uint32_t arg_count, const Graph &graph,
34              const AbcFile *abc_file)
35         : func_name_(func_name), m_id_(m_id), arg_count_(arg_count), graph_(graph), abc_file_(abc_file)
36     {
37     }
38     ~Function() = default;
39     NO_COPY_SEMANTIC(Function);
40     NO_MOVE_SEMANTIC(Function);
41 
42     const std::string &GetFunctionName() const;
43     const AbcFile *GetAbcFileInstance() const;
44     const Graph &GetGraph() const;
45     const Class *GetClass() const;
46     const Function *GetParentFunction() const;
47     uint32_t GetArgCount() const;
48     size_t GetDefinedClassCount() const;
49     size_t GetDefinedFunctionCount() const;
50     size_t GetCalleeInfoCount() const;
51     const Class *GetDefinedClassByIndex(size_t index) const;
52     const Function *GetDefinedFunctionByIndex(size_t index) const;
53     const CalleeInfo *GetCalleeInfoByIndex(size_t index) const;
54     std::vector<Inst> GetReturnInstList() const;
55     const CalleeInfo *GetCalleeInfoByCallInst(const Inst &call_inst) const;
56 
57 private:
58     panda_file::File::EntityId GetMethodId() const;
59     void SetParentFunction(const Function *parent_func);
60     void SetClass(const Class *clazz);
61     void AddDefinedClass(const Class *def_class);
62     void AddDefinedFunction(const Function *def_func);
63     void AddCalleeInfo(const CalleeInfo *callee_info);
64 
65     std::string func_name_;
66     panda_file::File::EntityId m_id_;
67     uint32_t arg_count_;
68     const Graph graph_;
69     const AbcFile *abc_file_ {nullptr};
70     // the class which current function belongs to
71     const Class *class_ {nullptr};
72     // the function where current function is defined
73     const Function *parent_func_ {nullptr};
74     std::vector<const Class *> def_class_list_;
75     std::vector<const Function *> def_func_list_;
76     std::vector<const CalleeInfo *> callee_info_list_;
77 
78     friend class AbcFile;
79 };
80 }  // namespace panda::defect_scan_aux
81 
82 #endif  // LIBARK_DEFECT_SCAN_AUX_INCLUDE_FUNCTION_H
83