2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-02-16 10:36:09 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-02-16 10:36:09 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-02-16 10:36:09 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2010-02-16 10:36:09 +01:00
|
|
|
|
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>
|
|
|
|
|
|
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-07 09:01:53 +01:00
|
|
|
~Check();
|
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
|
|
|
|
2014-10-14 10:10:58 +02:00
|
|
|
void enableQmlDesignerChecks();
|
|
|
|
|
void disableQmlDesignerChecks();
|
|
|
|
|
|
|
|
|
|
void enableQmlDesignerUiFileChecks();
|
|
|
|
|
void disableQmlDesignerUiFileChecks();
|
|
|
|
|
|
2010-02-16 10:36:09 +01:00
|
|
|
protected:
|
2015-06-03 15:34:13 +02:00
|
|
|
bool preVisit(AST::Node *ast) override;
|
|
|
|
|
void postVisit(AST::Node *ast) override;
|
|
|
|
|
|
|
|
|
|
bool visit(AST::UiProgram *ast) override;
|
|
|
|
|
bool visit(AST::UiObjectDefinition *ast) override;
|
|
|
|
|
bool visit(AST::UiObjectBinding *ast) override;
|
|
|
|
|
bool visit(AST::UiScriptBinding *ast) override;
|
|
|
|
|
bool visit(AST::UiArrayBinding *ast) override;
|
|
|
|
|
bool visit(AST::UiPublicMember *ast) override;
|
|
|
|
|
bool visit(AST::IdentifierExpression *ast) override;
|
|
|
|
|
bool visit(AST::FieldMemberExpression *ast) override;
|
|
|
|
|
bool visit(AST::FunctionDeclaration *ast) override;
|
|
|
|
|
bool visit(AST::FunctionExpression *ast) override;
|
|
|
|
|
bool visit(AST::UiObjectInitializer *) override;
|
|
|
|
|
|
|
|
|
|
bool visit(AST::BinaryExpression *ast) override;
|
|
|
|
|
bool visit(AST::Block *ast) override;
|
|
|
|
|
bool visit(AST::WithStatement *ast) override;
|
|
|
|
|
bool visit(AST::VoidExpression *ast) override;
|
|
|
|
|
bool visit(AST::Expression *ast) override;
|
|
|
|
|
bool visit(AST::ExpressionStatement *ast) override;
|
|
|
|
|
bool visit(AST::IfStatement *ast) override;
|
|
|
|
|
bool visit(AST::ForStatement *ast) override;
|
|
|
|
|
bool visit(AST::WhileStatement *ast) override;
|
|
|
|
|
bool visit(AST::DoWhileStatement *ast) override;
|
|
|
|
|
bool visit(AST::CaseBlock *ast) override;
|
|
|
|
|
bool visit(AST::NewExpression *ast) override;
|
|
|
|
|
bool visit(AST::NewMemberExpression *ast) override;
|
|
|
|
|
bool visit(AST::CallExpression *ast) override;
|
|
|
|
|
bool visit(AST::StatementList *ast) override;
|
|
|
|
|
bool visit(AST::ReturnStatement *ast) override;
|
|
|
|
|
bool visit(AST::ThrowStatement *ast) override;
|
|
|
|
|
bool visit(AST::DeleteExpression *ast) override;
|
|
|
|
|
bool visit(AST::TypeOfExpression *ast) override;
|
|
|
|
|
|
|
|
|
|
void endVisit(QmlJS::AST::UiObjectInitializer *) 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;
|
2014-10-13 16:46:30 +02:00
|
|
|
bool isQtQuick2Ui() const;
|
2013-11-13 17:20:01 +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
|
|
|
|
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
|