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

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, 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
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');
(...skipping 12 matching lines...) Expand all
23 for (Type type in cls.allSupertypes) { 23 for (Type type in cls.allSupertypes) {
24 List<Element> subtypes = emitter.subtypes.putIfAbsent( 24 List<Element> subtypes = emitter.subtypes.putIfAbsent(
25 type.element, 25 type.element,
26 () => <ClassElement>[]); 26 () => <ClassElement>[]);
27 subtypes.add(cls); 27 subtypes.add(cls);
28 } 28 }
29 } 29 }
30 30
31 void processNativeClassesInLibrary(Compiler compiler, 31 void processNativeClassesInLibrary(Compiler compiler,
32 LibraryElement library) { 32 LibraryElement library) {
33 bool hasNativeClass = false;
33 for (Link<Element> link = library.topLevelElements; 34 for (Link<Element> link = library.topLevelElements;
34 !link.isEmpty(); link = link.tail) { 35 !link.isEmpty(); link = link.tail) {
35 Element element = link.head; 36 Element element = link.head;
36 if (element.kind == ElementKind.CLASS) { 37 if (element.kind == ElementKind.CLASS) {
37 ClassElement classElement = element; 38 ClassElement classElement = element;
38 if (classElement.isNative()) { 39 if (classElement.isNative()) {
40 hasNativeClass = true;
39 compiler.registerInstantiatedClass(classElement); 41 compiler.registerInstantiatedClass(classElement);
40 // Also parse the node to know all its methods because 42 // Also parse the node to know all its methods because
41 // otherwise it will only be parsed if there is a call to 43 // otherwise it will only be parsed if there is a call to
42 // one of its constructor. 44 // one of its constructor.
43 classElement.parseNode(compiler); 45 classElement.parseNode(compiler);
44 // Resolve to setup the inheritance. 46 // Resolve to setup the inheritance.
45 classElement.ensureResolved(compiler); 47 classElement.ensureResolved(compiler);
46 // Add the information that this class is a subtype of 48 // Add the information that this class is a subtype of
47 // its supertypes. The code emitter and the ssa builder use that 49 // its supertypes. The code emitter and the ssa builder use that
48 // information. 50 // information.
49 NativeEmitter emitter = compiler.emitter.nativeEmitter; 51 NativeEmitter emitter = compiler.emitter.nativeEmitter;
50 addSubtypes(classElement, emitter); 52 addSubtypes(classElement, emitter);
51 } 53 }
52 } 54 }
53 } 55 }
56 if (hasNativeClass) {
57 compiler.registerStaticUse(compiler.findHelper(
58 const SourceString('dynamicFunction')));
59 compiler.registerStaticUse(compiler.findHelper(
60 const SourceString('dynamicSetMetadata')));
61 }
54 } 62 }
55 63
56 void maybeEnableNative(Compiler compiler, 64 void maybeEnableNative(Compiler compiler,
57 LibraryElement library, 65 LibraryElement library,
58 Uri uri) { 66 Uri uri) {
59 String libraryName = uri.toString(); 67 String libraryName = uri.toString();
60 if (library.script.name.contains('dart/frog/tests/native/src') 68 if (library.script.name.contains('dart/frog/tests/native/src')
61 || libraryName == 'dart:dom' 69 || libraryName == 'dart:dom'
62 || libraryName == 'dart:isolate' 70 || libraryName == 'dart:isolate'
63 || libraryName == 'dart:html') { 71 || libraryName == 'dart:html') {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 const LiteralDartString('void'), 338 const LiteralDartString('void'),
331 <HInstruction>[jsClosure])); 339 <HInstruction>[jsClosure]));
332 } 340 }
333 }); 341 });
334 LiteralString jsCode = node.arguments.head; 342 LiteralString jsCode = node.arguments.head;
335 builder.push(new HForeign(jsCode.dartString, 343 builder.push(new HForeign(jsCode.dartString,
336 const LiteralDartString('Object'), 344 const LiteralDartString('Object'),
337 <HInstruction>[])); 345 <HInstruction>[]));
338 } 346 }
339 } 347 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698