2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-02-16 10:36:09 +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
|
2010-02-16 10:36:09 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-02-16 10:36:09 +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.
|
2010-02-16 10:36:09 +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
|
|
|
****************************************************************************/
|
2010-02-16 10:36:09 +01:00
|
|
|
|
|
|
|
|
#ifndef QMLJSCHECK_H
|
|
|
|
|
#define QMLJSCHECK_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>
|
2014-02-05 13:07:46 +01:00
|
|
|
#include <utils/qtcoverride.h>
|
2010-02-16 10:36:09 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QSet>
|
|
|
|
|
#include <QStack>
|
2010-05-19 13:32:11 +02:00
|
|
|
|
2010-02-16 10:36:09 +01:00
|
|
|
namespace QmlJS {
|
|
|
|
|
|
2013-11-13 17:20:01 +01:00
|
|
|
class Imports;
|
|
|
|
|
|
2010-02-16 10:36:09 +01:00
|
|
|
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);
|
2014-02-05 13:07:46 +01:00
|
|
|
~Check() QTC_OVERRIDE;
|
2010-02-16 10:36:09 +01:00
|
|
|
|
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:
|
2014-02-05 13:07:46 +01:00
|
|
|
bool preVisit(AST::Node *ast) QTC_OVERRIDE;
|
|
|
|
|
void postVisit(AST::Node *ast) QTC_OVERRIDE;
|
|
|
|
|
|
|
|
|
|
bool visit(AST::UiProgram *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiObjectDefinition *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiObjectBinding *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiScriptBinding *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiArrayBinding *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiPublicMember *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::IdentifierExpression *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::FieldMemberExpression *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::FunctionDeclaration *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::FunctionExpression *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiObjectInitializer *) QTC_OVERRIDE;
|
|
|
|
|
|
|
|
|
|
bool visit(AST::BinaryExpression *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::Block *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::WithStatement *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::VoidExpression *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::Expression *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::ExpressionStatement *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::IfStatement *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::ForStatement *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::LocalForStatement *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::WhileStatement *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::DoWhileStatement *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::CaseBlock *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::NewExpression *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::NewMemberExpression *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::CallExpression *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::StatementList *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::ReturnStatement *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::ThrowStatement *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::DeleteExpression *ast) QTC_OVERRIDE;
|
|
|
|
|
bool visit(AST::TypeOfExpression *ast) QTC_OVERRIDE;
|
|
|
|
|
|
|
|
|
|
void endVisit(QmlJS::AST::UiObjectInitializer *) QTC_OVERRIDE;
|
2010-12-07 17:31:53 +01:00
|
|
|
|
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);
|
2011-11-28 14:58:01 +01:00
|
|
|
void checkCaseFallthrough(AST::StatementList *statements, AST::SourceLocation errorLoc, AST::SourceLocation nextLoc);
|
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
|
|
|
|
2011-10-20 09:45:29 +02:00
|
|
|
void scanCommentsForAnnotations();
|
|
|
|
|
void warnAboutUnnecessarySuppressions();
|
|
|
|
|
|
2013-11-13 17:20:01 +01:00
|
|
|
bool isQtQuick2() const;
|
|
|
|
|
|
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
|
|
|
|
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;
|
2012-09-17 14:06:03 +02:00
|
|
|
QStack<QString> m_typeStack;
|
2011-09-29 11:48:13 +02:00
|
|
|
|
2011-10-20 09:45:29 +02:00
|
|
|
class MessageTypeAndSuppression
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AST::SourceLocation suppressionSource;
|
|
|
|
|
StaticAnalysis::Type type;
|
|
|
|
|
bool wasSuppressed;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QHash< int, QList<MessageTypeAndSuppression> > m_disabledMessageTypesByLine;
|
|
|
|
|
|
2011-09-29 11:48:13 +02:00
|
|
|
bool _importsOk;
|
2011-12-02 10:41:13 +01:00
|
|
|
bool _inStatementBinding;
|
2013-11-13 17:20:01 +01:00
|
|
|
const Imports *_imports;
|
|
|
|
|
bool _isQtQuick2;
|
2010-02-16 10:36:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace QmlJS
|
|
|
|
|
|
|
|
|
|
#endif // QMLJSCHECK_H
|