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 "class.h" 17 #include "abc_file.h" 18 #include "function.h" 19 20 namespace panda::defect_scan_aux { GetClassName() const21const std::string &Class::GetClassName() const 22 { 23 return class_name_; 24 } 25 GetRecordName() const26const std::string &Class::GetRecordName() const 27 { 28 return record_name_; 29 } 30 GetAbcFileInstance() const31const AbcFile *Class::GetAbcFileInstance() const 32 { 33 return abc_file_; 34 } 35 GetDefiningFunction() const36Function *Class::GetDefiningFunction() const 37 { 38 return def_func_; 39 } 40 GetMemberFunctionCount() const41size_t Class::GetMemberFunctionCount() const 42 { 43 return member_func_list_.size(); 44 } 45 GetMemberFunctionList() const46const std::vector<const Function *> &Class::GetMemberFunctionList() const 47 { 48 return member_func_list_; 49 } 50 GetMemberFunctionByName(std::string_view func_name) const51const Function *Class::GetMemberFunctionByName(std::string_view func_name) const 52 { 53 for (auto func : member_func_list_) { 54 if (func->GetFunctionName() == func_name) { 55 return func; 56 } 57 } 58 if (par_class_info_.class_ != nullptr) { 59 return par_class_info_.class_->GetMemberFunctionByName(func_name); 60 } 61 return nullptr; 62 } 63 GetMemberFunctionByIndex(size_t index) const64const Function *Class::GetMemberFunctionByIndex(size_t index) const 65 { 66 ASSERT(index < member_func_list_.size()); 67 return member_func_list_[index]; 68 } 69 GetParentClass() const70const Class *Class::GetParentClass() const 71 { 72 return par_class_info_.class_; 73 } 74 GetParentClassName() const75const std::string &Class::GetParentClassName() const 76 { 77 return par_class_info_.class_name_; 78 } 79 GetParClassExternalModuleName() const80const std::string &Class::GetParClassExternalModuleName() const 81 { 82 return par_class_info_.external_module_name_; 83 } 84 GetParClassGlobalVarName() const85const std::string &Class::GetParClassGlobalVarName() const 86 { 87 return par_class_info_.global_var_name_; 88 } 89 SetParentClass(const Class * parent_class)90void Class::SetParentClass(const Class *parent_class) 91 { 92 ASSERT(parent_class != nullptr); 93 par_class_info_.class_ = parent_class; 94 par_class_info_.class_name_ = parent_class->GetClassName(); 95 } 96 SetParentClassName(std::string_view par_class_name)97void Class::SetParentClassName(std::string_view par_class_name) 98 { 99 par_class_info_.class_name_ = par_class_name; 100 } 101 SetParClassExternalModuleName(std::string_view external_module_name)102void Class::SetParClassExternalModuleName(std::string_view external_module_name) 103 { 104 par_class_info_.external_module_name_ = external_module_name; 105 } 106 SetParClassGlobalVarName(std::string global_var_name)107void Class::SetParClassGlobalVarName(std::string global_var_name) 108 { 109 par_class_info_.global_var_name_ = global_var_name; 110 } 111 AddMemberFunction(const Function * func)112void Class::AddMemberFunction(const Function *func) 113 { 114 ASSERT(func != nullptr); 115 member_func_list_.push_back(func); 116 } 117 } // namespace panda::defect_scan_aux 118