From ab83f16fd07300342d786f48a82b4d81f77f670d Mon Sep 17 00:00:00 2001 From: mae Date: Fri, 17 Apr 2009 19:32:32 +0200 Subject: support both *.qml and *.whatever with autodetection. Some debug output, some fixes. Some stuff works now, biggest omission is UiObjectBinding to get the more complex examples working. --- src/declarative/qml/qmlcompiler.cpp | 2 ++ src/declarative/qml/qmlcomponent.cpp | 25 +++++++++++++++++++++++ src/declarative/qml/qmlcomponent_p.h | 1 + src/declarative/qml/qmlparser.cpp | 2 ++ src/declarative/qml/qmlscriptparser.cpp | 35 +++++++++++++++++++++++++++------ 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index e1a88bb..dd42581 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -747,6 +747,8 @@ bool QmlCompiler::compileSignal(Property *prop, Object *obj) if(isBinding(script)) COMPILE_EXCEPTION("Cannot assign binding to signal property"); + qDebug() << "and here we go..."; + int idx = output->indexForString(script); int pr = output->indexForByteArray(prop->name); diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 590f23f..4a3f9b0 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -61,6 +61,17 @@ QT_BEGIN_NAMESPACE class QByteArray; +bool QmlComponentPrivate::isXml(const QByteArray &ba) +{ + for (int i = 0; i < ba.size(); ++i) { + char c = ba.at(i); + if (c == ' ' || c == '\n' || c == '\r' || c == '\t') + continue; + return (c == '<'); + } + return true; +} + /*! \class QmlComponent \brief The QmlComponent class encapsulates a QML component description. @@ -334,6 +345,20 @@ void QmlComponent::loadUrl(const QUrl &url) d->fromTypeData(data); +<<<<<<< HEAD:src/declarative/qml/qmlcomponent.cpp +======= + // Compile data + QmlCompiler compiler; + if(!compiler.compile(d->engine, parser, d->cc)) { + qWarning().nospace() +#ifdef QML_VERBOSEERRORS_ENABLED + << "QmlComponent: " +#endif + << compiler.errorDescription().toLatin1().constData() << " @" + << d->name.toLatin1().constData() << ":" + << compiler.errorLine(); + } +>>>>>>> support both *.qml and *.whatever with autodetection. Some debug output, some fixes.:src/declarative/qml/qmlcomponent.cpp } emit statusChanged(status()); diff --git a/src/declarative/qml/qmlcomponent_p.h b/src/declarative/qml/qmlcomponent_p.h index 8074775..bb5f7bb 100644 --- a/src/declarative/qml/qmlcomponent_p.h +++ b/src/declarative/qml/qmlcomponent_p.h @@ -81,6 +81,7 @@ public: QmlEngine *engine; void clear(); + static bool isXml(const QByteArray &); }; #endif // QMLCOMPONENT_P_H diff --git a/src/declarative/qml/qmlparser.cpp b/src/declarative/qml/qmlparser.cpp index 54db32e..6c71a97 100644 --- a/src/declarative/qml/qmlparser.cpp +++ b/src/declarative/qml/qmlparser.cpp @@ -57,6 +57,7 @@ #include #include "private/qmlxmlparser_p.h" #include +#include QT_BEGIN_NAMESPACE @@ -151,6 +152,7 @@ Object *QmlParser::Property::getValue() void QmlParser::Property::addValue(Value *v) { + qDebug() << "Property" << name << "addValue" << v->primitive; values << v; } diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index c74f4cb..9f4ff05 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -221,12 +221,38 @@ bool ProcessAST::visit(AST::UiScriptBinding *node) QTextStream out(&primitive); PrettyPretty pp(out); + Property *prop = currentProperty(); + if (node->statement->kind == AST::Node::Kind_ExpressionStatement) { AST::ExpressionStatement *stmt = static_cast(node->statement); - if (stmt->expression && stmt->expression->kind == AST::Node::Kind_IdentifierExpression) + if(prop->name.length() >= 3 && prop->name.startsWith("on") && + ('A' <= prop->name.at(2) && 'Z' >= prop->name.at(2))) { + pp(stmt->expression); + + // here comes a cruel hack until we support functions properly with arguments for signal properties + if (primitive.startsWith(QLatin1String("function("))) { + int brace = 0; + for (;brace < primitive.size(); ++brace) + if (primitive.at(brace) == QLatin1Char('{')) + break; + primitive = primitive.mid(brace + 1, primitive.size() - brace - 2); + } + //end of hack + + } else if (prop->name == "id" && stmt->expression && stmt->expression->kind == AST::Node::Kind_IdentifierExpression) { primitive = static_cast(stmt->expression)->name->asString(); - else { + } else if (stmt->expression->kind == AST::Node::Kind_StringLiteral) { + // hack: emulate weird XML feature that string literals are not quoted. + //This needs to be fixed in the qmlcompiler once xml goes away. + primitive = static_cast(stmt->expression)->value->asString(); + } else if (stmt->expression->kind == AST::Node::Kind_TrueLiteral + || stmt->expression->kind == AST::Node::Kind_FalseLiteral + || stmt->expression->kind == AST::Node::Kind_NumericLiteral + ) { + pp(stmt->expression); + } else { + // create a binding out << "{"; pp(stmt->expression); out << "}"; @@ -236,13 +262,10 @@ bool ProcessAST::visit(AST::UiScriptBinding *node) } - - - const State s = state(); Value *v = new Value; v->primitive = primitive; v->line = line; - s.property->addValue(v); + prop->addValue(v); for(int ii = str.count() - 1; ii >= 0; --ii) _stateStack.pop(); -- cgit v0.12