Skip to content

Commit cc6045b

Browse files
authored
Merge pull request #8006 from eeckstein/demangle-lib
demangler: put the demangler into a separate library
2 parents ce3ccfb + 5e80555 commit cc6045b

File tree

79 files changed

+2223
-2310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2223
-2310
lines changed

include/swift/Basic/DemangleWrappers.h

Lines changed: 0 additions & 51 deletions
This file was deleted.

include/swift/Basic/Mangler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef SWIFT_BASIC_MANGLER_H
1414
#define SWIFT_BASIC_MANGLER_H
1515

16-
#include "swift/Basic/ManglingUtils.h"
16+
#include "swift/Demangling/ManglingUtils.h"
1717
#include "llvm/ADT/DenseMap.h"
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/ADT/StringMap.h"

include/swift/Basic/Demangle.h renamed to include/swift/Demangling/Demangle.h

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@
1616
//
1717
//===----------------------------------------------------------------------===//
1818

19-
#ifndef SWIFT_BASIC_DEMANGLE_H
20-
#define SWIFT_BASIC_DEMANGLE_H
19+
#ifndef SWIFT_DEMANGLING_DEMANGLE_H
20+
#define SWIFT_DEMANGLING_DEMANGLE_H
2121

2222
#include <memory>
2323
#include <string>
24-
#include <vector>
2524
#include <cassert>
2625
#include <cstdint>
2726
#include "llvm/ADT/StringRef.h"
28-
#include "swift/Basic/Malloc.h"
2927

3028
namespace llvm {
3129
class raw_ostream;
@@ -116,7 +114,7 @@ static inline char encodeSpecializationPass(SpecializationPass Pass) {
116114
enum class ValueWitnessKind {
117115
#define VALUE_WITNESS(MANGLING, NAME) \
118116
NAME,
119-
#include "swift/Basic/ValueWitnessMangling.def"
117+
#include "swift/Demangling/ValueWitnessMangling.def"
120118
};
121119

122120
enum class Directness {
@@ -130,7 +128,7 @@ class Node {
130128
public:
131129
enum class Kind : uint16_t {
132130
#define NODE(ID) ID,
133-
#include "swift/Basic/DemangleNodes.def"
131+
#include "swift/Demangling/DemangleNodes.def"
134132
};
135133

136134
typedef uint64_t IndexType;
@@ -203,13 +201,18 @@ class Node {
203201
return Children[index];
204202
}
205203

206-
void addChild(NodePointer Child, Context &Ctx);
204+
// inline void addChild(NodePointer Child, Context &Ctx);
207205

208206
// Only to be used by the demangler parsers.
209207
void addChild(NodePointer Child, NodeFactory &Factory);
210208

211209
// Reverses the order of children.
212210
void reverseChildren(size_t StartingAt = 0);
211+
212+
/// Prints the whole node tree in readable form to stderr.
213+
///
214+
/// Useful to be called from the debugger.
215+
void dump();
213216
};
214217

215218
/// Returns true if the mangledName starts with the swift mangling prefix.
@@ -311,24 +314,6 @@ class Context {
311314
/// The memory which is used for nodes is not freed but recycled for the next
312315
/// demangling operation.
313316
void clear();
314-
315-
/// Creates a node of kind \p K.
316-
///
317-
/// The lifetime of the returned node ends with the lifetime of the
318-
/// context or with a call of clear().
319-
NodePointer createNode(Node::Kind K);
320-
321-
/// Creates a node of kind \p K with an \p Index payload.
322-
///
323-
/// The lifetime of the returned node ends with the lifetime of the
324-
/// context or with a call of clear().
325-
NodePointer createNode(Node::Kind K, Node::IndexType Index);
326-
327-
/// Creates a node of kind \p K with a \p Text payload.
328-
///
329-
/// The lifetime of the returned node ends with the lifetime of the
330-
/// context or with a call of clear().
331-
NodePointer createNode(Node::Kind K, llvm::StringRef Text);
332317
};
333318

334319
/// Standalong utility function to demangle the given symbol as string.
@@ -493,16 +478,17 @@ class DemanglerPrinter {
493478
std::string Stream;
494479
};
495480

496-
bool isSpecialized(Node *node);
497-
NodePointer getUnspecialized(Node *node, NodeFactory &Factory);
481+
/// Returns a the node kind \p k as string.
482+
const char *getNodeKindString(swift::Demangle::Node::Kind k);
498483

499-
/// Is a character considered a digit by the demangling grammar?
484+
/// Prints the whole node tree \p Root in readable form into a std::string.
500485
///
501-
/// Yes, this is equivalent to the standard C isdigit(3), but some platforms
502-
/// give isdigit suboptimal implementations.
503-
static inline bool isDigit(int c) {
504-
return c >= '0' && c <= '9';
505-
}
486+
/// Useful for debugging.
487+
std::string &&getNodeTreeAsString(NodePointer Root);
488+
489+
bool isSpecialized(Node *node);
490+
NodePointer getUnspecialized(Node *node, NodeFactory &Factory);
491+
std::string archetypeName(Node::IndexType index, Node::IndexType depth);
506492

507493
} // end namespace Demangle
508494

@@ -515,4 +501,4 @@ bool useNewMangling(Demangle::NodePointer Node);
515501

516502
} // end namespace swift
517503

518-
#endif // SWIFT_BASIC_DEMANGLE_H
504+
#endif // SWIFT_DEMANGLING_DEMANGLE_H

include/swift/Basic/Demangler.h renamed to include/swift/Demangling/Demangler.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
//
1717
//===----------------------------------------------------------------------===//
1818

19-
#ifndef SWIFT_BASIC_DEMANGLER_H
20-
#define SWIFT_BASIC_DEMANGLER_H
19+
#ifndef SWIFT_DEMANGLING_DEMANGLER_H
20+
#define SWIFT_DEMANGLING_DEMANGLER_H
2121

22-
#include "swift/Basic/Demangle.h"
23-
#include <vector>
22+
#include "swift/Demangling/Demangle.h"
2423

2524
//#define NODE_FACTORY_DEBUGGING
2625

@@ -490,7 +489,7 @@ NodePointer demangleOldSymbolAsNode(StringRef MangledName,
490489
NodePointer demangleOldTypeAsNode(StringRef MangledName,
491490
NodeFactory &Factory);
492491

493-
} // end namespace NewMangling
492+
} // end namespace Demangle
494493
} // end namespace swift
495494

