Move CodeCompletionBuilder's chunk adding methods out of line.

This makes sense because chunk's ctor is also out of line and simplifies considerably
when inlined with a constant parameter. Shrinks clang on i386-linux-Release+Asserts by 65k.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153446 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h
index c77b68f..8d35ece 100644
--- a/include/clang/Sema/CodeCompleteConsumer.h
+++ b/include/clang/Sema/CodeCompleteConsumer.h
@@ -405,7 +405,7 @@
 
     Chunk() : Kind(CK_Text), Text(0) { }
 
-    Chunk(ChunkKind Kind, const char *Text = "");
+    explicit Chunk(ChunkKind Kind, const char *Text = "");
 
     /// \brief Create a new text chunk.
     static Chunk CreateText(const char *Text);
@@ -546,42 +546,28 @@
   CodeCompletionString *TakeString();
 
   /// \brief Add a new typed-text chunk.
-  void AddTypedTextChunk(const char *Text) {
-    Chunks.push_back(Chunk(CodeCompletionString::CK_TypedText, Text));
-  }
+  void AddTypedTextChunk(const char *Text);
 
   /// \brief Add a new text chunk.
-  void AddTextChunk(const char *Text) {
-    Chunks.push_back(Chunk::CreateText(Text));
-  }
+  void AddTextChunk(const char *Text);
 
   /// \brief Add a new optional chunk.
-  void AddOptionalChunk(CodeCompletionString *Optional) {
-    Chunks.push_back(Chunk::CreateOptional(Optional));
-  }
+  void AddOptionalChunk(CodeCompletionString *Optional);
 
   /// \brief Add a new placeholder chunk.
-  void AddPlaceholderChunk(const char *Placeholder) {
-    Chunks.push_back(Chunk::CreatePlaceholder(Placeholder));
-  }
+  void AddPlaceholderChunk(const char *Placeholder);
 
   /// \brief Add a new informative chunk.
-  void AddInformativeChunk(const char *Text) {
-    Chunks.push_back(Chunk::CreateInformative(Text));
-  }
+  void AddInformativeChunk(const char *Text);
 
   /// \brief Add a new result-type chunk.
-  void AddResultTypeChunk(const char *ResultType) {
-    Chunks.push_back(Chunk::CreateResultType(ResultType));
-  }
+  void AddResultTypeChunk(const char *ResultType);
 
   /// \brief Add a new current-parameter chunk.
-  void AddCurrentParameterChunk(const char *CurrentParameter) {
-    Chunks.push_back(Chunk::CreateCurrentParameter(CurrentParameter));
-  }
+  void AddCurrentParameterChunk(const char *CurrentParameter);
 
   /// \brief Add a new chunk.
-  void AddChunk(Chunk C) { Chunks.push_back(C); }
+  void AddChunk(CodeCompletionString::ChunkKind CK, const char *Text = "");
 
   void AddAnnotation(const char *A) { Annotations.push_back(A); }
 };
diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp
index ad5829e..caebe3a 100644
--- a/lib/Sema/CodeCompleteConsumer.cpp
+++ b/lib/Sema/CodeCompleteConsumer.cpp
@@ -277,6 +277,40 @@
   return Result;
 }
 
