2016-07-07 11:47:58 +03:00
//--------------------------------------------------------------------*- 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"
2016-07-07 11:47:58 +03:00
# 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
2016-07-07 11:47:58 +03:00
= 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-07 11:47:58 +03:00
2016-07-14 19:06:47 +03:00
case CodeCompletionResult : : RK_Keyword :
m_Completions . push_back ( Results [ I ] . Keyword ) ;
break ;
2016-07-07 11:47:58 +03:00
2016-07-14 19:06:47 +03:00
case CodeCompletionResult : : RK_Macro :
if ( CodeCompletionString * CCS
2016-07-07 11:47:58 +03:00
= 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-07 11:47:58 +03:00
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 : {
2024-02-02 13:11:47 +03:00
return ! (
Result . Declaration - > getIdentifier ( ) & &
Result . Declaration - > getIdentifier ( ) - > getName ( ) . starts_with ( Filter ) ) ;
2016-07-14 19:06:47 +03:00
}
case CodeCompletionResult : : RK_Keyword : {
2024-02-02 13:11:47 +03:00
return ! ( ( StringRef ( Result . Keyword ) ) . starts_with ( Filter ) ) ;
2016-07-14 19:06:47 +03:00
}
case CodeCompletionResult : : RK_Macro : {
2024-02-02 13:11:47 +03:00
return ! ( Result . Macro - > getName ( ) . starts_with ( Filter ) ) ;
2016-07-14 19:06:47 +03:00
}
case CodeCompletionResult : : RK_Pattern : {
2024-02-02 13:11:47 +03:00
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-07-07 11:47:58 +03:00
}
2016-06-28 20:10:37 +03:00
}
}