[cfe-commits] r137973 - in /cfe/trunk: include/clang/Lex/CodeCompletionHandler.h lib/Lex/PPMacroExpansion.cpp lib/Sema/SemaCodeComplete.cpp test/Index/complete-macro-args.c
Douglas Gregor
dgregor at apple.com
Thu Aug 18 13:06:50 PDT 2011
On Aug 18, 2011, at 3:41 PM, Argyrios Kyrtzidis wrote:
> Author: akirtzidis
> Date: Thu Aug 18 14:41:28 2011
> New Revision: 137973
>
> URL: http://llvm.org/viewvc/llvm-project?rev=137973&view=rev
> Log:
> [libclang] Support code-completion inside macro arguments.
Awesome!
-Doug
> Added:
> cfe/trunk/test/Index/complete-macro-args.c
> Modified:
> cfe/trunk/include/clang/Lex/CodeCompletionHandler.h
> cfe/trunk/lib/Lex/PPMacroExpansion.cpp
> cfe/trunk/lib/Sema/SemaCodeComplete.cpp
>
> Modified: cfe/trunk/include/clang/Lex/CodeCompletionHandler.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/CodeCompletionHandler.h?rev=137973&r1=137972&r2=137973&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Lex/CodeCompletionHandler.h (original)
> +++ cfe/trunk/include/clang/Lex/CodeCompletionHandler.h Thu Aug 18 14:41:28 2011
> @@ -52,6 +52,10 @@
>
> /// \brief Callback invoked when performing code completion inside a
> /// function-like macro argument.
> + ///
> + /// There will be another callback invocation after the macro arguments are
> + /// parsed, so this callback should generally be used to note that the next
> + /// callback is invoked inside a macro argument.
> virtual void CodeCompleteMacroArgument(IdentifierInfo *Macro,
> MacroInfo *MacroInfo,
> unsigned ArgumentIndex) { }
>
> Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=137973&r1=137972&r2=137973&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
> +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Thu Aug 18 14:41:28 2011
> @@ -358,7 +358,23 @@
> if (CodeComplete)
> CodeComplete->CodeCompleteMacroArgument(MacroName.getIdentifierInfo(),
> MI, NumActuals);
> - LexUnexpandedToken(Tok);
> +
> + // Add the code-completion token and finish the lexing normally so that
> + // normal code-completion occurs again with the expanded tokens.
> + ArgTokens.push_back(Tok);
> + // Add a marker EOF token to the end of the token list.
> + Token EOFTok;
> + EOFTok.startToken();
> + EOFTok.setKind(tok::eof);
> + EOFTok.setLocation(Tok.getLocation());
> + EOFTok.setLength(0);
> + ArgTokens.push_back(EOFTok);
> + ++NumActuals;
> + // "Fill out" the other arguments.
> + for (; NumActuals < MI->getNumArgs(); ++NumActuals)
> + ArgTokens.push_back(EOFTok);
> + return MacroArgs::create(MI, ArgTokens.data(), ArgTokens.size(),
> + /*isVarargsElided=*/false, *this);
> }
>
> if (Tok.is(tok::eof) || Tok.is(tok::eod)) { // "#if f(<eof>" & "#if f(\n"
>
> Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=137973&r1=137972&r2=137973&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Aug 18 14:41:28 2011
> @@ -6857,9 +6857,8 @@
> // FIXME: In the future, we could provide "overload" results, much like we
> // do for function calls.
>
> - CodeCompleteOrdinaryName(S,
> - S->getFnParent()? Sema::PCC_RecoveryInFunction
> - : Sema::PCC_Namespace);
> + // Now just ignore this. There will be another code-completion callback
> + // for the expanded tokens.
> }
>
> void Sema::CodeCompleteNaturalLanguage() {
>
> Added: cfe/trunk/test/Index/complete-macro-args.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-macro-args.c?rev=137973&view=auto
> ==============================================================================
> --- cfe/trunk/test/Index/complete-macro-args.c (added)
> +++ cfe/trunk/test/Index/complete-macro-args.c Thu Aug 18 14:41:28 2011
> @@ -0,0 +1,22 @@
> +struct Point {
> + float x;
> + float y;
> + float z;
> +};
> +
> +#define MACRO2(x) x
> +#define MACRO(x) MACRO2(x)
> +
> +void test(struct Point *p) {
> + p->x;
> + MACRO(p->x);
> +}
> +
> +// RUN: c-index-test -code-completion-at=%s:11:12 %s | FileCheck %s
> +// RUN: c-index-test -code-completion-at=%s:12:12 %s | FileCheck %s
> +// CHECK: FieldDecl:{ResultType float}{TypedText x} (35)
> +// CHECK-NEXT: FieldDecl:{ResultType float}{TypedText y} (35)
> +// CHECK-NEXT: FieldDecl:{ResultType float}{TypedText z} (35)
> +// CHECK-NEXT: Completion contexts:
> +// CHECK-NEXT: Arrow member access
> +// CHECK-NEXT: Container Kind: StructDecl
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list