Skip to content

Commit 31af706

Browse files
committed
Port swift-demangle to Windows
1 parent e32985d commit 31af706

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

tools/swift-demangle/swift-demangle.cpp

Lines changed: 4 additions & 23 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"
@@ -34,12 +30,7 @@
3430
#include <cstdlib>
3531
#endif
3632

37-
#include <string>
38-
#if !defined(_MSC_VER) && !defined(__MINGW32__)
39-
#include <unistd.h>
40-
#else
41-
#include <io.h>
42-
#endif
33+
#include <iostream>
4334

4435
static llvm::cl::opt<bool>
4536
ExpandMode("expand",
@@ -124,27 +115,17 @@ static int demangleSTDIN(const swift::Demangle::DemangleOptions &options) {
124115
// This doesn't handle Unicode symbols, but maybe that's okay.
125116
llvm::Regex maybeSymbol("(_T|" MANGLING_PREFIX_STR ")[_a-zA-Z0-9$]+");
126117

127-
while (true) {
128-
char *inputLine = nullptr;
129-
size_t size;
130-
if (getline(&inputLine, &size, stdin) == -1 || size <= 0) {
131-
if (errno == 0) {
132-
break;
133-
}
134-
135-
return EXIT_FAILURE;
136-
}
118+
for (std::string mangled; std::getline(std::cin, mangled);) {
119+
llvm::StringRef inputContents(mangled);
137120

138-
llvm::StringRef inputContents(inputLine);
139121
llvm::SmallVector<llvm::StringRef, 1> matches;
140122
while (maybeSymbol.match(inputContents, &matches)) {
141123
llvm::outs() << substrBefore(inputContents, matches.front());
142124
demangle(llvm::outs(), matches.front(), options);
143125
inputContents = substrAfter(inputContents, matches.front());
144126
}
145127

146-
llvm::outs() << inputContents;
147-
free(inputLine);
128+
llvm::outs() << inputContents << '\n';
148129
}
149130

150131
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)