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

Side by Side Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10834243: Reduce usage of .enclosingElement to get enclosing class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 class SsaCodeGeneratorTask extends CompilerTask { 5 class SsaCodeGeneratorTask extends CompilerTask {
6 final JavaScriptBackend backend; 6 final JavaScriptBackend backend;
7 SsaCodeGeneratorTask(JavaScriptBackend backend) 7 SsaCodeGeneratorTask(JavaScriptBackend backend)
8 : this.backend = backend, 8 : this.backend = backend,
9 super(backend.compiler); 9 super(backend.compiler);
10 String get name() => 'SSA code generator'; 10 String get name() => 'SSA code generator';
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 parameterNames.forEach((element, name) { 51 parameterNames.forEach((element, name) {
52 compiler.enqueuer.codegen.addToWorkList(element); 52 compiler.enqueuer.codegen.addToWorkList(element);
53 }); 53 });
54 String parameters = Strings.join(parameterNames.getValues(), ', '); 54 String parameters = Strings.join(parameterNames.getValues(), ', ');
55 SsaOptimizedCodeGenerator codegen = new SsaOptimizedCodeGenerator( 55 SsaOptimizedCodeGenerator codegen = new SsaOptimizedCodeGenerator(
56 backend, work, parameters, parameterNames); 56 backend, work, parameters, parameterNames);
57 codegen.visitGraph(graph); 57 codegen.visitGraph(graph);
58 58
59 FunctionElement element = work.element; 59 FunctionElement element = work.element;
60 CodeBuffer code; 60 CodeBuffer code;
61 ClassElement enclosingClass = element.getEnclosingClass();
61 if (element.isInstanceMember() 62 if (element.isInstanceMember()
62 && element.enclosingElement.isClass() 63 && enclosingClass.isNative()
63 && element.enclosingElement.isNative()
64 && native.isOverriddenMethod( 64 && native.isOverriddenMethod(
65 element, element.enclosingElement, nativeEmitter)) { 65 element, enclosingClass, nativeEmitter)) {
66 // Record that this method is overridden. In case of optional 66 // Record that this method is overridden. In case of optional
67 // arguments, the emitter will generate stubs to handle them, 67 // arguments, the emitter will generate stubs to handle them,
68 // and needs to know if the method is overridden. 68 // and needs to know if the method is overridden.
69 nativeEmitter.overriddenMethods.add(element); 69 nativeEmitter.overriddenMethods.add(element);
70 StringBuffer buffer = new StringBuffer(); 70 StringBuffer buffer = new StringBuffer();
71 native.generateMethodWithPrototypeCheckForElement( 71 native.generateMethodWithPrototypeCheckForElement(
72 compiler, buffer, element, '${codegen.buffer}', parameters); 72 compiler, buffer, element, '${codegen.buffer}', parameters);
73 code = new CodeBuffer(); 73 code = new CodeBuffer();
74 code.add(buffer); 74 code.add(buffer);
75 } else { 75 } else {
(...skipping 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 visitInvokeStatic(HInvokeStatic node) { 1793 visitInvokeStatic(HInvokeStatic node) {
1794 beginExpression(JSPrecedence.CALL_PRECEDENCE); 1794 beginExpression(JSPrecedence.CALL_PRECEDENCE);
1795 use(node.target, JSPrecedence.CALL_PRECEDENCE); 1795 use(node.target, JSPrecedence.CALL_PRECEDENCE);
1796 visitArguments(node.inputs); 1796 visitArguments(node.inputs);
1797 endExpression(JSPrecedence.CALL_PRECEDENCE); 1797 endExpression(JSPrecedence.CALL_PRECEDENCE);
1798 } 1798 }
1799 1799
1800 visitInvokeSuper(HInvokeSuper node) { 1800 visitInvokeSuper(HInvokeSuper node) {
1801 beginExpression(JSPrecedence.CALL_PRECEDENCE); 1801 beginExpression(JSPrecedence.CALL_PRECEDENCE);
1802 Element superMethod = node.element; 1802 Element superMethod = node.element;
1803 Element superClass = superMethod.enclosingElement; 1803 Element superClass = superMethod.getEnclosingClass();
1804 // Remove the element and 'this'. 1804 // Remove the element and 'this'.
1805 int argumentCount = node.inputs.length - 2; 1805 int argumentCount = node.inputs.length - 2;
1806 String className = compiler.namer.isolateAccess(superClass); 1806 String className = compiler.namer.isolateAccess(superClass);
1807 if (superMethod.kind == ElementKind.FUNCTION || 1807 if (superMethod.kind == ElementKind.FUNCTION ||
1808 superMethod.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { 1808 superMethod.kind == ElementKind.GENERATIVE_CONSTRUCTOR) {
1809 String methodName = compiler.namer.instanceMethodName( 1809 String methodName = compiler.namer.instanceMethodName(
1810 currentLibrary, superMethod.name, argumentCount); 1810 currentLibrary, superMethod.name, argumentCount);
1811 buffer.add('$className.prototype.$methodName.call'); 1811 buffer.add('$className.prototype.$methodName.call');
1812 visitArguments(node.inputs); 1812 visitArguments(node.inputs);
1813 } else if (superMethod.kind == ElementKind.FIELD) { 1813 } else if (superMethod.kind == ElementKind.FIELD) {
1814 ClassElement currentClass = work.element.enclosingElement; 1814 ClassElement currentClass = work.element.getEnclosingClass();
1815 if (currentClass.isShadowedByField(superMethod)) { 1815 if (currentClass.isShadowedByField(superMethod)) {
1816 buffer.add('this.${compiler.namer.shadowedFieldName(superMethod)}'); 1816 buffer.add('this.${compiler.namer.shadowedFieldName(superMethod)}');
1817 } else { 1817 } else {
1818 LibraryElement library = superMethod.getLibrary(); 1818 LibraryElement library = superMethod.getLibrary();
1819 SourceString name = superMethod.name; 1819 SourceString name = superMethod.name;
1820 buffer.add('this.${compiler.namer.instanceFieldName(library, name)}'); 1820 buffer.add('this.${compiler.namer.instanceFieldName(library, name)}');
1821 } 1821 }
1822 } else { 1822 } else {
1823 assert(superMethod.kind == ElementKind.GETTER || 1823 assert(superMethod.kind == ElementKind.GETTER ||
1824 superMethod.kind == ElementKind.SETTER); 1824 superMethod.kind == ElementKind.SETTER);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 return (isSimpleFieldNumberComputation(value.left, node) && 1867 return (isSimpleFieldNumberComputation(value.left, node) &&
1868 isSimpleFieldNumberComputation(value.right, node)); 1868 isSimpleFieldNumberComputation(value.right, node));
1869 } 1869 }
1870 if (value is HFieldGet) return value.element == node.element; 1870 if (value is HFieldGet) return value.element == node.element;
1871 return false; 1871 return false;
1872 } 1872 }
1873 1873
1874 visitFieldSet(HFieldSet node) { 1874 visitFieldSet(HFieldSet node) {
1875 if (node.element != null && 1875 if (node.element != null &&
1876 work.element.isGenerativeConstructorBody() && 1876 work.element.isGenerativeConstructorBody() &&
1877 node.element.enclosingElement.isClass() && 1877 node.element.isMember() &&
1878 node.value.hasGuaranteedType() && 1878 node.value.hasGuaranteedType() &&
1879 node.block.dominates(currentGraph.exit)) { 1879 node.block.dominates(currentGraph.exit)) {
1880 backend.updateFieldConstructorSetters(node.element, 1880 backend.updateFieldConstructorSetters(node.element,
1881 node.value.guaranteedType); 1881 node.value.guaranteedType);
1882 } 1882 }
1883 String name = 1883 String name =
1884 compiler.namer.instanceFieldName(node.library, node.fieldName); 1884 compiler.namer.instanceFieldName(node.library, node.fieldName);
1885 beginExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); 1885 beginExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE);
1886 use(node.receiver, JSPrecedence.MEMBER_PRECEDENCE); 1886 use(node.receiver, JSPrecedence.MEMBER_PRECEDENCE);
1887 buffer.add('.'); 1887 buffer.add('.');
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after
3208 if (leftType.canBeNull() && rightType.canBeNull()) { 3208 if (leftType.canBeNull() && rightType.canBeNull()) {
3209 if (left.isConstantNull() || right.isConstantNull() || 3209 if (left.isConstantNull() || right.isConstantNull() ||
3210 (leftType.isPrimitive() && leftType == rightType)) { 3210 (leftType.isPrimitive() && leftType == rightType)) {
3211 return '=='; 3211 return '==';
3212 } 3212 }
3213 return null; 3213 return null;
3214 } else { 3214 } else {
3215 return '==='; 3215 return '===';
3216 } 3216 }
3217 } 3217 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698