+void CodeCompletionBuilder::AddTypedTextChunk(const char *Text) {
+  Chunks.push_back(Chunk(CodeCompletionString::CK_TypedText, Text));
+}
+
+void CodeCompletionBuilder::AddTextChunk(const char *Text) {
+  Chunks.push_back(Chunk::CreateText(Text));
+}
+
+void CodeCompletionBuilder::AddOptionalChunk(CodeCompletionString *Optional) {
+  Chunks.push_back(Chunk::CreateOptional(Optional));
+}
+
+void CodeCompletionBuilder::AddPlaceholderChunk(const char *Placeholder) {
+  Chunks.push_back(Chunk::CreatePlaceholder(Placeholder));
+}
+
+void CodeCompletionBuilder::AddInformativeChunk(const char *Text) {
+  Chunks.push_back(Chunk::CreateInformative(Text));
+}
+
+void CodeCompletionBuilder::AddResultTypeChunk(const char *ResultType) {
+  Chunks.push_back(Chunk::CreateResultType(ResultType));
+}
+
+void
+CodeCompletionBuilder::AddCurrentParameterChunk(const char *CurrentParameter) {
+  Chunks.push_back(Chunk::CreateCurrentParameter(CurrentParameter));
+}
+
+void CodeCompletionBuilder::AddChunk(CodeCompletionString::ChunkKind CK,
+                                     const char *Text) {
+  Chunks.push_back(Chunk(CK, Text));
+}
+
 unsigned CodeCompletionResult::getPriorityFromDecl(NamedDecl *ND) {
   if (!ND)
     return CCP_Unlikely;
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp
index 7ee2bcb..b33c169 100644
--- a/lib/Sema/SemaCodeComplete.cpp
+++ b/lib/Sema/SemaCodeComplete.cpp
@@ -2180,7 +2180,6 @@
                                        CodeCompletionBuilder &Result,
                                        unsigned Start = 0,
                                        bool InOptional = false) {
-  typedef CodeCompletionString::Chunk Chunk;
   bool FirstParameter = true;
   
   for (unsigned P = Start, N = Function->getNumParams(); P != N; ++P) {
@@ -2191,7 +2190,7 @@
       // the remaining default arguments into a new, optional string.
       CodeCompletionBuilder Opt(Result.getAllocator());
       if (!FirstParameter)
-        Opt.AddChunk(Chunk(CodeCompletionString::CK_Comma));        
+        Opt.AddChunk(CodeCompletionString::CK_Comma);
       AddFunctionParameterChunks(Context, Policy, Function, Opt, P, true);
       Result.AddOptionalChunk(Opt.TakeString());
       break;
@@ -2200,7 +2199,7 @@
     if (FirstParameter)
       FirstParameter = false;
     else
-      Result.AddChunk(Chunk(CodeCompletionString::CK_Comma));
+      Result.AddChunk(CodeCompletionString::CK_Comma);
     
     InOptional = false;
     
@@ -2234,7 +2233,6 @@
                                        unsigned MaxParameters = 0,
                                        unsigned Start = 0,
                                        bool InDefaultArg = false) {
-  typedef CodeCompletionString::Chunk Chunk;
   bool FirstParameter = true;
   
   TemplateParameterList *Params = Template->getTemplateParameters();
@@ -2283,7 +2281,7 @@
       // the remaining default arguments into a new, optional string.
       CodeCompletionBuilder Opt(Result.getAllocator());
       if (!FirstParameter)
-        Opt.AddChunk(Chunk(CodeCompletionString::CK_Comma));
+        Opt.AddChunk(CodeCompletionString::CK_Comma);
       AddTemplateParameterChunks(Context, Policy, Template, Opt, MaxParameters,
                                  P - Params->begin(), true);
       Result.AddOptionalChunk(Opt.TakeString());
@@ -2295,7 +2293,7 @@
     if (FirstParameter)
       FirstParameter = false;
     else
-      Result.AddChunk(Chunk(CodeCompletionString::CK_Comma));
+      Result.AddChunk(CodeCompletionString::CK_Comma);
     
     // Add the placeholder string.
     Result.AddPlaceholderChunk(
@@ -2365,8 +2363,6 @@
 /// \brief Add the name of the given declaration 
 static void AddTypedNameChunk(ASTContext &Context, const PrintingPolicy &Policy,
                               NamedDecl *ND, CodeCompletionBuilder &Result) {
-  typedef CodeCompletionString::Chunk Chunk;
-  
   DeclarationName Name = ND->getDeclName();
   if (!Name)
     return;
@@ -2428,9 +2424,9 @@
     Result.AddTypedTextChunk(
                   Result.getAllocator().CopyString(Record->getNameAsString()));
     if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) {
-      Result.AddChunk(Chunk(CodeCompletionString::CK_LeftAngle));
+      Result.AddChunk(CodeCompletionString::CK_LeftAngle);
       AddTemplateParameterChunks(Context, Policy, Template, Result);
-      Result.AddChunk(Chunk(CodeCompletionString::CK_RightAngle));
+      Result.AddChunk(CodeCompletionString::CK_RightAngle);
     }
     break;
   }
@@ -2452,7 +2448,6 @@
 CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx,
                                                  Preprocessor &PP,
                                            CodeCompletionAllocator &Allocator) {
-  typedef CodeCompletionString::Chunk Chunk;
   CodeCompletionBuilder Result(Allocator, Priority, Availability);
   
   PrintingPolicy Policy = getCompletionPrintingPolicy(Ctx, PP);
@@ -2478,7 +2473,7 @@
       return Result.TakeString();
     
     // Format a function-like macro with placeholders for the arguments.
-    Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
+    Result.AddChunk(CodeCompletionString::CK_LeftParen);
     MacroInfo::arg_iterator A = MI->arg_begin(), AEnd = MI->arg_end();
     
     // C99 variadic macros add __VA_ARGS__ at the end. Skip it.
@@ -2492,7 +2487,7 @@
     
     for (MacroInfo::arg_iterator A = MI->arg_begin(); A != AEnd; ++A) {
       if (A != MI->arg_begin())
-        Result.AddChunk(Chunk(CodeCompletionString::CK_Comma));
+        Result.AddChunk(CodeCompletionString::CK_Comma);
 
       if (MI->isVariadic() && (A+1) == AEnd) {
         SmallString<32> Arg = (*A)->getName();
@@ -2508,7 +2503,7 @@
       Result.AddPlaceholderChunk(
                           Result.getAllocator().CopyString((*A)->getName()));
     }
-    Result.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+    Result.AddChunk(CodeCompletionString::CK_RightParen);
     return Result.TakeString();
   }
   
@@ -2534,9 +2529,9 @@
     AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, 
                                    Ctx, Policy);
     AddTypedNameChunk(Ctx, Policy, ND, Result);
-    Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
+    Result.AddChunk(CodeCompletionString::CK_LeftParen);
     AddFunctionParameterChunks(Ctx, Policy, Function, Result);
-    Result.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+    Result.AddChunk(CodeCompletionString::CK_RightParen);
     AddFunctionTypeQualsToCompletionString(Result, Function);
     return Result.TakeString();
   }
