OLD | NEW |
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/implementation/elements/elements.dart' | 10 import 'package:compiler/implementation/elements/elements.dart' |
(...skipping 28 matching lines...) Expand all Loading... |
39 import 'package:compiler/implementation/dart2jslib.dart' | 39 import 'package:compiler/implementation/dart2jslib.dart' |
40 show Compiler; | 40 show Compiler; |
41 | 41 |
42 export 'package:compiler/implementation/tree/tree.dart'; | 42 export 'package:compiler/implementation/tree/tree.dart'; |
43 | 43 |
44 import 'mock_compiler.dart'; | 44 import 'mock_compiler.dart'; |
45 export 'mock_compiler.dart'; | 45 export 'mock_compiler.dart'; |
46 | 46 |
47 Future<String> compile(String code, | 47 Future<String> compile(String code, |
48 {String entry: 'main', | 48 {String entry: 'main', |
49 String coreSource: DEFAULT_CORELIB, | |
50 String interceptorsSource: DEFAULT_INTERCEPTORSLIB, | |
51 bool enableTypeAssertions: false, | 49 bool enableTypeAssertions: false, |
52 bool minify: false, | 50 bool minify: false, |
53 bool analyzeAll: false, | 51 bool analyzeAll: false, |
54 bool disableInlining: true, | 52 bool disableInlining: true, |
55 void check(String generated)}) { | 53 void check(String generated)}) { |
56 MockCompiler compiler = new MockCompiler.internal( | 54 MockCompiler compiler = new MockCompiler.internal( |
57 enableTypeAssertions: enableTypeAssertions, | 55 enableTypeAssertions: enableTypeAssertions, |
58 coreSource: coreSource, | |
59 // Type inference does not run when manually | 56 // Type inference does not run when manually |
60 // compiling a method. | 57 // compiling a method. |
61 disableTypeInference: true, | 58 disableTypeInference: true, |
62 interceptorsSource: interceptorsSource, | |
63 enableMinification: minify, | 59 enableMinification: minify, |
64 disableInlining: disableInlining); | 60 disableInlining: disableInlining); |
65 return compiler.init().then((_) { | 61 return compiler.init().then((_) { |
66 compiler.parseScript(code); | 62 compiler.parseScript(code); |
67 lego.Element element = compiler.mainApp.find(entry); | 63 lego.Element element = compiler.mainApp.find(entry); |
68 if (element == null) return null; | 64 if (element == null) return null; |
69 compiler.phase = Compiler.PHASE_RESOLVING; | 65 compiler.phase = Compiler.PHASE_RESOLVING; |
70 compiler.backend.enqueueHelpers(compiler.enqueuer.resolution, | 66 compiler.backend.enqueueHelpers(compiler.enqueuer.resolution, |
71 compiler.globalDependencies); | 67 compiler.globalDependencies); |
72 compiler.processQueue(compiler.enqueuer.resolution, element); | 68 compiler.processQueue(compiler.enqueuer.resolution, element); |
(...skipping 12 matching lines...) Expand all Loading... |
85 check(generated); | 81 check(generated); |
86 } | 82 } |
87 return generated; | 83 return generated; |
88 }); | 84 }); |
89 } | 85 } |
90 | 86 |
91 // TODO(herhut): Disallow warnings and errors during compilation by default. | 87 // TODO(herhut): Disallow warnings and errors during compilation by default. |
92 MockCompiler compilerFor(String code, Uri uri, | 88 MockCompiler compilerFor(String code, Uri uri, |
93 {bool analyzeAll: false, | 89 {bool analyzeAll: false, |
94 bool analyzeOnly: false, | 90 bool analyzeOnly: false, |
95 String coreSource: DEFAULT_CORELIB, | 91 Map<String, String> coreSource, |
96 bool disableInlining: true, | 92 bool disableInlining: true, |
97 bool minify: false, | 93 bool minify: false, |
98 int expectedErrors, | 94 int expectedErrors, |
99 int expectedWarnings}) { | 95 int expectedWarnings}) { |
100 MockCompiler compiler = new MockCompiler.internal( | 96 MockCompiler compiler = new MockCompiler.internal( |
101 analyzeAll: analyzeAll, | 97 analyzeAll: analyzeAll, |
102 analyzeOnly: analyzeOnly, | 98 analyzeOnly: analyzeOnly, |
103 coreSource: coreSource, | 99 coreSource: coreSource, |
104 disableInlining: disableInlining, | 100 disableInlining: disableInlining, |
105 enableMinification: minify, | 101 enableMinification: minify, |
106 expectedErrors: expectedErrors, | 102 expectedErrors: expectedErrors, |
107 expectedWarnings: expectedWarnings); | 103 expectedWarnings: expectedWarnings); |
108 compiler.registerSource(uri, code); | 104 compiler.registerSource(uri, code); |
109 return compiler; | 105 return compiler; |
110 } | 106 } |
111 | 107 |
112 Future<String> compileAll(String code, | 108 Future<String> compileAll(String code, |
113 {String coreSource: DEFAULT_CORELIB, | 109 {Map<String, String> coreSource, |
114 bool disableInlining: true, | 110 bool disableInlining: true, |
115 bool minify: false, | 111 bool minify: false, |
116 int expectedErrors, | 112 int expectedErrors, |
117 int expectedWarnings}) { | 113 int expectedWarnings}) { |
118 Uri uri = new Uri(scheme: 'source'); | 114 Uri uri = new Uri(scheme: 'source'); |
119 MockCompiler compiler = compilerFor( | 115 MockCompiler compiler = compilerFor( |
120 code, uri, coreSource: coreSource, disableInlining: disableInlining, | 116 code, uri, coreSource: coreSource, disableInlining: disableInlining, |
121 minify: minify, expectedErrors: expectedErrors, | 117 minify: minify, expectedErrors: expectedErrors, |
122 expectedWarnings: expectedWarnings); | 118 expectedWarnings: expectedWarnings); |
123 return compiler.runCompiler(uri).then((_) { | 119 return compiler.runCompiler(uri).then((_) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); | 240 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); |
245 final spaceRe = new RegExp('\\s+'); | 241 final spaceRe = new RegExp('\\s+'); |
246 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); | 242 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); |
247 if (shouldMatch) { | 243 if (shouldMatch) { |
248 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); | 244 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); |
249 } else { | 245 } else { |
250 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); | 246 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); |
251 } | 247 } |
252 }); | 248 }); |
253 } | 249 } |
OLD | NEW |