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/ASTFwd.h"
17#include "clang/AST/Type.h"
20#include "clang/Basic/LLVM.h"
24#include "clang/Sema/DeclSpec.h"
28#include "clang/Sema/SemaBase.h"
29#include "llvm/ADT/StringRef.h"
30#include <optional>
31
32namespace clang {
33class DeclGroupRef;
34class MacroInfo;
35class Scope;
36class TemplateName;
37
39public:
40 SemaCodeCompletion(Sema &S, CodeCompleteConsumer *CompletionConsumer);
41
44
45 /// Code-completion consumer.
48
49 /// Describes the context in which code completion occurs.
51 /// Code completion occurs at top-level or namespace context.
53 /// Code completion occurs within a class, struct, or union.
55 /// Code completion occurs within an Objective-C interface, protocol,
56 /// or category.
58 /// Code completion occurs within an Objective-C implementation or
59 /// category implementation
61 /// Code completion occurs within the list of instance variables
62 /// in an Objective-C interface, protocol, category, or implementation.
64 /// Code completion occurs following one or more template
65 /// headers.
67 /// Code completion occurs following one or more template
68 /// headers within a class.
70 /// Code completion occurs within an expression.
72 /// Code completion occurs within a statement, which may
73 /// also be an expression or a declaration.
75 /// Code completion occurs at the beginning of the
76 /// initialization statement (or expression) in a for loop.
78 /// Code completion occurs within the condition of an if,
79 /// while, switch, or for statement.
81 /// Code completion occurs within the body of a function on a
82 /// recovery path, where we do not have a specific handle on our position
83 /// in the grammar.
85 /// Code completion occurs where only a type is permitted.
87 /// Code completion occurs in a parenthesized expression, which
88 /// might also be a type cast.
90 /// Code completion occurs within a sequence of declaration
91 /// specifiers within a function, method, or block.
93 /// Code completion occurs at top-level in a REPL session
95 };
96
99 ParserCompletionContext CompletionContext);
100 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, bool AllowNonIdentifiers,
101 bool AllowNestedNameSpecifiers);
102
103 struct CodeCompleteExpressionData;
104 void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data);
105 void CodeCompleteExpression(Scope *S, QualType PreferredType,
106 bool IsParenthesized = false);
107 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase,
108 SourceLocation OpLoc, bool IsArrow,
109 bool IsBaseExprStatement,
110 QualType PreferredType);
112 QualType PreferredType);
113 void CodeCompleteTag(Scope *S, unsigned TagSpec);
116 const VirtSpecifiers *VS = nullptr);
118 void CodeCompleteCase(Scope *S);
120 Attribute,
121 Scope,
122 None,
123 };
127 const IdentifierInfo *Scope = nullptr);
128 /// Determines the preferred type of the current function argument, by
129 /// examining the signatures of all possible overloads.
130 /// Returns null if unknown or ambiguous, or if code completion is off.
131 ///
132 /// If the code completion point has been reached, also reports the function
133 /// signatures that were considered.
134 ///
135 /// FIXME: rename to GuessCallArgumentType to reduce confusion.
137 SourceLocation OpenParLoc);
139 ArrayRef<Expr *> Args,
140 SourceLocation OpenParLoc,
141 bool Braced);
143 Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy,
144 ArrayRef<Expr *> ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc,
145 bool Braced);
149 /// Trigger code completion for a record of \p BaseType. \p InitExprs are
150 /// expressions in the initializer list seen so far and \p D is the current
151 /// Designation being parsed.
152 void CodeCompleteDesignator(const QualType BaseType,
153 llvm::ArrayRef<Expr *> InitExprs,
154 const Designation &D);
155 void CodeCompleteAfterIf(Scope *S, bool IsBracedThen);
156
157 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext,
158 bool IsUsingDeclaration, QualType BaseType,
159 QualType PreferredType);
160 void CodeCompleteUsing(Scope *S);
161 void