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

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

Issue 832363002: Remove Compiler.assembledCode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 | Annotate | Revision Log
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.dart' as api;
11
10 import 'package:compiler/src/elements/elements.dart' 12 import 'package:compiler/src/elements/elements.dart'
11 as lego; 13 as lego;
12 export 'package:compiler/src/elements/elements.dart'; 14 export 'package:compiler/src/elements/elements.dart';
13 15
14 import 'package:compiler/src/js_backend/js_backend.dart' 16 import 'package:compiler/src/js_backend/js_backend.dart'
15 as js; 17 as js;
16 18
17 import 'package:compiler/src/dart2jslib.dart' 19 import 'package:compiler/src/dart2jslib.dart'
18 as leg; 20 as leg;
19 export 'package:compiler/src/dart2jslib.dart' 21 export 'package:compiler/src/dart2jslib.dart'
20 show Constant, 22 show Constant,
21 Message, 23 Message,
22 MessageKind, 24 MessageKind,
23 Selector, 25 Selector,
24 TypedSelector, 26 TypedSelector,
25 SourceSpan, 27 SourceSpan,
26 World; 28 World;
27 29
28 import 'package:compiler/src/ssa/ssa.dart' as ssa;
29
30 import 'package:compiler/src/types/types.dart' 30 import 'package:compiler/src/types/types.dart'
31 as types; 31 as types;
32 export 'package:compiler/src/types/types.dart' 32 export 'package:compiler/src/types/types.dart'
33 show TypeMask; 33 show TypeMask;
34 34
35 import 'package:compiler/src/util/util.dart'; 35 import 'package:compiler/src/util/util.dart';
36 export 'package:compiler/src/util/util.dart'; 36 export 'package:compiler/src/util/util.dart';
37 37
38 import 'package:compiler/src/source_file.dart';
39
40 import 'package:compiler/src/dart2jslib.dart' 38 import 'package:compiler/src/dart2jslib.dart'
41 show Compiler; 39 show Compiler;
42 40
43 export 'package:compiler/src/tree/tree.dart'; 41 export 'package:compiler/src/tree/tree.dart';
44 42
45 import 'mock_compiler.dart'; 43 import 'mock_compiler.dart';
46 export 'mock_compiler.dart'; 44 export 'mock_compiler.dart';
47 45
46 import 'output_collector.dart';
47 export 'output_collector.dart';
48
48 Future<String> compile(String code, 49 Future<String> compile(String code,
49 {String entry: 'main', 50 {String entry: 'main',
50 bool enableTypeAssertions: false, 51 bool enableTypeAssertions: false,
51 bool minify: false, 52 bool minify: false,
52 bool analyzeAll: false, 53 bool analyzeAll: false,
53 bool disableInlining: true, 54 bool disableInlining: true,
54 void check(String generated)}) { 55 void check(String generated)}) {
55 MockCompiler compiler = new MockCompiler.internal( 56 MockCompiler compiler = new MockCompiler.internal(
56 enableTypeAssertions: enableTypeAssertions, 57 enableTypeAssertions: enableTypeAssertions,
57 // Type inference does not run when manually 58 // Type inference does not run when manually
(...skipping 29 matching lines...) Expand all
87 88
88 // TODO(herhut): Disallow warnings and errors during compilation by default. 89 // TODO(herhut): Disallow warnings and errors during compilation by default.
89 MockCompiler compilerFor(String code, Uri uri, 90 MockCompiler compilerFor(String code, Uri uri,
90 {bool analyzeAll: false, 91 {bool analyzeAll: false,
91 bool analyzeOnly: false, 92 bool analyzeOnly: false,
92 Map<String, String> coreSource, 93 Map<String, String> coreSource,
93 bool disableInlining: true, 94 bool disableInlining: true,
94 bool minify: false, 95 bool minify: false,
95 bool trustTypeAnnotations: false, 96 bool trustTypeAnnotations: false,
96 int expectedErrors, 97 int expectedErrors,
97 int expectedWarnings}) { 98 int expectedWarnings,
99 api.CompilerOutputProvider outputProvider}) {
98 MockCompiler compiler = new MockCompiler.internal( 100 MockCompiler compiler = new MockCompiler.internal(
99 analyzeAll: analyzeAll, 101 analyzeAll: analyzeAll,
100 analyzeOnly: analyzeOnly, 102 analyzeOnly: analyzeOnly,
101 coreSource: coreSource, 103 coreSource: coreSource,
102 disableInlining: disableInlining, 104 disableInlining: disableInlining,
103 enableMinification: minify, 105 enableMinification: minify,
104 trustTypeAnnotations: trustTypeAnnotations, 106 trustTypeAnnotations: trustTypeAnnotations,
105 expectedErrors: expectedErrors, 107 expectedErrors: expectedErrors,
106 expectedWarnings: expectedWarnings); 108 expectedWarnings: expectedWarnings,
109 outputProvider: outputProvider);
107 compiler.registerSource(uri, code); 110 compiler.registerSource(uri, code);
108 return compiler; 111 return compiler;
109 } 112 }
110 113
111 Future<String> compileAll(String code, 114 Future<String> compileAll(String code,
112 {Map<String, String> coreSource, 115 {Map<String, String> coreSource,
113 bool disableInlining: true, 116 bool disableInlining: true,
114 bool trustTypeAnnotations: false, 117 bool trustTypeAnnotations: false,
115 bool minify: false, 118 bool minify: false,
116 int expectedErrors, 119 int expectedErrors,
117 int expectedWarnings}) { 120 int expectedWarnings}) {
118 Uri uri = new Uri(scheme: 'source'); 121 Uri uri = new Uri(scheme: 'source');
122 OutputCollector outputCollector = new OutputCollector();
119 MockCompiler compiler = compilerFor( 123 MockCompiler compiler = compilerFor(
120 code, uri, coreSource: coreSource, disableInlining: disableInlining, 124 code, uri, coreSource: coreSource, disableInlining: disableInlining,
121 minify: minify, expectedErrors: expectedErrors, 125 minify: minify, expectedErrors: expectedErrors,
122 trustTypeAnnotations: trustTypeAnnotations, 126 trustTypeAnnotations: trustTypeAnnotations,
123 expectedWarnings: expectedWarnings); 127 expectedWarnings: expectedWarnings,
128 outputProvider: outputCollector);
124 return compiler.runCompiler(uri).then((_) { 129 return compiler.runCompiler(uri).then((_) {
125 Expect.isFalse(compiler.compilationFailed, 130 Expect.isFalse(compiler.compilationFailed,
126 'Unexpected compilation error(s): ${compiler.errors}'); 131 'Unexpected compilation error(s): ${compiler.errors}');
127 return compiler.assembledCode; 132 return outputCollector.getOutput('', 'js');
128 }); 133 });
129 } 134 }
130 135
131 Future compileAndCheck(String code, 136 Future compileAndCheck(String code,
132 String name, 137 String name,
133 check(MockCompiler compiler, lego.Element element), 138 check(MockCompiler compiler, lego.Element element),
134 {int expectedErrors, int expectedWarnings}) { 139 {int expectedErrors, int expectedWarnings}) {
135 Uri uri = new Uri(scheme: 'source'); 140 Uri uri = new Uri(scheme: 'source');
136 MockCompiler compiler = compilerFor(code, uri, 141 MockCompiler compiler = compilerFor(code, uri,
137 expectedErrors: expectedErrors, 142 expectedErrors: expectedErrors,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 var sourceName = name; 180 var sourceName = name;
176 var element = compiler.mainApp.find(sourceName); 181 var element = compiler.mainApp.find(sourceName);
177 if (element == null) { 182 if (element == null) {
178 element = compiler.backend.interceptorsLibrary.find(sourceName); 183 element = compiler.backend.interceptorsLibrary.find(sourceName);
179 } 184 }
180 if (element == null) { 185 if (element == null) {
181 element = compiler.coreLibrary.find(sourceName); 186 element = compiler.coreLibrary.find(sourceName);
182 } 187 }
183 Expect.isNotNull(element, 'Could not locate $name'); 188 Expect.isNotNull(element, 'Could not locate $name');
184 switch (how) { 189 switch (how) {
185 case 'exact': return new types.TypeMask.exact(element); 190 case 'exact':
186 case 'nonNullExact': return new types.TypeMask.nonNullExact(element); 191 return new types.TypeMask.exact(element, compiler.world);
187 case 'subclass': { 192 case 'nonNullExact':
193 return new types.TypeMask.nonNullExact(element, compiler.world);
194 case 'subclass':
188 return new types.TypeMask.subclass(element, compiler.world); 195 return new types.TypeMask.subclass(element, compiler.world);
189 } 196 case 'nonNullSubclass':
190 case 'nonNullSubclass': {
191 return new types.TypeMask.nonNullSubclass(element, compiler.world); 197 return new types.TypeMask.nonNullSubclass(element, compiler.world);
192 } 198 case 'subtype':
193 case 'subtype': {
194 return new types.TypeMask.subtype(element, compiler.world); 199 return new types.TypeMask.subtype(element, compiler.world);
195 } 200 case 'nonNullSubtype':
196 case 'nonNullSubtype': {
197 return new types.TypeMask.nonNullSubtype(element, compiler.world); 201 return new types.TypeMask.nonNullSubtype(element, compiler.world);
198 }
199 } 202 }
200 Expect.fail('Unknown TypeMask constructor $how'); 203 Expect.fail('Unknown TypeMask constructor $how');
204 return null;
201 } 205 }
202 206
203 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*"; 207 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*";
204 208
205 String getIntTypeCheck(String variable) { 209 String getIntTypeCheck(String variable) {
206 return "\\($variable ?!== ?\\($variable ?\\| ?0\\)|" 210 return "\\($variable ?!== ?\\($variable ?\\| ?0\\)|"
207 "\\($variable ?>>> ?0 ?!== ?$variable"; 211 "\\($variable ?>>> ?0 ?!== ?$variable";
208 } 212 }
209 213
210 String getNumberTypeCheck(String variable) { 214 String getNumberTypeCheck(String variable) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); 257 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)');
254 final spaceRe = new RegExp('\\s+'); 258 final spaceRe = new RegExp('\\s+');
255 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); 259 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)');
256 if (shouldMatch) { 260 if (shouldMatch) {
257 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); 261 Expect.isTrue(new RegExp(regexp).hasMatch(generated));
258 } else { 262 } else {
259 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); 263 Expect.isFalse(new RegExp(regexp).hasMatch(generated));
260 } 264 }
261 }); 265 });
262 } 266 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698