Revision: 20965
Author: [email protected]
Date: Fri Apr 25 09:44:20 2014 UTC
Log: Parser: Introduce StatementList + NewStatementList()
Adds new Traits::Type::StatementList definitions both for Parser and
PreParser, and the corresponding NewStatementList() factory function.
This is needed to be able to define in ParserBase parsing functions
that return and manipulate lists of statements.
Moving and renaming PreParser::Statement to PreParserStatement is also
needed so its definition is available earlier for PreParserStatementList
to use it.
[email protected]
Review URL: https://codereview.chromium.org/252423007
Patch from Adrian Perez de Castro <[email protected]>.
http://code.google.com/p/v8/source/detail?r=20965
Modified:
/branches/bleeding_edge/src/parser.h
/branches/bleeding_edge/src/preparser.h
=======================================
--- /branches/bleeding_edge/src/parser.h Tue Apr 15 08:29:24 2014 UTC
+++ /branches/bleeding_edge/src/parser.h Fri Apr 25 09:44:20 2014 UTC
@@ -425,6 +425,7 @@
typedef ObjectLiteral::Property* ObjectLiteralProperty;
typedef ZoneList<v8::internal::Expression*>* ExpressionList;
typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
+ typedef ZoneList<v8::internal::Statement*>* StatementList;
// For constructing objects returned by the traversing functions.
typedef AstNodeFactory<AstConstructionVisitor> Factory;
@@ -592,6 +593,9 @@
ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone*
zone) {
return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone);
}
+ ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone*
zone) {
+ return new(zone) ZoneList<v8::internal::Statement*>(size, zone);
+ }
// Temporary glue; these functions will move to ParserBase.
Expression* ParseV8Intrinsic(bool* ok);
=======================================
--- /branches/bleeding_edge/src/preparser.h Thu Apr 17 09:23:04 2014 UTC
+++ /branches/bleeding_edge/src/preparser.h Fri Apr 25 09:44:20 2014 UTC
@@ -687,6 +687,67 @@
};
+class PreParserStatement {
+ public:
+ static PreParserStatement Default() {
+ return PreParserStatement(kUnknownStatement);
+ }
+
+ static PreParserStatement FunctionDeclaration() {
+ return PreParserStatement(kFunctionDeclaration);
+ }
+
+ // Creates expression statement from expression.
+ // Preserves being an unparenthesized string literal, possibly
+ // "use strict".
+ static PreParserStatement ExpressionStatement(
+ PreParserExpression expression) {
+ if (expression.IsUseStrictLiteral()) {
+ return PreParserStatement(kUseStrictExpressionStatement);
+ }
+ if (expression.IsStringLiteral()) {
+ return PreParserStatement(kStringLiteralExpressionStatement);
+ }
+ return Default();
+ }
+
+ bool IsStringLiteral() {
+ return code_ == kStringLiteralExpressionStatement;
+ }
+
+ bool IsUseStrictLiteral() {
+ return code_ == kUseStrictExpressionStatement;
+ }
+
+ bool IsFunctionDeclaration() {
+ return code_ == kFunctionDeclaration;
+ }
+
+ private:
+ enum Type {
+ kUnknownStatement,
+ kStringLiteralExpressionStatement,
+ kUseStrictExpressionStatement,
+ kFunctionDeclaration
+ };
+
+ explicit PreParserStatement(Type code) : code_(code) {}
+ Type code_;
+};
+
+
+
+// PreParserStatementList doesn't actually store the statements because
+// the PreParser does not need them.
+class PreParserStatementList {
+ public:
+ // These functions make list->Add(some_expression) work as no-ops.
+ PreParserStatementList() {}
+ PreParserStatementList* operator->() { return this; }
+ void Add(PreParserStatement, void*) {}
+};
+
+
class PreParserScope {
public:
explicit PreParserScope(PreParserScope* outer_scope, ScopeType
scope_type)
@@ -830,6 +891,7 @@
typedef PreParserExpression Literal;
typedef PreParserExpressionList ExpressionList;
typedef PreParserExpressionList PropertyList;
+ typedef PreParserStatementList StatementList;
// For constructing objects returned by the traversing functions.
typedef PreParserFactory Factory;
@@ -992,6 +1054,10 @@
static PreParserExpressionList NewExpressionList(int size, void* zone) {
return PreParserExpressionList();
}
+
+ static PreParserStatementList NewStatementList(int size, void* zone) {
+ return PreParserStatementList();
+ }
static PreParserExpressionList NewPropertyList(int size, void* zone) {
return PreParserExpressionList();
@@ -1029,6 +1095,7 @@
public:
typedef PreParserIdentifier Identifier;
typedef PreParserExpression Expression;
+ typedef PreParserStatement Statement;
enum PreParseResult {
kPreParseStackOverflow,
@@ -1090,52 +1157,6 @@
kHasNoInitializers
};
- class Statement {
- public:
- static Statement Default() {
- return Statement(kUnknownStatement);
- }
-
- static Statement FunctionDeclaration() {
- return Statement(kFunctionDeclaration);
- }
-
- // Creates expression statement from expression.
- // Preserves being an unparenthesized string literal, possibly
- // "use strict".
- static Statement ExpressionStatement(Expression expression) {
- if (expression.IsUseStrictLiteral()) {
- return Statement(kUseStrictExpressionStatement);
- }
- if (expression.IsStringLiteral()) {
- return Statement(kStringLiteralExpressionStatement);
- }
- return Default();
- }
-
- bool IsStringLiteral() {
- return code_ == kStringLiteralExpressionStatement;
- }
-
- bool IsUseStrictLiteral() {
- return code_ == kUseStrictExpressionStatement;
- }
-
- bool IsFunctionDeclaration() {
- return code_ == kFunctionDeclaration;
- }
-
- private:
- enum Type {
- kUnknownStatement,
- kStringLiteralExpressionStatement,
- kUseStrictExpressionStatement,
- kFunctionDeclaration
- };
-
- explicit Statement(Type code) : code_(code) {}
- Type code_;
- };
enum SourceElements {
kUnknownSourceElements
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.