This is an archive of the discontinued LLVM Phabricator instance.

[clang-repl] Enable basic multiline support.
ClosedPublic

Authored by v.g.vassilev on May 8 2023, 12:44 PM.

Details

Summary

This patch allows the users to use backslash to tell clang-repl that more input is coming. This would help support OpenMP directives which generally require to be in separate lines.

Diff Detail

Event Timeline

v.g.vassilev created this revision.May 8 2023, 12:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 8 2023, 12:44 PM
v.g.vassilev requested review of this revision.May 8 2023, 12:44 PM
aaron.ballman added inline comments.May 9 2023, 5:27 AM
clang/test/Interpreter/multiline.cpp
12–17

Another fun test case:

// Requires -ftrigraphs but the following line ends with a backslash (surprise!)
i=??/
  12;
v.g.vassilev added inline comments.May 11 2023, 1:46 AM
clang/test/Interpreter/multiline.cpp
12–17

Yes, the implementation of the multiline support here is actually rather rudimentary. It intentionally does not include deeper language understanding but provides a way for the users typing "well-behaved" code to tell clang-repl that more is coming before it could compile it. In theory we could check for the ??/ trigraph and do the same but I don't think that would be used people use clang-repl on things like IBM 3270 terminals which seem not to have some characters and trigraphs could help there ;)

Our full-fledged solution is described here https://discourse.llvm.org/t/rfc-flexible-lexer-buffering-for-handling-incomplete-input-in-interactive-c-c/64180/9

Until that lands we can have this to unblock work on things like OpenMP support.

aaron.ballman accepted this revision.May 11 2023, 11:28 AM

LGTM!

clang/test/Interpreter/multiline.cpp
12–17

Okay, that's reasonable enough for the initial commit. Thanks!

This revision is now accepted and ready to land.May 11 2023, 11:28 AM