Commit e561e4a5 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Copied new QML parser files from kinetic-declarativeui (875c342), which

has changes to make these files compile in Creator when Qt is compiled
in a namespace.
parent 21d9ede4
......@@ -10,7 +10,8 @@ HEADERS += $$PWD/qmljsast_p.h \
$$PWD/qmljslexer_p.h \
$$PWD/qmljsmemorypool_p.h \
$$PWD/qmljsnodepool_p.h \
$$PWD/qmljsparser_p.h
$$PWD/qmljsparser_p.h \
$$PWD/qmljsglobal_p.h
SOURCES += $$PWD/qmljsast.cpp \
$$PWD/qmljsastvisitor.cpp \
......
......@@ -70,7 +70,7 @@
%token T_REMAINDER_EQ "%=" T_RETURN "return" T_RPAREN ")"
%token T_SEMICOLON ";" T_AUTOMATIC_SEMICOLON T_STAR "*"
%token T_STAR_EQ "*=" T_STRING_LITERAL "string literal"
%token T_PROPERTY "property" T_SIGNAL "signal"
%token T_PROPERTY "property" T_SIGNAL "signal" T_READONLY "readonly"
%token T_SWITCH "switch" T_THIS "this" T_THROW "throw"
%token T_TILDE "~" T_TRY "try" T_TYPEOF "typeof"
%token T_VAR "var" T_VOID "void" T_WHILE "while"
......@@ -80,6 +80,7 @@
%token T_DEBUGGER "debugger"
%token T_RESERVED_WORD "reserved word"
%token T_MULTILINE_STRING_LITERAL "multiline string literal"
%token T_COMMENT "comment"
--- context keywords.
%token T_PUBLIC "public"
......@@ -92,7 +93,7 @@
%token T_FEED_JS_EXPRESSION
%nonassoc SHIFT_THERE
%nonassoc T_IDENTIFIER T_COLON T_SIGNAL T_PROPERTY
%nonassoc T_IDENTIFIER T_COLON T_SIGNAL T_PROPERTY T_READONLY
%nonassoc REDUCE_HERE
%start TopLevel
......@@ -211,15 +212,15 @@
#ifndef QMLJSPARSER_P_H
#define QMLJSPARSER_P_H
#include "qmljsglobal_p.h"
#include "qmljsgrammar_p.h"
#include "qmljsast_p.h"
#include "qmljsengine_p.h"
#include <QtCore/QList>
#include <QtCore/QString>
QT_BEGIN_NAMESPACE
class QString;
QT_QML_BEGIN_NAMESPACE
namespace QmlJS {
......@@ -387,7 +388,7 @@ protected:
using namespace QmlJS;
QT_BEGIN_NAMESPACE
QT_QML_BEGIN_NAMESPACE
void Parser::reallocateStack()
{
......@@ -606,6 +607,7 @@ case $rule_number: {
sym(1).UiImport->versionToken = loc(2);
sym(1).UiImport->asToken = loc(3);
sym(1).UiImport->importIdToken = loc(4);
sym(1).UiImport->importId = sym(4).sval;
sym(1).UiImport->semicolonToken = loc(5);
} break;
./
......@@ -616,6 +618,7 @@ UiImport: UiImportHead T_AS JsIdentifier T_SEMICOLON ;
case $rule_number: {
sym(1).UiImport->asToken = loc(2);
sym(1).UiImport->importIdToken = loc(3);
sym(1).UiImport->importId = sym(3).sval;
sym(1).UiImport->semicolonToken = loc(4);
} break;
./
......@@ -890,6 +893,23 @@ case $rule_number: {
} break;
./
UiObjectMember: T_READONLY T_PROPERTY UiPropertyType T_IDENTIFIER T_COLON Expression T_AUTOMATIC_SEMICOLON ;
UiObjectMember: T_READONLY T_PROPERTY UiPropertyType T_IDENTIFIER T_COLON Expression T_SEMICOLON ;
/.
case $rule_number: {
AST::UiPublicMember *node = makeAstNode<AST::UiPublicMember> (driver->nodePool(), sym(3).sval, sym(4).sval,
sym(6).Expression);
node->isReadonlyMember = true;
node->readonlyToken = loc(1);
node->propertyToken = loc(2);
node->typeToken = loc(3);
node->identifierToken = loc(4);
node->colonToken = loc(5);
node->semicolonToken = loc(7);
sym(1).Node = node;
} break;
./
UiObjectMember: T_DEFAULT T_PROPERTY UiPropertyType T_IDENTIFIER T_COLON Expression T_AUTOMATIC_SEMICOLON ;
UiObjectMember: T_DEFAULT T_PROPERTY UiPropertyType T_IDENTIFIER T_COLON Expression T_SEMICOLON ;
/.
......@@ -941,6 +961,15 @@ case $rule_number: {
}
./
JsIdentifier: T_READONLY ;
/.
case $rule_number: {
QString s = QLatin1String(QmlJSGrammar::spell[T_READONLY]);
sym(1).sval = driver->intern(s.constData(), s.length());
break;
}
./
--------------------------------------------------------------------------------------------------------
-- Expressions
--------------------------------------------------------------------------------------------------------
......@@ -2993,12 +3022,12 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
return false;
}
QT_END_NAMESPACE
QT_QML_END_NAMESPACE
./
/:
QT_END_NAMESPACE
QT_QML_END_NAMESPACE
......
......@@ -54,9 +54,10 @@
//
#include "qmljsastvisitor_p.h"
#include "qmljsglobal_p.h"
#include <QtCore/QString>
QT_BEGIN_NAMESPACE
QT_QML_BEGIN_NAMESPACE
#define QMLJS_DECLARE_AST_NODE(name) \
enum { K = Kind_##name };
......@@ -2480,19 +2481,21 @@ public:
UiPublicMember(NameId *memberType,
NameId *name)
: type(Property), memberType(memberType), name(name), expression(0), isDefaultMember(false), parameters(0)
: type(Property), memberType(memberType), name(name), expression(0), isDefaultMember(false), isReadonlyMember(false), parameters(0)
{ kind = K; }
UiPublicMember(NameId *memberType,
NameId *name,
ExpressionNode *expression)
: type(Property), memberType(memberType), name(name), expression(expression), isDefaultMember(false), parameters(0)
: type(Property), memberType(memberType), name(name), expression(expression), isDefaultMember(false), isReadonlyMember(false), parameters(0)
{ kind = K; }
virtual SourceLocation firstSourceLocation() const
{
if (defaultToken.isValid())
return defaultToken;
else if (readonlyToken.isValid())
return readonlyToken;
return propertyToken;
}
......@@ -2510,8 +2513,10 @@ public:
NameId *name;
ExpressionNode *expression;
bool isDefaultMember;
bool isReadonlyMember;
UiParameterList *parameters;
SourceLocation defaultToken;
SourceLocation readonlyToken;
SourceLocation propertyToken;
SourceLocation typeToken;
SourceLocation identifierToken;
......@@ -2662,6 +2667,6 @@ public:
QT_END_NAMESPACE
QT_QML_END_NAMESPACE
#endif
......@@ -43,6 +43,7 @@
#define QMLJSAST_FWD_P_H
#include <QtCore/qglobal.h>
#include "qmljsglobal_p.h"
//
// W A R N I N G
......@@ -55,16 +56,16 @@
// We mean it.
//
QT_BEGIN_NAMESPACE
QT_QML_BEGIN_NAMESPACE
namespace QmlJS { namespace AST {
class SourceLocation
{
public:
SourceLocation(quint32 offset = 0, quint32 length = 0)
SourceLocation(quint32 offset = 0, quint32 length = 0, quint32 line = 0, quint32 column = 0)
: offset(offset), length(length),
startLine(0), startColumn(0)
startLine(line), startColumn(column)
{ }
bool isValid() const { return length != 0; }
......@@ -182,6 +183,6 @@ class UiSignature;
} } // namespace AST
QT_END_NAMESPACE
QT_QML_END_NAMESPACE
#endif
......@@ -54,8 +54,9 @@
//
#include "qmljsastfwd_p.h"
#include "qmljsglobal_p.h"
QT_BEGIN_NAMESPACE
QT_QML_BEGIN_NAMESPACE
namespace QmlJS { namespace AST {
......@@ -329,6 +330,6 @@ public:
} } // namespace AST
QT_END_NAMESPACE
QT_QML_END_NAMESPACE
#endif // QMLJSASTVISITOR_P_H
......@@ -39,12 +39,13 @@
**
****************************************************************************/
#include "qmljsglobal_p.h"
#include "qmljsengine_p.h"
#include "qmljsnodepool_p.h"
#include <qnumeric.h>
#include <QHash>
QT_BEGIN_NAMESPACE
QT_QML_BEGIN_NAMESPACE
namespace QmlJS {
......@@ -178,6 +179,12 @@ Engine::~Engine()
QSet<NameId> Engine::literals() const
{ return _literals; }
void Engine::addComment(int pos, int len, int line, int col)
{ if (len > 0) _comments.append(QmlJS::AST::SourceLocation(pos, len, line, col)); }
QList<QmlJS::AST::SourceLocation> Engine::comments() const
{ return _comments; }
NameId *Engine::intern(const QChar *u, int s)
{ return const_cast<NameId *>(&*_literals.insert(NameId(u, s))); }
......@@ -200,4 +207,4 @@ void Engine::setNodePool(NodePool *nodePool)
} // end of namespace QmlJS
QT_END_NAMESPACE
QT_QML_END_NAMESPACE
......@@ -56,9 +56,10 @@
#include <QString>
#include <QSet>
#include "qmljsglobal_p.h"
#include "qmljsastfwd_p.h"
QT_BEGIN_NAMESPACE
QT_QML_BEGIN_NAMESPACE
namespace QmlJS {
class NameId
......@@ -143,6 +144,7 @@ class Engine
Lexer *_lexer;
NodePool *_nodePool;
QSet<NameId> _literals;
QList<QmlJS::AST::SourceLocation> _comments;
public:
Engine();
......@@ -150,6 +152,9 @@ public:
QSet<NameId> literals() const;
void addComment(int pos, int len, int line, int col);
QList<QmlJS::AST::SourceLocation> comments() const;
NameId *intern(const QChar *u, int s);
static QString toString(NameId *id);
......@@ -163,6 +168,6 @@ public:
} // end of namespace QmlJS
QT_END_NAMESPACE
QT_QML_END_NAMESPACE
#endif // QMLJSENGINE_P_H
#ifndef QMLJSGLOBAL_P_H
#define QMLJSGLOBAL_P_H
#include <QtCore/qglobal.h>
#ifndef QT_CREATOR
#define QT_QML_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
#define QT_QML_END_NAMESPACE QT_END_NAMESPACE
#else // !QT_CREATOR
#define QT_QML_BEGIN_NAMESPACE
#define QT_QML_END_NAMESPACE
#endif // QT_CREATOR
#endif // QMLJSGLOBAL_P_H
......@@ -10,8 +10,8 @@
** 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.
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
......@@ -22,20 +22,20 @@
** 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
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.1, 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 have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
......@@ -59,21 +59,22 @@ class QmlJSGrammar
public:
enum {
EOF_SYMBOL = 0,
REDUCE_HERE = 94,
SHIFT_THERE = 93,
REDUCE_HERE = 96,
SHIFT_THERE = 95,
T_AND = 1,
T_AND_AND = 2,
T_AND_EQ = 3,
T_AS = 89,
T_AS = 91,
T_AUTOMATIC_SEMICOLON = 62,
T_BREAK = 4,
T_CASE = 5,
T_CATCH = 6,
T_COLON = 7,
T_COMMA = 8,
T_CONST = 83,
T_COMMENT = 88,
T_CONST = 84,
T_CONTINUE = 9,
T_DEBUGGER = 84,
T_DEBUGGER = 85,
T_DEFAULT = 10,
T_DELETE = 11,
T_DIVIDE_ = 12,
......@@ -84,10 +85,10 @@ public:
T_EQ = 17,
T_EQ_EQ = 18,
T_EQ_EQ_EQ = 19,
T_FALSE = 82,
T_FEED_JS_EXPRESSION = 92,
T_FEED_JS_STATEMENT = 91,
T_FEED_UI_PROGRAM = 90,
T_FALSE = 83,
T_FEED_JS_EXPRESSION = 94,
T_FEED_JS_STATEMENT = 93,
T_FEED_UI_PROGRAM = 92,
T_FINALLY = 20,
T_FOR = 21,
T_FUNCTION = 22,
......@@ -99,7 +100,7 @@ public:
T_GT_GT_GT_EQ = 28,
T_IDENTIFIER = 29,
T_IF = 30,
T_IMPORT = 88,
T_IMPORT = 90,
T_IN = 31,
T_INSTANCEOF = 32,
T_LBRACE = 33,
......@@ -112,12 +113,12 @@ public:
T_MINUS = 40,
T_MINUS_EQ = 41,
T_MINUS_MINUS = 42,
T_MULTILINE_STRING_LITERAL = 86,
T_MULTILINE_STRING_LITERAL = 87,
T_NEW = 43,
T_NOT = 44,
T_NOT_EQ = 45,
T_NOT_EQ_EQ = 46,
T_NULL = 80,
T_NULL = 81,
T_NUMERIC_LITERAL = 47,
T_OR = 48,
T_OR_EQ = 49,
......@@ -126,13 +127,14 @@ public:
T_PLUS_EQ = 52,
T_PLUS_PLUS = 53,
T_PROPERTY = 66,
T_PUBLIC = 87,
T_PUBLIC = 89,
T_QUESTION = 54,
T_RBRACE = 55,
T_RBRACKET = 56,
T_READONLY = 68,
T_REMAINDER = 57,
T_REMAINDER_EQ = 58,
T_RESERVED_WORD = 85,
T_RESERVED_WORD = 86,
T_RETURN = 59,
T_RPAREN = 60,
T_SEMICOLON = 61,
......@@ -140,29 +142,29 @@ public:
T_STAR = 63,
T_STAR_EQ = 64,
T_STRING_LITERAL = 65,
T_SWITCH = 68,
T_THIS = 69,
T_THROW = 70,
T_TILDE = 71,
T_TRUE = 81,
T_TRY = 72,
T_TYPEOF = 73,
T_VAR = 74,
T_VOID = 75,
T_WHILE = 76,
T_WITH = 77,
T_XOR = 78,
T_XOR_EQ = 79,
ACCEPT_STATE = 612,
RULE_COUNT = 334,
STATE_COUNT = 613,
TERMINAL_COUNT = 95,
T_SWITCH = 69,
T_THIS = 70,
T_THROW = 71,
T_TILDE = 72,
T_TRUE = 82,
T_TRY = 73,
T_TYPEOF = 74,
T_VAR = 75,
T_VOID = 76,
T_WHILE = 77,
T_WITH = 78,
T_XOR = 79,
T_XOR_EQ = 80,
ACCEPT_STATE = 621,
RULE_COUNT = 337,
STATE_COUNT = 622,
TERMINAL_COUNT = 97,
NON_TERMINAL_COUNT = 105,
GOTO_INDEX_OFFSET = 613,
GOTO_INFO_OFFSET = 2434,
GOTO_CHECK_OFFSET = 2434
GOTO_INDEX_OFFSET = 622,
GOTO_INFO_OFFSET = 2402,
GOTO_CHECK_OFFSET = 2402
};
static const char *const spell [];
......
......@@ -43,6 +43,7 @@
#include "config.h"
#endif
#include "qmljsglobal_p.h"
#include "qmljsengine_p.h"
#include "qmljslexer_p.h"
#include "qmljsgrammar_p.h"
......@@ -52,7 +53,7 @@
#include <stdio.h>
#include <string.h>
QT_BEGIN_NAMESPACE
QT_QML_BEGIN_NAMESPACE
extern double qstrtod(const char *s00, char const **se, bool *ok);
......@@ -71,7 +72,7 @@ extern double integerFromString(const char *buf, int size, int radix);
using namespace QmlJS;
Lexer::Lexer(Engine *eng)
Lexer::Lexer(Engine *eng, bool tokenizeComments)
: driver(eng),
yylineno(0),
done(false),
......@@ -94,7 +95,8 @@ Lexer::Lexer(Engine *eng)
check_reserved(true),
parenthesesState(IgnoreParentheses),
parenthesesCount(0),
prohibitAutomaticSemicolon(false)
prohibitAutomaticSemicolon(false),
tokenizeComments(tokenizeComments)
{
driver->setLexer(this);
// allocate space for read buffers
......@@ -381,6 +383,11 @@ int Lexer::findReservedWord(const QChar *c, int size) const
&& c[4] == QLatin1Char('e') && c[5] == QLatin1Char('r')
&& c[6] == QLatin1Char('t') && c[7] == QLatin1Char('y'))
return QmlJSGrammar::T_PROPERTY;
else if (c[0] == QLatin1Char('r') && c[1] == QLatin1Char('e')
&& c[2] == QLatin1Char('a') && c[3] == QLatin1Char('d')
&& c[4] == QLatin1Char('o') && c[5] == QLatin1Char('n')
&& c[6] == QLatin1Char('l') && c[7] == QLatin1Char('y'))
return QmlJSGrammar::T_READONLY;
else if (check_reserved) {
if (c[0] == QLatin1Char('a') && c[1] == QLatin1Char('b')
&& c[2] == QLatin1Char('s') && c[3] == QLatin1Char('t')
......@@ -642,22 +649,28 @@ int Lexer::lex()
setDone(Other);
} else
state = Start;
driver->addComment(startpos, tokenLength(), startlineno, startcolumn);
} else if (current == 0) {
driver->addComment(startpos, tokenLength(), startlineno, startcolumn);
setDone(Eof);
}
break;
case InMultiLineComment:
if (current == 0) {
setDone(Bad);
err = UnclosedComment;
errmsg = QLatin1String("Unclosed comment at end of file");
driver->addComment(startpos, tokenLength(), startlineno, startcolumn);
} else if (isLineTerminator()) {
shiftWindowsLineBreak();
yylineno++;
} else if (current == '*' && next1 == '/') {
state = Start;
shift(1);
driver->addComment(startpos, tokenLength(), startlineno, startcolumn);
}
break;
case InIdentifier:
if (isIdentLetter(current) || isDecimalDigit(current)) {
......@@ -1135,6 +1148,6 @@ void Lexer::syncProhibitAutomaticSemicolon()
}
}
QT_END_NAMESPACE
QT_QML_END_NAMESPACE
......@@ -55,9 +55,9 @@
#include <QtCore/QString>
#include "qmljsglobal_p.h"
QT_BEGIN_NAMESPACE
QT_QML_BEGIN_NAMESPACE
namespace QmlJS {
......@@ -67,7 +67,7 @@ class NameId;
class Lexer
{
public:
Lexer(Engine *eng);
Lexer(Engine *eng, bool tokenizeComments = false);
~Lexer();
void setCode(const QString &c, int lineno);
......@@ -239,12 +239,11 @@ private:
ParenthesesState parenthesesState;
int parenthesesCount;
bool prohibitAutomaticSemicolon;
bool tokenizeComments;
};
} // namespace QmlJS
QT_END_NAMESPACE
QT_QML_END_NAMESPACE
#endif
......@@ -57,7 +57,9 @@
#include <QtCore/qshareddata.h>