Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:04

0001 //===----- SemaCodeCompletion.h ------ Code completion support ------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 /// \file
0009 /// This file declares facilities that support code completion.
0010 ///
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_SEMA_SEMACODECOMPLETION_H
0014 #define LLVM_CLANG_SEMA_SEMACODECOMPLETION_H
0015 
0016 #include "clang/AST/ASTFwd.h"
0017 #include "clang/AST/Type.h"
0018 #include "clang/Basic/AttributeCommonInfo.h"
0019 #include "clang/Basic/IdentifierTable.h"
0020 #include "clang/Basic/LLVM.h"
0021 #include "clang/Basic/SourceLocation.h"
0022 #include "clang/Lex/ModuleLoader.h"
0023 #include "clang/Sema/CodeCompleteConsumer.h"
0024 #include "clang/Sema/DeclSpec.h"
0025 #include "clang/Sema/Designator.h"
0026 #include "clang/Sema/HeuristicResolver.h"
0027 #include "clang/Sema/Ownership.h"
0028 #include "clang/Sema/SemaBase.h"
0029 #include "llvm/ADT/StringRef.h"
0030 #include <optional>
0031 
0032 namespace clang {
0033 class DeclGroupRef;
0034 class MacroInfo;
0035 class Scope;
0036 class TemplateName;
0037 
0038 class SemaCodeCompletion : public SemaBase {
0039 public:
0040   SemaCodeCompletion(Sema &S, CodeCompleteConsumer *CompletionConsumer);
0041 
0042   using TemplateTy = OpaquePtr<TemplateName>;
0043   using DeclGroupPtrTy = OpaquePtr<DeclGroupRef>;
0044 
0045   /// Code-completion consumer.
0046   CodeCompleteConsumer *CodeCompleter;
0047   HeuristicResolver Resolver;
0048 
0049   /// Describes the context in which code completion occurs.
0050   enum ParserCompletionContext {
0051     /// Code completion occurs at top-level or namespace context.
0052     PCC_Namespace,
0053     /// Code completion occurs within a class, struct, or union.
0054     PCC_Class,
0055     /// Code completion occurs within an Objective-C interface, protocol,
0056     /// or category.
0057     PCC_ObjCInterface,
0058     /// Code completion occurs within an Objective-C implementation or
0059     /// category implementation
0060     PCC_ObjCImplementation,
0061     /// Code completion occurs within the list of instance variables
0062     /// in an Objective-C interface, protocol, category, or implementation.
0063     PCC_ObjCInstanceVariableList,
0064     /// Code completion occurs following one or more template
0065     /// headers.
0066     PCC_Template,
0067     /// Code completion occurs following one or more template
0068     /// headers within a class.
0069     PCC_MemberTemplate,
0070     /// Code completion occurs within an expression.
0071     PCC_Expression,
0072     /// Code completion occurs within a statement, which may
0073     /// also be an expression or a declaration.
0074     PCC_Statement,
0075     /// Code completion occurs at the beginning of the
0076     /// initialization statement (or expression) in a for loop.
0077     PCC_ForInit,
0078     /// Code completion occurs within the condition of an if,
0079     /// while, switch, or for statement.
0080     PCC_Condition,
0081     /// Code completion occurs within the body of a function on a
0082     /// recovery path, where we do not have a specific handle on our position
0083     /// in the grammar.
0084     PCC_RecoveryInFunction,
0085     /// Code completion occurs where only a type is permitted.
0086     PCC_Type,
0087     /// Code completion occurs in a parenthesized expression, which
0088     /// might also be a type cast.
0089     PCC_ParenthesizedExpression,
0090     /// Code completion occurs within a sequence of declaration
0091     /// specifiers within a function, method, or block.
0092     PCC_LocalDeclarationSpecifiers,
0093     /// Code completion occurs at top-level in a REPL session
0094     PCC_TopLevelOrExpression,
0095   };
0096 
0097   void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
0098   void CodeCompleteOrdinaryName(Scope *S,
0099                                 ParserCompletionContext CompletionContext);
0100   void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, bool AllowNonIdentifiers,
0101                             bool AllowNestedNameSpecifiers);
0102 
0103   struct CodeCompleteExpressionData;
0104   void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data);
0105   void CodeCompleteExpression(Scope *S, QualType PreferredType,
0106                               bool IsParenthesized = false);
0107   void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase,
0108                                        SourceLocation OpLoc, bool IsArrow,
0109                                        bool IsBaseExprStatement,
0110                                        QualType PreferredType);
0111   void CodeCompletePostfixExpression(Scope *S, ExprResult LHS,
0112                                      QualType PreferredType);
0113   void CodeCompleteTag(Scope *S, unsigned TagSpec);
0114   void CodeCompleteTypeQualifiers(DeclSpec &DS);
0115   void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D,
0116                                       const VirtSpecifiers *VS = nullptr);
0117   void CodeCompleteBracketDeclarator(Scope *S);
0118   void CodeCompleteCase(Scope *S);
0119   enum class AttributeCompletion {
0120     Attribute,
0121     Scope,
0122     None,
0123   };
0124   void CodeCompleteAttribute(
0125       AttributeCommonInfo::Syntax Syntax,
0126       AttributeCompletion Completion = AttributeCompletion::Attribute,
0127       const IdentifierInfo *Scope = nullptr);
0128   /// Determines the preferred type of the current function argument, by
0129   /// examining the signatures of all possible overloads.
0130   /// Returns null if unknown or ambiguous, or if code completion is off.
0131   ///
0132   /// If the code completion point has been reached, also reports the function
0133   /// signatures that were considered.
0134   ///
0135   /// FIXME: rename to GuessCallArgumentType to reduce confusion.
0136   QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args,
0137                                     SourceLocation OpenParLoc);
0138   QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc,
0139                                            ArrayRef<Expr *> Args,
0140                                            SourceLocation OpenParLoc,
0141                                            bool Braced);
0142   QualType ProduceCtorInitMemberSignatureHelp(
0143       Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy,
0144       ArrayRef<Expr *> ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc,
0145       bool Braced);
0146   QualType ProduceTemplateArgumentSignatureHelp(
0147       TemplateTy, ArrayRef<ParsedTemplateArgument>, SourceLocation LAngleLoc);
0148   void CodeCompleteInitializer(Scope *S, Decl *D);
0149   /// Trigger code completion for a record of \p BaseType. \p InitExprs are
0150   /// expressions in the initializer list seen so far and \p D is the current
0151   /// Designation being parsed.
0152   void CodeCompleteDesignator(const QualType BaseType,
0153                               llvm::ArrayRef<Expr *> InitExprs,
0154                               const Designation &D);
0155   void CodeCompleteAfterIf(Scope *S, bool IsBracedThen);
0156 
0157   void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext,
0158                                bool IsUsingDeclaration, QualType BaseType,
0159                                QualType PreferredType);
0160   void CodeCompleteUsing(Scope *S);
0161   void CodeCompleteUsingDirective(Scope *S);
0162   void CodeCompleteNamespaceDecl(Scope *S);
0163   void CodeCompleteNamespaceAliasDecl(Scope *S);
0164   void CodeCompleteOperatorName(Scope *S);
0165   void CodeCompleteConstructorInitializer(
0166       Decl *Constructor, ArrayRef<CXXCtorInitializer *> Initializers);
0167 
0168   void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro,
0169                                     bool AfterAmpersand);
0170   void CodeCompleteAfterFunctionEquals(Declarator &D);
0171 
0172   void CodeCompleteObjCAtDirective(Scope *S);
0173   void CodeCompleteObjCAtVisibility(Scope *S);
0174   void CodeCompleteObjCAtStatement(Scope *S);
0175   void CodeCompleteObjCAtExpression(Scope *S);
0176   void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
0177   void CodeCompleteObjCPropertyGetter(Scope *S);
0178   void CodeCompleteObjCPropertySetter(Scope *S);
0179   void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
0180                                    bool IsParameter);
0181   void CodeCompleteObjCMessageReceiver(Scope *S);
0182   void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
0183                                     ArrayRef<const IdentifierInfo *> SelIdents,
0184                                     bool AtArgumentExpression);
0185   void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
0186                                     ArrayRef<const IdentifierInfo *> SelIdents,
0187                                     bool AtArgumentExpression,
0188                                     bool IsSuper = false);
0189   void CodeCompleteObjCInstanceMessage(
0190       Scope *S, Expr *Receiver, ArrayRef<const IdentifierInfo *> SelIdents,
0191       bool AtArgumentExpression, ObjCInterfaceDecl *Super = nullptr);
0192   void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar);
0193   void CodeCompleteObjCSelector(Scope *S,
0194                                 ArrayRef<const IdentifierInfo *> SelIdents);
0195   void
0196   CodeCompleteObjCProtocolReferences(ArrayRef<IdentifierLocPair> Protocols);
0197   void CodeCompleteObjCProtocolDecl(Scope *S);
0198   void CodeCompleteObjCInterfaceDecl(Scope *S);
0199   void CodeCompleteObjCClassForwardDecl(Scope *S);
0200   void CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName,
0201                                   SourceLocation ClassNameLoc);
0202   void CodeCompleteObjCImplementationDecl(Scope *S);
0203   void CodeCompleteObjCInterfaceCategory(Scope *S, IdentifierInfo *ClassName,
0204                                          SourceLocation ClassNameLoc);
0205   void CodeCompleteObjCImplementationCategory(Scope *S,
0206                                               IdentifierInfo *ClassName,
0207                                               SourceLocation ClassNameLoc);
0208   void CodeCompleteObjCPropertyDefinition(Scope *S);
0209   void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
0210                                               IdentifierInfo *PropertyName);
0211   void CodeCompleteObjCMethodDecl(Scope *S,
0212                                   std::optional<bool> IsInstanceMethod,
0213                                   ParsedType ReturnType);
0214   void CodeCompleteObjCMethodDeclSelector(
0215       Scope *S, bool IsInstanceMethod, bool AtParameterName,
0216       ParsedType ReturnType, ArrayRef<const IdentifierInfo *> SelIdents);
0217   void CodeCompleteObjCClassPropertyRefExpr(Scope *S,
0218                                             const IdentifierInfo &ClassName,
0219                                             SourceLocation ClassNameLoc,
0220                                             bool IsBaseExprStatement);
0221   void CodeCompletePreprocessorDirective(bool InConditional);
0222   void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
0223   void CodeCompletePreprocessorMacroName(bool IsDefinition);
0224   void CodeCompletePreprocessorExpression();
0225   void CodeCompletePreprocessorMacroArgument(Scope *S, IdentifierInfo *Macro,
0226                                              MacroInfo *MacroInfo,
0227                                              unsigned Argument);
0228   void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled);
0229   void CodeCompleteNaturalLanguage();
0230   void CodeCompleteAvailabilityPlatformName();
0231   void
0232   GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
0233                               CodeCompletionTUInfo &CCTUInfo,
0234                               SmallVectorImpl<CodeCompletionResult> &Results);
0235 };
0236 
0237 } // namespace clang
0238 
0239 #endif // LLVM_CLANG_SEMA_SEMACODECOMPLETION_H