diff options
author | Eike Ziller <eike.ziller@digia.com> | 2012-11-26 10:52:28 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@digia.com> | 2012-11-26 10:52:28 +0100 |
commit | 387f5a70065b6a21143f30a693b3946f43145aa1 (patch) | |
tree | 19499220eb78ffc2b83174768e4db33f36d33242 /tests/tools | |
parent | c9afad98efee2e9d7eb09407395c8ad00f175f17 (diff) | |
parent | 9820278a708024cc1ae01372dfafabe4ff295b88 (diff) | |
download | qt-creator-387f5a70065b6a21143f30a693b3946f43145aa1.tar.gz |
Merge remote-tracking branch 'origin/2.6'
Conflicts:
src/plugins/cpptools/cppcompletion_test.cpp
src/plugins/projectexplorer/kitmanagerconfigwidget.cpp
src/plugins/qmlprojectmanager/qmlprojectapplicationwizard.cpp
src/plugins/qtsupport/baseqtversion.cpp
tests/auto/cplusplus/findusages/tst_findusages.cpp
Change-Id: Idd2abc09753a71a6c252bfa9914274459b2c7e63
Diffstat (limited to 'tests/tools')
-rw-r--r-- | tests/tools/cplusplus-ast2png/cplusplus-ast2png.cpp (renamed from tests/tools/cplusplus-dump/main.cpp) | 138 | ||||
-rw-r--r-- | tests/tools/cplusplus-ast2png/cplusplus-ast2png.pro | 12 | ||||
-rw-r--r-- | tests/tools/cplusplus-ast2png/dumpers.inc (renamed from tests/tools/cplusplus-dump/dumpers.inc) | 0 | ||||
-rw-r--r-- | tests/tools/cplusplus-ast2png/tests/templ01.cpp (renamed from tests/tools/cplusplus-dump/tests/templ01.cpp) | 0 | ||||
-rwxr-xr-x | tests/tools/cplusplus-dump/c++ | 5 | ||||
-rw-r--r-- | tests/tools/cplusplus-dump/conf.c++ | 15 | ||||
-rw-r--r-- | tests/tools/cplusplus-dump/cplusplus-dump.pro | 20 | ||||
-rw-r--r-- | tests/tools/tools.pro | 2 |
8 files changed, 135 insertions, 57 deletions
diff --git a/tests/tools/cplusplus-dump/main.cpp b/tests/tools/cplusplus-ast2png/cplusplus-ast2png.cpp index 5b33ad4e4a..10a4e15ec7 100644 --- a/tests/tools/cplusplus-dump/main.cpp +++ b/tests/tools/cplusplus-ast2png/cplusplus-ast2png.cpp @@ -42,6 +42,9 @@ #include <SymbolVisitor.h> #include <Overview.h> +#include "cplusplus-tools-utils.h" + +#include <QDir> #include <QFile> #include <QList> #include <QCoreApplication> @@ -58,6 +61,22 @@ # include <cxxabi.h> #endif +// For isatty(), _isatty() +#if defined(Q_OS_WIN) +# include <io.h> +#else +# include <unistd.h> +#endif + +bool tty_for_stdin() +{ +#if defined(Q_OS_WIN) + return _isatty(_fileno(stdin)); +#else + return isatty(fileno(stdin)); +#endif +} + using namespace CPlusPlus; class ASTDump: protected ASTVisitor @@ -68,9 +87,6 @@ public: void operator()(AST *ast) { QByteArray basename = translationUnit()->fileName(); - int dotIdx = basename.lastIndexOf('.'); - if (dotIdx != -1) - basename.truncate(dotIdx); basename.append(".ast.dot"); out.open(basename.constData()); @@ -89,11 +105,10 @@ public: out << "}" << std::endl; out.close(); - std::cout << basename.constData() << std::endl; } // the following file can be generated by using: - // generate-ast <path to cpp stuff> <path to dumpers.inc> + // cplusplus-update-frontend <frontend-dir> <dumpers-file> #include "dumpers.inc" protected: @@ -195,9 +210,6 @@ public: void operator()(Symbol *s) { QByteArray basename = translationUnit->fileName(); - int dotIdx = basename.lastIndexOf('.'); - if (dotIdx != -1) - basename.truncate(dotIdx); basename.append(".symbols.dot"); out.open(basename.constData()); @@ -218,7 +230,6 @@ public: out << "}" << std::endl; out.close(); - std::cout << basename.constData() << std::endl; } protected: @@ -351,19 +362,103 @@ private: Overview o; }; + +void createImageFromDot(const QString &inputFile, const QString &outputFile, bool verbose) +{ + const QString command = CplusplusToolsUtils::portableExecutableName(QLatin1String("dot")); + const QStringList arguments = QStringList() + << QLatin1String("-Tpng") << QLatin1String("-o") << outputFile << inputFile; + CplusplusToolsUtils::executeCommand(command, arguments, QString(), verbose); +} + +const char PATH_STDIN_FILE[] = "_stdincontents.cpp"; + +QString example() +{ + return +#if defined(Q_OS_WIN) + QString::fromLatin1("> echo int foo() {} | %1 && %2.ast.png") +#elif defined(Q_OS_MAC) + QString::fromLatin1("$ echo \"int foo() {}\" | ./%1 && open %2.ast.png") +#else + QString::fromLatin1("$ echo \"int foo() {}\" | ./%1 && xdg-open %2.ast.png") +#endif + .arg(QFileInfo(qApp->arguments().at(0)).fileName(), PATH_STDIN_FILE); +} + +void printUsage() +{ + std::cout << "Usage: " << qPrintable(QFileInfo(qApp->arguments().at(0)).fileName()) + << " [-v] <file1> <file2> ...\n\n"; + + std::cout << qPrintable(QString::fromLatin1( + "Visualize AST and symbol hierarchy of given C++ files by generating png image files\n" + "in the same directory as the input files. Print paths to generated image files.\n" + "\n" + "Standard input is also read. The resulting files starts with \"%1\"\n" + "and are created in the current working directory. To show the AST for simple snippets\n" + "you might want to execute:\n" + "\n" + " %2\n" + "\n" + "Prerequisites:\n" + " 1) Make sure to have 'dot' from graphviz locatable by PATH.\n" + " 2) Make sure to have an up to date dumpers file by using 'cplusplus-update-frontend'.\n" + ).arg(PATH_STDIN_FILE, example())); +} + int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); + QStringList args = app.arguments(); + args.removeFirst(); + + bool optionVerbose = false; + + // Data from stdin? + if (!tty_for_stdin()) { + QFile file("_stdincontents.cpp"); + if (! file.open(QFile::WriteOnly)) { + std::cerr << "Error: Cannot open file for writing\"" << qPrintable(file.fileName()) + << "\"" << std::endl; + exit(EXIT_FAILURE); + } + file.write(QTextStream(stdin).readAll().toLocal8Bit()); + file.close(); + args.append(file.fileName()); + } - QStringList files = app.arguments(); - files.removeFirst(); + // Process options & arguments + if (args.contains("-v")) { + optionVerbose = true; + args.removeOne("-v"); + } + const bool helpRequested = args.contains("-h") || args.contains("-help"); + if (args.isEmpty() || helpRequested) { + printUsage(); + return helpRequested ? EXIT_SUCCESS : EXIT_FAILURE; + } + // Process files + const QStringList files = args; foreach (const QString &fileName, files) { - QFile file(fileName); + if (! QFile::exists(fileName)) { + std::cerr << "Error: File \"" << qPrintable(fileName) << "\" does not exist." + << std::endl; + exit(EXIT_FAILURE); + } + + // Run the preprocessor + const QString fileNamePreprocessed = fileName + QLatin1String(".preprocessed"); + CplusplusToolsUtils::SystemPreprocessor preprocessor(optionVerbose); + preprocessor.preprocessFile(fileName, fileNamePreprocessed); + + // Convert to dot + QFile file(fileNamePreprocessed); if (! file.open(QFile::ReadOnly)) { - std::cerr << "Cannot open \"" << qPrintable(fileName) - << "\", skipping it." << std::endl; - continue; + std::cerr << "Error: Could not open file \"" << qPrintable(fileNamePreprocessed) + << "\"" << std::endl; + exit(EXIT_FAILURE); } const QByteArray source = file.readAll(); @@ -373,7 +468,6 @@ int main(int argc, char *argv[]) doc->control()->setDiagnosticClient(0); doc->setUtf8Source(source); doc->parse(); - doc->check(); ASTDump dump(doc->translationUnit()); @@ -381,6 +475,18 @@ int main(int argc, char *argv[]) SymbolDump dump2(doc->translationUnit()); dump2(doc->globalNamespace()); + + // Create images + typedef QPair<QString, QString> Pair; + QList<Pair> inputOutputFiles; + inputOutputFiles.append(qMakePair(QString(fileName + QLatin1String(".ast.dot")), + QString(fileName + QLatin1String(".ast.png")))); + inputOutputFiles.append(qMakePair(QString(fileName + QLatin1String(".symbols.dot")), + QString(fileName + QLatin1String(".symbols.png")))); + foreach (const Pair &pair, inputOutputFiles) { + createImageFromDot(pair.first, pair.second, optionVerbose); + std::cout << qPrintable(QDir::toNativeSeparators(pair.second)) << std::endl; + } } return EXIT_SUCCESS; diff --git a/tests/tools/cplusplus-ast2png/cplusplus-ast2png.pro b/tests/tools/cplusplus-ast2png/cplusplus-ast2png.pro new file mode 100644 index 0000000000..8a0fd726ad --- /dev/null +++ b/tests/tools/cplusplus-ast2png/cplusplus-ast2png.pro @@ -0,0 +1,12 @@ +QT = core gui +macx:CONFIG -= app_bundle +win32:CONFIG += console +TEMPLATE = app +TARGET = cplusplus-ast2png +DESTDIR = ./ + +include(../../../qtcreator.pri) +include(../../../src/libs/cplusplus/cplusplus-lib.pri) +include(../../../src/tools/cplusplus-tools-utils/cplusplus-tools-utils.pri) + +SOURCES += cplusplus-ast2png.cpp diff --git a/tests/tools/cplusplus-dump/dumpers.inc b/tests/tools/cplusplus-ast2png/dumpers.inc index a08981a8f7..a08981a8f7 100644 --- a/tests/tools/cplusplus-dump/dumpers.inc +++ b/tests/tools/cplusplus-ast2png/dumpers.inc diff --git a/tests/tools/cplusplus-dump/tests/templ01.cpp b/tests/tools/cplusplus-ast2png/tests/templ01.cpp index c67299b1f1..c67299b1f1 100644 --- a/tests/tools/cplusplus-dump/tests/templ01.cpp +++ b/tests/tools/cplusplus-ast2png/tests/templ01.cpp diff --git a/tests/tools/cplusplus-dump/c++ b/tests/tools/cplusplus-dump/c++ deleted file mode 100755 index a5908b79ff..0000000000 --- a/tests/tools/cplusplus-dump/c++ +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -me=$(dirname $0) -${CPP-gcc} -U__BLOCKS__ -xc++ -E -include $me/conf.c++ $* > $me/file.i -$me/cplusplus0 $me/file.i - diff --git a/tests/tools/cplusplus-dump/conf.c++ b/tests/tools/cplusplus-dump/conf.c++ deleted file mode 100644 index 69bafe0459..0000000000 --- a/tests/tools/cplusplus-dump/conf.c++ +++ /dev/null @@ -1,15 +0,0 @@ -#define __extension__ -#define __context__ -#define __range__ -#define __asm(a...) -#define __asm__(a...) -#define restrict -#define __restrict -#define __restrict__ -// #define __weak -#define __builtin_va_arg(a,b) ((b)0) -#define __stdcall -#define __fastcall -#define __imag__ -#define __real__ -#define __complex__ diff --git a/tests/tools/cplusplus-dump/cplusplus-dump.pro b/tests/tools/cplusplus-dump/cplusplus-dump.pro deleted file mode 100644 index cd6525119e..0000000000 --- a/tests/tools/cplusplus-dump/cplusplus-dump.pro +++ /dev/null @@ -1,20 +0,0 @@ -QT = core gui -macx:CONFIG -= app_bundle -TARGET = cplusplus0 - -include(../../../qtcreator.pri) -include(../../../src/libs/cplusplus/cplusplus.pri) - -# Input -SOURCES += main.cpp - -unix { - debug:OBJECTS_DIR = $${OUT_PWD}/.obj/debug-shared - release:OBJECTS_DIR = $${OUT_PWD}/.obj/release-shared - - debug:MOC_DIR = $${OUT_PWD}/.moc/debug-shared - release:MOC_DIR = $${OUT_PWD}/.moc/release-shared - - RCC_DIR = $${OUT_PWD}/.rcc/ - UI_DIR = $${OUT_PWD}/.uic/ -} diff --git a/tests/tools/tools.pro b/tests/tools/tools.pro index f8339cd1f8..f54f92d40c 100644 --- a/tests/tools/tools.pro +++ b/tests/tools/tools.pro @@ -1,5 +1,5 @@ TEMPLATE=subdirs SUBDIRS= \ -cplusplus-dump \ +cplusplus-ast2png \ qml-ast2dot |