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 #include "util/string_builder.h" 11 12 namespace OHOS { 13 namespace HDI { AddParameter(const AutoPtr<ASTParameter> & parameter)14void ASTMethod::AddParameter(const AutoPtr<ASTParameter> ¶meter) 15 { 16 if (parameter == nullptr) { 17 return; 18 } 19 parameters_.push_back(parameter); 20 } 21 GetParameter(size_t index)22AutoPtr<ASTParameter> ASTMethod::GetParameter(size_t index) 23 { 24 if (index >= parameters_.size()) { 25 return nullptr; 26 } 27 28 return parameters_[index]; 29 } 30 Dump(const std::string & prefix)31std::string ASTMethod::Dump(const std::string &prefix) 32 { 33 StringBuilder sb; 34 35 sb.Append(prefix).Append(attr_->Dump(prefix)).Append(" "); 36 sb.Append(name_).Append('('); 37 if (parameters_.size() != 0) { 38 sb.Append('\n'); 39 for (auto parameter : parameters_) { 40 std::string info = parameter->Dump(prefix + TAB); 41 sb.Append(info); 42 if (parameter != parameters_[parameters_.size() - 1]) { 43 sb.Append(",\n"); 44 } 45 } 46 } 47 sb.Append(");\n"); 48 49 return sb.ToString(); 50 } 51 } // namespace HDI 52 } // namespace OHOS