[clang] Introduce SemaCodeCompletion (#92311)

This patch continues previous efforts to split `Sema` up, this time
covering code completion.
Context can be found in #84184.
Dropping `Code` prefix from function names in `SemaCodeCompletion` would
make sense, but I think this PR has enough changes already.
As usual, formatting changes are done as a separate commit. Hopefully
this helps with the review.
This commit is contained in:
Vlad Serebrennikov 2024-05-17 20:55:37 +04:00 committed by GitHub
parent e3686755ea
commit 874f511ae7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 1203 additions and 1022 deletions

View File

@ -18,6 +18,7 @@
#include "clang/Lex/CodeCompletionHandler.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "clang/Sema/SemaObjC.h"
#include "clang/Sema/SemaOpenMP.h"
#include "llvm/ADT/SmallVector.h"
@ -2997,7 +2998,8 @@ private:
IdentifierInfo *TryParseCXX11AttributeIdentifier(
SourceLocation &Loc,
Sema::AttributeCompletion Completion = Sema::AttributeCompletion::None,
SemaCodeCompletion::AttributeCompletion Completion =
SemaCodeCompletion::AttributeCompletion::None,
const IdentifierInfo *EnclosingScope = nullptr);
void MaybeParseHLSLAnnotations(Declarator &D,

View File

@ -167,6 +167,7 @@ class Preprocessor;
class PseudoDestructorTypeStorage;
class PseudoObjectExpr;
class QualType;
class SemaCodeCompletion;
class SemaCUDA;
class SemaHLSL;
class SemaObjC;
@ -481,9 +482,8 @@ class Sema final : public SemaBase {
// 29. C++ Variadic Templates (SemaTemplateVariadic.cpp)
// 30. Constraints and Concepts (SemaConcept.cpp)
// 31. Types (SemaType.cpp)
// 32. Code Completion (SemaCodeComplete.cpp)
// 33. FixIt Helpers (SemaFixItUtils.cpp)
// 34. Name Lookup for RISC-V Vector Intrinsic (SemaRISCVVectorLookup.cpp)
// 32. FixIt Helpers (SemaFixItUtils.cpp)
// 33. Name Lookup for RISC-V Vector Intrinsic (SemaRISCVVectorLookup.cpp)
/// \name Semantic Analysis
/// Implementations are in Sema.cpp
@ -984,6 +984,11 @@ public:
/// CurContext - This is the current declaration context of parsing.
DeclContext *CurContext;
SemaCodeCompletion &CodeCompletion() {
assert(CodeCompletionPtr);
return *CodeCompletionPtr;
}
SemaCUDA &CUDA() {
assert(CUDAPtr);
return *CUDAPtr;
@ -1044,6 +1049,7 @@ private:
mutable IdentifierInfo *Ident_super;
std::unique_ptr<SemaCodeCompletion> CodeCompletionPtr;
std::unique_ptr<SemaCUDA> CUDAPtr;
std::unique_ptr<SemaHLSL> HLSLPtr;
std::unique_ptr<SemaObjC> ObjCPtr;
@ -4801,6 +4807,11 @@ public:
DelayedDiagnostics.popUndelayed(state);
}
ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl,
CXXScopeSpec &SS,
ParsedType TemplateTypeTy,
IdentifierInfo *MemberOrBase);
private:
void setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem,
QualType ResultTy,
@ -4811,11 +4822,6 @@ private:
// of a ComparisonCategoryType enumerator.
llvm::SmallBitVector FullyCheckedComparisonCategories;
ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl,
CXXScopeSpec &SS,
ParsedType TemplateTypeTy,
IdentifierInfo *MemberOrBase);
/// Check if there is a field shadowing.
void CheckShadowInheritedFields(const SourceLocation &Loc,
DeclarationName FieldName,
@ -11664,209 +11670,6 @@ private:
//
//
/// \name Code Completion
/// Implementations are in SemaCodeComplete.cpp
///@{
public:
/// Code-completion consumer.
CodeCompleteConsumer *CodeCompleter;
/// Describes the context in which code completion occurs.
enum ParserCompletionContext {
/// Code completion occurs at top-level or namespace context.
PCC_Namespace,
/// Code completion occurs within a class, struct, or union.
PCC_Class,
/// Code completion occurs within an Objective-C interface, protocol,
/// or category.
PCC_ObjCInterface,
/// Code completion occurs within an Objective-C implementation or
/// category implementation
PCC_ObjCImplementation,
/// Code completion occurs within the list of instance variables
/// in an Objective-C interface, protocol, category, or implementation.
PCC_ObjCInstanceVariableList,
/// Code completion occurs following one or more template
/// headers.
PCC_Template,
/// Code completion occurs following one or more template
/// headers within a class.
PCC_MemberTemplate,
/// Code completion occurs within an expression.
PCC_Expression,
/// Code completion occurs within a statement, which may
/// also be an expression or a declaration.
PCC_Statement,
/// Code completion occurs at the beginning of the
/// initialization statement (or expression) in a for loop.
PCC_ForInit,
/// Code completion occurs within the condition of an if,
/// while, switch, or for statement.
PCC_Condition,
/// Code completion occurs within the body of a function on a
/// recovery path, where we do not have a specific handle on our position
/// in the grammar.
PCC_RecoveryInFunction,
/// Code completion occurs where only a type is permitted.
PCC_Type,
/// Code completion occurs in a parenthesized expression, which
/// might also be a type cast.
PCC_ParenthesizedExpression,
/// Code completion occurs within a sequence of declaration
/// specifiers within a function, method, or block.
PCC_LocalDeclarationSpecifiers,
/// Code completion occurs at top-level in a REPL session
PCC_TopLevelOrExpression,
};
void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
void CodeCompleteOrdinaryName(Scope *S,
ParserCompletionContext CompletionContext);
void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, bool AllowNonIdentifiers,
bool AllowNestedNameSpecifiers);
struct CodeCompleteExpressionData;
void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data);
void CodeCompleteExpression(Scope *S, QualType PreferredType,
bool IsParenthesized = false);
void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase,
SourceLocation OpLoc, bool IsArrow,
bool IsBaseExprStatement,
QualType PreferredType);
void CodeCompletePostfixExpression(Scope *S, ExprResult LHS,
QualType PreferredType);
void CodeCompleteTag(Scope *S, unsigned TagSpec);
void CodeCompleteTypeQualifiers(DeclSpec &DS);
void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D,
const VirtSpecifiers *VS = nullptr);
void CodeCompleteBracketDeclarator(Scope *S);
void CodeCompleteCase(Scope *S);
enum class AttributeCompletion {
Attribute,
Scope,
None,
};
void CodeCompleteAttribute(
AttributeCommonInfo::Syntax Syntax,
AttributeCompletion Completion = AttributeCompletion::Attribute,
const IdentifierInfo *Scope = nullptr);
/// Determines the preferred type of the current function argument, by
/// examining the signatures of all possible overloads.
/// Returns null if unknown or ambiguous, or if code completion is off.
///
/// If the code completion point has been reached, also reports the function
/// signatures that were considered.
///
/// FIXME: rename to GuessCallArgumentType to reduce confusion.
QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args,
SourceLocation OpenParLoc);
QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc,
ArrayRef<Expr *> Args,
SourceLocation OpenParLoc,
bool Braced);
QualType ProduceCtorInitMemberSignatureHelp(
Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy,
ArrayRef<Expr *> ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc,
bool Braced);
QualType ProduceTemplateArgumentSignatureHelp(
TemplateTy, ArrayRef<ParsedTemplateArgument>, SourceLocation LAngleLoc);
void CodeCompleteInitializer(Scope *S, Decl *D);
/// Trigger code completion for a record of \p BaseType. \p InitExprs are
/// expressions in the initializer list seen so far and \p D is the current
/// Designation being parsed.
void CodeCompleteDesignator(const QualType BaseType,
llvm::ArrayRef<Expr *> InitExprs,
const Designation &D);
void CodeCompleteAfterIf(Scope *S, bool IsBracedThen);
void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext,
bool IsUsingDeclaration, QualType BaseType,
QualType PreferredType);
void CodeCompleteUsing(Scope *S);
void CodeCompleteUsingDirective(Scope *S);
void CodeCompleteNamespaceDecl(Scope *S);
void CodeCompleteNamespaceAliasDecl(Scope *S);
void CodeCompleteOperatorName(Scope *S);
void CodeCompleteConstructorInitializer(
Decl *Constructor, ArrayRef<CXXCtorInitializer *> Initializers);
void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro,
bool AfterAmpersand);
void CodeCompleteAfterFunctionEquals(Declarator &D);
void CodeCompleteObjCAtDirective(Scope *S);
void CodeCompleteObjCAtVisibility(Scope *S);
void CodeCompleteObjCAtStatement(Scope *S);
void CodeCompleteObjCAtExpression(Scope *S);
void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
void CodeCompleteObjCPropertyGetter(Scope *S);
void CodeCompleteObjCPropertySetter(Scope *S);
void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
bool IsParameter);
void CodeCompleteObjCMessageReceiver(Scope *S);
void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
ArrayRef<const IdentifierInfo *> SelIdents,
bool AtArgumentExpression);
void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
ArrayRef<const IdentifierInfo *> SelIdents,
bool AtArgumentExpression,
bool IsSuper = false);
void CodeCompleteObjCInstanceMessage(
Scope *S, Expr *Receiver, ArrayRef<const IdentifierInfo *> SelIdents,
bool AtArgumentExpression, ObjCInterfaceDecl *Super = nullptr);
void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar);
void CodeCompleteObjCSelector(Scope *S,
ArrayRef<const IdentifierInfo *> SelIdents);
void
CodeCompleteObjCProtocolReferences(ArrayRef<IdentifierLocPair> Protocols);
void CodeCompleteObjCProtocolDecl(Scope *S);
void CodeCompleteObjCInterfaceDecl(Scope *S);
void CodeCompleteObjCClassForwardDecl(Scope *S);
void CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName,
SourceLocation ClassNameLoc);
void CodeCompleteObjCImplementationDecl(Scope *S);
void CodeCompleteObjCInterfaceCategory(Scope *S, IdentifierInfo *ClassName,
SourceLocation ClassNameLoc);
void CodeCompleteObjCImplementationCategory(Scope *S,
IdentifierInfo *ClassName,
SourceLocation ClassNameLoc);
void CodeCompleteObjCPropertyDefinition(Scope *S);
void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
IdentifierInfo *PropertyName);
void CodeCompleteObjCMethodDecl(Scope *S,
std::optional<bool> IsInstanceMethod,
ParsedType ReturnType);
void CodeCompleteObjCMethodDeclSelector(
Scope *S, bool IsInstanceMethod, bool AtParameterName,
ParsedType ReturnType, ArrayRef<const IdentifierInfo *> SelIdents);
void CodeCompleteObjCClassPropertyRefExpr(Scope *S,
const IdentifierInfo &ClassName,
SourceLocation ClassNameLoc,
bool IsBaseExprStatement);
void CodeCompletePreprocessorDirective(bool InConditional);
void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
void CodeCompletePreprocessorMacroName(bool IsDefinition);
void CodeCompletePreprocessorExpression();
void CodeCompletePreprocessorMacroArgument(Scope *S, IdentifierInfo *Macro,
MacroInfo *MacroInfo,
unsigned Argument);
void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled);
void CodeCompleteNaturalLanguage();
void CodeCompleteAvailabilityPlatformName();
void
GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
CodeCompletionTUInfo &CCTUInfo,
SmallVectorImpl<CodeCompletionResult> &Results);
///@}
//
//
// -------------------------------------------------------------------------
//
//
/// \name FixIt Helpers
/// Implementations are in SemaFixItUtils.cpp
///@{