@@ -2581,16 +2576,16 @@
       // Some of the function template arguments cannot be deduced from a
       // function call, so we introduce an explicit template argument list
       // containing all of the arguments up to the first deducible argument.
-      Result.AddChunk(Chunk(CodeCompletionString::CK_LeftAngle));
+      Result.AddChunk(CodeCompletionString::CK_LeftAngle);
       AddTemplateParameterChunks(Ctx, Policy, FunTmpl, Result, 
                                  LastDeducibleArgument);
-      Result.AddChunk(Chunk(CodeCompletionString::CK_RightAngle));
+      Result.AddChunk(CodeCompletionString::CK_RightAngle);
     }
     
     // Add the function parameters
-    Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
+    Result.AddChunk(CodeCompletionString::CK_LeftParen);
     AddFunctionParameterChunks(Ctx, Policy, Function, Result);
-    Result.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+    Result.AddChunk(CodeCompletionString::CK_RightParen);
     AddFunctionTypeQualsToCompletionString(Result, Function);
     return Result.TakeString();
   }
@@ -2600,9 +2595,9 @@
                                    Ctx, Policy);
     Result.AddTypedTextChunk(
                 Result.getAllocator().CopyString(Template->getNameAsString()));
-    Result.AddChunk(Chunk(CodeCompletionString::CK_LeftAngle));
+    Result.AddChunk(CodeCompletionString::CK_LeftAngle);
     AddTemplateParameterChunks(Ctx, Policy, Template, Result);
-    Result.AddChunk(Chunk(CodeCompletionString::CK_RightAngle));
+    Result.AddChunk(CodeCompletionString::CK_RightAngle);
     return Result.TakeString();
   }
   
