-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDemangleTypes.cpp
More file actions
82 lines (74 loc) · 2.42 KB
/
DemangleTypes.cpp
File metadata and controls
82 lines (74 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! ========================================================================================
//! ExecutionGraph
//! Copyright (C) 2014 by Gabriel Nützi <gnuetzi (at) gmail (døt) com>
//!
//! @date Mon Jan 08 2018
//! @author Gabriel Nützi, <gnuetzi (at) gmail (døt) com>
//!
//! This Source Code Form is subject to the terms of the Mozilla Public
//! License, v. 2.0. If a copy of the MPL was not distributed with this
//! file, You can obtain one at http://mozilla.org/MPL/2.0/.
//! ========================================================================================
#include "executionGraph/common/DemangleTypes.hpp"
#include <sstream>
#if defined(__GNUG__) || defined(__clang__)
# include <cstdlib>
# include <cxxabi.h>
# include <memory>
#endif
namespace executionGraph
{
namespace details
{
#if defined(__GNUG__) || defined(__clang__)
std::string demangle(const char* name)
{
int status;
std::unique_ptr<char, void (*)(void*)> res{abi::__cxa_demangle(name, nullptr, nullptr, &status), std::free};
return (status == 0) ? res.get() : name;
}
#else
std::string demangle(const char* name)
{
return name;
}
#endif
} // namespace details
std::string shortenTemplateBrackets(std::string s, unsigned int fromLevel)
{
std::stringstream ss;
std::size_t bracketLevel = 0;
bool pushedEllipsis = false;
for(std::size_t i = 0; i < s.length(); ++i)
{
char& c = s[i];
if(bracketLevel <= fromLevel)
{
ss << c; // Push the char
}
switch(c)
{
case '<':
++bracketLevel;
if(bracketLevel > fromLevel && !pushedEllipsis)
{
ss << "...";
pushedEllipsis = true;
}
break;
case '>':
if(bracketLevel > 0)
{
--bracketLevel;
if(bracketLevel <= fromLevel && pushedEllipsis)
{
pushedEllipsis = false;
ss << c;
}
}
break;
}
}
return ss.str();
}
} // namespace executionGraph