View File

@ -0,0 +1,237 @@
//===----- SemaCodeCompletion.h ------ Code completion support ------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
/// \file
/// This file declares facilities that support code completion.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_SEMA_SEMACODECOMPLETION_H
#define LLVM_CLANG_SEMA_SEMACODECOMPLETION_H
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/Expr.h"
#include "clang/AST/Type.h"
#include "clang/Basic/AttributeCommonInfo.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/ModuleLoader.h"
#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/Designator.h"
#include "clang/Sema/Ownership.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/ADT/StringRef.h"
#include <optional>
namespace clang {
class SemaCodeCompletion : public SemaBase {
public:
SemaCodeCompletion(Sema &S, CodeCompleteConsumer *CompletionConsumer);
using TemplateTy = OpaquePtr<TemplateName>;
using DeclGroupPtrTy = OpaquePtr<DeclGroupRef>;
/// Code-completion consumer.
CodeCompleteConsumer *CodeCompleter;
/// Describes the context in which code completion occurs.
enum ParserCompletionContext {
/// Code completion occurs at top-level or namespace context.
PCC_Namespace,
/// Code completion occurs within a class, struct, or union.
PCC_Class,
/// Code completion occurs within an Objective-C interface, protocol,
/// or category.
PCC_ObjCInterface,
/// Code completion occurs within an Objective-C implementation or
/// category implementation
PCC_ObjCImplementation,
/// Code completion occurs within the list of instance variables
/// in an Objective-C interface, protocol, category, or implementation.
PCC_ObjCInstanceVariableList,
/// Code completion occurs following one or more template
/// headers.
PCC_Template,
/// Code completion occurs following one or more template
/// headers within a class.
PCC_MemberTemplate,
/// Code completion occurs within an expression.
PCC_Expression,
/// Code completion occurs within a statement, which may
/// also be an expression or a declaration.
PCC_Statement,
/// Code completion occurs at the beginning of the
/// initialization statement (or expression) in a for loop.
PCC_ForInit,
/// Code completion occurs within the condition of an if,
/// while, switch, or for statement.
PCC_Condition,
/// Code completion occurs within the body of a function on a
/// recovery path, where we do not have a specific handle on our position
/// in the grammar.
PCC_RecoveryInFunction,
/// Code completion occurs where only a type is permitted.
PCC_Type,
/// Code completion occurs in a parenthesized expression, which
/// might also be a type cast.
PCC_ParenthesizedExpression,
/// Code completion occurs within a sequence of declaration
/// specifiers within a function, method, or block.
PCC_LocalDeclarationSpecifiers,
/// Code completion occurs at top-level in a REPL session
PCC_TopLevelOrExpression,
};
void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
void CodeCompleteOrdinaryName(Scope *S,
ParserCompletionContext CompletionContext);
void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, bool AllowNonIdentifiers,
bool AllowNestedNameSpecifiers);
struct CodeCompleteExpressionData;
void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data);
void CodeCompleteExpression(Scope *S, QualType PreferredType,
bool IsParenthesized = false);
void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase,
SourceLocation OpLoc, bool IsArrow,
bool IsBaseExprStatement,
QualType PreferredType);
void CodeCompletePostfixExpression(Scope *S, ExprResult LHS,
QualType PreferredType);
void CodeCompleteTag(Scope *S, unsigned TagSpec);
void CodeCompleteTypeQualifiers(DeclSpec &DS);
void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D,
const VirtSpecifiers *VS = nullptr);
void CodeCompleteBracketDeclarator(Scope *S);
void CodeCompleteCase(Scope *S);
enum class AttributeCompletion {
Attribute,
Scope,
None,
};
void CodeCompleteAttribute(
AttributeCommonInfo::Syntax Syntax,
AttributeCompletion Completion = AttributeCompletion::Attribute,
const IdentifierInfo *Scope = nullptr);
/// Determines the preferred type of the current function argument, by
/// examining the signatures of all possible overloads.
/// Returns null if unknown or ambiguous, or if code completion is off.
///
/// If the code completion point has been reached, also reports the function
/// signatures that were considered.
///
/// FIXME: rename to GuessCallArgumentType to reduce confusion.
QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args,
SourceLocation OpenParLoc);
QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc,
ArrayRef<Expr *> Args,
SourceLocation OpenParLoc,
bool Braced);
QualType ProduceCtorInitMemberSignatureHelp(
Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy,
ArrayRef<Expr *> ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc,
bool Braced);
QualType ProduceTemplateArgumentSignatureHelp(
TemplateTy, ArrayRef<ParsedTemplateArgument>, SourceLocation LAngleLoc);
void CodeCompleteInitializer(Scope *S, Decl *D);
/// Trigger code completion for a record of \p BaseType. \p InitExprs are
/// expressions in the initializer list seen so far and \p D is the current
/// Designation being parsed.
void CodeCompleteDesignator(const QualType BaseType,
llvm::ArrayRef<Expr *> InitExprs,
const Designation &D);
void CodeCompleteAfterIf(Scope *S, bool IsBracedThen);
void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext,
bool IsUsingDeclaration, QualType BaseType,
QualType PreferredType);
void CodeCompleteUsing(Scope *S);
void CodeCompleteUsingDirective(Scope *S);
void CodeCompleteNamespaceDecl(Scope *S);
void CodeCompleteNamespaceAliasDecl(Scope *S);
void CodeCompleteOperatorName(Scope *S);
void CodeCompleteConstructorInitializer(
Decl *Constructor, ArrayRef<CXXCtorInitializer *> Initializers);
void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro,
bool AfterAmpersand);
void CodeCompleteAfterFunctionEquals(Declarator &D);
void CodeCompleteObjCAtDirective(Scope *S);
void CodeCompleteObjCAtVisibility(Scope *S);
void CodeCompleteObjCAtStatement(Scope *S);
void CodeCompleteObjCAtExpression(Scope *S);
void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
void CodeCompleteObjCPropertyGetter(Scope *S);
void CodeCompleteObjCPropertySetter(Scope *S);
void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
bool IsParameter);
void CodeCompleteObjCMessageReceiver(Scope *S);
void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
ArrayRef<const IdentifierInfo *> SelIdents,
bool AtArgumentExpression);
void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
ArrayRef<const IdentifierInfo *> SelIdents,
bool AtArgumentExpression,
bool IsSuper = false);
void CodeCompleteObjCInstanceMessage(
Scope *S, Expr *Receiver, ArrayRef<const IdentifierInfo *> SelIdents,
bool AtArgumentExpression, ObjCInterfaceDecl *Super = nullptr);
void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar);
void CodeCompleteObjCSelector(Scope *S,
ArrayRef<const IdentifierInfo *> SelIdents);
void
CodeCompleteObjCProtocolReferences(ArrayRef<IdentifierLocPair> Protocols);
void CodeCompleteObjCProtocolDecl(Scope *S);
void CodeCompleteObjCInterfaceDecl(Scope *S);
void CodeCompleteObjCClassForwardDecl(Scope *S);
void CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName,
SourceLocation ClassNameLoc);
void CodeCompleteObjCImplementationDecl(Scope *S);
void CodeCompleteObjCInterfaceCategory(Scope *S, IdentifierInfo *ClassName,
SourceLocation ClassNameLoc);
void CodeCompleteObjCImplementationCategory(Scope *S,
IdentifierInfo *ClassName,
SourceLocation ClassNameLoc);
void CodeCompleteObjCPropertyDefinition(Scope *S);
void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
IdentifierInfo *PropertyName);
void CodeCompleteObjCMethodDecl(Scope *S,
std::optional<bool> IsInstanceMethod,
ParsedType ReturnType);
void CodeCompleteObjCMethodDeclSelector(
Scope *S, bool IsInstanceMethod, bool AtParameterName,
ParsedType ReturnType, ArrayRef<const IdentifierInfo *> SelIdents);
void CodeCompleteObjCClassPropertyRefExpr(Scope *S,
const IdentifierInfo &ClassName,
SourceLocation ClassNameLoc,
bool IsBaseExprStatement);
void CodeCompletePreprocessorDirective(bool InConditional);
void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
void CodeCompletePreprocessorMacroName(bool IsDefinition);
void CodeCompletePreprocessorExpression();
void CodeCompletePreprocessorMacroArgument(Scope *S, IdentifierInfo *Macro,
MacroInfo *MacroInfo,
unsigned Argument);
void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled);
void CodeCompleteNaturalLanguage();
void CodeCompleteAvailabilityPlatformName();
void
GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
CodeCompletionTUInfo &CCTUInfo,
SmallVectorImpl<CodeCompletionResult> &Results);
};
} // namespace clang
#endif // LLVM_CLANG_SEMA_SEMACODECOMPLETION_H

