bool Cursor::isNull() const { if (! pCursor_) return true; else return (clang().equalCursors(cursor(), clang().getNullCursor())); }
boost::shared_ptr<CodeCompleteResults> TranslationUnit::codeCompleteAt( const std::string& filename, unsigned line, unsigned column) const { CXCodeCompleteResults* pResults = clang().codeCompleteAt( tu_, filename.c_str(), line, column, pUnsavedFiles_->unsavedFilesArray(), pUnsavedFiles_->numUnsavedFiles(), clang().defaultCodeCompleteOptions()); if (pResults != nullptr) { clang().sortCodeCompletionResults(pResults->Results, pResults->NumResults); return boost::shared_ptr<CodeCompleteResults>( new CodeCompleteResults(pResults)); } else { return boost::shared_ptr<CodeCompleteResults>(new CodeCompleteResults()); } }
void TranslationUnit::printResourceUsage(std::ostream& ostr, bool detailed) const { CXTUResourceUsage usage = clang().getCXTUResourceUsage(tu_); unsigned long totalBytes = 0; for (unsigned i = 0; i < usage.numEntries; i++) { CXTUResourceUsageEntry entry = usage.entries[i]; if (detailed) { ostr << clang().getTUResourceUsageName(entry.kind) << ": " << formatBytes(entry.amount) << std::endl; } if (entry.kind >= CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN && entry.kind <= CXTUResourceUsage_MEMORY_IN_BYTES_END) { totalBytes += entry.amount; } } ostr << "TOTAL MEMORY: " << formatBytes(totalBytes) << " (" << FilePath(getSpelling()).filename() << ")" << std::endl; clang().disposeCXTUResourceUsage(usage); }
void SourceLocation::getExpansionLocation(std::string* pFile, unsigned* pLine, unsigned* pColumn, unsigned* pOffset) const { CXFile file; clang().getExpansionLocation(location_, &file, pLine, pColumn, pOffset); CXString filename = clang().getFileName(file); *pFile = toStdString(filename); }
// note that this function disposes the underlying CXString so it // shouldn't be used after this call std::string toStdString(CXString cxStr) { const char* str = clang().getCString(cxStr); if (str != NULL) { std::string stdString(str); clang().disposeString(cxStr); return stdString; } else { return std::string(); } }
CXFile TranslationUnit::getFile(const std::string& filename) const { std::string targetFile = filename; if (targetFile.empty()) targetFile = filename_; return clang().getFile(tu_, targetFile.c_str()); }
bool SourceLocation::getSpellingLocation(std::string* pFile, unsigned* pLine, unsigned* pColumn, unsigned* pOffset) const { if (!empty()) { CXFile file; clang().getSpellingLocation(location_, &file, pLine, pColumn, pOffset); CXString filename = clang().getFileName(file); *pFile = toStdString(filename); return true; } else { return false; } }
void SourceIndex::removeTranslationUnit(const std::string& filename) { TranslationUnits::iterator it = translationUnits_.find(filename); if (it != translationUnits_.end()) { if (verbose_ > 0) std::cerr << "CLANG REMOVE INDEX: " << it->first << std::endl; clang().disposeTranslationUnit(it->second.tu); translationUnits_.erase(it->first); } }
CXResult TranslationUnit::findReferencesInFile( Cursor cursor, CXCursorAndRangeVisitor visitor, const std::string& filename) const { CXFile file = getFile(filename); if (file == nullptr) return CXResult_Invalid; return clang().findReferencesInFile(cursor.getCXCursor(), file, visitor); }
Cursor TranslationUnit::getCursor(const std::string& filename, unsigned line, unsigned column) const { // get the file CXFile file = clang().getFile(tu_, filename.c_str()); if (file == nullptr) return Cursor(); // get the source location CXSourceLocation sourceLoc = clang().getLocation(tu_, file, line, column); // get the cursor CXCursor cursor = clang().getCursor(tu_, sourceLoc); if (clang().equalCursors(cursor, clang().getNullCursor())) return Cursor(); // return it return Cursor(cursor); }
void SourceIndex::removeAllTranslationUnits() { for(TranslationUnits::const_iterator it = translationUnits_.begin(); it != translationUnits_.end(); ++it) { if (verbose_ > 0) std::cerr << "CLANG REMOVE INDEX: " << it->first << std::endl; clang().disposeTranslationUnit(it->second.tu); } translationUnits_.clear(); }
/* Parse initialize message */ void parse_initialize_message(char *recvbuf){ char mode[100]; if ( !(strncmp(recvbuf,"(init",4)) ) { /* It's an init msg */ sscanf(recvbuf,"(init %c %d %[^)]",&Mem->MySide, &Mem->MyNumber, mode); Mem->ServerAlive = TRUE; } else if ( !(strncmp(recvbuf,"(reconnect",4)) ) { /* It's a reconnect msg */ sscanf(recvbuf,"(reconnect %c %[^)]",&Mem->MySide, mode); Mem->MyNumber = Mem->IP_reconnect; printf("reconnecting to %d on side %c!\n",Mem->MyNumber,Mem->MySide); Mem->ServerAlive = TRUE; } else { my_error("Didn't get an init message: '%s'",recvbuf); Mem->ServerAlive = FALSE; } if ( Mem->CP_goalie && Mem->FP_goalie_number != Mem->MyNumber ) my_error("goalie number inconsistent with me being goalie"); if ( !Mem->CP_goalie && Mem->FP_goalie_number == Mem->MyNumber ) my_error("I should be the goalie"); if ( mode[0] == 'b' ){ /* Before_kick_off */ if (Mem->IP_reconnect != 0) { Mem->SetPlayMode(PM_Half_Time); Mem->SetPlayMode(PM_Before_Kick_Off); if ( Mem->MySide == 'l' ) Mem->KickOffMode = KO_Theirs; else Mem->KickOffMode = KO_Mine; } else { Mem->SetPlayMode(PM_Before_Kick_Off); if ( Mem->MySide == 'l' ) Mem->KickOffMode = KO_Mine; else Mem->KickOffMode = KO_Theirs; } } else /* Act as if the game's in progress */ Mem->SetPlayMode(PM_Play_On); clang(8,8); /* support clang messages version 8 */ }
CompilerPtr CompilerLocatorCLANG::Locate(const wxString& folder) { m_compilers.clear(); wxFileName clang(folder, "clang"); #ifdef __WXMSW__ clang.SetExt("exe"); #endif bool found = clang.FileExists(); if ( ! found ) { // try to see if we have a bin folder here clang.AppendDir("bin"); found = clang.FileExists(); } if ( found ) { CompilerPtr compiler( new Compiler(NULL) ); compiler->SetCompilerFamily(COMPILER_FAMILY_CLANG); // get the compiler version compiler->SetName( GetCompilerFullName(clang.GetFullPath() ) ); compiler->SetGenerateDependeciesFile(true); m_compilers.push_back( compiler ); clang.RemoveLastDir(); AddTools(compiler, clang.GetPath()); // Update the toolchain (if Windows) #ifdef __WXMSW__ CompilerPtr defaultMinGWCmp = BuildSettingsConfigST::Get()->GetDefaultCompiler(COMPILER_FAMILY_MINGW); if ( defaultMinGWCmp ) { compiler->SetTool("MAKE", defaultMinGWCmp->GetTool("MAKE")); compiler->SetTool("ResourceCompiler", defaultMinGWCmp->GetTool("ResourceCompiler")); // Update the include paths IncludePathLocator locator(NULL); wxArrayString includePaths, excludePaths; locator.Locate(includePaths, excludePaths, false, defaultMinGWCmp->GetTool("CXX")); // Convert the include paths to semi colon separated list wxString mingwIncludePaths = wxJoin(includePaths, ';'); compiler->SetGlobalIncludePath( mingwIncludePaths ); } #endif return compiler; } return NULL; }
bool CompilerLocatorCLANG::Locate() { m_compilers.clear(); MSWLocate(); // POSIX locate wxFileName clang("/usr/bin", "clang"); if ( clang.FileExists() ) { CompilerPtr compiler( new Compiler(NULL) ); compiler->SetCompilerFamily(COMPILER_FAMILY_CLANG); // get the compiler version compiler->SetName( GetCompilerFullName(clang.GetFullPath() ) ); compiler->SetGenerateDependeciesFile(true); m_compilers.push_back( compiler ); clang.RemoveLastDir(); AddTools(compiler, clang.GetPath()); } return true; }
bool Cursor::isUnexposed() const { return clang().isUnexposed(getKind()); }
bool Cursor::isPreprocessing() const { return clang().isPreprocessing(getKind()); }
bool Cursor::isTranslationUnit() const { return clang().isTranslationUnit(getKind()); }
bool Cursor::isInvalid() const { return clang().isInvalid(getKind()); }
bool Cursor::isAttribute() const { return clang().isAttribute(getKind()); }
Cursor Cursor::getDefinition() const { return Cursor(clang().getCursorDefinition(cursor_)); }
bool Cursor::isReference() const { return clang().isReference(getKind()); }
bool Cursor::isDeclaration() const { return clang().isDeclaration(getKind()); }
CXCursorKind Cursor::getKind() const { return clang().getCursorKind(cursor_); }
std::string Cursor::spelling() const { return toStdString(clang().getCursorSpelling(cursor_)); }
Cursor::Cursor() : cursor_(clang().getNullCursor()) { }
bool Cursor::isDefinition() const { return clang().isCursorDefinition(cursor_) != 0; }
Cursor Cursor::getReferenced() const { return Cursor(clang().getCursorReferenced(cursor_)); }
bool Cursor::isExpression() const { return clang().isExpression(getKind()); }
std::string Cursor::displayName() const { return toStdString(clang().getCursorDisplayName(cursor_)); }
bool Cursor::isStatement() const { return clang().isStatement(getKind()); }