Files
qt-creator/tests/manual/cplusplus/main.cpp

105 lines
3.1 KiB
C++
Raw Normal View History

/**************************************************************************
2008-12-03 11:37:35 +01:00
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2008-12-03 11:37:35 +01:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
2008-12-03 11:37:35 +01:00
**
** Commercial Usage
2008-12-03 11:37:35 +01:00
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
2008-12-03 11:37:35 +01:00
**
** GNU Lesser General Public License Usage
2008-12-03 11:37:35 +01: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.
2008-12-03 11:37:35 +01:00
**
** If you are unsure which license is appropriate for your use, please
2009-08-14 09:30:56 +02:00
** contact the sales department at http://qt.nokia.com/contact.
2008-12-03 11:37:35 +01:00
**
**************************************************************************/
2008-12-09 15:25:01 +01:00
#include <AST.h>
2009-01-02 16:10:28 +01:00
#include <ASTVisitor.h>
2009-11-13 12:13:49 +01:00
#include <ASTMatcher.h>
2008-12-09 15:25:01 +01:00
#include <Control.h>
#include <Scope.h>
#include <Semantic.h>
#include <TranslationUnit.h>
#include <Literals.h>
#include <Symbols.h>
#include <Names.h>
#include <CoreTypes.h>
2008-12-09 15:25:01 +01:00
2009-01-06 15:15:13 +01:00
#include <QFile>
#include <QList>
#include <QCoreApplication>
#include <QStringList>
#include <QFileInfo>
#include <QTime>
2009-01-02 16:10:28 +01:00
#include <QtDebug>
#include <cstdio>
#include <cstdlib>
2009-01-06 15:15:13 +01:00
#include <iostream>
2009-01-06 15:23:59 +01:00
#include <sstream>
2009-10-21 14:56:42 +02:00
using namespace CPlusPlus;
2009-01-02 16:10:28 +01:00
2009-01-06 15:15:13 +01:00
int main(int argc, char *argv[])
2009-01-02 16:10:28 +01:00
{
2009-01-06 15:15:13 +01:00
QCoreApplication app(argc, argv);
QStringList args = app.arguments();
const QString appName = args.first();
args.removeFirst();
2009-10-21 14:56:42 +02:00
foreach (const QString &arg, args) {
if (arg == QLatin1String("--help")) {
2009-01-06 15:15:13 +01:00
const QFileInfo appInfo(appName);
const QByteArray appFileName = QFile::encodeName(appInfo.fileName());
printf("Usage: %s [options]\n"
" --help Display this information\n",
2009-01-06 15:15:13 +01:00
appFileName.constData());
2009-10-21 14:56:42 +02:00
2009-01-06 15:15:13 +01:00
return EXIT_SUCCESS;
}
}
QFile in;
if (! in.open(stdin, QFile::ReadOnly))
return EXIT_FAILURE;
const QByteArray source = in.readAll();
2009-01-02 16:10:28 +01:00
Control control;
2009-06-17 14:14:16 +02:00
StringLiteral *fileId = control.findOrInsertStringLiteral("<stdin>");
TranslationUnit unit(&control, fileId);
2009-01-12 14:55:33 +01:00
unit.setObjCEnabled(true);
unit.setSource(source.constData(), source.size());
unit.parse();
2009-01-02 16:10:28 +01:00
if (! unit.ast())
return EXIT_FAILURE;
TranslationUnitAST *ast = unit.ast()->asTranslationUnit();
Q_ASSERT(ast != 0);
Namespace *globalNamespace = control.newNamespace(0, 0);
2009-01-02 16:10:28 +01:00
Semantic sem(&control);
2009-11-13 12:13:49 +01:00
for (DeclarationListAST *it = ast->declaration_list; it; it = it->next) {
2009-11-10 16:19:52 +01:00
DeclarationAST *declaration = it->value;
sem.check(declaration, globalNamespace->members());
}
return EXIT_SUCCESS;
}