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

Unified Diff: src/preparser.h

Issue 918203002: Get rid of PreParserIdentifier. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: . Created 5 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 4b526f5f1f3c6f039ae730c70b07eccfa8a20444..d9825685595df89b1a50e2805b11a970dcc4d1f3 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -25,11 +25,10 @@ namespace internal {
// - Creating parse tree nodes: Parser generates an AST during the recursive
// descent. PreParser doesn't create a tree. Instead, it passes around minimal
-// data objects (PreParserExpression, PreParserIdentifier etc.) which contain
-// just enough data for the upper layer functions. PreParserFactory is
-// responsible for creating these dummy objects. It provides a similar kind of
-// interface as AstNodeFactory, so ParserBase doesn't need to care which one is
-// used.
+// data objects (PreParserExpression etc.) which contain just enough data for
+// the upper layer functions. PreParserFactory is responsible for creating these
+// dummy objects. It provides a similar kind of interface as AstNodeFactory, so
+// ParserBase doesn't need to care which one is used.
// - Miscellaneous other tasks interleaved with the recursive descent. For
// example, Parser keeps track of which function literals should be marked as
@@ -43,7 +42,6 @@ namespace internal {
// typedef Scope;
// typedef GeneratorVariable;
// // Return types for traversing functions.
-// typedef Identifier;
// typedef Expression;
// typedef FunctionLiteral;
// typedef ClassLiteral;
@@ -62,7 +60,6 @@ class ParserBase : public Traits {
public:
// Shorten type names defined by Traits.
typedef typename Traits::Type::Expression ExpressionT;
- typedef typename Traits::Type::Identifier IdentifierT;
typedef typename Traits::Type::FunctionLiteral FunctionLiteralT;
typedef typename Traits::Type::Literal LiteralT;
typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT;
@@ -304,6 +301,31 @@ class ParserBase : public Traits {
Mode old_mode_;
};
+ bool IsEvalOrArguments(const AstRawString* identifier) const {
+ return identifier == ast_value_factory_->eval_string() ||
+ identifier == ast_value_factory_->arguments_string();
+ }
+
+ const AstRawString* GetSymbol(Scanner* scanner) {
+ const AstRawString* result = scanner->CurrentSymbol(ast_value_factory_);
+ DCHECK(result != NULL);
+ return result;
+ }
+
+ const AstRawString* GetNumberAsSymbol(Scanner* scanner) {
+ double double_value = scanner->DoubleValue();
+ char array[100];
+ const char* string =
+ DoubleToCString(double_value, Vector<char>(array, arraysize(array)));
+ return ast_value_factory_->GetOneByteString(string);
+ }
+
+ const AstRawString* GetNextSymbol(Scanner* scanner) {
+ const AstRawString* result = scanner->NextSymbol(ast_value_factory_);
+ DCHECK(result != NULL);
+ return result;
+ }
+
Scope* NewScope(Scope* parent, ScopeType scope_type,
FunctionKind kind = kNormalFunction) {
DCHECK(ast_value_factory());
@@ -439,10 +461,9 @@ class ParserBase : public Traits {
// Checking the name of a function literal. This has to be done after parsing
// the function, since the function can declare itself strict.
void CheckFunctionName(LanguageMode language_mode, FunctionKind kind,
- IdentifierT function_name,
+ const AstRawString* function_name,
bool function_name_is_strict_reserved,
- const Scanner::Location& function_name_loc,
- bool* ok) {
+ const Scanner::Location& function_name_loc, bool* ok) {
// Property names are never checked.
if (IsConciseMethod(kind) || IsAccessorFunction(kind)) return;
// The function name needs to be checked in strict mode.
@@ -526,28 +547,25 @@ class ParserBase : public Traits {
// allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or
// "arguments" as identifier even in strict mode (this is needed in cases like
// "var foo = eval;").
- IdentifierT ParseIdentifier(
- AllowEvalOrArgumentsAsIdentifier,
- bool* ok);
+ const AstRawString* ParseIdentifier(AllowEvalOrArgumentsAsIdentifier,
+ bool* ok);
// Parses an identifier or a strict mode future reserved word, and indicate
// whether it is strict mode future reserved.
- IdentifierT ParseIdentifierOrStrictReservedWord(
- bool* is_strict_reserved,
- bool* ok);
- IdentifierT ParseIdentifierName(bool* ok);
+ const AstRawString* ParseIdentifierOrStrictReservedWord(
+ bool* is_strict_reserved, bool* ok);
+ const AstRawString* ParseIdentifierName(bool* ok);
// Parses an identifier and determines whether or not it is 'get' or 'set'.
- IdentifierT ParseIdentifierNameOrGetOrSet(bool* is_get,
- bool* is_set,
- bool* ok);
+ const AstRawString* ParseIdentifierNameOrGetOrSet(bool* is_get, bool* is_set,
+ bool* ok);
ExpressionT ParseRegExpLiteral(bool seen_equal, bool* ok);
ExpressionT ParsePrimaryExpression(bool* ok);
ExpressionT ParseExpression(bool accept_IN, bool* ok);
ExpressionT ParseArrayLiteral(bool* ok);
- ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set,
- bool* is_static, bool* is_computed_name,
- bool* ok);
+ ExpressionT ParsePropertyName(const AstRawString** name, bool* is_get,
+ bool* is_set, bool* is_static,
+ bool* is_computed_name, bool* ok);
ExpressionT ParseObjectLiteral(bool* ok);
ObjectLiteralPropertyT ParsePropertyDefinition(
ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends,
@@ -670,101 +688,18 @@ class ParserBase : public Traits {
};
-class PreParserIdentifier {
- public:
- PreParserIdentifier() : type_(kUnknownIdentifier) {}
- static PreParserIdentifier Default() {
- return PreParserIdentifier(kUnknownIdentifier);
- }
- static PreParserIdentifier Eval() {
- return PreParserIdentifier(kEvalIdentifier);
- }
- static PreParserIdentifier Arguments() {
- return PreParserIdentifier(kArgumentsIdentifier);
- }
- static PreParserIdentifier FutureReserved() {
- return PreParserIdentifier(kFutureReservedIdentifier);
- }
- static PreParserIdentifier FutureStrictReserved() {
- return PreParserIdentifier(kFutureStrictReservedIdentifier);
- }
- static PreParserIdentifier Let() {
- return PreParserIdentifier(kLetIdentifier);
- }
- static PreParserIdentifier Static() {
- return PreParserIdentifier(kStaticIdentifier);
- }
- static PreParserIdentifier Yield() {
- return PreParserIdentifier(kYieldIdentifier);
- }
- static PreParserIdentifier Prototype() {
- return PreParserIdentifier(kPrototypeIdentifier);
- }
- static PreParserIdentifier Constructor() {
- return PreParserIdentifier(kConstructorIdentifier);
- }
- bool IsEval() const { return type_ == kEvalIdentifier; }
- bool IsArguments(const AstValueFactory* = NULL) const {
- return type_ == kArgumentsIdentifier;
- }
- bool IsLet() const { return type_ == kLetIdentifier; }
- bool IsStatic() const { return type_ == kStaticIdentifier; }
- bool IsYield() const { return type_ == kYieldIdentifier; }
- bool IsPrototype() const { return type_ == kPrototypeIdentifier; }
- bool IsConstructor() const { return type_ == kConstructorIdentifier; }
- bool IsEvalOrArguments() const {
- return type_ == kEvalIdentifier || type_ == kArgumentsIdentifier;
- }
- bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; }
- bool IsFutureStrictReserved() const {
- return type_ == kFutureStrictReservedIdentifier ||
- type_ == kLetIdentifier || type_ == kStaticIdentifier ||
- type_ == kYieldIdentifier;
- }
- bool IsValidStrictVariable() const { return type_ == kUnknownIdentifier; }
- V8_INLINE bool IsValidArrowParam() const {
- // A valid identifier can be an arrow function parameter
- // except for eval, arguments, yield, and reserved keywords.
- return !(IsEval() || IsArguments() || IsFutureStrictReserved());
- }
-
- // Allow identifier->name()[->length()] to work. The preparser
- // does not need the actual positions/lengths of the identifiers.
- const PreParserIdentifier* operator->() const { return this; }
- const PreParserIdentifier raw_name() const { return *this; }
-
- int position() const { return 0; }
- int length() const { return 0; }
-
- private:
- enum Type {
- kUnknownIdentifier,
- kFutureReservedIdentifier,
- kFutureStrictReservedIdentifier,
- kLetIdentifier,
- kStaticIdentifier,
- kYieldIdentifier,
- kEvalIdentifier,
- kArgumentsIdentifier,
- kPrototypeIdentifier,
- kConstructorIdentifier
- };
- explicit PreParserIdentifier(Type type) : type_(type) {}
- Type type_;
-
- friend class PreParserExpression;
-};
-
-
class PreParserExpression {
public:
static PreParserExpression Default() {
return PreParserExpression(TypeField::encode(kExpression));
}
- static PreParserExpression FromIdentifier(PreParserIdentifier id) {
- return PreParserExpression(TypeField::encode(kIdentifierExpression) |
- IdentifierTypeField::encode(id.type_));
+ static PreParserExpression FromIdentifier(
+ const AstRawString* id, bool is_valid_arrow_function_param) {
+ return PreParserExpression(
+ TypeField::encode(kIdentifierExpression) |
+ IsValidArrowParamListField::encode(is_valid_arrow_function_param),
+ id);
}
static PreParserExpression BinaryOperation(PreParserExpression left,
@@ -782,7 +717,8 @@ class PreParserExpression {
static PreParserExpression EmptyArrowParamList() {
// Any expression for which IsValidArrowParamList() returns true
// will work here.
- return FromIdentifier(PreParserIdentifier::Default());
+ return PreParserExpression(TypeField::encode(kBinaryOperationExpression) |
+ IsValidArrowParamListField::encode(true));
}
static PreParserExpression StringLiteral() {
@@ -836,9 +772,10 @@ class PreParserExpression {
return TypeField::decode(code_) == kIdentifierExpression;
}
- PreParserIdentifier AsIdentifier() const {
+ const AstRawString* AsIdentifier() const {
DCHECK(IsIdentifier());
- return PreParserIdentifier(IdentifierTypeField::decode(code_));
+ DCHECK(identifier_);
+ return identifier_;
}
bool IsStringLiteral() const {
@@ -945,13 +882,12 @@ class PreParserExpression {
kNoTemplateTagExpression
};
- explicit PreParserExpression(uint32_t expression_code)
- : code_(expression_code) {}
+ explicit PreParserExpression(uint32_t expression_code,
+ const AstRawString* identifier = NULL)
+ : code_(expression_code), identifier_(identifier) {}
V8_INLINE bool IsValidArrowParams() const {
- return IsBinaryOperation()
- ? IsValidArrowParamListField::decode(code_)
- : (IsIdentifier() && AsIdentifier().IsValidArrowParam());
+ return IsValidArrowParamListField::decode(code_);
}
// The first four bits are for the Type and Parenthesization.
@@ -966,10 +902,13 @@ class PreParserExpression {
typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField;
typedef BitField<bool, ParenthesizationField::kNext, 1>
IsValidArrowParamListField;
- typedef BitField<PreParserIdentifier::Type, ParenthesizationField::kNext, 10>
- IdentifierTypeField;
uint32_t code_;
+
+ // If an expression is an identifier, this stores it. FIXME(marja): To do
+ // declare variables in scopes properly, PreParserExpression needs to keep
+ // track of multiple identifiers if it's an arrow function parameter list.
+ const AstRawString* identifier_;
};
@@ -1057,7 +996,7 @@ class PreParserStatementList {
class PreParserFactory {
public:
explicit PreParserFactory(void* unused_value_factory) {}
- PreParserExpression NewStringLiteral(PreParserIdentifier identifier,
+ PreParserExpression NewStringLiteral(const AstRawString* identifier,
int pos) {
return PreParserExpression::Default();
}
@@ -1065,10 +1004,9 @@ class PreParserFactory {
int pos) {
return PreParserExpression::Default();
}
- PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern,
- PreParserIdentifier js_flags,
- int literal_index,
- int pos) {
+ PreParserExpression NewRegExpLiteral(const AstRawString* js_pattern,
+ const AstRawString* js_flags,
+ int literal_index, int pos) {
return PreParserExpression::Default();
}
PreParserExpression NewArrayLiteral(PreParserExpressionList values,
@@ -1161,7 +1099,7 @@ class PreParserFactory {
return PreParserStatement::Default();
}
PreParserExpression NewFunctionLiteral(
- PreParserIdentifier name, AstValueFactory* ast_value_factory,
+ const AstRawString* name, AstValueFactory* ast_value_factory,
Scope* scope, PreParserStatementList body, int materialized_literal_count,
int expected_property_count, int handler_count, int parameter_count,
FunctionLiteral::ParameterFlag has_duplicate_parameters,
@@ -1195,10 +1133,8 @@ class PreParserTraits {
typedef void GeneratorVariable;
typedef int AstProperties;
- typedef Vector<PreParserIdentifier> ParameterIdentifierVector;
// Return types for traversing functions.
- typedef PreParserIdentifier Identifier;
typedef PreParserExpression Expression;
typedef PreParserExpression YieldExpression;
typedef PreParserExpression FunctionLiteral;
@@ -1215,19 +1151,6 @@ class PreParserTraits {
explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
- // Helper functions for recursive descent.
- static bool IsEvalOrArguments(PreParserIdentifier identifier) {
- return identifier.IsEvalOrArguments();
- }
-
- static bool IsPrototype(PreParserIdentifier identifier) {
- return identifier.IsPrototype();
- }
-
- static bool IsConstructor(PreParserIdentifier identifier) {
- return identifier.IsConstructor();
- }
-
// Returns true if the expression is of type "this.foo".
static bool IsThisProperty(PreParserExpression expression) {
return expression.IsThisProperty();
@@ -1237,30 +1160,22 @@ class PreParserTraits {
return expression.IsIdentifier();
}
- static PreParserIdentifier AsIdentifier(PreParserExpression expression) {
+ static const AstRawString* AsIdentifier(PreParserExpression expression) {
return expression.AsIdentifier();
}
- static bool IsFutureStrictReserved(PreParserIdentifier identifier) {
- return identifier.IsFutureStrictReserved();
- }
-
static bool IsBoilerplateProperty(PreParserExpression property) {
// PreParser doesn't count boilerplate properties.
return false;
}
- static bool IsArrayIndex(PreParserIdentifier string, uint32_t* index) {
- return false;
- }
-
static PreParserExpression GetPropertyValue(PreParserExpression property) {
return PreParserExpression::Default();
}
// Functions for encapsulating the differences between parsing and preparsing;
// operations interleaved with the recursive descent.
- static void PushLiteralName(FuncNameInferrer* fni, PreParserIdentifier id) {
+ static void PushLiteralName(FuncNameInferrer* fni, const AstRawString* id) {
// PreParser should not use FuncNameInferrer.
UNREACHABLE();
}
@@ -1332,12 +1247,6 @@ class PreParserTraits {
bool is_reference_error = false);
// "null" return type creators.
- static PreParserIdentifier EmptyIdentifier() {
- return PreParserIdentifier::Default();
- }
- static PreParserIdentifier EmptyIdentifierString() {
- return PreParserIdentifier::Default();
- }
static PreParserExpression EmptyExpression() {
return PreParserExpression::Default();
}
@@ -1364,12 +1273,7 @@ class PreParserTraits {
}
// Producing data during the recursive descent.
- PreParserIdentifier GetSymbol(Scanner* scanner);
- PreParserIdentifier GetNumberAsSymbol(Scanner* scanner);
-
- static PreParserIdentifier GetNextSymbol(Scanner* scanner) {
- return PreParserIdentifier::Default();
- }
+ const AstRawString* GetNumberAsSymbol(Scanner* scanner);
static PreParserExpression ThisExpression(Scope* scope,
PreParserFactory* factory) {
@@ -1392,11 +1296,9 @@ class PreParserTraits {
return PreParserExpression::Default();
}
- static PreParserExpression ExpressionFromIdentifier(
- PreParserIdentifier name, int pos, Scope* scope,
- PreParserFactory* factory) {
- return PreParserExpression::FromIdentifier(name);
- }
+ PreParserExpression ExpressionFromIdentifier(const AstRawString* name,
+ int pos, Scope* scope,
+ PreParserFactory* factory);
PreParserExpression ExpressionFromString(int pos,
Scanner* scanner,
@@ -1419,14 +1321,14 @@ class PreParserTraits {
return PreParserExpressionList();
}
- V8_INLINE void SkipLazyFunctionBody(PreParserIdentifier function_name,
+ V8_INLINE void SkipLazyFunctionBody(const AstRawString* function_name,
int* materialized_literal_count,
int* expected_property_count, bool* ok) {
UNREACHABLE();
}
V8_INLINE PreParserStatementList
- ParseEagerFunctionBody(PreParserIdentifier function_name, int pos,
+ ParseEagerFunctionBody(const AstRawString* function_name, int pos,
Variable* fvar, Token::Value fvar_init_op,
FunctionKind kind, bool* ok);
@@ -1469,12 +1371,12 @@ class PreParserTraits {
// Temporary glue; these functions will move to ParserBase.
PreParserExpression ParseV8Intrinsic(bool* ok);
PreParserExpression ParseFunctionLiteral(
- PreParserIdentifier name, Scanner::Location function_name_location,
+ const AstRawString* name, Scanner::Location function_name_location,
bool name_is_strict_reserved, FunctionKind kind,
int function_token_position, FunctionLiteral::FunctionType type,
FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
- PreParserExpression ParseClassLiteral(PreParserIdentifier name,
+ PreParserExpression ParseClassLiteral(const AstRawString* name,
Scanner::Location class_name_location,
bool name_is_strict_reserved, int pos,
bool* ok);
@@ -1498,7 +1400,6 @@ class PreParserTraits {
// it is used) are generally omitted.
class PreParser : public ParserBase<PreParserTraits> {
public:
- typedef PreParserIdentifier Identifier;
typedef PreParserExpression Expression;
typedef PreParserStatement Statement;
@@ -1602,22 +1503,22 @@ class PreParser : public ParserBase<PreParserTraits> {
Expression ParseObjectLiteral(bool* ok);
Expression ParseV8Intrinsic(bool* ok);
- V8_INLINE void SkipLazyFunctionBody(PreParserIdentifier function_name,
+ V8_INLINE void SkipLazyFunctionBody(const AstRawString* function_name,
int* materialized_literal_count,
int* expected_property_count, bool* ok);
V8_INLINE PreParserStatementList
- ParseEagerFunctionBody(PreParserIdentifier function_name, int pos,
+ ParseEagerFunctionBody(const AstRawString* function_name, int pos,
Variable* fvar, Token::Value fvar_init_op,
FunctionKind kind, bool* ok);
Expression ParseFunctionLiteral(
- Identifier name, Scanner::Location function_name_location,
+ const AstRawString* name, Scanner::Location function_name_location,
bool name_is_strict_reserved, FunctionKind kind, int function_token_pos,
FunctionLiteral::FunctionType function_type,
FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
void ParseLazyFunctionLiteralBody(bool* ok);
- PreParserExpression ParseClassLiteral(PreParserIdentifier name,
+ PreParserExpression ParseClassLiteral(const AstRawString* name,
Scanner::Location class_name_location,
bool name_is_strict_reserved, int pos,
bool* ok);
@@ -1633,7 +1534,7 @@ void PreParserTraits::MaterializeTemplateCallsiteLiterals() {
PreParserStatementList PreParser::ParseEagerFunctionBody(
- PreParserIdentifier function_name, int pos, Variable* fvar,
+ const AstRawString* function_name, int pos, Variable* fvar,
Token::Value fvar_init_op, FunctionKind kind, bool* ok) {
ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
@@ -1646,7 +1547,7 @@ PreParserStatementList PreParser::ParseEagerFunctionBody(
PreParserStatementList PreParserTraits::ParseEagerFunctionBody(
- PreParserIdentifier function_name, int pos, Variable* fvar,
+ const AstRawString* function_name, int pos, Variable* fvar,
Token::Value fvar_init_op, FunctionKind kind, bool* ok) {
return pre_parser_->ParseEagerFunctionBody(function_name, pos, fvar,
fvar_init_op, kind, ok);
@@ -1715,37 +1616,37 @@ void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
}
-template<class Traits>
-typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier(
- AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments,
- bool* ok) {
+template <class Traits>
+const AstRawString* ParserBase<Traits>::ParseIdentifier(
+ AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments, bool* ok) {
Token::Value next = Next();
if (next == Token::IDENTIFIER) {
- IdentifierT name = this->GetSymbol(scanner());
+ const AstRawString* name = GetSymbol(scanner());
if (allow_eval_or_arguments == kDontAllowEvalOrArguments &&
is_strict(language_mode()) && this->IsEvalOrArguments(name)) {
ReportMessage("strict_eval_arguments");
*ok = false;
}
- if (name->IsArguments(ast_value_factory())) scope_->RecordArgumentsUsage();
+ if (name == ast_value_factory()->arguments_string()) {
+ scope_->RecordArgumentsUsage();
+ }
return name;
} else if (is_sloppy(language_mode()) &&
(next == Token::FUTURE_STRICT_RESERVED_WORD ||
next == Token::LET || next == Token::STATIC ||
(next == Token::YIELD && !is_generator()))) {
- return this->GetSymbol(scanner());
+ return GetSymbol(scanner());
} else {
this->ReportUnexpectedToken(next);
*ok = false;
- return Traits::EmptyIdentifier();
+ return NULL;
}
}
template <class Traits>
-typename ParserBase<Traits>::IdentifierT ParserBase<
- Traits>::ParseIdentifierOrStrictReservedWord(bool* is_strict_reserved,
- bool* ok) {
+const AstRawString* ParserBase<Traits>::ParseIdentifierOrStrictReservedWord(
+ bool* is_strict_reserved, bool* ok) {
Token::Value next = Next();
if (next == Token::IDENTIFIER) {
*is_strict_reserved = false;
@@ -1756,40 +1657,41 @@ typename ParserBase<Traits>::IdentifierT ParserBase<
} else {
ReportUnexpectedToken(next);
*ok = false;
- return Traits::EmptyIdentifier();
+ return NULL;
}
- IdentifierT name = this->GetSymbol(scanner());
- if (name->IsArguments(ast_value_factory())) scope_->RecordArgumentsUsage();
+ const AstRawString* name = GetSymbol(scanner());
+ if (name == ast_value_factory()->arguments_string()) {
+ scope_->RecordArgumentsUsage();
+ }
return name;
}
template <class Traits>
-typename ParserBase<Traits>::IdentifierT
-ParserBase<Traits>::ParseIdentifierName(bool* ok) {
+const AstRawString* ParserBase<Traits>::ParseIdentifierName(bool* ok) {
Token::Value next = Next();
if (next != Token::IDENTIFIER && next != Token::FUTURE_RESERVED_WORD &&
next != Token::LET && next != Token::STATIC && next != Token::YIELD &&
next != Token::FUTURE_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) {
this->ReportUnexpectedToken(next);
*ok = false;
- return Traits::EmptyIdentifier();
+ return NULL;
}
- IdentifierT name = this->GetSymbol(scanner());
- if (name->IsArguments(ast_value_factory())) scope_->RecordArgumentsUsage();
+ const AstRawString* name = GetSymbol(scanner());
+ if (name == ast_value_factory()->arguments_string()) {
+ scope_->RecordArgumentsUsage();
+ }
return name;
}
template <class Traits>
-typename ParserBase<Traits>::IdentifierT
-ParserBase<Traits>::ParseIdentifierNameOrGetOrSet(bool* is_get,
- bool* is_set,
- bool* ok) {
- IdentifierT result = ParseIdentifierName(ok);
- if (!*ok) return Traits::EmptyIdentifier();
+const AstRawString* ParserBase<Traits>::ParseIdentifierNameOrGetOrSet(
+ bool* is_get, bool* is_set, bool* ok) {
+ const AstRawString* result = ParseIdentifierName(ok);
+ if (!*ok) return NULL;
scanner()->IsGetOrSet(is_get, is_set);
return result;
}
@@ -1808,14 +1710,14 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseRegExpLiteral(
int literal_index = function_state_->NextMaterializedLiteralIndex();
- IdentifierT js_pattern = this->GetNextSymbol(scanner());
+ const AstRawString* js_pattern = GetNextSymbol(scanner());
if (!scanner()->ScanRegExpFlags()) {
Next();
ReportMessage("malformed_regexp_flags");
*ok = false;
return Traits::EmptyExpression();
}
- IdentifierT js_flags = this->GetNextSymbol(scanner());
+ const AstRawString* js_flags = GetNextSymbol(scanner());
Next();
return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos);
}
@@ -1877,7 +1779,8 @@ ParserBase<Traits>::ParsePrimaryExpression(bool* ok) {
case Token::YIELD:
case Token::FUTURE_STRICT_RESERVED_WORD: {
// Using eval or arguments in this context is OK even in strict mode.
- IdentifierT name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
+ const AstRawString* name =
+ ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
result = this->ExpressionFromIdentifier(name, pos, scope_, factory());
break;
}
@@ -1930,7 +1833,7 @@ ParserBase<Traits>::ParsePrimaryExpression(bool* ok) {
break;
}
int class_token_position = position();
- IdentifierT name = this->EmptyIdentifier();
+ const AstRawString* name = NULL;
bool is_strict_reserved_name = false;
Scanner::Location class_name_location = Scanner::Location::invalid();
if (peek_any_identifier()) {
@@ -2020,7 +1923,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral(
template <class Traits>
typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName(
- IdentifierT* name, bool* is_get, bool* is_set, bool* is_static,
+ const AstRawString** name, bool* is_get, bool* is_set, bool* is_static,
bool* is_computed_name, bool* ok) {
Token::Value token = peek();
int pos = peek_position();
@@ -2037,12 +1940,12 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName(
switch (token) {
case Token::STRING:
Consume(Token::STRING);
- *name = this->GetSymbol(scanner());
+ *name = GetSymbol(scanner());
break;
case Token::NUMBER:
Consume(Token::NUMBER);
- *name = this->GetNumberAsSymbol(scanner());
+ *name = GetNumberAsSymbol(scanner());
break;
case Token::LBRACK:
@@ -2065,7 +1968,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName(
}
uint32_t index;
- return this->IsArrayIndex(*name, &index)
+ return (*name)->AsArrayIndex(&index)
? factory()->NewNumberLiteral(index, pos)
: factory()->NewStringLiteral(*name, pos);
}
@@ -2081,7 +1984,7 @@ ParserBase<Traits>::ParsePropertyDefinition(ObjectLiteralCheckerBase* checker,
bool* ok) {
DCHECK(!in_class || is_static || has_seen_constructor != nullptr);
ExpressionT value = this->EmptyExpression();
- IdentifierT name = this->EmptyIdentifier();
+ const AstRawString* name = NULL;
bool is_get = false;
bool is_set = false;
bool name_is_static = false;
@@ -2120,7 +2023,8 @@ ParserBase<Traits>::ParsePropertyDefinition(ObjectLiteralCheckerBase* checker,
FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod
: FunctionKind::kConciseMethod;
- if (in_class && !is_static && this->IsConstructor(name)) {
+ if (in_class && !is_static &&
+ name == ast_value_factory_->constructor_string()) {
*has_seen_constructor = true;
kind = has_extends ? FunctionKind::kSubclassConstructor
: FunctionKind::kBaseConstructor;
@@ -2143,7 +2047,7 @@ ParserBase<Traits>::ParsePropertyDefinition(ObjectLiteralCheckerBase* checker,
is_computed_name, nullptr, ok);
} else if (is_get || is_set) {
// Accessor
- name = this->EmptyIdentifier();
+ name = NULL;
bool dont_care = false;
name_token = peek();
@@ -2629,7 +2533,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(bool* ok) {
case Token::PERIOD: {
Consume(Token::PERIOD);
int pos = position();
- IdentifierT name = ParseIdentifierName(CHECK_OK);
+ const AstRawString* name = ParseIdentifierName(CHECK_OK);
result = factory()->NewProperty(
result, factory()->NewStringLiteral(name, pos), pos);
if (fni_ != NULL) this->PushLiteralName(fni_, name);
@@ -2708,7 +2612,7 @@ ParserBase<Traits>::ParseMemberExpression(bool* ok) {
Consume(Token::FUNCTION);
int function_token_position = position();
bool is_generator = Check(Token::MUL);
- IdentifierT name = this->EmptyIdentifier();
+ const AstRawString* name = NULL;
bool is_strict_reserved_name = false;
Scanner::Location function_name_location = Scanner::Location::invalid();
FunctionLiteral::FunctionType function_type =
@@ -2792,7 +2696,7 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(ExpressionT expression,
case Token::PERIOD: {
Consume(Token::PERIOD);
int pos = position();
- IdentifierT name = ParseIdentifierName(CHECK_OK);
+ const AstRawString* name = ParseIdentifierName(CHECK_OK);
expression = factory()->NewProperty(
expression, factory()->NewStringLiteral(name, pos), pos);
if (fni_ != NULL) {
@@ -2852,13 +2756,12 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos,
(mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation());
if (is_lazily_parsed) {
body = this->NewStatementList(0, zone());
- this->SkipLazyFunctionBody(this->EmptyIdentifier(),
- &materialized_literal_count,
+ this->SkipLazyFunctionBody(NULL, &materialized_literal_count,
&expected_property_count, CHECK_OK);
} else {
- body = this->ParseEagerFunctionBody(
- this->EmptyIdentifier(), RelocInfo::kNoPosition, NULL,
- Token::INIT_VAR, kArrowFunction, CHECK_OK);
+ body = this->ParseEagerFunctionBody(NULL, RelocInfo::kNoPosition, NULL,
+ Token::INIT_VAR, kArrowFunction,
+ CHECK_OK);
materialized_literal_count =
function_state.materialized_literal_count();
expected_property_count = function_state.expected_property_count();
@@ -2899,7 +2802,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos,
}
FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
- this->EmptyIdentifierString(), ast_value_factory(), scope, body,
+ ast_value_factory()->empty_string(), ast_value_factory(), scope, body,
materialized_literal_count, expected_property_count, handler_count,
num_parameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction,
« 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