summaryrefslogtreecommitdiff
path: root/src/qml/compiler/qv4codegen.cpp
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-08-02 16:50:27 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2021-08-04 17:15:22 +0200
commitef075016527c48f6ec64c088edb400ab52211d75 (patch)
tree7f33ce9b18ae1ef22cc00c2b8d7c43f45885e277 /src/qml/compiler/qv4codegen.cpp
parent283816d07dee9afaa9fa183b9102076f32568449 (diff)
downloadqtdeclarative-ef075016527c48f6ec64c088edb400ab52211d75.tar.gz
qmllint: Move use-before-declaration warning out of checkidentifiers
Another step to making checkidentifiers obsolete. Change-Id: I14be7491387200101b66e0930faf16e9b61d4159 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r--src/qml/compiler/qv4codegen.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index e57b0a27dd..33b440e62c 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -75,6 +75,16 @@ using namespace QV4::Compiler;
using namespace QQmlJS;
using namespace QQmlJS::AST;
+void CodegenWarningInterface::reportVarUsedBeforeDeclaration(
+ const QString &name, const QString &fileName, QQmlJS::SourceLocation declarationLocation,
+ QQmlJS::SourceLocation accessLocation)
+{
+ qCWarning(lcQmlCompiler).nospace().noquote()
+ << fileName << ":" << accessLocation.startLine << ":" << accessLocation.startColumn
+ << " Variable \"" << name << "\" is used before its declaration at "
+ << declarationLocation.startLine << ":" << declarationLocation.startColumn << ".";
+}
+
static inline void setJumpOutLocation(QV4::Moth::BytecodeGenerator *bytecodeGenerator,
const Statement *body, const SourceLocation &fallback)
{
@@ -94,14 +104,16 @@ static inline void setJumpOutLocation(QV4::Moth::BytecodeGenerator *bytecodeGene
}
}
-Codegen::Codegen(QV4::Compiler::JSUnitGenerator *jsUnitGenerator, bool strict)
- : _module(nullptr)
- , _returnAddress(-1)
- , _context(nullptr)
- , _labelledStatement(nullptr)
- , jsUnitGenerator(jsUnitGenerator)
- , _strictMode(strict)
- , _fileNameIsUrl(false)
+Codegen::Codegen(QV4::Compiler::JSUnitGenerator *jsUnitGenerator, bool strict,
+ CodegenWarningInterface *interface)
+ : _module(nullptr),
+ _returnAddress(-1),
+ _context(nullptr),
+ _labelledStatement(nullptr),
+ jsUnitGenerator(jsUnitGenerator),
+ _strictMode(strict),
+ _fileNameIsUrl(false),
+ _interface(interface)
{
jsUnitGenerator->codeGeneratorName = QStringLiteral("moth");
pushExpr();
@@ -2598,12 +2610,9 @@ Codegen::Reference Codegen::referenceForName(const QString &name, bool isLhs, co
if (resolved.declarationLocation.isValid() && accessLocation.isValid()
&& resolved.declarationLocation.begin() > accessLocation.end()) {
- qCWarning(lcQmlCompiler).nospace().noquote()
- << url().toString() << ":" << accessLocation.startLine
- << ":" << accessLocation.startColumn << " Variable \"" << name
- << "\" is used before its declaration at "
- << resolved.declarationLocation.startLine << ":"
- << resolved.declarationLocation.startColumn << ".";
+ Q_ASSERT(_interface);
+ _interface->reportVarUsedBeforeDeclaration(
+ name, url().toLocalFile(), resolved.declarationLocation, accessLocation);
}
if (resolved.isInjected && accessLocation.isValid()) {