2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-03 11:37:35 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-03 11:37:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-03 11:37:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-03 11:37:35 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-03 11:34:46 +01:00
|
|
|
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <cplusplus/AST.h>
|
|
|
|
|
#include <cplusplus/ASTMatcher.h>
|
|
|
|
|
#include <cplusplus/ASTPatternBuilder.h>
|
|
|
|
|
#include <cplusplus/ASTVisitor.h>
|
|
|
|
|
#include <cplusplus/Control.h>
|
|
|
|
|
#include <cplusplus/CoreTypes.h>
|
|
|
|
|
#include <cplusplus/CppDocument.h>
|
|
|
|
|
#include <cplusplus/Literals.h>
|
|
|
|
|
#include <cplusplus/Names.h>
|
|
|
|
|
#include <cplusplus/Scope.h>
|
|
|
|
|
#include <cplusplus/Symbols.h>
|
|
|
|
|
#include <cplusplus/TranslationUnit.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2012-10-29 13:54:33 +01:00
|
|
|
#include "cplusplus-tools-utils.h"
|
|
|
|
|
|
2009-01-06 15:15:13 +01:00
|
|
|
#include <QFile>
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QFileInfo>
|
2009-06-05 13:16:36 +02:00
|
|
|
#include <QTime>
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2008-12-03 11:34:46 +01:00
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdlib>
|
2009-01-06 15:15:13 +01:00
|
|
|
#include <iostream>
|
2008-12-03 11:34:46 +01:00
|
|
|
|
2009-10-21 14:56:42 +02:00
|
|
|
using namespace CPlusPlus;
|
2009-01-02 16:10:28 +01:00
|
|
|
|
2012-10-29 13:54:33 +01:00
|
|
|
void printUsage()
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Usage: " << qPrintable(QFileInfo(qApp->arguments().at(0)).fileName())
|
|
|
|
|
<< " [-v] <file1> <file2> ...\n\n"
|
|
|
|
|
<< "Run the parser with the given files.\n";
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-13 12:36:51 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
QCoreApplication app(argc, argv);
|
2012-10-29 13:54:33 +01:00
|
|
|
QStringList args = app.arguments();
|
|
|
|
|
args.removeFirst();
|
2009-11-13 12:36:51 +01:00
|
|
|
|
2012-10-29 13:54:33 +01:00
|
|
|
bool optionVerbose = false;
|
|
|
|
|
|
|
|
|
|
// Process options & arguments
|
2013-01-15 19:24:25 +01:00
|
|
|
if (args.contains(QLatin1String("-v"))) {
|
2012-10-29 13:54:33 +01:00
|
|
|
optionVerbose = true;
|
2013-01-15 19:24:25 +01:00
|
|
|
args.removeOne(QLatin1String("-v"));
|
2012-10-29 13:54:33 +01:00
|
|
|
}
|
2013-01-15 19:24:25 +01:00
|
|
|
const bool helpRequested = args.contains(QLatin1String("-h")) || args.contains(QLatin1String("-help"));
|
2012-10-29 13:54:33 +01:00
|
|
|
if (args.isEmpty() || helpRequested) {
|
|
|
|
|
printUsage();
|
|
|
|
|
return helpRequested ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
|
}
|
2009-11-13 12:36:51 +01:00
|
|
|
|
2012-10-29 13:54:33 +01:00
|
|
|
// Process files
|
|
|
|
|
const QStringList files = args;
|
2009-11-13 12:36:51 +01:00
|
|
|
foreach (const QString &fileName, files) {
|
2012-10-29 13:54:33 +01:00
|
|
|
// Run preprocessor
|
|
|
|
|
const QString fileNamePreprocessed = fileName + QLatin1String(".preprocessed");
|
|
|
|
|
CplusplusToolsUtils::SystemPreprocessor preprocessor(optionVerbose);
|
|
|
|
|
preprocessor.preprocessFile(fileName, fileNamePreprocessed);
|
2009-11-13 12:36:51 +01:00
|
|
|
|
2012-10-29 13:54:33 +01:00
|
|
|
// Run parser
|
|
|
|
|
QFile file(fileNamePreprocessed);
|
|
|
|
|
if (! file.open(QFile::ReadOnly)) {
|
|
|
|
|
std::cerr << "Error: Could not open file \"" << qPrintable(file.fileName()) << "\"."
|
|
|
|
|
<< std::endl;
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
2009-11-13 12:36:51 +01:00
|
|
|
const QByteArray source = file.readAll();
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
|
|
Document::Ptr doc = Document::create(fileName);
|
|
|
|
|
doc->control()->setDiagnosticClient(0);
|
2012-02-09 13:17:13 +01:00
|
|
|
doc->setUtf8Source(source);
|
2009-11-13 12:36:51 +01:00
|
|
|
doc->parse();
|
2008-12-03 11:34:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}
|