Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libcxxabi/src/demangle/DemangleConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@
#define DEMANGLE_NAMESPACE_BEGIN namespace { namespace itanium_demangle {
#define DEMANGLE_NAMESPACE_END } }

// The DEMANGLE_ABI macro resolves to nothing when building libc++abi. Only
// the llvm copy defines DEMANGLE_ABI as a visibility attribute.
#define DEMANGLE_ABI

#endif // LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H
29 changes: 23 additions & 6 deletions libcxxabi/src/demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ class TemplateTemplateParamDecl final : public Node {
template <typename Fn> void match(Fn F) const { F(Name, Params, Requires); }

void printLeft(OutputBuffer &OB) const override {
ScopedOverride<unsigned> LT(OB.GtIsGt, 0);
ScopedOverride<bool> LT(OB.TemplateTracker.InsideTemplate, true);
OB += "template<";
Params.printWithComma(OB);
OB += "> typename ";
Expand Down Expand Up @@ -1550,7 +1550,7 @@ class TemplateArgs final : public Node {
NodeArray getParams() { return Params; }

void printLeft(OutputBuffer &OB) const override {
ScopedOverride<unsigned> LT(OB.GtIsGt, 0);
ScopedOverride<bool> LT(OB.TemplateTracker.InsideTemplate, true);
OB += "<";
Params.printWithComma(OB);
OB += ">";
Expand Down Expand Up @@ -1824,7 +1824,7 @@ class ClosureTypeName : public Node {

void printDeclarator(OutputBuffer &OB) const {
if (!TemplateParams.empty()) {
ScopedOverride<unsigned> LT(OB.GtIsGt, 0);
ScopedOverride<bool> LT(OB.TemplateTracker.InsideTemplate, true);
OB += "<";
TemplateParams.printWithComma(OB);
OB += ">";
Expand Down Expand Up @@ -1885,7 +1885,9 @@ class BinaryExpr : public Node {
}

void printLeft(OutputBuffer &OB) const override {
bool ParenAll = OB.isGtInsideTemplateArgs() &&
// If we're printing a '<' inside of a template argument, and we haven't
// yet parenthesized the expression, do so now.
bool ParenAll = !OB.isInParensInTemplateArgs() &&
(InfixOperator == ">" || InfixOperator == ">>");
if (ParenAll)
OB.printOpen();
Expand Down Expand Up @@ -2061,7 +2063,7 @@ class CastExpr : public Node {
void printLeft(OutputBuffer &OB) const override {
OB += CastKind;
{
ScopedOverride<unsigned> LT(OB.GtIsGt, 0);
ScopedOverride<bool> LT(OB.TemplateTracker.InsideTemplate, true);
OB += "<";
OB.printLeft(*To);
OB += ">";
Expand Down Expand Up @@ -3049,7 +3051,8 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
Node *parse(bool ParseParams = true);
};

const char* parse_discriminator(const char* first, const char* last);
DEMANGLE_ABI const char *parse_discriminator(const char *first,
const char *last);

// <name> ::= <nested-name> // N
// ::= <local-name> # See Scope Encoding below // Z
Expand Down Expand Up @@ -4878,8 +4881,22 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExprPrimary() {
return nullptr;
}
case 'D':
switch (look(1))
{
case 'i': // char32_t
First += 2;
return getDerived().parseIntegerLiteral("char32_t");
case 's': // char16_t
First += 2;
return getDerived().parseIntegerLiteral("char16_t");
case 'u': // char8_t
First += 2;
return getDerived().parseIntegerLiteral("char8_t");
default:
}
if (consumeIf("Dn") && (consumeIf('0'), consumeIf('E')))
return make<NameType>("nullptr");

return nullptr;
case 'T':
// Invalid mangled name per
Expand Down
28 changes: 21 additions & 7 deletions libcxxabi/src/demangle/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class OutputBuffer {
OutputBuffer(const OutputBuffer &) = delete;
OutputBuffer &operator=(const OutputBuffer &) = delete;

virtual ~OutputBuffer() {}
virtual ~OutputBuffer() = default;

operator std::string_view() const {
return std::string_view(Buffer, CurrentPosition);
Expand All @@ -104,18 +104,32 @@ class OutputBuffer {
unsigned CurrentPackIndex = std::numeric_limits<unsigned>::max();
unsigned CurrentPackMax = std::numeric_limits<unsigned>::max();

/// When zero, we're printing template args and '>' needs to be parenthesized.
/// Use a counter so we can simply increment inside parentheses.
unsigned GtIsGt = 1;
struct {
/// The depth of '(' and ')' inside the currently printed template
/// arguments.
unsigned ParenDepth = 0;

bool isGtInsideTemplateArgs() const { return GtIsGt == 0; }
/// True if we're currently printing a template argument.
bool InsideTemplate = false;
} TemplateTracker;

/// Returns true if we're currently between a '(' and ')' when printing
/// template args.
bool isInParensInTemplateArgs() const {
return TemplateTracker.ParenDepth > 0;
}

/// Returns true if we're printing template args.
bool isInsideTemplateArgs() const { return TemplateTracker.InsideTemplate; }

void printOpen(char Open = '(') {
GtIsGt++;
if (isInsideTemplateArgs())
TemplateTracker.ParenDepth++;
*this += Open;
}
void printClose(char Close = ')') {
GtIsGt--;
if (isInsideTemplateArgs())
TemplateTracker.ParenDepth--;
*this += Close;
}

Expand Down
5 changes: 3 additions & 2 deletions libcxxabi/src/demangle/cp-to-llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ copy_files() {
chmod -w $dst/README.txt

for I in $hdrs ; do
echo "Copying ${src}/$I to ${dst}/$I"
rm -f $dst/$I
dash=$(echo "$I---------------------------" | cut -c -27 |\
sed 's|[^-]*||')
Expand All @@ -53,6 +54,6 @@ copy_files() {
}

if [[ $ANSWER =~ ^[Yy]$ ]]; then
copy_files . $LLVM_DEMANGLE_DIR $HDRS
copy_files ../../test $LLVM_TESTING_DIR $TEST_HDRS
copy_files . $LLVM_DEMANGLE_DIR "${HDRS}"
copy_files ../../test $LLVM_TESTING_DIR "${TEST_HDRS}"
fi