| 68 | } |
| 69 | |
| 70 | void StringTemplate::StringTemplateArgs::init_builtin() { |
| 71 | //! for is builtin func impl, you can use |
| 72 | //! ${_unroll(nr_iter, template_body, arg0:2, arg1:copy)} to render, |
| 73 | //! nr_iter is number or template arg, template_body is template arg, arg0 |
| 74 | //! is template in template_body. |
| 75 | //! template_body like x[${_i}] = ${arg1}(y[${_i}] + ${arg0}) |
| 76 | //! FIXME: unroll impl is slow, optimize it |
| 77 | this->add("_unroll", [&](std::vector<std::string> args) { |
| 78 | StringTemplate::StringTemplateArgs& template_args = *this; |
| 79 | StringTemplate::StringTemplateArgs this_temp = template_args; |
| 80 | CC_ASSERT(args.size() > 1); |
| 81 | auto k_str = template_args.try_get_str(args[0]); |
| 82 | if (k_str.size() == 0) { |
| 83 | k_str = args[0]; |
| 84 | } |
| 85 | int k = std::atoi(k_str.c_str()); |
| 86 | std::regex kv_reg("([\\w_]+):([\\w_]+)"); |
| 87 | for (size_t i = 2; i < args.size(); ++i) { |
| 88 | std::smatch base_match; |
| 89 | if (std::regex_match(args[i], base_match, kv_reg)) { |
| 90 | auto key_str = base_match[1].str(); |
| 91 | auto value_str = base_match[2].str(); |
| 92 | this_temp.add(key_str.c_str(), value_str.c_str()); |
| 93 | } else { |
| 94 | CC_ABORT << "tempstr for function only accept XXX:YYY as extra " |
| 95 | "string args"; |
| 96 | } |
| 97 | } |
| 98 | std::stringstream ss; |
| 99 | for (int i = 0; i < k; ++i) { |
| 100 | ss << this_temp.add("_i", i).render(this_temp.get_str(args[1])); |
| 101 | } |
| 102 | return ss.str(); |
| 103 | }); |
| 104 | } |
| 105 | |
| 106 | const std::string StringTemplate::render_init_body( |
| 107 | uint32_t nr_out_weight, const std::string& fill_weight_attr, |
nothing calls this directly
no test coverage detected