This is an archive of the discontinued LLVM Phabricator instance.

LineEditor: Add a bare-bones readline-based implementation
AcceptedPublic

Authored by thakis on May 13 2021, 7:21 AM.

Details

Reviewers
pcc
hans
Summary

Doesn't do tab completion yet, but it's enough to get working
Ctrl-P in clang-repl.

Diff Detail

Event Timeline

thakis created this revision.May 13 2021, 7:21 AM
thakis requested review of this revision.May 13 2021, 7:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2021, 7:21 AM

When this gets further along, maybe we can get LLDB to use it instead of EditLine.

llvm/lib/LineEditor/LineEditor.cpp
30

Nit: In theory, this should be followed with a flush of Out.

In practice, it won't matter in most cases because stdio will ensure flushing stdout before accepting input on stdin. But there's no guarantee here that In and Out correspond to the standard streams. And since the prompt probably doesn't end with '\n', you cannot count on that flushing either.

dblaikie added inline comments.May 16 2021, 4:52 PM
llvm/lib/LineEditor/LineEditor.cpp
39–40

Skip else-after-return

373

prefer std::make_unique here, perhaps (makes it a bit easier to read/clear this member isn't a raw pointer/risk of leaks)

thakis updated this revision to Diff 346740.May 20 2021, 7:58 AM
thakis marked 2 inline comments as done.

address comments

When this gets further along, maybe we can get LLDB to use it instead of EditLine.

+1

hans accepted this revision.Jun 2 2021, 12:48 AM
hans added a subscriber: hans.

Are the presubmit errors related to this?

The change itself lgtm

llvm/lib/LineEditor/LineEditor.cpp
30

+1 I'd flush here just to be sure.

43

Maybe use Line.back() instead of Line[Line.size() - 1] here and below.

47

Could be pop_back() instead, which would be a nice match if using Line.back() == .. for the condition above.

This revision is now accepted and ready to land.Jun 2 2021, 12:48 AM