summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/parser/javascript.g10
-rw-r--r--src/declarative/qml/parser/javascriptengine_p.cpp1
-rw-r--r--src/declarative/qml/parser/javascriptlexer.cpp64
-rw-r--r--src/declarative/qml/parser/javascriptparser.cpp5
-rw-r--r--src/declarative/qml/parser/javascriptparser_p.h5
-rw-r--r--src/declarative/qml/qmlscriptparser.cpp7
6 files changed, 46 insertions, 46 deletions
diff --git a/src/declarative/qml/parser/javascript.g b/src/declarative/qml/parser/javascript.g
index 53db3d9..14ab6b3 100644
--- a/src/declarative/qml/parser/javascript.g
+++ b/src/declarative/qml/parser/javascript.g
@@ -266,10 +266,10 @@ public:
};
public:
- Parser();
+ Parser(Engine *engine);
~Parser();
- bool parse(Engine *driver);
+ bool parse();
AST::UiProgram *ast()
{ return program; }
@@ -306,6 +306,7 @@ protected:
{ return location_stack [tos + index - 1]; }
protected:
+ Engine *driver;
int tos;
int stack_size;
Value *sym_stack;
@@ -373,7 +374,8 @@ inline static bool automatic(Engine *driver, int token)
}
-Parser::Parser():
+Parser::Parser(Engine *engine):
+ driver(engine),
tos(0),
stack_size(0),
sym_stack(0),
@@ -403,7 +405,7 @@ static inline AST::SourceLocation location(Lexer *lexer)
return loc;
}
-bool Parser::parse(Engine *driver)
+bool Parser::parse()
{
Lexer *lexer = driver->lexer();
bool hadErrors = false;
diff --git a/src/declarative/qml/parser/javascriptengine_p.cpp b/src/declarative/qml/parser/javascriptengine_p.cpp
index 679202c..5debfd3 100644
--- a/src/declarative/qml/parser/javascriptengine_p.cpp
+++ b/src/declarative/qml/parser/javascriptengine_p.cpp
@@ -72,6 +72,7 @@ QString Ecma::RegExp::flagsToString(int flags)
NodePool::NodePool(const QString &fileName, Engine *engine)
: m_fileName(fileName), m_engine(engine)
{
+ m_engine->setNodePool(this);
}
NodePool::~NodePool()
diff --git a/src/declarative/qml/parser/javascriptlexer.cpp b/src/declarative/qml/parser/javascriptlexer.cpp
index a0081c7..7455b87 100644
--- a/src/declarative/qml/parser/javascriptlexer.cpp
+++ b/src/declarative/qml/parser/javascriptlexer.cpp
@@ -44,13 +44,6 @@
#endif
#include "javascriptengine_p.h"
-
-
-
-
-
-
-
#include "javascriptlexer_p.h"
#include "javascriptgrammar_p.h"
@@ -76,7 +69,9 @@ namespace JavaScript {
extern double integerFromString(const char *buf, int size, int radix);
}
-JavaScript::Lexer::Lexer(Engine *eng)
+using namespace JavaScript;
+
+Lexer::Lexer(Engine *eng)
: driver(eng),
yylineno(0),
done(false),
@@ -101,6 +96,7 @@ JavaScript::Lexer::Lexer(Engine *eng)
parenthesesCount(0),
prohibitAutomaticSemicolon(false)
{
+ driver->setLexer(this);
// allocate space for read buffers
buffer8 = new char[size8];
buffer16 = new QChar[size16];
@@ -109,13 +105,13 @@ JavaScript::Lexer::Lexer(Engine *eng)
}
-JavaScript::Lexer::~Lexer()
+Lexer::~Lexer()
{
delete [] buffer8;
delete [] buffer16;
}
-void JavaScript::Lexer::setCode(const QString &c, int lineno)
+void Lexer::setCode(const QString &c, int lineno)
{
errmsg = QString();
yylineno = lineno;
@@ -135,7 +131,7 @@ void JavaScript::Lexer::setCode(const QString &c, int lineno)
next3 = (length > 3) ? code[3].unicode() : 0;
}
-void JavaScript::Lexer::shift(uint p)
+void Lexer::shift(uint p)
{
while (p--) {
++pos;
@@ -147,13 +143,13 @@ void JavaScript::Lexer::shift(uint p)
}
}
-void JavaScript::Lexer::setDone(State s)
+void Lexer::setDone(State s)
{
state = s;
done = true;
}
-int JavaScript::Lexer::findReservedWord(const QChar *c, int size) const
+int Lexer::findReservedWord(const QChar *c, int size) const
{
switch (size) {
case 2: {
@@ -454,7 +450,7 @@ int JavaScript::Lexer::findReservedWord(const QChar *c, int size) const
return -1;
}
-int JavaScript::Lexer::lex()
+int Lexer::lex()
{
int token = 0;
state = Start;
@@ -772,10 +768,10 @@ int JavaScript::Lexer::lex()
if (state == Number) {
dval = qstrtod(buffer8, 0, 0);
} else if (state == Hex) { // scan hex numbers
- dval = JavaScript::integerFromString(buffer8, pos8, 16);
+ dval = integerFromString(buffer8, pos8, 16);
state = Number;
} else if (state == Octal) { // scan octal number
- dval = JavaScript::integerFromString(buffer8, pos8, 8);
+ dval = integerFromString(buffer8, pos8, 8);
state = Number;
}
@@ -843,18 +839,18 @@ int JavaScript::Lexer::lex()
}
}
-bool JavaScript::Lexer::isWhiteSpace() const
+bool Lexer::isWhiteSpace() const
{
return (current == ' ' || current == '\t' ||
current == 0x0b || current == 0x0c);
}
-bool JavaScript::Lexer::isLineTerminator() const
+bool Lexer::isLineTerminator() const
{
return (current == '\n' || current == '\r');
}
-bool JavaScript::Lexer::isIdentLetter(ushort c)
+bool Lexer::isIdentLetter(ushort c)
{
/* TODO: allow other legitimate unicode chars */
return ((c >= 'a' && c <= 'z')
@@ -863,24 +859,24 @@ bool JavaScript::Lexer::isIdentLetter(ushort c)
|| c == '_');
}
-bool JavaScript::Lexer::isDecimalDigit(ushort c)
+bool Lexer::isDecimalDigit(ushort c)
{
return (c >= '0' && c <= '9');
}
-bool JavaScript::Lexer::isHexDigit(ushort c) const
+bool Lexer::isHexDigit(ushort c) const
{
return ((c >= '0' && c <= '9')
|| (c >= 'a' && c <= 'f')
|| (c >= 'A' && c <= 'F'));
}
-bool JavaScript::Lexer::isOctalDigit(ushort c) const
+bool Lexer::isOctalDigit(ushort c) const
{
return (c >= '0' && c <= '7');
}
-int JavaScript::Lexer::matchPunctuator(ushort c1, ushort c2,
+int Lexer::matchPunctuator(ushort c1, ushort c2,
ushort c3, ushort c4)
{
if (c1 == '>' && c2 == '>' && c3 == '>' && c4 == '=') {
@@ -987,7 +983,7 @@ int JavaScript::Lexer::matchPunctuator(ushort c1, ushort c2,
}
}
-ushort JavaScript::Lexer::singleEscape(ushort c) const
+ushort Lexer::singleEscape(ushort c) const
{
switch(c) {
case 'b':
@@ -1013,13 +1009,13 @@ ushort JavaScript::Lexer::singleEscape(ushort c) const
}
}
-ushort JavaScript::Lexer::convertOctal(ushort c1, ushort c2,
+ushort Lexer::convertOctal(ushort c1, ushort c2,
ushort c3) const
{
return ((c1 - '0') * 64 + (c2 - '0') * 8 + c3 - '0');
}
-unsigned char JavaScript::Lexer::convertHex(ushort c)
+unsigned char Lexer::convertHex(ushort c)
{
if (c >= '0' && c <= '9')
return (c - '0');
@@ -1029,19 +1025,19 @@ unsigned char JavaScript::Lexer::convertHex(ushort c)
return (c - 'A' + 10);
}
-unsigned char JavaScript::Lexer::convertHex(ushort c1, ushort c2)
+unsigned char Lexer::convertHex(ushort c1, ushort c2)
{
return ((convertHex(c1) << 4) + convertHex(c2));
}
-QChar JavaScript::Lexer::convertUnicode(ushort c1, ushort c2,
+QChar Lexer::convertUnicode(ushort c1, ushort c2,
ushort c3, ushort c4)
{
return QChar((convertHex(c3) << 4) + convertHex(c4),
(convertHex(c1) << 4) + convertHex(c2));
}
-void JavaScript::Lexer::record8(ushort c)
+void Lexer::record8(ushort c)
{
Q_ASSERT(c <= 0xff);
@@ -1057,7 +1053,7 @@ void JavaScript::Lexer::record8(ushort c)
buffer8[pos8++] = (char) c;
}
-void JavaScript::Lexer::record16(QChar c)
+void Lexer::record16(QChar c)
{
// enlarge buffer if full
if (pos16 >= size16 - 1) {
@@ -1071,14 +1067,14 @@ void JavaScript::Lexer::record16(QChar c)
buffer16[pos16++] = c;
}
-void JavaScript::Lexer::recordStartPos()
+void Lexer::recordStartPos()
{
startpos = pos;
startlineno = yylineno;
startcolumn = yycolumn;
}
-bool JavaScript::Lexer::scanRegExp(RegExpBodyPrefix prefix)
+bool Lexer::scanRegExp(RegExpBodyPrefix prefix)
{
pos16 = 0;
bool lastWasEscape = false;
@@ -1110,7 +1106,7 @@ bool JavaScript::Lexer::scanRegExp(RegExpBodyPrefix prefix)
flags = 0;
while (isIdentLetter(current)) {
- int flag = JavaScript::Ecma::RegExp::flagFromChar(current);
+ int flag = Ecma::RegExp::flagFromChar(current);
if (flag == 0) {
errmsg = QString::fromLatin1("Invalid regular expression flag '%0'")
.arg(QChar(current));
@@ -1124,7 +1120,7 @@ bool JavaScript::Lexer::scanRegExp(RegExpBodyPrefix prefix)
return true;
}
-void JavaScript::Lexer::syncProhibitAutomaticSemicolon()
+void Lexer::syncProhibitAutomaticSemicolon()
{
if (parenthesesState == BalancedParentheses) {
// we have seen something like "if (foo)", which means we should
diff --git a/src/declarative/qml/parser/javascriptparser.cpp b/src/declarative/qml/parser/javascriptparser.cpp
index 3c853cb..49a4181 100644
--- a/src/declarative/qml/parser/javascriptparser.cpp
+++ b/src/declarative/qml/parser/javascriptparser.cpp
@@ -83,7 +83,8 @@ inline static bool automatic(Engine *driver, int token)
}
-Parser::Parser():
+Parser::Parser(Engine *engine):
+ driver(engine),
tos(0),
stack_size(0),
sym_stack(0),
@@ -113,7 +114,7 @@ static inline AST::SourceLocation location(Lexer *lexer)
return loc;
}
-bool Parser::parse(Engine *driver)
+bool Parser::parse()
{
Lexer *lexer = driver->lexer();
bool hadErrors = false;
diff --git a/src/declarative/qml/parser/javascriptparser_p.h b/src/declarative/qml/parser/javascriptparser_p.h
index 6980cc8..a9f8593 100644
--- a/src/declarative/qml/parser/javascriptparser_p.h
+++ b/src/declarative/qml/parser/javascriptparser_p.h
@@ -121,10 +121,10 @@ public:
};
public:
- Parser();
+ Parser(Engine *engine);
~Parser();
- bool parse(Engine *driver);
+ bool parse();
AST::UiProgram *ast()
{ return program; }
@@ -161,6 +161,7 @@ protected:
{ return location_stack [tos + index - 1]; }
protected:
+ Engine *driver;
int tos;
int stack_size;
Value *sym_stack;
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp
index 10518d7..9d6b018 100644
--- a/src/declarative/qml/qmlscriptparser.cpp
+++ b/src/declarative/qml/qmlscriptparser.cpp
@@ -632,17 +632,16 @@ bool QmlScriptParser::parse(const QByteArray &data, const QUrl &url)
QTextStream stream(data, QIODevice::ReadOnly);
const QString code = stream.readAll();
- Parser parser;
Engine engine;
NodePool nodePool(fileName, &engine);
- engine.setNodePool(&nodePool);
Lexer lexer(&engine);
lexer.setCode(code, /*line = */ 1);
- engine.setLexer(&lexer);
- if (! parser.parse(&engine) || !_errors.isEmpty()) {
+ Parser parser(&engine);
+
+ if (! parser.parse() || !_errors.isEmpty()) {
// Extract errors from the parser
foreach (const DiagnosticMessage &m, parser.diagnosticMessages()) {