llvm-project/clang/test/Interpreter
Vassil Vassilev dc4889357a [clang-repl] Support statements on global scope in incremental mode.
This patch teaches clang to parse statements on the global scope to allow:
```
./bin/clang-repl
clang-repl> int i = 12;
clang-repl> ++i;
clang-repl> extern "C" int printf(const char*,...);
clang-repl> printf("%d\n", i);
13
clang-repl> %quit
```

Generally, disambiguating between statements and declarations is a non-trivial
task for a C++ parser. The challenge is to allow both standard C++ to be
translated as if this patch does not exist and in the cases where the user typed
a statement to be executed as if it were in a function body.

Clang's Parser does pretty well in disambiguating between declarations and
expressions. We have added DisambiguatingWithExpression flag which allows us to
preserve the existing and optimized behavior where needed and implement the
extra rules for disambiguating. Only few cases require additional attention:
  * Constructors/destructors -- Parser::isConstructorDeclarator was used in to
    disambiguate between ctor-looking declarations and statements on the global
    scope(eg. `Ns::f()`).
  * The template keyword -- the template keyword can appear in both declarations
    and statements. This patch considers the template keyword to be a declaration
    starter which breaks a few cases in incremental mode which will be tackled
    later.
  * The inline (and similar) keyword -- looking at the first token in many cases
    allows us to classify what is a declaration.
  * Other language keywords and specifiers -- ObjC/ObjC++/OpenCL/OpenMP rely on
    pragmas or special tokens which will be handled in subsequent patches.

The patch conceptually models a "top-level" statement into a TopLevelStmtDecl.
The TopLevelStmtDecl is lowered into a void function with no arguments.
We attach this function to the global initializer list to execute the statement
blocks in the correct order.

Differential revision: https://reviews.llvm.org/D127284
2022-12-03 07:18:07 +00:00
..
code-undo.cpp [clang-repl] Disable building when LLVM_STATIC_LINK_CXX_STDLIB is ON. 2022-07-31 05:42:57 +09:00
disambiguate-decl-stmt.cpp [clang-repl] Support statements on global scope in incremental mode. 2022-12-03 07:18:07 +00:00
execute-stmts.cpp [clang-repl] Support statements on global scope in incremental mode. 2022-12-03 07:18:07 +00:00
execute-weak.cpp [clang-repl] Disable building when LLVM_STATIC_LINK_CXX_STDLIB is ON. 2022-07-31 05:42:57 +09:00
execute.cpp [clang-repl] Disable building when LLVM_STATIC_LINK_CXX_STDLIB is ON. 2022-07-31 05:42:57 +09:00
fail.cpp [clang-repl] Fix incorrect return code 2022-07-31 19:07:05 +08:00
global-dtor.cpp [clang-repl] Disable building when LLVM_STATIC_LINK_CXX_STDLIB is ON. 2022-07-31 05:42:57 +09:00
incremental-mode.cpp Handles failing driver tests of clang 2022-08-02 12:29:26 +05:30
lambda.cpp [CodeGen] Track DeferredDecls that have been emitted 2022-08-27 22:32:47 +08:00
lit.local.cfg [clang-repl] Disable building when LLVM_STATIC_LINK_CXX_STDLIB is ON. 2022-07-31 05:42:57 +09:00
plugins.cpp [clang-repl] Disable building when LLVM_STATIC_LINK_CXX_STDLIB is ON. 2022-07-31 05:42:57 +09:00
sanity.c [clang-repl] Implement code undo. 2022-06-26 18:32:18 +08:00
simple-exception.cpp [clang-repl] XFAIL windows properly in simple-exception test case. 2022-08-01 09:06:35 +09:00
stmt-serialization.cpp [clang-repl] Support statements on global scope in incremental mode. 2022-12-03 07:18:07 +00:00