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/ast/ast.h" | 7 #include "src/ast/ast.h" |
8 #include "src/ast/ast-expression-visitor.h" | 8 #include "src/ast/ast-expression-visitor.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/parsing/parser.h" | 10 #include "src/parsing/parser.h" |
11 #include "src/parsing/rewriter.h" | 11 #include "src/parsing/rewriter.h" |
12 #include "src/type-cache.h" | 12 #include "src/type-cache.h" |
13 #include "src/typing-asm.h" | 13 #include "src/typing-asm.h" |
14 #include "test/cctest/cctest.h" | 14 #include "test/cctest/cctest.h" |
15 #include "test/cctest/expression-type-collector.h" | 15 #include "test/cctest/expression-type-collector.h" |
16 #include "test/cctest/expression-type-collector-macros.h" | 16 #include "test/cctest/expression-type-collector-macros.h" |
17 | 17 |
18 // Macros for function types. | 18 // Macros for function types. |
| 19 #define FUNC_BARE_TYPE Bounds(Type::Function(zone)) |
19 #define FUNC_V_TYPE Bounds(Type::Function(Type::Undefined(zone), zone)) | 20 #define FUNC_V_TYPE Bounds(Type::Function(Type::Undefined(zone), zone)) |
20 #define FUNC_I_TYPE Bounds(Type::Function(cache.kAsmSigned, zone)) | 21 #define FUNC_I_TYPE Bounds(Type::Function(cache.kAsmSigned, zone)) |
21 #define FUNC_F_TYPE Bounds(Type::Function(cache.kAsmFloat, zone)) | 22 #define FUNC_F_TYPE Bounds(Type::Function(cache.kAsmFloat, zone)) |
22 #define FUNC_D_TYPE Bounds(Type::Function(cache.kAsmDouble, zone)) | 23 #define FUNC_D_TYPE Bounds(Type::Function(cache.kAsmDouble, zone)) |
23 #define FUNC_D2D_TYPE \ | 24 #define FUNC_D2D_TYPE \ |
24 Bounds(Type::Function(cache.kAsmDouble, cache.kAsmDouble, zone)) | 25 Bounds(Type::Function(cache.kAsmDouble, cache.kAsmDouble, zone)) |
25 #define FUNC_N2F_TYPE \ | 26 #define FUNC_N2F_TYPE \ |
26 Bounds(Type::Function(cache.kAsmFloat, Type::Number(zone), zone)) | 27 Bounds(Type::Function(cache.kAsmFloat, Type::Number(zone), zone)) |
27 #define FUNC_I2I_TYPE \ | 28 #define FUNC_I2I_TYPE \ |
28 Bounds(Type::Function(cache.kAsmSigned, cache.kAsmInt, zone)) | 29 Bounds(Type::Function(cache.kAsmSigned, cache.kAsmInt, zone)) |
(...skipping 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1720 | 1721 |
1721 | 1722 |
1722 TEST(ForeignFunction) { | 1723 TEST(ForeignFunction) { |
1723 CHECK_FUNC_TYPES_BEGIN( | 1724 CHECK_FUNC_TYPES_BEGIN( |
1724 "var baz = foreign.baz;\n" | 1725 "var baz = foreign.baz;\n" |
1725 "function bar() { return baz(1, 2)|0; }\n" | 1726 "function bar() { return baz(1, 2)|0; }\n" |
1726 "function foo() { bar(); }") { | 1727 "function foo() { bar(); }") { |
1727 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { | 1728 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { |
1728 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 1729 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { |
1729 CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { | 1730 CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { |
1730 CHECK_VAR(baz, Bounds(Type::Any(zone))); | 1731 CHECK_VAR(baz, FUNC_BARE_TYPE); |
1731 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1732 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
1732 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1733 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
1733 } | 1734 } |
1734 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1735 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
1735 } | 1736 } |
1736 } | 1737 } |
1737 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { | 1738 CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { |
1738 CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { | 1739 CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { |
1739 CHECK_VAR(bar, FUNC_I_TYPE); | 1740 CHECK_VAR(bar, FUNC_I_TYPE); |
1740 } | 1741 } |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2121 CHECK_EQ("", Validate(zone, test_function, &types)); | 2122 CHECK_EQ("", Validate(zone, test_function, &types)); |
2122 TypeCache cache; | 2123 TypeCache cache; |
2123 | 2124 |
2124 CHECK_TYPES_BEGIN { | 2125 CHECK_TYPES_BEGIN { |
2125 // Module. | 2126 // Module. |
2126 CHECK_EXPR(FunctionLiteral, Bounds::Unbounded()) { | 2127 CHECK_EXPR(FunctionLiteral, Bounds::Unbounded()) { |
2127 // function test1 | 2128 // function test1 |
2128 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { | 2129 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { |
2129 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 2130 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { |
2130 CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { | 2131 CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { |
2131 CHECK_VAR(ffunc, Bounds(Type::Any(zone))); | 2132 CHECK_VAR(ffunc, FUNC_BARE_TYPE); |
2132 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 2133 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { |
2133 CHECK_VAR(fint, Bounds(cache.kAsmInt)); | 2134 CHECK_VAR(fint, Bounds(cache.kAsmInt)); |
2134 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 2135 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
2135 } | 2136 } |
2136 CHECK_VAR(fdouble, Bounds(cache.kAsmDouble)); | 2137 CHECK_VAR(fdouble, Bounds(cache.kAsmDouble)); |
2137 } | 2138 } |
2138 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 2139 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
2139 } | 2140 } |
2140 } | 2141 } |
2141 // function test2 | 2142 // function test2 |
2142 CHECK_EXPR(FunctionLiteral, FUNC_D_TYPE) { | 2143 CHECK_EXPR(FunctionLiteral, FUNC_D_TYPE) { |
2143 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmDouble)) { | 2144 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmDouble)) { |
2144 CHECK_EXPR(Call, Bounds(cache.kAsmDouble)) { | 2145 CHECK_EXPR(Call, Bounds(cache.kAsmDouble)) { |
2145 CHECK_VAR(ffunc, Bounds(Type::Any(zone))); | 2146 CHECK_VAR(ffunc, FUNC_BARE_TYPE); |
2146 CHECK_VAR(fdouble, Bounds(cache.kAsmDouble)); | 2147 CHECK_VAR(fdouble, Bounds(cache.kAsmDouble)); |
2147 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 2148 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { |
2148 CHECK_VAR(fint, Bounds(cache.kAsmInt)); | 2149 CHECK_VAR(fint, Bounds(cache.kAsmInt)); |
2149 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 2150 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
2150 } | 2151 } |
2151 } | 2152 } |
2152 CHECK_EXPR(Literal, Bounds(cache.kAsmDouble)); | 2153 CHECK_EXPR(Literal, Bounds(cache.kAsmDouble)); |
2153 } | 2154 } |
2154 } | 2155 } |
2155 // "use asm"; | 2156 // "use asm"; |
(...skipping 30 matching lines...) Expand all Loading... |
2186 } | 2187 } |
2187 // return { testFunc1: test1, testFunc2: test2 }; | 2188 // return { testFunc1: test1, testFunc2: test2 }; |
2188 CHECK_EXPR(ObjectLiteral, Bounds::Unbounded()) { | 2189 CHECK_EXPR(ObjectLiteral, Bounds::Unbounded()) { |
2189 CHECK_VAR(test1, FUNC_I_TYPE); | 2190 CHECK_VAR(test1, FUNC_I_TYPE); |
2190 CHECK_VAR(test2, FUNC_D_TYPE); | 2191 CHECK_VAR(test2, FUNC_D_TYPE); |
2191 } | 2192 } |
2192 } | 2193 } |
2193 } | 2194 } |
2194 CHECK_TYPES_END | 2195 CHECK_TYPES_END |
2195 } | 2196 } |
OLD | NEW |