View File

@ -56,6 +56,7 @@
#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang/Sema/CodeCompleteOptions.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "clang/Serialization/ASTBitCodes.h"
#include "clang/Serialization/ASTReader.h"
#include "clang/Serialization/ASTWriter.h"
@ -375,8 +376,8 @@ void ASTUnit::CacheCodeCompletionResults() {
SmallVector<Result, 8> Results;
CachedCompletionAllocator = std::make_shared<GlobalCodeCompletionAllocator>();
CodeCompletionTUInfo CCTUInfo(CachedCompletionAllocator);
TheSema->GatherGlobalCodeCompletions(*CachedCompletionAllocator,
CCTUInfo, Results);
TheSema->CodeCompletion().GatherGlobalCodeCompletions(
*CachedCompletionAllocator, CCTUInfo, Results);
// Translate global code completions into cached completions.
llvm::DenseMap<CanQualType, unsigned> CompletionTypes;

View File

@ -27,6 +27,7 @@
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaCUDA.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "clang/Sema/SemaDiagnostic.h"
#include "clang/Sema/SemaObjC.h"
#include "clang/Sema/SemaOpenMP.h"
@ -218,7 +219,8 @@ void Parser::ParseGNUAttributes(ParsedAttributes &Attrs,
break;
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteAttribute(AttributeCommonInfo::Syntax::AS_GNU);
Actions.CodeCompletion().CodeCompleteAttribute(
AttributeCommonInfo::Syntax::AS_GNU);
break;
}
IdentifierInfo *AttrName = Tok.getIdentifierInfo();
@ -895,7 +897,8 @@ void Parser::ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteAttribute(AttributeCommonInfo::AS_Declspec);
Actions.CodeCompletion().CodeCompleteAttribute(
AttributeCommonInfo::AS_Declspec);
return;
}
@ -2286,7 +2289,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
// Check to see if we have a function *definition* which must have a body.
if (Tok.is(tok::equal) && NextToken().is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteAfterFunctionEquals(D);
Actions.CodeCompletion().CodeCompleteAfterFunctionEquals(D);
return nullptr;
}
// We're at the point where the parsing of function declarator is finished.
@ -2722,7 +2725,8 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteInitializer(getCurScope(), ThisDecl);
Actions.CodeCompletion().CodeCompleteInitializer(getCurScope(),
ThisDecl);
Actions.FinalizeDeclaration(ThisDecl);
return nullptr;
}
@ -2767,10 +2771,11 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
auto RunSignatureHelp = [&]() {
QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
ThisVarDecl->getType()->getCanonicalTypeInternal(),
ThisDecl->getLocation(), Exprs, T.getOpenLocation(),
/*Braced=*/false);
QualType PreferredType =
Actions.CodeCompletion().ProduceConstructorSignatureHelp(
ThisVarDecl->getType()->getCanonicalTypeInternal(),
ThisDecl->getLocation(), Exprs, T.getOpenLocation(),
/*Braced=*/false);
CalledSignatureHelp = true;
return PreferredType;
};
@ -2791,7 +2796,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
if (SawError) {
if (ThisVarDecl && PP.isCodeCompletionReached() && !CalledSignatureHelp) {
Actions.ProduceConstructorSignatureHelp(
Actions.CodeCompletion().ProduceConstructorSignatureHelp(
ThisVarDecl->getType()->getCanonicalTypeInternal(),
ThisDecl->getLocation(), Exprs, T.getOpenLocation(),
/*Braced=*/false);
@ -3635,7 +3640,8 @@ void Parser::ParseDeclarationSpecifiers(
continue;
case tok::code_completion: {
Sema::ParserCompletionContext CCC = Sema::PCC_Namespace;
SemaCodeCompletion::ParserCompletionContext CCC =
SemaCodeCompletion::PCC_Namespace;
if (DS.hasTypeSpecifier()) {
bool AllowNonIdentifiers
= (getCurScope()->getFlags() & (Scope::ControlScope |
@ -3648,25 +3654,25 @@ void Parser::ParseDeclarationSpecifiers(
(DSContext == DeclSpecContext::DSC_class && DS.isFriendSpecified());
cutOffParsing();
Actions.CodeCompleteDeclSpec(getCurScope(), DS,
AllowNonIdentifiers,
AllowNestedNameSpecifiers);
Actions.CodeCompletion().CodeCompleteDeclSpec(
getCurScope(), DS, AllowNonIdentifiers, AllowNestedNameSpecifiers);
return;
}
// Class context can appear inside a function/block, so prioritise that.
if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate)
CCC = DSContext == DeclSpecContext::DSC_class ? Sema::PCC_MemberTemplate
: Sema::PCC_Template;
CCC = DSContext == DeclSpecContext::DSC_class
? SemaCodeCompletion::PCC_MemberTemplate
: SemaCodeCompletion::PCC_Template;
else if (DSContext == DeclSpecContext::DSC_class)
CCC = Sema::PCC_Class;
CCC = SemaCodeCompletion::PCC_Class;
else if (getCurScope()->getFnParent() || getCurScope()->getBlockParent())
CCC = Sema::PCC_LocalDeclarationSpecifiers;
CCC = SemaCodeCompletion::PCC_LocalDeclarationSpecifiers;
else if (CurParsedObjCImpl)
CCC = Sema::PCC_ObjCImplementation;
CCC = SemaCodeCompletion::PCC_ObjCImplementation;
cutOffParsing();
Actions.CodeCompleteOrdinaryName(getCurScope(), CCC);
Actions.CodeCompletion().CodeCompleteOrdinaryName(getCurScope(), CCC);
return;
}
@ -5076,7 +5082,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
if (Tok.is(tok::code_completion)) {
// Code completion for an enum name.
cutOffParsing();
Actions.CodeCompleteTag(getCurScope(), DeclSpec::TST_enum);
Actions.CodeCompletion().CodeCompleteTag(getCurScope(), DeclSpec::TST_enum);
DS.SetTypeSpecError(); // Needed by ActOnUsingDeclaration.
return;
}
@ -6266,7 +6272,7 @@ void Parser::ParseTypeQualifierListOpt(
if (CodeCompletionHandler)
(*CodeCompletionHandler)();
else
Actions.CodeCompleteTypeQualifiers(DS);
Actions.CodeCompletion().CodeCompleteTypeQualifiers(DS);
return;
case tok::kw_const:
@ -7403,12 +7409,12 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
// with the pure-specifier in the same way.
// Parse cv-qualifier-seq[opt].
ParseTypeQualifierListOpt(DS, AR_NoAttributesParsed,
/*AtomicAllowed*/ false,
/*IdentifierRequired=*/false,
llvm::function_ref<void()>([&]() {
Actions.CodeCompleteFunctionQualifiers(DS, D);
}));
ParseTypeQualifierListOpt(
DS, AR_NoAttributesParsed,
/*AtomicAllowed*/ false,
/*IdentifierRequired=*/false, llvm::function_ref<void()>([&]() {
Actions.CodeCompletion().CodeCompleteFunctionQualifiers(DS, D);
}));
if (!DS.getSourceRange().getEnd().isInvalid()) {
EndLoc = DS.getSourceRange().getEnd();
}
@ -7971,7 +7977,7 @@ void Parser::ParseBracketDeclarator(Declarator &D) {
return;
} else if (Tok.getKind() == tok::code_completion) {
cutOffParsing();
Actions.CodeCompleteBracketDeclarator(getCurScope());
Actions.CodeCompletion().CodeCompleteBracketDeclarator(getCurScope());
return;
}

View File

@ -27,6 +27,7 @@
#include "clang/Sema/EnterExpressionEvaluationContext.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/TimeProfiler.h"
#include <optional>
@ -69,7 +70,7 @@ Parser::DeclGroupPtrTy Parser::ParseNamespace(DeclaratorContext Context,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteNamespaceDecl(getCurScope());
Actions.CodeCompletion().CodeCompleteNamespaceDecl(getCurScope());
return nullptr;
}
@ -309,7 +310,7 @@ Decl *Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteNamespaceAliasDecl(getCurScope());
Actions.CodeCompletion().CodeCompleteNamespaceAliasDecl(getCurScope());
return nullptr;
}
@ -492,7 +493,7 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDirectiveOrDeclaration(
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteUsing(getCurScope());
Actions.CodeCompletion().CodeCompleteUsing(getCurScope());
return nullptr;
}
@ -542,7 +543,7 @@ Decl *Parser::ParseUsingDirective(DeclaratorContext Context,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteUsingDirective(getCurScope());
Actions.CodeCompletion().CodeCompleteUsingDirective(getCurScope());
return nullptr;
}
@ -733,7 +734,7 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration(
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteUsing(getCurScope());
Actions.CodeCompletion().CodeCompleteUsing(getCurScope());
return nullptr;
}
@ -1680,7 +1681,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
if (Tok.is(tok::code_completion)) {
// Code completion for a struct, class, or union name.
cutOffParsing();
Actions.CodeCompleteTag(getCurScope(), TagType);
Actions.CodeCompletion().CodeCompleteTag(getCurScope(), TagType);
return;
}
@ -2719,7 +2720,7 @@ void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(
ParseTypeQualifierListOpt(
DS, AR_NoAttributesParsed, false,
/*IdentifierRequired=*/false, llvm::function_ref<void()>([&]() {
Actions.CodeCompleteFunctionQualifiers(DS, D, &VS);
Actions.CodeCompletion().CodeCompleteFunctionQualifiers(DS, D, &VS);
}));
D.ExtendWithDeclSpec(DS);
@ -3080,7 +3081,8 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
DefinitionKind = FunctionDefinitionKind::Deleted;
else if (KW.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteAfterFunctionEquals(DeclaratorInfo);
Actions.CodeCompletion().CodeCompleteAfterFunctionEquals(
DeclaratorInfo);
return nullptr;
}
}
@ -3892,8 +3894,8 @@ void Parser::ParseConstructorInitializer(Decl *ConstructorDecl) {
do {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteConstructorInitializer(ConstructorDecl,
MemInitializers);
Actions.CodeCompletion().CodeCompleteConstructorInitializer(
ConstructorDecl, MemInitializers);
return;
}
@ -4013,9 +4015,10 @@ MemInitResult Parser::ParseMemInitializer(Decl *ConstructorDecl) {
auto RunSignatureHelp = [&] {
if (TemplateTypeTy.isInvalid())
return QualType();
QualType PreferredType = Actions.ProduceCtorInitMemberSignatureHelp(
ConstructorDecl, SS, TemplateTypeTy.get(), ArgExprs, II,
T.getOpenLocation(), /*Braced=*/false);
QualType PreferredType =
Actions.CodeCompletion().ProduceCtorInitMemberSignatureHelp(
ConstructorDecl, SS, TemplateTypeTy.get(), ArgExprs, II,
T.getOpenLocation(), /*Braced=*/false);
CalledSignatureHelp = true;
return PreferredType;
};
@ -4400,10 +4403,9 @@ void Parser::PopParsingClass(Sema::ParsingClassState state) {
/// If a keyword or an alternative token that satisfies the syntactic
/// requirements of an identifier is contained in an attribute-token,
/// it is considered an identifier.
IdentifierInfo *
Parser::TryParseCXX11AttributeIdentifier(SourceLocation &Loc,
Sema::AttributeCompletion Completion,
const IdentifierInfo *Scope) {
IdentifierInfo *Parser::TryParseCXX11AttributeIdentifier(
SourceLocation &Loc, SemaCodeCompletion::AttributeCompletion Completion,
const IdentifierInfo *Scope) {
switch (Tok.getKind()) {
default:
// Identifiers and keywords have identifier info attached.
@ -4417,9 +4419,9 @@ Parser::TryParseCXX11AttributeIdentifier(SourceLocation &Loc,
case tok::code_completion:
cutOffParsing();
Actions.CodeCompleteAttribute(getLangOpts().CPlusPlus ? ParsedAttr::AS_CXX11
: ParsedAttr::AS_C23,
Completion, Scope);
Actions.CodeCompletion().CodeCompleteAttribute(
getLangOpts().CPlusPlus ? ParsedAttr::AS_CXX11 : ParsedAttr::AS_C23,
Completion, Scope);
return nullptr;
case tok::numeric_constant: {
@ -4802,7 +4804,7 @@ void Parser::ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
ConsumeToken();
CommonScopeName = TryParseCXX11AttributeIdentifier(
CommonScopeLoc, Sema::AttributeCompletion::Scope);
CommonScopeLoc, SemaCodeCompletion::AttributeCompletion::Scope);
if (!CommonScopeName) {
Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
SkipUntil(tok::r_square, tok::colon, StopBeforeMatch);
@ -4831,7 +4833,8 @@ void Parser::ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
IdentifierInfo *ScopeName = nullptr, *AttrName = nullptr;
AttrName = TryParseCXX11AttributeIdentifier(
AttrLoc, Sema::AttributeCompletion::Attribute, CommonScopeName);
AttrLoc, SemaCodeCompletion::AttributeCompletion::Attribute,
CommonScopeName);
if (!AttrName)
// Break out to the "expected ']'" diagnostic.
break;
@ -4842,7 +4845,8 @@ void Parser::ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
ScopeLoc = AttrLoc;
AttrName = TryParseCXX11AttributeIdentifier(
AttrLoc, Sema::AttributeCompletion::Attribute, ScopeName);
AttrLoc, SemaCodeCompletion::AttributeCompletion::Attribute,
ScopeName);
if (!AttrName) {
Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
SkipUntil(tok::r_square, tok::comma, StopAtSemi | StopBeforeMatch);
@ -5066,9 +5070,10 @@ void Parser::ParseMicrosoftAttributes(ParsedAttributes &Attrs) {
StopAtSemi | StopBeforeMatch | StopAtCodeCompletion);
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteAttribute(AttributeCommonInfo::AS_Microsoft,
Sema::AttributeCompletion::Attribute,
/*Scope=*/nullptr);
Actions.CodeCompletion().CodeCompleteAttribute(
AttributeCommonInfo::AS_Microsoft,
SemaCodeCompletion::AttributeCompletion::Attribute,
/*Scope=*/nullptr);
break;
}
if (Tok.isNot(tok::identifier)) // ']', but also eof

View File

@ -31,6 +31,7 @@
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaCUDA.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "clang/Sema/SemaObjC.h"
#include "clang/Sema/SemaOpenACC.h"
#include "clang/Sema/SemaOpenMP.h"
@ -168,8 +169,8 @@ Parser::ParseExpressionWithLeadingExtension(SourceLocation ExtLoc) {
ExprResult Parser::ParseAssignmentExpression(TypeCastState isTypeCast) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteExpression(getCurScope(),
PreferredType.get(Tok.getLocation()));
Actions.CodeCompletion().CodeCompleteExpression(
getCurScope(), PreferredType.get(Tok.getLocation()));
return ExprError();
}
@ -187,8 +188,8 @@ ExprResult Parser::ParseAssignmentExpression(TypeCastState isTypeCast) {
ExprResult Parser::ParseConditionalExpression() {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteExpression(getCurScope(),
PreferredType.get(Tok.getLocation()));
Actions.CodeCompletion().CodeCompleteExpression(
getCurScope(), PreferredType.get(Tok.getLocation()));
return ExprError();
}
@ -1215,7 +1216,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
if (Tok.is(tok::code_completion) && &II != Ident_super) {
cutOffParsing();
Actions.CodeCompleteObjCClassPropertyRefExpr(
Actions.CodeCompletion().CodeCompleteObjCClassPropertyRefExpr(
getCurScope(), II, ILoc, ExprStatementTokLoc == ILoc);
return ExprError();
}
@ -1811,8 +1812,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
break;
case tok::code_completion: {
cutOffParsing();
Actions.CodeCompleteExpression(getCurScope(),
PreferredType.get(Tok.getLocation()));
Actions.CodeCompletion().CodeCompleteExpression(
getCurScope(), PreferredType.get(Tok.getLocation()));
return ExprError();
}
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
@ -1956,7 +1957,7 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
return LHS;
cutOffParsing();
Actions.CodeCompletePostfixExpression(
Actions.CodeCompletion().CodeCompletePostfixExpression(
getCurScope(), LHS, PreferredType.get(Tok.getLocation()));
return ExprError();
@ -2154,8 +2155,9 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
ExprVector ArgExprs;
auto RunSignatureHelp = [&]() -> QualType {
QualType PreferredType = Actions.ProduceCallSignatureHelp(
LHS.get(), ArgExprs, PT.getOpenLocation());
QualType PreferredType =
Actions.CodeCompletion().ProduceCallSignatureHelp(
LHS.get(), ArgExprs, PT.getOpenLocation());
CalledSignatureHelp = true;
return PreferredType;
};
@ -2279,7 +2281,7 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
// Code completion for a member access expression.
cutOffParsing();
Actions.CodeCompleteMemberReferenceExpr(
Actions.CodeCompletion().CodeCompleteMemberReferenceExpr(
getCurScope(), Base, CorrectedBase, OpLoc, OpKind == tok::arrow,
Base && ExprStatementTokLoc == Base->getBeginLoc(),
PreferredType.get(Tok.getLocation()));
@ -3001,7 +3003,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteExpression(
Actions.CodeCompletion().CodeCompleteExpression(
getCurScope(), PreferredType.get(Tok.getLocation()),
/*IsParenthesized=*/ExprType >= CompoundLiteral);
return ExprError();
@ -3678,7 +3680,8 @@ bool Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr *> &Exprs) {
void Parser::ParseBlockId(SourceLocation CaretLoc) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Type);
Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), SemaCodeCompletion::PCC_Type);
return;
}
@ -3867,7 +3870,7 @@ std::optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() {
// Parse the platform name.
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteAvailabilityPlatformName();
Actions.CodeCompletion().CodeCompleteAvailabilityPlatformName();
return std::nullopt;
}
if (Tok.isNot(tok::identifier)) {

View File

@ -23,6 +23,7 @@
#include "clang/Sema/EnterExpressionEvaluationContext.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include <numeric>
@ -270,9 +271,9 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
cutOffParsing();
// Code completion for a nested-name-specifier, where the code
// completion token follows the '::'.
Actions.CodeCompleteQualifiedId(getCurScope(), SS, EnteringContext,
InUsingDeclaration, ObjectType.get(),
SavedType.get(SS.getBeginLoc()));
Actions.CodeCompletion().CodeCompleteQualifiedId(
getCurScope(), SS, EnteringContext, InUsingDeclaration,
ObjectType.get(), SavedType.get(SS.getBeginLoc()));
// Include code completion token into the range of the scope otherwise
// when we try to annotate the scope tokens the dangling code completion
// token will cause assertion in
@ -954,8 +955,9 @@ bool Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro,
if (Tok.is(tok::code_completion) &&
!(getLangOpts().ObjC && Tentative)) {
cutOffParsing();
Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro,
/*AfterAmpersand=*/false);
Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
getCurScope(), Intro,
/*AfterAmpersand=*/false);
break;
}
@ -971,10 +973,11 @@ bool Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro,
// If we're in Objective-C++ and we have a bare '[', then this is more
// likely to be a message receiver.
if (getLangOpts().ObjC && Tentative && First)
Actions.CodeCompleteObjCMessageReceiver(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCMessageReceiver(getCurScope());
else
Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro,
/*AfterAmpersand=*/false);
Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
getCurScope(), Intro,
/*AfterAmpersand=*/false);
break;
}
@ -1020,8 +1023,9 @@ bool Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro,
/*AfterAmpersand=*/true);
Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
getCurScope(), Intro,
/*AfterAmpersand=*/true);
break;
}
}
@ -2031,9 +2035,10 @@ Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) {
auto RunSignatureHelp = [&]() {
QualType PreferredType;
if (TypeRep)
PreferredType = Actions.ProduceConstructorSignatureHelp(
TypeRep.get()->getCanonicalTypeInternal(), DS.getEndLoc(), Exprs,
T.getOpenLocation(), /*Braced=*/false);
PreferredType =
Actions.CodeCompletion().ProduceConstructorSignatureHelp(
TypeRep.get()->getCanonicalTypeInternal(), DS.getEndLoc(),
Exprs, T.getOpenLocation(), /*Braced=*/false);
CalledSignatureHelp = true;
return PreferredType;
};
@ -2140,7 +2145,8 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, SourceLocation Loc,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Condition);
Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), SemaCodeCompletion::PCC_Condition);
return Sema::ConditionError();
}
@ -2792,7 +2798,7 @@ bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
// Don't try to parse any further.
cutOffParsing();
// Code completion for the operator name.
Actions.CodeCompleteOperatorName(getCurScope());
Actions.CodeCompletion().CodeCompleteOperatorName(getCurScope());
return true;
}
@ -3350,10 +3356,12 @@ Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) {
// the passing DeclaratorInfo is valid, e.g. running SignatureHelp on
// `new decltype(invalid) (^)`.
if (TypeRep)
PreferredType = Actions.ProduceConstructorSignatureHelp(
TypeRep.get()->getCanonicalTypeInternal(),
DeclaratorInfo.getEndLoc(), ConstructorArgs, ConstructorLParen,
/*Braced=*/false);
PreferredType =
Actions.CodeCompletion().ProduceConstructorSignatureHelp(
TypeRep.get()->getCanonicalTypeInternal(),
DeclaratorInfo.getEndLoc(), ConstructorArgs,
ConstructorLParen,
/*Braced=*/false);
CalledSignatureHelp = true;
return PreferredType;
};

