diff options
author | dim <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
commit | c72c57c9e9b69944e3e009cd5e209634839581d3 (patch) | |
tree | 4fc2f184c499d106f29a386c452b49e5197bf63d /lib/Sema/SemaCodeComplete.cpp | |
parent | 5b20025c30d23d521e12c1f33ec8fa6b821952cd (diff) | |
download | FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.zip FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.tar.gz |
Vendor import of clang trunk r178860:
http://llvm.org/svn/llvm-project/cfe/trunk@178860
Diffstat (limited to 'lib/Sema/SemaCodeComplete.cpp')
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 540 |
1 files changed, 336 insertions, 204 deletions
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index b1aead8..2db1e2a 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -11,18 +11,19 @@ // //===----------------------------------------------------------------------===// #include "clang/Sema/SemaInternal.h" -#include "clang/Sema/Lookup.h" -#include "clang/Sema/Overload.h" -#include "clang/Sema/CodeCompleteConsumer.h" -#include "clang/Sema/ExternalSemaSource.h" -#include "clang/Sema/Scope.h" -#include "clang/Sema/ScopeInfo.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" +#include "clang/Basic/CharInfo.h" #include "clang/Lex/HeaderSearch.h" #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" +#include "clang/Sema/ScopeInfo.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallPtrSet.h" @@ -45,7 +46,7 @@ namespace { /// name-lookup routines to specify which declarations should be included in /// the result set (when it returns true) and which declarations should be /// filtered out (returns false). - typedef bool (ResultBuilder::*LookupFilter)(NamedDecl *) const; + typedef bool (ResultBuilder::*LookupFilter)(const NamedDecl *) const; typedef CodeCompletionResult Result; @@ -56,9 +57,9 @@ namespace { /// \brief A record of all of the declarations we have found and placed /// into the result set, used to ensure that no declaration ever gets into /// the result set twice. - llvm::SmallPtrSet<Decl*, 16> AllDeclsFound; + llvm::SmallPtrSet<const Decl*, 16> AllDeclsFound; - typedef std::pair<NamedDecl *, unsigned> DeclIndexPair; + typedef std::pair<const NamedDecl *, unsigned> DeclIndexPair; /// \brief An entry in the shadow map, which is optimized to store /// a single (declaration, index) mapping (the common case) but @@ -68,7 +69,7 @@ namespace { /// \brief Contains either the solitary NamedDecl * or a vector /// of (declaration, index) pairs. - llvm::PointerUnion<NamedDecl *, DeclIndexPairVector*> DeclOrVector; + llvm::PointerUnion<const NamedDecl *, DeclIndexPairVector*> DeclOrVector; /// \brief When the entry contains a single declaration, this is /// the index associated with that entry. @@ -77,7 +78,7 @@ namespace { public: ShadowMapEntry() : DeclOrVector(), SingleDeclIndex(0) { } - void Add(NamedDecl *ND, unsigned Index) { + void Add(const NamedDecl *ND, unsigned Index) { if (DeclOrVector.isNull()) { // 0 - > 1 elements: just set the single element information. DeclOrVector = ND; @@ -85,7 +86,8 @@ namespace { return; } - if (NamedDecl *PrevND = DeclOrVector.dyn_cast<NamedDecl *>()) { + if (const NamedDecl *PrevND = + DeclOrVector.dyn_cast<const NamedDecl *>()) { // 1 -> 2 elements: create the vector of results and push in the // existing declaration. DeclIndexPairVector *Vec = new DeclIndexPairVector; @@ -161,7 +163,7 @@ namespace { /// \brief If we are in an instance method definition, the \@implementation /// object. ObjCImplementationDecl *ObjCImplementation; - + void AdjustResultPriorityForDecl(Result &R); void MaybeAddConstructorResults(Result R); @@ -195,7 +197,10 @@ namespace { break; } } - + + /// \brief Determine the priority for a reference to the given declaration. + unsigned getBasePriority(const NamedDecl *D); + /// \brief Whether we should include code patterns in the completion /// results. bool includeCodePatterns() const { @@ -265,7 +270,8 @@ namespace { /// /// \param AsNestedNameSpecifier will be set true if this declaration is /// only interesting when it is a nested-name-specifier. - bool isInterestingDecl(NamedDecl *ND, bool &AsNestedNameSpecifier) const; + bool isInterestingDecl(const NamedDecl *ND, + bool &AsNestedNameSpecifier) const; /// \brief Check whether the result is hidden by the Hiding declaration. /// @@ -274,7 +280,7 @@ namespace { /// modified to describe how the result can be found (e.g., via extra /// qualification). bool CheckHiddenResult(Result &R, DeclContext *CurContext, - NamedDecl *Hiding); + const NamedDecl *Hiding); /// \brief Add a new result to this result set (if it isn't already in one /// of the shadow maps), or replace an existing result (for, e.g., a @@ -309,7 +315,7 @@ namespace { void ExitScope(); /// \brief Ignore this declaration, if it is seen again. - void Ignore(Decl *D) { AllDeclsFound.insert(D->getCanonicalDecl()); } + void Ignore(const Decl *D) { AllDeclsFound.insert(D->getCanonicalDecl()); } /// \name Name lookup predicates /// @@ -317,29 +323,29 @@ namespace { /// results of name lookup. All of the predicates have the same type, so that /// //@{ - bool IsOrdinaryName(NamedDecl *ND) const; - bool IsOrdinaryNonTypeName(NamedDecl *ND) const; - bool IsIntegralConstantValue(NamedDecl *ND) const; - bool IsOrdinaryNonValueName(NamedDecl *ND) const; - bool IsNestedNameSpecifier(NamedDecl *ND) const; - bool IsEnum(NamedDecl *ND) const; - bool IsClassOrStruct(NamedDecl *ND) const; - bool IsUnion(NamedDecl *ND) const; - bool IsNamespace(NamedDecl *ND) const; - bool IsNamespaceOrAlias(NamedDecl *ND) const; - bool IsType(NamedDecl *ND) const; - bool IsMember(NamedDecl *ND) const; - bool IsObjCIvar(NamedDecl *ND) const; - bool IsObjCMessageReceiver(NamedDecl *ND) const; - bool IsObjCMessageReceiverOrLambdaCapture(NamedDecl *ND) const; - bool IsObjCCollection(NamedDecl *ND) const; - bool IsImpossibleToSatisfy(NamedDecl *ND) const; + bool IsOrdinaryName(const NamedDecl *ND) const; + bool IsOrdinaryNonTypeName(const NamedDecl *ND) const; + bool IsIntegralConstantValue(const NamedDecl *ND) const; + bool IsOrdinaryNonValueName(const NamedDecl *ND) const; + bool IsNestedNameSpecifier(const NamedDecl *ND) const; + bool IsEnum(const NamedDecl *ND) const; + bool IsClassOrStruct(const NamedDecl *ND) const; + bool IsUnion(const NamedDecl *ND) const; + bool IsNamespace(const NamedDecl *ND) const; + bool IsNamespaceOrAlias(const NamedDecl *ND) const; + bool IsType(const NamedDecl *ND) const; + bool IsMember(const NamedDecl *ND) const; + bool IsObjCIvar(const NamedDecl *ND) const; + bool IsObjCMessageReceiver(const NamedDecl *ND) const; + bool IsObjCMessageReceiverOrLambdaCapture(const NamedDecl *ND) const; + bool IsObjCCollection(const NamedDecl *ND) const; + bool IsImpossibleToSatisfy(const NamedDecl *ND) const; //@} }; } class ResultBuilder::ShadowMapEntry::iterator { - llvm::PointerUnion<NamedDecl*, const DeclIndexPair*> DeclOrIterator; + llvm::PointerUnion<const NamedDecl *, const DeclIndexPair *> DeclOrIterator; unsigned SingleDeclIndex; public: @@ -361,14 +367,14 @@ public: iterator() : DeclOrIterator((NamedDecl *)0), SingleDeclIndex(0) { } - iterator(NamedDecl *SingleDecl, unsigned Index) + iterator(const NamedDecl *SingleDecl, unsigned Index) : DeclOrIterator(SingleDecl), SingleDeclIndex(Index) { } iterator(const DeclIndexPair *Iterator) : DeclOrIterator(Iterator), SingleDeclIndex(0) { } iterator &operator++() { - if (DeclOrIterator.is<NamedDecl *>()) { + if (DeclOrIterator.is<const NamedDecl *>()) { DeclOrIterator = (NamedDecl *)0; SingleDeclIndex = 0; return *this; @@ -387,7 +393,7 @@ public: }*/ reference operator*() const { - if (NamedDecl *ND = DeclOrIterator.dyn_cast<NamedDecl *>()) + if (const NamedDecl *ND = DeclOrIterator.dyn_cast<const NamedDecl *>()) return reference(ND, SingleDeclIndex); return *DeclOrIterator.get<const DeclIndexPair*>(); @@ -413,7 +419,7 @@ ResultBuilder::ShadowMapEntry::begin() const { if (DeclOrVector.isNull()) return iterator(); - if (NamedDecl *ND = DeclOrVector.dyn_cast<NamedDecl *>()) + if (const NamedDecl *ND = DeclOrVector.dyn_cast<const NamedDecl *>()) return iterator(ND, SingleDeclIndex); return iterator(DeclOrVector.get<DeclIndexPairVector *>()->begin()); @@ -421,7 +427,7 @@ ResultBuilder::ShadowMapEntry::begin() const { ResultBuilder::ShadowMapEntry::iterator ResultBuilder::ShadowMapEntry::end() const { - if (DeclOrVector.is<NamedDecl *>() || DeclOrVector.isNull()) + if (DeclOrVector.is<const NamedDecl *>() || DeclOrVector.isNull()) return iterator(); return iterator(DeclOrVector.get<DeclIndexPairVector *>()->end()); @@ -442,11 +448,11 @@ ResultBuilder::ShadowMapEntry::end() const { /// NULL if no qualification is needed. static NestedNameSpecifier * getRequiredQualification(ASTContext &Context, - DeclContext *CurContext, - DeclContext *TargetContext) { - SmallVector<DeclContext *, 4> TargetParents; + const DeclContext *CurContext, + const DeclContext *TargetContext) { + SmallVector<const DeclContext *, 4> TargetParents; - for (DeclContext *CommonAncestor = TargetContext; + for (const DeclContext *CommonAncestor = TargetContext; CommonAncestor && !CommonAncestor->Encloses(CurContext); CommonAncestor = CommonAncestor->getLookupParent()) { if (CommonAncestor->isTransparentContext() || @@ -458,16 +464,16 @@ getRequiredQualification(ASTContext &Context, NestedNameSpecifier *Result = 0; while (!TargetParents.empty()) { - DeclContext *Parent = TargetParents.back(); + const DeclContext *Parent = TargetParents.back(); TargetParents.pop_back(); - if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Parent)) { + if (const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Parent)) { if (!Namespace->getIdentifier()) continue; Result = NestedNameSpecifier::Create(Context, Result, Namespace); } - else if (TagDecl *TD = dyn_cast<TagDecl>(Parent)) + else if (const TagDecl *TD = dyn_cast<TagDecl>(Parent)) Result = NestedNameSpecifier::Create(Context, Result, false, Context.getTypeDeclType(TD).getTypePtr()); @@ -475,7 +481,7 @@ getRequiredQualification(ASTContext &Context, return Result; } -bool ResultBuilder::isInterestingDecl(NamedDecl *ND, +bool ResultBuilder::isInterestingDecl(const NamedDecl *ND, bool &AsNestedNameSpecifier) const { AsNestedNameSpecifier = false; @@ -547,14 +553,15 @@ bool ResultBuilder::isInterestingDecl(NamedDecl *ND, } bool ResultBuilder::CheckHiddenResult(Result &R, DeclContext *CurContext, - NamedDecl *Hiding) { + const NamedDecl *Hiding) { // In C, there is no way to refer to a hidden name. // FIXME: This isn't true; we can find a tag name hidden by an ordinary // name if we introduce the tag type. if (!SemaRef.getLangOpts().CPlusPlus) return true; - DeclContext *HiddenCtx = R.Declaration->getDeclContext()->getRedeclContext(); + const DeclContext *HiddenCtx = + R.Declaration->getDeclContext()->getRedeclContext(); // There is no way to qualify a name declared in a function or method. if (HiddenCtx->isFunctionOrMethod()) @@ -645,26 +652,27 @@ SimplifiedTypeClass clang::getSimplifiedTypeClass(CanQualType T) { /// \brief Get the type that a given expression will have if this declaration /// is used as an expression in its "typical" code-completion form. -QualType clang::getDeclUsageType(ASTContext &C, NamedDecl *ND) { +QualType clang::getDeclUsageType(ASTContext &C, const NamedDecl *ND) { ND = cast<NamedDecl>(ND->getUnderlyingDecl()); - if (TypeDecl *Type = dyn_cast<TypeDecl>(ND)) + if (const TypeDecl *Type = dyn_cast<TypeDecl>(ND)) return C.getTypeDeclType(Type); - if (ObjCInterfaceDecl *Iface = dyn_cast<ObjCInterfaceDecl>(ND)) + if (const ObjCInterfaceDecl *Iface = dyn_cast<ObjCInterfaceDecl>(ND)) return C.getObjCInterfaceType(Iface); QualType T; - if (FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) + if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) T = Function->getCallResultType(); - else if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND)) + else if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND)) T = Method->getSendResultType(); - else if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(ND)) + else if (const FunctionTemplateDecl *FunTmpl = + dyn_cast<FunctionTemplateDecl>(ND)) T = FunTmpl->getTemplatedDecl()->getCallResultType(); - else if (EnumConstantDecl *Enumerator = dyn_cast<EnumConstantDecl>(ND)) + else if (const EnumConstantDecl *Enumerator = dyn_cast<EnumConstantDecl>(ND)) T = C.getTypeDeclType(cast<EnumDecl>(Enumerator->getDeclContext())); - else if (ObjCPropertyDecl *Property = dyn_cast<ObjCPropertyDecl>(ND)) + else if (const ObjCPropertyDecl *Property = dyn_cast<ObjCPropertyDecl>(ND)) T = Property->getType(); - else if (ValueDecl *Value = dyn_cast<ValueDecl>(ND)) + else if (const ValueDecl *Value = dyn_cast<ValueDecl>(ND)) T = Value->getType(); else return QualType(); @@ -703,11 +711,48 @@ QualType clang::getDeclUsageType(ASTContext &C, NamedDecl *ND) { return T; } +unsigned ResultBuilder::getBasePriority(const NamedDecl *ND) { + if (!ND) + return CCP_Unlikely; + + // Context-based decisions. + const DeclContext *DC = ND->getDeclContext()->getRedeclContext(); + if (DC->isFunctionOrMethod() || isa<BlockDecl>(DC)) { + // _cmd is relatively rare + if (const ImplicitParamDecl *ImplicitParam = + dyn_cast<ImplicitParamDecl>(ND)) + if (ImplicitParam->getIdentifier() && + ImplicitParam->getIdentifier()->isStr("_cmd")) + return CCP_ObjC_cmd; + + return CCP_LocalDeclaration; + } + if (DC->isRecord() || isa<ObjCContainerDecl>(DC)) + return CCP_MemberDeclaration; + + // Content-based decisions. + if (isa<EnumConstantDecl>(ND)) + return CCP_Constant; + + // Use CCP_Type for type declarations unless we're in a statement, Objective-C + // message receiver, or parenthesized expression context. There, it's as + // likely that the user will want to write a type as other declarations. + if ((isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND)) && + !(CompletionContext.getKind() == CodeCompletionContext::CCC_Statement || + CompletionContext.getKind() + == CodeCompletionContext::CCC_ObjCMessageReceiver || + CompletionContext.getKind() + == CodeCompletionContext::CCC_ParenthesizedExpression)) + return CCP_Type; + + return CCP_Declaration; +} + void ResultBuilder::AdjustResultPriorityForDecl(Result &R) { // If this is an Objective-C method declaration whose selector matches our // preferred selector, give it a priority boost. if (!PreferredSelector.isNull()) - if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(R.Declaration)) + if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(R.Declaration)) if (PreferredSelector == Method->getSelector()) R.Priority += CCD_SelectorMatch; @@ -735,9 +780,9 @@ void ResultBuilder::MaybeAddConstructorResults(Result R) { return; ASTContext &Context = SemaRef.Context; - NamedDecl *D = R.Declaration; - CXXRecordDecl *Record = 0; - if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(D)) + const NamedDecl *D = R.Declaration; + const CXXRecordDecl *Record = 0; + if (const ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(D)) Record = ClassTemplate->getTemplatedDecl(); else if ((Record = dyn_cast<CXXRecordDecl>(D))) { // Skip specializations and partial specializations. @@ -757,9 +802,11 @@ void ResultBuilder::MaybeAddConstructorResults(Result R) { DeclarationName ConstructorName = Context.DeclarationNames.getCXXConstructorName( Context.getCanonicalType(RecordTy)); - for (DeclContext::lookup_result Ctors = Record->lookup(ConstructorName); - Ctors.first != Ctors.second; ++Ctors.first) { - R.Declaration = *Ctors.first; + DeclContext::lookup_const_result Ctors = Record->lookup(ConstructorName); + for (DeclContext::lookup_const_iterator I = Ctors.begin(), + E = Ctors.end(); + I != E; ++I) { + R.Declaration = *I; R.CursorKind = getCursorKindForDecl(R.Declaration); Results.push_back(R); } @@ -775,12 +822,16 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) { } // Look through using declarations. - if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) { - MaybeAddResult(Result(Using->getTargetDecl(), R.Qualifier), CurContext); + if (const UsingShadowDecl *Using = + dyn_cast<UsingShadowDecl>(R.Declaration)) { + MaybeAddResult(Result(Using->getTargetDecl(), + getBasePriority(Using->getTargetDecl()), + R.Qualifier), + CurContext); return; } - Decl *CanonDecl = R.Declaration->getCanonicalDecl(); + const Decl *CanonDecl = R.Declaration->getCanonicalDecl(); unsigned IDNS = CanonDecl->getIdentifierNamespace(); bool AsNestedNameSpecifier = false; @@ -800,7 +851,7 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) { } for (; I != IEnd; ++I) { - NamedDecl *ND = I->first; + const NamedDecl *ND = I->first; unsigned Index = I->second; if (ND->getCanonicalDecl() == CanonDecl) { // This is a redeclaration. Always pick the newer declaration. @@ -859,10 +910,10 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) { // If this result is supposed to have an informative qualifier, add one. if (R.QualifierIsInformative && !R.Qualifier && !R.StartsNestedNameSpecifier) { - DeclContext *Ctx = R.Declaration->getDeclContext(); - if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx)) + const DeclContext *Ctx = R.Declaration->getDeclContext(); + if (const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx)) R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, Namespace); - else if (TagDecl *Tag = dyn_cast<TagDecl>(Ctx)) + else if (const TagDecl *Tag = dyn_cast<TagDecl>(Ctx)) R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, false, SemaRef.Context.getTypeDeclType(Tag).getTypePtr()); else @@ -887,8 +938,11 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext, } // Look through using declarations. - if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) { - AddResult(Result(Using->getTargetDecl(), R.Qualifier), CurContext, Hiding); + if (const UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) { + AddResult(Result(Using->getTargetDecl(), + getBasePriority(Using->getTargetDecl()), + R.Qualifier), + CurContext, Hiding); return; } @@ -921,10 +975,10 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext, // If this result is supposed to have an informative qualifier, add one. if (R.QualifierIsInformative && !R.Qualifier && !R.StartsNestedNameSpecifier) { - DeclContext *Ctx = R.Declaration->getDeclContext(); - if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx)) + const DeclContext *Ctx = R.Declaration->getDeclContext(); + if (const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx)) R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, Namespace); - else if (TagDecl *Tag = dyn_cast<TagDecl>(Ctx)) + else if (const TagDecl *Tag = dyn_cast<TagDecl>(Ctx)) R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, false, SemaRef.Context.getTypeDeclType(Tag).getTypePtr()); else @@ -938,7 +992,7 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext, AdjustResultPriorityForDecl(R); if (HasObjectTypeQualifiers) - if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(R.Declaration)) + if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(R.Declaration)) if (Method->isInstance()) { Qualifiers MethodQuals = Qualifiers::fromCVRMask(Method->getTypeQualifiers()); @@ -982,7 +1036,7 @@ void ResultBuilder::ExitScope() { /// \brief Determines whether this given declaration will be found by /// ordinary name lookup. -bool ResultBuilder::IsOrdinaryName(NamedDecl *ND) const { +bool ResultBuilder::IsOrdinaryName(const NamedDecl *ND) const { ND = cast<NamedDecl>(ND->getUnderlyingDecl()); unsigned IDNS = Decl::IDNS_Ordinary; @@ -998,7 +1052,7 @@ bool ResultBuilder::IsOrdinaryName(NamedDecl *ND) const { /// \brief Determines whether this given declaration will be found by /// ordinary name lookup but is not a type name. -bool ResultBuilder::IsOrdinaryNonTypeName(NamedDecl *ND) const { +bool ResultBuilder::IsOrdinaryNonTypeName(const NamedDecl *ND) const { ND = cast<NamedDecl>(ND->getUnderlyingDecl()); if (isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND)) return false; @@ -1014,11 +1068,11 @@ bool ResultBuilder::IsOrdinaryNonTypeName(NamedDecl *ND) const { return ND->getIdentifierNamespace() & IDNS; } -bool ResultBuilder::IsIntegralConstantValue(NamedDecl *ND) const { +bool ResultBuilder::IsIntegralConstantValue(const NamedDecl *ND) const { if (!IsOrdinaryNonTypeName(ND)) return 0; - if (ValueDecl *VD = dyn_cast<ValueDecl>(ND->getUnderlyingDecl())) + if (const ValueDecl *VD = dyn_cast<ValueDecl>(ND->getUnderlyingDecl())) if (VD->getType()->isIntegralOrEnumerationType()) return true; @@ -1027,7 +1081,7 @@ bool ResultBuilder::IsIntegralConstantValue(NamedDecl *ND) const { /// \brief Determines whether this given declaration will be found by /// ordinary name lookup. -bool ResultBuilder::IsOrdinaryNonValueName(NamedDecl *ND) const { +bool ResultBuilder::IsOrdinaryNonValueName(const NamedDecl *ND) const { ND = cast<NamedDecl>(ND->getUnderlyingDecl()); unsigned IDNS = Decl::IDNS_Ordinary; @@ -1041,27 +1095,27 @@ bool ResultBuilder::IsOrdinaryNonValueName(NamedDecl *ND) const { /// \brief Determines whether the given declaration is suitable as the /// start of a C++ nested-name-specifier, e.g., a class or namespace. -bool ResultBuilder::IsNestedNameSpecifier(NamedDecl *ND) const { +bool ResultBuilder::IsNestedNameSpecifier(const NamedDecl *ND) const { // Allow us to find class templates, too. - if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND)) + if (const ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND)) ND = ClassTemplate->getTemplatedDecl(); return SemaRef.isAcceptableNestedNameSpecifier(ND); } /// \brief Determines whether the given declaration is an enumeration. -bool ResultBuilder::IsEnum(NamedDecl *ND) const { +bool ResultBuilder::IsEnum(const NamedDecl *ND) const { return isa<EnumDecl>(ND); } /// \brief Determines whether the given declaration is a class or struct. -bool ResultBuilder::IsClassOrStruct(NamedDecl *ND) const { +bool ResultBuilder::IsClassOrStruct(const NamedDecl *ND) const { // Allow us to find class templates, too. - if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND)) + if (const ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND)) ND = ClassTemplate->getTemplatedDecl(); // For purposes of this check, interfaces match too. - if (RecordDecl *RD = dyn_cast<RecordDecl>(ND)) + if (const RecordDecl *RD = dyn_cast<RecordDecl>(ND)) return RD->getTagKind() == TTK_Class || RD->getTagKind() == TTK_Struct || RD->getTagKind() == TTK_Interface; @@ -1070,31 +1124,31 @@ bool ResultBuilder::IsClassOrStruct(NamedDecl *ND) const { } /// \brief Determines whether the given declaration is a union. -bool ResultBuilder::IsUnion(NamedDecl *ND) const { +bool ResultBuilder::IsUnion(const NamedDecl *ND) const { // Allow us to find class templates, too. - if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND)) + if (const ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND)) ND = ClassTemplate->getTemplatedDecl(); - if (RecordDecl *RD = dyn_cast<RecordDecl>(ND)) + if (const RecordDecl *RD = dyn_cast<RecordDecl>(ND)) return RD->getTagKind() == TTK_Union; return false; } /// \brief Determines whether the given declaration is a namespace. -bool ResultBuilder::IsNamespace(NamedDecl *ND) const { +bool ResultBuilder::IsNamespace(const NamedDecl *ND) const { return isa<NamespaceDecl>(ND); } /// \brief Determines whether the given declaration is a namespace or /// namespace alias. -bool ResultBuilder::IsNamespaceOrAlias(NamedDecl *ND) const { +bool ResultBuilder::IsNamespaceOrAlias(const NamedDecl *ND) const { return isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND); } /// \brief Determines whether the given declaration is a type. -bool ResultBuilder::IsType(NamedDecl *ND) const { - if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(ND)) +bool ResultBuilder::IsType(const NamedDecl *ND) const { + if (const UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(ND)) ND = Using->getTargetDecl(); return isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND); @@ -1103,8 +1157,8 @@ bool ResultBuilder::IsType(NamedDecl *ND) const { /// \brief Determines which members of a class should be visible via /// "." or "->". Only value declarations, nested name specifiers, and /// using declarations thereof should show up. -bool ResultBuilder::IsMember(NamedDecl *ND) const { - if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(ND)) +bool ResultBuilder::IsMember(const NamedDecl *ND) const { + if (const UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(ND)) ND = Using->getTargetDecl(); return isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND) || @@ -1144,7 +1198,7 @@ static bool isObjCReceiverType(ASTContext &C, QualType T) { return T->isDependentType() || T->isRecordType(); } -bool ResultBuilder::IsObjCMessageReceiver(NamedDecl *ND) const { +bool ResultBuilder::IsObjCMessageReceiver(const NamedDecl *ND) const { QualType T = getDeclUsageType(SemaRef.Context, ND); if (T.isNull()) return false; @@ -1153,18 +1207,18 @@ bool ResultBuilder::IsObjCMessageReceiver(NamedDecl *ND) const { return isObjCReceiverType(SemaRef.Context, T); } -bool ResultBuilder::IsObjCMessageReceiverOrLambdaCapture(NamedDecl *ND) const { +bool ResultBuilder::IsObjCMessageReceiverOrLambdaCapture(const NamedDecl *ND) const { if (IsObjCMessageReceiver(ND)) return true; - VarDecl *Var = dyn_cast<VarDecl>(ND); + const VarDecl *Var = dyn_cast<VarDecl>(ND); if (!Var) return false; return Var->hasLocalStorage() && !Var->hasAttr<BlocksAttr>(); } -bool ResultBuilder::IsObjCCollection(NamedDecl *ND) const { +bool ResultBuilder::IsObjCCollection(const NamedDecl *ND) const { if ((SemaRef.getLangOpts().CPlusPlus && !IsOrdinaryName(ND)) || (!SemaRef.getLangOpts().CPlusPlus && !IsOrdinaryNonTypeName(ND))) return false; @@ -1179,13 +1233,13 @@ bool ResultBuilder::IsObjCCollection(NamedDecl *ND) const { (SemaRef.getLangOpts().CPlusPlus && T->isRecordType()); } -bool ResultBuilder::IsImpossibleToSatisfy(NamedDecl *ND) const { +bool ResultBuilder::IsImpossibleToSatisfy(const NamedDecl *ND) const { return false; } /// \brief Determines whether the given declaration is an Objective-C /// instance variable. -bool ResultBuilder::IsObjCIvar(NamedDecl *ND) const { +bool ResultBuilder::IsObjCIvar(const NamedDecl *ND) const { return isa<ObjCIvarDecl>(ND); } @@ -1206,7 +1260,8 @@ namespace { if (Ctx) Accessible = Results.getSema().IsSimplyAccessible(ND, Ctx); - ResultBuilder::Result Result(ND, 0, false, Accessible); + ResultBuilder::Result Result(ND, Results.getBasePriority(ND), 0, false, + Accessible); Results.AddResult(Result, CurContext, Hiding, InBaseClass); } }; @@ -1256,7 +1311,7 @@ static void AddTypeSpecifierResults(const LangOptions &LangOpts, Builder.AddPlaceholderChunk("name"); Results.AddResult(Result(Builder.TakeString())); - if (LangOpts.CPlusPlus0x) { + if (LangOpts.CPlusPlus11) { Results.AddResult(Result("auto", CCP_Type)); Results.AddResult(Result("char16_t", CCP_Type)); Results.AddResult(Result("char32_t", CCP_Type)); @@ -1421,7 +1476,7 @@ static const char *GetCompletionTypeString(QualType T, // Anonymous tag types are constant strings. if (const TagType *TagT = dyn_cast<TagType>(T)) if (TagDecl *Tag = TagT->getDecl()) - if (!Tag->getIdentifier() && !Tag->getTypedefNameForAnonDecl()) { + if (!Tag->hasNameForLinkage()) { switch (Tag->getTagKind()) { case TTK_Struct: return "struct <anonymous>"; case TTK_Interface: return "__interface <anonymous>"; @@ -1906,7 +1961,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, // FIXME: Rethrow? - if (SemaRef.getLangOpts().CPlusPlus0x) { + if (SemaRef.getLangOpts().CPlusPlus11) { // nullptr Builder.AddResultTypeChunk("std::nullptr_t"); Builder.AddTypedTextChunk("nullptr"); @@ -1997,7 +2052,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, /// type chunk. static void AddResultTypeChunk(ASTContext &Context, const PrintingPolicy &Policy, - NamedDecl *ND, + const NamedDecl *ND, CodeCompletionBuilder &Result) { if (!ND) return; @@ -2009,19 +2064,20 @@ static void AddResultTypeChunk(ASTContext &Context, // Determine the type of the declaration (if it has a type). QualType T; - if (FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) + if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) T = Function->getResultType(); - else if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND)) + else if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND)) T = Method->getResultType(); - else if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(ND)) + else if (const FunctionTemplateDecl *FunTmpl = + dyn_cast<FunctionTemplateDecl>(ND)) T = FunTmpl->getTemplatedDecl()->getResultType(); - else if (EnumConstantDecl *Enumerator = dyn_cast<EnumConstantDecl>(ND)) + else if (const EnumConstantDecl *Enumerator = dyn_cast<EnumConstantDecl>(ND)) T = Context.getTypeDeclType(cast<TypeDecl>(Enumerator->getDeclContext())); else if (isa<UnresolvedUsingValueDecl>(ND)) { /* Do nothing: ignore unresolved using declarations*/ - } else if (ValueDecl *Value = dyn_cast<ValueDecl>(ND)) { + } else if (const ValueDecl *Value = dyn_cast<ValueDecl>(ND)) { T = Value->getType(); - } else if (ObjCPropertyDecl *Property = dyn_cast<ObjCPropertyDecl>(ND)) + } else if (const ObjCPropertyDecl *Property = dyn_cast<ObjCPropertyDecl>(ND)) T = Property->getType(); if (T.isNull() || Context.hasSameType(T, Context.DependentTy)) @@ -2031,7 +2087,8 @@ static void AddResultTypeChunk(ASTContext &Context, Result.getAllocator())); } -static void MaybeAddSentinel(ASTContext &Context, NamedDecl *FunctionOrMethod, +static void MaybeAddSentinel(ASTContext &Context, + const NamedDecl *FunctionOrMethod, CodeCompletionBuilder &Result) { if (SentinelAttr *Sentinel = FunctionOrMethod->getAttr<SentinelAttr>()) if (Sentinel->getSentinel() == 0) { @@ -2064,7 +2121,7 @@ static std::string formatObjCParamQualifiers(unsigned ObjCQuals) { static std::string FormatFunctionParameter(ASTContext &Context, const PrintingPolicy &Policy, - ParmVarDecl *Param, + const ParmVarDecl *Param, bool SuppressName = false, bool SuppressBlock = false) { bool ObjCMethodParam = isa<ObjCMethodDecl>(Param->getDeclContext()); @@ -2090,36 +2147,35 @@ static std::string FormatFunctionParameter(ASTContext &Context, // The argument for a block pointer parameter is a block literal with // the appropriate type. - FunctionTypeLoc *Block = 0; - FunctionProtoTypeLoc *BlockProto = 0; + FunctionTypeLoc Block; + FunctionProtoTypeLoc BlockProto; TypeLoc TL; if (TypeSourceInfo *TSInfo = Param->getTypeSourceInfo()) { TL = TSInfo->getTypeLoc().getUnqualifiedLoc(); while (true) { // Look through typedefs. if (!SuppressBlock) { - if (TypedefTypeLoc *TypedefTL = dyn_cast<TypedefTypeLoc>(&TL)) { - if (TypeSourceInfo *InnerTSInfo - = TypedefTL->getTypedefNameDecl()->getTypeSourceInfo()) { + if (TypedefTypeLoc TypedefTL = TL.getAs<TypedefTypeLoc>()) { + if (TypeSourceInfo *InnerTSInfo = + TypedefTL.getTypedefNameDecl()->getTypeSourceInfo()) { TL = InnerTSInfo->getTypeLoc().getUnqualifiedLoc(); continue; } } // Look through qualified types - if (QualifiedTypeLoc *QualifiedTL = dyn_cast<QualifiedTypeLoc>(&TL)) { - TL = QualifiedTL->getUnqualifiedLoc(); + if (QualifiedTypeLoc QualifiedTL = TL.getAs<QualifiedTypeLoc>()) { + TL = QualifiedTL.getUnqualifiedLoc(); continue; } } // Try to get the function prototype behind the block pointer type, // then we're done. - if (BlockPointerTypeLoc *BlockPtr - = dyn_cast<BlockPointerTypeLoc>(&TL)) { - TL = BlockPtr->getPointeeLoc().IgnoreParens(); - Block = dyn_cast<FunctionTypeLoc>(&TL); - BlockProto = dyn_cast<FunctionProtoTypeLoc>(&TL); + if (BlockPointerTypeLoc BlockPtr = TL.getAs<BlockPointerTypeLoc>()) { + TL = BlockPtr.getPointeeLoc().IgnoreParens(); + Block = TL.getAs<FunctionTypeLoc>(); + BlockProto = TL.getAs<FunctionProtoTypeLoc>(); } break; } @@ -2147,27 +2203,27 @@ static std::string FormatFunctionParameter(ASTContext &Context, // We have the function prototype behind the block pointer type, as it was // written in the source. std::string Result; - QualType ResultType = Block->getTypePtr()->getResultType(); + QualType ResultType = Block.getTypePtr()->getResultType(); if (!ResultType->isVoidType() || SuppressBlock) ResultType.getAsStringInternal(Result, Policy); // Format the parameter list. std::string Params; - if (!BlockProto || Block->getNumArgs() == 0) { - if (BlockProto && BlockProto->getTypePtr()->isVariadic()) + if (!BlockProto || Block.getNumArgs() == 0) { + if (BlockProto && BlockProto.getTypePtr()->isVariadic()) Params = "(...)"; else Params = "(void)"; } else { Params += "("; - for (unsigned I = 0, N = Block->getNumArgs(); I != N; ++I) { + for (unsigned I = 0, N = Block.getNumArgs(); I != N; ++I) { if (I) Params += ", "; - Params += FormatFunctionParameter(Context, Policy, Block->getArg(I), + Params += FormatFunctionParameter(Context, Policy, Block.getArg(I), /*SuppressName=*/false, /*SuppressBlock=*/true); - if (I == N - 1 && BlockProto->getTypePtr()->isVariadic()) + if (I == N - 1 && BlockProto.getTypePtr()->isVariadic()) Params += ", ..."; } Params += ")"; @@ -2195,14 +2251,14 @@ static std::string FormatFunctionParameter(ASTContext &Context, /// \brief Add function parameter chunks to the given code completion string. static void AddFunctionParameterChunks(ASTContext &Context, const PrintingPolicy &Policy, - FunctionDecl *Function, + const FunctionDecl *Function, CodeCompletionBuilder &Result, unsigned Start = 0, bool InOptional = false) { bool FirstParameter = true; for (unsigned P = Start, N = Function->getNumParams(); P != N; ++P) { - ParmVarDecl *Param = Function->getParamDecl(P); + const ParmVarDecl *Param = Function->getParamDecl(P); if (Param->hasDefaultArg() && !InOptional) { // When we see an optional default argument, put that argument and @@ -2248,7 +2304,7 @@ static void AddFunctionParameterChunks(ASTContext &Context, /// \brief Add template parameter chunks to the given code completion string. static void AddTemplateParameterChunks(ASTContext &Context, const PrintingPolicy &Policy, - TemplateDecl *Template, + const TemplateDecl *Template, CodeCompletionBuilder &Result, unsigned MaxParameters = 0, unsigned Start = 0, @@ -2346,7 +2402,7 @@ AddQualifierToCompletionString(CodeCompletionBuilder &Result, static void AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result, - FunctionDecl *Function) { + const FunctionDecl *Function) { const FunctionProtoType *Proto = Function->getType()->getAs<FunctionProtoType>(); if (!Proto || !Proto->getTypeQuals()) @@ -2383,7 +2439,8 @@ AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result, /// \brief Add the name of the given declaration static void AddTypedNameChunk(ASTContext &Context, const PrintingPolicy &Policy, - NamedDecl *ND, CodeCompletionBuilder &Result) { + const NamedDecl *ND, + CodeCompletionBuilder &Result) { DeclarationName Name = ND->getDeclName(); if (!Name) return; @@ -2484,6 +2541,27 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, if (Declaration) { Result.addParentContext(Declaration->getDeclContext()); Pattern->ParentName = Result.getParentName(); + // Provide code completion comment for self.GetterName where + // GetterName is the getter method for a property with name + // different from the property name (declared via a property + // getter attribute. + const NamedDecl *ND = Declaration; + if (const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(ND)) + if (M->isPropertyAccessor()) + if (const ObjCPropertyDecl *PDecl = M->findPropertyDecl()) + if (PDecl->getGetterName() == M->getSelector() && + PDecl->getIdentifier() != M->getIdentifier()) { + if (const RawComment *RC = + Ctx.getRawCommentForAnyRedecl(M)) { + Result.addBriefComment(RC->getBriefText(Ctx)); + Pattern->BriefComment = Result.getBriefComment(); + } + else if (const RawComment *RC = + Ctx.getRawCommentForAnyRedecl(PDecl)) { + Result.addBriefComment(RC->getBriefText(Ctx)); + Pattern->BriefComment = Result.getBriefComment(); + } + } } return Pattern; @@ -2495,8 +2573,9 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, } if (Kind == RK_Macro) { - MacroInfo *MI = PP.getMacroInfoHistory(Macro); - assert(MI && "Not a macro?"); + const MacroDirective *MD = PP.getMacroDirectiveHistory(Macro); + assert(MD && "Not a macro?"); + const MacroInfo *MI = MD->getMacroInfo(); Result.AddTypedTextChunk( Result.getAllocator().CopyString(Macro->getName())); @@ -2540,14 +2619,19 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, } assert(Kind == RK_Declaration && "Missed a result kind?"); - NamedDecl *ND = Declaration; + const NamedDecl *ND = Declaration; Result.addParentContext(ND->getDeclContext()); if (IncludeBriefComments) { // Add documentation comment, if it exists. if (const RawComment *RC = Ctx.getRawCommentForAnyRedecl(ND)) { Result.addBriefComment(RC->getBriefText(Ctx)); - } + } + else if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND)) + if (OMD->isPropertyAccessor()) + if (const ObjCPropertyDecl *PDecl = OMD->findPropertyDecl()) + if (const RawComment *RC = Ctx.getRawCommentForAnyRedecl(PDecl)) + Result.addBriefComment(RC->getBriefText(Ctx)); } if (StartsNestedNameSpecifier) { @@ -2565,7 +2649,7 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, AddResultTypeChunk(Ctx, Policy, ND, Result); - if (FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) { + if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) { AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, Ctx, Policy); AddTypedNameChunk(Ctx, Policy, ND, Result); @@ -2576,7 +2660,7 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, return Result.TakeString(); } - if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(ND)) { + if (const FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(ND)) { AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, Ctx, Policy); FunctionDecl *Function = FunTmpl->getTemplatedDecl(); @@ -2630,7 +2714,7 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, return Result.TakeString(); } - if (TemplateDecl *Template = dyn_cast<TemplateDecl>(ND)) { + if (const TemplateDecl *Template = dyn_cast<TemplateDecl>(ND)) { AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, Ctx, Policy); Result.AddTypedTextChunk( @@ -2641,7 +2725,7 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, return Result.TakeString(); } - if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND)) { + if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND)) { Selector Sel = Method->getSelector(); if (Sel.isUnarySelector()) { Result.AddTypedTextChunk(Result.getAllocator().CopyString( @@ -2662,8 +2746,8 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, Result.AddTypedTextChunk(""); } unsigned Idx = 0; - for (ObjCMethodDecl::param_iterator P = Method->param_begin(), - PEnd = Method->param_end(); + for (ObjCMethodDecl::param_const_iterator P = Method->param_begin(), + PEnd = Method->param_end(); P != PEnd; (void)++P, ++Idx) { if (Idx > 0) { std::string Keyword; @@ -2827,7 +2911,7 @@ unsigned clang::getMacroUsagePriority(StringRef MacroName, return Priority; } -CXCursorKind clang::getCursorKindForDecl(Decl *D) { +CXCursorKind clang::getCursorKindForDecl(const Decl *D) { if (!D) return CXCursor_UnexposedDecl; @@ -2887,7 +2971,7 @@ CXCursorKind clang::getCursorKindForDecl(Decl *D) { return CXCursor_ModuleImportDecl; default: - if (TagDecl *TD = dyn_cast<TagDecl>(D)) { + if (const TagDecl *TD = dyn_cast<TagDecl>(D)) { switch (TD->getTagKind()) { case TTK_Interface: // fall through case TTK_Struct: return CXCursor_StructDecl; @@ -2930,7 +3014,7 @@ static void AddPrettyFunctionResults(const LangOptions &LangOpts, Results.AddResult(Result("__PRETTY_FUNCTION__", CCP_Constant)); Results.AddResult(Result("__FUNCTION__", CCP_Constant)); - if (LangOpts.C99 || LangOpts.CPlusPlus0x) + if (LangOpts.C99 || LangOpts.CPlusPlus11) Results.AddResult(Result("__func__", CCP_Constant)); Results.ExitScope(); } @@ -3036,7 +3120,7 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, M != MEnd; ++M) { CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); - CXXMethodDecl *Overridden = const_cast<CXXMethodDecl *>(*M); + const CXXMethodDecl *Overridden = *M; if (Overridden->getCanonicalDecl() == Method->getCanonicalDecl()) continue; @@ -3092,7 +3176,7 @@ void Sema::CodeCompleteModuleImport(SourceLocation ImportLoc, typedef CodeCompletionResult Result; if (Path.empty()) { // Enumerate all top-level modules. - llvm::SmallVector<Module *, 8> Modules; + SmallVector<Module *, 8> Modules; PP.getHeaderSearchInfo().collectAllModules(Modules); for (unsigned I = 0, N = Modules.size(); I != N; ++I) { Builder.AddTypedTextChunk( @@ -3265,7 +3349,7 @@ void Sema::CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, // the initial opening bracket '[' missing. Add appropriate completions. if (AllowNonIdentifiers && !AllowNestedNameSpecifiers && DS.getTypeSpecType() == DeclSpec::TST_typename && - DS.getStorageClassSpecAsWritten() == DeclSpec::SCS_unspecified && + DS.getStorageClassSpec() == DeclSpec::SCS_unspecified && !DS.isThreadSpecified() && !DS.isExternInLinkageSpec() && DS.getTypeSpecComplex() == DeclSpec::TSC_unspecified && DS.getTypeSpecSign() == DeclSpec::TSS_unspecified && @@ -3395,7 +3479,8 @@ static void AddObjCProperties(ObjCContainerDecl *Container, P != PEnd; ++P) { if (AddedProperties.insert(P->getIdentifier())) - Results.MaybeAddResult(Result(*P, 0), CurContext); + Results.MaybeAddResult(Result(*P, Results.getBasePriority(*P), 0), + CurContext); } // Add nullary methods @@ -3432,9 +3517,11 @@ static void AddObjCProperties(ObjCContainerDecl *Container, } else if (ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Container)){ if (AllowCategories) { // Look through categories. - for (ObjCCategoryDecl *Category = IFace->getCategoryList(); - Category; Category = Category->getNextClassCategory()) - AddObjCProperties(Category, AllowCategories, AllowNullaryMethods, + for (ObjCInterfaceDecl::known_categories_iterator + Cat = IFace->known_categories_begin(), + CatEnd = IFace->known_categories_end(); + Cat != CatEnd; ++Cat) + AddObjCProperties(*Cat, AllowCategories, AllowNullaryMethods, CurContext, AddedProperties, Results); } @@ -3642,6 +3729,9 @@ void Sema::CodeCompleteTypeQualifiers(DeclSpec &DS) { if (getLangOpts().C99 && !(DS.getTypeQualifiers() & DeclSpec::TQ_restrict)) Results.AddResult("restrict"); + if (getLangOpts().C11 && + !(DS.getTypeQualifiers() & DeclSpec::TQ_atomic)) + Results.AddResult("_Atomic"); Results.ExitScope(); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), @@ -3724,8 +3814,7 @@ void Sema::CodeCompleteCase(Scope *S) { if (EnumeratorsSeen.count(*E)) continue; - CodeCompletionResult R(*E, Qualifier); - R.Priority = CCP_EnumInCase; + CodeCompletionResult R(*E, CCP_EnumInCase, Qualifier); Results.AddResult(R, CurContext, 0, false); } Results.ExitScope(); @@ -4094,7 +4183,8 @@ void Sema::CodeCompleteNamespaceDecl(Scope *S) { NS = OrigToLatest.begin(), NSEnd = OrigToLatest.end(); NS != NSEnd; ++NS) - Results.AddResult(CodeCompletionResult(NS->second, 0), + Results.AddResult(CodeCompletionResult( + NS->second, Results.getBasePriority(NS->second), 0), CurContext, 0, false); Results.ExitScope(); } @@ -4308,7 +4398,8 @@ void Sema::CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, continue; if (Known.insert(Var->getIdentifier())) - Results.AddResult(CodeCompletionResult(Var), CurContext, 0, false); + Results.AddResult(CodeCompletionResult(Var, CCP_LocalDeclaration), + CurContext, 0, false); } } @@ -4410,6 +4501,14 @@ static void AddObjCTopLevelResults(ResultBuilder &Results, bool NeedAt) { Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("class"); Results.AddResult(Result(Builder.TakeString())); + + if (Results.getSema().getLangOpts().Modules) { + // @import name + Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt, "import")); + Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); + Builder.AddPlaceholderChunk("module"); + Results.AddResult(Result(Builder.TakeString())); + } } void Sema::CodeCompleteObjCAtDirective(Scope *S) { @@ -4757,10 +4856,15 @@ static void AddObjCMethods(ObjCContainerDecl *Container, bool InOriginalClass = true) { typedef CodeCompletionResult Result; Container = getContainerDef(Container); + ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Container); + bool isRootClass = IFace && !IFace->getSuperClass(); for (ObjCContainerDecl::method_iterator M = Container->meth_begin(), MEnd = Container->meth_end(); M != MEnd; ++M) { - if (M->isInstanceMethod() == WantInstanceMethods) { + // The instance methods on the root class can be messaged via the + // metaclass. + if (M->isInstanceMethod() == WantInstanceMethods || + (isRootClass && !WantInstanceMethods)) { // Check whether the selector identifiers we've been given are a // subset of the identifiers for this particular method. if (!isAcceptableObjCMethod(*M, WantKind, SelIdents, NumSelIdents, @@ -4770,7 +4874,7 @@ static void AddObjCMethods(ObjCContainerDecl *Container, if (!Selectors.insert(M->getSelector())) continue; - Result R = Result(*M, 0); + Result R = Result(*M, Results.getBasePriority(*M), 0); R.StartParameter = NumSelIdents; R.AllParametersAreInformative = (WantKind != MK_Any); if (!InOriginalClass) @@ -4793,7 +4897,6 @@ static void AddObjCMethods(ObjCContainerDecl *Container, } } - ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Container); if (!IFace || !IFace->hasDefinition()) return; @@ -4805,9 +4908,13 @@ static void AddObjCMethods(ObjCContainerDecl *Container, CurContext, Selectors, AllowSameLength, Results, false); // Add methods in categories. - for (ObjCCategoryDecl *CatDecl = IFace->getCategoryList(); CatDecl; - CatDecl = CatDecl->getNextClassCategory()) { - AddObjCMethods(CatDecl, WantInstanceMethods, WantKind, SelIdents, + for (ObjCInterfaceDecl::known_categories_iterator + Cat = IFace->known_categories_begin(), + CatEnd = IFace->known_categories_end(); + Cat != CatEnd; ++Cat) { + ObjCCategoryDecl *CatDecl = *Cat; + + AddObjCMethods(CatDecl, WantInstanceMethods, WantKind, SelIdents, NumSelIdents, CurContext, Selectors, AllowSameLength, Results, InOriginalClass); @@ -4946,6 +5053,11 @@ void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, Builder.AddTextChunk("sender"); Results.AddResult(CodeCompletionResult(Builder.TakeString())); } + + // If we're completing the return type, provide 'instancetype'. + if (!IsParameter) { + Results.AddResult(CodeCompletionResult("instancetype")); + } // Add various builtin type names and specifiers. AddOrdinaryNameResults(PCC_Type, S, *this, Results); @@ -5075,11 +5187,14 @@ static ObjCMethodDecl *AddSuperSendCompletion(Sema &S, bool NeedSuperKeyword, // Check in categories or class extensions. if (!SuperMethod) { - for (ObjCCategoryDecl *Category = Class->getCategoryList(); Category; - Category = Category->getNextClassCategory()) - if ((SuperMethod = Category->getMethod(CurMethod->getSelector(), + for (ObjCInterfaceDecl::known_categories_iterator + Cat = Class->known_categories_begin(), + CatEnd = Class->known_categories_end(); + Cat != CatEnd; ++Cat) { + if ((SuperMethod = Cat->getMethod(CurMethod->getSelector(), CurMethod->isInstanceMethod()))) break; + } } } @@ -5163,7 +5278,7 @@ void Sema::CodeCompleteObjCMessageReceiver(Scope *S) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_ObjCMessageReceiver, - getLangOpts().CPlusPlus0x + getLangOpts().CPlusPlus11 ? &ResultBuilder::IsObjCMessageReceiverOrLambdaCapture : &ResultBuilder::IsObjCMessageReceiver); @@ -5182,7 +5297,7 @@ void Sema::CodeCompleteObjCMessageReceiver(Scope *S) { AddSuperSendCompletion(*this, /*NeedSuperKeyword=*/true, 0, 0, Results); } - if (getLangOpts().CPlusPlus0x) + if (getLangOpts().CPlusPlus11) addThisCompletion(*this, Results); Results.ExitScope(); @@ -5224,7 +5339,7 @@ void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, } else { // "super" may be the name of a type or variable. Figure out which // it is. - IdentifierInfo *Super = &Context.Idents.get("super"); + IdentifierInfo *Super = getSuperIdentifier(); NamedDecl *ND = LookupSingleName(S, Super, SuperLoc, LookupOrdinaryName); if ((CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(ND))) { @@ -5274,7 +5389,7 @@ static QualType getPreferredArgumentTypeForMessageSend(ResultBuilder &Results, if (R.Kind == Result::RK_Declaration && isa<ObjCMethodDecl>(R.Declaration)) { if (R.Priority <= BestPriority) { - ObjCMethodDecl *Method = cast<ObjCMethodDecl>(R.Declaration); + const ObjCMethodDecl *Method = cast<ObjCMethodDecl>(R.Declaration); if (NumSelIdents <= Method->param_size()) { QualType MyPreferredType = Method->param_begin()[NumSelIdents - 1] ->getType(); @@ -5362,7 +5477,7 @@ static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, NumSelIdents)) continue; - Result R(MethList->Method, 0); + Result R(MethList->Method, Results.getBasePriority(MethList->Method),0); R.StartParameter = NumSelIdents; R.AllParametersAreInformative = false; Results.MaybeAddResult(R, SemaRef.CurContext); @@ -5538,7 +5653,7 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, if (!Selectors.insert(MethList->Method->getSelector())) continue; - Result R(MethList->Method, 0); + Result R(MethList->Method, Results.getBasePriority(MethList->Method),0); R.StartParameter = NumSelIdents; R.AllParametersAreInformative = false; Results.MaybeAddResult(R, CurContext); @@ -5656,7 +5771,8 @@ static void AddProtocolResults(DeclContext *Ctx, DeclContext *CurContext, // Record any protocols we find. if (ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(*D)) if (!OnlyForwardDeclarations || !Proto->hasDefinition()) - Results.AddResult(Result(Proto, 0), CurContext, 0, false); + Results.AddResult(Result(Proto, Results.getBasePriority(Proto), 0), + CurContext, 0, false); } } @@ -5724,7 +5840,8 @@ static void AddInterfaceResults(DeclContext *Ctx, DeclContext *CurContext, if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(*D)) if ((!OnlyForwardDeclarations || !Class->hasDefinition()) && (!OnlyUnimplemented || !Class->getImplementation())) - Results.AddResult(Result(Class, 0), CurContext, 0, false); + Results.AddResult(Result(Class, Results.getBasePriority(Class), 0), + CurContext, 0, false); } } @@ -5806,11 +5923,15 @@ void Sema::CodeCompleteObjCInterfaceCategory(Scope *S, llvm::SmallPtrSet<IdentifierInfo *, 16> CategoryNames; NamedDecl *CurClass = LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName); - if (ObjCInterfaceDecl *Class = dyn_cast_or_null<ObjCInterfaceDecl>(CurClass)) - for (ObjCCategoryDecl *Category = Class->getCategoryList(); Category; - Category = Category->getNextClassCategory()) - CategoryNames.insert(Category->getIdentifier()); - + if (ObjCInterfaceDecl *Class = dyn_cast_or_null<ObjCInterfaceDecl>(CurClass)){ + for (ObjCInterfaceDecl::visible_categories_iterator + Cat = Class->visible_categories_begin(), + CatEnd = Class->visible_categories_end(); + Cat != CatEnd; ++Cat) { + CategoryNames.insert(Cat->getIdentifier()); + } + } + // Add all of the categories we know about. Results.EnterNewScope(); TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); @@ -5819,7 +5940,8 @@ void Sema::CodeCompleteObjCInterfaceCategory(Scope *S, D != DEnd; ++D) if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(*D)) if (CategoryNames.insert(Category->getIdentifier())) - Results.AddResult(Result(Category, 0), CurContext, 0, false); + Results.AddResult(Result(Category, Results.getBasePriority(Category),0), + CurContext, 0, false); Results.ExitScope(); HandleCodeCompleteResults(this, CodeCompleter, @@ -5852,11 +5974,15 @@ void Sema::CodeCompleteObjCImplementationCategory(Scope *S, Results.EnterNewScope(); bool IgnoreImplemented = true; while (Class) { - for (ObjCCategoryDecl *Category = Class->getCategoryList(); Category; - Category = Category->getNextClassCategory()) - if ((!IgnoreImplemented || !Category->getImplementation()) && - CategoryNames.insert(Category->getIdentifier())) - Results.AddResult(Result(Category, 0), CurContext, 0, false); + for (ObjCInterfaceDecl::visible_categories_iterator + Cat = Class->visible_categories_begin(), + CatEnd = Class->visible_categories_end(); + Cat != CatEnd; ++Cat) { + if ((!IgnoreImplemented || !Cat->getImplementation()) && + CategoryNames.insert(Cat->getIdentifier())) + Results.AddResult(Result(*Cat, Results.getBasePriority(*Cat), 0), + CurContext, 0, false); + } Class = Class->getSuperClass(); IgnoreImplemented = false; @@ -5956,7 +6082,8 @@ void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S, for(; Class; Class = Class->getSuperClass()) { for (ObjCIvarDecl *Ivar = Class->all_declared_ivar_begin(); Ivar; Ivar = Ivar->getNextIvar()) { - Results.AddResult(Result(Ivar, 0), CurContext, 0, false); + Results.AddResult(Result(Ivar, Results.getBasePriority(Ivar), 0), + CurContext, 0, false); // Determine whether we've seen an ivar with a name similar to the // property. @@ -6032,12 +6159,14 @@ static void FindImplementableMethods(ASTContext &Context, KnownMethods, InOriginalClass); // Add methods from any class extensions and categories. - for (const ObjCCategoryDecl *Cat = IFace->getCategoryList(); Cat; - Cat = Cat->getNextClassCategory()) - FindImplementableMethods(Context, const_cast<ObjCCategoryDecl*>(Cat), - WantInstanceMethods, ReturnType, + for (ObjCInterfaceDecl::visible_categories_iterator + Cat = IFace->visible_categories_begin(), + CatEnd = IFace->visible_categories_end(); + Cat != CatEnd; ++Cat) { + FindImplementableMethods(Context, *Cat, WantInstanceMethods, ReturnType, KnownMethods, false); - + } + // Visit the superclass. if (IFace->getSuperClass()) FindImplementableMethods(Context, IFace->getSuperClass(), @@ -6167,7 +6296,7 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, // The uppercased name of the property name. std::string UpperKey = PropName->getName(); if (!UpperKey.empty()) - UpperKey[0] = toupper(UpperKey[0]); + UpperKey[0] = toUppercase(UpperKey[0]); bool ReturnTypeMatchesProperty = ReturnType.isNull() || Context.hasSameUnqualifiedType(ReturnType.getNonReferenceType(), @@ -6897,9 +7026,12 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, IFace = Category->getClassInterface(); if (IFace) { - for (ObjCCategoryDecl *Category = IFace->getCategoryList(); Category; - Category = Category->getNextClassCategory()) - Containers.push_back(Category); + for (ObjCInterfaceDecl::visible_categories_iterator + Cat = IFace->visible_categories_begin(), + CatEnd = IFace->visible_categories_end(); + Cat != CatEnd; ++Cat) { + Containers.push_back(*Cat); + } } for (unsigned I = 0, N = Containers.size(); I != N; ++I) { @@ -6975,7 +7107,7 @@ void Sema::CodeCompleteObjCMethodDeclSelector(Scope *S, continue; } - Result R(MethList->Method, 0); + Result R(MethList->Method, Results.getBasePriority(MethList->Method), 0); R.StartParameter = NumSelIdents; R.AllParametersAreInformative = false; R.DeclaringEntity = true; |