| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 closureData = translator.translate(node); | 257 closureData = translator.translate(node); |
| 258 | 258 |
| 259 FunctionParameters params = function.computeParameters(builder.compiler); | 259 FunctionParameters params = function.computeParameters(builder.compiler); |
| 260 params.forEachParameter((Element element) { | 260 params.forEachParameter((Element element) { |
| 261 HParameterValue parameter = new HParameterValue(element); | 261 HParameterValue parameter = new HParameterValue(element); |
| 262 builder.add(parameter); | 262 builder.add(parameter); |
| 263 // Note that for constructors [element] could be a field-element which we | 263 // Note that for constructors [element] could be a field-element which we |
| 264 // treat as if it was a local. | 264 // treat as if it was a local. |
| 265 directLocals[element] = parameter; | 265 directLocals[element] = parameter; |
| 266 }); | 266 }); |
| 267 if (closureData.thisElement !== null) { |
| 268 // Once closures have been mapped to classes their instance members might |
| 269 // not have any thisElement if the closure was created inside a static |
| 270 // context. |
| 271 assert(function.isInstanceMember() || function.isGenerativeConstructor()); |
| 272 // We have to introduce 'this' before we enter the scope, since it might |
| 273 // need to be copied into a box (if it is captured). This is similar |
| 274 // to all other parameters that are introduced. |
| 275 HInstruction thisInstruction = new HThis(); |
| 276 builder.add(thisInstruction); |
| 277 directLocals[closureData.thisElement] = thisInstruction; |
| 278 } |
| 267 | 279 |
| 268 enterScope(node); | 280 enterScope(node); |
| 269 | 281 |
| 270 // If the freeVariableMapping is not empty, then this function was a | 282 // If the freeVariableMapping is not empty, then this function was a |
| 271 // nested closure that captures variables. Redirect the captured | 283 // nested closure that captures variables. Redirect the captured |
| 272 // variables to fields in the closure. | 284 // variables to fields in the closure. |
| 273 closureData.freeVariableMapping.forEach((Element from, Element to) { | 285 closureData.freeVariableMapping.forEach((Element from, Element to) { |
| 274 redirectElement(from, to); | 286 redirectElement(from, to); |
| 275 }); | 287 }); |
| 276 if (closureData.isClosure()) { | 288 if (closureData.isClosure()) { |
| 277 // Inside closure redirect references to itself to [:this:]. | 289 // Inside closure redirect references to itself to [:this:]. |
| 278 HInstruction thisInstruction = new HThis(); | 290 HInstruction thisInstruction = new HThis(); |
| 279 builder.add(thisInstruction); | 291 builder.add(thisInstruction); |
| 280 updateLocal(closureData.closureElement, thisInstruction); | 292 updateLocal(closureData.closureElement, thisInstruction); |
| 281 } else if (function.isInstanceMember() || | |
| 282 function.isGenerativeConstructor()) { | |
| 283 HInstruction thisInstruction = new HThis(); | |
| 284 builder.add(thisInstruction); | |
| 285 updateLocal(closureData.thisElement, thisInstruction); | |
| 286 } | 293 } |
| 287 } | 294 } |
| 288 | 295 |
| 289 bool hasValueForDirectLocal(Element element) { | 296 bool hasValueForDirectLocal(Element element) { |
| 290 assert(element !== null); | 297 assert(element !== null); |
| 291 assert(isAccessedDirectly(element)); | 298 assert(isAccessedDirectly(element)); |
| 292 return directLocals[element] !== null; | 299 return directLocals[element] !== null; |
| 293 } | 300 } |
| 294 | 301 |
| 295 /** | 302 /** |
| (...skipping 2042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2338 } | 2345 } |
| 2339 | 2346 |
| 2340 visitCatchBlock(CatchBlock node) { | 2347 visitCatchBlock(CatchBlock node) { |
| 2341 visit(node.block); | 2348 visit(node.block); |
| 2342 } | 2349 } |
| 2343 | 2350 |
| 2344 visitTypedef(Typedef node) { | 2351 visitTypedef(Typedef node) { |
| 2345 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); | 2352 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); |
| 2346 } | 2353 } |
| 2347 } | 2354 } |
| OLD | NEW |