Commit 2dd4b5f9 authored by marja@chromium.org's avatar marja@chromium.org

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.

R=marja@chromium.org

Review URL: https://codereview.chromium.org/252423007

Patch from Adrian Perez de Castro <aperez@igalia.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20965 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent df07a827
......@@ -425,6 +425,7 @@ class ParserTraits {
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 @@ class ParserTraits {
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);
......
......@@ -687,6 +687,67 @@ class PreParserExpressionList {
};
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 @@ class PreParserTraits {
typedef PreParserExpression Literal;
typedef PreParserExpressionList ExpressionList;
typedef PreParserExpressionList PropertyList;
typedef PreParserStatementList StatementList;
// For constructing objects returned by the traversing functions.
typedef PreParserFactory Factory;
......@@ -993,6 +1055,10 @@ class PreParserTraits {
return PreParserExpressionList();
}
static PreParserStatementList NewStatementList(int size, void* zone) {
return PreParserStatementList();
}
static PreParserExpressionList NewPropertyList(int size, void* zone) {
return PreParserExpressionList();
}
......@@ -1029,6 +1095,7 @@ class PreParser : public ParserBase<PreParserTraits> {
public:
typedef PreParserIdentifier Identifier;
typedef PreParserExpression Expression;
typedef PreParserStatement Statement;
enum PreParseResult {
kPreParseStackOverflow,
......@@ -1090,52 +1157,6 @@ class PreParser : public ParserBase<PreParserTraits> {
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment