代码拉取完成,页面将自动刷新
#ifndef CLANGUTILS_H
#define CLANGUTILS_H
#include <QString>
#include <QDebug>
#include "clang-c/Index.h"
class ClangUtils
{
public:
static void printCursorInfo(CXCursor cursor)
{
CXString cursorSpelling = clang_getCursorSpelling(cursor);
CXType cursorType = clang_getCursorType(cursor);
CXString cursorTypeSpelling = clang_getTypeSpelling(cursorType);
//printf("Name: %s, Type: %s\n", clang_getCString(cursorSpelling), clang_getCString(cursorTypeSpelling));
qDebug() << "Name: " << clang_getCString(cursorSpelling) << ", Type: "
<< clang_getCString(cursorTypeSpelling);
clang_disposeString(cursorSpelling);
clang_disposeString(cursorTypeSpelling);
}
static bool checkDiagnostics(CXTranslationUnit translationUnit)
{
int nbDiag = clang_getNumDiagnostics(translationUnit);
qDebug() << "diagnostics num: " << nbDiag;
bool foundError = false;
for (unsigned int currentDiag = 0; currentDiag < nbDiag; ++currentDiag) {
CXDiagnostic diagnotic = clang_getDiagnostic(translationUnit, currentDiag);
CXString errorString = clang_formatDiagnostic(diagnotic, clang_defaultDiagnosticDisplayOptions());
std::string tmp{ clang_getCString(errorString) };
clang_disposeString(errorString);
if (tmp.find("error:") != std::string::npos) {
foundError = true;
}
qDebug() << QString::fromStdString(tmp);
}
return foundError;
}
static QString getDiagnostics(CXTranslationUnit translationUnit)
{
QString strError;
QTextStream stream(&strError);
int nbDiag = clang_getNumDiagnostics(translationUnit);
stream<< "diagnostics num: " << nbDiag << "\n";
bool foundError = false;
for (unsigned int currentDiag = 0; currentDiag < nbDiag; ++currentDiag) {
CXDiagnostic diagnotic = clang_getDiagnostic(translationUnit, currentDiag);
CXString errorString = clang_formatDiagnostic(diagnotic, clang_defaultDiagnosticDisplayOptions());
std::string tmp{ clang_getCString(errorString) };
clang_disposeString(errorString);
if (tmp.find("error:") != std::string::npos) {
foundError = true;
}
stream << QString::fromStdString(tmp) << "\n";
}
return strError;
}
static QString getCursorType(CXCursor cursor)
{
CXType cursorType = clang_getCursorType(cursor);
CXString cursorTypeSpelling = clang_getTypeSpelling(cursorType);
QString type = clang_getCString(cursorTypeSpelling);
clang_disposeString(cursorTypeSpelling);
return type;
}
static QString getCursorName(CXCursor cursor)
{
CXString cursorSpelling = clang_getCursorSpelling(cursor);
QString name = clang_getCString(cursorSpelling);
clang_disposeString(cursorSpelling);
return name;
}
static QString getCursorFilePath(CXCursor cursor)
{
CXFile file;
clang_getFileLocation(clang_getCursorLocation(cursor), &file, nullptr, nullptr, nullptr);
CXString cursorFilePath = clang_getFileName(file);
QString filePath = clang_getCString(cursorFilePath);
clang_disposeString(cursorFilePath);
return filePath;
}
};
#endif // CLANGUTILS_H
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。