| 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()) | 19 #define FUNC_FOREIGN_TYPE Bounds(Type::Function(Type::Any(), zone)) | 
| 20 #define FUNC_V_TYPE Bounds(Type::Function(Type::Undefined(), zone)) | 20 #define FUNC_V_TYPE Bounds(Type::Function(Type::Undefined(), zone)) | 
| 21 #define FUNC_I_TYPE Bounds(Type::Function(cache.kAsmSigned, zone)) | 21 #define FUNC_I_TYPE Bounds(Type::Function(cache.kAsmSigned, zone)) | 
| 22 #define FUNC_F_TYPE Bounds(Type::Function(cache.kAsmFloat, zone)) | 22 #define FUNC_F_TYPE Bounds(Type::Function(cache.kAsmFloat, zone)) | 
| 23 #define FUNC_D_TYPE Bounds(Type::Function(cache.kAsmDouble, zone)) | 23 #define FUNC_D_TYPE Bounds(Type::Function(cache.kAsmDouble, zone)) | 
| 24 #define FUNC_D2D_TYPE \ | 24 #define FUNC_D2D_TYPE \ | 
| 25   Bounds(Type::Function(cache.kAsmDouble, cache.kAsmDouble, zone)) | 25   Bounds(Type::Function(cache.kAsmDouble, cache.kAsmDouble, zone)) | 
| 26 #define FUNC_N2F_TYPE \ | 26 #define FUNC_N2F_TYPE \ | 
| 27   Bounds(Type::Function(cache.kAsmFloat, Type::Number(), zone)) | 27   Bounds(Type::Function(cache.kAsmFloat, Type::Number(), zone)) | 
| 28 #define FUNC_I2I_TYPE \ | 28 #define FUNC_I2I_TYPE \ | 
| 29   Bounds(Type::Function(cache.kAsmSigned, cache.kAsmInt, zone)) | 29   Bounds(Type::Function(cache.kAsmSigned, cache.kAsmInt, zone)) | 
| (...skipping 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1719 | 1719 | 
| 1720 | 1720 | 
| 1721 TEST(ForeignFunction) { | 1721 TEST(ForeignFunction) { | 
| 1722   CHECK_FUNC_TYPES_BEGIN( | 1722   CHECK_FUNC_TYPES_BEGIN( | 
| 1723       "var baz = foreign.baz;\n" | 1723       "var baz = foreign.baz;\n" | 
| 1724       "function bar() { return baz(1, 2)|0; }\n" | 1724       "function bar() { return baz(1, 2)|0; }\n" | 
| 1725       "function foo() { bar(); }") { | 1725       "function foo() { bar(); }") { | 
| 1726     CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { | 1726     CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { | 
| 1727       CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 1727       CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 
| 1728         CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { | 1728         CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { | 
| 1729           CHECK_VAR(baz, FUNC_BARE_TYPE); | 1729           CHECK_VAR(baz, FUNC_FOREIGN_TYPE); | 
| 1730           CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1730           CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 
| 1731           CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1731           CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 
| 1732         } | 1732         } | 
| 1733         CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1733         CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 
| 1734       } | 1734       } | 
| 1735     } | 1735     } | 
| 1736     CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { | 1736     CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) { | 
| 1737       CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { | 1737       CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { | 
| 1738         CHECK_VAR(bar, FUNC_I_TYPE); | 1738         CHECK_VAR(bar, FUNC_I_TYPE); | 
| 1739       } | 1739       } | 
| 1740     } | 1740     } | 
| 1741   } | 1741   } | 
| 1742   CHECK_FUNC_TYPES_END_1() | 1742   CHECK_FUNC_TYPES_END_1() | 
| 1743   CHECK_EXPR(Assignment, Bounds(Type::Any())) { | 1743   CHECK_EXPR(Assignment, Bounds(FUNC_FOREIGN_TYPE)) { | 
| 1744     CHECK_VAR(baz, Bounds(Type::Any())); | 1744     CHECK_VAR(baz, Bounds(FUNC_FOREIGN_TYPE)); | 
| 1745     CHECK_EXPR(Property, Bounds(Type::Any())) { | 1745     CHECK_EXPR(Property, Bounds(FUNC_FOREIGN_TYPE)) { | 
| 1746       CHECK_VAR(foreign, Bounds::Unbounded()); | 1746       CHECK_VAR(foreign, Bounds::Unbounded()); | 
| 1747       CHECK_EXPR(Literal, Bounds::Unbounded()); | 1747       CHECK_EXPR(Literal, Bounds::Unbounded()); | 
| 1748     } | 1748     } | 
| 1749   } | 1749   } | 
| 1750   CHECK_FUNC_TYPES_END_2() | 1750   CHECK_FUNC_TYPES_END_2() | 
| 1751 } | 1751 } | 
| 1752 | 1752 | 
| 1753 | 1753 | 
| 1754 TEST(BadExports) { | 1754 TEST(BadExports) { | 
| 1755   HARNESS_PREAMBLE() | 1755   HARNESS_PREAMBLE() | 
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2120   CHECK_EQ("", Validate(zone, test_function, &types)); | 2120   CHECK_EQ("", Validate(zone, test_function, &types)); | 
| 2121   TypeCache cache; | 2121   TypeCache cache; | 
| 2122 | 2122 | 
| 2123   CHECK_TYPES_BEGIN { | 2123   CHECK_TYPES_BEGIN { | 
| 2124     // Module. | 2124     // Module. | 
| 2125     CHECK_EXPR(FunctionLiteral, Bounds::Unbounded()) { | 2125     CHECK_EXPR(FunctionLiteral, Bounds::Unbounded()) { | 
| 2126       // function test1 | 2126       // function test1 | 
| 2127       CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { | 2127       CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { | 
| 2128         CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 2128         CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 
| 2129           CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { | 2129           CHECK_EXPR(Call, Bounds(cache.kAsmSigned)) { | 
| 2130             CHECK_VAR(ffunc, FUNC_BARE_TYPE); | 2130             CHECK_VAR(ffunc, FUNC_FOREIGN_TYPE); | 
| 2131             CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 2131             CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 
| 2132               CHECK_VAR(fint, Bounds(cache.kAsmInt)); | 2132               CHECK_VAR(fint, Bounds(cache.kAsmInt)); | 
| 2133               CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 2133               CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 
| 2134             } | 2134             } | 
| 2135             CHECK_VAR(fdouble, Bounds(cache.kAsmDouble)); | 2135             CHECK_VAR(fdouble, Bounds(cache.kAsmDouble)); | 
| 2136           } | 2136           } | 
| 2137           CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 2137           CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 
| 2138         } | 2138         } | 
| 2139       } | 2139       } | 
| 2140       // function test2 | 2140       // function test2 | 
| 2141       CHECK_EXPR(FunctionLiteral, FUNC_D_TYPE) { | 2141       CHECK_EXPR(FunctionLiteral, FUNC_D_TYPE) { | 
| 2142         CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmDouble)) { | 2142         CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmDouble)) { | 
| 2143           CHECK_EXPR(Call, Bounds(cache.kAsmDouble)) { | 2143           CHECK_EXPR(Call, Bounds(cache.kAsmDouble)) { | 
| 2144             CHECK_VAR(ffunc, FUNC_BARE_TYPE); | 2144             CHECK_VAR(ffunc, FUNC_FOREIGN_TYPE); | 
| 2145             CHECK_VAR(fdouble, Bounds(cache.kAsmDouble)); | 2145             CHECK_VAR(fdouble, Bounds(cache.kAsmDouble)); | 
| 2146             CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 2146             CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 
| 2147               CHECK_VAR(fint, Bounds(cache.kAsmInt)); | 2147               CHECK_VAR(fint, Bounds(cache.kAsmInt)); | 
| 2148               CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 2148               CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 
| 2149             } | 2149             } | 
| 2150           } | 2150           } | 
| 2151           CHECK_EXPR(Literal, Bounds(cache.kAsmDouble)); | 2151           CHECK_EXPR(Literal, Bounds(cache.kAsmDouble)); | 
| 2152         } | 2152         } | 
| 2153       } | 2153       } | 
| 2154       // "use asm"; | 2154       // "use asm"; | 
| 2155       CHECK_EXPR(Literal, Bounds(Type::String())); | 2155       CHECK_EXPR(Literal, Bounds(Type::String())); | 
| 2156       // var func = foreign.foo; | 2156       // var func = foreign.foo; | 
| 2157       CHECK_EXPR(Assignment, Bounds(Type::Any())) { | 2157       CHECK_EXPR(Assignment, Bounds(FUNC_FOREIGN_TYPE)) { | 
| 2158         CHECK_VAR(ffunc, Bounds(Type::Any())); | 2158         CHECK_VAR(ffunc, Bounds(FUNC_FOREIGN_TYPE)); | 
| 2159         CHECK_EXPR(Property, Bounds(Type::Any())) { | 2159         CHECK_EXPR(Property, Bounds(FUNC_FOREIGN_TYPE)) { | 
| 2160           CHECK_VAR(foreign, Bounds::Unbounded()); | 2160           CHECK_VAR(foreign, Bounds::Unbounded()); | 
| 2161           CHECK_EXPR(Literal, Bounds::Unbounded()); | 2161           CHECK_EXPR(Literal, Bounds::Unbounded()); | 
| 2162         } | 2162         } | 
| 2163       } | 2163       } | 
| 2164       // var fint = foreign.bar | 0; | 2164       // var fint = foreign.bar | 0; | 
| 2165       CHECK_EXPR(Assignment, Bounds(cache.kAsmInt)) { | 2165       CHECK_EXPR(Assignment, Bounds(cache.kAsmInt)) { | 
| 2166         CHECK_VAR(fint, Bounds(cache.kAsmInt)); | 2166         CHECK_VAR(fint, Bounds(cache.kAsmInt)); | 
| 2167         CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 2167         CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 
| 2168           CHECK_EXPR(Property, Bounds(Type::Number())) { | 2168           CHECK_EXPR(Property, Bounds(Type::Number())) { | 
| 2169             CHECK_VAR(foreign, Bounds::Unbounded()); | 2169             CHECK_VAR(foreign, Bounds::Unbounded()); | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 2185       } | 2185       } | 
| 2186       // return { testFunc1: test1, testFunc2: test2 }; | 2186       // return { testFunc1: test1, testFunc2: test2 }; | 
| 2187       CHECK_EXPR(ObjectLiteral, Bounds::Unbounded()) { | 2187       CHECK_EXPR(ObjectLiteral, Bounds::Unbounded()) { | 
| 2188         CHECK_VAR(test1, FUNC_I_TYPE); | 2188         CHECK_VAR(test1, FUNC_I_TYPE); | 
| 2189         CHECK_VAR(test2, FUNC_D_TYPE); | 2189         CHECK_VAR(test2, FUNC_D_TYPE); | 
| 2190       } | 2190       } | 
| 2191     } | 2191     } | 
| 2192   } | 2192   } | 
| 2193   CHECK_TYPES_END | 2193   CHECK_TYPES_END | 
| 2194 } | 2194 } | 
| OLD | NEW | 
|---|