Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1144)

Unified Diff: src/preparser.h

Issue 792083002: Add materialized literals for tagged templates in preparser (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Oops. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 847f994efe750fce20afa057c86878c46538f9e2..4dbcc5612b57264697bb817267a8a4a6dae4997f 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -756,6 +756,12 @@ class PreParserExpression {
ExpressionTypeField::encode(kCallExpression));
}
+ static PreParserExpression NoTemplateTag() {
+ return PreParserExpression(TypeField::encode(kExpression) |
+ ExpressionTypeField::encode(
+ kNoTemplateTagExpression));
+ }
+
bool IsIdentifier() const {
return TypeField::decode(code_) == kIdentifierExpression;
}
@@ -809,6 +815,11 @@ class PreParserExpression {
bool IsFunctionLiteral() const { return false; }
bool IsCallNew() const { return false; }
+ bool IsNoTemplateTag() const {
+ return TypeField::decode(code_) == kExpression &&
+ ExpressionTypeField::decode(code_) == kNoTemplateTagExpression;
+ }
+
PreParserExpression AsFunctionLiteral() { return *this; }
bool IsBinaryOperation() const {
@@ -855,7 +866,8 @@ class PreParserExpression {
kThisPropertyExpression,
kPropertyExpression,
kCallExpression,
- kSuperExpression
+ kSuperExpression,
+ kNoTemplateTagExpression
};
explicit PreParserExpression(uint32_t expression_code)
@@ -1398,10 +1410,21 @@ class PreParserTraits {
void AddTemplateSpan(TemplateLiteralState*, bool) {}
void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {}
PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int,
- PreParserExpression) {
+ PreParserExpression tag) {
+ if (IsTaggedTemplate(tag)) {
+ // Emulate generation of array literals for tag callsite
+ // 1st is array of cooked strings, second is array of raw strings
+ MaterializeTemplateCallsiteLiterals();
+ }
return EmptyExpression();
}
- PreParserExpression NoTemplateTag() { return PreParserExpression::Default(); }
+ inline void MaterializeTemplateCallsiteLiterals();
+ PreParserExpression NoTemplateTag() {
+ return PreParserExpression::NoTemplateTag();
+ }
+ static bool IsTaggedTemplate(const PreParserExpression tag) {
+ return !tag.IsNoTemplateTag();
+ }
static AstValueFactory* ast_value_factory() { return NULL; }
void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {}
@@ -1455,7 +1478,7 @@ class PreParser : public ParserBase<PreParserTraits> {
// success (even if parsing failed, the pre-parse data successfully
// captured the syntax error), and false if a stack-overflow happened
// during parsing.
- PreParseResult PreParseProgram() {
+ PreParseResult PreParseProgram(int* materialized_literals = 0) {
PreParserScope scope(scope_, SCRIPT_SCOPE);
PreParserFactory factory(NULL);
FunctionState top_scope(&function_state_, &scope_, &scope, &factory);
@@ -1468,6 +1491,8 @@ class PreParser : public ParserBase<PreParserTraits> {
} else if (scope_->strict_mode() == STRICT) {
CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok);
}
+ if (materialized_literals) *materialized_literals =
+ function_state_->materialized_literal_count();
marja 2014/12/11 11:31:12 Nit: the body is not a one-liner, so add { }.
return kPreParseSuccess;
}
@@ -1565,6 +1590,12 @@ class PreParser : public ParserBase<PreParserTraits> {
};
+void PreParserTraits::MaterializeTemplateCallsiteLiterals() {
+ pre_parser_->function_state_->NextMaterializedLiteralIndex();
+ pre_parser_->function_state_->NextMaterializedLiteralIndex();
+}
+
+
PreParserStatementList PreParser::ParseEagerFunctionBody(
PreParserIdentifier function_name, int pos, Variable* fvar,
Token::Value fvar_init_op, bool is_generator, bool* ok) {
« no previous file with comments | « src/parser.h ('k') | test/cctest/test-parsing.cc » ('j') | test/cctest/test-parsing.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698