diff options
author | Stefan Gränitz <stefan.graenitz@gmail.com> | 2024-03-11 13:39:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-11 13:39:23 +0100 |
commit | aec92830b79a8c49cdce0d592627d5f18bb6370b (patch) | |
tree | 48a221f3df00c11e8e537f1a5d526779700a78ab /clang/lib/Interpreter/Interpreter.cpp | |
parent | 702e2da15a1c5e728c042afd094eccf1cb3741f0 (diff) | |
download | llvm-aec92830b79a8c49cdce0d592627d5f18bb6370b.zip llvm-aec92830b79a8c49cdce0d592627d5f18bb6370b.tar.gz llvm-aec92830b79a8c49cdce0d592627d5f18bb6370b.tar.bz2 |
[clang-repl] Refactor locking of runtime PTU stack (NFC) (#84176)
The Interpreter locks PTUs that originate from implicit runtime code and
initialization to prevent users from undoing them accidentally.
The previous implementation seemed hacky, because it required the reader
to be familiar with the internal workings of the PTU stack. The concept
itself is a pragmatic solution and not very surprising. This patch
introduces a function for it and adds a comment.
Diffstat (limited to 'clang/lib/Interpreter/Interpreter.cpp')
-rw-r--r-- | clang/lib/Interpreter/Interpreter.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 3485da8..e293fef 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -280,15 +280,14 @@ Interpreter::create(std::unique_ptr<CompilerInstance> CI) { if (Err) return std::move(Err); + // Add runtime code and set a marker to hide it from user code. Undo will not + // go through that. auto PTU = Interp->Parse(Runtimes); if (!PTU) return PTU.takeError(); + Interp->markUserCodeStart(); Interp->ValuePrintingInfo.resize(4); - // FIXME: This is a ugly hack. Undo command checks its availability by looking - // at the size of the PTU list. However we have parsed something in the - // beginning of the REPL so we have to mark them as 'Irrevocable'. - Interp->InitPTUSize = Interp->IncrParser->getPTUs().size(); return std::move(Interp); } @@ -345,6 +344,11 @@ const ASTContext &Interpreter::getASTContext() const { return getCompilerInstance()->getASTContext(); } +void Interpreter::markUserCodeStart() { + assert(!InitPTUSize && "We only do this once"); + InitPTUSize = IncrParser->getPTUs().size(); +} + size_t Interpreter::getEffectivePTUSize() const { std::list<PartialTranslationUnit> &PTUs = IncrParser->getPTUs(); assert(PTUs.size() >= InitPTUSize && "empty PTU list?"); |