String^ CompileCommandArgumentCollection::default::get(int index) { // Check for a cached instance of the argument string first, this will also // verify that index is within bounds and throw appropriately String^ cached = m_cache[index]; if(!Object::ReferenceEquals(cached, nullptr)) return cached; // Create and cache a new argument string instance for this index and return it m_cache[index] = StringUtil::ToString(clang_CompileCommand_getArg(CompileCommandHandle::Reference(m_handle), index)); return m_cache[index]; }
CompilationInfoForFile CompilationDatabase::GetCompilationInfoForFile( const std::string &path_to_file ) { ReleaseGil unlock; CompilationInfoForFile info; if ( !is_loaded_ ) return info; lock_guard< mutex > lock( compilation_database_mutex_ ); CompileCommandsWrap commands( clang_CompilationDatabase_getCompileCommands( compilation_database_, path_to_file.c_str() ), clang_CompileCommands_dispose ); uint num_commands = clang_CompileCommands_getSize( commands.get() ); if ( num_commands < 1 ) { return info; } // We always pick the first command offered CXCompileCommand command = clang_CompileCommands_getCommand( commands.get(), 0 ); info.compiler_working_dir_ = CXStringToString( clang_CompileCommand_getDirectory( command ) ); uint num_flags = clang_CompileCommand_getNumArgs( command ); info.compiler_flags_.reserve( num_flags ); for ( uint i = 0; i < num_flags; ++i ) { info.compiler_flags_.push_back( CXStringToString( clang_CompileCommand_getArg( command, i ) ) ); } return info; }
void Irony::getCompileOptions(const std::string &buildDir, const std::string &file) const { #if !(HAS_COMPILATION_DATABASE) (void)buildDir; (void)file; std::cout << "nil\n"; return; #else CXCompilationDatabase_Error error; CXCompilationDatabase db = clang_CompilationDatabase_fromDirectory(buildDir.c_str(), &error); switch (error) { case CXCompilationDatabase_CanNotLoadDatabase: std::clog << "I: could not load compilation database in '" << buildDir << "'\n"; std::cout << "nil\n"; return; case CXCompilationDatabase_NoError: break; } CXCompileCommands compileCommands = clang_CompilationDatabase_getCompileCommands(db, file.c_str()); std::cout << "(\n"; for (unsigned i = 0, numCompileCommands = clang_CompileCommands_getSize(compileCommands); i < numCompileCommands; ++i) { CXCompileCommand compileCommand = clang_CompileCommands_getCommand(compileCommands, i); std::cout << "(" << "("; for (unsigned j = 0, numArgs = clang_CompileCommand_getNumArgs(compileCommand); j < numArgs; ++j) { CXString arg = clang_CompileCommand_getArg(compileCommand, j); std::cout << support::quoted(clang_getCString(arg)) << " "; clang_disposeString(arg); } std::cout << ")" << " . "; CXString directory = clang_CompileCommand_getDirectory(compileCommand); std::cout << support::quoted(clang_getCString(directory)); clang_disposeString(directory); std::cout << ")\n"; } std::cout << ")\n"; clang_CompileCommands_dispose(compileCommands); clang_CompilationDatabase_dispose(db); #endif }
std::string compilation_db::command::operator[](unsigned idx) const { return string(clang_CompileCommand_getArg(cmd, idx)).str(); }
JNIEXPORT void JNICALL JavaCritical_org_lwjgl_llvm_ClangCompilationDatabase_nclang_1CompileCommand_1getArg(jlong commandAddress, jint I, jlong __functionAddress, jlong __result) { clang_CompileCommand_getArgPROC clang_CompileCommand_getArg = (clang_CompileCommand_getArgPROC)(intptr_t)__functionAddress; intptr_t command = (intptr_t)commandAddress; *((CXString*)(intptr_t)__result) = clang_CompileCommand_getArg(command, I); }