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

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

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

Powered by Google App Engine
This is Rietveld 408576698