[demangler][NFC] Small cleanups and sync

Some precursor work to adding module demangling.

* some mismatched comment and code in the demangler

* a const fn was not marked thusly

* we use std::islower.  A direct range check is smaller code (no function call),
  and we know we're in ASCII-land and later in that same function make the same
  assumption about upper-case contiguity.  Heck, maybe just drop the switch's
  precondition and rely on the optimizer to do its thing?

* the directory is cloned in two places, which had gotten out of sync.

Differential Revision: https://reviews.llvm.org/D117800
This commit is contained in:
Nathan Sidwell 2022-01-20 07:40:12 -08:00
parent ba8eb31bd9
commit 8105e404f1
4 changed files with 16 additions and 14 deletions

View File

@ -310,7 +310,7 @@ public:
printRight(OB); printRight(OB);
} }
// Print the "left" side of this Node into OutputString. // Print the "left" side of this Node into OutputBuffer.
virtual void printLeft(OutputBuffer &) const = 0; virtual void printLeft(OutputBuffer &) const = 0;
// Print the "right". This distinction is necessary to represent C++ types // Print the "right". This distinction is necessary to represent C++ types
@ -1210,7 +1210,8 @@ public:
class ParameterPack final : public Node { class ParameterPack final : public Node {
NodeArray Data; NodeArray Data;
// Setup OutputString for a pack expansion unless we're already expanding one. // Setup OutputBuffer for a pack expansion, unless we're already expanding
// one.
void initializePackExpansion(OutputBuffer &OB) const { void initializePackExpansion(OutputBuffer &OB) const {
if (OB.CurrentPackMax == std::numeric_limits<unsigned>::max()) { if (OB.CurrentPackMax == std::numeric_limits<unsigned>::max()) {
OB.CurrentPackMax = static_cast<unsigned>(Data.size()); OB.CurrentPackMax = static_cast<unsigned>(Data.size());
@ -2473,7 +2474,7 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
char consume() { return First != Last ? *First++ : '\0'; } char consume() { return First != Last ? *First++ : '\0'; }
char look(unsigned Lookahead = 0) { char look(unsigned Lookahead = 0) const {
if (static_cast<size_t>(Last - First) <= Lookahead) if (static_cast<size_t>(Last - First) <= Lookahead)
return '\0'; return '\0';
return First[Lookahead]; return First[Lookahead];
@ -5437,7 +5438,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseSubstitution() {
if (!consumeIf('S')) if (!consumeIf('S'))
return nullptr; return nullptr;
if (std::islower(look())) { if (look() >= 'a' && look() <= 'z') {
Node *SpecialSub; Node *SpecialSub;
switch (look()) { switch (look()) {
case 'a': case 'a':

View File

@ -11,8 +11,8 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_DEMANGLE_ITANIUMDEMANGLE_H #ifndef DEMANGLE_ITANIUMDEMANGLE_H
#define LLVM_DEMANGLE_ITANIUMDEMANGLE_H #define DEMANGLE_ITANIUMDEMANGLE_H
// FIXME: (possibly) incomplete list of features that clang mangles that this // FIXME: (possibly) incomplete list of features that clang mangles that this
// file does not yet support: // file does not yet support:
@ -1210,7 +1210,8 @@ public:
class ParameterPack final : public Node { class ParameterPack final : public Node {
NodeArray Data; NodeArray Data;
// Setup OutputBuffer for a pack expansion unless we're already expanding one. // Setup OutputBuffer for a pack expansion, unless we're already expanding
// one.
void initializePackExpansion(OutputBuffer &OB) const { void initializePackExpansion(OutputBuffer &OB) const {
if (OB.CurrentPackMax == std::numeric_limits<unsigned>::max()) { if (OB.CurrentPackMax == std::numeric_limits<unsigned>::max()) {
OB.CurrentPackMax = static_cast<unsigned>(Data.size()); OB.CurrentPackMax = static_cast<unsigned>(Data.size());
@ -2473,7 +2474,7 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
char consume() { return First != Last ? *First++ : '\0'; } char consume() { return First != Last ? *First++ : '\0'; }
char look(unsigned Lookahead = 0) { char look(unsigned Lookahead = 0) const {
if (static_cast<size_t>(Last - First) <= Lookahead) if (static_cast<size_t>(Last - First) <= Lookahead)
return '\0'; return '\0';
return First[Lookahead]; return First[Lookahead];
@ -5437,7 +5438,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseSubstitution() {
if (!consumeIf('S')) if (!consumeIf('S'))
return nullptr; return nullptr;
if (std::islower(look())) { if (look() >= 'a' && look() <= 'z') {
Node *SpecialSub; Node *SpecialSub;
switch (look()) { switch (look()) {
case 'a': case 'a':
@ -5747,4 +5748,4 @@ struct ManglingParser : AbstractManglingParser<ManglingParser<Alloc>, Alloc> {
DEMANGLE_NAMESPACE_END DEMANGLE_NAMESPACE_END
#endif // LLVM_DEMANGLE_ITANIUMDEMANGLE_H #endif // DEMANGLE_ITANIUMDEMANGLE_H

View File

@ -10,8 +10,8 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_DEMANGLE_STRINGVIEW_H #ifndef DEMANGLE_STRINGVIEW_H
#define LLVM_DEMANGLE_STRINGVIEW_H #define DEMANGLE_STRINGVIEW_H
#include "DemangleConfig.h" #include "DemangleConfig.h"
#include <algorithm> #include <algorithm>

View File

@ -10,8 +10,8 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_DEMANGLE_UTILITY_H #ifndef DEMANGLE_UTILITY_H
#define LLVM_DEMANGLE_UTILITY_H #define DEMANGLE_UTILITY_H
#include "StringView.h" #include "StringView.h"
#include <cstdint> #include <cstdint>