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

Side by Side Diff: test/cctest/test-ast-expression-visitor.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/expression-type-collector-macros.h ('k') | test/cctest/test-typing-reset.cc » ('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 "test/cctest/cctest.h"
15 #include "test/cctest/expression-type-collector.h"
16 #include "test/cctest/expression-type-collector-macros.h"
17
18 using namespace v8::internal;
19
20 namespace {
21
22 static void CollectTypes(HandleAndZoneScope* handles, const char* source,
23 ZoneVector<ExpressionTypeEntry>* dst) {
24 i::Isolate* isolate = CcTest::i_isolate();
25 i::Factory* factory = isolate->factory();
26
27 i::Handle<i::String> source_code =
28 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked();
29
30 i::Handle<i::Script> script = factory->NewScript(source_code);
31
32 i::ParseInfo info(handles->main_zone(), script);
33 i::Parser parser(&info);
34 parser.set_allow_harmony_arrow_functions(true);
35 parser.set_allow_harmony_sloppy(true);
36 info.set_global();
37 info.set_lazy(false);
38 info.set_allow_lazy_parsing(false);
39 info.set_toplevel(true);
40
41 i::CompilationInfo compilation_info(&info);
42 CHECK(i::Compiler::ParseAndAnalyze(&info));
43 info.set_literal(
44 info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun());
45
46 ExpressionTypeCollector(&compilation_info, dst).Run();
47 }
48 }
49
50
51 TEST(VisitExpressions) {
52 v8::V8::Initialize();
53 HandleAndZoneScope handles;
54 ZoneVector<ExpressionTypeEntry> types(handles.main_zone());
55 const char test_function[] =
56 "function GeometricMean(stdlib, foreign, buffer) {\n"
57 " \"use asm\";\n"
58 "\n"
59 " var exp = stdlib.Math.exp;\n"
60 " var log = stdlib.Math.log;\n"
61 " var values = new stdlib.Float64Array(buffer);\n"
62 "\n"
63 " function logSum(start, end) {\n"
64 " start = start|0;\n"
65 " end = end|0;\n"
66 "\n"
67 " var sum = 0.0, p = 0, q = 0;\n"
68 "\n"
69 " // asm.js forces byte addressing of the heap by requiring shifting "
70 "by 3\n"
71 " for (p = start << 3, q = end << 3; (p|0) < (q|0); p = (p + 8)|0) {\n"
72 " sum = sum + +log(values[p>>3]);\n"
73 " }\n"
74 "\n"
75 " return +sum;\n"
76 " }\n"
77 "\n"
78 " function geometricMean(start, end) {\n"
79 " start = start|0;\n"
80 " end = end|0;\n"
81 "\n"
82 " return +exp(+logSum(start, end) / +((end - start)|0));\n"
83 " }\n"
84 "\n"
85 " return { geometricMean: geometricMean };\n"
86 "}\n";
87
88 CollectTypes(&handles, test_function, &types);
89 CHECK_TYPES_BEGIN {
90 // function logSum
91 CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) {
92 CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) {
93 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
94 CHECK_VAR(start, DEFAULT_TYPE);
95 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
96 CHECK_VAR(start, DEFAULT_TYPE);
97 CHECK_EXPR(Literal, DEFAULT_TYPE);
98 }
99 }
100 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
101 CHECK_VAR(end, DEFAULT_TYPE);
102 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
103 CHECK_VAR(end, DEFAULT_TYPE);
104 CHECK_EXPR(Literal, DEFAULT_TYPE);
105 }
106 }
107 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
108 CHECK_VAR(sum, DEFAULT_TYPE);
109 CHECK_EXPR(Literal, DEFAULT_TYPE);
110 }
111 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
112 CHECK_VAR(p, DEFAULT_TYPE);
113 CHECK_EXPR(Literal, DEFAULT_TYPE);
114 }
115 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
116 CHECK_VAR(q, DEFAULT_TYPE);
117 CHECK_EXPR(Literal, DEFAULT_TYPE);
118 }
119 // for (p = start << 3, q = end << 3;
120 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
121 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
122 CHECK_VAR(p, DEFAULT_TYPE);
123 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
124 CHECK_VAR(start, DEFAULT_TYPE);
125 CHECK_EXPR(Literal, DEFAULT_TYPE);
126 }
127 }
128 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
129 CHECK_VAR(q, DEFAULT_TYPE);
130 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
131 CHECK_VAR(end, DEFAULT_TYPE);
132 CHECK_EXPR(Literal, DEFAULT_TYPE);
133 }
134 }
135 }
136 // (p|0) < (q|0);
137 CHECK_EXPR(CompareOperation, DEFAULT_TYPE) {
138 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
139 CHECK_VAR(p, DEFAULT_TYPE);
140 CHECK_EXPR(Literal, DEFAULT_TYPE);
141 }
142 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
143 CHECK_VAR(q, DEFAULT_TYPE);
144 CHECK_EXPR(Literal, DEFAULT_TYPE);
145 }
146 }
147 // p = (p + 8)|0) {\n"
148 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
149 CHECK_VAR(p, DEFAULT_TYPE);
150 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
151 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
152 CHECK_VAR(p, DEFAULT_TYPE);
153 CHECK_EXPR(Literal, DEFAULT_TYPE);
154 }
155 CHECK_EXPR(Literal, DEFAULT_TYPE);
156 }
157 }
158 // sum = sum + +log(values[p>>3]);
159 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
160 CHECK_VAR(sum, DEFAULT_TYPE);
161 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
162 CHECK_VAR(sum, DEFAULT_TYPE);
163 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
164 CHECK_EXPR(Call, DEFAULT_TYPE) {
165 CHECK_VAR(log, DEFAULT_TYPE);
166 CHECK_VAR(values, DEFAULT_TYPE);
167 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
168 CHECK_VAR(p, DEFAULT_TYPE);
169 CHECK_EXPR(Literal, DEFAULT_TYPE);
170 }
171 }
172 CHECK_EXPR(Literal, DEFAULT_TYPE);
173 }
174 }
175 }
176 // return +sum;
177 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
178 CHECK_VAR(sum, DEFAULT_TYPE);
179 CHECK_EXPR(Literal, DEFAULT_TYPE);
180 }
181 }
182 // function geometricMean
183 CHECK_EXPR(FunctionLiteral, DEFAULT_TYPE) {
184 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
185 CHECK_VAR(start, DEFAULT_TYPE);
186 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
187 CHECK_VAR(start, DEFAULT_TYPE);
188 CHECK_EXPR(Literal, DEFAULT_TYPE);
189 }
190 }
191 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
192 CHECK_VAR(end, DEFAULT_TYPE);
193 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
194 CHECK_VAR(end, DEFAULT_TYPE);
195 CHECK_EXPR(Literal, DEFAULT_TYPE);
196 }
197 }
198 // return +exp(+logSum(start, end) / +((end - start)|0));
199 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
200 CHECK_EXPR(Call, DEFAULT_TYPE) {
201 CHECK_VAR(exp, DEFAULT_TYPE);
202 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
203 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
204 CHECK_EXPR(Call, DEFAULT_TYPE) {
205 CHECK_VAR(logSum, DEFAULT_TYPE);
206 CHECK_VAR(start, DEFAULT_TYPE);
207 CHECK_VAR(end, DEFAULT_TYPE);
208 }
209 CHECK_EXPR(Literal, DEFAULT_TYPE);
210 }
211 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
212 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
213 CHECK_EXPR(BinaryOperation, DEFAULT_TYPE) {
214 CHECK_VAR(end, DEFAULT_TYPE);
215 CHECK_VAR(start, DEFAULT_TYPE);
216 }
217 CHECK_EXPR(Literal, DEFAULT_TYPE);
218 }
219 CHECK_EXPR(Literal, DEFAULT_TYPE);
220 }
221 }
222 }
223 CHECK_EXPR(Literal, DEFAULT_TYPE);
224 }
225 }
226 // "use asm";
227 CHECK_EXPR(Literal, DEFAULT_TYPE);
228 // var exp = stdlib.Math.exp;
229 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
230 CHECK_VAR(exp, DEFAULT_TYPE);
231 CHECK_VAR(stdlib, DEFAULT_TYPE);
232 CHECK_EXPR(Literal, DEFAULT_TYPE);
233 CHECK_EXPR(Literal, DEFAULT_TYPE);
234 }
235 // var log = stdlib.Math.log;
236 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
237 CHECK_VAR(log, DEFAULT_TYPE);
238 CHECK_VAR(stdlib, DEFAULT_TYPE);
239 CHECK_EXPR(Literal, DEFAULT_TYPE);
240 CHECK_EXPR(Literal, DEFAULT_TYPE);
241 }
242 // var values = new stdlib.Float64Array(buffer);
243 CHECK_EXPR(Assignment, DEFAULT_TYPE) {
244 CHECK_VAR(values, DEFAULT_TYPE);
245 CHECK_EXPR(CallNew, DEFAULT_TYPE) {
246 CHECK_VAR(stdlib, DEFAULT_TYPE);
247 CHECK_EXPR(Literal, DEFAULT_TYPE);
248 CHECK_VAR(buffer, DEFAULT_TYPE);
249 }
250 }
251 // return { geometricMean: geometricMean };
252 CHECK_EXPR(ObjectLiteral, DEFAULT_TYPE) {
253 CHECK_VAR(geometricMean, DEFAULT_TYPE);
254 }
255 }
256 }
257 CHECK_TYPES_END
258 }
OLDNEW
« no previous file with comments | « test/cctest/expression-type-collector-macros.h ('k') | test/cctest/test-typing-reset.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698