clang 20.0.0git
SemaCodeCompletion.h
Go to the documentation of this file.
1//===----- SemaCodeCompletion.h ------ Code completion support ------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file declares facilities that support code completion.
10///
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_SEMA_SEMACODECOMPLETION_H
14#define LLVM_CLANG_SEMA_SEMACODECOMPLETION_H
15
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclCXX.h"
18#include "clang/AST/Expr.h"
19#include "clang/AST/Type.h"
22#include "clang/Basic/LLVM.h"
24#include "clang/Lex/MacroInfo.h"
27#include "clang/Sema/DeclSpec.h"
30#include "clang/Sema/Scope.h"
31#include "clang/Sema/SemaBase.h"
32#include "llvm/ADT/StringRef.h"
33#include <optional>
34
35namespace clang {
36
38public:
39 SemaCodeCompletion(Sema &S, CodeCompleteConsumer *CompletionConsumer);
40
43
44 /// Code-completion consumer.
46
47 /// Describes the context in which code completion occurs.
49 /// Code completion occurs at top-level or namespace context.
51 /// Code completion occurs within a class, struct, or union.
53 /// Code completion occurs within an Objective-C interface, protocol,
54 /// or category.
56 /// Code completion occurs within an Objective-C implementation or
57 /// category implementation
59 /// Code completion occurs within the list of instance variables
60 /// in an Objective-C interface, protocol, category, or implementation.
62 /// Code completion occurs following one or more template
63 /// headers.
65 /// Code completion occurs following one or more template
66 /// headers within a class.
68 /// Code completion occurs within an expression.
70 /// Code completion occurs within a statement, which may
71 /// also be an expression or a declaration.
73 /// Code completion occurs at the beginning of the
74 /// initialization statement (or expression) in a for loop.
76 /// Code completion occurs within the condition of an if,
77 /// while, switch, or for statement.
79 /// Code completion occurs within the body of a function on a
80 /// recovery path, where we do not have a specific handle on our position
81 /// in the grammar.
83 /// Code completion occurs where only a type is permitted.
85 /// Code completion occurs in a parenthesized expression, which
86 /// might also be a type cast.
88 /// Code completion occurs within a sequence of declaration
89 /// specifiers within a function, method, or block.
91 /// Code completion occurs at top-level in a REPL session
93 };
94
97 ParserCompletionContext CompletionContext);
98 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, bool AllowNonIdentifiers,
99 bool AllowNestedNameSpecifiers);
100
101 struct CodeCompleteExpressionData;
102 void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data);
103 void CodeCompleteExpression(Scope *S, QualType PreferredType,
104 bool IsParenthesized = false);
105 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase,
106 SourceLocation OpLoc, bool IsArrow,
107 bool IsBaseExprStatement,
108 QualType PreferredType);
110 QualType PreferredType);
111 void CodeCompleteTag(Scope *S, unsigned TagSpec);
114 const VirtSpecifiers *VS = nullptr);
116 void CodeCompleteCase(Scope *S);
118 Attribute,
119 Scope,
120 None,
121 };
125 const IdentifierInfo *Scope = nullptr);
126 /// Determines the preferred type of the current function argument, by
127 /// examining the signatures of all possible overloads.
128 /// Returns null if unknown or ambiguous, or if code completion is off.
129 ///
130 /// If the code completion point has been reached, also reports the function
131 /// signatures that were considered.
132 ///
133 /// FIXME: rename to GuessCallArgumentType to reduce confusion.
135 SourceLocation OpenParLoc);
137 ArrayRef<Expr *> Args,
138 SourceLocation OpenParLoc,
139 bool Braced);
141 Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy,
142 ArrayRef<Expr *> ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc,
143 bool Braced);
147 /// Trigger code completion for a record of \p BaseType. \p InitExprs are
148 /// expressions in the initializer list seen so far and \p D is the current
149 /// Designation being parsed.
150 void CodeCompleteDesignator(const QualType BaseType,
151 llvm::ArrayRef<Expr *> InitExprs,
152 const Designation &D);
153 void CodeCompleteAfterIf(Scope *S, bool IsBracedThen);
154
155 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext,
156 bool IsUsingDeclaration, QualType BaseType,
157 QualType PreferredType);
158 void CodeCompleteUsing(Scope *S);
164 Decl *Constructor, ArrayRef<CXXCtorInitializer *> Initializers);
165
167 bool AfterAmpersand);
169
178 bool IsParameter);
182 bool AtArgumentExpression);
185 bool AtArgumentExpression,
186 bool IsSuper = false);
188 Scope *S, Expr *Receiver, ArrayRef<const IdentifierInfo *> SelIdents,
189 bool AtArgumentExpression, ObjCInterfaceDecl *Super = nullptr);
193 void
199 SourceLocation ClassNameLoc);
202 SourceLocation ClassNameLoc);
204 IdentifierInfo *ClassName,
205 SourceLocation ClassNameLoc);
208 IdentifierInfo *PropertyName);
210 std::optional<bool> IsInstanceMethod,
211 ParsedType ReturnType);
213 Scope *S, bool IsInstanceMethod, bool AtParameterName,
214 ParsedType ReturnType, ArrayRef<const IdentifierInfo *> SelIdents);
216 const IdentifierInfo &ClassName,
217 SourceLocation ClassNameLoc,
218 bool IsBaseExprStatement);
219 void CodeCompletePreprocessorDirective(bool InConditional);
221 void CodeCompletePreprocessorMacroName(bool IsDefinition);
225 unsigned Argument);
226 void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled);
229 void
231 CodeCompletionTUInfo &CCTUInfo,
233};
234
235} // namespace clang
236
237#endif // LLVM_CLANG_SEMA_SEMACODECOMPLETION_H
const Decl * D
IndirectLocalPath & Path
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::MacroInfo and clang::MacroDirective classes.
SourceLocation Loc
Definition: SemaObjC.cpp:758
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
Syntax
The style used to specify an attribute.
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:74
Abstract interface for a consumer of code-completion information.
An allocator used specifically for the purpose of code completion.
Captures information about "declaration specifiers".
Definition: DeclSpec.h:247
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1900
Designation - Represent a full designation, which is a sequence of designators.
Definition: Designator.h:208
This represents one expression.
Definition: Expr.h:110
One of these records is kept for each identifier that is lexed.
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
Captures information about "declaration specifiers" specific to Objective-C.
Definition: DeclSpec.h:897
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
A (possibly-)qualified type.
Definition: Type.h:941
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:41
void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, ArrayRef< const IdentifierInfo * > SelIdents, bool AtArgumentExpression, ObjCInterfaceDecl *Super=nullptr)
void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, IdentifierInfo *PropertyName)
void CodeCompleteAttribute(AttributeCommonInfo::Syntax Syntax, AttributeCompletion Completion=AttributeCompletion::Attribute, const IdentifierInfo *Scope=nullptr)
QualType ProduceTemplateArgumentSignatureHelp(TemplateTy, ArrayRef< ParsedTemplateArgument >, SourceLocation LAngleLoc)
QualType ProduceCtorInitMemberSignatureHelp(Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy, ArrayRef< Expr * > ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc, bool Braced)
void CodeCompleteObjCClassForwardDecl(Scope *S)
void CodeCompleteNamespaceAliasDecl(Scope *S)
void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, SmallVectorImpl< CodeCompletionResult > &Results)
void CodeCompleteObjCAtStatement(Scope *S)
void CodeCompleteObjCMessageReceiver(Scope *S)
void CodeCompleteOperatorName(Scope *S)
void CodeCompleteUsingDirective(Scope *S)
void CodeCompleteObjCProtocolDecl(Scope *S)
void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS)
ParserCompletionContext
Describes the context in which code completion occurs.
@ PCC_LocalDeclarationSpecifiers
Code completion occurs within a sequence of declaration specifiers within a function,...
@ PCC_MemberTemplate
Code completion occurs following one or more template headers within a class.
@ PCC_Condition
Code completion occurs within the condition of an if, while, switch, or for statement.
@ PCC_ParenthesizedExpression
Code completion occurs in a parenthesized expression, which might also be a type cast.
@ PCC_TopLevelOrExpression
Code completion occurs at top-level in a REPL session.
@ PCC_Class
Code completion occurs within a class, struct, or union.
@ PCC_ForInit
Code completion occurs at the beginning of the initialization statement (or expression) in a for loop...
@ PCC_Type
Code completion occurs where only a type is permitted.
@ PCC_ObjCImplementation
Code completion occurs within an Objective-C implementation or category implementation.
@ PCC_ObjCInterface
Code completion occurs within an Objective-C interface, protocol, or category.
@ PCC_Namespace
Code completion occurs at top-level or namespace context.
@ PCC_Expression
Code completion occurs within an expression.
@ PCC_RecoveryInFunction
Code completion occurs within the body of a function on a recovery path, where we do not have a speci...
@ PCC_ObjCInstanceVariableList
Code completion occurs within the list of instance variables in an Objective-C interface,...
@ PCC_Template
Code completion occurs following one or more template headers.
@ PCC_Statement
Code completion occurs within a statement, which may also be an expression or a declaration.
void CodeCompleteObjCAtDirective(Scope *S)
void CodeCompleteObjCPropertySetter(Scope *S)
void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, bool AfterAmpersand)
void CodeCompleteObjCImplementationCategory(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc)
void CodeCompleteObjCInterfaceDecl(Scope *S)
void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D, const VirtSpecifiers *VS=nullptr)
void CodeCompletePreprocessorMacroName(bool IsDefinition)
void CodeCompleteInPreprocessorConditionalExclusion(Scope *S)
void CodeCompleteObjCAtExpression(Scope *S)
void CodeCompleteTypeQualifiers(DeclSpec &DS)
void CodeCompleteObjCPropertyDefinition(Scope *S)
void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, ArrayRef< const IdentifierInfo * > SelIdents, bool AtArgumentExpression)
CodeCompleteConsumer * CodeCompleter
Code-completion consumer.
void CodeCompleteAfterFunctionEquals(Declarator &D)
QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc, ArrayRef< Expr * > Args, SourceLocation OpenParLoc, bool Braced)
OpaquePtr< TemplateName > TemplateTy
void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data)
Perform code-completion in an expression context when we know what type we're looking for.
QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef< Expr * > Args, SourceLocation OpenParLoc)
Determines the preferred type of the current function argument, by examining the signatures of all po...
void CodeCompleteObjCMethodDeclSelector(Scope *S, bool IsInstanceMethod, bool AtParameterName, ParsedType ReturnType, ArrayRef< const IdentifierInfo * > SelIdents)
void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, bool IsUsingDeclaration, QualType BaseType, QualType PreferredType)
void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled)
void CodeCompletePreprocessorMacroArgument(Scope *S, IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned Argument)
void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path)
void CodeCompleteObjCInterfaceCategory(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc)
void CodeCompleteObjCSelector(Scope *S, ArrayRef< const IdentifierInfo * > SelIdents)
void CodeCompleteConstructorInitializer(Decl *Constructor, ArrayRef< CXXCtorInitializer * > Initializers)
void CodeCompleteObjCImplementationDecl(Scope *S)
void CodeCompleteAfterIf(Scope *S, bool IsBracedThen)
void CodeCompleteObjCMethodDecl(Scope *S, std::optional< bool > IsInstanceMethod, ParsedType ReturnType)
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
void CodeCompleteObjCProtocolReferences(ArrayRef< IdentifierLocPair > Protocols)
void CodeCompleteObjCClassPropertyRefExpr(Scope *S, const IdentifierInfo &ClassName, SourceLocation ClassNameLoc, bool IsBaseExprStatement)
void CodeCompleteInitializer(Scope *S, Decl *D)
void CodeCompleteNamespaceDecl(Scope *S)
void CodeCompleteDesignator(const QualType BaseType, llvm::ArrayRef< Expr * > InitExprs, const Designation &D)
Trigger code completion for a record of BaseType.
void CodeCompletePreprocessorDirective(bool InConditional)
void CodeCompleteBracketDeclarator(Scope *S)
void CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc)
void CodeCompleteObjCAtVisibility(Scope *S)
void CodeCompleteTag(Scope *S, unsigned TagSpec)
void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, ArrayRef< const IdentifierInfo * > SelIdents, bool AtArgumentExpression, bool IsSuper=false)
void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar)
void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase, SourceLocation OpLoc, bool IsArrow, bool IsBaseExprStatement, QualType PreferredType)
void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, bool IsParameter)
void CodeCompleteObjCPropertyGetter(Scope *S)
void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, bool AllowNonIdentifiers, bool AllowNestedNameSpecifiers)
void CodeCompletePostfixExpression(Scope *S, ExprResult LHS, QualType PreferredType)
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:535
Encodes a location in the source.
The base class of the type hierarchy.
Definition: Type.h:1829
Represents a C++11 virt-specifier-seq.
Definition: DeclSpec.h:2780
The JSON file list parser is used to communicate input to InstallAPI.
Represents a complete lambda introducer.
Definition: DeclSpec.h:2832