OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 dart2js.ir_builder_task; | 5 library dart2js.ir_builder_task; |
6 | 6 |
7 import '../closure.dart' as closurelib; | 7 import '../closure.dart' as closurelib; |
8 import '../closure.dart' hide ClosureScope; | 8 import '../closure.dart' hide ClosureScope; |
9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 } | 398 } |
399 irBuilder.declareLocalVariable(element, initialValue: initialValue); | 399 irBuilder.declareLocalVariable(element, initialValue: initialValue); |
400 } | 400 } |
401 return null; | 401 return null; |
402 } | 402 } |
403 | 403 |
404 // Build(Return(e), C) = C'[InvokeContinuation(return, x)] | 404 // Build(Return(e), C) = C'[InvokeContinuation(return, x)] |
405 // where (C', x) = Build(e, C) | 405 // where (C', x) = Build(e, C) |
406 // | 406 // |
407 // Return without a subexpression is translated as if it were return null. | 407 // Return without a subexpression is translated as if it were return null. |
408 ir.Primitive visitReturn(ast.Return node) { | 408 visitReturn(ast.Return node) { |
409 assert(irBuilder.isOpen); | 409 assert(irBuilder.isOpen); |
410 assert(invariant(node, node.beginToken.value != 'native')); | 410 SourceInformation source = sourceInformationBuilder.buildReturn(node); |
411 irBuilder.buildReturn( | 411 if (node.beginToken.value == 'native') { |
412 value: build(node.expression), | 412 irBuilder.buildNativeFunctionBody(node.expression, source); |
413 sourceInformation: sourceInformationBuilder.buildReturn(node)); | 413 } else { |
414 return null; | 414 irBuilder.buildReturn( |
| 415 value: build(node.expression), |
| 416 sourceInformation: source); |
| 417 } |
415 } | 418 } |
416 | 419 |
417 visitSwitchStatement(ast.SwitchStatement node) { | 420 visitSwitchStatement(ast.SwitchStatement node) { |
418 assert(irBuilder.isOpen); | 421 assert(irBuilder.isOpen); |
419 // We do not handle switch statements with continue to labeled cases. | 422 // We do not handle switch statements with continue to labeled cases. |
420 for (ast.SwitchCase switchCase in node.cases) { | 423 for (ast.SwitchCase switchCase in node.cases) { |
421 for (ast.Node labelOrCase in switchCase.labelsAndCases) { | 424 for (ast.Node labelOrCase in switchCase.labelsAndCases) { |
422 if (labelOrCase is ast.Label) { | 425 if (labelOrCase is ast.Label) { |
423 LabelDefinition definition = elements.getLabelDefinition(labelOrCase); | 426 LabelDefinition definition = elements.getLabelDefinition(labelOrCase); |
424 if (definition != null && definition.isContinueTarget) { | 427 if (definition != null && definition.isContinueTarget) { |
(...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2274 return _backend.getStringInterpolationHelper(); | 2277 return _backend.getStringInterpolationHelper(); |
2275 } | 2278 } |
2276 | 2279 |
2277 FunctionElement get throwTypeErrorHelper => _backend.getThrowTypeError(); | 2280 FunctionElement get throwTypeErrorHelper => _backend.getThrowTypeError(); |
2278 | 2281 |
2279 ClassElement get nullClass => _compiler.nullClass; | 2282 ClassElement get nullClass => _compiler.nullClass; |
2280 | 2283 |
2281 DartType unaliasType(DartType type) => type.unalias(_compiler); | 2284 DartType unaliasType(DartType type) => type.unalias(_compiler); |
2282 | 2285 |
2283 TypeMask getTypeMaskForForeign(NativeBehavior behavior) { | 2286 TypeMask getTypeMaskForForeign(NativeBehavior behavior) { |
| 2287 if (behavior == null) { |
| 2288 return _backend.dynamicType; |
| 2289 } |
2284 return TypeMaskFactory.fromNativeBehavior(behavior, _compiler); | 2290 return TypeMaskFactory.fromNativeBehavior(behavior, _compiler); |
2285 } | 2291 } |
2286 | 2292 |
2287 FieldElement locateSingleField(Selector selector, TypeMask type) { | 2293 FieldElement locateSingleField(Selector selector, TypeMask type) { |
2288 return _compiler.world.locateSingleField(selector, type); | 2294 return _compiler.world.locateSingleField(selector, type); |
2289 } | 2295 } |
| 2296 |
| 2297 Element get closureConverter { |
| 2298 return _backend.getClosureConverter(); |
| 2299 } |
| 2300 |
| 2301 void addNativeMethod(FunctionElement function) { |
| 2302 _backend.emitter.nativeEmitter.nativeMethods.add(function); |
| 2303 } |
2290 } | 2304 } |
2291 | 2305 |
2292 /// IR builder specific to the JavaScript backend, coupled to the [JsIrBuilder]. | 2306 /// IR builder specific to the JavaScript backend, coupled to the [JsIrBuilder]. |
2293 class JsIrBuilderVisitor extends IrBuilderVisitor { | 2307 class JsIrBuilderVisitor extends IrBuilderVisitor { |
2294 JavaScriptBackend get backend => compiler.backend; | 2308 JavaScriptBackend get backend => compiler.backend; |
2295 | 2309 |
2296 /// Result of closure conversion for the current body of code. | 2310 /// Result of closure conversion for the current body of code. |
2297 /// | 2311 /// |
2298 /// Will be initialized upon entering the body of a function. | 2312 /// Will be initialized upon entering the body of a function. |
2299 /// It is computed by the [ClosureTranslator]. | 2313 /// It is computed by the [ClosureTranslator]. |
(...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3347 if (compiler.backend.isForeign(function)) { | 3361 if (compiler.backend.isForeign(function)) { |
3348 return handleForeignCode(node, function, argumentList, callStructure); | 3362 return handleForeignCode(node, function, argumentList, callStructure); |
3349 } else { | 3363 } else { |
3350 return irBuilder.buildStaticFunctionInvocation(function, callStructure, | 3364 return irBuilder.buildStaticFunctionInvocation(function, callStructure, |
3351 translateStaticArguments(argumentList, function, callStructure), | 3365 translateStaticArguments(argumentList, function, callStructure), |
3352 sourceInformation: | 3366 sourceInformation: |
3353 sourceInformationBuilder.buildCall(node, node.selector)); | 3367 sourceInformationBuilder.buildCall(node, node.selector)); |
3354 } | 3368 } |
3355 } | 3369 } |
3356 } | 3370 } |
OLD | NEW |