From 05c1db3b28067336fcf14cce7909d1f09007998b Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 27 Jul 2009 01:43:22 +0200 Subject: Added formal parameters to the QML signals. --- src/declarative/qml/parser/qmljs.g | 52 +++++++++++++++ src/declarative/qml/parser/qmljsast.cpp | 25 ++++++++ src/declarative/qml/parser/qmljsast_p.h | 88 +++++++++++++++++++++++++- src/declarative/qml/parser/qmljsastfwd_p.h | 3 + src/declarative/qml/parser/qmljsastvisitor_p.h | 6 ++ src/declarative/qml/parser/qmljsparser.cpp | 40 ++++++++++++ src/declarative/qml/parser/qmljsparser_p.h | 3 + 7 files changed, 216 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/parser/qmljs.g b/src/declarative/qml/parser/qmljs.g index ccfe7fd..a1c4ba2 100644 --- a/src/declarative/qml/parser/qmljs.g +++ b/src/declarative/qml/parser/qmljs.g @@ -271,6 +271,9 @@ public: AST::UiObjectMemberList *UiObjectMemberList; AST::UiArrayMemberList *UiArrayMemberList; AST::UiQualifiedId *UiQualifiedId; + AST::UiSignature *UiSignature; + AST::UiFormalList *UiFormalList; + AST::UiFormal *UiFormal; }; public: @@ -880,13 +883,62 @@ case $rule_number: { ./ UiFormal: JsIdentifier ; +/. +case $rule_number: { + AST::UiFormal *node = makeAstNode(driver->nodePool(), sym(1).sval); + node->identifierToken = loc(1); + sym(1).UiFormal = node; +} break; +./ + UiFormal: JsIdentifier T_AS JsIdentifier ; +/. +case $rule_number: { + AST::UiFormal *node = makeAstNode(driver->nodePool(), + sym(1).sval, sym(3).sval); + node->identifierToken = loc(1); + node->asToken = loc(2); + node->aliasToken = loc(3); + sym(1).UiFormal = node; +} break; +./ UiFormalList: UiFormal ; +/. +case $rule_number: { + sym(1).UiFormalList = makeAstNode(driver->nodePool(), + sym(1).UiFormal); +} break; +./ + UiFormalList: UiFormalList T_COMMA UiFormal ; +/. +case $rule_number: { + sym(1).UiFormalList = makeAstNode(driver->nodePool(), + sym(1).UiFormalList, sym(3).UiFormal); +} break; +./ UiSignature: T_LPAREN T_RPAREN ; +/. +case $rule_number: { + AST::UiSignature *node = makeAstNode(driver->nodePool()); + node->lparenToken = loc(1); + node->rparenToken = loc(3); + sym(1).UiSignature = node; +} break; +./ + UiSignature: T_LPAREN UiFormalList T_RPAREN ; +/. +case $rule_number: { + AST::UiSignature *node = makeAstNode(driver->nodePool(), + sym(2).UiFormalList->finish()); + node->lparenToken = loc(1); + node->rparenToken = loc(3); + sym(1).UiSignature = node; +} break; +./ UiObjectMember: T_SIGNAL T_IDENTIFIER T_LPAREN UiParameterListOpt T_RPAREN T_AUTOMATIC_SEMICOLON ; UiObjectMember: T_SIGNAL T_IDENTIFIER T_LPAREN UiParameterListOpt T_RPAREN T_SEMICOLON ; diff --git a/src/declarative/qml/parser/qmljsast.cpp b/src/declarative/qml/parser/qmljsast.cpp index 52f19e2..1d7f09e 100644 --- a/src/declarative/qml/parser/qmljsast.cpp +++ b/src/declarative/qml/parser/qmljsast.cpp @@ -801,6 +801,31 @@ void UiProgram::accept0(Visitor *visitor) visitor->endVisit(this); } +void UiSignature::accept0(Visitor *visitor) +{ + if (visitor->visit(this)) { + acceptChild(formals, visitor); + } + visitor->endVisit(this); +} + +void UiFormalList::accept0(Visitor *visitor) +{ + if (visitor->visit(this)) { + for (UiFormalList *it = this; it; it = it->next) { + acceptChild(it->formal, visitor); + } + } + visitor->endVisit(this); +} + +void UiFormal::accept0(Visitor *visitor) +{ + if (visitor->visit(this)) { + } + visitor->endVisit(this); +} + void UiPublicMember::accept0(Visitor *visitor) { if (visitor->visit(this)) { diff --git a/src/declarative/qml/parser/qmljsast_p.h b/src/declarative/qml/parser/qmljsast_p.h index eba9202..9745153 100644 --- a/src/declarative/qml/parser/qmljsast_p.h +++ b/src/declarative/qml/parser/qmljsast_p.h @@ -213,7 +213,10 @@ public: Kind_UiPublicMember, Kind_UiQualifiedId, Kind_UiScriptBinding, - Kind_UiSourceElement + Kind_UiSourceElement, + Kind_UiFormal, + Kind_UiFormalList, + Kind_UiSignature }; inline Node() @@ -269,6 +272,89 @@ public: virtual SourceLocation lastSourceLocation() const = 0; }; +class UiFormal: public Node +{ +public: + QMLJS_DECLARE_AST_NODE(UiFormal) + + UiFormal(NameId *name, NameId *alias = 0) + : name(name), alias(alias) + { } + + virtual SourceLocation firstSourceLocation() const + { return SourceLocation(); } + + virtual SourceLocation lastSourceLocation() const + { return SourceLocation(); } + + virtual void accept0(Visitor *visitor); + +// attributes + NameId *name; + NameId *alias; + SourceLocation identifierToken; + SourceLocation asToken; + SourceLocation aliasToken; +}; + +class UiFormalList: public Node +{ +public: + QMLJS_DECLARE_AST_NODE(UiFormalList) + + UiFormalList(UiFormal *formal) + : formal(formal), next(this) {} + + UiFormalList(UiFormalList *previous, UiFormal *formal) + : formal(formal) + { + next = previous->next; + previous->next = this; + } + + UiFormalList *finish() + { + UiFormalList *head = next; + next = 0; + return head; + } + + virtual SourceLocation firstSourceLocation() const + { return SourceLocation(); } + + virtual SourceLocation lastSourceLocation() const + { return SourceLocation(); } + + virtual void accept0(Visitor *visitor); + +// attributes + UiFormal *formal; + UiFormalList *next; +}; + +class UiSignature: public Node +{ +public: + QMLJS_DECLARE_AST_NODE(UiSignature) + + UiSignature(UiFormalList *formals = 0) + : formals(formals) + { } + + virtual SourceLocation firstSourceLocation() const + { return SourceLocation(); } + + virtual SourceLocation lastSourceLocation() const + { return SourceLocation(); } + + virtual void accept0(Visitor *visitor); + +// attributes + SourceLocation lparenToken; + UiFormalList *formals; + SourceLocation rparenToken; +}; + class NestedExpression: public ExpressionNode { public: diff --git a/src/declarative/qml/parser/qmljsastfwd_p.h b/src/declarative/qml/parser/qmljsastfwd_p.h index 339bea4..f79cfc2 100644 --- a/src/declarative/qml/parser/qmljsastfwd_p.h +++ b/src/declarative/qml/parser/qmljsastfwd_p.h @@ -176,6 +176,9 @@ class UiObjectMember; class UiObjectMemberList; class UiArrayMemberList; class UiQualifiedId; +class UiFormalList; +class UiFormal; +class UiSignature; } } // namespace AST diff --git a/src/declarative/qml/parser/qmljsastvisitor_p.h b/src/declarative/qml/parser/qmljsastvisitor_p.h index 3677b1a..237640f 100644 --- a/src/declarative/qml/parser/qmljsastvisitor_p.h +++ b/src/declarative/qml/parser/qmljsastvisitor_p.h @@ -82,6 +82,9 @@ public: virtual bool visit(UiObjectMemberList *) { return true; } virtual bool visit(UiArrayMemberList *) { return true; } virtual bool visit(UiQualifiedId *) { return true; } + virtual bool visit(UiSignature *) { return true; } + virtual bool visit(UiFormalList *) { return true; } + virtual bool visit(UiFormal *) { return true; } virtual void endVisit(UiProgram *) {} virtual void endVisit(UiImportList *) {} @@ -96,6 +99,9 @@ public: virtual void endVisit(UiObjectMemberList *) {} virtual void endVisit(UiArrayMemberList *) {} virtual void endVisit(UiQualifiedId *) {} + virtual void endVisit(UiSignature *) {} + virtual void endVisit(UiFormalList *) {} + virtual void endVisit(UiFormal *) {} // QmlJS virtual bool visit(ThisExpression *) { return true; } diff --git a/src/declarative/qml/parser/qmljsparser.cpp b/src/declarative/qml/parser/qmljsparser.cpp index 22f3820..9bd6e6f 100644 --- a/src/declarative/qml/parser/qmljsparser.cpp +++ b/src/declarative/qml/parser/qmljsparser.cpp @@ -419,6 +419,46 @@ case 47: { sym(1).Node = node; } break; +case 48: { + AST::UiFormal *node = makeAstNode(driver->nodePool(), sym(1).sval); + node->identifierToken = loc(1); + sym(1).UiFormal = node; +} break; + +case 49: { + AST::UiFormal *node = makeAstNode(driver->nodePool(), + sym(1).sval, sym(3).sval); + node->identifierToken = loc(1); + node->asToken = loc(2); + node->aliasToken = loc(3); + sym(1).UiFormal = node; +} break; + +case 50: { + sym(1).UiFormalList = makeAstNode(driver->nodePool(), + sym(1).UiFormal); +} break; + +case 51: { + sym(1).UiFormalList = makeAstNode(driver->nodePool(), + sym(1).UiFormalList, sym(3).UiFormal); +} break; + +case 52: { + AST::UiSignature *node = makeAstNode(driver->nodePool()); + node->lparenToken = loc(1); + node->rparenToken = loc(3); + sym(1).UiSignature = node; +} break; + +case 53: { + AST::UiSignature *node = makeAstNode(driver->nodePool(), + sym(2).UiFormalList->finish()); + node->lparenToken = loc(1); + node->rparenToken = loc(3); + sym(1).UiSignature = node; +} break; + case 55: { AST::UiPublicMember *node = makeAstNode (driver->nodePool(), (NameId *)0, sym(2).sval); node->type = AST::UiPublicMember::Signal; diff --git a/src/declarative/qml/parser/qmljsparser_p.h b/src/declarative/qml/parser/qmljsparser_p.h index be5317b..e352f43 100644 --- a/src/declarative/qml/parser/qmljsparser_p.h +++ b/src/declarative/qml/parser/qmljsparser_p.h @@ -120,6 +120,9 @@ public: AST::UiObjectMemberList *UiObjectMemberList; AST::UiArrayMemberList *UiArrayMemberList; AST::UiQualifiedId *UiQualifiedId; + AST::UiSignature *UiSignature; + AST::UiFormalList *UiFormalList; + AST::UiFormal *UiFormal; }; public: -- cgit v0.12 From be7b6bcac093abfb1ca1afedcdc6c5d12da12c8e Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 27 Jul 2009 01:49:11 +0200 Subject: Fixed project dependencies --- src/declarative/qml/parser/parser.pri | 1 + src/declarative/qml/rewriter/rewriter.pri | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/declarative/qml/parser/parser.pri b/src/declarative/qml/parser/parser.pri index 610b2aa..1ea249a 100644 --- a/src/declarative/qml/parser/parser.pri +++ b/src/declarative/qml/parser/parser.pri @@ -1,5 +1,6 @@ INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD HEADERS += $$PWD/qmljsast_p.h \ $$PWD/qmljsastfwd_p.h \ diff --git a/src/declarative/qml/rewriter/rewriter.pri b/src/declarative/qml/rewriter/rewriter.pri index de3c298..550741b 100644 --- a/src/declarative/qml/rewriter/rewriter.pri +++ b/src/declarative/qml/rewriter/rewriter.pri @@ -1,5 +1,7 @@ INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + HEADERS += $$PWD/textwriter_p.h SOURCES += $$PWD/textwriter.cpp -- cgit v0.12 From ca81810f92b6181c1854988860588d6ea84cf1b4 Mon Sep 17 00:00:00 2001 From: Henrik Hartz Date: Mon, 27 Jul 2009 10:24:49 +1000 Subject: compile fix --- src/declarative/qml/qmlmetatype.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp index 3552b44..a037702 100644 --- a/src/declarative/qml/qmlmetatype.cpp +++ b/src/declarative/qml/qmlmetatype.cpp @@ -56,7 +56,7 @@ #include #include #include -//#include +#include #include #include -- cgit v0.12 From ef1a5d6bad05b99765658b3ca916bd3c5f507db0 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 27 Jul 2009 13:34:13 +1000 Subject: Make private --- src/declarative/qml/qml.pri | 2 +- src/declarative/qml/qmlcomponentjs.cpp | 3 +- src/declarative/qml/qmlcomponentjs.h | 92 -------------------------------- src/declarative/qml/qmlcomponentjs_p.h | 47 +++++++++++----- src/declarative/qml/qmlcomponentjs_p_p.h | 77 ++++++++++++++++++++++++++ src/declarative/qml/qmlengine.cpp | 2 +- 6 files changed, 115 insertions(+), 108 deletions(-) delete mode 100644 src/declarative/qml/qmlcomponentjs.h create mode 100644 src/declarative/qml/qmlcomponentjs_p_p.h diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 6ee670e..75e5692 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -38,8 +38,8 @@ HEADERS += qml/qmlparser_p.h \ qml/qmlbinding.h \ qml/qmlbinding_p.h \ qml/qmlmetaproperty.h \ - qml/qmlcomponentjs.h \ qml/qmlcomponentjs_p.h \ + qml/qmlcomponentjs_p_p.h \ qml/qmlcomponent.h \ qml/qmlcomponent_p.h \ qml/qmlcustomparser_p.h \ diff --git a/src/declarative/qml/qmlcomponentjs.cpp b/src/declarative/qml/qmlcomponentjs.cpp index 32c2249..89f3851 100644 --- a/src/declarative/qml/qmlcomponentjs.cpp +++ b/src/declarative/qml/qmlcomponentjs.cpp @@ -39,11 +39,12 @@ ** ****************************************************************************/ -#include "qmlcomponentjs.h" #include "qmlcomponentjs_p.h" +#include "qmlcomponentjs_p_p.h" #include "qmlcomponent.h" QT_BEGIN_NAMESPACE + QmlComponentJS::QmlComponentJS(QmlEngine *engine, QObject *parent) : QmlComponent(*(new QmlComponentJSPrivate), parent) { diff --git a/src/declarative/qml/qmlcomponentjs.h b/src/declarative/qml/qmlcomponentjs.h deleted file mode 100644 index 5ad1635..0000000 --- a/src/declarative/qml/qmlcomponentjs.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLBINDABLECOMPONENT_H -#define QMLBINDABLECOMPONENT_H - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlComponentJSPrivate; -class QmlEngine; -class QmlContext; -class Q_DECLARATIVE_EXPORT QmlComponentJS : public QmlComponent -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlComponentJS) - friend class QmlEngine; -public: - QmlComponentJS(QmlEngine *, const QUrl &url, QObject *parent = 0); - QmlComponentJS(QmlEngine *, QObject *parent=0); - Q_PROPERTY(bool isNull READ isNull NOTIFY isNullChanged); - Q_PROPERTY(bool isReady READ isReady NOTIFY isReadyChanged); - Q_PROPERTY(bool isError READ isError NOTIFY isErrorChanged); - Q_PROPERTY(bool isLoading READ isLoading NOTIFY isLoadingChanged); - - Q_INVOKABLE QScriptValue createObject(); - Q_INVOKABLE QString errorsString() const; - - void setContext(QmlContext* c); -Q_SIGNALS: - void isNullChanged(); - void isErrorChanged(); - void isReadyChanged(); - void isLoadingChanged(); -private slots: - void statusChange(QmlComponent::Status newStatus); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlComponentJS) - -QT_END_HEADER -#endif diff --git a/src/declarative/qml/qmlcomponentjs_p.h b/src/declarative/qml/qmlcomponentjs_p.h index 75d5517..8c69b5f 100644 --- a/src/declarative/qml/qmlcomponentjs_p.h +++ b/src/declarative/qml/qmlcomponentjs_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QMLBINDABLECOMPONENT_P_H -#define QMLBINDABLECOMPONENT_P_H +#ifndef QMLCOMPONENTJS_P_H +#define QMLCOMPONENTJS_P_H // // W A R N I N G @@ -53,25 +53,46 @@ // We mean it. // -#include "qmlcomponent.h" -#include "qmlcomponentjs.h" -#include "qmlcomponent_p.h" +#include +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE +class QmlComponentJSPrivate; +class QmlEngine; class QmlContext; -class QmlComponentJSPrivate : public QmlComponentPrivate +class Q_DECLARATIVE_EXPORT QmlComponentJS : public QmlComponent { - Q_DECLARE_PUBLIC(QmlComponentJS) + Q_OBJECT + Q_DECLARE_PRIVATE(QmlComponentJS) + friend class QmlEngine; public: - QmlComponentJSPrivate() : QmlComponentPrivate(), - prevStatus(QmlComponentJS::Null), ctxt(0) - { } + QmlComponentJS(QmlEngine *, const QUrl &url, QObject *parent = 0); + QmlComponentJS(QmlEngine *, QObject *parent=0); + Q_PROPERTY(bool isNull READ isNull NOTIFY isNullChanged); + Q_PROPERTY(bool isReady READ isReady NOTIFY isReadyChanged); + Q_PROPERTY(bool isError READ isError NOTIFY isErrorChanged); + Q_PROPERTY(bool isLoading READ isLoading NOTIFY isLoadingChanged); - QmlComponent::Status prevStatus; - QmlContext* ctxt; + Q_INVOKABLE QScriptValue createObject(); + Q_INVOKABLE QString errorsString() const; + + void setContext(QmlContext* c); +Q_SIGNALS: + void isNullChanged(); + void isErrorChanged(); + void isReadyChanged(); + void isLoadingChanged(); +private slots: + void statusChange(QmlComponent::Status newStatus); }; QT_END_NAMESPACE -#endif +QML_DECLARE_TYPE(QmlComponentJS) + +#endif // QMLCOMPONENTJS_P_H diff --git a/src/declarative/qml/qmlcomponentjs_p_p.h b/src/declarative/qml/qmlcomponentjs_p_p.h new file mode 100644 index 0000000..47ce491 --- /dev/null +++ b/src/declarative/qml/qmlcomponentjs_p_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLCOMPONENTJS_P_P_H +#define QMLCOMPONENTJS_P_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlcomponent.h" +#include "qmlcomponentjs_p.h" +#include "qmlcomponent_p.h" + +QT_BEGIN_NAMESPACE + +class QmlContext; +class QmlComponentJSPrivate : public QmlComponentPrivate +{ + Q_DECLARE_PUBLIC(QmlComponentJS) +public: + QmlComponentJSPrivate() : QmlComponentPrivate(), + prevStatus(QmlComponentJS::Null), ctxt(0) + { } + + QmlComponent::Status prevStatus; + QmlContext* ctxt; +}; + +QT_END_NAMESPACE + +#endif // QMLCOMPONENTJS_P_P_H diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 69cc542..b478618 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -71,7 +71,7 @@ #include #include #include -#include +#include "private/qmlcomponentjs_p.h" #include "private/qmlmetaproperty_p.h" #include #include -- cgit v0.12