ClanUtils functions are now all in one place
Also, internal ClanUtils functions are now in an unnamed namespace
This commit is contained in:
parent
b48111bb2f
commit
ae57c9c39b
@ -29,35 +29,49 @@ using boost::unordered_map;
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
|
||||
std::vector< CXUnsavedFile > ToCXUnsavedFiles(
|
||||
const std::vector< UnsavedFile > &unsaved_files )
|
||||
std::string CXStringToString( CXString text )
|
||||
{
|
||||
std::vector< CXUnsavedFile > clang_unsaved_files( unsaved_files.size() );
|
||||
for ( uint i = 0; i < unsaved_files.size(); ++i )
|
||||
{
|
||||
X_VERIFY( unsaved_files[ i ].filename_ );
|
||||
X_VERIFY( unsaved_files[ i ].contents_ );
|
||||
X_VERIFY( unsaved_files[ i ].length_ );
|
||||
clang_unsaved_files[ i ].Filename = unsaved_files[ i ].filename_;
|
||||
clang_unsaved_files[ i ].Contents = unsaved_files[ i ].contents_;
|
||||
clang_unsaved_files[ i ].Length = unsaved_files[ i ].length_;
|
||||
std::string final_string;
|
||||
if ( !text.data )
|
||||
return final_string;
|
||||
|
||||
final_string = std::string( clang_getCString( text ) );
|
||||
clang_disposeString( text );
|
||||
return final_string;
|
||||
}
|
||||
|
||||
return clang_unsaved_files;
|
||||
}
|
||||
|
||||
|
||||
// Returns true when the provided completion string is available to the user;
|
||||
// unavailable completion strings refer to entities that are private/protected,
|
||||
// deprecated etc.
|
||||
bool CompletionStringAvailable( CXCompletionString completion_string )
|
||||
namespace
|
||||
{
|
||||
if ( !completion_string )
|
||||
return false;
|
||||
return clang_getCompletionAvailability( completion_string ) ==
|
||||
CXAvailability_Available;
|
||||
|
||||
// NOTE: The passed in pointer should never be NULL!
|
||||
std::string FullDiagnosticText( CXDiagnostic cxdiagnostic )
|
||||
{
|
||||
std::string full_text = CXStringToString( clang_formatDiagnostic(
|
||||
cxdiagnostic,
|
||||
clang_defaultDiagnosticDisplayOptions() ) );
|
||||
|
||||
// Note: clang docs say that a CXDiagnosticSet retrieved with
|
||||
// clang_getChildDiagnostics do NOT need to be released with
|
||||
// clang_diposeDiagnosticSet
|
||||
CXDiagnosticSet diag_set = clang_getChildDiagnostics( cxdiagnostic );
|
||||
if ( !diag_set )
|
||||
return full_text;
|
||||
|
||||
uint num_child_diagnostics = clang_getNumDiagnosticsInSet( diag_set );
|
||||
if ( !num_child_diagnostics )
|
||||
return full_text;
|
||||
|
||||
for ( uint i = 0; i < num_child_diagnostics; ++i )
|
||||
{
|
||||
CXDiagnostic diagnostic = clang_getDiagnosticInSet( diag_set, i );
|
||||
if ( !diagnostic )
|
||||
continue;
|
||||
|
||||
full_text.append( FullDiagnosticText( diagnostic ) );
|
||||
}
|
||||
|
||||
return full_text;
|
||||
}
|
||||
|
||||
|
||||
char DiagnosticSeverityToType( CXDiagnosticSeverity severity )
|
||||
@ -81,6 +95,38 @@ char DiagnosticSeverityToType( CXDiagnosticSeverity severity )
|
||||
}
|
||||
|
||||
|
||||
// Returns true when the provided completion string is available to the user;
|
||||
// unavailable completion strings refer to entities that are private/protected,
|
||||
// deprecated etc.
|
||||
bool CompletionStringAvailable( CXCompletionString completion_string )
|
||||
{
|
||||
if ( !completion_string )
|
||||
return false;
|
||||
return clang_getCompletionAvailability( completion_string ) ==
|
||||
CXAvailability_Available;
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
|
||||
std::vector< CXUnsavedFile > ToCXUnsavedFiles(
|
||||
const std::vector< UnsavedFile > &unsaved_files )
|
||||
{
|
||||
std::vector< CXUnsavedFile > clang_unsaved_files( unsaved_files.size() );
|
||||
for ( uint i = 0; i < unsaved_files.size(); ++i )
|
||||
{
|
||||
X_VERIFY( unsaved_files[ i ].filename_ );
|
||||
X_VERIFY( unsaved_files[ i ].contents_ );
|
||||
X_VERIFY( unsaved_files[ i ].length_ );
|
||||
clang_unsaved_files[ i ].Filename = unsaved_files[ i ].filename_;
|
||||
clang_unsaved_files[ i ].Contents = unsaved_files[ i ].contents_;
|
||||
clang_unsaved_files[ i ].Length = unsaved_files[ i ].length_;
|
||||
}
|
||||
|
||||
return clang_unsaved_files;
|
||||
}
|
||||
|
||||
|
||||
std::vector< CompletionData > ToCompletionDataVector(
|
||||
CXCodeCompleteResults *results )
|
||||
{
|
||||
@ -125,38 +171,6 @@ std::vector< CompletionData > ToCompletionDataVector(
|
||||
}
|
||||
|
||||
|
||||
// NOTE: The passed in pointer should never be NULL!
|
||||
// TODO: move all functions that are not external into an unnamed namespace
|
||||
std::string FullDiagnosticText( CXDiagnostic cxdiagnostic )
|
||||
{
|
||||
std::string full_text = CXStringToString( clang_formatDiagnostic(
|
||||
cxdiagnostic,
|
||||
clang_defaultDiagnosticDisplayOptions() ) );
|
||||
|
||||
// Note: clang docs say that a CXDiagnosticSet retrieved with
|
||||
// clang_getChildDiagnostics do NOT need to be released with
|
||||
// clang_diposeDiagnosticSet
|
||||
CXDiagnosticSet diag_set = clang_getChildDiagnostics( cxdiagnostic );
|
||||
if ( !diag_set )
|
||||
return full_text;
|
||||
|
||||
uint num_child_diagnostics = clang_getNumDiagnosticsInSet( diag_set );
|
||||
if ( !num_child_diagnostics )
|
||||
return full_text;
|
||||
|
||||
for ( uint i = 0; i < num_child_diagnostics; ++i )
|
||||
{
|
||||
CXDiagnostic diagnostic = clang_getDiagnosticInSet( diag_set, i );
|
||||
if ( !diagnostic )
|
||||
continue;
|
||||
|
||||
full_text.append( FullDiagnosticText( diagnostic ) );
|
||||
}
|
||||
|
||||
return full_text;
|
||||
}
|
||||
|
||||
|
||||
Diagnostic CXDiagnosticToDiagnostic( CXDiagnostic cxdiagnostic )
|
||||
{
|
||||
Diagnostic diagnostic;
|
||||
|
@ -28,6 +28,8 @@
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
|
||||
std::string CXStringToString( CXString text );
|
||||
|
||||
std::vector< CompletionData > ToCompletionDataVector(
|
||||
CXCodeCompleteResults *results );
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
// along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "CompletionData.h"
|
||||
#include "ClangUtils.h"
|
||||
|
||||
#include <boost/algorithm/string/erase.hpp>
|
||||
#include <boost/move/move.hpp>
|
||||
@ -145,18 +146,6 @@ std::string RemoveTwoConsecutiveUnderscores( std::string text )
|
||||
namespace YouCompleteMe
|
||||
{
|
||||
|
||||
std::string CXStringToString( CXString text )
|
||||
{
|
||||
std::string final_string;
|
||||
if ( !text.data )
|
||||
return final_string;
|
||||
|
||||
final_string = std::string( clang_getCString( text ) );
|
||||
clang_disposeString( text );
|
||||
return final_string;
|
||||
}
|
||||
|
||||
|
||||
CompletionData::CompletionData( const CXCompletionResult &completion_result )
|
||||
{
|
||||
CXCompletionString completion_string = completion_result.CompletionString;
|
||||
|
Loading…
Reference in New Issue
Block a user