Skip to content

Commit

Permalink
Merge pull request #7586 from wmtan/RemoveULQualifiers
Browse files Browse the repository at this point in the history
ROOT does not use u or l qualifiers for integer template parameters in na...
  • Loading branch information
cmsbuild committed Feb 7, 2015
2 parents f67f7a2 + 6735046 commit 06d1322
Showing 1 changed file with 15 additions and 34 deletions.
49 changes: 15 additions & 34 deletions FWCore/Utilities/src/TypeDemangler.cc
@@ -1,5 +1,6 @@
#include <cxxabi.h>
#include <cctype>
#include <regex>
#include <string>
#include "FWCore/Utilities/interface/Exception.h"

Expand All @@ -24,6 +25,15 @@
********************************************************************/
namespace {
void
reformatter(std::string& input, char const* exp, char const* format) {
std::regex regexp(exp, std::regex::egrep);
while(std::regex_match(input, regexp)) {
std::string newstring = std::regex_replace(input, regexp, format);
input.swap(newstring);
}
}

void
removeParameter(std::string& demangledName, std::string const& toRemove) {
std::string::size_type const asize = toRemove.size();
Expand All @@ -50,37 +60,6 @@ namespace {
}
}

bool isAlnumOrUnderscore(char c) {
return c == '_' || std::isalnum(c);
}

void
replaceDelimitedString(std::string& demangledName, std::string const& from, std::string const& to) {
// from must not be a substring of to.
std::string::size_type length = from.size();
std::string::size_type pos = 0;
while((pos = demangledName.find(from, pos)) != std::string::npos) {
// replace 'from', unless preceded or followed by a letter, digit, or unsderscore.
if(pos != 0 && isAlnumOrUnderscore(demangledName[pos - 1])) {
++pos;
} else if(pos + length < demangledName.size() && isAlnumOrUnderscore(demangledName[pos + length])) {
++pos;
} else {
demangledName.replace(pos, length, to);
}
}
}

void
replaceString(std::string& demangledName, std::string const& from, std::string const& to) {
// from must not be a substring of to.
std::string::size_type length = from.size();
std::string::size_type pos = 0;
while((pos = demangledName.find(from, pos)) != std::string::npos) {
demangledName.replace(pos, length, to);
}
}

void
constBeforeIdentifier(std::string& demangledName) {
std::string const toBeMoved(" const");
Expand Down Expand Up @@ -121,19 +100,21 @@ namespace edm {
// We must use the same conventions used by REFLEX.
// The order of these is important.
// No space after comma
replaceString(demangledName, ", ", ",");
reformatter(demangledName, "(.*), (.*)", "$1,$2");
// Strip default allocator
std::string const allocator(",std::allocator<");
removeParameter(demangledName, allocator);
// Strip default comparator
std::string const comparator(",std::less<");
removeParameter(demangledName, comparator);
// Replace 'std::string' with 'std::basic_string<char>'.
replaceDelimitedString(demangledName, "std::string", "std::basic_string<char>");
reformatter(demangledName, "(.*[^0-9A-Za-z_])std::string([^0-9A-Za-z_].*)", "$1std::basic_string<char>$2");
// Put const qualifier before identifier.
constBeforeIdentifier(demangledName);
// No two consecutive '>'
replaceString(demangledName, ">>", "> >");
reformatter(demangledName, "(.*)>>(.*)", "$1> >$2");
// No u or l qualifiers for integers.
reformatter(demangledName, "(.*[<,][0-9]+)[ul]l*([,>].*)", "$1$2");
return demangledName;
}
}

0 comments on commit 06d1322

Please sign in to comment.