Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: test/cctest/test-typing-reset.cc

Issue 1288773007: Adding visitors to regurgitate expression types or reset them. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: back to macros Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-ast-expression-visitor.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <stdlib.h>
6
7 #include "src/v8.h"
8
9 #include "src/ast.h"
10 #include "src/ast-expression-visitor.h"
11 #include "src/parser.h"
12 #include "src/rewriter.h"
13 #include "src/scopes.h"
14 #include "src/typing-reset.h"
15 #include "test/cctest/cctest.h"
16 #include "test/cctest/compiler/function-tester.h"
17 #include "test/cctest/expression-type-collector.h"
18 #include "test/cctest/expression-type-collector-macros.h"
19
20 using namespace v8::internal;
21
22 namespace {
23
24 class TypeSetter : public AstExpressionVisitor {
25 public:
26 explicit TypeSetter(CompilationInfo* info) : AstExpressionVisitor(info) {}
27
28 protected:
29 void VisitExpression(Expression* expression) {
30 expression->set_bounds(Bounds(Type::Integral32()));
31 }
32 };
33
34
35 void CheckAllSame(ZoneVector<ExpressionTypeEntry>& types,
36 Bounds expected_type) {
37 HandleAndZoneScope handles;
38 CHECK_TYPES_BEGIN {
39 // function logSum
40 CHECK_EXPR(FunctionLiteral, expected_type) {
41 CHECK_EXPR(FunctionLiteral, expected_type) {
42 CHECK_EXPR(Assignment, expected_type) {
43 CHECK_VAR(start, expected_type);
44 CHECK_EXPR(BinaryOperation, expected_type) {
45 CHECK_VAR(start, expected_type);
46 CHECK_EXPR(Literal, expected_type);
47 }
48 }
49 CHECK_EXPR(Assignment, expected_type) {
50 CHECK_VAR(end, expected_type);
51 CHECK_EXPR(BinaryOperation, expected_type) {
52 CHECK_VAR(end, expected_type);
53 CHECK_EXPR(Literal, expected_type);
54 }
55 }
56 CHECK_EXPR(Assignment, expected_type) {
57 CHECK_VAR(sum, expected_type);
58 CHECK_EXPR(Literal, expected_type);
59 }
60 CHECK_EXPR(Assignment, expected_type) {
61 CHECK_VAR(p, expected_type);
62 CHECK_EXPR(Literal, expected_type);
63 }
64 CHECK_EXPR(Assignment, expected_type) {
65 CHECK_VAR(q, expected_type);
66 CHECK_EXPR(Literal, expected_type);
67 }
68 // for (p = start << 3, q = end << 3;
69 CHECK_EXPR(BinaryOperation, expected_type) {
70 CHECK_EXPR(Assignment, expected_type) {
71 CHECK_VAR(p, expected_type);
72 CHECK_EXPR(BinaryOperation, expected_type) {
73 CHECK_VAR(start, expected_type);
74 CHECK_EXPR(Literal, expected_type);
75 }
76 }
77 CHECK_EXPR(Assignment, expected_type) {
78 CHECK_VAR(q, expected_type);
79 CHECK_EXPR(BinaryOperation, expected_type) {
80 CHECK_VAR(end, expected_type);
81 CHECK_EXPR(Literal, expected_type);
82 }
83 }
84 }
85 // (p|0) < (q|0);
86 CHECK_EXPR(CompareOperation, expected_type) {
87 CHECK_EXPR(BinaryOperation, expected_type) {
88 CHECK_VAR(p, expected_type);
89 CHECK_EXPR(Literal, expected_type);
90 }
91 CHECK_EXPR(BinaryOperation, expected_type) {
92 CHECK_VAR(q, expected_type);
93 CHECK_EXPR(Literal, expected_type);
94 }
95 }
96 // p = (p + 8)|0) {\n"
97 CHECK_EXPR(Assignment, expected_type) {
98 CHECK_VAR(p, expected_type);
99 CHECK_EXPR(BinaryOperation, expected_type) {
100 CHECK_EXPR(BinaryOperation, expected_type) {
101 CHECK_VAR(p, expected_type);
102 CHECK_EXPR(Literal, expected_type);
103 }
104 CHECK_EXPR(Literal, expected_type);
105 }
106 }
107 // sum = sum + +log(values[p>>3]);
108 CHECK_EXPR(Assignment, expected_type) {
109 CHECK_VAR(sum, expected_type);
110 CHECK_EXPR(BinaryOperation, expected_type) {
111 CHECK_VAR(sum, expected_type);
112 CHECK_EXPR(BinaryOperation, expected_type) {
113 CHECK_EXPR(Call, expected_type) {
114 CHECK_VAR(log, expected_type);
115 CHECK_VAR(values, expected_type);
116 CHECK_EXPR(BinaryOperation, expected_type) {
117 CHECK_VAR(p, expected_type);
118 CHECK_EXPR(Literal, expected_type);
119 }
120 }
121 CHECK_EXPR(Literal, expected_type);
122 }
123 }
124 }
125 // return +sum;
126 CHECK_EXPR(BinaryOperation, expected_type) {
127 CHECK_VAR(sum, expected_type);
128 CHECK_EXPR(Literal, expected_type);
129 }
130 }
131 // function geometricMean
132 CHECK_EXPR(FunctionLiteral, expected_type) {
133 CHECK_EXPR(Assignment, expected_type) {
134 CHECK_VAR(start, expected_type);
135 CHECK_EXPR(BinaryOperation, expected_type) {
136 CHECK_VAR(start, expected_type);
137 CHECK_EXPR(Literal, expected_type);
138 }
139 }
140 CHECK_EXPR(Assignment, expected_type) {
141 CHECK_VAR(end, expected_type);
142 CHECK_EXPR(BinaryOperation, expected_type) {
143 CHECK_VAR(end, expected_type);
144 CHECK_EXPR(Literal, expected_type);
145 }
146 }
147 // return +exp(+logSum(start, end) / +((end - start)|0));
148 CHECK_EXPR(BinaryOperation, expected_type) {
149 CHECK_EXPR(Call, expected_type) {
150 CHECK_VAR(exp, expected_type);
151 CHECK_EXPR(BinaryOperation, expected_type) {
152 CHECK_EXPR(BinaryOperation, expected_type) {
153 CHECK_EXPR(Call, expected_type) {
154 CHECK_VAR(logSum, expected_type);
155 CHECK_VAR(start, expected_type);
156 CHECK_VAR(end, expected_type);
157 }
158 CHECK_EXPR(Literal, expected_type);
159 }
160 CHECK_EXPR(BinaryOperation, expected_type) {
161 CHECK_EXPR(BinaryOperation, expected_type) {
162 CHECK_EXPR(BinaryOperation, expected_type) {
163 CHECK_VAR(end, expected_type);
164 CHECK_VAR(start, expected_type);
165 }
166 CHECK_EXPR(Literal, expected_type);
167 }
168 CHECK_EXPR(Literal, expected_type);
169 }
170 }
171 }
172 CHECK_EXPR(Literal, expected_type);
173 }
174 }
175 // "use asm";
176 CHECK_EXPR(Literal, expected_type);
177 // var exp = stdlib.Math.exp;
178 CHECK_EXPR(Assignment, expected_type) {
179 CHECK_VAR(exp, expected_type);
180 CHECK_VAR(stdlib, expected_type);
181 CHECK_EXPR(Literal, expected_type);
182 CHECK_EXPR(Literal, expected_type);
183 }
184 // var log = stdlib.Math.log;
185 CHECK_EXPR(Assignment, expected_type) {
186 CHECK_VAR(log, expected_type);
187 CHECK_VAR(stdlib, expected_type);
188 CHECK_EXPR(Literal, expected_type);
189 CHECK_EXPR(Literal, expected_type);
190 }
191 // var values = new stdlib.Float64Array(buffer);
192 CHECK_EXPR(Assignment, expected_type) {
193 CHECK_VAR(values, expected_type);
194 CHECK_EXPR(CallNew, expected_type) {
195 CHECK_VAR(stdlib, expected_type);
196 CHECK_EXPR(Literal, expected_type);
197 CHECK_VAR(buffer, expected_type);
198 }
199 }
200 // return { geometricMean: geometricMean };
201 CHECK_EXPR(ObjectLiteral, expected_type) {
202 CHECK_VAR(geometricMean, expected_type);
203 }
204 }
205 }
206 CHECK_TYPES_END
207 }
208 }
209
210
211 TEST(ResetTypingInfo) {
212 const char test_function[] =
213 "function GeometricMean(stdlib, foreign, buffer) {\n"
214 " \"use asm\";\n"
215 "\n"
216 " var exp = stdlib.Math.exp;\n"
217 " var log = stdlib.Math.log;\n"
218 " var values = new stdlib.Float64Array(buffer);\n"
219 "\n"
220 " function logSum(start, end) {\n"
221 " start = start|0;\n"
222 " end = end|0;\n"
223 "\n"
224 " var sum = 0.0, p = 0, q = 0;\n"
225 "\n"
226 " // asm.js forces byte addressing of the heap by requiring shifting "
227 "by 3\n"
228 " for (p = start << 3, q = end << 3; (p|0) < (q|0); p = (p + 8)|0) {\n"
229 " sum = sum + +log(values[p>>3]);\n"
230 " }\n"
231 "\n"
232 " return +sum;\n"
233 " }\n"
234 "\n"
235 " function geometricMean(start, end) {\n"
236 " start = start|0;\n"
237 " end = end|0;\n"
238 "\n"
239 " return +exp(+logSum(start, end) / +((end - start)|0));\n"
240 " }\n"
241 "\n"
242 " return { geometricMean: geometricMean };\n"
243 "}\n";
244
245 v8::V8::Initialize();
246 HandleAndZoneScope handles;
247
248 i::Isolate* isolate = CcTest::i_isolate();
249 i::Factory* factory = isolate->factory();
250
251 i::Handle<i::String> source_code =
252 factory->NewStringFromUtf8(i::CStrVector(test_function))
253 .ToHandleChecked();
254
255 i::Handle<i::Script> script = factory->NewScript(source_code);
256
257 i::ParseInfo info(handles.main_zone(), script);
258 i::Parser parser(&info);
259 parser.set_allow_harmony_arrow_functions(true);
260 parser.set_allow_harmony_sloppy(true);
261 info.set_global();
262 info.set_lazy(false);
263 info.set_allow_lazy_parsing(false);
264 info.set_toplevel(true);
265
266 i::CompilationInfo compilation_info(&info);
267 CHECK(i::Compiler::ParseAndAnalyze(&info));
268 info.set_literal(
269 info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun());
270
271 // Core of the test.
272 ZoneVector<ExpressionTypeEntry> types(handles.main_zone());
273 ExpressionTypeCollector(&compilation_info, &types).Run();
274 CheckAllSame(types, DEFAULT_TYPE);
275
276 TypeSetter(&compilation_info).Run();
277
278 ExpressionTypeCollector(&compilation_info, &types).Run();
279 CheckAllSame(types, INT32_TYPE);
280
281 TypingReseter(&compilation_info).Run();
282
283 ExpressionTypeCollector(&compilation_info, &types).Run();
284 CheckAllSame(types, DEFAULT_TYPE);
285 }
OLDNEW
« no previous file with comments | « test/cctest/test-ast-expression-visitor.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698