@@ -2701,7 +2696,6 @@
                                                           unsigned CurrentArg,
                                                                Sema &S,
                                      CodeCompletionAllocator &Allocator) const {
-  typedef CodeCompletionString::Chunk Chunk;
   PrintingPolicy Policy = getCompletionPrintingPolicy(S);
 
   // FIXME: Set priority, availability appropriately.
@@ -2717,9 +2711,9 @@
     Result.AddTextChunk(GetCompletionTypeString(FT->getResultType(),
                                                 S.Context, Policy, 
                                                 Result.getAllocator()));
-    Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
-    Result.AddChunk(Chunk(CodeCompletionString::CK_CurrentParameter, "..."));
-    Result.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+    Result.AddChunk(CodeCompletionString::CK_LeftParen);
+    Result.AddChunk(CodeCompletionString::CK_CurrentParameter, "...");
+    Result.AddChunk(CodeCompletionString::CK_RightParen);
     return Result.TakeString();
   }
   
@@ -2731,11 +2725,11 @@
          Result.getAllocator().CopyString(
                                   Proto->getResultType().getAsString(Policy)));
   
-  Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
+  Result.AddChunk(CodeCompletionString::CK_LeftParen);
   unsigned NumParams = FDecl? FDecl->getNumParams() : Proto->getNumArgs();
   for (unsigned I = 0; I != NumParams; ++I) {
     if (I)
-      Result.AddChunk(Chunk(CodeCompletionString::CK_Comma));
+      Result.AddChunk(CodeCompletionString::CK_Comma);
     
     std::string ArgString;
     QualType ArgType;
@@ -2750,20 +2744,20 @@
     ArgType.getAsStringInternal(ArgString, Policy);
     
     if (I == CurrentArg)
-      Result.AddChunk(Chunk(CodeCompletionString::CK_CurrentParameter, 
-                             Result.getAllocator().CopyString(ArgString)));
+      Result.AddChunk(CodeCompletionString::CK_CurrentParameter,
+                      Result.getAllocator().CopyString(ArgString));
     else
       Result.AddTextChunk(Result.getAllocator().CopyString(ArgString));
   }
   
   if (Proto && Proto->isVariadic()) {
-    Result.AddChunk(Chunk(CodeCompletionString::CK_Comma));
+    Result.AddChunk(CodeCompletionString::CK_Comma);
     if (CurrentArg < NumParams)
       Result.AddTextChunk("...");
     else
-      Result.AddChunk(Chunk(CodeCompletionString::CK_CurrentParameter, "..."));
+      Result.AddChunk(CodeCompletionString::CK_CurrentParameter, "...");
   }
-  Result.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+  Result.AddChunk(CodeCompletionString::CK_RightParen);
   
   return Result.TakeString();
 }
@@ -4845,16 +4839,15 @@
   //   IBAction)<#selector#>:(id)sender
   if (DS.getObjCDeclQualifier() == 0 && !IsParameter &&
       Context.Idents.get("IBAction").hasMacroDefinition()) {
-    typedef CodeCompletionString::Chunk Chunk;
     CodeCompletionBuilder Builder(Results.getAllocator(), CCP_CodePattern, 
                                   CXAvailability_Available);
     Builder.AddTypedTextChunk("IBAction");
-    Builder.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+    Builder.AddChunk(CodeCompletionString::CK_RightParen);
     Builder.AddPlaceholderChunk("selector");
-    Builder.AddChunk(Chunk(CodeCompletionString::CK_Colon));
-    Builder.AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
+    Builder.AddChunk(CodeCompletionString::CK_Colon);
+    Builder.AddChunk(CodeCompletionString::CK_LeftParen);
     Builder.AddTextChunk("id");
-    Builder.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+    Builder.AddChunk(CodeCompletionString::CK_RightParen);
     Builder.AddTextChunk("sender");
     Results.AddResult(CodeCompletionResult(Builder.TakeString()));
   }