[all-commits] [llvm/llvm-project] 247fa0: [clang] Add a new annotation token: annot_repl_inp...
Jun Zhang via All-commits
all-commits at lists.llvm.org
Tue May 16 05:11:25 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 247fa04116a6cabf8378c6c72d90b2f705e969de
https://github.com/llvm/llvm-project/commit/247fa04116a6cabf8378c6c72d90b2f705e969de
Author: Jun Zhang <jun at junz.org>
Date: 2023-05-16 (Tue, 16 May 2023)
Changed paths:
M clang/include/clang/AST/Decl.h
M clang/include/clang/Basic/TokenKinds.def
M clang/include/clang/Parse/Parser.h
M clang/lib/Frontend/PrintPreprocessedOutput.cpp
M clang/lib/Interpreter/IncrementalParser.cpp
M clang/lib/Lex/PPLexerChange.cpp
M clang/lib/Parse/ParseCXXInlineMethods.cpp
M clang/lib/Parse/ParseDecl.cpp
M clang/lib/Parse/ParseStmt.cpp
M clang/lib/Parse/Parser.cpp
Log Message:
-----------
[clang] Add a new annotation token: annot_repl_input_end
This patch is the first part of the below RFC:
https://discourse.llvm.org/t/rfc-handle-execution-results-in-clang-repl/68493
It adds an annotation token which will replace the original EOF token
when we are in the incremental C++ mode. In addition, when we're
parsing an ExprStmt and there's a missing semicolon after the
expression, we set a marker in the annotation token and continue
parsing.
Eventually, we propogate this info in ParseTopLevelStmtDecl and are able
to mark this Decl as something we want to do value printing. Below is a
example:
clang-repl> int x = 42;
clang-repl> x
// `x` is a TopLevelStmtDecl and without a semicolon, we should set
// it's IsSemiMissing bit so we can do something interesting in
// ASTConsumer::HandleTopLevelDecl.
The idea about annotation toke is proposed by Richard Smith, thanks!
Signed-off-by: Jun Zhang <jun at junz.org>
Differential Revision: https://reviews.llvm.org/D148997
Commit: a423b7f1d7ca8b263af85944f57a69aa08fc942c
https://github.com/llvm/llvm-project/commit/a423b7f1d7ca8b263af85944f57a69aa08fc942c
Author: Jun Zhang <jun at junz.org>
Date: 2023-05-16 (Tue, 16 May 2023)
Changed paths:
M clang/include/clang/Interpreter/Interpreter.h
A clang/include/clang/Interpreter/Value.h
M clang/lib/Interpreter/CMakeLists.txt
M clang/lib/Interpreter/IncrementalParser.cpp
M clang/lib/Interpreter/IncrementalParser.h
M clang/lib/Interpreter/Interpreter.cpp
A clang/lib/Interpreter/InterpreterUtils.cpp
A clang/lib/Interpreter/InterpreterUtils.h
A clang/lib/Interpreter/Value.cpp
M clang/tools/clang-repl/CMakeLists.txt
M clang/unittests/Interpreter/CMakeLists.txt
M clang/unittests/Interpreter/InterpreterTest.cpp
Log Message:
-----------
[clang-repl] Introduce Value to capture expression results
This is the second part of the below RFC:
https://discourse.llvm.org/t/rfc-handle-execution-results-in-clang-repl/68493
This patch implements a Value class that can be used to carry expression
results in clang-repl. In other words, when we see a top expression
without semi, it will be captured and stored to a Value object. You can
explicitly specify where you want to store the object, like:
```
Value V;
llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
llvm::cantFail(Interp->ParseAndExecute("x", &V));
```
`V` now stores some useful infomation about `x`, you can get its real
value (42), it's `clang::QualType` or anything interesting.
However, if you don't specify the optional argument, it will be captured
to a local variable, and automatically called `Value::dump`, which is
not implemented yet in this patch.
Signed-off-by: Jun Zhang <jun at junz.org>
Compare: https://github.com/llvm/llvm-project/compare/8a5450d322c0...a423b7f1d7ca
More information about the All-commits
mailing list