1 /* 2 * Copyright (c) 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_attribute.h" 10 #include "util/string_builder.h" 11 12 namespace OHOS { 13 namespace HDI { ToString() const14std::string ASTAttr::ToString() const 15 { 16 std::vector<std::string> attrs; 17 if (value_ & ASTAttr::MINI) { 18 attrs.push_back("mini"); 19 } 20 21 if (value_ & ASTAttr::LITE) { 22 attrs.push_back("lite"); 23 } 24 25 if (value_ & ASTAttr::FULL) { 26 attrs.push_back("full"); 27 } 28 29 if (value_ & ASTAttr::ONEWAY) { 30 attrs.push_back("oneway"); 31 } 32 33 if (value_ & ASTAttr::CALLBACK) { 34 attrs.push_back("callback"); 35 } 36 37 StringBuilder sb; 38 sb.Append("["); 39 for (size_t i = 0; i < attrs.size(); i++) { 40 sb.Append(attrs[i]); 41 if (i + 1 < attrs.size()) { 42 sb.Append(", "); 43 } 44 } 45 sb.Append("]"); 46 return sb.ToString(); 47 } 48 Dump(const std::string & prefix)49std::string ASTAttr::Dump(const std::string &prefix) 50 { 51 return prefix + ToString(); 52 } 53 Match(SystemLevel level) const54bool ASTAttr::Match(SystemLevel level) const 55 { 56 switch (level) { 57 case SystemLevel::MINI: 58 return HasValue(ASTAttr::MINI); 59 case SystemLevel::LITE: 60 return HasValue(ASTAttr::LITE); 61 case SystemLevel::FULL: 62 return HasValue(ASTAttr::FULL); 63 default: 64 return false; 65 } 66 } 67 ToString() const68std::string ASTParamAttr::ToString() const 69 { 70 return StringHelper::Format("[%s]", (value_ == ParamAttr::PARAM_IN) ? "in" : "out"); 71 } 72 Dump(const std::string & prefix)73std::string ASTParamAttr::Dump(const std::string &prefix) 74 { 75 return prefix + ToString(); 76 } 77 } // namespace HDI 78 } // namespace OHOS