• 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 #include "function.h"
17 #include "libpandafile/method_data_accessor.h"
18 #include "abc_file.h"
19 #include "callee_info.h"
20 
21 namespace panda::defect_scan_aux {
GetFunctionName() const22 const std::string &Function::GetFunctionName() const
23 {
24     return func_name_;
25 }
26 
GetAbcFileInstance() const27 const AbcFile *Function::GetAbcFileInstance() const
28 {
29     return abc_file_;
30 }
31 
GetGraph() const32 const Graph &Function::GetGraph() const
33 {
34     return graph_;
35 }
36 
GetClass() const37 const Class *Function::GetClass() const
38 {
39     return class_;
40 }
41 
GetParentFunction() const42 const Function *Function::GetParentFunction() const
43 {
44     return parent_func_;
45 }
46 
GetArgCount() const47 uint32_t Function::GetArgCount() const
48 {
49     return arg_count_;
50 }
51 
GetDefinedClassCount() const52 size_t Function::GetDefinedClassCount() const
53 {
54     return def_class_list_.size();
55 }
56 
GetDefinedFunctionCount() const57 size_t Function::GetDefinedFunctionCount() const
58 {
59     return def_func_list_.size();
60 }
61 
GetCalleeInfoCount() const62 size_t Function::GetCalleeInfoCount() const
63 {
64     return callee_info_list_.size();
65 }
66 
GetDefinedClassByIndex(size_t index) const67 const Class *Function::GetDefinedClassByIndex(size_t index) const
68 {
69     ASSERT(index < def_class_list_.size());
70     return def_class_list_[index];
71 }
72 
GetDefinedFunctionByIndex(size_t index) const73 const Function *Function::GetDefinedFunctionByIndex(size_t index) const
74 {
75     ASSERT(index < def_func_list_.size());
76     return def_func_list_[index];
77 }
78 
GetCalleeInfoByIndex(size_t index) const79 const CalleeInfo *Function::GetCalleeInfoByIndex(size_t index) const
80 {
81     ASSERT(index < callee_info_list_.size());
82     return callee_info_list_[index];
83 }
84 
GetReturnInstList() const85 std::vector<Inst> Function::GetReturnInstList() const
86 {
87     std::vector<Inst> ret_inst_list;
88     graph_.VisitAllInstructions([&](const Inst &inst) {
89         InstType type = inst.GetType();
90         if (type == InstType::RETURN) {
91             ret_inst_list.push_back(inst);
92         }
93     });
94     return ret_inst_list;
95 }
96 
GetCalleeInfoByCallInst(const Inst & call_inst) const97 const CalleeInfo *Function::GetCalleeInfoByCallInst(const Inst &call_inst) const
98 {
99     for (auto callee_info : callee_info_list_) {
100         auto &cur_call_inst = callee_info->GetCallInst();
101         if (cur_call_inst == call_inst) {
102             return callee_info;
103         }
104     }
105     return nullptr;
106 }
107 
GetMethodId() const108 panda_file::File::EntityId Function::GetMethodId() const
109 {
110     return m_id_;
111 }
112 
SetParentFunction(const Function * parent_func)113 void Function::SetParentFunction(const Function *parent_func)
114 {
115     ASSERT(parent_func != nullptr);
116     parent_func_ = parent_func;
117 }
118 
SetClass(const Class * clazz)119 void Function::SetClass(const Class *clazz)
120 {
121     ASSERT(clazz != nullptr);
122     class_ = clazz;
123 }
124 
AddDefinedClass(const Class * def_class)125 void Function::AddDefinedClass(const Class *def_class)
126 {
127     ASSERT(def_class != nullptr);
128     def_class_list_.push_back(def_class);
129 }
130 
AddDefinedFunction(const Function * def_func)131 void Function::AddDefinedFunction(const Function *def_func)
132 {
133     ASSERT(def_func != nullptr);
134     def_func_list_.push_back(def_func);
135 }
136 
AddCalleeInfo(const CalleeInfo * callee_info)137 void Function::AddCalleeInfo(const CalleeInfo *callee_info)
138 {
139     ASSERT(callee_info != nullptr);
140     callee_info_list_.push_back(callee_info);
141 }
142 }  // namespace panda::defect_scan_aux