View File

@ -18,6 +18,7 @@
#include "clang/Sema/EnterExpressionEvaluationContext.h"
#include "clang/Sema/Ownership.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "clang/Sema/SemaObjC.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
@ -204,8 +205,9 @@ ExprResult Parser::ParseInitializerWithPotentialDesignator(
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteDesignator(DesignatorCompletion.PreferredBaseType,
DesignatorCompletion.InitExprs, Desig);
Actions.CodeCompletion().CodeCompleteDesignator(
DesignatorCompletion.PreferredBaseType,
DesignatorCompletion.InitExprs, Desig);
return ExprError();
}
if (Tok.isNot(tok::identifier)) {
@ -471,7 +473,7 @@ ExprResult Parser::ParseBraceInitializer() {
auto RunSignatureHelp = [&] {
QualType PreferredType;
if (!LikelyType.isNull())
PreferredType = Actions.ProduceConstructorSignatureHelp(
PreferredType = Actions.CodeCompletion().ProduceConstructorSignatureHelp(
LikelyType->getCanonicalTypeInternal(), T.getOpenLocation(),
InitExprs, T.getOpenLocation(), /*Braced=*/true);
CalledSignatureHelp = true;

View File

@ -20,6 +20,7 @@
#include "clang/Parse/RAIIObjectsForParser.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "clang/Sema/SemaObjC.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
@ -56,7 +57,7 @@ Parser::ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCAtDirective(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCAtDirective(getCurScope());
return nullptr;
}
@ -156,7 +157,7 @@ Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) {
MaybeSkipAttributes(tok::objc_class);
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCClassForwardDecl(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCClassForwardDecl(getCurScope());
return Actions.ConvertDeclToDeclGroup(nullptr);
}
if (expectIdentifier()) {
@ -242,7 +243,7 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
// Code completion after '@interface'.
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCInterfaceDecl(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCInterfaceDecl(getCurScope());
return nullptr;
}
@ -276,7 +277,8 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
IdentifierInfo *categoryId = nullptr;
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc);
Actions.CodeCompletion().CodeCompleteObjCInterfaceCategory(
getCurScope(), nameId, nameLoc);
return nullptr;
}
@ -331,7 +333,8 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
// Code completion of superclass names.
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc);
Actions.CodeCompletion().CodeCompleteObjCSuperclass(getCurScope(), nameId,
nameLoc);
return nullptr;
}
@ -508,7 +511,8 @@ ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs(
// FIXME: If these aren't protocol references, we'll need different
// completions.
cutOffParsing();
Actions.CodeCompleteObjCProtocolReferences(protocolIdents);
Actions.CodeCompletion().CodeCompleteObjCProtocolReferences(
protocolIdents);
// FIXME: Better recovery here?.
return nullptr;
@ -681,9 +685,10 @@ void Parser::ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey,
// Code completion within an Objective-C interface.
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteOrdinaryName(getCurScope(),
CurParsedObjCImpl? Sema::PCC_ObjCImplementation
: Sema::PCC_ObjCInterface);
Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), CurParsedObjCImpl
? SemaCodeCompletion::PCC_ObjCImplementation
: SemaCodeCompletion::PCC_ObjCInterface);
return;
}
@ -720,7 +725,7 @@ void Parser::ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey,
const auto &NextTok = NextToken();
if (NextTok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCAtDirective(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCAtDirective(getCurScope());
return;
}
@ -895,7 +900,7 @@ void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) {
while (true) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS);
Actions.CodeCompletion().CodeCompleteObjCPropertyFlags(getCurScope(), DS);
return;
}
const IdentifierInfo *II = Tok.getIdentifierInfo();
@ -943,9 +948,11 @@ void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
if (IsSetter)
Actions.CodeCompleteObjCPropertySetter(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCPropertySetter(
getCurScope());
else
Actions.CodeCompleteObjCPropertyGetter(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCPropertyGetter(
getCurScope());
return;
}
@ -1196,7 +1203,7 @@ void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
while (true) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCPassingType(
Actions.CodeCompletion().CodeCompleteObjCPassingType(
getCurScope(), DS, Context == DeclaratorContext::ObjCParameter);
return;
}
@ -1390,8 +1397,9 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus,
/*ReturnType=*/nullptr);
Actions.CodeCompletion().CodeCompleteObjCMethodDecl(getCurScope(),
mType == tok::minus,
/*ReturnType=*/nullptr);
return nullptr;
}
@ -1409,8 +1417,8 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus,
ReturnType);
Actions.CodeCompletion().CodeCompleteObjCMethodDecl(
getCurScope(), mType == tok::minus, ReturnType);
return nullptr;
}
@ -1472,10 +1480,9 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
KeyIdents.push_back(SelIdent);
Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(),
mType == tok::minus,
/*AtParameterName=*/true,
ReturnType, KeyIdents);
Actions.CodeCompletion().CodeCompleteObjCMethodDeclSelector(
getCurScope(), mType == tok::minus,
/*AtParameterName=*/true, ReturnType, KeyIdents);
return nullptr;
}
@ -1496,10 +1503,9 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
// Code completion for the next piece of the selector.
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(),
mType == tok::minus,
/*AtParameterName=*/false,
ReturnType, KeyIdents);
Actions.CodeCompletion().CodeCompleteObjCMethodDeclSelector(
getCurScope(), mType == tok::minus,
/*AtParameterName=*/false, ReturnType, KeyIdents);
return nullptr;
}
@ -1584,7 +1590,8 @@ ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &Protocols,
while (true) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents);
Actions.CodeCompletion().CodeCompleteObjCProtocolReferences(
ProtocolIdents);
return true;
}
@ -1682,9 +1689,11 @@ void Parser::parseObjCTypeArgsOrProtocolQualifiers(
QualType BaseT = Actions.GetTypeFromParser(baseType);
cutOffParsing();
if (!BaseT.isNull() && BaseT->acceptsObjCTypeParams()) {
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Type);
Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), SemaCodeCompletion::PCC_Type);
} else {
Actions.CodeCompleteObjCProtocolReferences(identifierLocPairs);
Actions.CodeCompletion().CodeCompleteObjCProtocolReferences(
identifierLocPairs);
}
return;
}
@ -1959,7 +1968,7 @@ void Parser::ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
if (TryConsumeToken(tok::at)) { // parse objc-visibility-spec
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCAtVisibility(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCAtVisibility(getCurScope());
return;
}
@ -1990,8 +1999,8 @@ void Parser::ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteOrdinaryName(getCurScope(),
Sema::PCC_ObjCInstanceVariableList);
Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), SemaCodeCompletion::PCC_ObjCInstanceVariableList);
return;
}
@ -2058,7 +2067,7 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCProtocolDecl(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCProtocolDecl(getCurScope());
return nullptr;
}
@ -2156,7 +2165,7 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
// Code completion after '@implementation'.
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCImplementationDecl(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCImplementationDecl(getCurScope());
return nullptr;
}
@ -2194,7 +2203,8 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc);
Actions.CodeCompletion().CodeCompleteObjCImplementationCategory(
getCurScope(), nameId, nameLoc);
return nullptr;
}
@ -2368,7 +2378,8 @@ Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) {
while (true) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCPropertyDefinition(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCPropertyDefinition(
getCurScope());
return nullptr;
}
@ -2386,7 +2397,8 @@ Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) {
// property '=' ivar-name
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId);
Actions.CodeCompletion().CodeCompleteObjCPropertySynthesizeIvar(
getCurScope(), propertyId);
return nullptr;
}
@ -2445,7 +2457,8 @@ Decl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) {
while (true) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCPropertyDefinition(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCPropertyDefinition(
getCurScope());
return nullptr;
}
@ -2784,7 +2797,7 @@ StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc,
ParsedStmtContext StmtCtx) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCAtStatement(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCAtStatement(getCurScope());
return StmtError();
}
@ -2825,7 +2838,7 @@ ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
switch (Tok.getKind()) {
case tok::code_completion:
cutOffParsing();
Actions.CodeCompleteObjCAtExpression(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCAtExpression(getCurScope());
return ExprError();
case tok::minus:
@ -3073,7 +3086,7 @@ ExprResult Parser::ParseObjCMessageExpression() {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCMessageReceiver(getCurScope());
Actions.CodeCompletion().CodeCompleteObjCMessageReceiver(getCurScope());
return ExprError();
}
@ -3210,14 +3223,14 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
if (SuperLoc.isValid())
Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc,
std::nullopt, false);
Actions.CodeCompletion().CodeCompleteObjCSuperMessage(
getCurScope(), SuperLoc, std::nullopt, false);
else if (ReceiverType)
Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType,
std::nullopt, false);
Actions.CodeCompletion().CodeCompleteObjCClassMessage(
getCurScope(), ReceiverType, std::nullopt, false);
else
Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr,
std::nullopt, false);
Actions.CodeCompletion().CodeCompleteObjCInstanceMessage(
getCurScope(), ReceiverExpr, std::nullopt, false);
return ExprError();
}
@ -3248,17 +3261,17 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
if (SuperLoc.isValid())
Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc,
KeyIdents,
/*AtArgumentExpression=*/true);
Actions.CodeCompletion().CodeCompleteObjCSuperMessage(
getCurScope(), SuperLoc, KeyIdents,
/*AtArgumentExpression=*/true);
else if (ReceiverType)
Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType,
KeyIdents,
/*AtArgumentExpression=*/true);
Actions.CodeCompletion().CodeCompleteObjCClassMessage(
getCurScope(), ReceiverType, KeyIdents,
/*AtArgumentExpression=*/true);
else
Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr,
KeyIdents,
/*AtArgumentExpression=*/true);
Actions.CodeCompletion().CodeCompleteObjCInstanceMessage(
getCurScope(), ReceiverExpr, KeyIdents,
/*AtArgumentExpression=*/true);
return ExprError();
}
@ -3286,17 +3299,17 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
if (SuperLoc.isValid())
Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc,
KeyIdents,
/*AtArgumentExpression=*/false);
Actions.CodeCompletion().CodeCompleteObjCSuperMessage(
getCurScope(), SuperLoc, KeyIdents,
/*AtArgumentExpression=*/false);
else if (ReceiverType)
Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType,
KeyIdents,
/*AtArgumentExpression=*/false);
Actions.CodeCompletion().CodeCompleteObjCClassMessage(
getCurScope(), ReceiverType, KeyIdents,
/*AtArgumentExpression=*/false);
else
Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr,
KeyIdents,
/*AtArgumentExpression=*/false);
Actions.CodeCompletion().CodeCompleteObjCInstanceMessage(
getCurScope(), ReceiverExpr, KeyIdents,
/*AtArgumentExpression=*/false);
return ExprError();
}
@ -3637,7 +3650,7 @@ ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents);
Actions.CodeCompletion().CodeCompleteObjCSelector(getCurScope(), KeyIdents);
return ExprError();
}
@ -3663,7 +3676,8 @@ ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents);
Actions.CodeCompletion().CodeCompleteObjCSelector(getCurScope(),
KeyIdents);
return ExprError();
}

