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

Side by Side Diff: dart/frog/leg/apiimpl.dart

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

Powered by Google App Engine
This is Rietveld 408576698