diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-05 05:16:43 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-05 05:16:43 (GMT) |
commit | c248a3c68fdce3387bec61e3b19bdf766ae93ed0 (patch) | |
tree | d5497314129d1da6bba17acce9bddf2e3c625f69 | |
parent | 0725ca189ad30ec54a2a7a054404a50f20e2bfed (diff) | |
download | Qt-c248a3c68fdce3387bec61e3b19bdf766ae93ed0.zip Qt-c248a3c68fdce3387bec61e3b19bdf766ae93ed0.tar.gz Qt-c248a3c68fdce3387bec61e3b19bdf766ae93ed0.tar.bz2 |
Add parser support for object slot declarations
-rw-r--r-- | src/declarative/qml/qmlparser.cpp | 9 | ||||
-rw-r--r-- | src/declarative/qml/qmlparser_p.h | 13 | ||||
-rw-r--r-- | src/declarative/qml/qmlscriptparser.cpp | 65 |
3 files changed, 64 insertions, 23 deletions
diff --git a/src/declarative/qml/qmlparser.cpp b/src/declarative/qml/qmlparser.cpp index d862315..a943c4d 100644 --- a/src/declarative/qml/qmlparser.cpp +++ b/src/declarative/qml/qmlparser.cpp @@ -123,6 +123,15 @@ QmlParser::Object::DynamicSignal::DynamicSignal(const DynamicSignal &o) { } +QmlParser::Object::DynamicSlot::DynamicSlot() +{ +} + +QmlParser::Object::DynamicSlot::DynamicSlot(const DynamicSlot &o) +: name(o.name), body(o.body) +{ +} + QmlParser::Property::Property() : type(0), index(-1), value(0), isDefault(true), line(-1), column(-1) { diff --git a/src/declarative/qml/qmlparser_p.h b/src/declarative/qml/qmlparser_p.h index aeacee8..676e25e 100644 --- a/src/declarative/qml/qmlparser_p.h +++ b/src/declarative/qml/qmlparser_p.h @@ -123,11 +123,20 @@ namespace QmlParser QByteArray name; }; + struct DynamicSlot { + DynamicSlot(); + DynamicSlot(const DynamicSlot &); - // The list of dynamic properties described in the "properties" property + QByteArray name; + QString body; + }; + + // The list of dynamic properties QList<DynamicProperty> dynamicProperties; - // The list of dynamic signals described in the "signals" property + // The list of dynamic signals QList<DynamicSignal> dynamicSignals; + // The list of dynamic slots + QList<DynamicSlot> dynamicSlots; }; class Value : public QmlRefCount diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 81315c3..22ff4a5 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -521,31 +521,54 @@ bool ProcessAST::visit(AST::UiArrayBinding *node) bool ProcessAST::visit(AST::UiSourceElement *node) { QmlParser::Object *obj = currentObject(); - if (! (obj && obj->typeName == "Script")) { - QmlError error; - error.setDescription("JavaScript declaration outside Script element"); - error.setLine(node->firstSourceLocation().startLine); - error.setColumn(node->firstSourceLocation().startColumn); - _parser->_errors << error; - return false; - } - QString source; + bool isScript = (obj && obj->typeName == "Script"); - int line = 0; - if (AST::FunctionDeclaration *funDecl = AST::cast<AST::FunctionDeclaration *>(node->sourceElement)) { - line = funDecl->functionToken.startLine; - source = asString(funDecl); - } else if (AST::VariableStatement *varStmt = AST::cast<AST::VariableStatement *>(node->sourceElement)) { - // ignore variable declarations - line = varStmt->declarationKindToken.startLine; - } + if (!isScript) { - Value *value = new Value; - value->primitive = source; - value->line = line; + if (AST::FunctionDeclaration *funDecl = AST::cast<AST::FunctionDeclaration *>(node->sourceElement)) { + + if(funDecl->formals) { + QmlError error; + error.setDescription("Slot declarations must be parameterless"); + error.setLine(funDecl->lparenToken.startLine); + error.setColumn(funDecl->lparenToken.startColumn); + _parser->_errors << error; + return false; + } + + QString body = textAt(funDecl->lbraceToken, funDecl->rbraceToken); + Object::DynamicSlot slot; + slot.name = funDecl->name->asString().toUtf8(); + slot.body = body; + obj->dynamicSlots << slot; + } else { + QmlError error; + error.setDescription("JavaScript declaration outside Script element"); + error.setLine(node->firstSourceLocation().startLine); + error.setColumn(node->firstSourceLocation().startColumn); + _parser->_errors << error; + } + return false; - obj->getDefaultProperty()->addValue(value); + } else { + QString source; + + int line = 0; + if (AST::FunctionDeclaration *funDecl = AST::cast<AST::FunctionDeclaration *>(node->sourceElement)) { + line = funDecl->functionToken.startLine; + source = asString(funDecl); + } else if (AST::VariableStatement *varStmt = AST::cast<AST::VariableStatement *>(node->sourceElement)) { + // ignore variable declarations + line = varStmt->declarationKindToken.startLine; + } + + Value *value = new Value; + value->primitive = source; + value->line = line; + + obj->getDefaultProperty()->addValue(value); + } return false; } |