OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/typing-asm.h" | 7 #include "src/typing-asm.h" |
8 | 8 |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 case Token::COMMA: { | 834 case Token::COMMA: { |
835 RECURSE(VisitWithExpectation(expr->left(), Type::Any(), | 835 RECURSE(VisitWithExpectation(expr->left(), Type::Any(), |
836 "left comma operand expected to be any")); | 836 "left comma operand expected to be any")); |
837 RECURSE(VisitWithExpectation(expr->right(), Type::Any(), | 837 RECURSE(VisitWithExpectation(expr->right(), Type::Any(), |
838 "right comma operand expected to be any")); | 838 "right comma operand expected to be any")); |
839 IntersectResult(expr, computed_type_); | 839 IntersectResult(expr, computed_type_); |
840 return; | 840 return; |
841 } | 841 } |
842 case Token::OR: | 842 case Token::OR: |
843 case Token::AND: | 843 case Token::AND: |
844 FAIL(expr, "logical operator encountered"); | 844 FAIL(expr, "illegal logical operator"); |
845 case Token::BIT_OR: { | 845 case Token::BIT_OR: { |
846 // BIT_OR allows Any since it is used as a type coercion. | 846 // BIT_OR allows Any since it is used as a type coercion. |
847 VisitIntegerBitwiseOperator(expr, Type::Any(), cache_.kIntegral32, | 847 VisitIntegerBitwiseOperator(expr, Type::Any(), cache_.kIntegral32, |
848 cache_.kInt32, true); | 848 cache_.kInt32, true); |
849 return; | 849 return; |
850 } | 850 } |
851 case Token::BIT_XOR: { | 851 case Token::BIT_XOR: { |
| 852 // Handle booleans specially to handle de-sugared ! |
| 853 Literal* left = expr->left()->AsLiteral(); |
| 854 if (left && left->value()->IsBoolean()) { |
| 855 if (left->ToBooleanIsTrue()) { |
| 856 left->set_bounds(Bounds(cache_.kSingletonOne)); |
| 857 RECURSE(VisitWithExpectation(expr->right(), cache_.kIntegral32, |
| 858 "not operator expects an integer")); |
| 859 IntersectResult(expr, cache_.kInt32); |
| 860 return; |
| 861 } else { |
| 862 FAIL(left, "unexpected false"); |
| 863 } |
| 864 } |
852 // BIT_XOR allows Number since it is used as a type coercion (via ~~). | 865 // BIT_XOR allows Number since it is used as a type coercion (via ~~). |
853 VisitIntegerBitwiseOperator(expr, Type::Number(), cache_.kIntegral32, | 866 VisitIntegerBitwiseOperator(expr, Type::Number(), cache_.kIntegral32, |
854 cache_.kInt32, true); | 867 cache_.kInt32, true); |
855 return; | 868 return; |
856 } | 869 } |
857 case Token::SHR: { | 870 case Token::SHR: { |
858 VisitIntegerBitwiseOperator(expr, cache_.kIntegral32, cache_.kIntegral32, | 871 VisitIntegerBitwiseOperator(expr, cache_.kIntegral32, cache_.kIntegral32, |
859 cache_.kUint32, false); | 872 cache_.kUint32, false); |
860 return; | 873 return; |
861 } | 874 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 | 940 |
928 | 941 |
929 void AsmTyper::VisitCompareOperation(CompareOperation* expr) { | 942 void AsmTyper::VisitCompareOperation(CompareOperation* expr) { |
930 RECURSE( | 943 RECURSE( |
931 VisitWithExpectation(expr->left(), Type::Number(), | 944 VisitWithExpectation(expr->left(), Type::Number(), |
932 "left comparison operand expected to be number")); | 945 "left comparison operand expected to be number")); |
933 Type* left_type = computed_type_; | 946 Type* left_type = computed_type_; |
934 RECURSE( | 947 RECURSE( |
935 VisitWithExpectation(expr->right(), Type::Number(), | 948 VisitWithExpectation(expr->right(), Type::Number(), |
936 "right comparison operand expected to be number")); | 949 "right comparison operand expected to be number")); |
| 950 Token::Value op = expr->op(); |
| 951 if (op != Token::EQ && op != Token::NE && op != Token::LT && |
| 952 op != Token::LTE && op != Token::GT && op != Token::GTE) { |
| 953 FAIL(expr, "illegal comparison operator"); |
| 954 } |
937 Type* right_type = computed_type_; | 955 Type* right_type = computed_type_; |
938 Type* type = Type::Union(left_type, right_type, zone()); | 956 Type* type = Type::Union(left_type, right_type, zone()); |
939 expr->set_combined_type(type); | 957 expr->set_combined_type(type); |
940 if (type->Is(cache_.kInt32) || type->Is(cache_.kUint32) || | 958 if (type->Is(cache_.kInt32) || type->Is(cache_.kUint32) || |
941 type->Is(cache_.kFloat32) || type->Is(cache_.kFloat64)) { | 959 type->Is(cache_.kFloat32) || type->Is(cache_.kFloat64)) { |
942 IntersectResult(expr, cache_.kInt32); | 960 IntersectResult(expr, cache_.kInt32); |
943 } else { | 961 } else { |
944 FAIL(expr, "ill-typed comparison operation"); | 962 FAIL(expr, "ill-typed comparison operation"); |
945 } | 963 } |
946 } | 964 } |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 computed_type_->Print(); | 1124 computed_type_->Print(); |
1107 PrintF("Expected type: "); | 1125 PrintF("Expected type: "); |
1108 expected_type_->Print(); | 1126 expected_type_->Print(); |
1109 #endif | 1127 #endif |
1110 FAIL(expr, msg); | 1128 FAIL(expr, msg); |
1111 } | 1129 } |
1112 expected_type_ = save; | 1130 expected_type_ = save; |
1113 } | 1131 } |
1114 } // namespace internal | 1132 } // namespace internal |
1115 } // namespace v8 | 1133 } // namespace v8 |
OLD | NEW |