| 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 #import("../../../lib/compiler/implementation/leg.dart", prefix: "leg"); | 9 #import("../../../lib/compiler/implementation/leg.dart", prefix: "leg"); |
| 10 #import("../../../lib/compiler/implementation/js_backend/js_backend.dart", prefi
x: "js"); |
| 10 #import("../../../lib/compiler/implementation/elements/elements.dart", prefix: "
lego"); | 11 #import("../../../lib/compiler/implementation/elements/elements.dart", prefix: "
lego"); |
| 11 #import('../../../lib/compiler/implementation/source_file.dart'); | 12 #import('../../../lib/compiler/implementation/source_file.dart'); |
| 12 #import("../../../lib/compiler/implementation/ssa/ssa.dart", prefix: "ssa"); | 13 #import("../../../lib/compiler/implementation/ssa/ssa.dart", prefix: "ssa"); |
| 13 #import("parser_helper.dart"); | 14 #import("parser_helper.dart"); |
| 14 #import("mock_compiler.dart"); | 15 #import("mock_compiler.dart"); |
| 15 | 16 |
| 16 String compile(String code, [String entry = 'main']) { | 17 String compile(String code, [String entry = 'main']) { |
| 17 MockCompiler compiler = new MockCompiler(); | 18 MockCompiler compiler = new MockCompiler(); |
| 18 compiler.parseScript(code); | 19 compiler.parseScript(code); |
| 19 lego.Element element = compiler.mainApp.find(buildSourceString(entry)); | 20 lego.Element element = compiler.mainApp.find(buildSourceString(entry)); |
| 20 if (element === null) return null; | 21 if (element === null) return null; |
| 21 compiler.processQueue(compiler.enqueuer.resolution, element); | 22 compiler.processQueue(compiler.enqueuer.resolution, element); |
| 22 leg.WorkItem work = new leg.WorkItem(element, null); | 23 var context = new js.JavaScriptItemCompilationContext(); |
| 24 leg.WorkItem work = new leg.WorkItem(element, null, context); |
| 23 work.run(compiler, compiler.enqueuer.codegen); | 25 work.run(compiler, compiler.enqueuer.codegen); |
| 24 return compiler.enqueuer.codegen.lookupCode(element); | 26 return compiler.enqueuer.codegen.lookupCode(element); |
| 25 } | 27 } |
| 26 | 28 |
| 27 MockCompiler compilerFor(String code, Uri uri) { | 29 MockCompiler compilerFor(String code, Uri uri) { |
| 28 MockCompiler compiler = new MockCompiler(); | 30 MockCompiler compiler = new MockCompiler(); |
| 29 compiler.sourceFiles[uri.toString()] = new SourceFile(uri.toString(), code); | 31 compiler.sourceFiles[uri.toString()] = new SourceFile(uri.toString(), code); |
| 30 return compiler; | 32 return compiler; |
| 31 } | 33 } |
| 32 | 34 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 String generated = compile(code, entry); | 67 String generated = compile(code, entry); |
| 66 Expect.isTrue(regexp.hasMatch(generated), | 68 Expect.isTrue(regexp.hasMatch(generated), |
| 67 '"$generated" does not match /$regexp/'); | 69 '"$generated" does not match /$regexp/'); |
| 68 } | 70 } |
| 69 | 71 |
| 70 void compileAndDoNotMatch(String code, String entry, RegExp regexp) { | 72 void compileAndDoNotMatch(String code, String entry, RegExp regexp) { |
| 71 String generated = compile(code, entry); | 73 String generated = compile(code, entry); |
| 72 Expect.isFalse(regexp.hasMatch(generated), | 74 Expect.isFalse(regexp.hasMatch(generated), |
| 73 '"$generated" has a match in /$regexp/'); | 75 '"$generated" has a match in /$regexp/'); |
| 74 } | 76 } |
| OLD | NEW |