From 6ca4318ee793da2c2c7aa2a24099743937e299bd Mon Sep 17 00:00:00 2001 From: Conor Hoekstra Date: Mon, 6 Jul 2020 13:39:40 +0000 Subject: [PATCH] Refactor #8 --- cpp/src/jit/parser.cpp | 55 +++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/cpp/src/jit/parser.cpp b/cpp/src/jit/parser.cpp index f869c56f996..333f7cd68ea 100644 --- a/cpp/src/jit/parser.cpp +++ b/cpp/src/jit/parser.cpp @@ -241,38 +241,37 @@ std::string ptx_parser::parse_param(const std::string& src) std::string ptx_parser::parse_param_list(const std::string& src) { - const size_t length = src.size(); - size_t start = 0; - size_t stop = 0; + auto f = src.begin(); + auto l = src.begin(); - std::string output; + auto item_count = 0; + std::string output{}; - int item_count = 0; - std::string first_name; - std::string arg_type; - while (stop < length) { - while (stop < length && src[stop] != ',') { stop++; } - std::string name = parse_param(std::string(src, start, stop - start)); - if (pointer_arg_list.find(item_count) != pointer_arg_list.end()) { - if (item_count == 0) { - output += output_arg_type + "* " + name; - } else { - // On a 64-bit machine inside the PTX function body a pointer is - // literally just a uint_64 so here is doesn't make sense to - // have the type of the pointer. Thus we will just use void* here. - output += ",\n const void* " + name; - } - } else { - if (input_arg_list.count(name)) { - output += ", \n " + input_arg_list[name] + " " + name; + while (l < src.end()) { + l = std::find(l, src.end(), ','); + + output += [&, name = parse_param(std::string(f, l))] { + if (pointer_arg_list.find(item_count) != pointer_arg_list.end()) { + if (item_count == 0) { + return output_arg_type + "* " + name; + } else { + // On a 64-bit machine inside the PTX function body a pointer is + // literally just a uint_64 so here is doesn't make sense to + // have the type of the pointer. Thus we will just use void* here. + return ",\n const void* " + name; + } } else { - // This parameter isn't used in the function body so we just pretend - // it's an int. After being inlined they are gone anyway. - output += ", \n int " + name; + if (input_arg_list.count(name)) { + return ", \n " + input_arg_list[name] + " " + name; + } else { + // This parameter isn't used in the function body so we just pretend + // it's an int. After being inlined they are gone anyway. + return ", \n int " + name; + } } - } - stop++; - start = stop; + }(); + + f = ++l; item_count++; }