summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qmlscriptparser.cpp159
-rw-r--r--tools/qmlconv/qmlconv.cpp81
2 files changed, 78 insertions, 162 deletions
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp
index 099985e..dbf71dd 100644
--- a/src/declarative/qml/qmlscriptparser.cpp
+++ b/src/declarative/qml/qmlscriptparser.cpp
@@ -240,177 +240,38 @@ Object *ProcessAST::defineObjectBinding(int line,
const QString &objectType,
AST::UiObjectInitializer *initializer)
{
-#if 0
if (objectType == QLatin1String("Connection")) {
- AST::UiObjectMemberList *it = initializer->members;
+ Object *obj = defineObjectBinding_helper(line, 0, QLatin1String("Connection"));
- QString sender;
- QString signal;
- QString script;
+ _stateStack.pushObject(obj);
+ AST::UiObjectMemberList *it = initializer->members;
for (; it; it = it->next) {
AST::UiScriptBinding *scriptBinding = AST::cast<AST::UiScriptBinding *>(it->member);
if (! scriptBinding)
continue;
- QString s;
- QTextStream out(&s);
- PrettyPretty pp(out);
-
QString propertyName = asString(scriptBinding->qualifiedId);
- if (propertyName == QLatin1String("signal")) {
- // ## TODO verify that this is a function call statement and nothing else.
- if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(scriptBinding->statement)) {
- pp(stmt->expression);
- int dot = s.lastIndexOf(QLatin1Char('.'));
- if (dot >= 0) {
- sender = s.left(dot);
- signal = s.mid(dot+1);
- } else {
- // ### TODO generate error
- }
- } else {
- // ### TODO generate error
- }
-
- } else if (propertyName == QLatin1String("onSignal")) {
+ if (propertyName == QLatin1String("script")) {
+ QString script;
if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(scriptBinding->statement)) {
- script = getPrimitive("onSignal", stmt->expression);
+ script = getPrimitive("script", stmt->expression);
} else {
+ QTextStream out(&script);
+ PrettyPretty pp(out);
pp(scriptBinding->statement);
- script = s;
}
+ defineProperty(QLatin1String("script"), line, script);
} else {
- //### TODO generate error
+ accept(it->member);
}
}
- Object *obj = defineObjectBinding_helper(line,
- 0,
- QLatin1String("Connection"));
- _stateStack.pushObject(obj);
- if (!sender.isEmpty())
- defineProperty(QLatin1String("sender"), line, QLatin1Char('{') + sender + QLatin1Char('}'));
- if (!script.isEmpty())
- defineProperty(QLatin1String("script"), line, script);
- if (!signal.isEmpty())
- defineProperty(QLatin1String("signal"), line, signal);
_stateStack.pop(); // object
return obj;
-
- } else if (objectType == QLatin1String("PropertyChangeSet")) {
-
- AST::UiObjectMemberList *it = initializer->members;
- for (; it; it = it->next) {
- AST::UiScriptBinding *scriptBinding = AST::cast<AST::UiScriptBinding *>(it->member);
- if (!scriptBinding)
- continue; // ### TODO generate error
-
-
- QString target;
- QString property;
- QString value;
-
- int propertyCount = 0;
- AST::UiQualifiedId *propertyName = scriptBinding->qualifiedId;
- for (; propertyName; propertyName = propertyName->next){
- if (propertyName->next) {
- if (!target.isEmpty())
- target += QLatin1Char('.');
- target += propertyName->name->asString();
- } else {
- property = propertyName->name->asString();
- }
- ++propertyCount;
- }
-
- if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(scriptBinding->statement)) {
- value = getPrimitive(property.toLatin1(), stmt->expression);
- } else {
- // #### TODO generate error
- }
-
- Object *obj = defineObjectBinding_helper(line,
- 0,
- QLatin1String("SetProperty"));
-
- _stateStack.pushObject(obj);
- if (!target.isEmpty())
- defineProperty(QLatin1String("target"), scriptBinding->colonToken.startLine, QLatin1Char('{') + target + QLatin1Char('}'));
- if (!property.isEmpty())
- defineProperty(QLatin1String("property"), scriptBinding->colonToken.startLine, property);
- if (!value.isEmpty())
- defineProperty(QLatin1String("value"), scriptBinding->colonToken.startLine, value);
- _stateStack.pop(); // object
-
- }
-
- return 0;
- } else if (objectType == QLatin1String("ParentChangeSet")) {
-
- AST::UiObjectMemberList *it = initializer->members;
- for (; it; it = it->next) {
- AST::UiScriptBinding *scriptBinding = AST::cast<AST::UiScriptBinding *>(it->member);
- if (!scriptBinding)
- continue; // ### TODO generate error
-
-
- QString target;
- QString property;
- QString parent;
-
- int propertyCount = 0;
- AST::UiQualifiedId *propertyName = scriptBinding->qualifiedId;
- for (; propertyName; propertyName = propertyName->next){
- if (propertyName->next) {
- if (!target.isEmpty())
- target += QLatin1Char('.');
- target += propertyName->name->asString();
- } else {
- property = propertyName->name->asString();
- }
- ++propertyCount;
- }
-
- if (property != QLatin1String("parent")) {
- // ### TODO generate error
- } else {
-
- if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(scriptBinding->statement)) {
- parent = getPrimitive(property.toLatin1(), stmt->expression);
- } else {
- // #### TODO generate error
- }
-
- Object *obj = defineObjectBinding_helper(line,
- 0,
- QLatin1String("ParentChange"));
-
- _stateStack.pushObject(obj);
- if (!target.isEmpty())
- defineProperty(QLatin1String("target"), scriptBinding->colonToken.startLine, QLatin1Char('{') + target + QLatin1Char('}'));
- if (!parent.isEmpty())
- defineProperty(QLatin1String("parent"), scriptBinding->colonToken.startLine, parent);
- _stateStack.pop(); // object
- }
-
- }
-
- return 0;
- } else if(!currentProperty() && objectType == QLatin1String("State")) {
- _stateStack.pushProperty(QLatin1String("states"), line);
- Object *obj = defineObjectBinding_helper(line, 0, objectType, initializer);
- _stateStack.pop();
- return obj;
- } else if (!currentProperty() && objectType == QLatin1String("Transition")) {
- _stateStack.pushProperty(QLatin1String("transitions"), line);
- Object *obj = defineObjectBinding_helper(line, 0, objectType, initializer);
- _stateStack.pop();
- return obj;
}
-#endif
return defineObjectBinding_helper(line, qualifiedId, objectType, initializer);
}
diff --git a/tools/qmlconv/qmlconv.cpp b/tools/qmlconv/qmlconv.cpp
index e9358df..3ba40a4 100644
--- a/tools/qmlconv/qmlconv.cpp
+++ b/tools/qmlconv/qmlconv.cpp
@@ -6,7 +6,7 @@
#include <QtCore/QDebug>
-
+static bool optionInPlace = false;
class Reader
{
@@ -34,8 +34,16 @@ public:
loop();
out.flush();
- QTextStream print(stdout);
- print << outString;
+
+ if (! optionInPlace) {
+ QTextStream print(stdout);
+ print << outString;
+ }
+ }
+
+ QString output() const
+ {
+ return outString;
}
void comment()
@@ -100,7 +108,7 @@ public:
startSetProperty();
else if (false && xml.name() == "ParentChange")
startParentChange();
- else if (false && xml.name() == "Connection")
+ else if (true && xml.name() == "Connection")
startConnection();
else if (false && xml.name() == "Script")
startScript();
@@ -350,10 +358,32 @@ public:
possiblyRemoveBraces(&sender);
out << depthString() << "Connection {" << endl;
++depth;
- out << depthString() << "signal: " << sender + "." + xml.attributes().value("signal").toString() << endl;
- out << depthString() << "onSignal: { " << xml.attributes().value("script").toString() << " }" << endl;
- --depth;
- out << depthString() << "}" << endl;
+ if (! sender.isEmpty())
+ out << depthString() << "sender: " << sender << endl;
+ if (xml.attributes().hasAttribute("signal"))
+ out << depthString() << "signal: \"" << xml.attributes().value("signal").toString() << '"' << endl;
+ if (xml.attributes().hasAttribute("script")) {
+ out << depthString() << "script: { " << xml.attributes().value("script").toString() << " }" << endl;
+ --depth;
+ out << depthString() << "}" << endl;
+ } else {
+ QString text;
+ while (!xml.atEnd()) {
+ xml.readNext();
+ if (xml.tokenType() == QXmlStreamReader::EndElement)
+ break;
+ else if (xml.tokenType() == QXmlStreamReader::Characters)
+ text.append(xml.text());
+ }
+
+ out << depthString() << "script: {" << endl;
+ foreach (QString line, text.split(QLatin1Char('\n'))) {
+ out << depthString() << line << endl;
+ }
+ out << depthString() << "}" << endl;
+ --depth;
+ out << depthString() << "}" << endl;
+ }
emptyLoop();
}
@@ -409,17 +439,42 @@ int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
- if (argc != 2) {
- qWarning() << "Usage: qmlconf filename";
+ QStringList args = a.arguments();
+ args.removeFirst();
+
+again:
+ if (args.isEmpty()) {
+ qWarning() << "Usage: qmlconf [-i] filename";
exit(1);
}
- QFile file(argv[1]);
- if (file.open(QIODevice::ReadOnly)) {
- Reader r(&file);
+ if (args.first() == QLatin1String("-i")) {
+ optionInPlace = true;
+ args.removeFirst();
+ goto again;
}
+ const QString fileName = args.first();
+
+ QFile file(fileName);
+ if (! file.open(QIODevice::ReadOnly)) {
+ qWarning() << "qmlconv: no input file";
+ exit(1);
+ }
+ Reader r(&file);
file.close();
+
+ if (optionInPlace) {
+ if (! file.open(QFile::WriteOnly)) {
+ qWarning() << "qmlconv: cannot open file" << qPrintable(fileName);
+ exit(1);
+ }
+
+ QTextStream out(&file);
+ out << r.output();
+ file.close();
+ }
+
return 0;
}