Revision: 19909
Author: [email protected]
Date: Thu Mar 13 16:11:26 2014 UTC
Log: Revert "Move ParseAssignmentExpression to ParserBase."
This reverts revision 19908.
Reason: clang doesn't like it.
BUG=
Review URL: https://codereview.chromium.org/199233003
http://code.google.com/p/v8/source/detail?r=19909
Modified:
/branches/bleeding_edge/src/parser.cc
/branches/bleeding_edge/src/parser.h
/branches/bleeding_edge/src/preparser.cc
/branches/bleeding_edge/src/preparser.h
=======================================
--- /branches/bleeding_edge/src/parser.cc Thu Mar 13 16:06:08 2014 UTC
+++ /branches/bleeding_edge/src/parser.cc Thu Mar 13 16:11:26 2014 UTC
@@ -435,59 +435,6 @@
identifier.is_identical_to(
parser_->isolate()->factory()->arguments_string());
}
-
-
-bool ParserTraits::IsThisProperty(Expression* expression) {
- ASSERT(expression != NULL);
- Property* property = expression->AsProperty();
- return property != NULL &&
- property->obj()->AsVariableProxy() != NULL &&
- property->obj()->AsVariableProxy()->is_this();
-}
-
-
-void ParserTraits::CheckAssigningFunctionLiteralToProperty(Expression*
left,
- Expression*
right) {
- ASSERT(left != NULL);
- if (left->AsProperty() != NULL &&
- right->AsFunctionLiteral() != NULL) {
- right->AsFunctionLiteral()->set_pretenure();
- }
-}
-
-
-Expression* ParserTraits::ValidateAssignmentLeftHandSide(
- Expression* expression) const {
- ASSERT(expression != NULL);
- if (!expression->IsValidLeftHandSide()) {
- Handle<String> message =
- parser_->isolate()->factory()->invalid_lhs_in_assignment_string();
- expression = parser_->NewThrowReferenceError(message);
- }
- return expression;
-}
-
-
-Expression* ParserTraits::MarkExpressionAsLValue(Expression* expression) {
- VariableProxy* proxy = expression != NULL
- ? expression->AsVariableProxy()
- : NULL;
- if (proxy != NULL) proxy->MarkAsLValue();
- return expression;
-}
-
-
-void ParserTraits::CheckStrictModeLValue(Expression* expression,
- bool* ok) {
- VariableProxy* lhs = expression != NULL
- ? expression->AsVariableProxy()
- : NULL;
- if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) {
- parser_->ReportMessage("strict_eval_arguments",
- Vector<const char*>::empty());
- *ok = false;
- }
-}
void ParserTraits::ReportMessageAt(Scanner::Location source_location,
@@ -617,6 +564,11 @@
return
factory->NewLiteral(parser_->isolate()->factory()->the_hole_value(),
RelocInfo::kNoPosition);
}
+
+
+Expression* ParserTraits::ParseAssignmentExpression(bool accept_IN, bool*
ok) {
+ return parser_->ParseAssignmentExpression(accept_IN, ok);
+}
Expression* ParserTraits::ParseV8Intrinsic(bool* ok) {
@@ -638,16 +590,6 @@
}
-Expression* ParserTraits::ParseYieldExpression(bool* ok) {
- return parser_->ParseYieldExpression(ok);
-}
-
-
-Expression* ParserTraits::ParseConditionalExpression(bool accept_IN, bool*
ok) {
- return parser_->ParseConditionalExpression(accept_IN, ok);
-}
-
-
Parser::Parser(CompilationInfo* info)
: ParserBase<ParserTraits>(&scanner_,
info->isolate()->stack_guard()->real_climit(),
@@ -2934,6 +2876,85 @@
}
}
+
+// Precedence = 2
+Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) {
+ // AssignmentExpression ::
+ // ConditionalExpression
+ // YieldExpression
+ // LeftHandSideExpression AssignmentOperator AssignmentExpression
+
+ if (peek() == Token::YIELD && is_generator()) {
+ return ParseYieldExpression(ok);
+ }
+
+ if (fni_ != NULL) fni_->Enter();
+ Expression* expression = ParseConditionalExpression(accept_IN, CHECK_OK);
+
+ if (!Token::IsAssignmentOp(peek())) {
+ if (fni_ != NULL) fni_->Leave();
+ // Parsed conditional expression only (no assignment).
+ return expression;
+ }
+
+ // Signal a reference error if the expression is an invalid left-hand
+ // side expression. We could report this as a syntax error here but
+ // for compatibility with JSC we choose to report the error at
+ // runtime.
+ // TODO(ES5): Should change parsing for spec conformance.
+ if (expression == NULL || !expression->IsValidLeftHandSide()) {
+ Handle<String> message =
+ isolate()->factory()->invalid_lhs_in_assignment_string();
+ expression = NewThrowReferenceError(message);
+ }
+
+ if (strict_mode() == STRICT) {
+ // Assignment to eval or arguments is disallowed in strict mode.
+ CheckStrictModeLValue(expression, CHECK_OK);
+ }
+ MarkAsLValue(expression);
+
+ Token::Value op = Next(); // Get assignment operator.
+ int pos = position();
+ Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
+
+ // TODO(1231235): We try to estimate the set of properties set by
+ // constructors. We define a new property whenever there is an
+ // assignment to a property of 'this'. We should probably only add
+ // properties if we haven't seen them before. Otherwise we'll
+ // probably overestimate the number of properties.
+ Property* property = expression ? expression->AsProperty() : NULL;
+ if (op == Token::ASSIGN &&
+ property != NULL &&
+ property->obj()->AsVariableProxy() != NULL &&
+ property->obj()->AsVariableProxy()->is_this()) {
+ function_state_->AddProperty();
+ }
+
+ // If we assign a function literal to a property we pretenure the
+ // literal so it can be added as a constant function property.
+ if (property != NULL && right->AsFunctionLiteral() != NULL) {
+ right->AsFunctionLiteral()->set_pretenure();
+ }
+
+ if (fni_ != NULL) {
+ // Check if the right hand side is a call to avoid inferring a
+ // name if we're dealing with "a = function(){...}();"-like
+ // expression.
+ if ((op == Token::INIT_VAR
+ || op == Token::INIT_CONST_LEGACY
+ || op == Token::ASSIGN)
+ && (right->AsCall() == NULL && right->AsCallNew() == NULL)) {
+ fni_->Infer();
+ } else {
+ fni_->RemoveLastFunction();
+ }
+ fni_->Leave();
+ }
+
+ return factory()->NewAssignment(op, expression, right, pos);
+}
+
Expression* Parser::ParseYieldExpression(bool* ok) {
// YieldExpression ::
@@ -3163,7 +3184,7 @@
// Prefix expression operand in strict mode may not be eval or
arguments.
CheckStrictModeLValue(expression, CHECK_OK);
}
- MarkExpressionAsLValue(expression);
+ MarkAsLValue(expression);
return factory()->NewCountOperation(op,
true /* prefix */,
@@ -3197,7 +3218,7 @@
// Postfix expression operand in strict mode may not be eval or
arguments.
CheckStrictModeLValue(expression, CHECK_OK);
}
- MarkExpressionAsLValue(expression);
+ MarkAsLValue(expression);
Token::Value next = Next();
expression =
@@ -3951,6 +3972,31 @@
return factory()->NewLiteral(
isolate()->factory()->undefined_value(), position);
}
+
+
+void Parser::MarkAsLValue(Expression* expression) {
+ VariableProxy* proxy = expression != NULL
+ ? expression->AsVariableProxy()
+ : NULL;
+
+ if (proxy != NULL) proxy->MarkAsLValue();
+}
+
+
+// Checks LHS expression for assignment and prefix/postfix
increment/decrement
+// in strict mode.
+void Parser::CheckStrictModeLValue(Expression* expression,
+ bool* ok) {
+ ASSERT(strict_mode() == STRICT);
+ VariableProxy* lhs = expression != NULL
+ ? expression->AsVariableProxy()
+ : NULL;
+
+ if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) {
+ ReportMessage("strict_eval_arguments", Vector<const char*>::empty());
+ *ok = false;
+ }
+}
void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) {
=======================================
--- /branches/bleeding_edge/src/parser.h Thu Mar 13 16:06:08 2014 UTC
+++ /branches/bleeding_edge/src/parser.h Thu Mar 13 16:11:26 2014 UTC
@@ -452,9 +452,6 @@
// Helper functions for recursive descent.
bool IsEvalOrArguments(Handle<String> identifier) const;
- // Returns true if the expression is of type "this.foo".
- static bool IsThisProperty(Expression* expression);
-
static bool IsBoilerplateProperty(ObjectLiteral::Property* property) {
return ObjectLiteral::IsBoilerplateProperty(property);
}
@@ -463,8 +460,6 @@
return !string.is_null() && string->AsArrayIndex(index);
}
- // Functions for encapsulating the differences between parsing and
preparsing;
- // operations interleaved with the recursive descent.
static void PushLiteralName(FuncNameInferrer* fni, Handle<String> id) {
fni->PushLiteralName(id);
}
@@ -477,25 +472,6 @@
value->AsFunctionLiteral()->set_pretenure();
}
}
-
- // If we assign a function literal to a property we pretenure the
- // literal so it can be added as a constant function property.
- static void CheckAssigningFunctionLiteralToProperty(Expression* left,
- Expression* right);
-
- // Signal a reference error if the expression is an invalid left-hand
side
- // expression. We could report this as a syntax error but for
compatibility
- // with JSC we choose to report the error at runtime.
- Expression* ValidateAssignmentLeftHandSide(Expression* expression) const;
-
- // Determine if the expression is a variable proxy and mark it as being
used
- // in an assignment or with a increment/decrement operator. This is
currently
- // used on for the statically checking assignments to harmony const
bindings.
- static Expression* MarkExpressionAsLValue(Expression* expression);
-
- // Checks LHS expression for assignment and prefix/postfix
increment/decrement
- // in strict mode.
- void CheckStrictModeLValue(Expression*expression, bool* ok);
// Reporting errors.
void ReportMessageAt(Scanner::Location source_location,
@@ -547,6 +523,7 @@
}
// Temporary glue; these functions will move to ParserBase.
+ Expression* ParseAssignmentExpression(bool accept_IN, bool* ok);
Expression* ParseV8Intrinsic(bool* ok);
FunctionLiteral* ParseFunctionLiteral(
Handle<String> name,
@@ -556,8 +533,6 @@
int function_token_position,
FunctionLiteral::FunctionType type,
bool* ok);
- Expression* ParseYieldExpression(bool* ok);
- Expression* ParseConditionalExpression(bool accept_IN, bool* ok);
private:
Parser* parser_;
@@ -700,6 +675,7 @@
// Support for hamony block scoped bindings.
Block* ParseScopedBlock(ZoneStringList* labels, bool* ok);
+ Expression* ParseAssignmentExpression(bool accept_IN, bool* ok);
Expression* ParseYieldExpression(bool* ok);
Expression* ParseConditionalExpression(bool accept_IN, bool* ok);
Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
@@ -735,6 +711,15 @@
// Get odd-ball literals.
Literal* GetLiteralUndefined(int position);
+ // Determine if the expression is a variable proxy and mark it as being
used
+ // in an assignment or with a increment/decrement operator. This is
currently
+ // used on for the statically checking assignments to harmony const
bindings.
+ void MarkAsLValue(Expression* expression);
+
+ // Strict mode validation of LValue expressions
+ void CheckStrictModeLValue(Expression* expression,
+ bool* ok);
+
// For harmony block scoping mode: Check if the scope has conflicting
var/let
// declarations from different scopes. It covers for example
//
=======================================
--- /branches/bleeding_edge/src/preparser.cc Thu Mar 13 16:06:08 2014 UTC
+++ /branches/bleeding_edge/src/preparser.cc Thu Mar 13 16:11:26 2014 UTC
@@ -55,18 +55,6 @@
namespace v8 {
namespace internal {
-
-void PreParserTraits::CheckStrictModeLValue(PreParserExpression expression,
- bool* ok) {
- if (expression.IsIdentifier() &&
- expression.AsIdentifier().IsEvalOrArguments()) {
- pre_parser_->ReportMessage("strict_eval_arguments",
- Vector<const char*>::empty());
- *ok = false;
- }
-}
-
-
void PreParserTraits::ReportMessageAt(Scanner::Location location,
const char* message,
Vector<const char*> args) {
@@ -121,6 +109,12 @@
}
return PreParserExpression::StringLiteral();
}
+
+
+PreParserExpression PreParserTraits::ParseAssignmentExpression(bool
accept_IN,
+ bool* ok) {
+ return pre_parser_->ParseAssignmentExpression(accept_IN, ok);
+}
PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) {
@@ -142,17 +136,6 @@
}
-PreParserExpression PreParserTraits::ParseYieldExpression(bool* ok) {
- return pre_parser_->ParseYieldExpression(ok);
-}
-
-
-PreParserExpression PreParserTraits::ParseConditionalExpression(bool
accept_IN,
- bool* ok) {
- return pre_parser_->ParseConditionalExpression(accept_IN, ok);
-}
-
-
PreParser::PreParseResult PreParser::PreParseLazyFunction(
StrictMode strict_mode, bool is_generator, ParserRecorder* log) {
log_ = log;
@@ -842,6 +825,47 @@
((void)0
#define DUMMY ) // to make indentation work
#undef DUMMY
+
+
+// Precedence = 2
+PreParser::Expression PreParser::ParseAssignmentExpression(bool accept_IN,
+ bool* ok) {
+ // AssignmentExpression ::
+ // ConditionalExpression
+ // YieldExpression
+ // LeftHandSideExpression AssignmentOperator AssignmentExpression
+
+ if (function_state_->is_generator() && peek() == Token::YIELD) {
+ return ParseYieldExpression(ok);
+ }
+
+ Scanner::Location before = scanner()->peek_location();
+ Expression expression = ParseConditionalExpression(accept_IN, CHECK_OK);
+
+ if (!Token::IsAssignmentOp(peek())) {
+ // Parsed conditional expression only (no assignment).
+ return expression;
+ }
+
+ if (strict_mode() == STRICT &&
+ expression.IsIdentifier() &&
+ expression.AsIdentifier().IsEvalOrArguments()) {
+ Scanner::Location after = scanner()->location();
+ PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos,
+ "strict_eval_arguments", NULL);
+ *ok = false;
+ return Expression::Default();
+ }
+
+ Token::Value op = Next(); // Get assignment operator.
+ ParseAssignmentExpression(accept_IN, CHECK_OK);
+
+ if ((op == Token::ASSIGN) && expression.IsThisProperty()) {
+ function_state_->AddProperty();
+ }
+
+ return Expression::Default();
+}
// Precedence = 3
@@ -915,9 +939,15 @@
return Expression::Default();
} else if (Token::IsCountOp(op)) {
op = Next();
+ Scanner::Location before = scanner()->peek_location();
Expression expression = ParseUnaryExpression(CHECK_OK);
- if (strict_mode() == STRICT) {
- CheckStrictModeLValue(expression, CHECK_OK);
+ if (strict_mode() == STRICT &&
+ expression.IsIdentifier() &&
+ expression.AsIdentifier().IsEvalOrArguments()) {
+ Scanner::Location after = scanner()->location();
+ PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos,
+ "strict_eval_arguments", NULL);
+ *ok = false;
}
return Expression::Default();
} else {
@@ -930,11 +960,18 @@
// PostfixExpression ::
// LeftHandSideExpression ('++' | '--')?
+ Scanner::Location before = scanner()->peek_location();
Expression expression = ParseLeftHandSideExpression(CHECK_OK);
if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
Token::IsCountOp(peek())) {
- if (strict_mode() == STRICT) {
- CheckStrictModeLValue(expression, CHECK_OK);
+ if (strict_mode() == STRICT &&
+ expression.IsIdentifier() &&
+ expression.AsIdentifier().IsEvalOrArguments()) {
+ Scanner::Location after = scanner()->location();
+ PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos,
+ "strict_eval_arguments", NULL);
+ *ok = false;
+ return Expression::Default();
}
Next();
return Expression::Default();
=======================================
--- /branches/bleeding_edge/src/preparser.h Thu Mar 13 16:06:08 2014 UTC
+++ /branches/bleeding_edge/src/preparser.h Thu Mar 13 16:11:26 2014 UTC
@@ -382,8 +382,6 @@
typename Traits::Type::Expression ParseArrayLiteral(bool* ok);
typename Traits::Type::Expression ParseObjectLiteral(bool* ok);
typename Traits::Type::ExpressionList ParseArguments(bool* ok);
- typename Traits::Type::Expression ParseAssignmentExpression(bool
accept_IN,
- bool* ok);
// Used to detect duplicates in object literals. Each of the values
// kGetterProperty, kSetterProperty and kValueProperty represents
@@ -565,14 +563,6 @@
bool IsThisProperty() { return code_ == kThisPropertyExpression; }
bool IsStrictFunction() { return code_ == kStrictFunctionExpression; }
-
- // Dummy implementation for making expression->AsCall() work (see below).
- PreParserExpression* operator->() { return this; }
-
- // These are only used when doing function name inferring, and PreParser
- // doesn't do function name inferring.
- void* AsCall() const { return NULL; }
- void* AsCallNew() const { return NULL; }
private:
// First two/three bits are used as flags.
@@ -693,13 +683,6 @@
int pos) {
return PreParserExpression::Default();
}
-
- PreParserExpression NewAssignment(Token::Value op,
- PreParserExpression left,
- PreParserExpression right,
- int pos) {
- return PreParserExpression::Default();
- }
};
@@ -745,11 +728,6 @@
static bool IsEvalOrArguments(PreParserIdentifier identifier) {
return identifier.IsEvalOrArguments();
}
-
- // Returns true if the expression is of type "this.foo".
- static bool IsThisProperty(PreParserExpression expression) {
- return expression.IsThisProperty();
- }
static bool IsBoilerplateProperty(PreParserExpression property) {
// PreParser doesn't count boilerplate properties.
@@ -760,8 +738,6 @@
return false;
}
- // Functions for encapsulating the differences between parsing and
preparsing;
- // operations interleaved with the recursive descent.
static void PushLiteralName(FuncNameInferrer* fni, PreParserIdentifier
id) {
// PreParser should not use FuncNameInferrer.
ASSERT(false);
@@ -770,29 +746,6 @@
static void CheckFunctionLiteralInsideTopLevelObjectLiteral(
PreParserScope* scope, PreParserExpression value, bool*
has_function) {}
- static void CheckAssigningFunctionLiteralToProperty(
- PreParserExpression left, PreParserExpression right) {}
-
-
- static PreParserExpression ValidateAssignmentLeftHandSide(
- PreParserExpression expression) {
- // Parser generates a runtime error here if the left hand side is not
valid.
- // PreParser doesn't have to.
- return expression;
- }
-
- static PreParserExpression MarkExpressionAsLValue(
- PreParserExpression expression) {
- // TODO(marja): To be able to produce the same errors, the preparser
needs
- // to start tracking which expressions are variables and which are
lvalues.
- return expression;
- }
-
- // Checks LHS expression for assignment and prefix/postfix
increment/decrement
- // in strict mode.
- void CheckStrictModeLValue(PreParserExpression expression, bool* ok);
-
-
// Reporting errors.
void ReportMessageAt(Scanner::Location location,
const char* message,
@@ -862,6 +815,7 @@
}
// Temporary glue; these functions will move to ParserBase.
+ PreParserExpression ParseAssignmentExpression(bool accept_IN, bool* ok);
PreParserExpression ParseV8Intrinsic(bool* ok);
PreParserExpression ParseFunctionLiteral(
PreParserIdentifier name,
@@ -871,8 +825,6 @@
int function_token_position,
FunctionLiteral::FunctionType type,
bool* ok);
- PreParserExpression ParseYieldExpression(bool* ok);
- PreParserExpression ParseConditionalExpression(bool accept_IN, bool* ok);
private:
PreParser* pre_parser_;
@@ -1037,6 +989,8 @@
Statement ParseThrowStatement(bool* ok);
Statement ParseTryStatement(bool* ok);
Statement ParseDebuggerStatement(bool* ok);
+
+ Expression ParseAssignmentExpression(bool accept_IN, bool* ok);
Expression ParseYieldExpression(bool* ok);
Expression ParseConditionalExpression(bool accept_IN, bool* ok);
Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
@@ -1583,75 +1537,6 @@
return result;
}
-// Precedence = 2
-template <class Traits>
-typename Traits::Type::Expression
ParserBase<Traits>::ParseAssignmentExpression(
- bool accept_IN, bool* ok) {
- // AssignmentExpression ::
- // ConditionalExpression
- // YieldExpression
- // LeftHandSideExpression AssignmentOperator AssignmentExpression
-
- if (peek() == Token::YIELD && is_generator()) {
- return this->ParseYieldExpression(ok);
- }
-
- if (fni_ != NULL) fni_->Enter();
- typename Traits::Type::Expression expression =
- this->ParseConditionalExpression(accept_IN, CHECK_OK);
-
- if (!Token::IsAssignmentOp(peek())) {
- if (fni_ != NULL) fni_->Leave();
- // Parsed conditional expression only (no assignment).
- return expression;
- }
-
- // Signal a reference error if the expression is an invalid left-hand
- // side expression. We could report this as a syntax error here but
- // for compatibility with JSC we choose to report the error at
- // runtime.
- // TODO(ES5): Should change parsing for spec conformance.
- expression = this->ValidateAssignmentLeftHandSide(expression);
-
- if (strict_mode() == STRICT) {
- // Assignment to eval or arguments is disallowed in strict mode.
- CheckStrictModeLValue(expression, CHECK_OK);
- }
- expression = this->MarkExpressionAsLValue(expression);
-
- Token::Value op = Next(); // Get assignment operator.
- int pos = position();
- typename Traits::Type::Expression right =
- this->ParseAssignmentExpression(accept_IN, CHECK_OK);
-
- // TODO(1231235): We try to estimate the set of properties set by
- // constructors. We define a new property whenever there is an
- // assignment to a property of 'this'. We should probably only add
- // properties if we haven't seen them before. Otherwise we'll
- // probably overestimate the number of properties.
- if (op == Token::ASSIGN && this->IsThisProperty(expression)) {
- function_state_->AddProperty();
- }
-
- this->CheckAssigningFunctionLiteralToProperty(expression, right);
-
- if (fni_ != NULL) {
- // Check if the right hand side is a call to avoid inferring a
- // name if we're dealing with "a = function(){...}();"-like
- // expression.
- if ((op == Token::INIT_VAR
- || op == Token::INIT_CONST_LEGACY
- || op == Token::ASSIGN)
- && (right->AsCall() == NULL && right->AsCallNew() == NULL)) {
- fni_->Infer();
- } else {
- fni_->RemoveLastFunction();
- }
- fni_->Leave();
- }
-
- return factory()->NewAssignment(op, expression, right, pos);
-}
#undef CHECK_OK
#undef CHECK_OK_CUSTOM
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.