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

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: Rebased 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
« no previous file with comments | « src/parser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 847f994efe750fce20afa057c86878c46538f9e2..3b221ac09235654af5ff7fe241b6a507e6839df7 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));
arv (Not doing code reviews) 2014/12/11 15:29:38 Is this the formatting `git cl format` gives you?
caitp (gmail) 2014/12/11 16:14:04 clang-formatter doesn't complain about this becaus
+ }
+
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
arv (Not doing code reviews) 2014/12/11 15:29:38 This comment goes better with PreParserTraits::Mat
+ // 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,9 @@ 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();
+ }
return kPreParseSuccess;
}
@@ -1565,6 +1591,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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698