| 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("../../../lib/compiler/implementation/elements/elements.dart", prefix: "
lego"); | 10 #import("../../../lib/compiler/implementation/elements/elements.dart", prefix: "
lego"); |
| 11 #import("../../../lib/compiler/implementation/js_backend/js_backend.dart", prefi
x: "js"); | 11 #import("../../../lib/compiler/implementation/js_backend/js_backend.dart", prefi
x: "js"); |
| 12 #import("../../../lib/compiler/implementation/leg.dart", prefix: "leg"); | 12 #import("../../../lib/compiler/implementation/leg.dart", prefix: "leg"); |
| 13 #import("../../../lib/compiler/implementation/ssa/ssa.dart", prefix: "ssa"); | 13 #import("../../../lib/compiler/implementation/ssa/ssa.dart", prefix: "ssa"); |
| 14 #import("../../../lib/compiler/implementation/util/util.dart"); | 14 #import("../../../lib/compiler/implementation/util/util.dart"); |
| 15 #import('../../../lib/compiler/implementation/source_file.dart'); | 15 #import('../../../lib/compiler/implementation/source_file.dart'); |
| 16 | 16 |
| 17 #import("mock_compiler.dart"); | 17 #import("mock_compiler.dart"); |
| 18 #import("parser_helper.dart"); | 18 #import("parser_helper.dart"); |
| 19 | 19 |
| 20 String compile(String code, [String entry = 'main', | 20 String compile(String code, [String entry = 'main', |
| 21 bool enableTypeAssertions = false]) { | 21 bool enableTypeAssertions = false]) { |
| 22 MockCompiler compiler = | 22 MockCompiler compiler = |
| 23 new MockCompiler(enableTypeAssertions: enableTypeAssertions); | 23 new MockCompiler(enableTypeAssertions: enableTypeAssertions); |
| 24 compiler.parseScript(code); | 24 compiler.parseScript(code); |
| 25 lego.Element element = compiler.mainApp.find(buildSourceString(entry)); | 25 lego.Element element = compiler.mainApp.find(buildSourceString(entry)); |
| 26 if (element === null) return null; | 26 if (element === null) return null; |
| 27 compiler.backend.enqueueHelpers(compiler.enqueuer.resolution); |
| 27 compiler.processQueue(compiler.enqueuer.resolution, element); | 28 compiler.processQueue(compiler.enqueuer.resolution, element); |
| 28 var context = new js.JavaScriptItemCompilationContext(); | 29 var context = new js.JavaScriptItemCompilationContext(); |
| 29 leg.WorkItem work = new leg.WorkItem(element, null, context); | 30 leg.WorkItem work = new leg.WorkItem(element, null, context); |
| 30 work.run(compiler, compiler.enqueuer.codegen); | 31 work.run(compiler, compiler.enqueuer.codegen); |
| 31 return compiler.enqueuer.codegen.lookupCode(element); | 32 return compiler.enqueuer.codegen.lookupCode(element); |
| 32 } | 33 } |
| 33 | 34 |
| 34 MockCompiler compilerFor(String code, Uri uri) { | 35 MockCompiler compilerFor(String code, Uri uri) { |
| 35 MockCompiler compiler = new MockCompiler(); | 36 MockCompiler compiler = new MockCompiler(); |
| 36 compiler.sourceFiles[uri.toString()] = new SourceFile(uri.toString(), code); | 37 compiler.sourceFiles[uri.toString()] = new SourceFile(uri.toString(), code); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 '"$generated" does not match /$regexp/'); | 87 '"$generated" does not match /$regexp/'); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void compileAndDoNotMatch(String code, String entry, RegExp regexp) { | 90 void compileAndDoNotMatch(String code, String entry, RegExp regexp) { |
| 90 String generated = compile(code, entry); | 91 String generated = compile(code, entry); |
| 91 Expect.isFalse(regexp.hasMatch(generated), | 92 Expect.isFalse(regexp.hasMatch(generated), |
| 92 '"$generated" has a match in /$regexp/'); | 93 '"$generated" has a match in /$regexp/'); |
| 93 } | 94 } |
| 94 | 95 |
| 95 int length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1; | 96 int length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1; |
| OLD | NEW |