summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne H Juul <arnej27959@users.noreply.github.com>2021-03-03 15:16:21 +0100
committerGitHub <noreply@github.com>2021-03-03 15:16:21 +0100
commitd8930ed3c9bb4a897121e550cde520366ca19c8f (patch)
treeb9593271e3312028062faf7e1ff1dab1a0ef84dc
parent3f86e311e1c3cdcf4ebfe80bc50271ad5f541ec6 (diff)
parentd834dcfc246fed4ceac949de14179ebf97e3bb14 (diff)
Merge pull request #16763 from vespa-engine/arnej/unify-cell-type-parsing
Arnej/unify cell type parsing
-rw-r--r--eval/src/vespa/eval/eval/value_type_spec.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/eval/src/vespa/eval/eval/value_type_spec.cpp b/eval/src/vespa/eval/eval/value_type_spec.cpp
index 1eabbd0a9fc..470da4f63a3 100644
--- a/eval/src/vespa/eval/eval/value_type_spec.cpp
+++ b/eval/src/vespa/eval/eval/value_type_spec.cpp
@@ -8,16 +8,6 @@
namespace vespalib::eval::value_type {
-std::optional<CellType> cell_type_from_name(const vespalib::string &name) {
- if (name == "double") {
- return CellType::DOUBLE;
- } else if (name == "float") {
- return CellType::FLOAT;
- } else {
- return std::nullopt;
- }
-}
-
vespalib::string cell_type_to_name(CellType cell_type) {
switch (cell_type) {
case CellType::DOUBLE: return "double";
@@ -26,6 +16,15 @@ vespalib::string cell_type_to_name(CellType cell_type) {
abort();
}
+std::optional<CellType> cell_type_from_name(const vespalib::string &name) {
+ for (CellType t : CellTypeUtils::list_types()) {
+ if (name == cell_type_to_name(t)) {
+ return t;
+ }
+ }
+ return std::nullopt;
+}
+
namespace {
class ParseContext
@@ -171,12 +170,13 @@ CellType parse_cell_type(ParseContext &ctx) {
ctx.eat('>');
if (ctx.failed()) {
ctx.revert(mark);
- return CellType::DOUBLE;
- }
- if (cell_type == "float") {
- return CellType::FLOAT;
- } else if (cell_type != "double") {
- ctx.fail();
+ } else {
+ auto result = cell_type_from_name(cell_type);
+ if (result.has_value()) {
+ return result.value();
+ } else {
+ ctx.fail();
+ }
}
return CellType::DOUBLE;
}