diff options
| -rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 66 | 
1 files changed, 36 insertions, 30 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index dba916e0b99..eec01b0c892 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -3869,6 +3869,40 @@ static void AddObjCProperties(    }  } +static void AddRecordMembersCompletionResults(Sema &SemaRef, +                                              ResultBuilder &Results, Scope *S, +                                              QualType BaseType, +                                              RecordDecl *RD) { +  // Indicate that we are performing a member access, and the cv-qualifiers +  // for the base object type. +  Results.setObjectTypeQualifiers(BaseType.getQualifiers()); + +  // Access to a C/C++ class, struct, or union. +  Results.allowNestedNameSpecifiers(); +  CodeCompletionDeclConsumer Consumer(Results, SemaRef.CurContext); +  SemaRef.LookupVisibleDecls(RD, Sema::LookupMemberName, Consumer, +                             SemaRef.CodeCompleter->includeGlobals()); + +  if (SemaRef.getLangOpts().CPlusPlus) { +    if (!Results.empty()) { +      // The "template" keyword can follow "->" or "." in the grammar. +      // However, we only want to suggest the template keyword if something +      // is dependent. +      bool IsDependent = BaseType->isDependentType(); +      if (!IsDependent) { +        for (Scope *DepScope = S; DepScope; DepScope = DepScope->getParent()) +          if (DeclContext *Ctx = DepScope->getEntity()) { +            IsDependent = Ctx->isDependentContext(); +            break; +          } +      } + +      if (IsDependent) +        Results.AddResult(CodeCompletionResult("template")); +    } +  } +} +  void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,                                             SourceLocation OpLoc, bool IsArrow,                                             bool IsBaseExprStatement) { @@ -3879,8 +3913,6 @@ void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,    if (ConvertedBase.isInvalid())      return;    Base = ConvertedBase.get(); - -  typedef CodeCompletionResult Result;    QualType BaseType = Base->getType(); @@ -3915,34 +3947,8 @@ void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,                          &ResultBuilder::IsMember);    Results.EnterNewScope();    if (const RecordType *Record = BaseType->getAs<RecordType>()) { -    // Indicate that we are performing a member access, and the cv-qualifiers -    // for the base object type. -    Results.setObjectTypeQualifiers(BaseType.getQualifiers()); -     -    // Access to a C/C++ class, struct, or union. -    Results.allowNestedNameSpecifiers(); -    CodeCompletionDeclConsumer Consumer(Results, CurContext); -    LookupVisibleDecls(Record->getDecl(), LookupMemberName, Consumer, -                       CodeCompleter->includeGlobals()); - -    if (getLangOpts().CPlusPlus) { -      if (!Results.empty()) { -        // The "template" keyword can follow "->" or "." in the grammar. -        // However, we only want to suggest the template keyword if something -        // is dependent. -        bool IsDependent = BaseType->isDependentType(); -        if (!IsDependent) { -          for (Scope *DepScope = S; DepScope; DepScope = DepScope->getParent()) -            if (DeclContext *Ctx = DepScope->getEntity()) { -              IsDependent = Ctx->isDependentContext(); -              break; -            } -        } - -        if (IsDependent) -          Results.AddResult(Result("template")); -      } -    } +    AddRecordMembersCompletionResults(*this, Results, S, BaseType, +                                      Record->getDecl());    } else if (!IsArrow && BaseType->isObjCObjectPointerType()) {      // Objective-C property reference.      AddedPropertiesSet AddedProperties;  | 

