[clang-repl] Introduce Value to capture expression results
authorJun Zhang <jun@junz.org>
Tue, 16 May 2023 12:10:49 +0000 (20:10 +0800)
committerJun Zhang <jun@junz.org>
Tue, 16 May 2023 12:10:49 +0000 (20:10 +0800)
commita423b7f1d7ca8b263af85944f57a69aa08fc942c
tree08a01eea0d617018a9137e15e3a9021a7fe6ccf4
parent247fa04116a6cabf8378c6c72d90b2f705e969de
[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@junz.org>
12 files changed:
clang/include/clang/Interpreter/Interpreter.h
clang/include/clang/Interpreter/Value.h [new file with mode: 0644]
clang/lib/Interpreter/CMakeLists.txt
clang/lib/Interpreter/IncrementalParser.cpp
clang/lib/Interpreter/IncrementalParser.h
clang/lib/Interpreter/Interpreter.cpp
clang/lib/Interpreter/InterpreterUtils.cpp [new file with mode: 0644]
clang/lib/Interpreter/InterpreterUtils.h [new file with mode: 0644]
clang/lib/Interpreter/Value.cpp [new file with mode: 0644]
clang/tools/clang-repl/CMakeLists.txt
clang/unittests/Interpreter/CMakeLists.txt
clang/unittests/Interpreter/InterpreterTest.cpp