| 153 | } |
| 154 | |
| 155 | std::string cpp_generator::generate_point_op(const operation& op, |
| 156 | const std::vector<std::string>& args) |
| 157 | { |
| 158 | auto v = op.to_value(); |
| 159 | std::string code; |
| 160 | if(contains(impl->point_op_map, op.name())) |
| 161 | { |
| 162 | code = impl->point_op_map.at(op.name()); |
| 163 | } |
| 164 | else |
| 165 | { |
| 166 | auto attributes = op.attributes(); |
| 167 | if(not attributes.contains("point_op")) |
| 168 | MIGRAPHX_THROW("op is missing point_op attribute: " + op.name()); |
| 169 | code = attributes["point_op"].to<std::string>(); |
| 170 | } |
| 171 | return interpolate_string(code, [&](auto start, auto last) -> std::string { |
| 172 | auto key = trim({start, last}); |
| 173 | if(key.empty()) |
| 174 | MIGRAPHX_THROW("Empty parameter"); |
| 175 | std::string fselector = "function:"; |
| 176 | if(starts_with(key, fselector)) |
| 177 | { |
| 178 | auto fname = key.substr(fselector.size()); |
| 179 | if(impl->fmap == nullptr) |
| 180 | return fname; |
| 181 | else |
| 182 | return impl->fmap(fname); |
| 183 | } |
| 184 | else if(with_char(::isdigit)(key[0])) |
| 185 | { |
| 186 | auto i = std::stoul(key); |
| 187 | if(i >= args.size()) |
| 188 | MIGRAPHX_THROW("Invalid argument index: " + key); |
| 189 | return args.at(i); |
| 190 | } |
| 191 | else if(v.contains(key)) |
| 192 | { |
| 193 | return v[key].template to<std::string>(); |
| 194 | } |
| 195 | else |
| 196 | { |
| 197 | return key; |
| 198 | } |
| 199 | }); |
| 200 | } |
| 201 | |
| 202 | std::string cpp_generator::str() const { return impl->fs.str(); } |
| 203 |
no test coverage detected