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

Side by Side Diff: src/parser.cc

Issue 345573002: Infer whether a variable is assigned (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: A few more tests Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/char-predicates-inl.h" 10 #include "src/char-predicates-inl.h"
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 void ParserTraits::CheckPossibleEvalCall(Expression* expression, 445 void ParserTraits::CheckPossibleEvalCall(Expression* expression,
446 Scope* scope) { 446 Scope* scope) {
447 VariableProxy* callee = expression->AsVariableProxy(); 447 VariableProxy* callee = expression->AsVariableProxy();
448 if (callee != NULL && 448 if (callee != NULL &&
449 callee->IsVariable(parser_->isolate()->factory()->eval_string())) { 449 callee->IsVariable(parser_->isolate()->factory()->eval_string())) {
450 scope->DeclarationScope()->RecordEvalCall(); 450 scope->DeclarationScope()->RecordEvalCall();
451 } 451 }
452 } 452 }
453 453
454 454
455 Expression* ParserTraits::MarkExpressionAsLValue(Expression* expression) { 455 Expression* ParserTraits::MarkExpressionAsAssigned(Expression* expression) {
456 VariableProxy* proxy = expression != NULL 456 VariableProxy* proxy =
457 ? expression->AsVariableProxy() 457 expression != NULL ? expression->AsVariableProxy() : NULL;
458 : NULL; 458 if (proxy != NULL) proxy->set_is_assigned();
459 if (proxy != NULL) proxy->MarkAsLValue();
460 return expression; 459 return expression;
461 } 460 }
462 461
463 462
464 bool ParserTraits::ShortcutNumericLiteralBinaryExpression( 463 bool ParserTraits::ShortcutNumericLiteralBinaryExpression(
465 Expression** x, Expression* y, Token::Value op, int pos, 464 Expression** x, Expression* y, Token::Value op, int pos,
466 AstNodeFactory<AstConstructionVisitor>* factory) { 465 AstNodeFactory<AstConstructionVisitor>* factory) {
467 if ((*x)->AsLiteral() && (*x)->AsLiteral()->value()->IsNumber() && 466 if ((*x)->AsLiteral() && (*x)->AsLiteral()->value()->IsNumber() &&
468 y->AsLiteral() && y->AsLiteral()->value()->IsNumber()) { 467 y->AsLiteral() && y->AsLiteral()->value()->IsNumber()) {
469 double x_val = (*x)->AsLiteral()->value()->Number(); 468 double x_val = (*x)->AsLiteral()->value()->Number();
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 if (allow_harmony_scoping() && strict_mode() == STRICT) { 1707 if (allow_harmony_scoping() && strict_mode() == STRICT) {
1709 // In harmony we treat re-declarations as early errors. See 1708 // In harmony we treat re-declarations as early errors. See
1710 // ES5 16 for a definition of early errors. 1709 // ES5 16 for a definition of early errors.
1711 ParserTraits::ReportMessage("var_redeclaration", name); 1710 ParserTraits::ReportMessage("var_redeclaration", name);
1712 *ok = false; 1711 *ok = false;
1713 return; 1712 return;
1714 } 1713 }
1715 Expression* expression = NewThrowTypeError( 1714 Expression* expression = NewThrowTypeError(
1716 "var_redeclaration", name, declaration->position()); 1715 "var_redeclaration", name, declaration->position());
1717 declaration_scope->SetIllegalRedeclaration(expression); 1716 declaration_scope->SetIllegalRedeclaration(expression);
1717 } else if (mode == VAR) {
1718 var->set_maybe_assigned();
1718 } 1719 }
1719 } 1720 }
1720 1721
1721 // We add a declaration node for every declaration. The compiler 1722 // We add a declaration node for every declaration. The compiler
1722 // will only generate code if necessary. In particular, declarations 1723 // will only generate code if necessary. In particular, declarations
1723 // for inner local variables that do not represent functions won't 1724 // for inner local variables that do not represent functions won't
1724 // result in any generated code. 1725 // result in any generated code.
1725 // 1726 //
1726 // Note that we always add an unresolved proxy even if it's not 1727 // Note that we always add an unresolved proxy even if it's not
1727 // used, simply because we don't know in this method (w/o extra 1728 // used, simply because we don't know in this method (w/o extra
(...skipping 3098 matching lines...) Expand 10 before | Expand all | Expand 10 after
4826 ASSERT(info()->isolate()->has_pending_exception()); 4827 ASSERT(info()->isolate()->has_pending_exception());
4827 } else { 4828 } else {
4828 result = ParseProgram(); 4829 result = ParseProgram();
4829 } 4830 }
4830 } 4831 }
4831 info()->SetFunction(result); 4832 info()->SetFunction(result);
4832 return (result != NULL); 4833 return (result != NULL);
4833 } 4834 }
4834 4835
4835 } } // namespace v8::internal 4836 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698