[PATCH] Switch clang-query to use the lineeditor library.
Peter Collingbourne
peter at pcc.me.uk
Sun Nov 24 23:55:20 PST 2013
Hi klimek, sbenza,
http://llvm-reviews.chandlerc.com/D2262
Files:
CMakeLists.txt
clang-query/CMakeLists.txt
clang-query/tool/ClangQuery.cpp
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -1,5 +1,3 @@
-check_library_exists(edit el_init "" HAVE_LIBEDIT)
-
add_subdirectory(clang-apply-replacements)
add_subdirectory(clang-modernize)
add_subdirectory(clang-query)
Index: clang-query/CMakeLists.txt
===================================================================
--- clang-query/CMakeLists.txt
+++ clang-query/CMakeLists.txt
@@ -1,3 +1,5 @@
+set(LLVM_LINK_COMPONENTS lineeditor)
+
add_clang_library(clangQuery
Query.cpp
QueryParser.cpp
Index: clang-query/tool/ClangQuery.cpp
===================================================================
--- clang-query/tool/ClangQuery.cpp
+++ clang-query/tool/ClangQuery.cpp
@@ -34,14 +34,13 @@
#include "clang/Tooling/CompilationDatabase.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/OwningPtr.h"
+#include "llvm/LineEditor/LineEditor.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Signals.h"
#include <fstream>
#include <string>
-#include <histedit.h>
-
using namespace clang;
using namespace clang::ast_matchers;
using namespace clang::ast_matchers::dynamic;
@@ -63,11 +62,6 @@
cl::desc("<source0> [... <sourceN>]"),
cl::OneOrMore);
-static char *ReturnPrompt(EditLine *EL) {
- static char Prompt[] = "clang-query> ";
- return Prompt;
-}
-
int main(int argc, const char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal();
cl::ParseCommandLineOptions(argc, argv);
@@ -126,30 +120,11 @@
}
}
} else {
- History *Hist = history_init();
- HistEvent Event;
- history(Hist, &Event, H_SETSIZE, 100);
-
- EditLine *EL = el_init("clang-query", stdin, stdout, stderr);
- el_set(EL, EL_PROMPT, ReturnPrompt);
- el_set(EL, EL_EDITOR, "emacs");
- el_set(EL, EL_HIST, history, Hist);
-
- int Count;
- while (const char *Line = el_gets(EL, &Count)) {
- if (Count == 0)
- break;
-
- history(Hist, &Event, H_ENTER, Line);
-
- QueryRef Q = ParseQuery(Line);
+ LineEditor LE("clang-query");
+ while (llvm::Optional<std::string> Line = LE.readLine()) {
+ QueryRef Q = ParseQuery(*Line);
Q->run(llvm::outs(), QS);
}
-
- history_end(Hist);
- el_end(EL);
-
- llvm::outs() << "\n";
}
llvm::DeleteContainerPointers(ASTs);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2262.1.patch
Type: text/x-patch
Size: 2473 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131124/38171950/attachment.bin>
More information about the cfe-commits
mailing list