496-
#endif // SWIFT_BASIC_DEMANGLER_H
495+
#endif // SWIFT_DEMANGLING_DEMANGLER_H

include/swift/Basic/ManglingMacros.h renamed to include/swift/Demangling/ManglingMacros.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef SWIFT_BASIC_MANGLING_MACROS_H
14-
#define SWIFT_BASIC_MANGLING_MACROS_H
13+
#ifndef SWIFT_DEMANGLING_MANGLING_MACROS_H
14+
#define SWIFT_DEMANGLING_MANGLING_MACROS_H
1515

1616
// The following macro enables the "new" mangling, which has an _S prefix rather
1717
// then the original _T prefix.
@@ -107,5 +107,5 @@
107107
#define OBJC_PARTIAL_APPLY_THUNK_SYM \
108108
MANGLE_SYM(OBJC_PARTIAL_APPLY_THUNK_MANGLING)
109109

110-
#endif // SWIFT_BASIC_MANGLING_MACROS_H
110+
#endif // SWIFT_DEMANGLING_MANGLING_MACROS_H
111111

include/swift/Basic/ManglingUtils.h renamed to include/swift/Demangling/ManglingUtils.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef SWIFT_BASIC_MANGLINGUTILS_H
14-
#define SWIFT_BASIC_MANGLINGUTILS_H
13+
#ifndef SWIFT_DEMANGLING_MANGLINGUTILS_H
14+
#define SWIFT_DEMANGLING_MANGLINGUTILS_H
1515

1616
#include "llvm/ADT/StringRef.h"
17-
#include "llvm/ADT/ArrayRef.h"
18-
#include "swift/Basic/Punycode.h"
17+
#include "swift/Demangling/Punycode.h"
1918

