| 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 // Test constant folding. | 4 // Test constant folding. |
| 5 | 5 |
| 6 library compiler_helper; | 6 library compiler_helper; |
| 7 | 7 |
| 8 import "dart:uri"; | 8 import "dart:uri"; |
| 9 | 9 |
| 10 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t" | 10 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t" |
| 11 as lego; | 11 as lego; |
| 12 import "../../../sdk/lib/_internal/compiler/implementation/js_backend/js_backend
.dart" | 12 import "../../../sdk/lib/_internal/compiler/implementation/js_backend/js_backend
.dart" |
| 13 as js; | 13 as js; |
| 14 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart" | 14 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart" |
| 15 as leg; | 15 as leg; |
| 16 import "../../../sdk/lib/_internal/compiler/implementation/ssa/ssa.dart" as ssa; | 16 import "../../../sdk/lib/_internal/compiler/implementation/ssa/ssa.dart" as ssa; |
| 17 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart"; | 17 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart"; |
| 18 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; | 18 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; |
| 19 | 19 |
| 20 import "mock_compiler.dart"; | 20 import "mock_compiler.dart"; |
| 21 import "parser_helper.dart"; | 21 import "parser_helper.dart"; |
| 22 | 22 |
| 23 String compile(String code, {String entry: 'main', | 23 String compile(String code, {String entry: 'main', |
| 24 bool enableTypeAssertions: false, | 24 bool enableTypeAssertions: false, |
| 25 bool minify: false}) { | 25 bool minify: false, |
| 26 bool analyzeAll: false}) { |
| 26 MockCompiler compiler = | 27 MockCompiler compiler = |
| 27 new MockCompiler(enableTypeAssertions: enableTypeAssertions, | 28 new MockCompiler(enableTypeAssertions: enableTypeAssertions, |
| 28 enableMinification: minify); | 29 enableMinification: minify); |
| 29 compiler.parseScript(code); | 30 compiler.parseScript(code); |
| 30 lego.Element element = compiler.mainApp.find(buildSourceString(entry)); | 31 lego.Element element = compiler.mainApp.find(buildSourceString(entry)); |
| 31 if (element == null) return null; | 32 if (element == null) return null; |
| 32 compiler.backend.enqueueHelpers(compiler.enqueuer.resolution); | 33 compiler.backend.enqueueHelpers(compiler.enqueuer.resolution); |
| 33 compiler.processQueue(compiler.enqueuer.resolution, element); | 34 compiler.processQueue(compiler.enqueuer.resolution, element); |
| 34 var context = new js.JavaScriptItemCompilationContext(); | 35 var context = new js.JavaScriptItemCompilationContext(); |
| 35 leg.WorkItem work = new leg.WorkItem(element, null, context); | 36 leg.WorkItem work = new leg.WorkItem(element, null, context); |
| 36 work.run(compiler, compiler.enqueuer.codegen); | 37 work.run(compiler, compiler.enqueuer.codegen); |
| 37 return compiler.enqueuer.codegen.lookupCode(element); | 38 return compiler.enqueuer.codegen.lookupCode(element); |
| 38 } | 39 } |
| 39 | 40 |
| 40 MockCompiler compilerFor(String code, Uri uri) { | 41 MockCompiler compilerFor(String code, Uri uri, {bool analyzeAll: false}) { |
| 41 MockCompiler compiler = new MockCompiler(); | 42 MockCompiler compiler = new MockCompiler(analyzeAll: analyzeAll); |
| 42 compiler.sourceFiles[uri.toString()] = new SourceFile(uri.toString(), code); | 43 compiler.sourceFiles[uri.toString()] = new SourceFile(uri.toString(), code); |
| 43 return compiler; | 44 return compiler; |
| 44 } | 45 } |
| 45 | 46 |
| 46 String compileAll(String code) { | 47 String compileAll(String code) { |
| 47 Uri uri = new Uri.fromComponents(scheme: 'source'); | 48 Uri uri = new Uri.fromComponents(scheme: 'source'); |
| 48 MockCompiler compiler = compilerFor(code, uri); | 49 MockCompiler compiler = compilerFor(code, uri); |
| 49 compiler.runCompiler(uri); | 50 compiler.runCompiler(uri); |
| 50 Expect.isFalse(compiler.compilationFailed, | 51 Expect.isFalse(compiler.compilationFailed, |
| 51 'Unexpected compilation error'); | 52 'Unexpected compilation error'); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); | 118 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); |
| 118 final spaceRe = new RegExp('\\s+'); | 119 final spaceRe = new RegExp('\\s+'); |
| 119 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); | 120 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); |
| 120 if (shouldMatch) { | 121 if (shouldMatch) { |
| 121 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); | 122 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); |
| 122 } else { | 123 } else { |
| 123 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); | 124 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); |
| 124 } | 125 } |
| 125 } | 126 } |
| 126 | 127 |
| OLD | NEW |