1 Star 0 Fork 0

yuanerhh/GenUML

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ClangUtils.h 3.35 KB
一键复制 编辑 原始数据 按行查看 历史
#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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yuanerhh/GenUML.git
[email protected]:yuanerhh/GenUML.git
yuanerhh
GenUML
GenUML
master

搜索帮助