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

114 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>
#include <CppDocument.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-10-21 14:56:42 +02:00
using namespace CPlusPlus;
2009-01-02 16:10:28 +01:00
class ForEachBinaryExpression: protected ASTVisitor
2009-01-02 16:10:28 +01:00
{
Document::Ptr doc;
Document::Ptr pattern;
2009-01-06 15:15:13 +01:00
public:
ForEachBinaryExpression(Document::Ptr doc, Document::Ptr pattern)
: ASTVisitor(doc->control()), doc(doc), pattern(pattern) {}
2009-01-06 15:15:13 +01:00
void operator()() { accept(doc->translationUnit()->ast()); }
2009-01-06 15:15:13 +01:00
protected:
using ASTVisitor::visit;
2009-10-21 14:56:42 +02:00
virtual bool visit(BinaryExpressionAST *ast)
{
ASTMatcher matcher(doc->translationUnit(), pattern->translationUnit());
if (ast->match(ast, pattern->translationUnit()->ast(), &matcher)) {
translationUnit()->warning(ast->binary_op_token, "binary expression");
2009-01-06 15:15:13 +01:00
}
return true;
2009-01-06 15:15:13 +01:00
}
};
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QStringList files = app.arguments();
files.removeFirst();
Document::Ptr pattern = Document::create("<pattern>");
pattern->setSource("__y < __x");
pattern->parse(Document::ParseExpression);
foreach (const QString &fileName, files) {
QFile file(fileName);
if (! file.open(QFile::ReadOnly))
continue;
const QByteArray source = file.readAll();
file.close();
Document::Ptr doc = Document::create(fileName);
doc->control()->setDiagnosticClient(0);
doc->setSource(source);
doc->parse();
ForEachBinaryExpression forEachBinaryExpression(doc, pattern);
2009-01-06 15:15:13 +01:00
forEachBinaryExpression();
}
return EXIT_SUCCESS;
}