summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qmlscriptparser.cpp
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-10-07 05:37:44 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-10-07 05:37:44 (GMT)
commit99573a8e81fcea38c5f68b340068fff266315c03 (patch)
tree42f71fa7727fa4036096b07f15d2e9ba27ec8ef9 /src/declarative/qml/qmlscriptparser.cpp
parent50a4a8ec76b98cc860de9b6e6aaf25c87e690eed (diff)
downloadQt-99573a8e81fcea38c5f68b340068fff266315c03.zip
Qt-99573a8e81fcea38c5f68b340068fff266315c03.tar.gz
Qt-99573a8e81fcea38c5f68b340068fff266315c03.tar.bz2
Make Script an instrinsic type
This allows us to delay the QML load until external script files have been loaded from the network, and to correctly scope these scripts.
Diffstat (limited to 'src/declarative/qml/qmlscriptparser.cpp')
-rw-r--r--src/declarative/qml/qmlscriptparser.cpp51
1 files changed, 47 insertions, 4 deletions
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp
index c126830..1c7bf83 100644
--- a/src/declarative/qml/qmlscriptparser.cpp
+++ b/src/declarative/qml/qmlscriptparser.cpp
@@ -289,12 +289,26 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName,
if (lastTypeDot >= 0)
resolvableObjectType.replace(QLatin1Char('.'),QLatin1Char('/'));
- QmlScriptParser::TypeReference *typeRef = _parser->findOrCreateType(resolvableObjectType);
+ bool isScript = resolvableObjectType == QLatin1String("Script");
+
+ if (isScript) {
+ if (_stateStack.isEmpty() || _stateStack.top().property) {
+ QmlError error;
+ error.setDescription(QLatin1String("Invalid use of Script block"));
+ error.setLine(typeLocation.startLine);
+ error.setColumn(typeLocation.startColumn);
+ _parser->_errors << error;
+ }
+ }
Object *obj = new Object;
- obj->type = typeRef->id;
- typeRef->refObjects.append(obj);
+ if (!isScript) {
+ QmlScriptParser::TypeReference *typeRef = _parser->findOrCreateType(resolvableObjectType);
+ obj->type = typeRef->id;
+
+ typeRef->refObjects.append(obj);
+ }
// XXX this doesn't do anything (_scope never builds up)
_scope.append(resolvableObjectType);
@@ -303,7 +317,11 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName,
obj->location = location;
- if (propertyCount) {
+ if (isScript) {
+
+ _stateStack.top().object->scriptBlockObjects.append(obj);
+
+ } else if (propertyCount) {
Property *prop = currentProperty();
Value *v = new Value;
@@ -385,6 +403,26 @@ Object *ProcessAST::defineObjectBinding(AST::UiQualifiedId *qualifiedId,
_stateStack.pop(); // object
return obj;
+ } else if (objectType == QLatin1String("Script")) {
+
+ AST::UiObjectMemberList *it = initializer->members;
+ for (; it; it = it->next) {
+ AST::UiScriptBinding *scriptBinding = AST::cast<AST::UiScriptBinding *>(it->member);
+ if (! scriptBinding)
+ continue;
+
+ QString propertyName = asString(scriptBinding->qualifiedId);
+ if (propertyName == QLatin1String("source")) {
+ if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(scriptBinding->statement)) {
+ AST::StringLiteral *string = AST::cast<AST::StringLiteral *>(stmt->expression);
+ if (string) {
+ // We need to add this as a resource
+ _parser->_refUrls << QUrl(string->value->asString());
+ }
+ }
+ }
+ }
+
}
return defineObjectBinding_helper(qualifiedId, objectType, typeLocation, location, initializer);
@@ -867,6 +905,11 @@ QList<QmlScriptParser::TypeReference*> QmlScriptParser::referencedTypes() const
return _refTypes;
}
+QList<QUrl> QmlScriptParser::referencedResources() const
+{
+ return _refUrls;
+}
+
Object *QmlScriptParser::tree() const
{
return root;