1 /* 2 * Copyright (c) 2021 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>& parameter) 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 String & prefix)31String ASTMethod::Dump(const String& prefix) 32 { 33 StringBuilder sb; 34 35 sb.Append(prefix); 36 37 std::vector<String> attributes; 38 if (isOneWay_) attributes.push_back("oneway"); 39 if (isFull_) attributes.push_back("full"); 40 if (isLite_) attributes.push_back("lite"); 41 if (attributes.size() > 0) { 42 sb.Append("["); 43 for (size_t i = 0; i < attributes.size(); i++) { 44 sb.Append(attributes[i]); 45 if (i < attributes.size() - 1) { 46 sb.Append(','); 47 } 48 } 49 sb.Append("] "); 50 } 51 52 sb.Append(name_).Append('('); 53 if (parameters_.size() != 0) { 54 sb.Append('\n'); 55 for (auto parameter : parameters_) { 56 String info = parameter->Dump(prefix + " "); 57 sb.Append(info); 58 if (parameter != parameters_[parameters_.size() - 1]) { 59 sb.Append(",\n"); 60 } 61 } 62 } 63 sb.Append(");\n"); 64 65 return sb.ToString(); 66 } 67 } // namespace HDI 68 } // namespace OHOS