2010-02-16 10:36:09 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-02-16 10:36:09 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-02-16 10:36:09 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-02-16 10:36:09 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2010-02-16 10:36:09 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef QMLJSCHECK_H
|
|
|
|
|
#define QMLJSCHECK_H
|
|
|
|
|
|
|
|
|
|
#include <qmljs/qmljsdocument.h>
|
2011-07-01 13:51:53 +02:00
|
|
|
#include <qmljs/qmljscontext.h>
|
2010-02-19 15:55:11 +01:00
|
|
|
#include <qmljs/qmljsscopebuilder.h>
|
2011-07-12 14:55:27 +02:00
|
|
|
#include <qmljs/qmljsscopechain.h>
|
2011-09-28 15:16:00 +02:00
|
|
|
#include <qmljs/qmljsstaticanalysismessage.h>
|
2010-02-16 10:36:09 +01:00
|
|
|
#include <qmljs/parser/qmljsastvisitor_p.h>
|
|
|
|
|
|
2010-05-19 13:32:11 +02:00
|
|
|
#include <QtCore/QCoreApplication>
|
2010-12-07 17:31:53 +01:00
|
|
|
#include <QtCore/QSet>
|
|
|
|
|
#include <QtCore/QStack>
|
2010-07-29 11:20:06 +02:00
|
|
|
#include <QtGui/QColor>
|
2010-05-19 13:32:11 +02:00
|
|
|
|
2010-02-16 10:36:09 +01:00
|
|
|
namespace QmlJS {
|
|
|
|
|
|
|
|
|
|
class QMLJS_EXPORT Check: protected AST::Visitor
|
|
|
|
|
{
|
2010-05-19 13:42:56 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(QmlJS::Check)
|
|
|
|
|
|
2010-12-07 17:31:53 +01:00
|
|
|
typedef QSet<QString> StringSet;
|
|
|
|
|
|
2010-02-16 10:36:09 +01:00
|
|
|
public:
|
2011-07-12 14:55:27 +02:00
|
|
|
// prefer taking root scope chain?
|
2011-08-08 12:47:49 +02:00
|
|
|
Check(Document::Ptr doc, const ContextPtr &context);
|
2010-02-16 10:36:09 +01:00
|
|
|
virtual ~Check();
|
|
|
|
|
|
2011-09-28 15:16:00 +02:00
|
|
|
QList<StaticAnalysis::Message> operator()();
|
|
|
|
|
|
|
|
|
|
void enableMessage(StaticAnalysis::Type type);
|
|
|
|
|
void disableMessage(StaticAnalysis::Type type);
|
2011-03-01 14:36:09 +01:00
|
|
|
|
2010-02-16 10:36:09 +01:00
|
|
|
protected:
|
2010-11-25 13:38:15 +01:00
|
|
|
virtual bool preVisit(AST::Node *ast);
|
|
|
|
|
virtual void postVisit(AST::Node *ast);
|
|
|
|
|
|
2010-02-16 10:36:09 +01:00
|
|
|
virtual bool visit(AST::UiProgram *ast);
|
|
|
|
|
virtual bool visit(AST::UiObjectDefinition *ast);
|
|
|
|
|
virtual bool visit(AST::UiObjectBinding *ast);
|
|
|
|
|
virtual bool visit(AST::UiScriptBinding *ast);
|
|
|
|
|
virtual bool visit(AST::UiArrayBinding *ast);
|
2011-09-05 15:37:14 +02:00
|
|
|
virtual bool visit(AST::UiPublicMember *ast);
|
2010-11-24 15:12:11 +01:00
|
|
|
virtual bool visit(AST::IdentifierExpression *ast);
|
|
|
|
|
virtual bool visit(AST::FieldMemberExpression *ast);
|
|
|
|
|
virtual bool visit(AST::FunctionDeclaration *ast);
|
|
|
|
|
virtual bool visit(AST::FunctionExpression *ast);
|
2010-12-07 17:31:53 +01:00
|
|
|
virtual bool visit(AST::UiObjectInitializer *);
|
2010-02-16 10:36:09 +01:00
|
|
|
|
2010-11-25 13:38:15 +01:00
|
|
|
virtual bool visit(AST::BinaryExpression *ast);
|
|
|
|
|
virtual bool visit(AST::Block *ast);
|
|
|
|
|
virtual bool visit(AST::WithStatement *ast);
|
|
|
|
|
virtual bool visit(AST::VoidExpression *ast);
|
|
|
|
|
virtual bool visit(AST::Expression *ast);
|
|
|
|
|
virtual bool visit(AST::ExpressionStatement *ast);
|
|
|
|
|
virtual bool visit(AST::IfStatement *ast);
|
|
|
|
|
virtual bool visit(AST::ForStatement *ast);
|
2010-12-06 09:54:10 +01:00
|
|
|
virtual bool visit(AST::LocalForStatement *ast);
|
2010-11-25 13:38:15 +01:00
|
|
|
virtual bool visit(AST::WhileStatement *ast);
|
|
|
|
|
virtual bool visit(AST::DoWhileStatement *ast);
|
|
|
|
|
virtual bool visit(AST::CaseClause *ast);
|
|
|
|
|
virtual bool visit(AST::DefaultClause *ast);
|
2011-09-06 12:59:30 +02:00
|
|
|
virtual bool visit(AST::NewExpression *ast);
|
|
|
|
|
virtual bool visit(AST::NewMemberExpression *ast);
|
|
|
|
|
virtual bool visit(AST::CallExpression *ast);
|
2011-09-30 12:11:58 +02:00
|
|
|
virtual bool visit(AST::StatementList *ast);
|
2011-10-04 09:49:30 +02:00
|
|
|
virtual bool visit(AST::ReturnStatement *ast);
|
|
|
|
|
virtual bool visit(AST::ThrowStatement *ast);
|
|
|
|
|
virtual bool visit(AST::DeleteExpression *ast);
|
|
|
|
|
virtual bool visit(AST::TypeOfExpression *ast);
|
2010-11-25 13:38:15 +01:00
|
|
|
|
2010-12-07 17:31:53 +01:00
|
|
|
virtual void endVisit(QmlJS::AST::UiObjectInitializer *);
|
|
|
|
|
|
2010-02-16 10:36:09 +01:00
|
|
|
private:
|
2010-02-16 13:28:43 +01:00
|
|
|
void visitQmlObject(AST::Node *ast, AST::UiQualifiedId *typeId,
|
|
|
|
|
AST::UiObjectInitializer *initializer);
|
2011-08-08 12:47:49 +02:00
|
|
|
const Value *checkScopeObjectMember(const AST::UiQualifiedId *id);
|
2010-11-25 13:38:15 +01:00
|
|
|
void checkAssignInCondition(AST::ExpressionNode *condition);
|
|
|
|
|
void checkEndsWithControlFlow(AST::StatementList *statements, AST::SourceLocation errorLoc);
|
2010-12-07 17:31:53 +01:00
|
|
|
void checkProperty(QmlJS::AST::UiQualifiedId *);
|
2011-09-06 12:59:30 +02:00
|
|
|
void checkNewExpression(AST::ExpressionNode *node);
|
2011-09-07 07:21:38 +02:00
|
|
|
void checkBindingRhs(AST::Statement *statement);
|
2011-10-04 09:49:30 +02:00
|
|
|
void checkExtraParentheses(AST::ExpressionNode *expression);
|
2010-02-16 10:36:09 +01:00
|
|
|
|
2011-09-28 15:16:00 +02:00
|
|
|
void addMessages(const QList<StaticAnalysis::Message> &messages);
|
|
|
|
|
void addMessage(const StaticAnalysis::Message &message);
|
|
|
|
|
void addMessage(StaticAnalysis::Type type, const AST::SourceLocation &location,
|
|
|
|
|
const QString &arg1 = QString(), const QString &arg2 = QString());
|
2010-02-16 10:36:09 +01:00
|
|
|
|
2010-11-25 13:38:15 +01:00
|
|
|
AST::Node *parent(int distance = 0);
|
|
|
|
|
|
2010-02-16 10:36:09 +01:00
|
|
|
Document::Ptr _doc;
|
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
ContextPtr _context;
|
|
|
|
|
ScopeChain _scopeChain;
|
2010-02-19 15:55:11 +01:00
|
|
|
ScopeBuilder _scopeBuilder;
|
2010-02-16 10:36:09 +01:00
|
|
|
|
2011-09-28 15:16:00 +02:00
|
|
|
QList<StaticAnalysis::Message> _messages;
|
|
|
|
|
QSet<StaticAnalysis::Type> _enabledMessages;
|
2010-11-24 15:12:11 +01:00
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
const Value *_lastValue;
|
2010-11-25 13:38:15 +01:00
|
|
|
QList<AST::Node *> _chain;
|
2010-12-13 16:46:29 +01:00
|
|
|
QStack<StringSet> m_idStack;
|
2010-12-07 17:31:53 +01:00
|
|
|
QStack<StringSet> m_propertyStack;
|
2011-09-29 11:48:13 +02:00
|
|
|
|
|
|
|
|
bool _importsOk;
|
2010-02-16 10:36:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace QmlJS
|
|
|
|
|
|
|
|
|
|
#endif // QMLJSCHECK_H
|