2019
namespace swift {
2120
namespace NewMangling {
2221

22+
using llvm::StringRef;
23+
2324
inline bool isLowerLetter(char ch) {
2425
return ch >= 'a' && ch <= 'z';
2526
}
@@ -313,5 +314,5 @@ class SubstitutionMerging {
313314
} // end namespace Mangle
314315
} // end namespace swift
315316

316-
#endif // SWIFT_BASIC_MANGLINGUTILS_H
317+
#endif // SWIFT_DEMANGLING_MANGLINGUTILS_H
317318

include/swift/Basic/Punycode.h renamed to include/swift/Demangling/Punycode.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
//
2525
//===----------------------------------------------------------------------===//
2626

27-
#ifndef SWIFT_BASIC_PUNYCODE_H
28-
#define SWIFT_BASIC_PUNYCODE_H
27+
#ifndef SWIFT_DEMANGLING_PUNYCODE_H
28+
#define SWIFT_DEMANGLING_PUNYCODE_H
2929

30-
#include "swift/Basic/LLVM.h"
3130
#include "llvm/ADT/StringRef.h"
32-
#include "llvm/ADT/SmallVector.h"
3331
#include <vector>
3432
#include <cstdint>
3533

3634
namespace swift {
3735
namespace Punycode {
3836

37+
using llvm::StringRef;
38+
3939
/// Encodes a sequence of code points into Punycode.
4040
///
4141
/// Returns false if input contains surrogate code points.
@@ -61,5 +61,5 @@ bool decodePunycodeUTF8(StringRef InputPunycode, std::string &OutUTF8);
6161
} // end namespace Punycode
6262
} // end namespace swift
6363

64-
#endif // SWIFT_BASIC_PUNYCODE_H
64+
#endif // SWIFT_DEMANGLING_PUNYCODE_H
6565

include/swift/Remote/MetadataReader.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
#include "swift/Runtime/Metadata.h"
2121
#include "swift/Remote/MemoryReader.h"
22-
#include "swift/Basic/Demangler.h"
23-
#include "swift/Basic/Demangle.h"
22+
#include "swift/Demangling/Demangler.h"
2423
#include "swift/Basic/LLVM.h"
2524
#include "swift/Runtime/Unreachable.h"
2625

include/swift/Runtime/Metadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "swift/Basic/Malloc.h"
3333
#include "swift/Basic/FlaggedPointer.h"
3434
#include "swift/Basic/RelativePointer.h"
35-
#include "swift/Basic/ManglingMacros.h"
35+
#include "swift/Demangling/ManglingMacros.h"
3636
#include "swift/Runtime/Unreachable.h"
3737
#include "../../../stdlib/public/SwiftShims/HeapObject.h"
3838

include/swift/SIL/Mangle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef SWIFT_SIL_MANGLE_H
1414
#define SWIFT_SIL_MANGLE_H
1515

16-
#include "swift/Basic/Demangle.h"
16+
#include "swift/Demangling/Demangle.h"
1717
#include "swift/Basic/NullablePtr.h"
1818
#include "swift/AST/Decl.h"
1919
#include "swift/AST/Mangle.h"

include/swift/SILOptimizer/Utils/SpecializationMangler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef SWIFT_SILOPTIMIZER_UTILS_SPECIALIZATIONMANGLER_H
1414
#define SWIFT_SILOPTIMIZER_UTILS_SPECIALIZATIONMANGLER_H
1515

16-
#include "swift/Basic/Demangler.h"
16+
#include "swift/Demangling/Demangler.h"
1717
#include "swift/Basic/NullablePtr.h"
1818
#include "swift/AST/ASTMangler.h"
1919
#include "swift/SIL/SILLinkage.h"

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "swift/AST/Module.h"
2222
#include "swift/AST/ProtocolConformance.h"
2323
#include "swift/AST/Mangle.h"
24-
#include "swift/Basic/ManglingUtils.h"
24+
#include "swift/Demangling/ManglingUtils.h"
2525
#include "swift/Strings.h"
2626
#include "clang/Basic/CharInfo.h"
2727
#include "clang/AST/Attr.h"

lib/AST/Mangle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include "swift/AST/Initializer.h"
2121
#include "swift/AST/Module.h"
2222
#include "swift/AST/ProtocolConformance.h"
23-
#include "swift/Basic/Demangle.h"
24-
#include "swift/Basic/Punycode.h"
23+
#include "swift/Demangling/Demangle.h"
24+
#include "swift/Demangling/Punycode.h"
2525
#include "clang/Basic/CharInfo.h"
2626
#include "clang/AST/Attr.h"
2727
#include "clang/AST/Decl.h"

lib/Basic/CMakeLists.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ set(version_inc_files
6767
add_swift_library(swiftBasic STATIC
6868
Cache.cpp
6969
ClusteredBitVector.cpp
70-
Demangle.cpp
71-
Demangler.cpp
72-
DemangleWrappers.cpp
7370
DiagnosticConsumer.cpp
7471
DiverseStack.cpp
7572
Edit.cpp
@@ -79,17 +76,12 @@ add_swift_library(swiftBasic STATIC
7976
LangOptions.cpp
8077
LLVMContext.cpp
8178
Mangler.cpp
82-
ManglingUtils.cpp
8379
Platform.cpp
8480
PrefixMap.cpp
8581
PrettyStackTrace.cpp
8682
PrimitiveParsing.cpp
8783
Program.cpp
88-
Punycode.cpp
89-
PunycodeUTF8.cpp
9084
QuotedString.cpp
91-
Remangle.cpp
92-
Remangler.cpp
9385
SourceLoc.cpp
9486
StringExtras.cpp
9587
TaskQueue.cpp
@@ -109,7 +101,9 @@ add_swift_library(swiftBasic STATIC
109101
UnicodeExtendedGraphemeClusters.cpp.gyb
110102

111103
C_COMPILE_FLAGS ${UUID_INCLUDE}
112-
LINK_LIBRARIES ${UUID_LIBRARIES}
104+
LINK_LIBRARIES
105+
swiftDemangling
106+
${UUID_LIBRARIES}
113107
LLVM_COMPONENT_DEPENDS support)
114108

115109
message(STATUS "Swift version: ${SWIFT_VERSION}")

0 commit comments

Comments
 (0)