[PATCH] D127284: [WIP] [clang-repl] Support statements on global scope in incremental mode.

Vassil Vassilev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 8 03:13:16 PDT 2022


v.g.vassilev created this revision.
v.g.vassilev added reviewers: rsmith, rjmccall, lhames, sgraenitz.
Herald added a subscriber: StephenFan.
Herald added a project: All.
v.g.vassilev requested review of this revision.

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
   

      

The patch conceptually models the possible "top-level" statements between two top-level declarations into a block which is emitted as part of the global init function.

The current implementation in CodeGen is a placeholder allowing us to discuss what would be the best approach to tackle this usecase. CodeGen works with "GlobalDecl"s and it is awkward to model a block of statements in that way. Currently, we attach each statement as an initializer of a global VarDecl. However, that granularity is not desirable.


Repository:
  rC Clang

https://reviews.llvm.org/D127284

Files:
  clang/include/clang/AST/ASTConsumer.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Interpreter/execute-stmts.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127284.435089.patch
Type: text/x-patch
Size: 12366 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220608/365047b4/attachment-0001.bin>


More information about the cfe-commits mailing list