diff options
author | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2014-03-17 08:49:40 -0300 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2014-03-26 15:57:27 +0100 |
commit | 25be7e087d6cffb2ac3619c80968aaa82ef0255d (patch) | |
tree | 8cfa1ed9e3884e7325bfbeb3d5cc33e2fd43afc7 /src/plugins/cppeditor | |
parent | 0d84603c41cb1e2b9afead49bd7777c856da377f (diff) |
CppEditor: Extract CodeModelInspector::Dumper
Change-Id: I58acfb2d049dd4239a3f41b0a5795bfaab7b4f2f
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/plugins/cppeditor')
-rw-r--r-- | src/plugins/cppeditor/cppcodemodelinspectordialog.cpp | 710 |
1 files changed, 45 insertions, 665 deletions
diff --git a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp index c602bd25d0b..4c032fb7694 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp +++ b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp @@ -28,14 +28,13 @@ ****************************************************************************/ #include "cppcodemodelinspectordialog.h" -#include "cppeditor.h" #include "ui_cppcodemodelinspectordialog.h" +#include "cppeditor.h" -#include <app/app_version.h> #include <coreplugin/editormanager/editormanager.h> #include <coreplugin/icore.h> +#include <cpptools/cppcodemodelinspectordumper.h> #include <cpptools/cppmodelmanagerinterface.h> -#include <cpptools/cppprojectfile.h> #include <cpptools/cpptoolseditorsupport.h> #include <projectexplorer/project.h> @@ -51,386 +50,10 @@ #include <QSortFilterProxyModel> using namespace CppTools; +namespace CMI = CppCodeModelInspector; namespace { -// --- Utils -------------------------------------------------------------------------------------- - -QString toString(bool value) -{ - return value ? QLatin1String("Yes") : QLatin1String("No"); -} - -QString toString(unsigned value) -{ - return QString::number(value); -} - -QString toString(const QDateTime &dateTime) -{ - return dateTime.toString(QLatin1String("hh:mm:ss dd.MM.yy")); -} - -QString toString(CPlusPlus::Document::CheckMode checkMode) -{ -#define CASE_CHECKMODE(x) case CPlusPlus::Document::x: return QLatin1String(#x) - switch (checkMode) { - CASE_CHECKMODE(Unchecked); - CASE_CHECKMODE(FullCheck); - CASE_CHECKMODE(FastCheck); - // no default to get a compiler warning if anything is added - } -#undef CASE_CHECKMODE - return QString(); -} - -QString toString(CPlusPlus::Document::DiagnosticMessage::Level level) -{ -#define CASE_LEVEL(x) case CPlusPlus::Document::DiagnosticMessage::x: return QLatin1String(#x) - switch (level) { - CASE_LEVEL(Warning); - CASE_LEVEL(Error); - CASE_LEVEL(Fatal); - // no default to get a compiler warning if anything is added - } -#undef CASE_LEVEL - return QString(); -} - -QString toString(ProjectPart::CVersion cVersion) -{ -#define CASE_CVERSION(x) case ProjectPart::x: return QLatin1String(#x) - switch (cVersion) { - CASE_CVERSION(C89); - CASE_CVERSION(C99); - CASE_CVERSION(C11); - // no default to get a compiler warning if anything is added - } -#undef CASE_CVERSION - return QString(); -} - -QString toString(ProjectPart::CXXVersion cxxVersion) -{ -#define CASE_CXXVERSION(x) case ProjectPart::x: return QLatin1String(#x) - switch (cxxVersion) { - CASE_CXXVERSION(CXX98); - CASE_CXXVERSION(CXX11); - // no default to get a compiler warning if anything is added - } -#undef CASE_CXXVERSION - return QString(); -} - -QString toString(ProjectPart::CXXExtensions cxxExtension) -{ - QString result; - -#define CASE_CXXEXTENSION(ext) if (cxxExtension & ProjectPart::ext) \ - result += QLatin1String(#ext ", "); - - CASE_CXXEXTENSION(NoExtensions); - CASE_CXXEXTENSION(GnuExtensions); - CASE_CXXEXTENSION(MicrosoftExtensions); - CASE_CXXEXTENSION(BorlandExtensions); - CASE_CXXEXTENSION(OpenMPExtensions); -#undef CASE_CXXEXTENSION - if (result.endsWith(QLatin1String(", "))) - result.chop(2); - return result; -} - -QString toString(ProjectPart::QtVersion qtVersion) -{ -#define CASE_QTVERSION(x) case ProjectPart::x: return QLatin1String(#x) - switch (qtVersion) { - CASE_QTVERSION(UnknownQt); - CASE_QTVERSION(NoQt); - CASE_QTVERSION(Qt4); - CASE_QTVERSION(Qt5); - // no default to get a compiler warning if anything is added - } -#undef CASE_QTVERSION - return QString(); -} - -QString toString(const QList<ProjectFile> &projectFiles) -{ - QStringList filesList; - foreach (const ProjectFile &projectFile, projectFiles) - filesList << QDir::toNativeSeparators(projectFile.path); - qSort(filesList); - return filesList.join(QLatin1String("\n")); -} - -QString toString(ProjectFile::Kind kind) -{ -#define CASE_PROFECTFILEKIND(x) case ProjectFile::x: return QLatin1String(#x) - switch (kind) { - CASE_PROFECTFILEKIND(Unclassified); - CASE_PROFECTFILEKIND(CHeader); - CASE_PROFECTFILEKIND(CSource); - CASE_PROFECTFILEKIND(CXXHeader); - CASE_PROFECTFILEKIND(CXXSource); - CASE_PROFECTFILEKIND(ObjCHeader); - CASE_PROFECTFILEKIND(ObjCSource); - CASE_PROFECTFILEKIND(ObjCXXHeader); - CASE_PROFECTFILEKIND(ObjCXXSource); - CASE_PROFECTFILEKIND(CudaSource); - CASE_PROFECTFILEKIND(OpenCLSource); - // no default to get a compiler warning if anything is added - } -#undef CASE_PROFECTFILEKIND - return QString(); -} - -QString toString(CPlusPlus::Kind kind) -{ - using namespace CPlusPlus; -#define TOKEN(x) case x: return QLatin1String(#x) -#define TOKEN_AND_ALIASES(x,y) case x: return QLatin1String(#x "/" #y) - switch (kind) { - TOKEN(T_EOF_SYMBOL); - TOKEN(T_ERROR); - TOKEN(T_CPP_COMMENT); - TOKEN(T_CPP_DOXY_COMMENT); - TOKEN(T_COMMENT); - TOKEN(T_DOXY_COMMENT); - TOKEN(T_IDENTIFIER); - TOKEN(T_NUMERIC_LITERAL); - TOKEN(T_CHAR_LITERAL); - TOKEN(T_WIDE_CHAR_LITERAL); - TOKEN(T_UTF16_CHAR_LITERAL); - TOKEN(T_UTF32_CHAR_LITERAL); - TOKEN(T_STRING_LITERAL); - TOKEN(T_WIDE_STRING_LITERAL); - TOKEN(T_UTF8_STRING_LITERAL); - TOKEN(T_UTF16_STRING_LITERAL); - TOKEN(T_UTF32_STRING_LITERAL); - TOKEN(T_RAW_STRING_LITERAL); - TOKEN(T_RAW_WIDE_STRING_LITERAL); - TOKEN(T_RAW_UTF8_STRING_LITERAL); - TOKEN(T_RAW_UTF16_STRING_LITERAL); - TOKEN(T_RAW_UTF32_STRING_LITERAL); - TOKEN(T_AT_STRING_LITERAL); - TOKEN(T_ANGLE_STRING_LITERAL); - TOKEN_AND_ALIASES(T_AMPER, T_BITAND); - TOKEN_AND_ALIASES(T_AMPER_AMPER, T_AND); - TOKEN_AND_ALIASES(T_AMPER_EQUAL, T_AND_EQ); - TOKEN(T_ARROW); - TOKEN(T_ARROW_STAR); - TOKEN_AND_ALIASES(T_CARET, T_XOR); - TOKEN_AND_ALIASES(T_CARET_EQUAL, T_XOR_EQ); - TOKEN(T_COLON); - TOKEN(T_COLON_COLON); - TOKEN(T_COMMA); - TOKEN(T_SLASH); - TOKEN(T_SLASH_EQUAL); - TOKEN(T_DOT); - TOKEN(T_DOT_DOT_DOT); - TOKEN(T_DOT_STAR); - TOKEN(T_EQUAL); - TOKEN(T_EQUAL_EQUAL); - TOKEN_AND_ALIASES(T_EXCLAIM, T_NOT); - TOKEN_AND_ALIASES(T_EXCLAIM_EQUAL, T_NOT_EQ); - TOKEN(T_GREATER); - TOKEN(T_GREATER_EQUAL); - TOKEN(T_GREATER_GREATER); - TOKEN(T_GREATER_GREATER_EQUAL); - TOKEN(T_LBRACE); - TOKEN(T_LBRACKET); - TOKEN(T_LESS); - TOKEN(T_LESS_EQUAL); - TOKEN(T_LESS_LESS); - TOKEN(T_LESS_LESS_EQUAL); - TOKEN(T_LPAREN); - TOKEN(T_MINUS); - TOKEN(T_MINUS_EQUAL); - TOKEN(T_MINUS_MINUS); - TOKEN(T_PERCENT); - TOKEN(T_PERCENT_EQUAL); - TOKEN_AND_ALIASES(T_PIPE, T_BITOR); - TOKEN_AND_ALIASES(T_PIPE_EQUAL, T_OR_EQ); - TOKEN_AND_ALIASES(T_PIPE_PIPE, T_OR); - TOKEN(T_PLUS); - TOKEN(T_PLUS_EQUAL); - TOKEN(T_PLUS_PLUS); - TOKEN(T_POUND); - TOKEN(T_POUND_POUND); - TOKEN(T_QUESTION); - TOKEN(T_RBRACE); - TOKEN(T_RBRACKET); - TOKEN(T_RPAREN); - TOKEN(T_SEMICOLON); - TOKEN(T_STAR); - TOKEN(T_STAR_EQUAL); - TOKEN_AND_ALIASES(T_TILDE, T_COMPL); - TOKEN(T_TILDE_EQUAL); - TOKEN(T_ALIGNAS); - TOKEN(T_ALIGNOF); - TOKEN_AND_ALIASES(T_ASM, T___ASM/T___ASM__); - TOKEN(T_AUTO); - TOKEN(T_BOOL); - TOKEN(T_BREAK); - TOKEN(T_CASE); - TOKEN(T_CATCH); - TOKEN(T_CHAR); - TOKEN(T_CHAR16_T); - TOKEN(T_CHAR32_T); - TOKEN(T_CLASS); - TOKEN_AND_ALIASES(T_CONST, T___CONST/T___CONST__); - TOKEN(T_CONST_CAST); - TOKEN(T_CONSTEXPR); - TOKEN(T_CONTINUE); - TOKEN_AND_ALIASES(T_DECLTYPE, T___DECLTYPE); - TOKEN(T_DEFAULT); - TOKEN(T_DELETE); - TOKEN(T_DO); - TOKEN(T_DOUBLE); - TOKEN(T_DYNAMIC_CAST); - TOKEN(T_ELSE); - TOKEN(T_ENUM); - TOKEN(T_EXPLICIT); - TOKEN(T_EXPORT); - TOKEN(T_EXTERN); - TOKEN(T_FALSE); - TOKEN(T_FLOAT); - TOKEN(T_FOR); - TOKEN(T_FRIEND); - TOKEN(T_GOTO); - TOKEN(T_IF); - TOKEN_AND_ALIASES(T_INLINE, T___INLINE/T___INLINE__); - TOKEN(T_INT); - TOKEN(T_LONG); - TOKEN(T_MUTABLE); - TOKEN(T_NAMESPACE); - TOKEN(T_NEW); - TOKEN(T_NOEXCEPT); - TOKEN(T_NULLPTR); - TOKEN(T_OPERATOR); - TOKEN(T_PRIVATE); - TOKEN(T_PROTECTED); - TOKEN(T_PUBLIC); - TOKEN(T_REGISTER); - TOKEN(T_REINTERPRET_CAST); - TOKEN(T_RETURN); - TOKEN(T_SHORT); - TOKEN(T_SIGNED); - TOKEN(T_SIZEOF); - TOKEN(T_STATIC); - TOKEN(T_STATIC_ASSERT); - TOKEN(T_STATIC_CAST); - TOKEN(T_STRUCT); - TOKEN(T_SWITCH); - TOKEN(T_TEMPLATE); - TOKEN(T_THIS); - TOKEN(T_THREAD_LOCAL); - TOKEN(T_THROW); - TOKEN(T_TRUE); - TOKEN(T_TRY); - TOKEN(T_TYPEDEF); - TOKEN(T_TYPEID); - TOKEN(T_TYPENAME); - TOKEN(T_UNION); - TOKEN(T_UNSIGNED); - TOKEN(T_USING); - TOKEN(T_VIRTUAL); - TOKEN(T_VOID); - TOKEN_AND_ALIASES(T_VOLATILE, T___VOLATILE/T___VOLATILE__); - TOKEN(T_WCHAR_T); - TOKEN(T_WHILE); - TOKEN_AND_ALIASES(T___ATTRIBUTE__, T___ATTRIBUTE); - TOKEN(T___THREAD); - TOKEN_AND_ALIASES(T___TYPEOF__, T_TYPEOF/T___TYPEOF); - TOKEN(T_AT_CATCH); - TOKEN(T_AT_CLASS); - TOKEN(T_AT_COMPATIBILITY_ALIAS); - TOKEN(T_AT_DEFS); - TOKEN(T_AT_DYNAMIC); - TOKEN(T_AT_ENCODE); - TOKEN(T_AT_END); - TOKEN(T_AT_FINALLY); - TOKEN(T_AT_IMPLEMENTATION); - TOKEN(T_AT_INTERFACE); - TOKEN(T_AT_NOT_KEYWORD); - TOKEN(T_AT_OPTIONAL); - TOKEN(T_AT_PACKAGE); - TOKEN(T_AT_PRIVATE); - TOKEN(T_AT_PROPERTY); - TOKEN(T_AT_PROTECTED); - TOKEN(T_AT_PROTOCOL); - TOKEN(T_AT_PUBLIC); - TOKEN(T_AT_REQUIRED); - TOKEN(T_AT_SELECTOR); - TOKEN(T_AT_SYNCHRONIZED); - TOKEN(T_AT_SYNTHESIZE); - TOKEN(T_AT_THROW); - TOKEN(T_AT_TRY); - TOKEN(T_EMIT); - TOKEN(T_SIGNAL); - TOKEN(T_SLOT); - TOKEN(T_Q_SIGNAL); - TOKEN(T_Q_SLOT); - TOKEN(T_Q_SIGNALS); - TOKEN(T_Q_SLOTS); - TOKEN(T_Q_FOREACH); - TOKEN(T_Q_D); - TOKEN(T_Q_Q); - TOKEN(T_Q_INVOKABLE); - TOKEN(T_Q_PROPERTY); - TOKEN(T_Q_PRIVATE_PROPERTY); - TOKEN(T_Q_INTERFACES); - TOKEN(T_Q_EMIT); - TOKEN(T_Q_ENUMS); - TOKEN(T_Q_FLAGS); - TOKEN(T_Q_PRIVATE_SLOT); - TOKEN(T_Q_DECLARE_INTERFACE); - TOKEN(T_Q_OBJECT); - TOKEN(T_Q_GADGET); - // no default to get a compiler warning if anything is added - } -#undef TOKEN -#undef TOKEN_AND_ALIASES - return QString(); -} - -QString partsForFile(const QString &fileName) -{ - const QList<ProjectPart::Ptr> parts - = CppModelManagerInterface::instance()->projectPart(fileName); - QString result; - foreach (const ProjectPart::Ptr &part, parts) - result += part->displayName + QLatin1Char(','); - if (result.endsWith(QLatin1Char(','))) - result.chop(1); - return result; -} - -QString unresolvedFileNameWithDelimiters(const CPlusPlus::Document::Include &include) -{ - const QString unresolvedFileName = include.unresolvedFileName(); - if (include.type() == CPlusPlus::Client::IncludeLocal) - return QLatin1Char('"') + unresolvedFileName + QLatin1Char('"'); - return QLatin1Char('<') + unresolvedFileName + QLatin1Char('>'); -} - -QString pathListToString(const QStringList &pathList) -{ - QStringList result; - foreach (const QString &path, pathList) - result << QDir::toNativeSeparators(path); - return result.join(QLatin1String("\n")); -} - -QList<CPlusPlus::Document::Ptr> snapshotToList(const CPlusPlus::Snapshot &snapshot) -{ - QList<CPlusPlus::Document::Ptr> documents; - CPlusPlus::Snapshot::const_iterator it = snapshot.begin(), end = snapshot.end(); - for (; it != end; ++it) - documents.append(it.value()); - return documents; -} - template <class T> void resizeColumns(QTreeView *view) { for (int column = 0; column < T::ColumnCount - 1; ++column) @@ -490,262 +113,6 @@ private: bool m_stop; }; -class CppCodeModelInspectorDumper -{ -public: - explicit CppCodeModelInspectorDumper(const CPlusPlus::Snapshot &globalSnapshot); - ~CppCodeModelInspectorDumper(); - - void dumpProjectInfos(const QList<CppModelManagerInterface::ProjectInfo> &projectInfos); - void dumpSnapshot(const CPlusPlus::Snapshot &snapshot, const QString &title, - bool isGlobalSnapshot = false); - void dumpWorkingCopy(const CppModelManagerInterface::WorkingCopy &workingCopy); - -private: - void dumpDocuments(const QList<CPlusPlus::Document::Ptr> &documents, - bool skipDetails = false); - static QByteArray indent(int level); - - CPlusPlus::Snapshot m_globalSnapshot; - QFile m_logFile; - QTextStream m_out; -}; - -CppCodeModelInspectorDumper::CppCodeModelInspectorDumper(const CPlusPlus::Snapshot &globalSnapshot) - : m_globalSnapshot(globalSnapshot), m_out(stderr) -{ - const QString logFileName = QDir::tempPath() - + QString::fromLatin1("/qtc-codemodelinspection.txt"); - m_logFile.setFileName(logFileName); - if (m_logFile.open(QIODevice::WriteOnly | QIODevice::Text)) { - m_out << "Code model inspection log file is \"" << QDir::toNativeSeparators(logFileName) - << "\".\n"; - m_out.setDevice(&m_logFile); - } - m_out << "*** START Code Model Inspection Report for "; - QString ideRevision; -#ifdef IDE_REVISION - ideRevision = QLatin1String(" from revision ") - + QString::fromLatin1(Core::Constants::IDE_REVISION_STR).left(10); -#endif - m_out << Core::ICore::versionString() << ideRevision << "\n"; - m_out << "Note: This file contains vim fold markers (\"{{{n\"). " - "Make use of them via \":set foldmethod=marker\".\n"; -} - -CppCodeModelInspectorDumper::~CppCodeModelInspectorDumper() -{ - m_out << "*** END Code Model Inspection Report\n"; -} - -void CppCodeModelInspectorDumper::dumpProjectInfos( - const QList<CppModelManagerInterface::ProjectInfo> &projectInfos) -{ - const QByteArray i1 = indent(1); - const QByteArray i2 = indent(2); - const QByteArray i3 = indent(3); - const QByteArray i4 = indent(4); - - m_out << "Projects loaded: " << projectInfos.size() << "{{{1\n"; - foreach (const CppModelManagerInterface::ProjectInfo &info, projectInfos) { - const QPointer<ProjectExplorer::Project> project = info.project(); - m_out << i1 << "Project " << project->displayName() << " (" << project->projectFilePath() - << "){{{2\n"; - - const QList<ProjectPart::Ptr> projectParts = info.projectParts(); - foreach (const ProjectPart::Ptr &part, projectParts) { - QString projectName = QLatin1String("<None>"); - QString projectFilePath = QLatin1String("<None>"); - if (ProjectExplorer::Project *project = part->project) { - projectName = project->displayName(); - projectFilePath = project->projectFilePath(); - } - if (!part->projectConfigFile.isEmpty()) - m_out << i3 << "Project Config File: " << part->projectConfigFile << "\n"; - m_out << i2 << "Project Part \"" << part->projectFile << "\"{{{3\n"; - m_out << i3 << "Project Part Name : " << part->displayName << "\n"; - m_out << i3 << "Project Name : " << projectName << "\n"; - m_out << i3 << "Project File : " << projectFilePath << "\n"; - m_out << i3 << "C Version : " << toString(part->cVersion) << "\n"; - m_out << i3 << "CXX Version : " << toString(part->cxxVersion) << "\n"; - m_out << i3 << "CXX Extensions : " << toString(part->cxxExtensions) << "\n"; - m_out << i3 << "Qt Version : " << toString(part->qtVersion) << "\n"; - - if (!part->files.isEmpty()) { - m_out << i3 << "Files:{{{4\n"; - foreach (const ProjectFile &projectFile, part->files) { - m_out << i4 << toString(projectFile.kind) << ": " << projectFile.path - << "\n"; - } - } - - if (!part->toolchainDefines.isEmpty()) { - m_out << i3 << "Toolchain Defines:{{{4\n"; - const QList<QByteArray> defineLines = part->toolchainDefines.split('\n'); - foreach (const QByteArray &defineLine, defineLines) - m_out << i4 << defineLine << "\n"; - } - if (!part->projectDefines.isEmpty()) { - m_out << i3 << "Project Defines:{{{4\n"; - const QList<QByteArray> defineLines = part->projectDefines.split('\n'); - foreach (const QByteArray &defineLine, defineLines) - m_out << i4 << defineLine << "\n"; - } - - if (!part->includePaths.isEmpty()) { - m_out << i3 << "Include Paths:{{{4\n"; - foreach (const QString &includePath, part->includePaths) - m_out << i4 << includePath << "\n"; - } - - if (!part->frameworkPaths.isEmpty()) { - m_out << i3 << "Framework Paths:{{{4\n"; - foreach (const QString &frameworkPath, part->frameworkPaths) - m_out << i4 << frameworkPath << "\n"; - } - - if (!part->precompiledHeaders.isEmpty()) { - m_out << i3 << "Precompiled Headers:{{{4\n"; - foreach (const QString &precompiledHeader, part->precompiledHeaders) - m_out << i4 << precompiledHeader << "\n"; - } - } // for part - } // for project Info -} - -void CppCodeModelInspectorDumper::dumpSnapshot(const CPlusPlus::Snapshot &snapshot, - const QString &title, bool isGlobalSnapshot) -{ - m_out << "Snapshot \"" << title << "\"{{{1\n"; - - const QByteArray i1 = indent(1); - const QList<CPlusPlus::Document::Ptr> documents = snapshotToList(snapshot); - - if (isGlobalSnapshot) { - if (!documents.isEmpty()) { - m_out << i1 << "Globally-Shared documents{{{2\n"; - dumpDocuments(documents, false); - } - } else { - // Divide into shared and not shared - QList<CPlusPlus::Document::Ptr> globallyShared; - QList<CPlusPlus::Document::Ptr> notGloballyShared; - foreach (const CPlusPlus::Document::Ptr &document, documents) { - CPlusPlus::Document::Ptr globalDocument = m_globalSnapshot.document(document->fileName()); - if (globalDocument && globalDocument->fingerprint() == document->fingerprint()) - globallyShared.append(document); - else - notGloballyShared.append(document); - } - - if (!notGloballyShared.isEmpty()) { - m_out << i1 << "Not-Globally-Shared documents:{{{2\n"; - dumpDocuments(notGloballyShared); - } - if (!globallyShared.isEmpty()) { - m_out << i1 << "Globally-Shared documents{{{2\n"; - dumpDocuments(globallyShared, true); - } - } -} - -void CppCodeModelInspectorDumper::dumpWorkingCopy( - const CppModelManagerInterface::WorkingCopy &workingCopy) -{ - m_out << "Working Copy contains " << workingCopy.size() << " entries{{{1\n"; - - const QByteArray i1 = indent(1); - QHashIterator<QString, QPair<QByteArray, unsigned> > it = workingCopy.iterator(); - while (it.hasNext()) { - it.next(); - const QString filePath = it.key(); - unsigned sourcRevision = it.value().second; - m_out << i1 << "rev=" << sourcRevision << ", " << filePath << "\n"; - } -} - -void CppCodeModelInspectorDumper::dumpDocuments(const QList<CPlusPlus::Document::Ptr> &documents, - bool skipDetails) -{ - const QByteArray i2 = indent(2); - const QByteArray i3 = indent(3); - const QByteArray i4 = indent(4); - foreach (const CPlusPlus::Document::Ptr &document, documents) { - if (skipDetails) { - m_out << i2 << "\"" << document->fileName() << "\"\n"; - continue; - } - - m_out << i2 << "Document \"" << document->fileName() << "\"{{{3\n"; - m_out << i3 << "Last Modified : " << toString(document->lastModified()) << "\n"; - m_out << i3 << "Revision : " << toString(document->revision()) << "\n"; - m_out << i3 << "Editor Revision: " << toString(document->editorRevision()) << "\n"; - m_out << i3 << "Check Mode : " << toString(document->checkMode()) << "\n"; - m_out << i3 << "Tokenized : " << toString(document->isTokenized()) << "\n"; - m_out << i3 << "Parsed : " << toString(document->isParsed()) << "\n"; - m_out << i3 << "Project Parts : " << partsForFile(document->fileName()) << "\n"; - - const QList<CPlusPlus::Document::Include> includes = document->unresolvedIncludes() - + document->resolvedIncludes(); - if (!includes.isEmpty()) { - m_out << i3 << "Includes:{{{4\n"; - foreach (const CPlusPlus::Document::Include &include, includes) { - m_out << i4 << "at line " << include.line() << ": " - << unresolvedFileNameWithDelimiters(include) << " ==> " - << include.resolvedFileName() << "\n"; - } - } - - const QList<CPlusPlus::Document::DiagnosticMessage> diagnosticMessages - = document->diagnosticMessages(); - if (!diagnosticMessages.isEmpty()) { - m_out << i3 << "Diagnostic Messages:{{{4\n"; - foreach (const CPlusPlus::Document::DiagnosticMessage &msg, diagnosticMessages) { - const CPlusPlus::Document::DiagnosticMessage::Level level - = static_cast<CPlusPlus::Document::DiagnosticMessage::Level>(msg.level()); - m_out << i4 << "at " << msg.line() << ":" << msg.column() << ", " << toString(level) - << ": " << msg.text() << "\n"; - } - } - - const QList<CPlusPlus::Macro> macroDefinitions = document->definedMacros(); - if (!macroDefinitions.isEmpty()) { - m_out << i3 << "(Un)Defined Macros:{{{4\n"; - foreach (const CPlusPlus::Macro ¯o, macroDefinitions) - m_out << i4 << "at line " << macro.line() << ": " << macro.toString() << "\n"; - } - - const QList<CPlusPlus::Document::MacroUse> macroUses = document->macroUses(); - if (!macroUses.isEmpty()) { - m_out << i3 << "Macro Uses:{{{4\n"; - foreach (const CPlusPlus::Document::MacroUse &use, macroUses) { - const QString type = use.isFunctionLike() - ? QLatin1String("function-like") : QLatin1String("object-like"); - m_out << i4 << "at line " << use.beginLine() << ", " - << QString::fromUtf8(use.macro().name()) << ", begin=" << use.begin() - << ", end=" << use.end() << ", " << type << ", args=" - << use.arguments().size() << "\n"; - } - } - - const QString source = QString::fromUtf8(document->utf8Source()); - if (!source.isEmpty()) { - m_out << i4 << "Source:{{{4\n"; - m_out << source; - m_out << "\n<<<EOF\n"; - } - } -} - -QByteArray CppCodeModelInspectorDumper::indent(int level) -{ - const QByteArray basicIndent(" "); - QByteArray indent = basicIndent; - while (level-- > 1) - indent += basicIndent; - return indent; -} - } // anonymous namespace namespace CppEditor { @@ -945,7 +312,7 @@ SnapshotModel::SnapshotModel(QObject *parent) : QAbstractListModel(parent) void SnapshotModel::configure(const CPlusPlus::Snapshot &snapshot) { emit layoutAboutToBeChanged(); - m_documents = snapshotToList(snapshot); + m_documents = CMI::Utils::snapshotToList(snapshot); emit layoutChanged(); } @@ -985,7 +352,7 @@ QVariant SnapshotModel::data(const QModelIndex &index, int role) const CPlusPlus::Document::Ptr globalDocument = m_globalSnapshot.document(document->fileName()); const bool isShared = globalDocument && globalDocument->fingerprint() == document->fingerprint(); - return toString(isShared); + return CMI::Utils::toString(isShared); } else if (column == FilePathColumn) { return QDir::toNativeSeparators(document->fileName()); } @@ -1081,12 +448,12 @@ QVariant IncludesModel::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { const int column = index.column(); if (column == ResolvedOrNotColumn) { - return toString(isResolved); + return CMI::Utils::toString(isResolved); } else if (column == LineNumberColumn) { return include.line(); } else if (column == FilePathsColumn) { - return QVariant(unresolvedFileNameWithDelimiters(include) + QLatin1String(" --> ") - + resolvedFileName); + return QVariant(CMI::Utils::unresolvedFileNameWithDelimiters(include) + + QLatin1String(" --> ") + resolvedFileName); } } else if (role == Qt::ForegroundRole) { return isResolved ? greenBrush : redBrush; @@ -1185,7 +552,7 @@ QVariant DiagnosticMessagesModel::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { const int column = index.column(); if (column == LevelColumn) { - return toString(level); + return CMI::Utils::toString(level); } else if (column == LineColumnNumberColumn) { return QVariant(QString::number(message.line()) + QLatin1Char(':') + QString::number(message.column())); @@ -1517,23 +884,24 @@ QVariant TokensModel::data(const QModelIndex &index, int role) const if (column == SpelledColumn) return QString::fromUtf8(token.spell()); else if (column == KindColumn) - return toString(static_cast<CPlusPlus::Kind>(token.kind())); + return CMI::Utils::toString(static_cast<CPlusPlus::Kind>(token.kind())); else if (column == IndexColumn) return index.row(); else if (column == OffsetColumn) return token.offset; else if (column == LineColumnNumberColumn) - return QString::fromLatin1("%1:%2").arg(toString(info.line), toString(info.column)); + return QString::fromLatin1("%1:%2") + .arg(CMI::Utils::toString(info.line), CMI::Utils::toString(info.column)); else if (column == LengthColumn) - return toString(token.length()); + return CMI::Utils::toString(token.length()); else if (column == GeneratedColumn) - return toString(token.generated()); + return CMI::Utils::toString(token.generated()); else if (column == ExpandedColumn) - return toString(token.expanded()); + return CMI::Utils::toString(token.expanded()); else if (column == WhiteSpaceColumn) - return toString(token.whitespace()); + return CMI::Utils::toString(token.whitespace()); else if (column == NewlineColumn) - return toString(token.newline()); + return CMI::Utils::toString(token.newline()); } else if (role == Qt::TextAlignmentRole) { return Qt::AlignTop + Qt::AlignLeft; } @@ -1978,7 +1346,7 @@ void CppCodeModelInspectorDialog::refresh() m_ui->snapshotSelector->clear(); const CPlusPlus::Snapshot globalSnapshot = cmm->snapshot(); - CppCodeModelInspectorDumper dumper(globalSnapshot); + CppCodeModelInspector::Dumper dumper(globalSnapshot); m_snapshotModel->setGlobalSnapshot(globalSnapshot); m_snapshotInfos->append(SnapshotInfo(globalSnapshot, SnapshotInfo::GlobalSnapshot)); @@ -2133,13 +1501,20 @@ void CppCodeModelInspectorDialog::updateDocumentData(const CPlusPlus::Document:: KeyValueModel::Table table = KeyValueModel::Table() << qMakePair(QString::fromLatin1("File Path"), QDir::toNativeSeparators(document->fileName())) - << qMakePair(QString::fromLatin1("Last Modified"), toString(document->lastModified())) - << qMakePair(QString::fromLatin1("Revision"), toString(document->revision())) - << qMakePair(QString::fromLatin1("Editor Revision"), toString(document->editorRevision())) - << qMakePair(QString::fromLatin1("Check Mode"), toString(document->checkMode())) - << qMakePair(QString::fromLatin1("Tokenized"), toString(document->isTokenized())) - << qMakePair(QString::fromLatin1("Parsed"), toString(document->isParsed())) - << qMakePair(QString::fromLatin1("Project Parts"), partsForFile(document->fileName())) + << qMakePair(QString::fromLatin1("Last Modified"), + CMI::Utils::toString(document->lastModified())) + << qMakePair(QString::fromLatin1("Revision"), + CMI::Utils::toString(document->revision())) + << qMakePair(QString::fromLatin1("Editor Revision"), + CMI::Utils::toString(document->editorRevision())) + << qMakePair(QString::fromLatin1("Check Mode"), + CMI::Utils::toString(document->checkMode())) + << qMakePair(QString::fromLatin1("Tokenized"), + CMI::Utils::toString(document->isTokenized())) + << qMakePair(QString::fromLatin1("Parsed"), + CMI::Utils::toString(document->isParsed())) + << qMakePair(QString::fromLatin1("Project Parts"), + CMI::Utils::partsForFile(document->fileName())) ; m_docGenericInfoModel->configure(table); resizeColumns<KeyValueModel>(m_ui->docGeneralView); @@ -2243,10 +1618,14 @@ void CppCodeModelInspectorDialog::updateProjectPartData(const ProjectPart::Ptr & << qMakePair(QString::fromLatin1("Project Name"), projectName) << qMakePair(QString::fromLatin1("Project File"), QDir::toNativeSeparators(projectFilePath)) - << qMakePair(QString::fromLatin1("C Version"), toString(part->cVersion)) - << qMakePair(QString::fromLatin1("CXX Version"), toString(part->cxxVersion)) - << qMakePair(QString::fromLatin1("CXX Extensions"), toString(part->cxxExtensions)) - << qMakePair(QString::fromLatin1("Qt Version"), toString(part->qtVersion)) + << qMakePair(QString::fromLatin1("C Version"), + CMI::Utils::toString(part->cVersion)) + << qMakePair(QString::fromLatin1("CXX Version"), + CMI::Utils::toString(part->cxxVersion)) + << qMakePair(QString::fromLatin1("CXX Extensions"), + CMI::Utils::toString(part->cxxExtensions)) + << qMakePair(QString::fromLatin1("Qt Version"), + CMI::Utils::toString(part->qtVersion)) ; if (!part->projectConfigFile.isEmpty()) table.prepend(qMakePair(QString::fromLatin1("Project Config File"), @@ -2255,7 +1634,7 @@ void CppCodeModelInspectorDialog::updateProjectPartData(const ProjectPart::Ptr & resizeColumns<KeyValueModel>(m_ui->partGeneralView); // Project Files - m_ui->partProjectFilesEdit->setPlainText(toString(part->files)); + m_ui->partProjectFilesEdit->setPlainText(CMI::Utils::toString(part->files)); m_ui->projectPartTab->setTabText(ProjectPartFilesTab, partTabName(ProjectPartFilesTab, part->files.size())); @@ -2273,17 +1652,18 @@ void CppCodeModelInspectorDialog::updateProjectPartData(const ProjectPart::Ptr & partTabName(ProjectPartDefinesTab, numberOfDefines)); // Include Paths - m_ui->partIncludePathsEdit->setPlainText(pathListToString(part->includePaths)); + m_ui->partIncludePathsEdit->setPlainText(CMI::Utils::pathListToString(part->includePaths)); m_ui->projectPartTab->setTabText(ProjectPartIncludePathsTab, partTabName(ProjectPartIncludePathsTab, part->includePaths.size())); // Framework Paths - m_ui->partFrameworkPathsEdit->setPlainText(pathListToString(part->frameworkPaths)); + m_ui->partFrameworkPathsEdit->setPlainText(CMI::Utils::pathListToString(part->frameworkPaths)); m_ui->projectPartTab->setTabText(ProjectPartFrameworkPathsTab, partTabName(ProjectPartFrameworkPathsTab, part->frameworkPaths.size())); // Precompiled Headers - m_ui->partPrecompiledHeadersEdit->setPlainText(pathListToString(part->precompiledHeaders)); + m_ui->partPrecompiledHeadersEdit->setPlainText( + CMI::Utils::pathListToString(part->precompiledHeaders)); m_ui->projectPartTab->setTabText(ProjectPartPrecompiledHeadersTab, partTabName(ProjectPartPrecompiledHeadersTab, part->precompiledHeaders.size())); } |