diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2009-05-06 13:46:12 (GMT) |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2009-05-06 13:46:12 (GMT) |
commit | 775eceeceac1e0607ff3f41d0ef490488297a400 (patch) | |
tree | 1603f822450bfdea2de9517b655537b528b507be /src/declarative/qml/parser | |
parent | 4b4c852c2e5c360f19d1656ba4ac077764931ac1 (diff) | |
download | Qt-775eceeceac1e0607ff3f41d0ef490488297a400.zip Qt-775eceeceac1e0607ff3f41d0ef490488297a400.tar.gz Qt-775eceeceac1e0607ff3f41d0ef490488297a400.tar.bz2 |
Use source locations in the diagnostic messages.
Diffstat (limited to 'src/declarative/qml/parser')
-rw-r--r-- | src/declarative/qml/parser/javascript.g | 43 | ||||
-rw-r--r-- | src/declarative/qml/parser/javascriptparser.cpp | 28 | ||||
-rw-r--r-- | src/declarative/qml/parser/javascriptparser_p.h | 13 |
3 files changed, 32 insertions, 52 deletions
diff --git a/src/declarative/qml/parser/javascript.g b/src/declarative/qml/parser/javascript.g index fe2077d..d66266f 100644 --- a/src/declarative/qml/parser/javascript.g +++ b/src/declarative/qml/parser/javascript.g @@ -264,10 +264,10 @@ public: enum Kind { Warning, Error }; DiagnosticMessage() - : kind(Error), line(0), column(0) {} + : kind(Error) {} - DiagnosticMessage(Kind kind, int line, int column, const QString &message) - : kind(kind), line(line), column(column), message(message) {} + DiagnosticMessage(Kind kind, const JavaScript::AST::SourceLocation &loc, const QString &message) + : kind(kind), loc(loc), message(message) {} bool isWarning() const { return kind == Warning; } @@ -276,8 +276,7 @@ public: { return kind == Error; } Kind kind; - int line; - int column; + JavaScript::AST::SourceLocation loc; QString message; }; @@ -307,10 +306,10 @@ public: { return diagnosticMessage().message; } inline int errorLineNumber() const - { return diagnosticMessage().line; } + { return diagnosticMessage().loc.startLine; } inline int errorColumnNumber() const - { return diagnosticMessage().column; } + { return diagnosticMessage().loc.startColumn; } protected: void reallocateStack(); @@ -873,9 +872,8 @@ PrimaryExpression: T_DIVIDE_ ; case $rule_number: { bool rx = lexer->scanRegExp(Lexer::NoPrefix); if (!rx) { - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, lexer->startLineNo(), - lexer->startColumnNo(), lexer->errorMessage())); - return false; + diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, location(lexer), lexer->errorMessage())); + return false; // ### remove me } AST::RegExpLiteral *node = makeAstNode<AST::RegExpLiteral> (driver->nodePool(), lexer->pattern, lexer->flags); node->literalToken = loc(1); @@ -891,9 +889,8 @@ PrimaryExpression: T_DIVIDE_EQ ; case $rule_number: { bool rx = lexer->scanRegExp(Lexer::EqualPrefix); if (!rx) { - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, lexer->startLineNo(), - lexer->startColumnNo(), lexer->errorMessage())); - return false; + diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, location(lexer), lexer->errorMessage())); + return false; } AST::RegExpLiteral *node = makeAstNode<AST::RegExpLiteral> (driver->nodePool(), lexer->pattern, lexer->flags); node->literalToken = loc(1); @@ -2703,10 +2700,8 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ; yylloc.startColumn += yylloc.length; yylloc.length = 0; - const QString msg = QString::fromUtf8("Missing `;'"); - - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning, - yylloc.startLine, yylloc.startColumn, msg)); + //const QString msg = QString::fromUtf8("Missing `;'"); + //diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning, yylloc, msg)); first_token = &token_buffer[0]; last_token = &token_buffer[1]; @@ -2731,9 +2726,7 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ; if (t_action(errorState, yytoken)) { const QString msg = QString::fromUtf8("Unexpected token `%1'").arg(QLatin1String(spell[token_buffer[0].token])); - - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, - token_buffer[0].loc.startLine, token_buffer[0].loc.startColumn, msg)); + diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg)); action = errorState; goto _Lcheck_token; @@ -2761,9 +2754,7 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ; int a = t_action(errorState, *tk); if (a > 0 && t_action(a, yytoken)) { const QString msg = QString::fromUtf8("Expected token `%1'").arg(QLatin1String(spell[*tk])); - - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, - token_buffer[0].loc.startLine, token_buffer[0].loc.startColumn, msg)); + diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg)); yytoken = *tk; yylval = 0; @@ -2785,8 +2776,7 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ; int a = t_action(errorState, tk); if (a > 0 && t_action(a, yytoken)) { const QString msg = QString::fromUtf8("Expected token `%1'").arg(QLatin1String(spell[tk])); - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, - token_buffer[0].loc.startLine, token_buffer[0].loc.startColumn, msg)); + diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg)); yytoken = tk; yylval = 0; @@ -2799,8 +2789,7 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ; } const QString msg = QString::fromUtf8("Syntax error"); - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, - token_buffer[0].loc.startLine, token_buffer[0].loc.startColumn, msg)); + diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg)); } return false; diff --git a/src/declarative/qml/parser/javascriptparser.cpp b/src/declarative/qml/parser/javascriptparser.cpp index e1bed5d..0857eef 100644 --- a/src/declarative/qml/parser/javascriptparser.cpp +++ b/src/declarative/qml/parser/javascriptparser.cpp @@ -415,9 +415,8 @@ case 51: { case 52: { bool rx = lexer->scanRegExp(Lexer::NoPrefix); if (!rx) { - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, lexer->startLineNo(), - lexer->startColumnNo(), lexer->errorMessage())); - return false; + diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, location(lexer), lexer->errorMessage())); + return false; // ### remove me } AST::RegExpLiteral *node = makeAstNode<AST::RegExpLiteral> (driver->nodePool(), lexer->pattern, lexer->flags); node->literalToken = loc(1); @@ -427,9 +426,8 @@ case 52: { case 53: { bool rx = lexer->scanRegExp(Lexer::EqualPrefix); if (!rx) { - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, lexer->startLineNo(), - lexer->startColumnNo(), lexer->errorMessage())); - return false; + diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, location(lexer), lexer->errorMessage())); + return false; } AST::RegExpLiteral *node = makeAstNode<AST::RegExpLiteral> (driver->nodePool(), lexer->pattern, lexer->flags); node->literalToken = loc(1); @@ -1556,10 +1554,8 @@ case 314: { yylloc.startColumn += yylloc.length; yylloc.length = 0; - const QString msg = QString::fromUtf8("Missing `;'"); - - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning, - yylloc.startLine, yylloc.startColumn, msg)); + //const QString msg = QString::fromUtf8("Missing `;'"); + //diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning, yylloc, msg)); first_token = &token_buffer[0]; last_token = &token_buffer[1]; @@ -1585,8 +1581,7 @@ case 314: { if (t_action(errorState, yytoken)) { const QString msg = QString::fromUtf8("Unexpected token `%1'").arg(QLatin1String(spell[token_buffer[0].token])); - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, - token_buffer[0].loc.startLine, token_buffer[0].loc.startColumn, msg)); + diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg)); action = errorState; goto _Lcheck_token; @@ -1615,8 +1610,7 @@ case 314: { if (a > 0 && t_action(a, yytoken)) { const QString msg = QString::fromUtf8("Expected token `%1'").arg(QLatin1String(spell[*tk])); - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, - token_buffer[0].loc.startLine, token_buffer[0].loc.startColumn, msg)); + diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg)); yytoken = *tk; yylval = 0; @@ -1638,8 +1632,7 @@ case 314: { int a = t_action(errorState, tk); if (a > 0 && t_action(a, yytoken)) { const QString msg = QString::fromUtf8("Expected token `%1'").arg(QLatin1String(spell[tk])); - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, - token_buffer[0].loc.startLine, token_buffer[0].loc.startColumn, msg)); + diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg)); yytoken = tk; yylval = 0; @@ -1652,8 +1645,7 @@ case 314: { } const QString msg = QString::fromUtf8("Syntax error"); - diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, - token_buffer[0].loc.startLine, token_buffer[0].loc.startColumn, msg)); + diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg)); } return false; diff --git a/src/declarative/qml/parser/javascriptparser_p.h b/src/declarative/qml/parser/javascriptparser_p.h index bfbaf20..5e68fe7 100644 --- a/src/declarative/qml/parser/javascriptparser_p.h +++ b/src/declarative/qml/parser/javascriptparser_p.h @@ -119,10 +119,10 @@ public: enum Kind { Warning, Error }; DiagnosticMessage() - : kind(Error), line(0), column(0) {} + : kind(Error) {} - DiagnosticMessage(Kind kind, int line, int column, const QString &message) - : kind(kind), line(line), column(column), message(message) {} + DiagnosticMessage(Kind kind, const JavaScript::AST::SourceLocation &loc, const QString &message) + : kind(kind), loc(loc), message(message) {} bool isWarning() const { return kind == Warning; } @@ -131,8 +131,7 @@ public: { return kind == Error; } Kind kind; - int line; - int column; + JavaScript::AST::SourceLocation loc; QString message; }; @@ -162,10 +161,10 @@ public: { return diagnosticMessage().message; } inline int errorLineNumber() const - { return diagnosticMessage().line; } + { return diagnosticMessage().loc.startLine; } inline int errorColumnNumber() const - { return diagnosticMessage().column; } + { return diagnosticMessage().loc.startColumn; } protected: void reallocateStack(); |