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 emitJavascript: options.indexOf('--output-type=dart') == -1, | 32 emitJavascript: _hasOption(options, '--output-type=dart'), |
33 minify: options.indexOf('--minify') != -1); | 33 minify: options.indexOf('--minify') != -1); |
34 | |
35 static bool _hasOption(List<String> options, String option) { | |
36 return options.indexOf(option) >= 0; | |
37 } | |
38 | |
39 String dartLibraryPath(String dartLibraryName) { | |
Johnni Winther
2012/08/28 13:26:04
Rename to getDartLibraryPath.
Lasse Reichstein Nielsen
2012/08/29 09:09:39
Renamed to lookupDartLibraryPath to make it a verb
| |
40 LibraryInfo info = LIBRARIES[dartLibraryName]; | |
41 if (info == null) return null; | |
42 if (!info.isDart2jsLibrary) return null; | |
43 String path = info.dart2jsPath; | |
44 if (path == null) path = info.path; | |
45 return "lib/$path"; | |
46 } | |
47 | |
48 String dartPatchPath(String dartLibraryName) { | |
Johnni Winther
2012/08/28 13:26:04
Rename to getDartPatchPath.
Lasse Reichstein Nielsen
2012/08/29 09:09:39
Dittos.
| |
49 LibraryInfo info = LIBRARIES[dartLibraryName]; | |
50 if (info == null) return null; | |
51 if (!info.isDart2jsLibrary) return null; | |
52 String path = info.dart2jsPatchPath; | |
53 if (path == null) return null; | |
54 return "lib/$path"; | |
55 } | |
34 | 56 |
35 elements.LibraryElement scanBuiltinLibrary(String path) { | 57 elements.LibraryElement scanBuiltinLibrary(String path) { |
36 Uri uri = libraryRoot.resolve(DART2JS_LIBRARY_MAP[path].libraryPath); | 58 Uri uri = libraryRoot.resolve(dartLibraryPath(path)); |
37 Uri canonicalUri; | 59 Uri canonicalUri; |
38 if (path.startsWith("_")) { | 60 if (path.startsWith("_")) { |
39 canonicalUri = uri; | 61 canonicalUri = uri; |
40 } else { | 62 } else { |
41 canonicalUri = new Uri.fromComponents(scheme: "dart", path: path); | 63 canonicalUri = new Uri.fromComponents(scheme: "dart", path: path); |
42 } | 64 } |
43 elements.LibraryElement library = | 65 elements.LibraryElement library = |
44 scanner.loadLibrary(uri, null, canonicalUri); | 66 scanner.loadLibrary(uri, null, canonicalUri); |
45 return library; | 67 return library; |
46 } | 68 } |
(...skipping 23 matching lines...) Expand all Loading... | |
70 } | 92 } |
71 | 93 |
72 Uri translateUri(Uri uri, tree.Node node) { | 94 Uri translateUri(Uri uri, tree.Node node) { |
73 switch (uri.scheme) { | 95 switch (uri.scheme) { |
74 case 'package': return translatePackageUri(uri, node); | 96 case 'package': return translatePackageUri(uri, node); |
75 default: return uri; | 97 default: return uri; |
76 } | 98 } |
77 } | 99 } |
78 | 100 |
79 Uri translateDartUri(Uri uri, tree.Node node) { | 101 Uri translateDartUri(Uri uri, tree.Node node) { |
80 String path = DART2JS_LIBRARY_MAP[uri.path].libraryPath; | 102 String path = dartLibraryPath(uri.path); |
81 if (path === null || uri.path.startsWith('_')) { | 103 if (path === null || LIBRARIES[uri.path].category == "Internal") { |
82 reportError(node, 'library not found ${uri}'); | 104 reportError(node, 'library not found ${uri}'); |
83 return null; | 105 return null; |
84 } | 106 } |
85 if (uri.path == 'dom_deprecated' | 107 if (uri.path == 'dom_deprecated' || |
86 || uri.path == 'html' || uri.path == 'io') { | 108 uri.path == 'html' || |
109 uri.path == 'io') { | |
87 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart | 110 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart |
88 // supports this use case better. | 111 // supports this use case better. |
89 mockableLibraryUsed = true; | 112 mockableLibraryUsed = true; |
90 } | 113 } |
91 return libraryRoot.resolve(path); | 114 return libraryRoot.resolve(path); |
92 } | 115 } |
93 | 116 |
94 Uri resolvePatchUri(String dartLibraryPath) { | 117 Uri resolvePatchUri(String dartLibraryPath) { |
95 String patchPath = DART2JS_LIBRARY_MAP[dartLibraryPath].patchPath; | 118 String patchPath = dartPatchPath(dartLibraryPath); |
96 if (patchPath === null) return null; | 119 if (patchPath === null) return null; |
97 return libraryRoot.resolve(patchPath); | 120 return libraryRoot.resolve(patchPath); |
98 } | 121 } |
99 | 122 |
100 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); | 123 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); |
101 | 124 |
102 bool run(Uri uri) { | 125 bool run(Uri uri) { |
103 bool success = super.run(uri); | 126 bool success = super.run(uri); |
104 for (final task in tasks) { | 127 for (final task in tasks) { |
105 log('${task.name} took ${task.timing}msec'); | 128 log('${task.name} took ${task.timing}msec'); |
(...skipping 14 matching lines...) Expand all Loading... | |
120 handler(translateUri(span.uri, null), span.begin, span.end, | 143 handler(translateUri(span.uri, null), span.begin, span.end, |
121 message, kind); | 144 message, kind); |
122 } | 145 } |
123 } | 146 } |
124 | 147 |
125 bool get isMockCompilation { | 148 bool get isMockCompilation { |
126 return mockableLibraryUsed | 149 return mockableLibraryUsed |
127 && (options.indexOf('--allow-mock-compilation') !== -1); | 150 && (options.indexOf('--allow-mock-compilation') !== -1); |
128 } | 151 } |
129 } | 152 } |
OLD | NEW |