Skip to content

Port swift-demangle to Windows #6821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2017
Merged
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
30 changes: 8 additions & 22 deletions tools/swift-demangle/swift-demangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
//
//===----------------------------------------------------------------------===//

#if defined(__FreeBSD__)
#define _WITH_GETLINE
#endif

#include "swift/Basic/DemangleWrappers.h"
#include "swift/Basic/ManglingMacros.h"
#include "llvm/ADT/SmallString.h"
Expand All @@ -28,14 +24,14 @@
#include "llvm/Support/Signals.h"
#include "llvm/Support/raw_ostream.h"

// For std::rand, to work around a bug if main()'s first function call passes
// argv[0].
#if defined(__CYGWIN__)
#include <cstdlib>
#include <string>
#if !defined(_MSC_VER) && !defined(__MINGW32__)
#include <unistd.h>
#else
#include <io.h>
#endif

#include <iostream>

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

while (true) {
char *inputLine = nullptr;
size_t size;
if (getline(&inputLine, &size, stdin) == -1 || size <= 0) {
if (errno == 0) {
break;
}

return EXIT_FAILURE;
}
for (std::string mangled; std::getline(std::cin, mangled);) {
llvm::StringRef inputContents(mangled);

llvm::StringRef inputContents(inputLine);
llvm::SmallVector<llvm::StringRef, 1> matches;
while (maybeSymbol.match(inputContents, &matches)) {
llvm::outs() << substrBefore(inputContents, matches.front());
demangle(llvm::outs(), matches.front(), options);
inputContents = substrAfter(inputContents, matches.front());
}

llvm::outs() << inputContents;
free(inputLine);
llvm::outs() << inputContents << '\n';
}

return EXIT_SUCCESS;
Expand Down