View File

@ -21,6 +21,7 @@
#include "clang/Parse/RAIIObjectsForParser.h"
#include "clang/Sema/EnterExpressionEvaluationContext.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "clang/Sema/SemaOpenMP.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/StringSwitch.h"
@ -460,7 +461,8 @@ void Parser::ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteInitializer(getCurScope(), OmpPrivParm);
Actions.CodeCompletion().CodeCompleteInitializer(getCurScope(),
OmpPrivParm);
Actions.FinalizeDeclaration(OmpPrivParm);
return;
}
@ -484,9 +486,10 @@ void Parser::ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm) {
SourceLocation LParLoc = T.getOpenLocation();
auto RunSignatureHelp = [this, OmpPrivParm, LParLoc, &Exprs]() {
QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
OmpPrivParm->getType()->getCanonicalTypeInternal(),
OmpPrivParm->getLocation(), Exprs, LParLoc, /*Braced=*/false);
QualType PreferredType =
Actions.CodeCompletion().ProduceConstructorSignatureHelp(
OmpPrivParm->getType()->getCanonicalTypeInternal(),
OmpPrivParm->getLocation(), Exprs, LParLoc, /*Braced=*/false);
CalledSignatureHelp = true;
return PreferredType;
};

View File

@ -22,6 +22,7 @@
#include "clang/Sema/EnterExpressionEvaluationContext.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaCUDA.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringSwitch.h"
#include <optional>
@ -1924,7 +1925,8 @@ void Parser::HandlePragmaAttribute() {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
// FIXME: suppress completion of unsupported attributes?
Actions.CodeCompleteAttribute(AttributeCommonInfo::Syntax::AS_GNU);
Actions.CodeCompletion().CodeCompleteAttribute(
AttributeCommonInfo::Syntax::AS_GNU);
return SkipToEnd();
}

