-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang-repl] add %help, documentation, and tests for %commands #150348
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
Changes from 6 commits
4e24cb2
752e490
99e2421
f1f6d9c
1cd23df
cde1b98
d5b1c8a
b7821e5
05516ca
ec701ca
94f3128
54ea08c
fafd7bd
4ceeef5
a84ff32
3b3d5f6
264b08b
9593d1e
e61f8ab
8f523e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| #include "llvm/Support/ManagedStatic.h" // llvm_shutdown | ||
| #include "llvm/Support/Signals.h" | ||
| #include "llvm/Support/TargetSelect.h" | ||
| #include "llvm/Support/raw_ostream.h" | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include "llvm/TargetParser/Host.h" | ||
| #include <optional> | ||
|
|
||
|
|
@@ -185,7 +186,7 @@ struct ReplListCompleter { | |
| clang::Interpreter &MainInterp; | ||
| ReplListCompleter(clang::IncrementalCompilerBuilder &CB, | ||
| clang::Interpreter &Interp) | ||
| : CB(CB), MainInterp(Interp){}; | ||
| : CB(CB), MainInterp(Interp) {}; | ||
aadanen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| std::vector<llvm::LineEditor::Completion> operator()(llvm::StringRef Buffer, | ||
| size_t Pos) const; | ||
|
|
@@ -347,7 +348,15 @@ int main(int argc, const char **argv) { | |
| } | ||
| } | ||
|
|
||
| // if we add more % commands, there should be better architecture than this | ||
DavidSpickett marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const char *help_output = "%help\tlist clang-repl %commands\n" | ||
| "%undo\tundo the previous input\n" | ||
| "%quit\texit clang-repl\n"; | ||
DavidSpickett marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const char *help_prompt = "type %help to list clang-repl commands\n"; | ||
|
||
|
|
||
| llvm::raw_ostream &OS = llvm::outs(); | ||
| if (OptInputs.empty()) { | ||
| OS << help_prompt; | ||
| llvm::LineEditor LE("clang-repl"); | ||
| std::string Input; | ||
| LE.setListCompleter(ReplListCompleter(CB, *Interp)); | ||
|
|
@@ -370,6 +379,10 @@ int main(int argc, const char **argv) { | |
| if (Input == R"(%undo)") { | ||
| if (auto Err = Interp->Undo()) | ||
| llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: "); | ||
| } else if (Input == R"(%help)") { | ||
| OS << help_output << '\n'; | ||
| } else if (Input[0] == '%') { // make sure this is evaluated last | ||
DavidSpickett marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| OS << "Invalid % command: \"" << Input << "\". " << help_prompt; | ||
aadanen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else if (Input.rfind("%lib ", 0) == 0) { | ||
| if (auto Err = Interp->LoadDynamicLibrary(Input.data() + 5)) | ||
| llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: "); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.