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

Side by Side Diff: lib/compiler/implementation/compile_time_constants.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 Constant implements Hashable { 5 class Constant implements Hashable {
6 const Constant(); 6 const Constant();
7 7
8 bool isNull() => false; 8 bool isNull() => false;
9 bool isBool() => false; 9 bool isBool() => false;
10 bool isTrue() => false; 10 bool isTrue() => false;
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 compiler); 980 compiler);
981 assert(succeeded); 981 assert(succeeded);
982 return compiledArguments; 982 return compiledArguments;
983 } 983 }
984 984
985 Constant visitNewExpression(NewExpression node) { 985 Constant visitNewExpression(NewExpression node) {
986 if (!node.isConst()) error(node); 986 if (!node.isConst()) error(node);
987 987
988 Send send = node.send; 988 Send send = node.send;
989 FunctionElement constructor = elements[send]; 989 FunctionElement constructor = elements[send];
990 ClassElement classElement = constructor.enclosingElement; 990 ClassElement classElement = constructor.getEnclosingClass();
991 if (classElement.isInterface()) { 991 if (classElement.isInterface()) {
992 compiler.resolver.resolveMethodElement(constructor); 992 compiler.resolver.resolveMethodElement(constructor);
993 constructor = constructor.defaultImplementation; 993 constructor = constructor.defaultImplementation;
994 classElement = constructor.enclosingElement; 994 classElement = constructor.getEnclosingClass();
995 } 995 }
996 996
997 Selector selector = elements.getSelector(send); 997 Selector selector = elements.getSelector(send);
998 List<Constant> arguments = 998 List<Constant> arguments =
999 evaluateArgumentsToConstructor(selector, send.arguments, constructor); 999 evaluateArgumentsToConstructor(selector, send.arguments, constructor);
1000 ConstructorEvaluator evaluator = 1000 ConstructorEvaluator evaluator =
1001 new ConstructorEvaluator(constructor, compiler); 1001 new ConstructorEvaluator(constructor, compiler);
1002 evaluator.evaluateConstructorFieldValues(arguments); 1002 evaluator.evaluateConstructorFieldValues(arguments);
1003 List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement); 1003 List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement);
1004 1004
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 assert(!initArguments.isEmpty() && initArguments.tail.isEmpty()); 1119 assert(!initArguments.isEmpty() && initArguments.tail.isEmpty());
1120 Constant fieldValue = evaluate(initArguments.head); 1120 Constant fieldValue = evaluate(initArguments.head);
1121 fieldValues[elements[init]] = fieldValue; 1121 fieldValues[elements[init]] = fieldValue;
1122 } 1122 }
1123 } 1123 }
1124 } 1124 }
1125 1125
1126 if (!foundSuperOrRedirect) { 1126 if (!foundSuperOrRedirect) {
1127 // No super initializer found. Try to find the default constructor if 1127 // No super initializer found. Try to find the default constructor if
1128 // the class is not Object. 1128 // the class is not Object.
1129 ClassElement enclosingClass = constructor.enclosingElement; 1129 ClassElement enclosingClass = constructor.getEnclosingClass();
1130 ClassElement superClass = enclosingClass.superclass; 1130 ClassElement superClass = enclosingClass.superclass;
1131 if (enclosingClass != compiler.objectClass) { 1131 if (enclosingClass != compiler.objectClass) {
1132 assert(superClass !== null); 1132 assert(superClass !== null);
1133 assert(superClass.isResolved); 1133 assert(superClass.isResolved);
1134 FunctionElement targetConstructor = 1134 FunctionElement targetConstructor =
1135 superClass.lookupConstructor(superClass.name); 1135 superClass.lookupConstructor(superClass.name);
1136 if (targetConstructor === null) { 1136 if (targetConstructor === null) {
1137 compiler.internalError("no default constructor available", 1137 compiler.internalError("no default constructor available",
1138 node: functionNode); 1138 node: functionNode);
1139 } 1139 }
(...skipping 26 matching lines...) Expand all
1166 Constant fieldValue = fieldValues[field]; 1166 Constant fieldValue = fieldValues[field];
1167 if (fieldValue === null) { 1167 if (fieldValue === null) {
1168 // Use the default value. 1168 // Use the default value.
1169 fieldValue = compiler.compileVariable(field); 1169 fieldValue = compiler.compileVariable(field);
1170 } 1170 }
1171 jsNewArguments.add(fieldValue); 1171 jsNewArguments.add(fieldValue);
1172 }); 1172 });
1173 return jsNewArguments; 1173 return jsNewArguments;
1174 } 1174 }
1175 } 1175 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/compiler.dart » ('j') | lib/compiler/implementation/elements/elements.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698