[cfe-commits] r91139 - in /cfe/trunk: lib/Sema/SemaCodeComplete.cpp test/CodeCompletion/member-access.cpp

Douglas Gregor dgregor at apple.com
Fri Dec 11 10:44:16 PST 2009


Author: dgregor
Date: Fri Dec 11 12:44:16 2009
New Revision: 91139

URL: http://llvm.org/viewvc/llvm-project?rev=91139&view=rev
Log:
Add a function's cv-qualifiers to the code-completion results as an
informative chunk.

Modified:
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/test/CodeCompletion/member-access.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=91139&r1=91138&r2=91139&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Dec 11 12:44:16 2009
@@ -947,10 +947,11 @@
 
 /// \brief Add a qualifier to the given code-completion string, if the
 /// provided nested-name-specifier is non-NULL.
-void AddQualifierToCompletionString(CodeCompletionString *Result, 
-                                    NestedNameSpecifier *Qualifier, 
-                                    bool QualifierIsInformative,
-                                    ASTContext &Context) {
+static void 
+AddQualifierToCompletionString(CodeCompletionString *Result, 
+                               NestedNameSpecifier *Qualifier, 
+                               bool QualifierIsInformative,
+                               ASTContext &Context) {
   if (!Qualifier)
     return;
   
@@ -965,6 +966,23 @@
     Result->AddTextChunk(PrintedNNS);
 }
 
+static void AddFunctionTypeQualsToCompletionString(CodeCompletionString *Result,
+                                                   FunctionDecl *Function) {
+  const FunctionProtoType *Proto
+    = Function->getType()->getAs<FunctionProtoType>();
+  if (!Proto || !Proto->getTypeQuals())
+    return;
+
+  std::string QualsStr;
+  if (Proto->getTypeQuals() & Qualifiers::Const)
+    QualsStr += " const";
+  if (Proto->getTypeQuals() & Qualifiers::Volatile)
+    QualsStr += " volatile";
+  if (Proto->getTypeQuals() & Qualifiers::Restrict)
+    QualsStr += " restrict";
+  Result->AddInformativeChunk(QualsStr);
+}
+
 /// \brief If possible, create a new code completion string for the given
 /// result.
 ///
@@ -1038,6 +1056,7 @@
     Result->AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
     AddFunctionParameterChunks(S.Context, Function, Result);
     Result->AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+    AddFunctionTypeQualsToCompletionString(Result, Function);
     return Result;
   }
   
@@ -1091,6 +1110,7 @@
     Result->AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
     AddFunctionParameterChunks(S.Context, Function, Result);
     Result->AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+    AddFunctionTypeQualsToCompletionString(Result, Function);
     return Result;
   }
   

Modified: cfe/trunk/test/CodeCompletion/member-access.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/member-access.cpp?rev=91139&r1=91138&r2=91139&view=diff

==============================================================================
--- cfe/trunk/test/CodeCompletion/member-access.cpp (original)
+++ cfe/trunk/test/CodeCompletion/member-access.cpp Fri Dec 11 12:44:16 2009
@@ -11,7 +11,7 @@
 
 struct Base3 : Base1, Base2 {
   void memfun1(float);
-  void memfun1(double);
+  void memfun1(double) const;
   void memfun2(int);
 };
 
@@ -34,7 +34,7 @@
   // CHECK-CC1: member3 : 0
   // CHECK-CC1: member4 : 0
   // CHECK-CC1: memfun1 : 0 : [#Base3::#]memfun1(<#float#>)
-  // CHECK-CC1: memfun1 : 0 : [#Base3::#]memfun1(<#double#>)
+  // CHECK-CC1: memfun1 : 0 : [#Base3::#]memfun1(<#double#>)[# const#]
   // CHECK-CC1: memfun2 : 0 : [#Base3::#]memfun2(<#int#>)
   // CHECK-CC1: memfun3 : 0 : memfun3(<#int#>)
   // CHECK-CC1: memfun1 : 0 (Hidden) : Base2::memfun1(<#int#>)





More information about the cfe-commits mailing list