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

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

Issue 10386086: RFC: Start refactoring to provide more than a single backend. (Closed) Base URL: https://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');
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 compiler.registerInstantiatedClass(classElement); 46 compiler.registerInstantiatedClass(classElement);
47 // Also parse the node to know all its methods because 47 // Also parse the node to know all its methods because
48 // 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
49 // one of its constructor. 49 // one of its constructor.
50 classElement.parseNode(compiler); 50 classElement.parseNode(compiler);
51 // Resolve to setup the inheritance. 51 // Resolve to setup the inheritance.
52 classElement.ensureResolved(compiler); 52 classElement.ensureResolved(compiler);
53 // Add the information that this class is a subtype of 53 // Add the information that this class is a subtype of
54 // its supertypes. The code emitter and the ssa builder use that 54 // its supertypes. The code emitter and the ssa builder use that
55 // information. 55 // information.
56 NativeEmitter emitter = compiler.emitter.nativeEmitter; 56 NativeEmitter emitter = compiler.backend.emitter.nativeEmitter;
57 addSubtypes(classElement, emitter); 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(
(...skipping 121 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 = compiler.emitter.nativeEmitter; 198 NativeEmitter nativeEmitter = compiler.backend.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 compiler.emitter.nativeEmitter.nativeMethods.add(element); 250 compiler.backend.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

Powered by Google App Engine
This is Rietveld 408576698