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

Unified Diff: src/preparser.h

Issue 156423005: Move ParseRegexpLiteral to ParserBase. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Code review (ulan) Created 6 years, 10 months 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.cc ('k') | src/preparser.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 b6a9e8422151cc5ce12308ebd71714039cb53d56..b3f67c9a698a17920f67fd0c0d216ef28ac0bc22 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -225,6 +225,8 @@ class ParserBase : public Traits {
bool* is_set,
bool* ok);
+ typename Traits::ExpressionType ParseRegExpLiteral(bool seen_equal, bool* ok);
+
// Used to detect duplicates in object literals. Each of the values
// kGetterProperty, kSetterProperty and kValueProperty represents
// a type of object literal property. When parsing a property, its
@@ -427,6 +429,7 @@ class PreParserTraits {
typedef PreParser* ParserType;
// Return types for traversing functions.
typedef PreParserIdentifier IdentifierType;
+ typedef PreParserExpression ExpressionType;
explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
@@ -436,6 +439,7 @@ class PreParserTraits {
static bool IsEvalOrArguments(IdentifierType identifier) {
return identifier.IsEvalOrArguments();
}
+ int NextMaterializedLiteralIndex();
// Reporting errors.
void ReportMessageAt(Scanner::Location location,
@@ -449,12 +453,25 @@ class PreParserTraits {
const char* type,
const char* name_opt);
- // Identifiers:
+ // "null" return type creators.
static IdentifierType EmptyIdentifier() {
return PreParserIdentifier::Default();
}
+ static ExpressionType EmptyExpression() {
+ return PreParserExpression::Default();
+ }
+ // Producing data during the recursive descent.
IdentifierType GetSymbol();
+ static IdentifierType NextLiteralString(PretenureFlag tenured) {
+ return PreParserIdentifier::Default();
+ }
+ ExpressionType NewRegExpLiteral(IdentifierType js_pattern,
+ IdentifierType js_flags,
+ int literal_index,
+ int pos) {
+ return PreParserExpression::Default();
+ }
private:
PreParser* pre_parser_;
@@ -616,7 +633,7 @@ class PreParser : public ParserBase<PreParserTraits> {
*variable = this;
}
~Scope() { *variable_ = prev_; }
- void NextMaterializedLiteralIndex() { materialized_literal_count_++; }
+ int NextMaterializedLiteralIndex() { return materialized_literal_count_++; }
void AddProperty() { expected_properties_++; }
ScopeType type() { return type_; }
int expected_properties() { return expected_properties_; }
@@ -701,7 +718,6 @@ class PreParser : public ParserBase<PreParserTraits> {
Expression ParsePrimaryExpression(bool* ok);
Expression ParseArrayLiteral(bool* ok);
Expression ParseObjectLiteral(bool* ok);
- Expression ParseRegExpLiteral(bool seen_equal, bool* ok);
Expression ParseV8Intrinsic(bool* ok);
Arguments ParseArguments(bool* ok);
@@ -848,6 +864,32 @@ ParserBase<Traits>::ParseIdentifierNameOrGetOrSet(bool* is_get,
}
+template <class Traits>
+typename Traits::ExpressionType
+ParserBase<Traits>::ParseRegExpLiteral(bool seen_equal, bool* ok) {
+ int pos = peek_position();
+ if (!scanner()->ScanRegExpPattern(seen_equal)) {
+ Next();
+ ReportMessage("unterminated_regexp", Vector<const char*>::empty());
+ *ok = false;
+ return Traits::EmptyExpression();
+ }
+
+ int literal_index = this->NextMaterializedLiteralIndex();
+
+ typename Traits::IdentifierType js_pattern = this->NextLiteralString(TENURED);
+ if (!scanner()->ScanRegExpFlags()) {
+ Next();
+ ReportMessageAt(scanner()->location(), "invalid_regexp_flags");
+ *ok = false;
+ return Traits::EmptyExpression();
+ }
+ typename Traits::IdentifierType js_flags = this->NextLiteralString(TENURED);
+ Next();
+ return this->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos);
+}
+
+
template <typename Traits>
void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty(
Token::Value property,
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698