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('leg_apiimpl'); | 5 #library('leg_apiimpl'); |
6 | 6 |
7 #import('dart:uri'); | 7 #import('dart:uri'); |
8 | 8 |
9 #import('../compiler.dart', prefix: 'api'); | 9 #import('../compiler.dart', prefix: 'api'); |
10 #import('leg.dart', prefix: 'leg'); | 10 #import('leg.dart', prefix: 'leg'); |
11 #import('tree/tree.dart', prefix: 'tree'); | 11 #import('tree/tree.dart', prefix: 'tree'); |
12 #import('elements/elements.dart', prefix: 'elements'); | 12 #import('elements/elements.dart', prefix: 'elements'); |
13 #import('ssa/tracer.dart', prefix: 'ssa'); | 13 #import('ssa/tracer.dart', prefix: 'ssa'); |
14 #import('library_map.dart'); | 14 #import('../../../lib/_internal/libraries.dart'); |
15 #import('source_file.dart'); | 15 #import('source_file.dart'); |
16 | 16 |
17 class Compiler extends leg.Compiler { | 17 class Compiler extends leg.Compiler { |
18 api.ReadStringFromUri provider; | 18 api.ReadStringFromUri provider; |
19 api.DiagnosticHandler handler; | 19 api.DiagnosticHandler handler; |
20 final Uri libraryRoot; | 20 final Uri libraryRoot; |
21 final Uri packageRoot; | 21 final Uri packageRoot; |
22 List<String> options; | 22 List<String> options; |
23 bool mockableLibraryUsed = false; | 23 bool mockableLibraryUsed = false; |
24 | 24 |
25 Compiler(this.provider, this.handler, this.libraryRoot, this.packageRoot, | 25 Compiler(this.provider, this.handler, this.libraryRoot, this.packageRoot, |
26 List<String> options) | 26 List<String> options) |
27 : this.options = options, | 27 : this.options = options, |
28 super( | 28 super( |
29 tracer: new ssa.HTracer(), | 29 tracer: new ssa.HTracer(), |
30 enableTypeAssertions: options.indexOf('--enable-checked-mode') != -1, | 30 enableTypeAssertions: hasOption(options, '--enable-checked-mode'), |
31 enableUserAssertions: options.indexOf('--enable-checked-mode') != -1, | 31 enableUserAssertions: hasOption(options, '--enable-checked-mode'), |
32 enableMinification: options.indexOf('--minify') != -1, | 32 enableMinification: hasOption(options, '--minify'), |
33 emitJavascript: options.indexOf('--output-type=dart') == -1, | 33 emitJavascript: !hasOption(options, '--output-type=dart'), |
34 cutDeclarationTypes: options.indexOf('--cutDeclarationTypes') != -1); | 34 cutDeclarationTypes: hasOption(options, '--cutDeclarationTypes')); |
| 35 |
| 36 static bool hasOption(List<String> options, String option) { |
| 37 return options.indexOf(option) >= 0; |
| 38 } |
| 39 |
| 40 String lookupLibraryPath(String dartLibraryName) { |
| 41 LibraryInfo info = LIBRARIES[dartLibraryName]; |
| 42 if (info === null) return null; |
| 43 if (!info.isDart2jsLibrary) return null; |
| 44 String path = info.dart2jsPath; |
| 45 if (path === null) { |
| 46 path = info.path; |
| 47 } |
| 48 return "lib/$path"; |
| 49 } |
| 50 String lookupPatchPath(String dartLibraryName) { |
| 51 LibraryInfo info = LIBRARIES[dartLibraryName]; |
| 52 if (info === null) return null; |
| 53 if (!info.isDart2jsLibrary) return null; |
| 54 String path = info.dart2jsPatchPath; |
| 55 if (path === null) return null; |
| 56 return "lib/$path"; |
| 57 } |
35 | 58 |
36 elements.LibraryElement scanBuiltinLibrary(String path) { | 59 elements.LibraryElement scanBuiltinLibrary(String path) { |
37 Uri uri = libraryRoot.resolve(DART2JS_LIBRARY_MAP[path].libraryPath); | 60 Uri uri = libraryRoot.resolve(lookupLibraryPath(path)); |
38 Uri canonicalUri; | 61 Uri canonicalUri; |
39 if (path.startsWith("_")) { | 62 if (path.startsWith("_")) { |
40 canonicalUri = uri; | 63 canonicalUri = uri; |
41 } else { | 64 } else { |
42 canonicalUri = new Uri.fromComponents(scheme: "dart", path: path); | 65 canonicalUri = new Uri.fromComponents(scheme: "dart", path: path); |
43 } | 66 } |
44 elements.LibraryElement library = | 67 elements.LibraryElement library = |
45 scanner.loadLibrary(uri, null, canonicalUri); | 68 scanner.loadLibrary(uri, null, canonicalUri); |
46 return library; | 69 return library; |
47 } | 70 } |
(...skipping 23 matching lines...) Expand all Loading... |
71 } | 94 } |
72 | 95 |
73 Uri translateUri(Uri uri, tree.Node node) { | 96 Uri translateUri(Uri uri, tree.Node node) { |
74 switch (uri.scheme) { | 97 switch (uri.scheme) { |
75 case 'package': return translatePackageUri(uri, node); | 98 case 'package': return translatePackageUri(uri, node); |
76 default: return uri; | 99 default: return uri; |
77 } | 100 } |
78 } | 101 } |
79 | 102 |
80 Uri translateDartUri(Uri uri, tree.Node node) { | 103 Uri translateDartUri(Uri uri, tree.Node node) { |
81 String path = DART2JS_LIBRARY_MAP[uri.path].libraryPath; | 104 String path = lookupLibraryPath(uri.path); |
82 if (path === null || uri.path.startsWith('_')) { | 105 if (path === null || LIBRARIES[uri.path].category == "Internal") { |
83 reportError(node, 'library not found ${uri}'); | 106 reportError(node, 'library not found ${uri}'); |
84 return null; | 107 return null; |
85 } | 108 } |
86 if (uri.path == 'dom_deprecated' | 109 if (uri.path == 'dom_deprecated' || |
87 || uri.path == 'html' || uri.path == 'io') { | 110 uri.path == 'html' || |
| 111 uri.path == 'io') { |
88 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart | 112 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart |
89 // supports this use case better. | 113 // supports this use case better. |
90 mockableLibraryUsed = true; | 114 mockableLibraryUsed = true; |
91 } | 115 } |
92 return libraryRoot.resolve(path); | 116 return libraryRoot.resolve(path); |
93 } | 117 } |
94 | 118 |
95 Uri resolvePatchUri(String dartLibraryPath) { | 119 Uri resolvePatchUri(String dartLibraryPath) { |
96 String patchPath = DART2JS_LIBRARY_MAP[dartLibraryPath].patchPath; | 120 String patchPath = lookupPatchPath(dartLibraryPath); |
97 if (patchPath === null) return null; | 121 if (patchPath === null) return null; |
98 return libraryRoot.resolve(patchPath); | 122 return libraryRoot.resolve(patchPath); |
99 } | 123 } |
100 | 124 |
101 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); | 125 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); |
102 | 126 |
103 bool run(Uri uri) { | 127 bool run(Uri uri) { |
104 bool success = super.run(uri); | 128 bool success = super.run(uri); |
105 for (final task in tasks) { | 129 for (final task in tasks) { |
106 log('${task.name} took ${task.timing}msec'); | 130 log('${task.name} took ${task.timing}msec'); |
(...skipping 14 matching lines...) Expand all Loading... |
121 handler(translateUri(span.uri, null), span.begin, span.end, | 145 handler(translateUri(span.uri, null), span.begin, span.end, |
122 message, kind); | 146 message, kind); |
123 } | 147 } |
124 } | 148 } |
125 | 149 |
126 bool get isMockCompilation { | 150 bool get isMockCompilation { |
127 return mockableLibraryUsed | 151 return mockableLibraryUsed |
128 && (options.indexOf('--allow-mock-compilation') !== -1); | 152 && (options.indexOf('--allow-mock-compilation') !== -1); |
129 } | 153 } |
130 } | 154 } |
OLD | NEW |