From dbb71db4cc79d6b74c0683ffec5f3a847179603c Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 23 Aug 2010 23:51:41 +0000 Subject: When calling a function or messaging a method marked "sentinel", add the ", nil", ", NULL", or ", (void*)0" to the end of the code completion, since it always has to be there anyway. llvm-svn: 111867 --- clang/lib/Sema/SemaCodeComplete.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'clang/lib/Sema/SemaCodeComplete.cpp') diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index d886e64bb53..aec55682180 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -1666,6 +1666,20 @@ static void AddResultTypeChunk(ASTContext &Context, Result->AddResultTypeChunk(TypeStr); } +static void MaybeAddSentinel(ASTContext &Context, NamedDecl *FunctionOrMethod, + CodeCompletionString *Result) { + if (SentinelAttr *Sentinel = FunctionOrMethod->getAttr()) + if (Sentinel->getSentinel() == 0) { + if (Context.getLangOptions().ObjC1 && + Context.Idents.get("nil").hasMacroDefinition()) + Result->AddTextChunk(", nil"); + else if (Context.Idents.get("NULL").hasMacroDefinition()) + Result->AddTextChunk(", NULL"); + else + Result->AddTextChunk(", (void*)0"); + } +} + /// \brief Add function parameter chunks to the given code completion string. static void AddFunctionParameterChunks(ASTContext &Context, FunctionDecl *Function, @@ -1702,8 +1716,11 @@ static void AddFunctionParameterChunks(ASTContext &Context, if (const FunctionProtoType *Proto = Function->getType()->getAs()) - if (Proto->isVariadic()) + if (Proto->isVariadic()) { CCStr->AddPlaceholderChunk(", ..."); + + MaybeAddSentinel(Context, Function, CCStr); + } } /// \brief Add template parameter chunks to the given code completion string. @@ -2020,6 +2037,8 @@ CodeCompleteConsumer::Result::CreateCodeCompletionString(Sema &S, Result->AddInformativeChunk(", ..."); else Result->AddPlaceholderChunk(", ..."); + + MaybeAddSentinel(S.Context, Method, Result); } return Result; -- cgit v1.2.3