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

Side by Side Diff: tests/compiler/dart2js/compiler_helper.dart

Issue 2690063002: Refactor CompilerOutput (Closed)
Patch Set: Cleanup. Created 3 years, 10 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library compiler_helper; 5 library compiler_helper;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
9 9
10 import 'package:compiler/compiler_new.dart';
11
10 import 'package:compiler/src/elements/elements.dart' as lego; 12 import 'package:compiler/src/elements/elements.dart' as lego;
11 export 'package:compiler/src/elements/elements.dart'; 13 export 'package:compiler/src/elements/elements.dart';
12 14
13 import 'package:compiler/src/js_backend/js_backend.dart' as js; 15 import 'package:compiler/src/js_backend/js_backend.dart' as js;
14 16
15 import 'package:compiler/src/commandline_options.dart'; 17 import 'package:compiler/src/commandline_options.dart';
16 import 'package:compiler/src/common/codegen.dart'; 18 import 'package:compiler/src/common/codegen.dart';
17 import 'package:compiler/src/common/resolution.dart'; 19 import 'package:compiler/src/common/resolution.dart';
18 20
19 export 'package:compiler/src/diagnostics/messages.dart'; 21 export 'package:compiler/src/diagnostics/messages.dart';
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 resolutionWork.run(); 82 resolutionWork.run();
81 compiler.closeResolution(); 83 compiler.closeResolution();
82 CodegenWorkItem work = new CodegenWorkItem(compiler.backend, element); 84 CodegenWorkItem work = new CodegenWorkItem(compiler.backend, element);
83 compiler.phase = Compiler.PHASE_COMPILING; 85 compiler.phase = Compiler.PHASE_COMPILING;
84 work.run(); 86 work.run();
85 js.JavaScriptBackend backend = compiler.backend; 87 js.JavaScriptBackend backend = compiler.backend;
86 String generated = backend.getGeneratedCode(element); 88 String generated = backend.getGeneratedCode(element);
87 if (check != null) { 89 if (check != null) {
88 check(generated); 90 check(generated);
89 } 91 }
90 return returnAll ? outputCollector.getOutput('', 'js') : generated; 92 return returnAll ? outputCollector.getOutput('', OutputType.js) : generated;
91 } else { 93 } else {
92 List<String> options = <String>[Flags.disableTypeInference]; 94 List<String> options = <String>[Flags.disableTypeInference];
93 if (enableTypeAssertions) { 95 if (enableTypeAssertions) {
94 options.add(Flags.enableCheckedMode); 96 options.add(Flags.enableCheckedMode);
95 } 97 }
96 if (minify) { 98 if (minify) {
97 options.add(Flags.minify); 99 options.add(Flags.minify);
98 } 100 }
99 if (analyzeAll) { 101 if (analyzeAll) {
100 options.add(Flags.analyzeAll); 102 options.add(Flags.analyzeAll);
(...skipping 18 matching lines...) Expand all
119 options: options, 121 options: options,
120 outputProvider: outputCollector); 122 outputProvider: outputCollector);
121 Expect.isTrue(result.isSuccess); 123 Expect.isTrue(result.isSuccess);
122 Compiler compiler = result.compiler; 124 Compiler compiler = result.compiler;
123 lego.Element element = compiler.mainApp.find(entry); 125 lego.Element element = compiler.mainApp.find(entry);
124 js.JavaScriptBackend backend = compiler.backend; 126 js.JavaScriptBackend backend = compiler.backend;
125 String generated = backend.getGeneratedCode(element); 127 String generated = backend.getGeneratedCode(element);
126 if (check != null) { 128 if (check != null) {
127 check(generated); 129 check(generated);
128 } 130 }
129 return returnAll ? outputCollector.getOutput('', 'js') : generated; 131 return returnAll ? outputCollector.getOutput('', OutputType.js) : generated;
130 } 132 }
131 } 133 }
132 134
133 Future<String> compileAll(String code, 135 Future<String> compileAll(String code,
134 {Map<String, String> coreSource, 136 {Map<String, String> coreSource,
135 bool disableInlining: true, 137 bool disableInlining: true,
136 bool trustTypeAnnotations: false, 138 bool trustTypeAnnotations: false,
137 bool minify: false, 139 bool minify: false,
138 int expectedErrors, 140 int expectedErrors,
139 int expectedWarnings}) { 141 int expectedWarnings}) {
140 Uri uri = new Uri(scheme: 'source'); 142 Uri uri = new Uri(scheme: 'source');
141 OutputCollector outputCollector = new OutputCollector(); 143 OutputCollector outputCollector = new OutputCollector();
142 MockCompiler compiler = compilerFor(code, uri, 144 MockCompiler compiler = compilerFor(code, uri,
143 coreSource: coreSource, 145 coreSource: coreSource,
144 disableInlining: disableInlining, 146 disableInlining: disableInlining,
145 minify: minify, 147 minify: minify,
146 expectedErrors: expectedErrors, 148 expectedErrors: expectedErrors,
147 trustTypeAnnotations: trustTypeAnnotations, 149 trustTypeAnnotations: trustTypeAnnotations,
148 expectedWarnings: expectedWarnings, 150 expectedWarnings: expectedWarnings,
149 outputProvider: outputCollector); 151 outputProvider: outputCollector);
150 compiler.diagnosticHandler = createHandler(compiler, code); 152 compiler.diagnosticHandler = createHandler(compiler, code);
151 return compiler.run(uri).then((compilationSucceded) { 153 return compiler.run(uri).then((compilationSucceded) {
152 Expect.isTrue( 154 Expect.isTrue(
153 compilationSucceded, 155 compilationSucceded,
154 'Unexpected compilation error(s): ' 156 'Unexpected compilation error(s): '
155 '${compiler.diagnosticCollector.errors}'); 157 '${compiler.diagnosticCollector.errors}');
156 return outputCollector.getOutput('', 'js'); 158 return outputCollector.getOutput('', OutputType.js);
157 }); 159 });
158 } 160 }
159 161
160 Future compileAndCheck(String code, String name, 162 Future compileAndCheck(String code, String name,
161 check(MockCompiler compiler, lego.Element element), 163 check(MockCompiler compiler, lego.Element element),
162 {int expectedErrors, int expectedWarnings}) { 164 {int expectedErrors, int expectedWarnings}) {
163 Uri uri = new Uri(scheme: 'source'); 165 Uri uri = new Uri(scheme: 'source');
164 MockCompiler compiler = compilerFor(code, uri, 166 MockCompiler compiler = compilerFor(code, uri,
165 expectedErrors: expectedErrors, expectedWarnings: expectedWarnings); 167 expectedErrors: expectedErrors, expectedWarnings: expectedWarnings);
166 return compiler.run(uri).then((_) { 168 return compiler.run(uri).then((_) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 291 }
290 } 292 }
291 293
292 return checker; 294 return checker;
293 } 295 }
294 296
295 RegExp _directivePattern = new RegExp( 297 RegExp _directivePattern = new RegExp(
296 // \1 \2 \3 298 // \1 \2 \3
297 r'''// *(present|absent): *(?:"([^"]*)"|'([^'']*)')''', 299 r'''// *(present|absent): *(?:"([^"]*)"|'([^'']*)')''',
298 multiLine: true); 300 multiLine: true);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698