Skip to content

[cling] Use single Parser for LookupHelper #17353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace cling {
WithDiagnostics
};
private:
std::unique_ptr<clang::Parser> m_Parser;
clang::Parser* m_Parser;
Interpreter* m_Interpreter; // we do not own.
std::array<const clang::Type*, kNumCachedStrings> m_StringTy = {{}};
/// A map containing the hash of the lookup buffer. This allows us to avoid
Expand Down
11 changes: 4 additions & 7 deletions interpreter/cling/lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,6 @@ namespace cling {
}

Sema& SemaRef = getSema();
Preprocessor& PP = SemaRef.getPreprocessor();

m_LookupHelper.reset(new LookupHelper(new Parser(PP, SemaRef,
/*SkipFunctionBodies*/false,
/*isTemp*/true), this));
if (!m_LookupHelper)
return;

if (!isInSyntaxOnlyMode() && !m_Opts.CompilerOpts.CUDADevice) {
m_Executor.reset(new IncrementalExecutor(SemaRef.Diags, *getCI(),
Expand Down Expand Up @@ -317,6 +310,10 @@ namespace cling {
return;
}

m_LookupHelper.reset(new LookupHelper(m_IncrParser->getParser(), this));
if (!m_LookupHelper)
return;

// When not using C++ modules, we now have a PCH and we can safely setup
// our callbacks without fearing that they get overwritten by clang code.
// The modules setup is handled above.
Expand Down
11 changes: 4 additions & 7 deletions interpreter/llvm-project/clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,8 @@ class Parser : public CodeCompletionHandler {
/// a statement expression and builds a suitable expression statement.
StmtResult handleExprStmt(ExprResult E, ParsedStmtContext StmtCtx);

bool IsTemporary;

public:
Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies,
bool isTemp = false);
Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies);
~Parser() override;

const LangOptions &getLangOpts() const { return PP.getLangOpts(); }
Expand All @@ -482,7 +479,7 @@ class Parser : public CodeCompletionHandler {

public:
ParserCurTokRestoreRAII(Parser &P)
: P(P), SavedTok(P.Tok)
: P(P), SavedTok(P.Tok)
{
}

Expand All @@ -491,7 +488,7 @@ class Parser : public CodeCompletionHandler {
return;

P.Tok = SavedTok;

SavedTok.startToken();
}

Expand Down Expand Up @@ -1261,7 +1258,7 @@ class Parser : public CodeCompletionHandler {
return Diag(Tok, DiagID);
}

protected:
private:
void SuggestParentheses(SourceLocation Loc, unsigned DK,
SourceRange ParenRange);
void CheckNestedObjCContexts(SourceLocation AtLoc);
Expand Down
8 changes: 0 additions & 8 deletions interpreter/llvm-project/clang/lib/Parse/ParsePragma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,6 @@ void markAsReinjectedForRelexing(llvm::MutableArrayRef<clang::Token> Toks) {
} // end namespace

void Parser::initializePragmaHandlers() {
// No pragma parsing for temporary parsers.
if (IsTemporary)
return;

AlignHandler = std::make_unique<PragmaAlignHandler>();
PP.AddPragmaHandler(AlignHandler.get());

Expand Down Expand Up @@ -572,10 +568,6 @@ void Parser::initializePragmaHandlers() {
}

void Parser::resetPragmaHandlers() {
// No pragma parsing for temporary parsers.
if (IsTemporary)
return;

// Remove the pragma handlers we installed.
PP.RemovePragmaHandler(AlignHandler.get());
AlignHandler.reset();
Expand Down
40 changes: 15 additions & 25 deletions interpreter/llvm-project/clang/lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,15 @@ IdentifierInfo *Parser::getSEHExceptKeyword() {
return Ident__except;
}

Parser::Parser(Preprocessor &pp, Sema &actions, bool skipFunctionBodies,
bool isTemporary /*=false*/)
Parser::Parser(Preprocessor &pp, Sema &actions, bool skipFunctionBodies)
: PP(pp), PreferredType(pp.isCodeCompletionEnabled()), Actions(actions),
Diags(PP.getDiagnostics()), GreaterThanIsOperator(true),
ColonIsSacred(false), InMessageExpression(false),
TemplateParameterDepth(0), ParsingInObjCContainer(false),
IsTemporary(isTemporary) {
TemplateParameterDepth(0), ParsingInObjCContainer(false) {
SkipFunctionBodies = pp.isCodeCompletionEnabled() || skipFunctionBodies;
Tok.startToken();
Tok.setKind(tok::eof);
if (!IsTemporary)
Actions.CurScope = nullptr;
Actions.CurScope = nullptr;
NumCachedScopes = 0;
CurParsedObjCImpl = nullptr;

Expand All @@ -70,17 +67,14 @@ Parser::Parser(Preprocessor &pp, Sema &actions, bool skipFunctionBodies,
initializePragmaHandlers();

CommentSemaHandler.reset(new ActionCommentHandler(actions));
if (!IsTemporary)
PP.addCommentHandler(CommentSemaHandler.get());

if (!IsTemporary) {
PP.setCodeCompletionHandler(*this);
Actions.ParseTypeFromStringCallback = [this](StringRef TypeStr,
StringRef Context,
SourceLocation IncludeLoc) {
return this->ParseTypeFromString(TypeStr, Context, IncludeLoc);
};
}
PP.addCommentHandler(CommentSemaHandler.get());

PP.setCodeCompletionHandler(*this);

Actions.ParseTypeFromStringCallback =
[this](StringRef TypeStr, StringRef Context, SourceLocation IncludeLoc) {
return this->ParseTypeFromString(TypeStr, Context, IncludeLoc);
};
}

DiagnosticBuilder Parser::Diag(SourceLocation Loc, unsigned DiagID) {
Expand Down Expand Up @@ -474,22 +468,18 @@ Parser::ParseScopeFlags::~ParseScopeFlags() {

Parser::~Parser() {
// If we still have scopes active, delete the scope tree.
if (!IsTemporary) {
delete getCurScope();
Actions.CurScope = nullptr;
}
delete getCurScope();
Actions.CurScope = nullptr;

// Free the scope cache.
for (unsigned i = 0, e = NumCachedScopes; i != e; ++i)
delete ScopeCache[i];

resetPragmaHandlers();

if (!IsTemporary)
PP.removeCommentHandler(CommentSemaHandler.get());
PP.removeCommentHandler(CommentSemaHandler.get());

if (!IsTemporary)
PP.clearCodeCompletionHandler();
PP.clearCodeCompletionHandler();

DestroyTemplateIds();
}
Expand Down
2 changes: 1 addition & 1 deletion interpreter/llvm-project/llvm-project.tag
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ROOT-llvm18-20250207-02
ROOT-llvm18-20250225-01
Loading