| 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/typing-asm.h" | 5 #include "src/typing-asm.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "src/v8.h" | 9 #include "src/v8.h" |
| 10 | 10 |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 RECURSE(VisitWithExpectation(expr->condition(), Type::Number(), | 533 RECURSE(VisitWithExpectation(expr->condition(), Type::Number(), |
| 534 "condition expected to be integer")); | 534 "condition expected to be integer")); |
| 535 if (!computed_type_->Is(cache_.kAsmInt)) { | 535 if (!computed_type_->Is(cache_.kAsmInt)) { |
| 536 FAIL(expr->condition(), "condition must be of type int"); | 536 FAIL(expr->condition(), "condition must be of type int"); |
| 537 } | 537 } |
| 538 | 538 |
| 539 RECURSE(VisitWithExpectation( | 539 RECURSE(VisitWithExpectation( |
| 540 expr->then_expression(), expected_type_, | 540 expr->then_expression(), expected_type_, |
| 541 "conditional then branch type mismatch with enclosing expression")); | 541 "conditional then branch type mismatch with enclosing expression")); |
| 542 Type* then_type = StorageType(computed_type_); | 542 Type* then_type = StorageType(computed_type_); |
| 543 if (intish_ != 0 || !then_type->Is(cache_.kAsmComparable)) { | 543 int then_intish = intish_; |
| 544 FAIL(expr->then_expression(), "invalid type in ? then expression"); | |
| 545 } | |
| 546 | 544 |
| 547 RECURSE(VisitWithExpectation( | 545 RECURSE(VisitWithExpectation( |
| 548 expr->else_expression(), expected_type_, | 546 expr->else_expression(), expected_type_, |
| 549 "conditional else branch type mismatch with enclosing expression")); | 547 "conditional else branch type mismatch with enclosing expression")); |
| 550 Type* else_type = StorageType(computed_type_); | 548 Type* else_type = StorageType(computed_type_); |
| 551 if (intish_ != 0 || !else_type->Is(cache_.kAsmComparable)) { | 549 int else_intish = intish_; |
| 552 FAIL(expr->else_expression(), "invalid type in ? else expression"); | |
| 553 } | |
| 554 | 550 |
| 555 if (!then_type->Is(else_type) || !else_type->Is(then_type)) { | 551 if (then_intish != 0 || else_intish != 0 || |
| 556 FAIL(expr, "then and else expressions in ? must have the same type"); | 552 !((then_type->Is(cache_.kAsmInt) && else_type->Is(cache_.kAsmInt)) || |
| 553 (then_type->Is(cache_.kAsmFloat) && else_type->Is(cache_.kAsmFloat)) || |
| 554 (then_type->Is(cache_.kAsmDouble) && |
| 555 else_type->Is(cache_.kAsmDouble)))) { |
| 556 FAIL(expr, |
| 557 "then and else expressions in ? must have the same type " |
| 558 "and be int, float, or double"); |
| 557 } | 559 } |
| 558 | 560 |
| 559 RECURSE(IntersectResult(expr, then_type)); | 561 RECURSE(IntersectResult(expr, then_type)); |
| 560 } | 562 } |
| 561 | 563 |
| 562 | 564 |
| 563 void AsmTyper::VisitVariableProxy(VariableProxy* expr) { | 565 void AsmTyper::VisitVariableProxy(VariableProxy* expr) { |
| 564 Variable* var = expr->var(); | 566 Variable* var = expr->var(); |
| 565 VariableInfo* info = GetVariableInfo(var); | 567 VariableInfo* info = GetVariableInfo(var); |
| 566 if (!in_function_ && !building_function_tables_ && !visiting_exports_) { | 568 if (!in_function_ && !building_function_tables_ && !visiting_exports_) { |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 Token::Value op = expr->op(); | 1374 Token::Value op = expr->op(); |
| 1373 if (op != Token::EQ && op != Token::NE && op != Token::LT && | 1375 if (op != Token::EQ && op != Token::NE && op != Token::LT && |
| 1374 op != Token::LTE && op != Token::GT && op != Token::GTE) { | 1376 op != Token::LTE && op != Token::GT && op != Token::GTE) { |
| 1375 FAIL(expr, "illegal comparison operator"); | 1377 FAIL(expr, "illegal comparison operator"); |
| 1376 } | 1378 } |
| 1377 | 1379 |
| 1378 RECURSE( | 1380 RECURSE( |
| 1379 VisitWithExpectation(expr->left(), Type::Number(), | 1381 VisitWithExpectation(expr->left(), Type::Number(), |
| 1380 "left comparison operand expected to be number")); | 1382 "left comparison operand expected to be number")); |
| 1381 Type* left_type = computed_type_; | 1383 Type* left_type = computed_type_; |
| 1382 if (!left_type->Is(cache_.kAsmComparable)) { | 1384 int left_intish = intish_; |
| 1383 FAIL(expr->left(), "bad type on left side of comparison"); | |
| 1384 } | |
| 1385 | 1385 |
| 1386 RECURSE( | 1386 RECURSE( |
| 1387 VisitWithExpectation(expr->right(), Type::Number(), | 1387 VisitWithExpectation(expr->right(), Type::Number(), |
| 1388 "right comparison operand expected to be number")); | 1388 "right comparison operand expected to be number")); |
| 1389 Type* right_type = computed_type_; | 1389 Type* right_type = computed_type_; |
| 1390 if (!right_type->Is(cache_.kAsmComparable)) { | 1390 int right_intish = intish_; |
| 1391 FAIL(expr->right(), "bad type on right side of comparison"); | |
| 1392 } | |
| 1393 | 1391 |
| 1394 if (!left_type->Is(right_type) && !right_type->Is(left_type)) { | 1392 if (left_intish != 0 || right_intish != 0 || |
| 1395 FAIL(expr, "left and right side of comparison must match"); | 1393 !((left_type->Is(cache_.kAsmUnsigned) && |
| 1394 right_type->Is(cache_.kAsmUnsigned)) || |
| 1395 (left_type->Is(cache_.kAsmSigned) && |
| 1396 right_type->Is(cache_.kAsmSigned)) || |
| 1397 (left_type->Is(cache_.kAsmFloat) && right_type->Is(cache_.kAsmFloat)) || |
| 1398 (left_type->Is(cache_.kAsmDouble) && |
| 1399 right_type->Is(cache_.kAsmDouble)))) { |
| 1400 FAIL(expr, |
| 1401 "left and right side of comparison must match type " |
| 1402 "and be signed, unsigned, float, or double"); |
| 1396 } | 1403 } |
| 1397 | 1404 |
| 1398 RECURSE(IntersectResult(expr, cache_.kAsmSigned)); | 1405 RECURSE(IntersectResult(expr, cache_.kAsmSigned)); |
| 1399 } | 1406 } |
| 1400 | 1407 |
| 1401 | 1408 |
| 1402 void AsmTyper::VisitThisFunction(ThisFunction* expr) { | 1409 void AsmTyper::VisitThisFunction(ThisFunction* expr) { |
| 1403 FAIL(expr, "this function not allowed"); | 1410 FAIL(expr, "this function not allowed"); |
| 1404 } | 1411 } |
| 1405 | 1412 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1642 } | 1649 } |
| 1643 | 1650 |
| 1644 | 1651 |
| 1645 void AsmTyper::VisitRewritableExpression(RewritableExpression* expr) { | 1652 void AsmTyper::VisitRewritableExpression(RewritableExpression* expr) { |
| 1646 RECURSE(Visit(expr->expression())); | 1653 RECURSE(Visit(expr->expression())); |
| 1647 } | 1654 } |
| 1648 | 1655 |
| 1649 | 1656 |
| 1650 } // namespace internal | 1657 } // namespace internal |
| 1651 } // namespace v8 | 1658 } // namespace v8 |
| OLD | NEW |