// Argument taken as non-const ref because we need to be able to pass a // non-const pointer to clang. This function (and clang too) will not modify the // param though. void TranslationUnit::Reparse( std::vector< CXUnsavedFile > &unsaved_files, size_t parse_options ) { CXErrorCode failure; { unique_lock< mutex > lock( clang_access_mutex_ ); if ( !clang_translation_unit_ ) { return; } CXUnsavedFile *unsaved = unsaved_files.empty() ? nullptr : &unsaved_files[ 0 ]; // This function should technically return a CXErrorCode enum but return an // int instead. failure = static_cast< CXErrorCode >( clang_reparseTranslationUnit( clang_translation_unit_, unsaved_files.size(), unsaved, parse_options ) ); } if ( failure != CXError_Success ) { Destroy(); throw ClangParseError( failure ); } UpdateLatestDiagnostics(); }
TranslationUnit::TranslationUnit( const std::string &filename, const std::vector< UnsavedFile > &unsaved_files, const std::vector< std::string > &flags, CXIndex clang_index ) : clang_translation_unit_( nullptr ) { std::vector< const char * > pointer_flags; pointer_flags.reserve( flags.size() ); for ( const std::string & flag : flags ) { pointer_flags.push_back( flag.c_str() ); } EnsureCompilerNamePresent( pointer_flags ); std::vector< CXUnsavedFile > cxunsaved_files = ToCXUnsavedFiles( unsaved_files ); const CXUnsavedFile *unsaved = cxunsaved_files.empty() ? nullptr : &cxunsaved_files[ 0 ]; // Actually parse the translation unit. CXErrorCode failure = clang_parseTranslationUnit2FullArgv( clang_index, filename.c_str(), &pointer_flags[ 0 ], pointer_flags.size(), const_cast<CXUnsavedFile *>( unsaved ), cxunsaved_files.size(), EditingOptions(), &clang_translation_unit_ ); if ( failure != CXError_Success ) { throw ClangParseError( failure ); } }
// Argument taken as non-const ref because we need to be able to pass a // non-const pointer to clang. This function (and clang too) will not modify the // param though. void TranslationUnit::Reparse( std::vector< CXUnsavedFile > &unsaved_files, size_t parse_options ) { int failure = 0; { unique_lock< mutex > lock( clang_access_mutex_ ); if ( !clang_translation_unit_ ) return; CXUnsavedFile *unsaved = unsaved_files.size() > 0 ? &unsaved_files[ 0 ] : NULL; failure = clang_reparseTranslationUnit( clang_translation_unit_, unsaved_files.size(), unsaved, parse_options ); } if ( failure ) { Destroy(); throw( ClangParseError() ); } UpdateLatestDiagnostics(); }