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

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

Issue 10398044: Reverting 7667 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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('dart:uri'); 6 #import('dart:uri');
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(CodeEmitterTask emitter, 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(emitter, library); 17 processNativeClassesInLibrary(compiler, library);
18 } 18 }
19 } 19 }
20 20
21 void addSubtypes(ClassElement cls, 21 void addSubtypes(ClassElement cls,
22 NativeEmitter emitter) { 22 NativeEmitter emitter) {
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 List<Element> directSubtypes = emitter.directSubtypes.putIfAbsent( 30 List<Element> directSubtypes = emitter.directSubtypes.putIfAbsent(
31 cls.superclass, 31 cls.superclass,
32 () => <ClassElement>[]); 32 () => <ClassElement>[]);
33 directSubtypes.add(cls); 33 directSubtypes.add(cls);
34 } 34 }
35 35
36 void processNativeClassesInLibrary(CodeEmitterTask emitter, 36 void processNativeClassesInLibrary(Compiler compiler,
37 LibraryElement library) { 37 LibraryElement library) {
38 bool hasNativeClass = false; 38 bool hasNativeClass = false;
39 final compiler = emitter.compiler;
40 for (Link<Element> link = library.topLevelElements; 39 for (Link<Element> link = library.topLevelElements;
41 !link.isEmpty(); link = link.tail) { 40 !link.isEmpty(); link = link.tail) {
42 Element element = link.head; 41 Element element = link.head;
43 if (element.kind == ElementKind.CLASS) { 42 if (element.kind == ElementKind.CLASS) {
44 ClassElement classElement = element; 43 ClassElement classElement = element;
45 if (classElement.isNative()) { 44 if (classElement.isNative()) {
46 hasNativeClass = true; 45 hasNativeClass = true;
47 compiler.registerInstantiatedClass(classElement); 46 compiler.registerInstantiatedClass(classElement);
48 // Also parse the node to know all its methods because 47 // Also parse the node to know all its methods because
49 // otherwise it will only be parsed if there is a call to 48 // otherwise it will only be parsed if there is a call to
50 // one of its constructor. 49 // one of its constructor.
51 classElement.parseNode(compiler); 50 classElement.parseNode(compiler);
52 // Resolve to setup the inheritance. 51 // Resolve to setup the inheritance.
53 classElement.ensureResolved(compiler); 52 classElement.ensureResolved(compiler);
54 // Add the information that this class is a subtype of 53 // Add the information that this class is a subtype of
55 // its supertypes. The code emitter and the ssa builder use that 54 // its supertypes. The code emitter and the ssa builder use that
56 // information. 55 // information.
57 addSubtypes(classElement, emitter.nativeEmitter); 56 NativeEmitter emitter = compiler.emitter.nativeEmitter;
57 addSubtypes(classElement, emitter);
58 } 58 }
59 } 59 }
60 } 60 }
61 if (hasNativeClass) { 61 if (hasNativeClass) {
62 compiler.registerStaticUse(compiler.findHelper( 62 compiler.registerStaticUse(compiler.findHelper(
63 const SourceString('dynamicFunction'))); 63 const SourceString('dynamicFunction')));
64 compiler.registerStaticUse(compiler.findHelper( 64 compiler.registerStaticUse(compiler.findHelper(
65 const SourceString('dynamicSetMetadata'))); 65 const SourceString('dynamicSetMetadata')));
66 compiler.registerStaticUse(compiler.findHelper( 66 compiler.registerStaticUse(compiler.findHelper(
67 const SourceString('defineProperty'))); 67 const SourceString('defineProperty')));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 for (ClassElement subtype in subtypes) { 188 for (ClassElement subtype in subtypes) {
189 if (subtype.lookupLocalMember(element.name) != null) return true; 189 if (subtype.lookupLocalMember(element.name) != null) return true;
190 } 190 }
191 return false; 191 return false;
192 } 192 }
193 193
194 void handleSsaNative(SsaBuilder builder, Send node) { 194 void handleSsaNative(SsaBuilder builder, Send node) {
195 Compiler compiler = builder.compiler; 195 Compiler compiler = builder.compiler;
196 FunctionElement element = builder.work.element; 196 FunctionElement element = builder.work.element;
197 element.setNative(); 197 element.setNative();
198 NativeEmitter nativeEmitter = builder.emitter.nativeEmitter; 198 NativeEmitter nativeEmitter = compiler.emitter.nativeEmitter;
199 // If what we're compiling is a getter named 'typeName' and the native 199 // If what we're compiling is a getter named 'typeName' and the native
200 // class is named 'DOMType', we generate a call to the typeNameOf 200 // class is named 'DOMType', we generate a call to the typeNameOf
201 // function attached on the isolate. 201 // function attached on the isolate.
202 // The DOM classes assume that their 'typeName' property, which is 202 // The DOM classes assume that their 'typeName' property, which is
203 // not a JS property on the DOM types, returns the type name. 203 // not a JS property on the DOM types, returns the type name.
204 if (element.name == const SourceString('typeName') 204 if (element.name == const SourceString('typeName')
205 && element.isGetter() 205 && element.isGetter()
206 && nativeEmitter.toNativeName(element.enclosingElement) == 'DOMType') { 206 && nativeEmitter.toNativeName(element.enclosingElement) == 'DOMType') {
207 Element methodElement = 207 Element methodElement =
208 compiler.findHelper(const SourceString('getTypeNameOf')); 208 compiler.findHelper(const SourceString('getTypeNameOf'));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 String str = jsCode.dartString.slowToString(); 240 String str = jsCode.dartString.slowToString();
241 if (nativeRedirectionRegExp.hasMatch(str)) { 241 if (nativeRedirectionRegExp.hasMatch(str)) {
242 nativeMethodName = str; 242 nativeMethodName = str;
243 isRedirecting = true; 243 isRedirecting = true;
244 } else { 244 } else {
245 hasBody = true; 245 hasBody = true;
246 } 246 }
247 } 247 }
248 248
249 if (!hasBody) { 249 if (!hasBody) {
250 nativeEmitter.nativeMethods.add(element); 250 compiler.emitter.nativeEmitter.nativeMethods.add(element);
251 } 251 }
252 252
253 FunctionSignature parameters = element.computeSignature(builder.compiler); 253 FunctionSignature parameters = element.computeSignature(builder.compiler);
254 if (!hasBody) { 254 if (!hasBody) {
255 List<String> arguments = <String>[]; 255 List<String> arguments = <String>[];
256 List<HInstruction> inputs = <HInstruction>[]; 256 List<HInstruction> inputs = <HInstruction>[];
257 String receiver = ''; 257 String receiver = '';
258 if (element.isInstanceMember()) { 258 if (element.isInstanceMember()) {
259 receiver = '#.'; 259 receiver = '#.';
260 inputs.add(builder.localsHandler.readThis()); 260 inputs.add(builder.localsHandler.readThis());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 String parameters) { 346 String parameters) {
347 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty"); 347 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty");
348 buffer.add("('$methodName')) {\n"); 348 buffer.add("('$methodName')) {\n");
349 buffer.add(" $code"); 349 buffer.add(" $code");
350 buffer.add(" } else {\n"); 350 buffer.add(" } else {\n");
351 buffer.add(" return Object.prototype.$methodName.call(this"); 351 buffer.add(" return Object.prototype.$methodName.call(this");
352 buffer.add(parameters == '' ? '' : ', $parameters'); 352 buffer.add(parameters == '' ? '' : ', $parameters');
353 buffer.add(");\n"); 353 buffer.add(");\n");
354 buffer.add(" }\n"); 354 buffer.add(" }\n");
355 } 355 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/native_emitter.dart ('k') | lib/compiler/implementation/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698