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

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

Issue 10032015: Add support for the package: directive in Frog and dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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
« frog/reader.dart ('K') | « frog/reader.dart ('k') | no next file » | 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('leg.dart', prefix: 'leg'); 7 #import('leg.dart', prefix: 'leg');
8 #import('elements/elements.dart', prefix: 'leg'); 8 #import('elements/elements.dart', prefix: 'leg');
9 #import('tree/tree.dart', prefix: 'leg'); 9 #import('tree/tree.dart', prefix: 'leg');
10 #import('ssa/tracer.dart', prefix: 'ssa'); 10 #import('ssa/tracer.dart', prefix: 'ssa');
11 // TODO(ahe): Remove dependency on frog. 11 // TODO(ahe): Remove dependency on frog.
12 #import('../../../frog/lang.dart', prefix: 'frog'); 12 #import('../../../frog/lang.dart', prefix: 'frog');
13 #import('../compiler.dart'); 13 #import('../compiler.dart');
14 #import('../../uri/uri.dart'); 14 #import('../../uri/uri.dart');
15 #import('library_map.dart'); 15 #import('library_map.dart');
16 16
17 17
18 class Compiler extends leg.Compiler { 18 class Compiler extends leg.Compiler {
19 ReadUriFromString provider; 19 ReadUriFromString provider;
20 DiagnosticHandler handler; 20 DiagnosticHandler handler;
21 Uri libraryRoot; 21 Uri libraryRoot;
22 Uri packageRoot;
22 List<String> options; 23 List<String> options;
23 bool mockableLibraryUsed = false; 24 bool mockableLibraryUsed = false;
24 25
25 Compiler(this.provider, this.handler, this.libraryRoot, this.options) 26 Compiler(this.provider, this.handler, this.libraryRoot, this.options)
26 : super(tracer: new ssa.HTracer()); 27 : super(tracer: new ssa.HTracer());
27 28
28 leg.LibraryElement scanBuiltinLibrary(String path) { 29 leg.LibraryElement scanBuiltinLibrary(String path) {
29 Uri uri = libraryRoot.resolve(DART2JS_LIBRARY_MAP[path]); 30 Uri uri = libraryRoot.resolve(DART2JS_LIBRARY_MAP[path]);
30 leg.LibraryElement library = scanner.loadLibrary(uri, null); 31 leg.LibraryElement library = scanner.loadLibrary(uri, null);
31 return library; 32 return library;
32 } 33 }
33 34
34 void log(message) { 35 void log(message) {
35 handler(null, null, null, message, false); 36 handler(null, null, null, message, false);
36 } 37 }
37 38
38 leg.Script readScript(Uri uri, [leg.ScriptTag node]) { 39 leg.Script readScript(Uri uri, [leg.ScriptTag node]) {
39 if (uri.scheme == 'dart') { 40 if (uri.scheme == 'dart') {
40 uri = translateDartUri(uri, node); 41 uri = translateDartUri(uri, node);
42 } else if (uri.scheme == 'package') {
43 uri = translatePackageUri(uri, node);
41 } 44 }
42 String text = ""; 45 String text = "";
43 try { 46 try {
44 // TODO(ahe): We expect the future to be complete and call value 47 // TODO(ahe): We expect the future to be complete and call value
45 // directly. In effect, we don't support truly asynchronous API. 48 // directly. In effect, we don't support truly asynchronous API.
46 text = provider(uri).value; 49 text = provider(uri).value;
47 } catch (var exception) { 50 } catch (var exception) {
48 cancel("${uri}: $exception", node: node); 51 cancel("${uri}: $exception", node: node);
49 } 52 }
50 frog.SourceFile sourceFile = new frog.SourceFile(uri.toString(), text); 53 frog.SourceFile sourceFile = new frog.SourceFile(uri.toString(), text);
51 return new leg.Script(uri, sourceFile); 54 return new leg.Script(uri, sourceFile);
52 } 55 }
53 56
54 translateDartUri(Uri uri, leg.ScriptTag node) { 57 translateDartUri(Uri uri, leg.ScriptTag node) {
55 String path = DART2JS_LIBRARY_MAP[uri.path]; 58 String path = DART2JS_LIBRARY_MAP[uri.path];
56 if (path === null || uri.path.startsWith('_')) { 59 if (path === null || uri.path.startsWith('_')) {
57 reportError(node, 'library not found ${uri}'); 60 reportError(node, 'library not found ${uri}');
58 return null; 61 return null;
59 } 62 }
60 if (uri.path == 'dom' || uri.path == 'html' || uri.path == 'io') { 63 if (uri.path == 'dom' || uri.path == 'html' || uri.path == 'io') {
61 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart 64 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart
62 // supports this use case better. 65 // supports this use case better.
63 mockableLibraryUsed = true; 66 mockableLibraryUsed = true;
64 } 67 }
65 return libraryRoot.resolve(path); 68 return libraryRoot.resolve(path);
66 } 69 }
67 70
71 translatePackageUri(Uri uri, leg.ScriptTag node) =>
Bob Nystrom 2012/04/09 23:54:08 I <3 => too, but I think a regular {} body is bett
nweiz 2012/04/10 00:16:31 I think it's fine for a single-line body, even if
72 packageRoot.resolve(uri.path);
73
68 bool run(Uri uri) { 74 bool run(Uri uri) {
75 packageRoot = uri.resolve('packages/');
69 bool success = super.run(uri); 76 bool success = super.run(uri);
70 for (final task in tasks) { 77 for (final task in tasks) {
71 log('${task.name} took ${task.timing}msec'); 78 log('${task.name} took ${task.timing}msec');
72 } 79 }
73 return success; 80 return success;
74 } 81 }
75 82
76 void reportDiagnostic(leg.SourceSpan span, String message, bool fatal) { 83 void reportDiagnostic(leg.SourceSpan span, String message, bool fatal) {
77 if (span === null) { 84 if (span === null) {
78 handler(null, null, null, message, fatal); 85 handler(null, null, null, message, fatal);
79 } else { 86 } else {
80 handler(span.uri, span.begin, span.end, message, fatal); 87 handler(span.uri, span.begin, span.end, message, fatal);
81 } 88 }
82 } 89 }
83 90
84 bool get isMockCompilation() { 91 bool get isMockCompilation() {
85 return mockableLibraryUsed 92 return mockableLibraryUsed
86 && (options.indexOf('--allow-mock-compilation') !== -1); 93 && (options.indexOf('--allow-mock-compilation') !== -1);
87 } 94 }
88 } 95 }
OLDNEW
« frog/reader.dart ('K') | « frog/reader.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698