diff options
Diffstat (limited to 'lib/Sema/SemaCodeComplete.cpp')
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 67 |
1 files changed, 45 insertions, 22 deletions
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 21cf625851428..36babc4bc0cd6 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -19,7 +19,6 @@ #include "clang/Lex/MacroInfo.h" #include "clang/Lex/Preprocessor.h" #include "clang/Sema/CodeCompleteConsumer.h" -#include "clang/Sema/ExternalSemaSource.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/Overload.h" #include "clang/Sema/Scope.h" @@ -482,12 +481,37 @@ getRequiredQualification(ASTContext &Context, /// Determine whether \p Id is a name reserved for the implementation (C99 /// 7.1.3, C++ [lib.global.names]). -static bool isReservedName(const IdentifierInfo *Id) { +static bool isReservedName(const IdentifierInfo *Id, + bool doubleUnderscoreOnly = false) { if (Id->getLength() < 2) return false; const char *Name = Id->getNameStart(); return Name[0] == '_' && - (Name[1] == '_' || (Name[1] >= 'A' && Name[1] <= 'Z')); + (Name[1] == '_' || (Name[1] >= 'A' && Name[1] <= 'Z' && + !doubleUnderscoreOnly)); +} + +// Some declarations have reserved names that we don't want to ever show. +// Filter out names reserved for the implementation if they come from a +// system header. +static bool shouldIgnoreDueToReservedName(const NamedDecl *ND, Sema &SemaRef) { + const IdentifierInfo *Id = ND->getIdentifier(); + if (!Id) + return false; + + // Ignore reserved names for compiler provided decls. + if (isReservedName(Id) && ND->getLocation().isInvalid()) + return true; + + // For system headers ignore only double-underscore names. + // This allows for system headers providing private symbols with a single + // underscore. + if (isReservedName(Id, /*doubleUnderscoreOnly=*/true) && + SemaRef.SourceMgr.isInSystemHeader( + SemaRef.SourceMgr.getSpellingLoc(ND->getLocation()))) + return true; + + return false; } bool ResultBuilder::isInterestingDecl(const NamedDecl *ND, @@ -514,17 +538,9 @@ bool ResultBuilder::isInterestingDecl(const NamedDecl *ND, // Using declarations themselves are never added as results. if (isa<UsingDecl>(ND)) return false; - - // Some declarations have reserved names that we don't want to ever show. - // Filter out names reserved for the implementation if they come from a - // system header. - // TODO: Add a predicate for this. - if (const IdentifierInfo *Id = ND->getIdentifier()) - if (isReservedName(Id) && - (ND->getLocation().isInvalid() || - SemaRef.SourceMgr.isInSystemHeader( - SemaRef.SourceMgr.getSpellingLoc(ND->getLocation())))) - return false; + + if (shouldIgnoreDueToReservedName(ND, SemaRef)) + return false; if (Filter == &ResultBuilder::IsNestedNameSpecifier || (isa<NamespaceDecl>(ND) && @@ -1518,7 +1534,6 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, ResultBuilder &Results) { CodeCompletionAllocator &Allocator = Results.getAllocator(); CodeCompletionBuilder Builder(Allocator, Results.getCodeCompletionTUInfo()); - PrintingPolicy Policy = getCompletionPrintingPolicy(SemaRef); typedef CodeCompletionResult Result; switch (CCC) { @@ -3046,6 +3061,7 @@ CXCursorKind clang::getCursorKindForDecl(const Decl *D) { case Decl::ClassTemplatePartialSpecialization: return CXCursor_ClassTemplatePartialSpecialization; case Decl::UsingDirective: return CXCursor_UsingDirective; + case Decl::StaticAssert: return CXCursor_StaticAssert; case Decl::TranslationUnit: return CXCursor_TranslationUnit; case Decl::Using: @@ -3209,7 +3225,7 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, // We need to have names for all of the parameters, if we're going to // generate a forwarding call. - for (auto P : Method->params()) + for (auto P : Method->parameters()) if (!P->getDeclName()) return; @@ -3241,7 +3257,7 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, Overridden->getNameAsString())); Builder.AddChunk(CodeCompletionString::CK_LeftParen); bool FirstParam = true; - for (auto P : Method->params()) { + for (auto P : Method->parameters()) { if (FirstParam) FirstParam = false; else @@ -3570,7 +3586,7 @@ static void AddObjCProperties(const CodeCompletionContext &CCContext, Container = getContainerDef(Container); // Add properties in this container. - for (const auto *P : Container->properties()) + for (const auto *P : Container->instance_properties()) if (AddedProperties.insert(P->getIdentifier()).second) Results.MaybeAddResult(Result(P, Results.getBasePriority(P), nullptr), CurContext); @@ -3812,12 +3828,19 @@ void Sema::CodeCompleteTypeQualifiers(DeclSpec &DS) { if (getLangOpts().C11 && !(DS.getTypeQualifiers() & DeclSpec::TQ_atomic)) Results.AddResult("_Atomic"); + if (getLangOpts().MSVCCompat && + !(DS.getTypeQualifiers() & DeclSpec::TQ_unaligned)) + Results.AddResult("__unaligned"); Results.ExitScope(); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } +void Sema::CodeCompleteBracketDeclarator(Scope *S) { + CodeCompleteExpression(S, QualType(getASTContext().getSizeType())); +} + void Sema::CodeCompleteCase(Scope *S) { if (getCurFunction()->SwitchStack.empty() || !CodeCompleter) return; @@ -6189,7 +6212,7 @@ void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S, // Figure out which interface we're looking into. ObjCInterfaceDecl *Class = nullptr; if (ObjCImplementationDecl *ClassImpl - = dyn_cast<ObjCImplementationDecl>(Container)) + = dyn_cast<ObjCImplementationDecl>(Container)) Class = ClassImpl->getClassInterface(); else Class = cast<ObjCCategoryImplDecl>(Container)->getCategoryDecl() @@ -6198,8 +6221,8 @@ void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S, // Determine the type of the property we're synthesizing. QualType PropertyType = Context.getObjCIdType(); if (Class) { - if (ObjCPropertyDecl *Property - = Class->FindPropertyDeclaration(PropertyName)) { + if (ObjCPropertyDecl *Property = Class->FindPropertyDeclaration( + PropertyName, ObjCPropertyQueryKind::OBJC_PR_query_instance)) { PropertyType = Property->getType().getNonReferenceType().getUnqualifiedType(); @@ -7178,7 +7201,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, Containers.push_back(Cat); for (unsigned I = 0, N = Containers.size(); I != N; ++I) - for (auto *P : Containers[I]->properties()) + for (auto *P : Containers[I]->instance_properties()) AddObjCKeyValueCompletions(P, IsInstanceMethod, ReturnType, Context, KnownSelectors, Results); } |