OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
6 #include "src/compilation-info.h" | 6 #include "src/compilation-info.h" |
7 #include "src/compiler/ast-loop-assignment-analyzer.h" | 7 #include "src/compiler/ast-loop-assignment-analyzer.h" |
8 #include "src/parsing/parse-info.h" | 8 #include "src/parsing/parse-info.h" |
9 #include "src/parsing/parser.h" | 9 #include "src/parsing/parsing.h" |
10 #include "src/parsing/rewriter.h" | 10 #include "src/parsing/rewriter.h" |
11 #include "test/cctest/cctest.h" | 11 #include "test/cctest/cctest.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 namespace compiler { | 15 namespace compiler { |
16 | 16 |
17 namespace { | 17 namespace { |
18 const int kBufferSize = 1024; | 18 const int kBufferSize = 1024; |
19 | 19 |
20 struct TestHelper : public HandleAndZoneScope { | 20 struct TestHelper : public HandleAndZoneScope { |
21 Handle<JSFunction> function; | 21 Handle<JSFunction> function; |
22 LoopAssignmentAnalysis* result; | 22 LoopAssignmentAnalysis* result; |
23 | 23 |
24 explicit TestHelper(const char* body) | 24 explicit TestHelper(const char* body) |
25 : function(Handle<JSFunction>::null()), result(NULL) { | 25 : function(Handle<JSFunction>::null()), result(NULL) { |
26 ScopedVector<char> program(kBufferSize); | 26 ScopedVector<char> program(kBufferSize); |
27 SNPrintF(program, "function f(a,b,c) { %s; } f;", body); | 27 SNPrintF(program, "function f(a,b,c) { %s; } f;", body); |
28 v8::Local<v8::Value> v = CompileRun(program.start()); | 28 v8::Local<v8::Value> v = CompileRun(program.start()); |
29 Handle<Object> obj = v8::Utils::OpenHandle(*v); | 29 Handle<Object> obj = v8::Utils::OpenHandle(*v); |
30 function = Handle<JSFunction>::cast(obj); | 30 function = Handle<JSFunction>::cast(obj); |
31 } | 31 } |
32 | 32 |
33 void CheckLoopAssignedCount(int expected, const char* var_name) { | 33 void CheckLoopAssignedCount(int expected, const char* var_name) { |
34 // TODO(titzer): don't scope analyze every single time. | 34 // TODO(titzer): don't scope analyze every single time. |
35 ParseInfo parse_info(main_zone(), handle(function->shared())); | 35 ParseInfo parse_info(main_zone(), handle(function->shared())); |
36 CompilationInfo info(&parse_info, function); | 36 CompilationInfo info(&parse_info, function); |
37 | 37 |
38 CHECK(Parser::ParseStatic(&parse_info)); | 38 CHECK(parsing::ParseFunction(&parse_info)); |
39 CHECK(Rewriter::Rewrite(&parse_info)); | 39 CHECK(Rewriter::Rewrite(&parse_info)); |
40 DeclarationScope::Analyze(&parse_info, AnalyzeMode::kRegular); | 40 DeclarationScope::Analyze(&parse_info, AnalyzeMode::kRegular); |
41 | 41 |
42 DeclarationScope* scope = info.literal()->scope(); | 42 DeclarationScope* scope = info.literal()->scope(); |
43 AstValueFactory* factory = parse_info.ast_value_factory(); | 43 AstValueFactory* factory = parse_info.ast_value_factory(); |
44 CHECK(scope); | 44 CHECK(scope); |
45 | 45 |
46 if (result == NULL) { | 46 if (result == NULL) { |
47 AstLoopAssignmentAnalyzer analyzer(main_zone(), &info); | 47 AstLoopAssignmentAnalyzer analyzer(main_zone(), &info); |
48 result = analyzer.Analyze(); | 48 result = analyzer.Analyze(); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 293 |
294 f.CheckLoopAssignedCount(1, "x"); | 294 f.CheckLoopAssignedCount(1, "x"); |
295 f.CheckLoopAssignedCount(3, "y"); | 295 f.CheckLoopAssignedCount(3, "y"); |
296 f.CheckLoopAssignedCount(5, "z"); | 296 f.CheckLoopAssignedCount(5, "z"); |
297 f.CheckLoopAssignedCount(0, "w"); | 297 f.CheckLoopAssignedCount(0, "w"); |
298 } | 298 } |
299 | 299 |
300 } // namespace compiler | 300 } // namespace compiler |
301 } // namespace internal | 301 } // namespace internal |
302 } // namespace v8 | 302 } // namespace v8 |
OLD | NEW |