From ec00a268552c93b79c5049111b674e2aa184bf5d Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 24 Aug 2010 22:20:20 +0000 Subject: Implement code completion for preprocessor expressions and in macro arguments. llvm-svn: 111976 --- clang/lib/Sema/SemaCodeComplete.cpp | 43 +++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'clang/lib/Sema/SemaCodeComplete.cpp') diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 06e65784e85d..e25a47c2a553 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -4608,7 +4608,7 @@ void Sema::CodeCompleteObjCMethodDeclSelector(Scope *S, Results.data(),Results.size()); } -void Sema::CodeCompletePreprocessorDirective(Scope *S, bool InConditional) { +void Sema::CodeCompletePreprocessorDirective(bool InConditional) { ResultBuilder Results(*this); Results.EnterNewScope(); @@ -4785,11 +4785,12 @@ void Sema::CodeCompletePreprocessorDirective(Scope *S, bool InConditional) { } void Sema::CodeCompleteInPreprocessorConditionalExclusion(Scope *S) { - CodeCompleteOrdinaryName(S, Action::PCC_RecoveryInFunction); + CodeCompleteOrdinaryName(S, + S->getFnParent()? Action::PCC_RecoveryInFunction + : Action::PCC_Namespace); } -void Sema::CodeCompletePreprocessorMacroName(Scope *S, bool IsDefinition) { - typedef CodeCompleteConsumer::Result Result; +void Sema::CodeCompletePreprocessorMacroName(bool IsDefinition) { ResultBuilder Results(*this); if (!IsDefinition && (!CodeCompleter || CodeCompleter->includeMacros())) { // Add just the names of macros, not their arguments. @@ -4812,6 +4813,40 @@ void Sema::CodeCompletePreprocessorMacroName(Scope *S, bool IsDefinition) { Results.data(), Results.size()); } +void Sema::CodeCompletePreprocessorExpression() { + ResultBuilder Results(*this); + + if (!CodeCompleter || CodeCompleter->includeMacros()) + AddMacroResults(PP, Results); + + // defined () + Results.EnterNewScope(); + CodeCompletionString *Pattern = new CodeCompletionString; + Pattern->AddTypedTextChunk("defined"); + Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace); + Pattern->AddChunk(CodeCompletionString::CK_LeftParen); + Pattern->AddPlaceholderChunk("macro"); + Pattern->AddChunk(CodeCompletionString::CK_RightParen); + Results.AddResult(Pattern); + Results.ExitScope(); + + HandleCodeCompleteResults(this, CodeCompleter, + CodeCompletionContext::CCC_PreprocessorExpression, + Results.data(), Results.size()); +} + +void Sema::CodeCompletePreprocessorMacroArgument(Scope *S, + IdentifierInfo *Macro, + MacroInfo *MacroInfo, + unsigned Argument) { + // FIXME: In the future, we could provide "overload" results, much like we + // do for function calls. + + CodeCompleteOrdinaryName(S, + S->getFnParent()? Action::PCC_RecoveryInFunction + : Action::PCC_Namespace); +} + void Sema::GatherGlobalCodeCompletions( llvm::SmallVectorImpl &Results) { ResultBuilder Builder(*this); -- cgit v1.2.3