Skip to content

Commit cde1b98

Browse files
committed
got rid of printf(), added bad % command handling
1 parent 1cd23df commit cde1b98

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

clang/tools/clang-repl/ClangRepl.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "llvm/Support/ManagedStatic.h" // llvm_shutdown
2929
#include "llvm/Support/Signals.h"
3030
#include "llvm/Support/TargetSelect.h"
31+
#include "llvm/Support/raw_ostream.h"
3132
#include "llvm/TargetParser/Host.h"
3233
#include <optional>
3334

@@ -347,11 +348,15 @@ int main(int argc, const char **argv) {
347348
}
348349
}
349350

350-
const char *percent_commands = "%help\tlist clang-repl %commands\n"
351-
"%undo\tundo the previous input\n"
352-
"%quit\texit clang-repl\n";
351+
// if we add more % commands, there should be better architecture than this
352+
const char *help_output = "%help\tlist clang-repl %commands\n"
353+
"%undo\tundo the previous input\n"
354+
"%quit\texit clang-repl\n";
355+
const char *help_prompt = "type %help to list clang-repl commands\n";
356+
357+
llvm::raw_ostream &OS = llvm::outs();
353358
if (OptInputs.empty()) {
354-
printf("type %%help to list clang-repl commands\n");
359+
OS << help_prompt;
355360
llvm::LineEditor LE("clang-repl");
356361
std::string Input;
357362
LE.setListCompleter(ReplListCompleter(CB, *Interp));
@@ -375,7 +380,9 @@ int main(int argc, const char **argv) {
375380
if (auto Err = Interp->Undo())
376381
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
377382
} else if (Input == R"(%help)") {
378-
printf("%s\n", percent_commands);
383+
OS << help_output << '\n';
384+
} else if (Input[0] == '%') { // make sure this is evaluated last
385+
OS << "Invalid % command: \"" << Input << "\". " << help_prompt;
379386
} else if (Input.rfind("%lib ", 0) == 0) {
380387
if (auto Err = Interp->LoadDynamicLibrary(Input.data() + 5))
381388
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");

0 commit comments

Comments
 (0)