-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spend more effort to make type-derived task labels readable
- Loading branch information
Showing
10 changed files
with
93 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <utils.h> | ||
|
||
#include <regex> | ||
|
||
namespace celerity::detail::utils { | ||
|
||
std::string simplify_task_name(const std::string& demangled_type_name) { | ||
if(demangled_type_name.length() < 2) return demangled_type_name; | ||
bool templated = false; | ||
// there are two options: | ||
// 1. the type is templated; in this case, the last character is ">" and we go back to the matching "<" | ||
std::string::size_type last_idx = demangled_type_name.length() - 1; | ||
if(demangled_type_name[last_idx] == '>') { | ||
templated = true; | ||
int open = 0; | ||
while(last_idx > 1) { | ||
last_idx--; | ||
if(demangled_type_name[last_idx] == '>') { open++; } | ||
if(demangled_type_name[last_idx] == '<') { | ||
if(open > 0) { | ||
open--; | ||
} else { | ||
last_idx--; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
// 2. the type isn't templated (or we just removed the template); in this case, we are interested in the part from the end to the last ":" (or the start) | ||
std::string::size_type start_idx = last_idx - 1; | ||
while(start_idx > 0 && demangled_type_name[start_idx - 1] != ':') { | ||
start_idx--; | ||
} | ||
// if the type was templated, we add a "<...>" to indicate that | ||
return demangled_type_name.substr(start_idx, last_idx - start_idx + 1) + (templated ? "<...>" : ""); | ||
} | ||
|
||
std::string escape_for_dot_label(std::string str) { | ||
str = std::regex_replace(str, std::regex("&"), "&"); | ||
str = std::regex_replace(str, std::regex("<"), "<"); | ||
str = std::regex_replace(str, std::regex(">"), ">"); | ||
return str; | ||
} | ||
|
||
} // namespace celerity::detail::utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <utils.h> | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
|
||
using namespace celerity::detail::utils; | ||
using std::string; | ||
|
||
TEST_CASE("name strings are correctly extracted from types", "[utils][simplify_task_name]") { | ||
const string simple = "name"; | ||
CHECK(simplify_task_name(simple) == "name"); | ||
|
||
const string namespaced = "ns::another::name2"; | ||
CHECK(simplify_task_name(namespaced) == "name2"); | ||
|
||
const string templated = "name3<class, int>"; | ||
CHECK(simplify_task_name(templated) == "name3<...>"); | ||
|
||
const string real = "set_identity<float>(celerity::distr_queue, celerity::buffer<float, 2>, " | ||
"bool)::{lambda(celerity::handler&)#1}::operator()(celerity::handler&) const::set_identity_kernel<const celerity::buffer&>"; | ||
CHECK(simplify_task_name(real) == "set_identity_kernel<...>"); | ||
} | ||
|
||
TEST_CASE("escaping of invalid characters for dot labels", "[utils][escape_for_dot_label]") { | ||
const string test = "hello<bla&>"; | ||
CHECK(escape_for_dot_label(test) == "hello<bla&>"); | ||
} |