[cfe-commits] r136563 - in /cfe/trunk: lib/Sema/SemaCodeComplete.cpp test/Index/complete-macros.c
Douglas Gregor
dgregor at apple.com
Sat Jul 30 01:17:44 PDT 2011
Author: dgregor
Date: Sat Jul 30 03:17:44 2011
New Revision: 136563
URL: http://llvm.org/viewvc/llvm-project?rev=136563&view=rev
Log:
When producing code completion results for variadic macros, fold the
variadic bit (", ..." or ", args...") into the prior placeholder, like
we do with functions and methods. Fixes <rdar://problem/9740808>.
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/Index/complete-macros.c
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=136563&r1=136562&r2=136563&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Sat Jul 30 03:17:44 2011
@@ -2368,19 +2368,24 @@
// Format a function-like macro with placeholders for the arguments.
Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
- for (MacroInfo::arg_iterator A = MI->arg_begin(), AEnd = MI->arg_end();
- A != AEnd; ++A) {
+ bool CombineVariadicArgument = false;
+ MacroInfo::arg_iterator A = MI->arg_begin(), AEnd = MI->arg_end();
+ if (MI->isVariadic() && AEnd - A > 1) {
+ AEnd -= 2;
+ CombineVariadicArgument = true;
+ }
+ for (MacroInfo::arg_iterator A = MI->arg_begin(); A != AEnd; ++A) {
if (A != MI->arg_begin())
Result.AddChunk(Chunk(CodeCompletionString::CK_Comma));
- if (!MI->isVariadic() || A != AEnd - 1) {
+ if (!MI->isVariadic() || A + 1 != AEnd) {
// Non-variadic argument.
Result.AddPlaceholderChunk(
Result.getAllocator().CopyString((*A)->getName()));
continue;
}
- // Variadic argument; cope with the different between GNU and C99
+ // Variadic argument; cope with the difference between GNU and C99
// variadic macros, providing a single placeholder for the rest of the
// arguments.
if ((*A)->isStr("__VA_ARGS__"))
@@ -2391,6 +2396,18 @@
Result.AddPlaceholderChunk(Result.getAllocator().CopyString(Arg));
}
}
+
+ if (CombineVariadicArgument) {
+ // Handle the next-to-last argument, combining it with the variadic
+ // argument.
+ std::string LastArg = (*A)->getName();
+ ++A;
+ if ((*A)->isStr("__VA_ARGS__"))
+ LastArg += ", ...";
+ else
+ LastArg += ", " + (*A)->getName().str() + "...";
+ Result.AddPlaceholderChunk(Result.getAllocator().CopyString(LastArg));
+ }
Result.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
return Result.TakeString();
}
Modified: cfe/trunk/test/Index/complete-macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-macros.c?rev=136563&r1=136562&r2=136563&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-macros.c (original)
+++ cfe/trunk/test/Index/complete-macros.c Sat Jul 30 03:17:44 2011
@@ -15,6 +15,15 @@
g(nil);
}
+#define variadic1(...)
+#define variadic2(args...)
+#define variadic3(args, ...)
+#define variadic4(first, second, args, ...)
+
+void test_variadic() {
+
+}
+
// RUN: c-index-test -code-completion-at=%s:7:1 %s | FileCheck -check-prefix=CHECK-CC1 %s
// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:7:1 %s | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: macro definition:{TypedText FOO}{LeftParen (}{Placeholder Arg1}{Comma , }{Placeholder Arg2}{RightParen )}
@@ -25,3 +34,8 @@
// RUN: c-index-test -code-completion-at=%s:15:5 %s | FileCheck -check-prefix=CHECK-CC3 %s
// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:15:5 %s | FileCheck -check-prefix=CHECK-CC3 %s
// CHECK-CC3: macro definition:{TypedText nil} (65)
+// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:24:2 %s | FileCheck -check-prefix=CHECK-VARIADIC %s
+// CHECK-VARIADIC: macro definition:{TypedText variadic1}{LeftParen (}{Placeholder ...}{RightParen )} (70)
+// CHECK-VARIADIC: macro definition:{TypedText variadic2}{LeftParen (}{Placeholder args...}{RightParen )} (70)
+// CHECK-VARIADIC: macro definition:{TypedText variadic3}{LeftParen (}{Placeholder args, ...}{RightParen )} (70)
+// CHECK-VARIADIC: macro definition:{TypedText variadic4}{LeftParen (}{Placeholder first}{Comma , }{Placeholder second...}{Placeholder first, second...}{RightParen )} (70)
More information about the cfe-commits
mailing list