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

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

Issue 9750003: Write our JS blobs for handling native classes in Dart. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
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
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('native'); 5 #library('native');
6 #import('../../lib/uri/uri.dart'); 6 #import('../../lib/uri/uri.dart');
7 #import('leg.dart'); 7 #import('leg.dart');
8 #import('elements/elements.dart'); 8 #import('elements/elements.dart');
9 #import('scanner/scannerlib.dart'); 9 #import('scanner/scannerlib.dart');
10 #import('ssa/ssa.dart'); 10 #import('ssa/ssa.dart');
11 #import('tree/tree.dart'); 11 #import('tree/tree.dart');
12 #import('util/util.dart'); 12 #import('util/util.dart');
13 13
14 void processNativeClasses(Compiler compiler, 14 void processNativeClasses(Compiler compiler,
15 Collection<LibraryElement> libraries) { 15 Collection<LibraryElement> libraries) {
16 for (LibraryElement library in libraries) { 16 for (LibraryElement library in libraries) {
17 processNativeClassesInLibrary(compiler, library); 17 processNativeClassesInLibrary(compiler, library);
18 } 18 }
19 } 19 }
20 20
21 void processNativeClassesInLibrary(Compiler compiler, 21 void processNativeClassesInLibrary(Compiler compiler,
22 LibraryElement library) { 22 LibraryElement library) {
23 bool hasNativeClass = false;
23 for (Link<Element> link = library.topLevelElements; 24 for (Link<Element> link = library.topLevelElements;
24 !link.isEmpty(); link = link.tail) { 25 !link.isEmpty(); link = link.tail) {
25 Element element = link.head; 26 Element element = link.head;
26 if (element.kind == ElementKind.CLASS) { 27 if (element.kind == ElementKind.CLASS) {
27 ClassElement classElement = element; 28 ClassElement classElement = element;
28 if (classElement.isNative()) { 29 if (classElement.isNative()) {
30 hasNativeClass = true;
29 compiler.registerInstantiatedClass(classElement); 31 compiler.registerInstantiatedClass(classElement);
30 // Also parse the node to know all its methods because 32 // Also parse the node to know all its methods because
31 // otherwise it will only be parsed if there is a call to 33 // otherwise it will only be parsed if there is a call to
32 // one of its constructor. 34 // one of its constructor.
33 classElement.parseNode(compiler); 35 classElement.parseNode(compiler);
34 // Resolve to setup the inheritance. 36 // Resolve to setup the inheritance.
35 classElement.ensureResolved(compiler); 37 classElement.ensureResolved(compiler);
36 // Add the information that this class is a direct subclass of 38 // Add the information that this class is a direct subclass of
37 // its superclass. The code emitter and the ssa builder use that 39 // its superclass. The code emitter and the ssa builder use that
38 // information. 40 // information.
39 NativeEmitter emitter = compiler.emitter.nativeEmitter; 41 NativeEmitter emitter = compiler.emitter.nativeEmitter;
40 List<Element> subclasses = emitter.subclasses.putIfAbsent( 42 List<Element> subclasses = emitter.subclasses.putIfAbsent(
41 classElement.superclass, 43 classElement.superclass,
42 () => <ClassElement>[]); 44 () => <ClassElement>[]);
43 subclasses.add(classElement); 45 subclasses.add(classElement);
44 } 46 }
45 } 47 }
46 } 48 }
49 if (hasNativeClass) {
50 compiler.registerStaticUse(compiler.findHelper(
51 const SourceString('dynamicFunction')));
52 compiler.registerStaticUse(compiler.findHelper(
53 const SourceString('dynamicSetMetadata')));
54 }
47 } 55 }
48 56
49 void maybeEnableNative(Compiler compiler, 57 void maybeEnableNative(Compiler compiler,
50 LibraryElement library, 58 LibraryElement library,
51 Uri uri) { 59 Uri uri) {
52 String libraryName = uri.toString(); 60 String libraryName = uri.toString();
53 if (library.script.name.contains('dart/frog/tests/native/src') 61 if (library.script.name.contains('dart/frog/tests/native/src')
54 || libraryName == 'dart:dom' 62 || libraryName == 'dart:dom'
55 || libraryName == 'dart:isolate' 63 || libraryName == 'dart:isolate'
56 || libraryName == 'dart:html') { 64 || libraryName == 'dart:html') {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 const LiteralDartString('void'), 332 const LiteralDartString('void'),
325 <HInstruction>[jsClosure])); 333 <HInstruction>[jsClosure]));
326 } 334 }
327 }); 335 });
328 LiteralString jsCode = node.arguments.head; 336 LiteralString jsCode = node.arguments.head;
329 builder.push(new HForeign(jsCode.dartString, 337 builder.push(new HForeign(jsCode.dartString,
330 const LiteralDartString('Object'), 338 const LiteralDartString('Object'),
331 <HInstruction>[])); 339 <HInstruction>[]));
332 } 340 }
333 } 341 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698