Skip to content

Commit baedff6

Browse files
authored
Merge pull request #6821 from hughbe/demangle-windows
Port swift-demangle to Windows
2 parents d79fc62 + 31af706 commit baedff6

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

tools/swift-demangle/swift-demangle.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#if defined(__FreeBSD__)
18-
#define _WITH_GETLINE
19-
#endif
20-
2117
#include "swift/Basic/DemangleWrappers.h"
2218
#include "swift/Basic/ManglingMacros.h"
2319
#include "llvm/ADT/SmallString.h"
@@ -28,14 +24,14 @@
2824
#include "llvm/Support/Signals.h"
2925
#include "llvm/Support/raw_ostream.h"
3026

27+
// For std::rand, to work around a bug if main()'s first function call passes
28+
// argv[0].
29+
#if defined(__CYGWIN__)
3130
#include <cstdlib>
32-
#include <string>
33-
#if !defined(_MSC_VER) && !defined(__MINGW32__)
34-
#include <unistd.h>
35-
#else
36-
#include <io.h>
3731
#endif
3832

33+
#include <iostream>
34+
3935
static llvm::cl::opt<bool>
4036
ExpandMode("expand",
4137
llvm::cl::desc("Expand mode (show node structure of the demangling)"));
@@ -119,27 +115,17 @@ static int demangleSTDIN(const swift::Demangle::DemangleOptions &options) {
119115
// This doesn't handle Unicode symbols, but maybe that's okay.
120116
llvm::Regex maybeSymbol("(_T|" MANGLING_PREFIX_STR ")[_a-zA-Z0-9$]+");
121117

122-
while (true) {
123-
char *inputLine = nullptr;
124-
size_t size;
125-
if (getline(&inputLine, &size, stdin) == -1 || size <= 0) {
126-
if (errno == 0) {
127-
break;
128-
}
129-
130-
return EXIT_FAILURE;
131-
}
118+
for (std::string mangled; std::getline(std::cin, mangled);) {
119+
llvm::StringRef inputContents(mangled);
132120

133-
llvm::StringRef inputContents(inputLine);
134121
llvm::SmallVector<llvm::StringRef, 1> matches;
135122
while (maybeSymbol.match(inputContents, &matches)) {
136123
llvm::outs() << substrBefore(inputContents, matches.front());
137124
demangle(llvm::outs(), matches.front(), options);
138125
inputContents = substrAfter(inputContents, matches.front());
139126
}
140127

141-
llvm::outs() << inputContents;
142-
free(inputLine);
128+
llvm::outs() << inputContents << '\n';
143129
}
144130

145131
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)