Implement preprocessor code completion where a macro name is expected,

e.g., after #ifdef/#ifndef or #undef, or inside a defined <macroname>
expression in a preprocessor conditional.

llvm-svn: 111954
This commit is contained in:
Douglas Gregor
2010-08-24 20:21:13 +00:00
parent 3aeedd1e5a
commit 127851084d
12 changed files with 107 additions and 8 deletions

View File

@@ -4787,6 +4787,30 @@ void Sema::CodeCompleteInPreprocessorConditionalExclusion(Scope *S) {
CodeCompleteOrdinaryName(S, Action::PCC_RecoveryInFunction);
}
void Sema::CodeCompletePreprocessorMacroName(Scope *S, bool IsDefinition) {
typedef CodeCompleteConsumer::Result Result;
ResultBuilder Results(*this);
if (!IsDefinition && (!CodeCompleter || CodeCompleter->includeMacros())) {
// Add just the names of macros, not their arguments.
Results.EnterNewScope();
for (Preprocessor::macro_iterator M = PP.macro_begin(),
MEnd = PP.macro_end();
M != MEnd; ++M) {
CodeCompletionString *Pattern = new CodeCompletionString;
Pattern->AddTypedTextChunk(M->first->getName());
Results.AddResult(Pattern);
}
Results.ExitScope();
} else if (IsDefinition) {
// FIXME: Can we detect when the user just wrote an include guard above?
}
HandleCodeCompleteResults(this, CodeCompleter,
IsDefinition? CodeCompletionContext::CCC_MacroName
: CodeCompletionContext::CCC_MacroNameUse,
Results.data(), Results.size());
}
void Sema::GatherGlobalCodeCompletions(
llvm::SmallVectorImpl<CodeCompleteConsumer::Result> &Results) {
ResultBuilder Builder(*this);