| OLD | NEW |
| 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 Interceptors { | 5 class Interceptors { |
| 6 Compiler compiler; | 6 Compiler compiler; |
| 7 Interceptors(Compiler this.compiler); | 7 Interceptors(Compiler this.compiler); |
| 8 | 8 |
| 9 SourceString mapOperatorToMethodName(Operator op) { | 9 SourceString mapOperatorToMethodName(Operator op) { |
| 10 String name = op.source.stringValue; | 10 String name = op.source.stringValue; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 bool inLoop = functionsCalledInLoop.contains(element.declaration); | 188 bool inLoop = functionsCalledInLoop.contains(element.declaration); |
| 189 if (!inLoop) { | 189 if (!inLoop) { |
| 190 Selector selector = selectorsCalledInLoop[element.name]; | 190 Selector selector = selectorsCalledInLoop[element.name]; |
| 191 inLoop = selector !== null && selector.applies(element, compiler); | 191 inLoop = selector !== null && selector.applies(element, compiler); |
| 192 } | 192 } |
| 193 graph.calledInLoop = inLoop; | 193 graph.calledInLoop = inLoop; |
| 194 | 194 |
| 195 // If there is an estimate of the parameter types assume these types | 195 // If there is an estimate of the parameter types assume these types |
| 196 // when compiling. | 196 // when compiling. |
| 197 OptionalParameterTypes defaultValueTypes = null; | 197 OptionalParameterTypes defaultValueTypes = null; |
| 198 FunctionSignature signature = element.computeSignature(compiler); | 198 FunctionSignature signature = |
| 199 element.computeSignature(compiler); |
| 199 if (signature.optionalParameterCount > 0) { | 200 if (signature.optionalParameterCount > 0) { |
| 200 defaultValueTypes = | 201 defaultValueTypes = |
| 201 new OptionalParameterTypes(signature.optionalParameterCount); | 202 new OptionalParameterTypes(signature.optionalParameterCount); |
| 202 int index = 0; | 203 int index = 0; |
| 203 signature.forEachOptionalParameter((Element parameter) { | 204 signature.forEachOptionalParameter((Element parameter) { |
| 204 Constant defaultValue = compiler.compileVariable(parameter); | 205 Constant defaultValue = compiler.compileVariable(parameter); |
| 205 HType type = HGraph.mapConstantTypeToSsaType(defaultValue); | 206 HType type = HGraph.mapConstantTypeToSsaType(defaultValue); |
| 206 defaultValueTypes.update(index, parameter.name, type); | 207 defaultValueTypes.update(index, parameter.name, type); |
| 207 index++; | 208 index++; |
| 208 }); | 209 }); |
| 209 } | 210 } |
| 210 HTypeList parameterTypes = | 211 HTypeList parameterTypes = |
| 211 backend.optimisticParameterTypes(element.declaration, | 212 backend.optimisticParameterTypes(element.declaration, |
| 212 defaultValueTypes); | 213 defaultValueTypes); |
| 213 if (!parameterTypes.allUnknown) { | 214 if (!parameterTypes.allUnknown) { |
| 214 int i = 0; | 215 int i = 0; |
| 215 signature.forEachParameter((Element param) { | 216 signature.forEachParameter((Element param) { |
| 216 builder.parameters[param].guaranteedType = parameterTypes[i++]; | 217 builder.parameters[param].guaranteedType = parameterTypes[i++]; |
| 217 }); | 218 }); |
| 218 } | 219 } |
| 219 backend.registerParameterTypesOptimization( | 220 backend.registerParameterTypesOptimization( |
| 220 element, parameterTypes, defaultValueTypes); | 221 element.declaration, parameterTypes, defaultValueTypes); |
| 221 } | 222 } |
| 222 | 223 |
| 223 if (compiler.tracer.enabled) { | 224 if (compiler.tracer.enabled) { |
| 224 String name; | 225 String name; |
| 225 if (element.isMember()) { | 226 if (element.isMember()) { |
| 226 String className = element.getEnclosingClass().name.slowToString(); | 227 String className = element.getEnclosingClass().name.slowToString(); |
| 227 String memberName = element.name.slowToString(); | 228 String memberName = element.name.slowToString(); |
| 228 name = "$className.$memberName"; | 229 name = "$className.$memberName"; |
| 229 if (element.isGenerativeConstructorBody()) { | 230 if (element.isGenerativeConstructorBody()) { |
| 230 name = "$name (body)"; | 231 name = "$name (body)"; |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 } | 968 } |
| 968 } | 969 } |
| 969 if (bodyElement === null) { | 970 if (bodyElement === null) { |
| 970 bodyElement = new ConstructorBodyElement(constructor); | 971 bodyElement = new ConstructorBodyElement(constructor); |
| 971 // [:resolveMethodElement:] require the passed element to be a | 972 // [:resolveMethodElement:] require the passed element to be a |
| 972 // declaration. | 973 // declaration. |
| 973 TreeElements treeElements = | 974 TreeElements treeElements = |
| 974 compiler.resolver.resolveMethodElement(constructor.declaration); | 975 compiler.resolver.resolveMethodElement(constructor.declaration); |
| 975 classElement.backendMembers = | 976 classElement.backendMembers = |
| 976 classElement.backendMembers.prepend(bodyElement); | 977 classElement.backendMembers.prepend(bodyElement); |
| 978 |
| 979 if (constructor.origin != null) { |
| 980 // Create origin body element for patched constructors. |
| 981 bodyElement.origin = new ConstructorBodyElement(constructor.origin); |
| 982 bodyElement.origin.patch = bodyElement; |
| 983 classElement.origin.backendMembers = |
| 984 classElement.origin.backendMembers.prepend(bodyElement.origin); |
| 985 } |
| 977 compiler.enqueuer.codegen.addToWorkList(bodyElement.declaration, | 986 compiler.enqueuer.codegen.addToWorkList(bodyElement.declaration, |
| 978 treeElements); | 987 treeElements); |
| 979 } | 988 } |
| 980 assert(bodyElement.isGenerativeConstructorBody()); | 989 assert(bodyElement.isGenerativeConstructorBody()); |
| 981 return bodyElement; | 990 return bodyElement; |
| 982 } | 991 } |
| 983 | 992 |
| 984 /** | 993 /** |
| 985 * Documentation wanted -- johnniwinther | 994 * Documentation wanted -- johnniwinther |
| 986 * | 995 * |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 if (!foundSuperOrRedirect) { | 1191 if (!foundSuperOrRedirect) { |
| 1183 // No super initializer found. Try to find the default constructor if | 1192 // No super initializer found. Try to find the default constructor if |
| 1184 // the class is not Object. | 1193 // the class is not Object. |
| 1185 ClassElement enclosingClass = constructor.getEnclosingClass(); | 1194 ClassElement enclosingClass = constructor.getEnclosingClass(); |
| 1186 ClassElement superClass = enclosingClass.superclass; | 1195 ClassElement superClass = enclosingClass.superclass; |
| 1187 if (!enclosingClass.isObject(compiler)) { | 1196 if (!enclosingClass.isObject(compiler)) { |
| 1188 assert(superClass !== null); | 1197 assert(superClass !== null); |
| 1189 assert(superClass.resolutionState == STATE_DONE); | 1198 assert(superClass.resolutionState == STATE_DONE); |
| 1190 Selector selector = | 1199 Selector selector = |
| 1191 new Selector.call(superClass.name, enclosingClass.getLibrary(), 0); | 1200 new Selector.call(superClass.name, enclosingClass.getLibrary(), 0); |
| 1201 // TODO(johnniwinther): Should we find injected constructors as well? |
| 1192 FunctionElement target = superClass.lookupConstructor(superClass.name); | 1202 FunctionElement target = superClass.lookupConstructor(superClass.name); |
| 1193 if (target === null) { | 1203 if (target === null) { |
| 1194 compiler.internalError("no default constructor available"); | 1204 compiler.internalError("no default constructor available"); |
| 1195 } | 1205 } |
| 1196 inlineSuperOrRedirect(target.implementation, | 1206 inlineSuperOrRedirect(target.implementation, |
| 1197 selector, | 1207 selector, |
| 1198 const EmptyLink<Node>(), | 1208 const EmptyLink<Node>(), |
| 1199 constructors, | 1209 constructors, |
| 1200 fieldValues); | 1210 fieldValues); |
| 1201 } | 1211 } |
| 1202 } | 1212 } |
| 1203 } | 1213 } |
| 1204 | 1214 |
| 1205 /** | 1215 /** |
| 1206 * Run through the fields of [cls] and add their potential | 1216 * Run through the fields of [cls] and add their potential |
| 1207 * initializers. | 1217 * initializers. |
| 1208 * | 1218 * |
| 1209 * Invariant: [classElement] must be a declaration element. | 1219 * Invariant: [classElement] must be a declaration element. |
| 1210 */ | 1220 */ |
| 1211 void buildFieldInitializers(ClassElement classElement, | 1221 void buildFieldInitializers(ClassElement classElement, |
| 1212 Map<Element, HInstruction> fieldValues) { | 1222 Map<Element, HInstruction> fieldValues) { |
| 1213 assert(invariant(classElement, classElement.isDeclaration)); | 1223 assert(invariant(classElement, classElement.isDeclaration)); |
| 1214 classElement.forEachInstanceField( | 1224 classElement.forEachInstanceField( |
| 1215 includeBackendMembers: true, | 1225 includeBackendMembers: true, |
| 1216 includeSuperMembers: false, | 1226 includeSuperMembers: false, |
| 1227 includeInjectedMembers: true, |
| 1217 f: (ClassElement enclosingClass, Element member) { | 1228 f: (ClassElement enclosingClass, Element member) { |
| 1218 TreeElements definitions = compiler.analyzeElement(member); | 1229 TreeElements definitions = compiler.analyzeElement(member); |
| 1219 Node node = member.parseNode(compiler); | 1230 Node node = member.parseNode(compiler); |
| 1220 SendSet assignment = node.asSendSet(); | 1231 SendSet assignment = node.asSendSet(); |
| 1221 HInstruction value; | 1232 HInstruction value; |
| 1222 if (assignment === null) { | 1233 if (assignment === null) { |
| 1223 value = graph.addConstantNull(constantSystem); | 1234 value = graph.addConstantNull(constantSystem); |
| 1224 } else { | 1235 } else { |
| 1225 Node right = assignment.arguments.head; | 1236 Node right = assignment.arguments.head; |
| 1226 TreeElements savedElements = elements; | 1237 TreeElements savedElements = elements; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 // Analyze the constructor and all referenced constructors and collect | 1290 // Analyze the constructor and all referenced constructors and collect |
| 1280 // initializers and constructor bodies. | 1291 // initializers and constructor bodies. |
| 1281 List<FunctionElement> constructors = <FunctionElement>[functionElement]; | 1292 List<FunctionElement> constructors = <FunctionElement>[functionElement]; |
| 1282 buildInitializers(functionElement, constructors, fieldValues); | 1293 buildInitializers(functionElement, constructors, fieldValues); |
| 1283 | 1294 |
| 1284 // Call the JavaScript constructor with the fields as argument. | 1295 // Call the JavaScript constructor with the fields as argument. |
| 1285 List<HInstruction> constructorArguments = <HInstruction>[]; | 1296 List<HInstruction> constructorArguments = <HInstruction>[]; |
| 1286 classElement.forEachInstanceField( | 1297 classElement.forEachInstanceField( |
| 1287 includeBackendMembers: true, | 1298 includeBackendMembers: true, |
| 1288 includeSuperMembers: true, | 1299 includeSuperMembers: true, |
| 1300 includeInjectedMembers: true, |
| 1289 f: (ClassElement enclosingClass, Element member) { | 1301 f: (ClassElement enclosingClass, Element member) { |
| 1290 constructorArguments.add( | 1302 constructorArguments.add( |
| 1291 potentiallyCheckType(fieldValues[member], member)); | 1303 potentiallyCheckType(fieldValues[member], member)); |
| 1292 }); | 1304 }); |
| 1293 | 1305 |
| 1294 HForeignNew newObject = new HForeignNew(classElement, constructorArguments); | 1306 HForeignNew newObject = new HForeignNew(classElement, constructorArguments); |
| 1295 add(newObject); | 1307 add(newObject); |
| 1296 | 1308 |
| 1297 // Create the runtime type information, if needed. | 1309 // Create the runtime type information, if needed. |
| 1298 InterfaceType type = classElement.computeType(compiler); | 1310 InterfaceType type = classElement.computeType(compiler); |
| (...skipping 3028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4327 new HSubGraphBlockInformation(elseBranch.graph)); | 4339 new HSubGraphBlockInformation(elseBranch.graph)); |
| 4328 | 4340 |
| 4329 HBasicBlock conditionStartBlock = conditionBranch.block; | 4341 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 4330 conditionStartBlock.setBlockFlow(info, joinBlock); | 4342 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 4331 SubGraph conditionGraph = conditionBranch.graph; | 4343 SubGraph conditionGraph = conditionBranch.graph; |
| 4332 HIf branch = conditionGraph.end.last; | 4344 HIf branch = conditionGraph.end.last; |
| 4333 assert(branch is HIf); | 4345 assert(branch is HIf); |
| 4334 branch.blockInformation = conditionStartBlock.blockFlow; | 4346 branch.blockInformation = conditionStartBlock.blockFlow; |
| 4335 } | 4347 } |
| 4336 } | 4348 } |
| OLD | NEW |