diff --git a/cpp/ycm/ClangCompleter/ClangCompleter.cpp b/cpp/ycm/ClangCompleter/ClangCompleter.cpp index 7c4a74ab..cac6bc73 100644 --- a/cpp/ycm/ClangCompleter/ClangCompleter.cpp +++ b/cpp/ycm/ClangCompleter/ClangCompleter.cpp @@ -80,10 +80,10 @@ std::vector< Diagnostic > ClangCompleter::UpdateTranslationUnit( ReleaseGil unlock; bool translation_unit_created; shared_ptr< TranslationUnit > unit = translation_unit_store_.GetOrCreate( - filename, - unsaved_files, - flags, - translation_unit_created ); + filename, + unsaved_files, + flags, + translation_unit_created ); if ( !unit ) return std::vector< Diagnostic >(); @@ -93,6 +93,7 @@ std::vector< Diagnostic > ClangCompleter::UpdateTranslationUnit( // parsed in the TU constructor if ( !translation_unit_created ) return unit->Reparse( unsaved_files ); + return unit->LatestDiagnostics(); } @@ -116,7 +117,7 @@ ClangCompleter::CandidatesForLocationInFile( const std::vector< std::string > &flags ) { ReleaseGil unlock; shared_ptr< TranslationUnit > unit = - translation_unit_store_.GetOrCreate( filename, unsaved_files, flags ); + translation_unit_store_.GetOrCreate( filename, unsaved_files, flags ); if ( !unit ) return std::vector< CompletionData >(); @@ -135,7 +136,7 @@ Location ClangCompleter::GetDeclarationLocation( const std::vector< std::string > &flags ) { ReleaseGil unlock; shared_ptr< TranslationUnit > unit = - translation_unit_store_.GetOrCreate( filename, unsaved_files, flags ); + translation_unit_store_.GetOrCreate( filename, unsaved_files, flags ); if ( !unit ) { return Location(); @@ -153,7 +154,7 @@ Location ClangCompleter::GetDefinitionLocation( const std::vector< std::string > &flags ) { ReleaseGil unlock; shared_ptr< TranslationUnit > unit = - translation_unit_store_.GetOrCreate( filename, unsaved_files, flags ); + translation_unit_store_.GetOrCreate( filename, unsaved_files, flags ); if ( !unit ) { return Location(); diff --git a/cpp/ycm/ClangCompleter/TranslationUnit.cpp b/cpp/ycm/ClangCompleter/TranslationUnit.cpp index fd01fcc6..02dad2c0 100644 --- a/cpp/ycm/ClangCompleter/TranslationUnit.cpp +++ b/cpp/ycm/ClangCompleter/TranslationUnit.cpp @@ -57,14 +57,14 @@ TranslationUnit::TranslationUnit( std::vector< CXUnsavedFile > cxunsaved_files = ToCXUnsavedFiles( unsaved_files ); const CXUnsavedFile *unsaved = cxunsaved_files.size() > 0 - ? &cxunsaved_files[ 0 ] : NULL; + ? &cxunsaved_files[ 0 ] : NULL; clang_translation_unit_ = clang_parseTranslationUnit( clang_index, filename.c_str(), &pointer_flags[ 0 ], pointer_flags.size(), - const_cast(unsaved), + const_cast( unsaved ), cxunsaved_files.size(), clang_defaultEditingTranslationUnitOptions() ); @@ -146,7 +146,7 @@ std::vector< CompletionData > TranslationUnit::CandidatesForLocation( std::vector< CXUnsavedFile > cxunsaved_files = ToCXUnsavedFiles( unsaved_files ); const CXUnsavedFile *unsaved = cxunsaved_files.size() > 0 - ? &cxunsaved_files[ 0 ] : NULL; + ? &cxunsaved_files[ 0 ] : NULL; // codeCompleteAt reparses the TU if the underlying source file has changed on // disk since the last time the TU was updated and there are no unsaved files. @@ -163,7 +163,7 @@ std::vector< CompletionData > TranslationUnit::CandidatesForLocation( filename_.c_str(), line, column, - const_cast(unsaved), + const_cast( unsaved ), cxunsaved_files.size(), clang_defaultCodeCompleteOptions() ), clang_disposeCodeCompleteResults ); @@ -242,8 +242,9 @@ void TranslationUnit::Reparse( std::vector< CXUnsavedFile > &unsaved_files, if ( !clang_translation_unit_ ) return; + CXUnsavedFile *unsaved = unsaved_files.size() > 0 - ? &unsaved_files[ 0 ] : NULL; + ? &unsaved_files[ 0 ] : NULL; failure = clang_reparseTranslationUnit( clang_translation_unit_, unsaved_files.size(), diff --git a/cpp/ycm/ClangCompleter/TranslationUnit.h b/cpp/ycm/ClangCompleter/TranslationUnit.h index d1469805..4ba765ad 100644 --- a/cpp/ycm/ClangCompleter/TranslationUnit.h +++ b/cpp/ycm/ClangCompleter/TranslationUnit.h @@ -57,7 +57,7 @@ public: bool IsCurrentlyUpdating() const; std::vector< Diagnostic > Reparse( - const std::vector< UnsavedFile > &unsaved_files ); + const std::vector< UnsavedFile > &unsaved_files ); void ReparseForIndexing( const std::vector< UnsavedFile > &unsaved_files ); diff --git a/cpp/ycm/ClangCompleter/TranslationUnitStore.cpp b/cpp/ycm/ClangCompleter/TranslationUnitStore.cpp index a93d5e7e..ec62a46d 100644 --- a/cpp/ycm/ClangCompleter/TranslationUnitStore.cpp +++ b/cpp/ycm/ClangCompleter/TranslationUnitStore.cpp @@ -79,7 +79,7 @@ shared_ptr< TranslationUnit > TranslationUnitStore::GetOrCreate( // TU object. When we are done creating the TU, we will overwrite this value // with the valid object. filename_to_translation_unit_[ filename ] = - make_shared< TranslationUnit >(); + make_shared< TranslationUnit >(); // We need to store the flags for the sentinel TU so that other threads end // up returning the sentinel TU while the real one is being created. @@ -110,7 +110,7 @@ shared_ptr< TranslationUnit > TranslationUnitStore::GetOrCreate( shared_ptr< TranslationUnit > TranslationUnitStore::Get( - const std::string &filename ) { + const std::string &filename ) { lock_guard< mutex > lock( filename_to_translation_unit_and_flags_mutex_ ); return GetNoLock( filename ); } @@ -131,7 +131,7 @@ void TranslationUnitStore::RemoveAll() { shared_ptr< TranslationUnit > TranslationUnitStore::GetNoLock( - const std::string &filename ) { + const std::string &filename ) { return FindWithDefault( filename_to_translation_unit_, filename, shared_ptr< TranslationUnit >() ); diff --git a/cpp/ycm/ClangCompleter/TranslationUnitStore.h b/cpp/ycm/ClangCompleter/TranslationUnitStore.h index 66156a05..bfae1bac 100644 --- a/cpp/ycm/ClangCompleter/TranslationUnitStore.h +++ b/cpp/ycm/ClangCompleter/TranslationUnitStore.h @@ -67,10 +67,10 @@ private: boost::shared_ptr< TranslationUnit > GetNoLock( const std::string &filename ); - typedef boost::unordered_map< std::string, + typedef boost::unordered_map < std::string, boost::shared_ptr< TranslationUnit > > TranslationUnitForFilename; - typedef boost::unordered_map< std::string, + typedef boost::unordered_map < std::string, std::size_t > FlagsHashForFilename; CXIndex clang_index_; diff --git a/cpp/ycm/IdentifierUtils.cpp b/cpp/ycm/IdentifierUtils.cpp index f55783e1..734ddbcb 100644 --- a/cpp/ycm/IdentifierUtils.cpp +++ b/cpp/ycm/IdentifierUtils.cpp @@ -30,7 +30,7 @@ namespace fs = boost::filesystem; namespace { -const char * const COMMENT_AND_STRING_REGEX = +const char *const COMMENT_AND_STRING_REGEX = "//.*?$" // Anything following '//' "|" "#.*?$" // Anything following '#' @@ -50,12 +50,12 @@ const char * const COMMENT_AND_STRING_REGEX = // 3. the escaped double quote inside the string "(? -{ - bool operator()( const std::string &a, const std::string &b ) const { - return a == b; - } + std::binary_function< std::string, std::string, bool > { + bool operator()( const std::string &a, const std::string &b ) const { + return a == b; + } }; // List of languages Exuberant Ctags supports: @@ -84,51 +83,51 @@ struct StringEqualityComparer : // :e $VIMRUNTIME/filetype.vim // This is a map of const char* and not std::string to prevent issues with // static initialization. -const boost::unordered_map< const char*, - const char*, - boost::hash< std::string >, - StringEqualityComparer > LANG_TO_FILETYPE = - boost::assign::map_list_of - ( "Ant" , "ant" ) - ( "Asm" , "asm" ) - ( "Awk" , "awk" ) - ( "Basic" , "basic" ) - ( "C++" , "cpp" ) - ( "C#" , "cs" ) - ( "C" , "c" ) - ( "COBOL" , "cobol" ) - ( "DosBatch" , "dosbatch" ) - ( "Eiffel" , "eiffel" ) - ( "Erlang" , "erlang" ) - ( "Fortran" , "fortran" ) - ( "HTML" , "html" ) - ( "Java" , "java" ) - ( "JavaScript" , "javascript" ) - ( "Lisp" , "lisp" ) - ( "Lua" , "lua" ) - ( "Make" , "make" ) - ( "MatLab" , "matlab" ) - ( "OCaml" , "ocaml" ) - ( "Pascal" , "pascal" ) - ( "Perl" , "perl" ) - ( "PHP" , "php" ) - ( "Python" , "python" ) - ( "REXX" , "rexx" ) - ( "Ruby" , "ruby" ) - ( "Scheme" , "scheme" ) - ( "Sh" , "sh" ) - ( "SLang" , "slang" ) - ( "SML" , "sml" ) - ( "SQL" , "sql" ) - ( "Tcl" , "tcl" ) - ( "Tex" , "tex" ) - ( "Vera" , "vera" ) - ( "Verilog" , "verilog" ) - ( "VHDL" , "vhdl" ) - ( "Vim" , "vim" ) - ( "YACC" , "yacc" ); +const boost::unordered_map < const char *, + const char *, + boost::hash< std::string >, + StringEqualityComparer > LANG_TO_FILETYPE = + boost::assign::map_list_of + ( "Ant" , "ant" ) + ( "Asm" , "asm" ) + ( "Awk" , "awk" ) + ( "Basic" , "basic" ) + ( "C++" , "cpp" ) + ( "C#" , "cs" ) + ( "C" , "c" ) + ( "COBOL" , "cobol" ) + ( "DosBatch" , "dosbatch" ) + ( "Eiffel" , "eiffel" ) + ( "Erlang" , "erlang" ) + ( "Fortran" , "fortran" ) + ( "HTML" , "html" ) + ( "Java" , "java" ) + ( "JavaScript" , "javascript" ) + ( "Lisp" , "lisp" ) + ( "Lua" , "lua" ) + ( "Make" , "make" ) + ( "MatLab" , "matlab" ) + ( "OCaml" , "ocaml" ) + ( "Pascal" , "pascal" ) + ( "Perl" , "perl" ) + ( "PHP" , "php" ) + ( "Python" , "python" ) + ( "REXX" , "rexx" ) + ( "Ruby" , "ruby" ) + ( "Scheme" , "scheme" ) + ( "Sh" , "sh" ) + ( "SLang" , "slang" ) + ( "SML" , "sml" ) + ( "SQL" , "sql" ) + ( "Tcl" , "tcl" ) + ( "Tex" , "tex" ) + ( "Vera" , "vera" ) + ( "Verilog" , "verilog" ) + ( "VHDL" , "vhdl" ) + ( "Vim" , "vim" ) + ( "YACC" , "yacc" ); -const char * const NOT_FOUND = "YCMFOOBAR_NOT_FOUND"; +const char *const NOT_FOUND = "YCMFOOBAR_NOT_FOUND"; } // unnamed namespace diff --git a/cpp/ycm/PythonSupport.cpp b/cpp/ycm/PythonSupport.cpp index 1b14cd63..abab370f 100644 --- a/cpp/ycm/PythonSupport.cpp +++ b/cpp/ycm/PythonSupport.cpp @@ -40,8 +40,10 @@ namespace { std::string GetUtf8String( const boost::python::object &string_or_unicode ) { extract< std::string > to_string( string_or_unicode ); + if ( to_string.check() ) return to_string(); + return extract< std::string >( str( string_or_unicode ).encode( "utf8" ) ); } @@ -95,7 +97,7 @@ boost::python::list FilterAndSortCandidates( continue; Result result = candidate->QueryMatchResult( query, - query_has_uppercase_letters ); + query_has_uppercase_letters ); if ( result.IsSubsequence() ) { ResultAnd< int > object_and_result( i, result ); diff --git a/cpp/ycm/tests/main.cpp b/cpp/ycm/tests/main.cpp index 62c5198c..c9a3700b 100644 --- a/cpp/ycm/tests/main.cpp +++ b/cpp/ycm/tests/main.cpp @@ -7,7 +7,7 @@ int main( int argc, char **argv ) { // Necessary because of usage of the ReleaseGil class PyEval_InitThreads(); - testing::InitGoogleMock(&argc, argv); + testing::InitGoogleMock( &argc, argv ); return RUN_ALL_TESTS(); }