OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // Test constant folding. | |
5 | |
6 #library("compiler_helper"); | |
7 | |
8 #import("dart:uri"); | |
9 #import("../../../lib/compiler/implementation/leg.dart", prefix: "leg"); | |
10 #import("../../../lib/compiler/implementation/elements/elements.dart", prefix: "
lego"); | |
11 #import("../../../lib/compiler/implementation/ssa/ssa.dart", prefix: "ssa"); | |
12 #import("parser_helper.dart"); | |
13 #import("mock_compiler.dart"); | |
14 | |
15 String compile(String code, [String entry = 'main']) { | |
16 MockCompiler compiler = new MockCompiler(); | |
17 compiler.parseScript(code); | |
18 lego.Element element = compiler.mainApp.find(buildSourceString(entry)); | |
19 if (element === null) return null; | |
20 leg.WorkItem work = new leg.WorkItem(element, null); | |
21 work.run(compiler, compiler.enqueuer.resolution); | |
22 String generated = work.run(compiler, compiler.enqueuer.codegen); | |
23 return generated; | |
24 } | |
25 | |
26 String compileAll(String code) { | |
27 MockCompiler compiler = new MockCompiler(); | |
28 Uri uri = new Uri(scheme: 'source'); | |
29 compiler.sources[uri.toString()] = code; | |
30 compiler.runCompiler(uri); | |
31 return compiler.assembledCode; | |
32 } | |
33 | |
34 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*"; | |
35 | |
36 String getIntTypeCheck(String variable) { | |
37 return "\\($variable !== \\($variable \\| 0\\)\\)"; | |
38 } | |
39 | |
40 String getNumberTypeCheck(String variable) { | |
41 return "\\(typeof $variable !== 'number'\\)"; | |
42 } | |
43 | |
44 bool checkNumberOfMatches(Iterator it, int nb) { | |
45 for (int i = 0; i < nb; i++) { | |
46 Expect.isTrue(it.hasNext()); | |
47 it.next(); | |
48 } | |
49 Expect.isFalse(it.hasNext()); | |
50 } | |
51 | |
52 void compileAndMatch(String code, String entry, RegExp regexp) { | |
53 String generated = compile(code, entry); | |
54 Expect.isTrue(regexp.hasMatch(generated), | |
55 '"$generated" does not match /$regexp/'); | |
56 } | |
57 | |
58 void compileAndDoNotMatch(String code, String entry, RegExp regexp) { | |
59 String generated = compile(code, entry); | |
60 Expect.isFalse(regexp.hasMatch(generated), | |
61 '"$generated" has a match in /$regexp/'); | |
62 } | |
OLD | NEW |