cling/lib/Interpreter/ClingCodeCompleteConsumer.cpp

82 lines
3.3 KiB
C++
Raw Normal View History

//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// author: Bianca-Cristina Cristescu <bianca-cristina.cristescu@cern.ch>
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------
2016-06-28 20:10:37 +03:00
#include "cling/Interpreter/ClingCodeCompleteConsumer.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/Sema.h"
2016-06-28 20:10:37 +03:00
2016-07-14 19:06:47 +03:00
namespace cling {
void ClingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
CodeCompletionContext Context,
CodeCompletionResult *Results,
unsigned NumResults) {
std::stable_sort(Results, Results + NumResults);
2016-06-28 20:10:37 +03:00
2016-07-14 19:06:47 +03:00
StringRef Filter = SemaRef.getPreprocessor().getCodeCompletionFilter();
for (unsigned I = 0; I != NumResults; ++I) {
if (!Filter.empty() && isResultFilteredOut(Filter, Results[I]))
continue;
switch (Results[I].Kind) {
case CodeCompletionResult::RK_Declaration:
if (CodeCompletionString *CCS
= Results[I].CreateCodeCompletionString(SemaRef, Context,
getAllocator(),
m_CCTUInfo,
includeBriefComments())) {
2016-07-14 19:06:47 +03:00
m_Completions.push_back(CCS->getAsString());
}
break;
2016-07-14 19:06:47 +03:00
case CodeCompletionResult::RK_Keyword:
m_Completions.push_back(Results[I].Keyword);
break;
2016-07-14 19:06:47 +03:00
case CodeCompletionResult::RK_Macro:
if (CodeCompletionString *CCS
= Results[I].CreateCodeCompletionString(SemaRef, Context,
getAllocator(),
m_CCTUInfo,
includeBriefComments())) {
2016-07-14 19:06:47 +03:00
m_Completions.push_back(CCS->getAsString());
}
break;
2016-07-14 19:06:47 +03:00
case CodeCompletionResult::RK_Pattern:
m_Completions.push_back(Results[I].Pattern->getAsString());
break;
}
2016-06-28 20:10:37 +03:00
}
}
2016-07-14 19:06:47 +03:00
bool ClingCodeCompleteConsumer::isResultFilteredOut(StringRef Filter,
CodeCompletionResult Result) {
switch (Result.Kind) {
case CodeCompletionResult::RK_Declaration: {
return !(
Result.Declaration->getIdentifier() &&
Result.Declaration->getIdentifier()->getName().starts_with(Filter));
2016-07-14 19:06:47 +03:00
}
case CodeCompletionResult::RK_Keyword: {
return !((StringRef(Result.Keyword)).starts_with(Filter));
2016-07-14 19:06:47 +03:00
}
case CodeCompletionResult::RK_Macro: {
return !(Result.Macro->getName().starts_with(Filter));
2016-07-14 19:06:47 +03:00
}
case CodeCompletionResult::RK_Pattern: {
return !(
StringRef((Result.Pattern->getAsString())).starts_with(Filter));
2016-07-14 19:06:47 +03:00
}
default: llvm_unreachable("Unknown code completion result Kind.");
}
2016-06-28 20:10:37 +03:00
}
}