diff options
author | mae <qt-info@nokia.com> | 2009-04-20 12:51:57 (GMT) |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2009-04-24 07:52:35 (GMT) |
commit | 765166f9aca829391bc2f4ee60b6ea4b5f7ff683 (patch) | |
tree | 12fbe4d0671d07ed2cd66c444a1937783c947d0e /src/declarative/qml | |
parent | 3b60326ce12dcbac1dfeba3c6ba73fa04c15d16e (diff) | |
download | Qt-765166f9aca829391bc2f4ee60b6ea4b5f7ff683.zip Qt-765166f9aca829391bc2f4ee60b6ea4b5f7ff683.tar.gz Qt-765166f9aca829391bc2f4ee60b6ea4b5f7ff683.tar.bz2 |
code cleanup (helper functions rule)
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/qmlscriptparser.cpp | 147 |
1 files changed, 73 insertions, 74 deletions
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 2f62cfd..42cd812 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -61,16 +61,17 @@ public: void operator()(AST::Node *node); protected: + Object *defineObjectBinding(int line, + const QString &propertyName, + const QString &objectType, + AST::UiObjectInitializer *initializer = 0); + using AST::Visitor::visit; using AST::Visitor::endVisit; virtual bool visit(AST::UiObjectDefinition *node); - virtual void endVisit(AST::UiObjectDefinition *node); - virtual bool visit(AST::UiPublicMember *node); - virtual bool visit(AST::UiObjectBinding *node); - virtual void endVisit(AST::UiObjectBinding *node); virtual bool visit(AST::UiScriptBinding *node); virtual bool visit(AST::UiArrayBinding *node); @@ -147,35 +148,46 @@ QString ProcessAST::asString(AST::UiQualifiedId *node) const return s; } -// UiObjectMember: T_PUBLIC T_IDENTIFIER T_IDENTIFIER T_COLON Expression UiObjectInitializer ; -bool ProcessAST::visit(AST::UiPublicMember *node) -{ - qWarning() << Q_FUNC_INFO << "not implemented"; - return false; -} - -// UiObjectMember: T_IDENTIFIER UiObjectInitializer ; -bool ProcessAST::visit(AST::UiObjectDefinition *node) +Object *ProcessAST::defineObjectBinding(int line, + const QString &propertyName, + const QString &objectType, + AST::UiObjectInitializer *initializer) { - const QString name = node->name->asString(); - bool isType = name.at(0).isUpper() && !name.contains(QLatin1Char('.')); - - _scope.append(name); - - if (! isType) { + bool isType = !objectType.isEmpty() && objectType.at(0).isUpper() && !objectType.contains(QLatin1Char('.')); + if (!isType) { qWarning() << "bad name for a class"; // ### FIXME return false; } + const QStringList str = propertyName.split(QLatin1Char('.'), QString::SkipEmptyParts); + + for(int ii = 0; ii < str.count(); ++ii) { + const QString s = str.at(ii); + _stateStack.pushProperty(s, line); + } + + // Class - const int typeId = _parser->findOrCreateTypeId(name); - int line = node->identifierToken.startLine; + const int typeId = _parser->findOrCreateTypeId(objectType); Object *obj = new Object; obj->type = typeId; + _scope.append(objectType); obj->typeName = qualifiedNameId().toLatin1(); + _scope.removeLast(); obj->line = line; + if (Property *prop = currentProperty()) { + Value *v = new Value; + v->object = obj; + v->line = line; + prop->addValue(v); + } + + for(int ii = str.count() - 1; ii >= 0; --ii) + _stateStack.pop(); + + if (! _parser->tree()) { _parser->setTree(obj); _stateStack.pushObject(obj); @@ -191,80 +203,67 @@ bool ProcessAST::visit(AST::UiObjectDefinition *node) _stateStack.pushObject(obj); } - return true; -} + accept(initializer); -// UiObjectMember: T_IDENTIFIER UiObjectInitializer ; -void ProcessAST::endVisit(AST::UiObjectDefinition *) -{ _stateStack.pop(); - _scope.removeLast(); + + return obj; } -// UiObjectMember: UiQualifiedId T_COLON T_IDENTIFIER UiObjectInitializer ; -bool ProcessAST::visit(AST::UiObjectBinding *node) +// UiObjectMember: T_PUBLIC T_IDENTIFIER T_IDENTIFIER T_COLON Expression UiObjectInitializer ; +bool ProcessAST::visit(AST::UiPublicMember *node) { -// qWarning() << Q_FUNC_INFO << "not implemented"; - const QString qualifiedId = asString(node->qualifiedId); - const QStringList str = qualifiedId.split(QLatin1Char('.')); - int line = node->colonToken.startLine; - - for(int ii = 0; ii < str.count(); ++ii) { - const QString s = str.at(ii); - _stateStack.pushProperty(s, line); - } - +#if 0 + const QString type = node->type->asString(); const QString name = node->name->asString(); - bool isType = name.at(0).isUpper() && !name.contains(QLatin1Char('.')); - _scope.append(name); + if (type == QLatin1String("property")) { + Object *properties = defineObjectBinding(node->publicToken.startLine, + QLatin1String("properties"), + Q + property = QLatin1("properties"); + _stateStack.pushProperty(QLatin1String("properties"), node->publicToken.startLine); - if (! isType) { - qWarning() << "bad name for a class"; // ### FIXME - return false; - } + const int typeId = _parser->findOrCreateTypeId(QLatin1String("Property")); + int line = node->identifierToken.startLine; - // Class - const int typeId = _parser->findOrCreateTypeId(name); - line = node->identifierToken.startLine; + Object *obj = new Object; + obj->type = typeId; + obj->typeName = qualifiedNameId().toLatin1(); + obj->line = line; - Object *obj = new Object; - obj->type = typeId; - obj->typeName = qualifiedNameId().toLatin1(); - obj->line = line; - Property *prop = currentProperty(); - Value *v = new Value; - v->object = obj; - v->line = line; - prop->addValue(v); + accept(node->initializer); - for(int ii = str.count() - 1; ii >= 0; --ii) _stateStack.pop(); - if (! _parser->tree()) { - _parser->setTree(obj); - _stateStack.pushObject(obj); } else { - const State state = _stateStack.top(); - Value *v = new Value; - v->object = obj; - v->line = line; - if(state.property) - state.property->addValue(v); - else - state.object->getDefaultProperty()->addValue(v); - _stateStack.pushObject(obj); + qWarning << "bad public identifier" << type; // ### FIXME } +#endif + return false; +} - return true; + +// UiObjectMember: T_IDENTIFIER UiObjectInitializer ; +bool ProcessAST::visit(AST::UiObjectDefinition *node) +{ + defineObjectBinding(node->identifierToken.startLine, + QString(), + node->name->asString(), + node->initializer); + return false; } + // UiObjectMember: UiQualifiedId T_COLON T_IDENTIFIER UiObjectInitializer ; -void ProcessAST::endVisit(AST::UiObjectBinding *node) +bool ProcessAST::visit(AST::UiObjectBinding *node) { - _stateStack.pop(); - _scope.removeLast(); + defineObjectBinding(node->identifierToken.startLine, + asString(node->qualifiedId), + node->name->asString(), + node->initializer); + return false; } // UiObjectMember: UiQualifiedId T_COLON Statement ; |