Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/apiimpl.dart

Issue 11967010: Internal libraries supported. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/compiler.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'dart:async'; 8 import 'dart:async';
9 9
10 import '../compiler.dart' as api; 10 import '../compiler.dart' as api;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return option.substring('--force-strip='.length).split(','); 60 return option.substring('--force-strip='.length).split(',');
61 } 61 }
62 } 62 }
63 return []; 63 return [];
64 } 64 }
65 65
66 static bool hasOption(List<String> options, String option) { 66 static bool hasOption(List<String> options, String option) {
67 return options.indexOf(option) >= 0; 67 return options.indexOf(option) >= 0;
68 } 68 }
69 69
70 // TODO(johnniwinther): Merge better with [translateDartUri] when
71 // [scanBuiltinLibrary] is removed.
70 String lookupLibraryPath(String dartLibraryName) { 72 String lookupLibraryPath(String dartLibraryName) {
71 LibraryInfo info = LIBRARIES[dartLibraryName]; 73 LibraryInfo info = LIBRARIES[dartLibraryName];
72 if (info == null) return null; 74 if (info == null) return null;
73 if (!info.isDart2jsLibrary) return null; 75 if (!info.isDart2jsLibrary) return null;
74 String path = info.dart2jsPath; 76 String path = info.dart2jsPath;
75 if (path == null) { 77 if (path == null) {
76 path = info.path; 78 path = info.path;
77 } 79 }
78 return "lib/$path"; 80 return "lib/$path";
79 } 81 }
80 82
81 String lookupPatchPath(String dartLibraryName) { 83 String lookupPatchPath(String dartLibraryName) {
82 LibraryInfo info = LIBRARIES[dartLibraryName]; 84 LibraryInfo info = LIBRARIES[dartLibraryName];
83 if (info == null) return null; 85 if (info == null) return null;
84 if (!info.isDart2jsLibrary) return null; 86 if (!info.isDart2jsLibrary) return null;
85 String path = info.dart2jsPatchPath; 87 String path = info.dart2jsPatchPath;
86 if (path == null) return null; 88 if (path == null) return null;
87 return "lib/$path"; 89 return "lib/$path";
88 } 90 }
89 91
90 elements.LibraryElement scanBuiltinLibrary(String path) { 92 elements.LibraryElement scanBuiltinLibrary(String path) {
91 Uri uri = libraryRoot.resolve(lookupLibraryPath(path)); 93 Uri uri = libraryRoot.resolve(lookupLibraryPath(path));
92 Uri canonicalUri = null; 94 Uri canonicalUri = new Uri.fromComponents(scheme: "dart", path: path);
93 if (!path.startsWith("_")) {
94 canonicalUri = new Uri.fromComponents(scheme: "dart", path: path);
95 }
96 elements.LibraryElement library = 95 elements.LibraryElement library =
97 libraryLoader.loadLibrary(uri, null, canonicalUri); 96 libraryLoader.loadLibrary(uri, null, canonicalUri);
98 return library; 97 return library;
99 } 98 }
100 99
101 void log(message) { 100 void log(message) {
102 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); 101 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO);
103 } 102 }
104 103
105 leg.Script readScript(Uri uri, [tree.Node node]) { 104 /// See [leg.Compiler.translateResolvedUri].
105 Uri translateResolvedUri(elements.LibraryElement importingLibrary,
106 Uri resolvedUri, tree.Node node) {
107 if (resolvedUri.scheme == 'dart') {
108 return translateDartUri(importingLibrary, resolvedUri, node);
109 }
110 return resolvedUri;
111 }
112
113 /**
114 * Reads the script designated by [readableUri].
115 */
116 leg.Script readScript(Uri readableUri, [tree.Node node]) {
117 if (!readableUri.isAbsolute()) {
118 internalError('Relative uri $readableUri provided to readScript(Uri)',
119 node: node);
120 }
106 return fileReadingTask.measure(() { 121 return fileReadingTask.measure(() {
107 if (uri.scheme == 'dart') uri = translateDartUri(uri, node); 122 Uri resourceUri = translateUri(readableUri, node);
108 var translated = translateUri(uri, node);
109 String text = ""; 123 String text = "";
110 try { 124 try {
111 // TODO(ahe): We expect the future to be complete and call value 125 // TODO(ahe): We expect the future to be complete and call value
112 // directly. In effect, we don't support truly asynchronous API. 126 // directly. In effect, we don't support truly asynchronous API.
113 text = deprecatedFutureValue(provider(translated)); 127 text = deprecatedFutureValue(provider(resourceUri));
114 } catch (exception) { 128 } catch (exception) {
115 if (node != null) { 129 if (node != null) {
116 cancel("$exception", node: node); 130 cancel("$exception", node: node);
117 } else { 131 } else {
118 reportDiagnostic(null, "$exception", api.Diagnostic.ERROR); 132 reportDiagnostic(null, "$exception", api.Diagnostic.ERROR);
119 throw new leg.CompilerCancelledException("$exception"); 133 throw new leg.CompilerCancelledException("$exception");
120 } 134 }
121 } 135 }
122 SourceFile sourceFile = new SourceFile(translated.toString(), text); 136 SourceFile sourceFile = new SourceFile(resourceUri.toString(), text);
123 return new leg.Script(uri, sourceFile); 137 // We use [readableUri] as the URI for the script since need to preserve
138 // the scheme in the script because [Script.uri] is used for resolving
139 // relative URIs mentioned in the script. See the comment on
140 // [LibraryLoader] for more details.
141 return new leg.Script(readableUri, sourceFile);
124 }); 142 });
125 } 143 }
126 144
127 Uri translateUri(Uri uri, tree.Node node) { 145 /**
128 switch (uri.scheme) { 146 * Translates a readable URI into a resource URI.
129 case 'package': return translatePackageUri(uri, node); 147 *
130 default: return uri; 148 * See [LibraryLoader] for terminology on URIs.
149 */
150 Uri translateUri(Uri readableUri, tree.Node node) {
151 switch (readableUri.scheme) {
152 case 'package': return translatePackageUri(readableUri, node);
153 default: return readableUri;
131 } 154 }
132 } 155 }
133 156
134 Uri translateDartUri(Uri uri, tree.Node node) { 157 Uri translateDartUri(elements.LibraryElement importingLibrary,
135 String path = lookupLibraryPath(uri.path); 158 Uri resolvedUri, tree.Node node) {
136 if (path == null || LIBRARIES[uri.path].category == "Internal") { 159 LibraryInfo libraryInfo = LIBRARIES[resolvedUri.path];
160 String path = lookupLibraryPath(resolvedUri.path);
161 if (libraryInfo != null &&
162 libraryInfo.category == "Internal") {
163 bool allowInternalLibraryAccess = false;
164 if (importingLibrary != null) {
165 if (importingLibrary.isPlatformLibrary || importingLibrary.isPatch) {
166 allowInternalLibraryAccess = true;
167 } else if (importingLibrary.canonicalUri.path.contains(
168 'dart/tests/compiler/dart2js_native')) {
169 allowInternalLibraryAccess = true;
170 }
171 }
172 if (!allowInternalLibraryAccess) {
173 if (node != null && importingLibrary != null) {
174 reportDiagnostic(spanFromNode(node),
175 'Error: Internal library $resolvedUri is not accessible from '
176 '${importingLibrary.canonicalUri}.',
177 api.Diagnostic.ERROR);
178 } else {
179 reportDiagnostic(null,
180 'Error: Internal library $resolvedUri is not accessible.',
181 api.Diagnostic.ERROR);
182 }
183 //path = null;
184 }
185 }
186 if (path == null) {
137 if (node != null) { 187 if (node != null) {
138 reportError(node, 'library not found ${uri}'); 188 reportError(node, 'library not found ${resolvedUri}');
139 } else { 189 } else {
140 reportDiagnostic(null, 'library not found ${uri}', 190 reportDiagnostic(null, 'library not found ${resolvedUri}',
141 api.Diagnostic.ERROR); 191 api.Diagnostic.ERROR);
142 } 192 }
143 return null; 193 return null;
144 } 194 }
145 if (uri.path == 'html' || 195 if (resolvedUri.path == 'html' ||
146 uri.path == 'io') { 196 resolvedUri.path == 'io') {
147 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart 197 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart
148 // supports this use case better. 198 // supports this use case better.
149 mockableLibraryUsed = true; 199 mockableLibraryUsed = true;
150 } 200 }
151 return libraryRoot.resolve(path); 201 return libraryRoot.resolve(path);
152 } 202 }
153 203
154 Uri resolvePatchUri(String dartLibraryPath) { 204 Uri resolvePatchUri(String dartLibraryPath) {
155 String patchPath = lookupPatchPath(dartLibraryPath); 205 String patchPath = lookupPatchPath(dartLibraryPath);
156 if (patchPath == null) return null; 206 if (patchPath == null) return null;
(...skipping 29 matching lines...) Expand all
186 handler(translateUri(span.uri, null), span.begin, span.end, 236 handler(translateUri(span.uri, null), span.begin, span.end,
187 message, kind); 237 message, kind);
188 } 238 }
189 } 239 }
190 240
191 bool get isMockCompilation { 241 bool get isMockCompilation {
192 return mockableLibraryUsed 242 return mockableLibraryUsed
193 && (options.indexOf('--allow-mock-compilation') != -1); 243 && (options.indexOf('--allow-mock-compilation') != -1);
194 } 244 }
195 } 245 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698