Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qdeclarativescript.cpp
index 9e6e09e..48384ce 100644 (file)
@@ -1,8 +1,7 @@
 /****************************************************************************
 **
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
 **
 ** This file is part of the QtDeclarative module of the Qt Toolkit.
 **
 **
 **
 **
+**
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
 
-#include "private/qdeclarativescript_p.h"
+#include "qdeclarativescript_p.h"
 
 #include "parser/qdeclarativejsengine_p.h"
 #include "parser/qdeclarativejsparser_p.h"
@@ -47,7 +47,7 @@
 #include "parser/qdeclarativejsmemorypool_p.h"
 #include "parser/qdeclarativejsastvisitor_p.h"
 #include "parser/qdeclarativejsast_p.h"
-#include "private/qdeclarativerewrite_p.h"
+#include <private/qdeclarativerewrite_p.h>
 
 #include <QStack>
 #include <QCoreApplication>
@@ -182,7 +182,7 @@ Property *QDeclarativeScript::Object::getProperty(const QString &name, bool crea
 }
 
 QDeclarativeScript::Object::DynamicProperty::DynamicProperty()
-: isDefaultProperty(false), type(Variant), defaultValue(0), nextProperty(0), 
+: isDefaultProperty(false), isReadOnly(false), type(Variant), defaultValue(0), nextProperty(0),
   resolvedCustomTypeName(0)
 {
 }
@@ -225,8 +225,8 @@ int QDeclarativeScript::Object::DynamicSlot::parameterNamesLength() const
 
 QDeclarativeScript::Property::Property()
 : parent(0), type(0), index(-1), value(0), isDefault(true), isDeferred(false), 
-  isValueTypeSubProperty(false), isAlias(false), scriptStringScope(-1), 
-  nextMainProperty(0), nextProperty(0)
+  isValueTypeSubProperty(false), isAlias(false), isReadOnlyDeclaration(false),
+  scriptStringScope(-1), nextMainProperty(0), nextProperty(0)
 {
 }
 
@@ -252,7 +252,7 @@ bool QDeclarativeScript::Property::isEmpty() const
 }
 
 QDeclarativeScript::Value::Value()
-: type(Unknown), object(0), bindingReference(0), signalExpressionContextStack(0), nextValue(0)
+: type(Unknown), object(0), bindingReference(0), nextValue(0)
 {
 }
 
@@ -679,9 +679,9 @@ ProcessAST::defineObjectBinding(AST::UiQualifiedId *propertyName,
                                 AST::UiObjectInitializer *initializer)
 {
     int lastTypeDot = objectType.lastIndexOf(QLatin1Char('.'));
-    bool isType = !objectType.isEmpty() &&
-                    (objectType.at(0).isUpper() ||
-                        (lastTypeDot >= 0 && objectType.at(lastTypeDot+1).isUpper()));
+
+    // With no preceding qualification, first char is at (-1 + 1) == 0
+    bool isType = !objectType.isEmpty() && objectType.at(lastTypeDot+1).isUpper();
 
     int propertyCount = 0;
     for (AST::UiQualifiedId *name = propertyName; name; name = name->next){
@@ -701,11 +701,26 @@ ProcessAST::defineObjectBinding(AST::UiQualifiedId *propertyName,
 
     if (!isType) {
 
-        if(propertyCount || !currentObject()) {
+        // Is the identifier qualified by a namespace?
+        int namespaceLength = 0;
+        if (lastTypeDot > 0) {
+            const QString qualifier(objectType.left(lastTypeDot));
+
+            for (int ii = 0; ii < _parser->_imports.count(); ++ii) {
+                const QDeclarativeScript::Import &import = _parser->_imports.at(ii);
+                if (import.qualifier == qualifier) {
+                    // The qualifier is a namespace - expect a type here
+                    namespaceLength = qualifier.length() + 1;
+                    break;
+                }
+            }
+        }
+
+        if (propertyCount || !currentObject() || namespaceLength) {
             QDeclarativeError error;
             error.setDescription(QCoreApplication::translate("QDeclarativeParser","Expected type name"));
             error.setLine(typeLocation.startLine);
-            error.setColumn(typeLocation.startColumn);
+            error.setColumn(typeLocation.startColumn + namespaceLength);
             _parser->_errors << error;
             return 0;
         }
@@ -736,7 +751,7 @@ ProcessAST::defineObjectBinding(AST::UiQualifiedId *propertyName,
 
         // XXX this doesn't do anything (_scope never builds up)
         _scope.append(resolvableObjectType);
-        obj->typeName = qualifiedNameId().toUtf8();
+        obj->typeName = qualifiedNameId();
         _scope.removeLast();
 
         obj->location = location;
@@ -920,7 +935,8 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
         // { "time", strlen("time"), Object::DynamicProperty::Time, "QTime", strlen("QTime") },
         // { "date", strlen("date"), Object::DynamicProperty::Date, "QDate", strlen("QDate") },
         { "date", strlen("date"), Object::DynamicProperty::DateTime, "QDateTime", strlen("QDateTime") },
-        { "variant", strlen("variant"), Object::DynamicProperty::Variant, "QVariant", strlen("QVariant") }
+        { "variant", strlen("variant"), Object::DynamicProperty::Variant, "QVariant", strlen("QVariant") },
+        { "var", strlen("var"), Object::DynamicProperty::Var, "QVariant", strlen("QVariant") }
     };
     static const int propTypeNameToTypesCount = sizeof(propTypeNameToTypes) /
                                                 sizeof(propTypeNameToTypes[0]);
@@ -1027,19 +1043,12 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
             return false;
         }
 
-        if (node->isReadonlyMember) {
-            QDeclarativeError error;
-            error.setDescription(QCoreApplication::translate("QDeclarativeParser","Readonly not yet supported"));
-            error.setLine(node->readonlyToken.startLine);
-            error.setColumn(node->readonlyToken.startColumn);
-            _parser->_errors << error;
-            return false;
-
-        }
-
         Object::DynamicProperty *property = _parser->_pool.New<Object::DynamicProperty>();
         property->isDefaultProperty = node->isDefaultMember;
+        property->isReadOnly = node->isReadonlyMember;
         property->type = type;
+        property->nameLocation.line = node->identifierToken.startLine;
+        property->nameLocation.column = node->identifierToken.startColumn;
         if (type >= Object::DynamicProperty::Custom) {
             QDeclarativeScript::TypeReference *typeRef =
                 _parser->findOrCreateType(memberType.toString());
@@ -1226,7 +1235,7 @@ bool ProcessAST::visit(AST::UiSourceElement *node)
     if (AST::FunctionDeclaration *funDecl = AST::cast<AST::FunctionDeclaration *>(node->sourceElement)) {
 
         Object::DynamicSlot *slot = _parser->_pool.New<Object::DynamicSlot>();
-        slot->location = location(funDecl->firstSourceLocation(), funDecl->lastSourceLocation());
+        slot->location = location(funDecl->identifierToken, funDecl->lastSourceLocation());
 
         AST::FormalParameterList *f = funDecl->formals;
         while (f) {