View File

@ -22,6 +22,7 @@
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/EnterExpressionEvaluationContext.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "clang/Sema/SemaObjC.h"
#include "clang/Sema/SemaOpenMP.h"
#include "clang/Sema/TypoCorrection.h"
@ -191,7 +192,8 @@ Retry:
case tok::code_completion:
cutOffParsing();
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Statement);
Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), SemaCodeCompletion::PCC_Statement);
return StmtError();
case tok::identifier:
@ -843,7 +845,7 @@ StmtResult Parser::ParseCaseStatement(ParsedStmtContext StmtCtx,
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteCase(getCurScope());
Actions.CodeCompletion().CodeCompleteCase(getCurScope());
return StmtError();
}
@ -1649,7 +1651,7 @@ StmtResult Parser::ParseIfStatement(SourceLocation *TrailingElseLoc) {
InnerScope.Exit();
} else if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteAfterIf(getCurScope(), IsBracedThen);
Actions.CodeCompletion().CodeCompleteAfterIf(getCurScope(), IsBracedThen);
return StmtError();
} else if (InnerStatementTrailingElseLoc.isValid()) {
Diag(InnerStatementTrailingElseLoc, diag::warn_dangling_else);
@ -2040,9 +2042,9 @@ StmtResult Parser::ParseForStatement(SourceLocation *TrailingElseLoc) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteOrdinaryName(getCurScope(),
C99orCXXorObjC? Sema::PCC_ForInit
: Sema::PCC_Expression);
Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), C99orCXXorObjC ? SemaCodeCompletion::PCC_ForInit
: SemaCodeCompletion::PCC_Expression);
return StmtError();
}
@ -2117,7 +2119,8 @@ StmtResult Parser::ParseForStatement(SourceLocation *TrailingElseLoc) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCForCollection(getCurScope(), DG);
Actions.CodeCompletion().CodeCompleteObjCForCollection(getCurScope(),
DG);
return StmtError();
}
Collection = ParseExpression();
@ -2154,7 +2157,8 @@ StmtResult Parser::ParseForStatement(SourceLocation *TrailingElseLoc) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCForCollection(getCurScope(), nullptr);
Actions.CodeCompletion().CodeCompleteObjCForCollection(getCurScope(),
nullptr);
return StmtError();
}
Collection = ParseExpression();
@ -2431,8 +2435,8 @@ StmtResult Parser::ParseReturnStatement() {
// FIXME: Code completion for co_return.
if (Tok.is(tok::code_completion) && !IsCoreturn) {
cutOffParsing();
Actions.CodeCompleteExpression(getCurScope(),
PreferredType.get(Tok.getLocation()));
Actions.CodeCompletion().CodeCompleteExpression(
getCurScope(), PreferredType.get(Tok.getLocation()));
return StmtError();
}

View File

@ -1541,8 +1541,8 @@ bool Parser::ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
if (!Template)
return QualType();
CalledSignatureHelp = true;
return Actions.ProduceTemplateArgumentSignatureHelp(Template, TemplateArgs,
OpenLoc);
return Actions.CodeCompletion().ProduceTemplateArgumentSignatureHelp(
Template, TemplateArgs, OpenLoc);
};
do {

View File

@ -21,6 +21,7 @@
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/TimeProfiler.h"
using namespace clang;
@ -944,20 +945,21 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
cutOffParsing();
if (CurParsedObjCImpl) {
// Code-complete Objective-C methods even without leading '-'/'+' prefix.
Actions.CodeCompleteObjCMethodDecl(getCurScope(),
/*IsInstanceMethod=*/std::nullopt,
/*ReturnType=*/nullptr);
Actions.CodeCompletion().CodeCompleteObjCMethodDecl(
getCurScope(),
/*IsInstanceMethod=*/std::nullopt,
/*ReturnType=*/nullptr);
}
Sema::ParserCompletionContext PCC;
SemaCodeCompletion::ParserCompletionContext PCC;
if (CurParsedObjCImpl) {
PCC = Sema::PCC_ObjCImplementation;
PCC = SemaCodeCompletion::PCC_ObjCImplementation;
} else if (PP.isIncrementalProcessingEnabled()) {
PCC = Sema::PCC_TopLevelOrExpression;
PCC = SemaCodeCompletion::PCC_TopLevelOrExpression;
} else {
PCC = Sema::PCC_Namespace;
PCC = SemaCodeCompletion::PCC_Namespace;
};
Actions.CodeCompleteOrdinaryName(getCurScope(), PCC);
Actions.CodeCompletion().CodeCompleteOrdinaryName(getCurScope(), PCC);
return nullptr;
case tok::kw_import: {
Sema::ModuleImportState IS = Sema::ModuleImportState::NotACXX20Module;
@ -2281,54 +2283,57 @@ SourceLocation Parser::handleUnexpectedCodeCompletionToken() {
for (Scope *S = getCurScope(); S; S = S->getParent()) {
if (S->isFunctionScope()) {
cutOffParsing();
Actions.CodeCompleteOrdinaryName(getCurScope(),
Sema::PCC_RecoveryInFunction);
Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), SemaCodeCompletion::PCC_RecoveryInFunction);
return PrevTokLocation;
}
if (S->isClassScope()) {
cutOffParsing();
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Class);
Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), SemaCodeCompletion::PCC_Class);
return PrevTokLocation;
}
}
cutOffParsing();
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Namespace);
Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), SemaCodeCompletion::PCC_Namespace);
return PrevTokLocation;
}
// Code-completion pass-through functions
void Parser::CodeCompleteDirective(bool InConditional) {
Actions.CodeCompletePreprocessorDirective(InConditional);
Actions.CodeCompletion().CodeCompletePreprocessorDirective(InConditional);
}
void Parser::CodeCompleteInConditionalExclusion() {
Actions.CodeCompleteInPreprocessorConditionalExclusion(getCurScope());
Actions.CodeCompletion().CodeCompleteInPreprocessorConditionalExclusion(
getCurScope());
}
void Parser::CodeCompleteMacroName(bool IsDefinition) {
Actions.CodeCompletePreprocessorMacroName(IsDefinition);
Actions.CodeCompletion().CodeCompletePreprocessorMacroName(IsDefinition);
}
void Parser::CodeCompletePreprocessorExpression() {
Actions.CodeCompletePreprocessorExpression();
Actions.CodeCompletion().CodeCompletePreprocessorExpression();
}
void Parser::CodeCompleteMacroArgument(IdentifierInfo *Macro,
MacroInfo *MacroInfo,
unsigned ArgumentIndex) {
Actions.CodeCompletePreprocessorMacroArgument(getCurScope(), Macro, MacroInfo,
ArgumentIndex);
Actions.CodeCompletion().CodeCompletePreprocessorMacroArgument(
getCurScope(), Macro, MacroInfo, ArgumentIndex);
}
void Parser::CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled) {
Actions.CodeCompleteIncludedFile(Dir, IsAngled);
Actions.CodeCompletion().CodeCompleteIncludedFile(Dir, IsAngled);
}
void Parser::CodeCompleteNaturalLanguage() {
Actions.CodeCompleteNaturalLanguage();
Actions.CodeCompletion().CodeCompleteNaturalLanguage();
}
bool Parser::ParseMicrosoftIfExistsCondition(IfExistsCondition& Result) {
@ -2682,7 +2687,7 @@ bool Parser::ParseModuleName(
if (!Tok.is(tok::identifier)) {
if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteModuleImport(UseLoc, Path);
Actions.CodeCompletion().CodeCompleteModuleImport(UseLoc, Path);
return true;
}

View File

@ -42,6 +42,7 @@
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaCUDA.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "clang/Sema/SemaConsumer.h"
#include "clang/Sema/SemaHLSL.h"
#include "clang/Sema/SemaInternal.h"
@ -202,6 +203,8 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
LateTemplateParser(nullptr), LateTemplateParserCleanup(nullptr),
OpaqueParser(nullptr), CurContext(nullptr), ExternalSource(nullptr),
CurScope(nullptr), Ident_super(nullptr),
CodeCompletionPtr(
std::make_unique<SemaCodeCompletion>(*this, CodeCompleter)),
CUDAPtr(std::make_unique<SemaCUDA>(*this)),
HLSLPtr(std::make_unique<SemaHLSL>(*this)),
ObjCPtr(std::make_unique<SemaObjC>(*this)),
@ -225,8 +228,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
TyposCorrected(0), IsBuildingRecoveryCallExpr(false), NumSFINAEErrors(0),
AccessCheckingSFINAE(false), CurrentInstantiationScope(nullptr),
InNonInstantiationSFINAEContext(false), NonInstantiationEntries(0),
ArgumentPackSubstitutionIndex(-1), SatisfactionCache(Context),
CodeCompleter(CodeCompleter) {
ArgumentPackSubstitutionIndex(-1), SatisfactionCache(Context) {
assert(pp.TUKind == TUKind);
TUScope = nullptr;

File diff suppressed because it is too large Load Diff