]> granicus.if.org Git - clang/commitdiff
Do not add a colon chunk to the code completion of class inheritance access modifiers
authorErik Verbruggen <erikjv@me.com>
Tue, 24 Oct 2017 13:46:58 +0000 (13:46 +0000)
committerErik Verbruggen <erikjv@me.com>
Tue, 24 Oct 2017 13:46:58 +0000 (13:46 +0000)
With enabled CINDEXTEST_CODE_COMPLETE_PATTERNS env option (which enables
IncludeCodePatterns in completion options) code completion after colon
currently suggests access modifiers with 2 completion chunks which is
incorrect.

Example:
class A : <Cursor>B
{
}

Currently we get 'NotImplemented:{TypedText public}{Colon :} (40)'
but the correct line is just 'NotImplemented:{TypedText public} (40)'

The fix introduces more specific scope that occurs between ':' and '{'
It allows us to determine when we don't need to add ':' as a second
chunk to the public/protected/private access modifiers.

Patch by Ivan Donchevskii!

Differential Revision: https://reviews.llvm.org/D38618

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316436 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Scope.h
lib/Parse/ParseDeclCXX.cpp
lib/Sema/SemaCodeComplete.cpp
test/Index/complete-super.cpp

index e892d8205b557feb0971c0459d0c5a41e29aa0d5..cd58a9910f98ea31ed9d8acc9630423eed9f3f61 100644 (file)
@@ -127,6 +127,9 @@ public:
 
     /// This is a compound statement scope.
     CompoundStmtScope = 0x400000,
+
+    /// We are between inheritance colon and the real class/struct definition scope.
+    ClassInheritanceScope = 0x800000,
   };
 private:
   /// The parent scope for this scope.  This is null for the translation-unit
index ada67e84d2136c370509a4d1c6ae373095f5d681..ca195901cfbb4faa304a4e4485af9bdc34eb05d0 100644 (file)
@@ -3195,6 +3195,9 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
   }
 
   if (Tok.is(tok::colon)) {
+    ParseScope InheritanceScope(this, getCurScope()->getFlags() |
+                                          Scope::ClassInheritanceScope);
+
     ParseBaseClause(TagDecl);
     if (!Tok.is(tok::l_brace)) {
       bool SuggestFixIt = false;
index 90a15e17a2fc0e480abcd6e32b6beaa6e4175169..fdfc39993ded98b7d45dc11c58e412e8e0e56089 100644 (file)
@@ -1658,21 +1658,23 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC,
       if (CCC == Sema::PCC_Class) {
         AddTypedefResult(Results);
 
+        bool IsNotInheritanceScope =
+            !(S->getFlags() & Scope::ClassInheritanceScope);
         // public:
         Builder.AddTypedTextChunk("public");
-        if (Results.includeCodePatterns())
+        if (IsNotInheritanceScope && Results.includeCodePatterns())
           Builder.AddChunk(CodeCompletionString::CK_Colon);
         Results.AddResult(Result(Builder.TakeString()));
 
         // protected:
         Builder.AddTypedTextChunk("protected");
-        if (Results.includeCodePatterns())
+        if (IsNotInheritanceScope && Results.includeCodePatterns())
           Builder.AddChunk(CodeCompletionString::CK_Colon);
         Results.AddResult(Result(Builder.TakeString()));
 
         // private:
         Builder.AddTypedTextChunk("private");
-        if (Results.includeCodePatterns())
+        if (IsNotInheritanceScope && Results.includeCodePatterns())
           Builder.AddChunk(CodeCompletionString::CK_Colon);
         Results.AddResult(Result(Builder.TakeString()));
       }
index 9ffa7c8a40563c89d951b30726231e312b98db30..92d3f7f585f3b674187686eac63e870a3ca5a1ba 100644 (file)
@@ -40,3 +40,8 @@ void B::bar(float real) {
 // CHECK-ACCESS-PATTERN: NotImplemented:{TypedText private}{Colon :} (40)
 // CHECK-ACCESS-PATTERN: NotImplemented:{TypedText protected}{Colon :} (40)
 // CHECK-ACCESS-PATTERN: NotImplemented:{TypedText public}{Colon :} (40)
+
+// RUN: env CINDEXTEST_CODE_COMPLETE_PATTERNS=1 c-index-test -code-completion-at=%s:10:12 %s | FileCheck -check-prefix=CHECK-INHERITANCE-PATTERN %s
+// CHECK-INHERITANCE-PATTERN: NotImplemented:{TypedText private} (40)
+// CHECK-INHERITANCE-PATTERN: NotImplemented:{TypedText protected} (40)
+// CHECK-INHERITANCE-PATTERN: NotImplemented:{TypedText public} (40)