diff options
Diffstat (limited to 'src/declarative/qml/qmlscriptparser.cpp')
-rw-r--r-- | src/declarative/qml/qmlscriptparser.cpp | 104 |
1 files changed, 50 insertions, 54 deletions
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 8039b5c..618eb2e 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -65,10 +65,12 @@ protected: Object *defineObjectBinding(int line, AST::UiQualifiedId *propertyName, const QString &objectType, + AST::SourceLocation typeLocation, AST::UiObjectInitializer *initializer = 0); Object *defineObjectBinding_helper(int line, AST::UiQualifiedId *propertyName, const QString &objectType, + AST::SourceLocation typeLocation, AST::UiObjectInitializer *initializer = 0); QString getPrimitive(const QByteArray &propertyName, AST::ExpressionNode *expr); void defineProperty(const QString &propertyName, int line, const QString &primitive); @@ -194,11 +196,17 @@ QString ProcessAST::asString(AST::UiQualifiedId *node) const Object *ProcessAST::defineObjectBinding_helper(int line, AST::UiQualifiedId *propertyName, const QString &objectType, + AST::SourceLocation typeLocation, AST::UiObjectInitializer *initializer) { bool isType = !objectType.isEmpty() && objectType.at(0).isUpper() && !objectType.contains(QLatin1Char('.')); + if (!isType) { - qWarning() << "bad name for a class"; // ### FIXME + QmlError error; + error.setDescription("Expected type name"); + error.setLine(typeLocation.startLine); + error.setColumn(typeLocation.startColumn); + _parser->_errors << error; return false; } @@ -235,7 +243,7 @@ Object *ProcessAST::defineObjectBinding_helper(int line, if (!_parser->scriptFile().isEmpty()) { _stateStack.pushObject(obj); - Object *scriptObject= defineObjectBinding(line, 0, QLatin1String("Script")); + Object *scriptObject= defineObjectBinding(line, 0, QLatin1String("Script"), AST::SourceLocation()); _stateStack.pushObject(scriptObject); defineProperty(QLatin1String("src"), line, _parser->scriptFile()); _stateStack.pop(); // scriptObject @@ -264,11 +272,12 @@ Object *ProcessAST::defineObjectBinding_helper(int line, Object *ProcessAST::defineObjectBinding(int line, AST::UiQualifiedId *qualifiedId, const QString &objectType, + AST::SourceLocation typeLocation, AST::UiObjectInitializer *initializer) { if (objectType == QLatin1String("Connection")) { - Object *obj = defineObjectBinding_helper(line, 0, QLatin1String("Connection")); + Object *obj = defineObjectBinding_helper(line, 0, objectType, typeLocation); _stateStack.pushObject(obj); @@ -297,7 +306,7 @@ Object *ProcessAST::defineObjectBinding(int line, return obj; } - return defineObjectBinding_helper(line, qualifiedId, objectType, initializer); + return defineObjectBinding_helper(line, qualifiedId, objectType, typeLocation, initializer); } void ProcessAST::defineProperty(const QString &propertyName, int line, const QString &primitive) @@ -372,7 +381,11 @@ bool ProcessAST::visit(AST::UiPublicMember *node) } if(!typeFound) { - qWarning() << "Unknown property type" << memberType; // ### FIXME + QmlError error; + error.setDescription("Expected property type"); + error.setLine(node->typeToken.startLine); + error.setColumn(node->typeToken.startColumn); + _parser->_errors << error; return false; } @@ -402,6 +415,7 @@ bool ProcessAST::visit(AST::UiObjectDefinition *node) defineObjectBinding(node->identifierToken.startLine, 0, node->name->asString(), + node->identifierToken, node->initializer); return false; @@ -414,6 +428,7 @@ bool ProcessAST::visit(AST::UiObjectBinding *node) defineObjectBinding(node->identifierToken.startLine, node->qualifiedId, node->name->asString(), + node->identifierToken, node->initializer); return false; @@ -476,7 +491,8 @@ bool ProcessAST::visit(AST::UiScriptBinding *node) Value *v = new Value; v->primitive = primitive; - v->line = node->colonToken.startLine; + v->line = node->statement->firstSourceLocation().startLine; + v->column = node->statement->firstSourceLocation().startColumn; prop->addValue(v); while (propertyCount--) @@ -535,7 +551,7 @@ bool ProcessAST::visit(AST::UiSourceElement *node) QmlScriptParser::QmlScriptParser() - : root(0), _errorLine(-1) +: root(0) { } @@ -556,8 +572,11 @@ bool QmlScriptParser::parse(const QByteArray &data, const QUrl &url) return true; } - _error = xmlParser.errorDescription(); - _errorLine = 0; // ### FIXME + QmlError error; + error.setUrl(url); + error.setDescription(xmlParser.errorDescription()); + _errors << error; + return false; } @@ -576,61 +595,34 @@ bool QmlScriptParser::parse(const QByteArray &data, const QUrl &url) lexer.setCode(code, /*line = */ 1); driver.setLexer(&lexer); - if (! parser.parse(&driver)) { - _error = parser.errorMessage(); - _errorLine = parser.errorLineNumber(); - - const QStringList lines = code.split(QLatin1Char('\n')); + if (! parser.parse(&driver) || !_errors.isEmpty()) { + // Extract errors from the parser foreach (const JavaScriptParser::DiagnosticMessage &m, parser.diagnosticMessages()) { if (m.isWarning()) continue; - qWarning().nospace() << qPrintable(fileName) << ":" - << m.line << ":" - << m.column << ": " - << "error: " - << qPrintable(m.message); - - const QString textLine = lines.at(m.line - 1); - - qWarning() << qPrintable(textLine); + QmlError error; + error.setUrl(url); + error.setDescription(m.message); + error.setLine(m.line); + error.setColumn(m.column); + _errors << error; - int column = qMax(0, m.column - 1); - column = qMin(column, textLine.length()); // paranoia check - - QByteArray ind; - ind.reserve(column); - - for (int i = 0; i < column; ++i) { - const QChar ch = textLine.at(i); - if (ch.isSpace()) - ind.append(ch.unicode()); - else - ind.append(' '); - } - ind.append('^'); - qWarning() << ind.constData(); } - - return false; } - ProcessAST process(this); - process(code, parser.ast()); + if (_errors.isEmpty()) { + ProcessAST process(this); + process(code, parser.ast()); - return true; -} - -QString QmlScriptParser::errorDescription() const -{ - return _error; -} + // Set the url for process errors + for(int ii = 0; ii < _errors.count(); ++ii) + _errors[ii].setUrl(url); + } -int QmlScriptParser::errorLine() const -{ - return _errorLine; + return _errors.isEmpty(); } QMap<QString,QString> QmlScriptParser::nameSpacePaths() const @@ -648,6 +640,11 @@ Object *QmlScriptParser::tree() const return root; } +QList<QmlError> QmlScriptParser::errors() const +{ + return _errors; +} + void QmlScriptParser::clear() { if (root) { @@ -656,9 +653,8 @@ void QmlScriptParser::clear() } _nameSpacePaths.clear(); _typeNames.clear(); - _error.clear(); + _errors.clear(); _scriptFile.clear(); - _errorLine = 0; } int QmlScriptParser::findOrCreateTypeId(const QString &name) |