forked from qt-creator/qt-creator
QmlJS checks: Fix collection of use-before-declaration warnings.
Previously they would not be collected if the var had a duplicate-declaration warning. Change-Id: I82244e911fcdfc3d11cc391288da263ee288a3ca Reviewed-on: http://codereview.qt-project.org/4330 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
@@ -243,7 +243,7 @@ public:
|
|||||||
ExpressionNode *_ast;
|
ExpressionNode *_ast;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FunctionBodyCheck : protected Visitor
|
class DeclarationsCheck : protected Visitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QList<DiagnosticMessage> operator()(FunctionExpression *function, Check::Options options)
|
QList<DiagnosticMessage> operator()(FunctionExpression *function, Check::Options options)
|
||||||
@@ -310,20 +310,14 @@ protected:
|
|||||||
return true;
|
return true;
|
||||||
const QString name = ast->name->asString();
|
const QString name = ast->name->asString();
|
||||||
|
|
||||||
|
if (_options & Check::WarnDuplicateDeclaration) {
|
||||||
if (_formalParameterNames.contains(name)) {
|
if (_formalParameterNames.contains(name)) {
|
||||||
if (_options & Check::WarnDuplicateDeclaration)
|
|
||||||
warning(ast->identifierToken, Check::tr("already a formal parameter"));
|
warning(ast->identifierToken, Check::tr("already a formal parameter"));
|
||||||
return true;
|
} else if (_declaredFunctions.contains(name)) {
|
||||||
}
|
|
||||||
if (_declaredFunctions.contains(name)) {
|
|
||||||
if (_options & Check::WarnDuplicateDeclaration)
|
|
||||||
warning(ast->identifierToken, Check::tr("already declared as function"));
|
warning(ast->identifierToken, Check::tr("already declared as function"));
|
||||||
return true;
|
} else if (_declaredVariables.contains(name)) {
|
||||||
}
|
|
||||||
if (_declaredVariables.contains(name)) {
|
|
||||||
if (_options & Check::WarnDuplicateDeclaration)
|
|
||||||
warning(ast->identifierToken, Check::tr("duplicate declaration"));
|
warning(ast->identifierToken, Check::tr("duplicate declaration"));
|
||||||
return true;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_possiblyUndeclaredUses.contains(name)) {
|
if (_possiblyUndeclaredUses.contains(name)) {
|
||||||
@@ -354,20 +348,14 @@ protected:
|
|||||||
return false;
|
return false;
|
||||||
const QString name = ast->name->asString();
|
const QString name = ast->name->asString();
|
||||||
|
|
||||||
|
if (_options & Check::WarnDuplicateDeclaration) {
|
||||||
if (_formalParameterNames.contains(name)) {
|
if (_formalParameterNames.contains(name)) {
|
||||||
if (_options & Check::WarnDuplicateDeclaration)
|
|
||||||
warning(ast->identifierToken, Check::tr("already a formal parameter"));
|
warning(ast->identifierToken, Check::tr("already a formal parameter"));
|
||||||
return false;
|
} else if (_declaredVariables.contains(name)) {
|
||||||
}
|
|
||||||
if (_declaredVariables.contains(name)) {
|
|
||||||
if (_options & Check::WarnDuplicateDeclaration)
|
|
||||||
warning(ast->identifierToken, Check::tr("already declared as var"));
|
warning(ast->identifierToken, Check::tr("already declared as var"));
|
||||||
return false;
|
} else if (_declaredFunctions.contains(name)) {
|
||||||
}
|
|
||||||
if (_declaredFunctions.contains(name)) {
|
|
||||||
if (_options & Check::WarnDuplicateDeclaration)
|
|
||||||
warning(ast->identifierToken, Check::tr("duplicate declaration"));
|
warning(ast->identifierToken, Check::tr("duplicate declaration"));
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FunctionDeclaration *decl = cast<FunctionDeclaration *>(ast)) {
|
if (FunctionDeclaration *decl = cast<FunctionDeclaration *>(ast)) {
|
||||||
@@ -614,7 +602,7 @@ bool Check::visit(UiScriptBinding *ast)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Block *block = cast<Block *>(ast->statement)) {
|
if (Block *block = cast<Block *>(ast->statement)) {
|
||||||
FunctionBodyCheck bodyCheck;
|
DeclarationsCheck bodyCheck;
|
||||||
_messages.append(bodyCheck(block->statements, _options));
|
_messages.append(bodyCheck(block->statements, _options));
|
||||||
Node::accept(ast->qualifiedId, this);
|
Node::accept(ast->qualifiedId, this);
|
||||||
_scopeBuilder.push(ast);
|
_scopeBuilder.push(ast);
|
||||||
@@ -697,7 +685,7 @@ bool Check::visit(FunctionDeclaration *ast)
|
|||||||
|
|
||||||
bool Check::visit(FunctionExpression *ast)
|
bool Check::visit(FunctionExpression *ast)
|
||||||
{
|
{
|
||||||
FunctionBodyCheck bodyCheck;
|
DeclarationsCheck bodyCheck;
|
||||||
_messages.append(bodyCheck(ast, _options));
|
_messages.append(bodyCheck(ast, _options));
|
||||||
|
|
||||||
Node::accept(ast->formals, this);
|
Node::accept(ast->formals, this);
|
||||||
|
Reference in New Issue
Block a user