OLD | NEW |
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/ast/ast.h" | 5 #include "src/ast/ast.h" |
6 | 6 |
7 #include <cmath> // For isfinite. | 7 #include <cmath> // For isfinite. |
8 | 8 |
9 #include "src/ast/prettyprinter.h" | 9 #include "src/ast/prettyprinter.h" |
10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 bool Expression::IsStringLiteral() const { | 56 bool Expression::IsStringLiteral() const { |
57 return IsLiteral() && AsLiteral()->value()->IsString(); | 57 return IsLiteral() && AsLiteral()->value()->IsString(); |
58 } | 58 } |
59 | 59 |
60 | 60 |
61 bool Expression::IsNullLiteral() const { | 61 bool Expression::IsNullLiteral() const { |
62 return IsLiteral() && AsLiteral()->value()->IsNull(); | 62 return IsLiteral() && AsLiteral()->value()->IsNull(); |
63 } | 63 } |
64 | 64 |
65 | 65 bool Expression::IsUndefinedLiteral() const { |
66 bool Expression::IsUndefinedLiteral(Isolate* isolate) const { | |
67 if (IsLiteral() && AsLiteral()->value()->IsUndefined()) { | 66 if (IsLiteral() && AsLiteral()->value()->IsUndefined()) { |
68 return true; | 67 return true; |
69 } | 68 } |
70 | 69 |
71 const VariableProxy* var_proxy = AsVariableProxy(); | 70 const VariableProxy* var_proxy = AsVariableProxy(); |
72 if (var_proxy == NULL) return false; | 71 if (var_proxy == NULL) return false; |
73 Variable* var = var_proxy->var(); | 72 Variable* var = var_proxy->var(); |
74 // The global identifier "undefined" is immutable. Everything | 73 // The global identifier "undefined" is immutable. Everything |
75 // else could be reassigned. | 74 // else could be reassigned. |
76 return var != NULL && var->IsUnallocatedOrGlobalSlot() && | 75 return var != NULL && var->IsUnallocatedOrGlobalSlot() && |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 maybe_unary->op() == Token::VOID && | 661 maybe_unary->op() == Token::VOID && |
663 maybe_unary->expression()->IsLiteral(); | 662 maybe_unary->expression()->IsLiteral(); |
664 } | 663 } |
665 | 664 |
666 | 665 |
667 // Check for the pattern: void <literal> equals <expression> or | 666 // Check for the pattern: void <literal> equals <expression> or |
668 // undefined equals <expression> | 667 // undefined equals <expression> |
669 static bool MatchLiteralCompareUndefined(Expression* left, | 668 static bool MatchLiteralCompareUndefined(Expression* left, |
670 Token::Value op, | 669 Token::Value op, |
671 Expression* right, | 670 Expression* right, |
672 Expression** expr, | 671 Expression** expr) { |
673 Isolate* isolate) { | |
674 if (IsVoidOfLiteral(left) && Token::IsEqualityOp(op)) { | 672 if (IsVoidOfLiteral(left) && Token::IsEqualityOp(op)) { |
675 *expr = right; | 673 *expr = right; |
676 return true; | 674 return true; |
677 } | 675 } |
678 if (left->IsUndefinedLiteral(isolate) && Token::IsEqualityOp(op)) { | 676 if (left->IsUndefinedLiteral() && Token::IsEqualityOp(op)) { |
679 *expr = right; | 677 *expr = right; |
680 return true; | 678 return true; |
681 } | 679 } |
682 return false; | 680 return false; |
683 } | 681 } |
684 | 682 |
685 | 683 bool CompareOperation::IsLiteralCompareUndefined(Expression** expr) { |
686 bool CompareOperation::IsLiteralCompareUndefined( | 684 return MatchLiteralCompareUndefined(left_, op_, right_, expr) || |
687 Expression** expr, Isolate* isolate) { | 685 MatchLiteralCompareUndefined(right_, op_, left_, expr); |
688 return MatchLiteralCompareUndefined(left_, op_, right_, expr, isolate) || | |
689 MatchLiteralCompareUndefined(right_, op_, left_, expr, isolate); | |
690 } | 686 } |
691 | 687 |
692 | 688 |
693 // Check for the pattern: null equals <expression> | 689 // Check for the pattern: null equals <expression> |
694 static bool MatchLiteralCompareNull(Expression* left, | 690 static bool MatchLiteralCompareNull(Expression* left, |
695 Token::Value op, | 691 Token::Value op, |
696 Expression* right, | 692 Expression* right, |
697 Expression** expr) { | 693 Expression** expr) { |
698 if (left->IsNullLiteral() && Token::IsEqualityOp(op)) { | 694 if (left->IsNullLiteral() && Token::IsEqualityOp(op)) { |
699 *expr = right; | 695 *expr = right; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 bool Literal::Match(void* literal1, void* literal2) { | 831 bool Literal::Match(void* literal1, void* literal2) { |
836 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); | 832 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); |
837 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); | 833 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); |
838 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || | 834 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || |
839 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); | 835 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); |
840 } | 836 } |
841 | 837 |
842 | 838 |
843 } // namespace internal | 839 } // namespace internal |
844 } // namespace v8 | 840 } // namespace v8 |
OLD | NEW |