• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "ast/ast_method.h"
10 
11 #include "ast/ast_interface_type.h"
12 #include "util/string_builder.h"
13 
14 namespace OHOS {
15 namespace HDI {
CheckOverload(AutoPtr<ASTInterfaceType> interface)16 void ASTMethod::CheckOverload(AutoPtr<ASTInterfaceType> interface)
17 {
18     if (interface == nullptr) {
19         return;
20     }
21     interface = interface->GetExtendsInterface();
22     while (interface != nullptr) {
23         for (const auto &method : interface->GetMethodsBySystem(Options::GetInstance().GetSystemLevel())) {
24             if (name_ == method->GetName()) {
25                 isOverload_ = true;
26                 return;
27             }
28         }
29         interface = interface->GetExtendsInterface();
30     }
31     isOverload_ = false;
32 }
33 
AddParameter(const AutoPtr<ASTParameter> & parameter)34 void ASTMethod::AddParameter(const AutoPtr<ASTParameter> &parameter)
35 {
36     if (parameter == nullptr) {
37         return;
38     }
39     parameters_.push_back(parameter);
40 }
41 
GetParameter(size_t index)42 AutoPtr<ASTParameter> ASTMethod::GetParameter(size_t index)
43 {
44     if (index >= parameters_.size()) {
45         return nullptr;
46     }
47 
48     return parameters_[index];
49 }
50 
Dump(const std::string & prefix)51 std::string ASTMethod::Dump(const std::string &prefix)
52 {
53     StringBuilder sb;
54 
55     sb.Append(prefix).Append(attr_->Dump(prefix)).Append(" ");
56     sb.Append(name_).Append('(');
57     if (parameters_.size() != 0) {
58         sb.Append('\n');
59         for (auto parameter : parameters_) {
60             std::string info = parameter->Dump(prefix + TAB);
61             sb.Append(info);
62             if (parameter != parameters_[parameters_.size() - 1]) {
63                 sb.Append(",\n");
64             }
65         }
66     }
67     sb.Append(");\n");
68 
69     return sb.ToString();
70 }
71 } // namespace HDI
72 } // namespace OHOS