diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2009-05-14 09:30:40 (GMT) |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2009-05-14 09:30:40 (GMT) |
commit | 96bf1dee730651afa4f763fd5d7d52e49921d214 (patch) | |
tree | 98fca338fb127b69ae9996fb355292fad890af48 /src/declarative/qml | |
parent | e83bf531362a9626ad41b97dd3fbfa39d6665c85 (diff) | |
download | Qt-96bf1dee730651afa4f763fd5d7d52e49921d214.zip Qt-96bf1dee730651afa4f763fd5d7d52e49921d214.tar.gz Qt-96bf1dee730651afa4f763fd5d7d52e49921d214.tar.bz2 |
Protect the QML front-end using the namespace JavaScript.
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/parser/javascript.g | 132 | ||||
-rw-r--r-- | src/declarative/qml/parser/javascriptast_p.h | 88 | ||||
-rw-r--r-- | src/declarative/qml/parser/javascriptengine_p.cpp | 3 | ||||
-rw-r--r-- | src/declarative/qml/parser/javascriptengine_p.h | 56 | ||||
-rw-r--r-- | src/declarative/qml/parser/javascriptlexer_p.h | 12 | ||||
-rw-r--r-- | src/declarative/qml/parser/javascriptnodepool_p.h | 3 | ||||
-rw-r--r-- | src/declarative/qml/parser/javascriptparser.cpp | 26 | ||||
-rw-r--r-- | src/declarative/qml/parser/javascriptparser_p.h | 106 | ||||
-rw-r--r-- | src/declarative/qml/qmlscriptparser.cpp | 4 |
9 files changed, 222 insertions, 208 deletions
diff --git a/src/declarative/qml/parser/javascript.g b/src/declarative/qml/parser/javascript.g index 48e8244..b70774b 100644 --- a/src/declarative/qml/parser/javascript.g +++ b/src/declarative/qml/parser/javascript.g @@ -212,52 +212,55 @@ QT_BEGIN_NAMESPACE class QString; + +namespace JavaScript { + class JavaScriptEnginePrivate; -class JavaScriptNameIdImpl; +class NameId; -class JavaScriptParser: protected $table +class Parser: protected $table { public: union Value { int ival; double dval; - JavaScriptNameIdImpl *sval; - JavaScript::AST::ArgumentList *ArgumentList; - JavaScript::AST::CaseBlock *CaseBlock; - JavaScript::AST::CaseClause *CaseClause; - JavaScript::AST::CaseClauses *CaseClauses; - JavaScript::AST::Catch *Catch; - JavaScript::AST::DefaultClause *DefaultClause; - JavaScript::AST::ElementList *ElementList; - JavaScript::AST::Elision *Elision; - JavaScript::AST::ExpressionNode *Expression; - JavaScript::AST::Finally *Finally; - JavaScript::AST::FormalParameterList *FormalParameterList; - JavaScript::AST::FunctionBody *FunctionBody; - JavaScript::AST::FunctionDeclaration *FunctionDeclaration; - JavaScript::AST::Node *Node; - JavaScript::AST::PropertyName *PropertyName; - JavaScript::AST::PropertyNameAndValueList *PropertyNameAndValueList; - JavaScript::AST::SourceElement *SourceElement; - JavaScript::AST::SourceElements *SourceElements; - JavaScript::AST::Statement *Statement; - JavaScript::AST::StatementList *StatementList; - JavaScript::AST::Block *Block; - JavaScript::AST::VariableDeclaration *VariableDeclaration; - JavaScript::AST::VariableDeclarationList *VariableDeclarationList; - - JavaScript::AST::UiProgram *UiProgram; - JavaScript::AST::UiImportList *UiImportList; - JavaScript::AST::UiImport *UiImport; - JavaScript::AST::UiPublicMember *UiPublicMember; - JavaScript::AST::UiObjectDefinition *UiObjectDefinition; - JavaScript::AST::UiObjectInitializer *UiObjectInitializer; - JavaScript::AST::UiObjectBinding *UiObjectBinding; - JavaScript::AST::UiScriptBinding *UiScriptBinding; - JavaScript::AST::UiArrayBinding *UiArrayBinding; - JavaScript::AST::UiObjectMember *UiObjectMember; - JavaScript::AST::UiObjectMemberList *UiObjectMemberList; - JavaScript::AST::UiQualifiedId *UiQualifiedId; + NameId *sval; + AST::ArgumentList *ArgumentList; + AST::CaseBlock *CaseBlock; + AST::CaseClause *CaseClause; + AST::CaseClauses *CaseClauses; + AST::Catch *Catch; + AST::DefaultClause *DefaultClause; + AST::ElementList *ElementList; + AST::Elision *Elision; + AST::ExpressionNode *Expression; + AST::Finally *Finally; + AST::FormalParameterList *FormalParameterList; + AST::FunctionBody *FunctionBody; + AST::FunctionDeclaration *FunctionDeclaration; + AST::Node *Node; + AST::PropertyName *PropertyName; + AST::PropertyNameAndValueList *PropertyNameAndValueList; + AST::SourceElement *SourceElement; + AST::SourceElements *SourceElements; + AST::Statement *Statement; + AST::StatementList *StatementList; + AST::Block *Block; + AST::VariableDeclaration *VariableDeclaration; + AST::VariableDeclarationList *VariableDeclarationList; + + AST::UiProgram *UiProgram; + AST::UiImportList *UiImportList; + AST::UiImport *UiImport; + AST::UiPublicMember *UiPublicMember; + AST::UiObjectDefinition *UiObjectDefinition; + AST::UiObjectInitializer *UiObjectInitializer; + AST::UiObjectBinding *UiObjectBinding; + AST::UiScriptBinding *UiScriptBinding; + AST::UiArrayBinding *UiArrayBinding; + AST::UiObjectMember *UiObjectMember; + AST::UiObjectMemberList *UiObjectMemberList; + AST::UiQualifiedId *UiQualifiedId; }; struct DiagnosticMessage { @@ -266,7 +269,7 @@ public: DiagnosticMessage() : kind(Error) {} - DiagnosticMessage(Kind kind, const JavaScript::AST::SourceLocation &loc, const QString &message) + DiagnosticMessage(Kind kind, const AST::SourceLocation &loc, const QString &message) : kind(kind), loc(loc), message(message) {} bool isWarning() const @@ -276,17 +279,17 @@ public: { return kind == Error; } Kind kind; - JavaScript::AST::SourceLocation loc; + AST::SourceLocation loc; QString message; }; public: - JavaScriptParser(); - ~JavaScriptParser(); + Parser(); + ~Parser(); bool parse(JavaScriptEnginePrivate *driver); - JavaScript::AST::UiProgram *ast() + AST::UiProgram *ast() { return program; } QList<DiagnosticMessage> diagnosticMessages() const @@ -317,7 +320,7 @@ protected: inline Value &sym(int index) { return sym_stack [tos + index - 1]; } - inline JavaScript::AST::SourceLocation &loc(int index) + inline AST::SourceLocation &loc(int index) { return location_stack [tos + index - 1]; } protected: @@ -325,9 +328,9 @@ protected: int stack_size; Value *sym_stack; int *state_stack; - JavaScript::AST::SourceLocation *location_stack; + AST::SourceLocation *location_stack; - JavaScript::AST::UiProgram *program; + AST::UiProgram *program; // error recovery enum { TOKEN_BUFFER_SIZE = 3 }; @@ -335,12 +338,12 @@ protected: struct SavedToken { int token; double dval; - JavaScript::AST::SourceLocation loc; + AST::SourceLocation loc; }; double yylval; - JavaScript::AST::SourceLocation yylloc; - JavaScript::AST::SourceLocation yyprevlloc; + AST::SourceLocation yylloc; + AST::SourceLocation yyprevlloc; SavedToken token_buffer[TOKEN_BUFFER_SIZE]; SavedToken *first_token; @@ -349,6 +352,9 @@ protected: QList<DiagnosticMessage> diagnostic_messages; }; +} // end of namespace JavaScript + + :/ @@ -365,7 +371,7 @@ using namespace JavaScript; QT_BEGIN_NAMESPACE -void JavaScriptParser::reallocateStack() +void Parser::reallocateStack() { if (! stack_size) stack_size = 128; @@ -385,7 +391,7 @@ inline static bool automatic(JavaScriptEnginePrivate *driver, int token) } -JavaScriptParser::JavaScriptParser(): +Parser::Parser(): tos(0), stack_size(0), sym_stack(0), @@ -396,7 +402,7 @@ JavaScriptParser::JavaScriptParser(): { } -JavaScriptParser::~JavaScriptParser() +Parser::~Parser() { if (stack_size) { qFree(sym_stack); @@ -415,7 +421,7 @@ static inline AST::SourceLocation location(Lexer *lexer) return loc; } -bool JavaScriptParser::parse(JavaScriptEnginePrivate *driver) +bool Parser::parse(JavaScriptEnginePrivate *driver) { Lexer *lexer = driver->lexer(); bool hadErrors = false; @@ -475,7 +481,7 @@ UiProgram: UiImportListOpt UiRootMember ; case $rule_number: { program = makeAstNode<AST::UiProgram> (driver->nodePool(), sym(1).UiImportList, sym(2).UiObjectMemberList->finish()); - sym(1).UiProgram = program; + sym(1).UiProgram = program; } break; ./ @@ -648,7 +654,7 @@ case $rule_number: { UiPropertyType: T_VAR ; /. -case $rule_number: +case $rule_number: ./ UiPropertyType: T_RESERVED_WORD ; /. @@ -663,7 +669,7 @@ UiPropertyType: T_IDENTIFIER ; UiObjectMember: T_SIGNAL T_IDENTIFIER ; /. case $rule_number: { - AST::UiPublicMember *node = makeAstNode<AST::UiPublicMember> (driver->nodePool(), (JavaScriptNameIdImpl *)0, sym(2).sval); + AST::UiPublicMember *node = makeAstNode<AST::UiPublicMember> (driver->nodePool(), (NameId *)0, sym(2).sval); node->type = AST::UiPublicMember::Signal; node->propertyToken = loc(1); node->typeToken = loc(2); @@ -1038,7 +1044,7 @@ case $rule_number: { sym(1).PropertyNameAndValueList, sym(3).PropertyName, sym(5).Expression); node->commaToken = loc(2); node->colonToken = loc(4); - sym(1).Node = node; + sym(1).Node = node; } break; ./ @@ -1047,7 +1053,7 @@ PropertyName: T_IDENTIFIER %prec REDUCE_HERE ; case $rule_number: { AST::IdentifierPropertyName *node = makeAstNode<AST::IdentifierPropertyName> (driver->nodePool(), sym(1).sval); node->propertyNameToken = loc(1); - sym(1).Node = node; + sym(1).Node = node; } break; ./ @@ -1059,7 +1065,7 @@ PropertyName: T_PROPERTY ; case $rule_number: { AST::IdentifierPropertyName *node = makeAstNode<AST::IdentifierPropertyName> (driver->nodePool(), driver->intern(lexer->characterBuffer(), lexer->characterCount())); node->propertyNameToken = loc(1); - sym(1).Node = node; + sym(1).Node = node; } break; ./ @@ -1068,7 +1074,7 @@ PropertyName: T_STRING_LITERAL ; case $rule_number: { AST::StringLiteralPropertyName *node = makeAstNode<AST::StringLiteralPropertyName> (driver->nodePool(), sym(1).sval); node->propertyNameToken = loc(1); - sym(1).Node = node; + sym(1).Node = node; } break; ./ @@ -1077,7 +1083,7 @@ PropertyName: T_NUMERIC_LITERAL ; case $rule_number: { AST::NumericLiteralPropertyName *node = makeAstNode<AST::NumericLiteralPropertyName> (driver->nodePool(), sym(1).dval); node->propertyNameToken = loc(1); - sym(1).Node = node; + sym(1).Node = node; } break; ./ @@ -1086,7 +1092,7 @@ PropertyName: ReservedIdentifier ; case $rule_number: { AST::IdentifierPropertyName *node = makeAstNode<AST::IdentifierPropertyName> (driver->nodePool(), sym(1).sval); node->propertyNameToken = loc(1); - sym(1).Node = node; + sym(1).Node = node; } break; ./ diff --git a/src/declarative/qml/parser/javascriptast_p.h b/src/declarative/qml/parser/javascriptast_p.h index cd47e42..816835e 100644 --- a/src/declarative/qml/parser/javascriptast_p.h +++ b/src/declarative/qml/parser/javascriptast_p.h @@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE #define JAVASCRIPT_DECLARE_AST_NODE(name) \ enum { K = Kind_##name }; -class JavaScriptNameIdImpl; +class NameId; namespace QSOperator // ### rename { @@ -339,7 +339,7 @@ class IdentifierExpression: public ExpressionNode public: JAVASCRIPT_DECLARE_AST_NODE(IdentifierExpression) - IdentifierExpression(JavaScriptNameIdImpl *n): + IdentifierExpression(NameId *n): name (n) { kind = K; } virtual ~IdentifierExpression() {} @@ -353,7 +353,7 @@ public: { return identifierToken; } // attributes - JavaScriptNameIdImpl *name; + NameId *name; SourceLocation identifierToken; }; @@ -444,7 +444,7 @@ class StringLiteral: public ExpressionNode public: JAVASCRIPT_DECLARE_AST_NODE(StringLiteral) - StringLiteral(JavaScriptNameIdImpl *v): + StringLiteral(NameId *v): value (v) { kind = K; } virtual ~StringLiteral() {} @@ -458,7 +458,7 @@ public: { return literalToken; } // attributes: - JavaScriptNameIdImpl *value; + NameId *value; SourceLocation literalToken; }; @@ -467,7 +467,7 @@ class RegExpLiteral: public ExpressionNode public: JAVASCRIPT_DECLARE_AST_NODE(RegExpLiteral) - RegExpLiteral(JavaScriptNameIdImpl *p, int f): + RegExpLiteral(NameId *p, int f): pattern (p), flags (f) { kind = K; } virtual ~RegExpLiteral() {} @@ -481,7 +481,7 @@ public: { return literalToken; } // attributes: - JavaScriptNameIdImpl *pattern; + NameId *pattern; int flags; SourceLocation literalToken; }; @@ -667,7 +667,7 @@ class IdentifierPropertyName: public PropertyName public: JAVASCRIPT_DECLARE_AST_NODE(IdentifierPropertyName) - IdentifierPropertyName(JavaScriptNameIdImpl *n): + IdentifierPropertyName(NameId *n): id (n) { kind = K; } virtual ~IdentifierPropertyName() {} @@ -675,7 +675,7 @@ public: virtual void accept0(Visitor *visitor); // attributes - JavaScriptNameIdImpl *id; + NameId *id; }; class StringLiteralPropertyName: public PropertyName @@ -683,14 +683,14 @@ class StringLiteralPropertyName: public PropertyName public: JAVASCRIPT_DECLARE_AST_NODE(StringLiteralPropertyName) - StringLiteralPropertyName(JavaScriptNameIdImpl *n): + StringLiteralPropertyName(NameId *n): id (n) { kind = K; } virtual ~StringLiteralPropertyName() {} virtual void accept0(Visitor *visitor); // attributes - JavaScriptNameIdImpl *id; + NameId *id; }; class NumericLiteralPropertyName: public PropertyName @@ -739,7 +739,7 @@ class FieldMemberExpression: public ExpressionNode public: JAVASCRIPT_DECLARE_AST_NODE(FieldMemberExpression) - FieldMemberExpression(ExpressionNode *b, JavaScriptNameIdImpl *n): + FieldMemberExpression(ExpressionNode *b, NameId *n): base (b), name (n) { kind = K; } @@ -755,7 +755,7 @@ public: // attributes ExpressionNode *base; - JavaScriptNameIdImpl *name; + NameId *name; SourceLocation dotToken; SourceLocation identifierToken; }; @@ -1288,7 +1288,7 @@ class VariableDeclaration: public Node public: JAVASCRIPT_DECLARE_AST_NODE(VariableDeclaration) - VariableDeclaration(JavaScriptNameIdImpl *n, ExpressionNode *e): + VariableDeclaration(NameId *n, ExpressionNode *e): name (n), expression (e), readOnly(false) { kind = K; } @@ -1297,7 +1297,7 @@ public: virtual void accept0(Visitor *visitor); // attributes - JavaScriptNameIdImpl *name; + NameId *name; ExpressionNode *expression; bool readOnly; SourceLocation identifierToken; @@ -1602,7 +1602,7 @@ class ContinueStatement: public Statement public: JAVASCRIPT_DECLARE_AST_NODE(ContinueStatement) - ContinueStatement(JavaScriptNameIdImpl *l = 0): + ContinueStatement(NameId *l = 0): label (l) { kind = K; } virtual ~ContinueStatement() {} @@ -1616,7 +1616,7 @@ public: { return semicolonToken; } // attributes - JavaScriptNameIdImpl *label; + NameId *label; SourceLocation continueToken; SourceLocation identifierToken; SourceLocation semicolonToken; @@ -1627,7 +1627,7 @@ class BreakStatement: public Statement public: JAVASCRIPT_DECLARE_AST_NODE(BreakStatement) - BreakStatement(JavaScriptNameIdImpl *l = 0): + BreakStatement(NameId *l = 0): label (l) { kind = K; } virtual ~BreakStatement() {} @@ -1641,7 +1641,7 @@ public: { return semicolonToken; } // attributes - JavaScriptNameIdImpl *label; + NameId *label; SourceLocation breakToken; SourceLocation identifierToken; SourceLocation semicolonToken; @@ -1823,7 +1823,7 @@ class LabelledStatement: public Statement public: JAVASCRIPT_DECLARE_AST_NODE(LabelledStatement) - LabelledStatement(JavaScriptNameIdImpl *l, Statement *stmt): + LabelledStatement(NameId *l, Statement *stmt): label (l), statement (stmt) { kind = K; } @@ -1838,7 +1838,7 @@ public: { return statement->lastSourceLocation(); } // attributes - JavaScriptNameIdImpl *label; + NameId *label; Statement *statement; SourceLocation identifierToken; SourceLocation colonToken; @@ -1873,7 +1873,7 @@ class Catch: public Node public: JAVASCRIPT_DECLARE_AST_NODE(Catch) - Catch(JavaScriptNameIdImpl *n, Block *stmt): + Catch(NameId *n, Block *stmt): name (n), statement (stmt) { kind = K; } @@ -1882,7 +1882,7 @@ public: virtual void accept0(Visitor *visitor); // attributes - JavaScriptNameIdImpl *name; + NameId *name; Block *statement; SourceLocation catchToken; SourceLocation lparenToken; @@ -1954,7 +1954,7 @@ class FunctionExpression: public ExpressionNode public: JAVASCRIPT_DECLARE_AST_NODE(FunctionExpression) - FunctionExpression(JavaScriptNameIdImpl *n, FormalParameterList *f, FunctionBody *b): + FunctionExpression(NameId *n, FormalParameterList *f, FunctionBody *b): name (n), formals (f), body (b) { kind = K; } @@ -1969,7 +1969,7 @@ public: { return rbraceToken; } // attributes - JavaScriptNameIdImpl *name; + NameId *name; FormalParameterList *formals; FunctionBody *body; SourceLocation functionToken; @@ -1985,7 +1985,7 @@ class FunctionDeclaration: public FunctionExpression public: JAVASCRIPT_DECLARE_AST_NODE(FunctionDeclaration) - FunctionDeclaration(JavaScriptNameIdImpl *n, FormalParameterList *f, FunctionBody *b): + FunctionDeclaration(NameId *n, FormalParameterList *f, FunctionBody *b): FunctionExpression(n, f, b) { kind = K; } @@ -1999,11 +1999,11 @@ class FormalParameterList: public Node public: JAVASCRIPT_DECLARE_AST_NODE(FormalParameterList) - FormalParameterList(JavaScriptNameIdImpl *n): + FormalParameterList(NameId *n): name (n), next (this) { kind = K; } - FormalParameterList(FormalParameterList *previous, JavaScriptNameIdImpl *n): + FormalParameterList(FormalParameterList *previous, NameId *n): name (n) { kind = K; @@ -2023,7 +2023,7 @@ public: } // attributes - JavaScriptNameIdImpl *name; + NameId *name; FormalParameterList *next; SourceLocation commaToken; SourceLocation identifierToken; @@ -2185,11 +2185,11 @@ class UiQualifiedId: public Node public: JAVASCRIPT_DECLARE_AST_NODE(UiQualifiedId) - UiQualifiedId(JavaScriptNameIdImpl *name) + UiQualifiedId(NameId *name) : next(this), name(name) { kind = K; } - UiQualifiedId(UiQualifiedId *previous, JavaScriptNameIdImpl *name) + UiQualifiedId(UiQualifiedId *previous, NameId *name) : name(name) { kind = K; @@ -2210,7 +2210,7 @@ public: // attributes UiQualifiedId *next; - JavaScriptNameIdImpl *name; + NameId *name; SourceLocation identifierToken; }; @@ -2219,14 +2219,14 @@ class UiImport: public Node public: JAVASCRIPT_DECLARE_AST_NODE(UiImport) - UiImport(JavaScriptNameIdImpl *fileName) + UiImport(NameId *fileName) : fileName(fileName) { kind = K; } virtual void accept0(Visitor *visitor); // attributes - JavaScriptNameIdImpl *fileName; + NameId *fileName; SourceLocation importToken; SourceLocation fileNameToken; SourceLocation semicolonToken; @@ -2324,13 +2324,13 @@ class UiPublicMember: public UiObjectMember public: JAVASCRIPT_DECLARE_AST_NODE(UiPublicMember) - UiPublicMember(JavaScriptNameIdImpl *memberType, - JavaScriptNameIdImpl *name) + UiPublicMember(NameId *memberType, + NameId *name) : type(Property), memberType(memberType), name(name), expression(0), isDefaultMember(false) { kind = K; } - UiPublicMember(JavaScriptNameIdImpl *memberType, - JavaScriptNameIdImpl *name, + UiPublicMember(NameId *memberType, + NameId *name, ExpressionNode *expression) : type(Property), memberType(memberType), name(name), expression(expression), isDefaultMember(false) { kind = K; } @@ -2352,8 +2352,8 @@ public: // attributes enum { Signal, Property } type; - JavaScriptNameIdImpl *memberType; - JavaScriptNameIdImpl *name; + NameId *memberType; + NameId *name; ExpressionNode *expression; bool isDefaultMember; SourceLocation defaultToken; @@ -2369,7 +2369,7 @@ class UiObjectDefinition: public UiObjectMember public: JAVASCRIPT_DECLARE_AST_NODE(UiObjectDefinition) - UiObjectDefinition(JavaScriptNameIdImpl *name, + UiObjectDefinition(NameId *name, UiObjectInitializer *initializer) : name(name), initializer(initializer) { kind = K; } @@ -2388,7 +2388,7 @@ public: virtual void accept0(Visitor *visitor); // attributes - JavaScriptNameIdImpl *name; + NameId *name; UiObjectInitializer *initializer; SourceLocation identifierToken; }; @@ -2435,7 +2435,7 @@ public: JAVASCRIPT_DECLARE_AST_NODE(UiObjectBinding) UiObjectBinding(UiQualifiedId *qualifiedId, - JavaScriptNameIdImpl *name, + NameId *name, UiObjectInitializer *initializer) : qualifiedId(qualifiedId), name(name), @@ -2452,7 +2452,7 @@ public: // attributes UiQualifiedId *qualifiedId; - JavaScriptNameIdImpl *name; + NameId *name; UiObjectInitializer *initializer; SourceLocation colonToken; SourceLocation identifierToken; diff --git a/src/declarative/qml/parser/javascriptengine_p.cpp b/src/declarative/qml/parser/javascriptengine_p.cpp index 56ee76c..ab1e370 100644 --- a/src/declarative/qml/parser/javascriptengine_p.cpp +++ b/src/declarative/qml/parser/javascriptengine_p.cpp @@ -34,6 +34,9 @@ QT_BEGIN_NAMESPACE +uint qHash(const JavaScript::NameId &id) +{ return qHash(id.asString()); } + namespace JavaScript { QString numberToString(double value) diff --git a/src/declarative/qml/parser/javascriptengine_p.h b/src/declarative/qml/parser/javascriptengine_p.h index 7941b27..b768f5e 100644 --- a/src/declarative/qml/parser/javascriptengine_p.h +++ b/src/declarative/qml/parser/javascriptengine_p.h @@ -36,15 +36,19 @@ QT_BEGIN_NAMESPACE namespace JavaScript { +class NameId; +} + +uint qHash(const JavaScript::NameId &id); + +namespace JavaScript { class Node; class Lexer; class NodePool; namespace AST { - class Node; - } // end of namespace AST namespace Ecma { @@ -65,79 +69,75 @@ public: } // end of namespace Ecma -} // end of namespace JavaScript - - -class JavaScriptNameIdImpl +class NameId { QString _text; public: - JavaScriptNameIdImpl(const QChar *u, int s) + NameId(const QChar *u, int s) : _text(u, s) { } const QString asString() const { return _text; } - bool operator == (const JavaScriptNameIdImpl &other) const + bool operator == (const NameId &other) const { return _text == other._text; } - bool operator != (const JavaScriptNameIdImpl &other) const + bool operator != (const NameId &other) const { return _text != other._text; } - bool operator < (const JavaScriptNameIdImpl &other) const + bool operator < (const NameId &other) const { return _text < other._text; } }; -inline uint qHash(const JavaScriptNameIdImpl &id) -{ return qHash(id.asString()); } - class JavaScriptEnginePrivate { - JavaScript::Lexer *_lexer; - JavaScript::NodePool *_nodePool; - JavaScript::AST::Node *_ast; - QSet<JavaScriptNameIdImpl> _literals; + Lexer *_lexer; + NodePool *_nodePool; + AST::Node *_ast; + QSet<NameId> _literals; public: JavaScriptEnginePrivate() : _lexer(0), _nodePool(0), _ast(0) { } - QSet<JavaScriptNameIdImpl> literals() const + QSet<NameId> literals() const { return _literals; } - JavaScriptNameIdImpl *intern(const QChar *u, int s) - { return const_cast<JavaScriptNameIdImpl *>(&*_literals.insert(JavaScriptNameIdImpl(u, s))); } + NameId *intern(const QChar *u, int s) + { return const_cast<NameId *>(&*_literals.insert(NameId(u, s))); } - static QString toString(JavaScriptNameIdImpl *id) + static QString toString(NameId *id) { return id->asString(); } - JavaScript::Lexer *lexer() const + Lexer *lexer() const { return _lexer; } - void setLexer(JavaScript::Lexer *lexer) + void setLexer(Lexer *lexer) { _lexer = lexer; } - JavaScript::NodePool *nodePool() const + NodePool *nodePool() const { return _nodePool; } - void setNodePool(JavaScript::NodePool *nodePool) + void setNodePool(NodePool *nodePool) { _nodePool = nodePool; } - JavaScript::AST::Node *ast() const + AST::Node *ast() const { return _ast; } - JavaScript::AST::Node *changeAbstractSyntaxTree(JavaScript::AST::Node *node) + AST::Node *changeAbstractSyntaxTree(AST::Node *node) { - JavaScript::AST::Node *previousAST = _ast; + AST::Node *previousAST = _ast; _ast = node; return previousAST; } }; +} // end of namespace JavaScript + QT_END_NAMESPACE #endif // JAVASCRIPTENGINE_P_H diff --git a/src/declarative/qml/parser/javascriptlexer_p.h b/src/declarative/qml/parser/javascriptlexer_p.h index e71c10c..55351c4 100644 --- a/src/declarative/qml/parser/javascriptlexer_p.h +++ b/src/declarative/qml/parser/javascriptlexer_p.h @@ -59,11 +59,11 @@ QT_BEGIN_NAMESPACE -class JavaScriptEnginePrivate; -class JavaScriptNameIdImpl; - namespace JavaScript { +class JavaScriptEnginePrivate; +class NameId; + class Lexer { public: @@ -136,7 +136,7 @@ public: bool scanRegExp(RegExpBodyPrefix prefix = NoPrefix); - JavaScriptNameIdImpl *pattern; + NameId *pattern; int flags; State lexerState() const @@ -194,7 +194,7 @@ public: inline int ival() const { return qsyylval.ival; } inline double dval() const { return qsyylval.dval; } - inline JavaScriptNameIdImpl *ustr() const { return qsyylval.ustr; } + inline NameId *ustr() const { return qsyylval.ustr; } const QChar *characterBuffer() const { return buffer16; } int characterCount() const { return pos16; } @@ -219,7 +219,7 @@ private: union { int ival; double dval; - JavaScriptNameIdImpl *ustr; + NameId *ustr; } qsyylval; // current and following unicode characters diff --git a/src/declarative/qml/parser/javascriptnodepool_p.h b/src/declarative/qml/parser/javascriptnodepool_p.h index 3f59123..91b9132 100644 --- a/src/declarative/qml/parser/javascriptnodepool_p.h +++ b/src/declarative/qml/parser/javascriptnodepool_p.h @@ -60,8 +60,6 @@ QT_BEGIN_NAMESPACE -class JavaScriptEnginePrivate; - namespace JavaScript { namespace AST { @@ -70,6 +68,7 @@ class Node; class Code; class CompilationUnit; +class JavaScriptEnginePrivate; template <typename NodeType> inline NodeType *makeAstNode(MemoryPool *storage) diff --git a/src/declarative/qml/parser/javascriptparser.cpp b/src/declarative/qml/parser/javascriptparser.cpp index ed791c8..39e7aba 100644 --- a/src/declarative/qml/parser/javascriptparser.cpp +++ b/src/declarative/qml/parser/javascriptparser.cpp @@ -63,7 +63,7 @@ using namespace JavaScript; QT_BEGIN_NAMESPACE -void JavaScriptParser::reallocateStack() +void Parser::reallocateStack() { if (! stack_size) stack_size = 128; @@ -83,7 +83,7 @@ inline static bool automatic(JavaScriptEnginePrivate *driver, int token) } -JavaScriptParser::JavaScriptParser(): +Parser::Parser(): tos(0), stack_size(0), sym_stack(0), @@ -94,7 +94,7 @@ JavaScriptParser::JavaScriptParser(): { } -JavaScriptParser::~JavaScriptParser() +Parser::~Parser() { if (stack_size) { qFree(sym_stack); @@ -113,7 +113,7 @@ static inline AST::SourceLocation location(Lexer *lexer) return loc; } -bool JavaScriptParser::parse(JavaScriptEnginePrivate *driver) +bool Parser::parse(JavaScriptEnginePrivate *driver) { Lexer *lexer = driver->lexer(); bool hadErrors = false; @@ -166,7 +166,7 @@ bool JavaScriptParser::parse(JavaScriptEnginePrivate *driver) case 0: { program = makeAstNode<AST::UiProgram> (driver->nodePool(), sym(1).UiImportList, sym(2).UiObjectMemberList->finish()); - sym(1).UiProgram = program; + sym(1).UiProgram = program; } break; case 2: { @@ -275,7 +275,7 @@ case 23: { sym(1).Node = node; } break; -case 24: +case 24: case 25: { sym(1).sval = driver->intern(lexer->characterBuffer(), lexer->characterCount()); @@ -283,7 +283,7 @@ case 25: { } case 27: { - AST::UiPublicMember *node = makeAstNode<AST::UiPublicMember> (driver->nodePool(), (JavaScriptNameIdImpl *)0, sym(2).sval); + AST::UiPublicMember *node = makeAstNode<AST::UiPublicMember> (driver->nodePool(), (NameId *)0, sym(2).sval); node->type = AST::UiPublicMember::Signal; node->propertyToken = loc(1); node->typeToken = loc(2); @@ -529,37 +529,37 @@ case 67: { sym(1).PropertyNameAndValueList, sym(3).PropertyName, sym(5).Expression); node->commaToken = loc(2); node->colonToken = loc(4); - sym(1).Node = node; + sym(1).Node = node; } break; case 68: { AST::IdentifierPropertyName *node = makeAstNode<AST::IdentifierPropertyName> (driver->nodePool(), sym(1).sval); node->propertyNameToken = loc(1); - sym(1).Node = node; + sym(1).Node = node; } break; case 69: case 70: { AST::IdentifierPropertyName *node = makeAstNode<AST::IdentifierPropertyName> (driver->nodePool(), driver->intern(lexer->characterBuffer(), lexer->characterCount())); node->propertyNameToken = loc(1); - sym(1).Node = node; + sym(1).Node = node; } break; case 71: { AST::StringLiteralPropertyName *node = makeAstNode<AST::StringLiteralPropertyName> (driver->nodePool(), sym(1).sval); node->propertyNameToken = loc(1); - sym(1).Node = node; + sym(1).Node = node; } break; case 72: { AST::NumericLiteralPropertyName *node = makeAstNode<AST::NumericLiteralPropertyName> (driver->nodePool(), sym(1).dval); node->propertyNameToken = loc(1); - sym(1).Node = node; + sym(1).Node = node; } break; case 73: { AST::IdentifierPropertyName *node = makeAstNode<AST::IdentifierPropertyName> (driver->nodePool(), sym(1).sval); node->propertyNameToken = loc(1); - sym(1).Node = node; + sym(1).Node = node; } break; case 74: diff --git a/src/declarative/qml/parser/javascriptparser_p.h b/src/declarative/qml/parser/javascriptparser_p.h index 5e68fe7..e3e08cb 100644 --- a/src/declarative/qml/parser/javascriptparser_p.h +++ b/src/declarative/qml/parser/javascriptparser_p.h @@ -67,52 +67,55 @@ QT_BEGIN_NAMESPACE class QString; + +namespace JavaScript { + class JavaScriptEnginePrivate; -class JavaScriptNameIdImpl; +class NameId; -class JavaScriptParser: protected JavaScriptGrammar +class Parser: protected JavaScriptGrammar { public: union Value { int ival; double dval; - JavaScriptNameIdImpl *sval; - JavaScript::AST::ArgumentList *ArgumentList; - JavaScript::AST::CaseBlock *CaseBlock; - JavaScript::AST::CaseClause *CaseClause; - JavaScript::AST::CaseClauses *CaseClauses; - JavaScript::AST::Catch *Catch; - JavaScript::AST::DefaultClause *DefaultClause; - JavaScript::AST::ElementList *ElementList; - JavaScript::AST::Elision *Elision; - JavaScript::AST::ExpressionNode *Expression; - JavaScript::AST::Finally *Finally; - JavaScript::AST::FormalParameterList *FormalParameterList; - JavaScript::AST::FunctionBody *FunctionBody; - JavaScript::AST::FunctionDeclaration *FunctionDeclaration; - JavaScript::AST::Node *Node; - JavaScript::AST::PropertyName *PropertyName; - JavaScript::AST::PropertyNameAndValueList *PropertyNameAndValueList; - JavaScript::AST::SourceElement *SourceElement; - JavaScript::AST::SourceElements *SourceElements; - JavaScript::AST::Statement *Statement; - JavaScript::AST::StatementList *StatementList; - JavaScript::AST::Block *Block; - JavaScript::AST::VariableDeclaration *VariableDeclaration; - JavaScript::AST::VariableDeclarationList *VariableDeclarationList; - - JavaScript::AST::UiProgram *UiProgram; - JavaScript::AST::UiImportList *UiImportList; - JavaScript::AST::UiImport *UiImport; - JavaScript::AST::UiPublicMember *UiPublicMember; - JavaScript::AST::UiObjectDefinition *UiObjectDefinition; - JavaScript::AST::UiObjectInitializer *UiObjectInitializer; - JavaScript::AST::UiObjectBinding *UiObjectBinding; - JavaScript::AST::UiScriptBinding *UiScriptBinding; - JavaScript::AST::UiArrayBinding *UiArrayBinding; - JavaScript::AST::UiObjectMember *UiObjectMember; - JavaScript::AST::UiObjectMemberList *UiObjectMemberList; - JavaScript::AST::UiQualifiedId *UiQualifiedId; + NameId *sval; + AST::ArgumentList *ArgumentList; + AST::CaseBlock *CaseBlock; + AST::CaseClause *CaseClause; + AST::CaseClauses *CaseClauses; + AST::Catch *Catch; + AST::DefaultClause *DefaultClause; + AST::ElementList *ElementList; + AST::Elision *Elision; + AST::ExpressionNode *Expression; + AST::Finally *Finally; + AST::FormalParameterList *FormalParameterList; + AST::FunctionBody *FunctionBody; + AST::FunctionDeclaration *FunctionDeclaration; + AST::Node *Node; + AST::PropertyName *PropertyName; + AST::PropertyNameAndValueList *PropertyNameAndValueList; + AST::SourceElement *SourceElement; + AST::SourceElements *SourceElements; + AST::Statement *Statement; + AST::StatementList *StatementList; + AST::Block *Block; + AST::VariableDeclaration *VariableDeclaration; + AST::VariableDeclarationList *VariableDeclarationList; + + AST::UiProgram *UiProgram; + AST::UiImportList *UiImportList; + AST::UiImport *UiImport; + AST::UiPublicMember *UiPublicMember; + AST::UiObjectDefinition *UiObjectDefinition; + AST::UiObjectInitializer *UiObjectInitializer; + AST::UiObjectBinding *UiObjectBinding; + AST::UiScriptBinding *UiScriptBinding; + AST::UiArrayBinding *UiArrayBinding; + AST::UiObjectMember *UiObjectMember; + AST::UiObjectMemberList *UiObjectMemberList; + AST::UiQualifiedId *UiQualifiedId; }; struct DiagnosticMessage { @@ -121,7 +124,7 @@ public: DiagnosticMessage() : kind(Error) {} - DiagnosticMessage(Kind kind, const JavaScript::AST::SourceLocation &loc, const QString &message) + DiagnosticMessage(Kind kind, const AST::SourceLocation &loc, const QString &message) : kind(kind), loc(loc), message(message) {} bool isWarning() const @@ -131,17 +134,17 @@ public: { return kind == Error; } Kind kind; - JavaScript::AST::SourceLocation loc; + AST::SourceLocation loc; QString message; }; public: - JavaScriptParser(); - ~JavaScriptParser(); + Parser(); + ~Parser(); bool parse(JavaScriptEnginePrivate *driver); - JavaScript::AST::UiProgram *ast() + AST::UiProgram *ast() { return program; } QList<DiagnosticMessage> diagnosticMessages() const @@ -172,7 +175,7 @@ protected: inline Value &sym(int index) { return sym_stack [tos + index - 1]; } - inline JavaScript::AST::SourceLocation &loc(int index) + inline AST::SourceLocation &loc(int index) { return location_stack [tos + index - 1]; } protected: @@ -180,9 +183,9 @@ protected: int stack_size; Value *sym_stack; int *state_stack; - JavaScript::AST::SourceLocation *location_stack; + AST::SourceLocation *location_stack; - JavaScript::AST::UiProgram *program; + AST::UiProgram *program; // error recovery enum { TOKEN_BUFFER_SIZE = 3 }; @@ -190,12 +193,12 @@ protected: struct SavedToken { int token; double dval; - JavaScript::AST::SourceLocation loc; + AST::SourceLocation loc; }; double yylval; - JavaScript::AST::SourceLocation yylloc; - JavaScript::AST::SourceLocation yyprevlloc; + AST::SourceLocation yylloc; + AST::SourceLocation yyprevlloc; SavedToken token_buffer[TOKEN_BUFFER_SIZE]; SavedToken *first_token; @@ -204,6 +207,9 @@ protected: QList<DiagnosticMessage> diagnostic_messages; }; +} // end of namespace JavaScript + + #define J_SCRIPT_REGEXPLITERAL_RULE1 52 diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index ff19d25..cd33624 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -632,7 +632,7 @@ bool QmlScriptParser::parse(const QByteArray &data, const QUrl &url) QTextStream stream(data, QIODevice::ReadOnly); const QString code = stream.readAll(); - JavaScriptParser parser; + Parser parser; JavaScriptEnginePrivate driver; NodePool nodePool(fileName, &driver); @@ -645,7 +645,7 @@ bool QmlScriptParser::parse(const QByteArray &data, const QUrl &url) if (! parser.parse(&driver) || !_errors.isEmpty()) { // Extract errors from the parser - foreach (const JavaScriptParser::DiagnosticMessage &m, parser.diagnosticMessages()) { + foreach (const Parser::DiagnosticMessage &m, parser.diagnosticMessages()) { if (m.isWarning()) continue; |