Chromium Code Reviews| 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 part of dart2js.ir_builder; | 5 part of dart2js.ir_builder; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * This task iterates through all resolved elements and builds [ir.Node]s. The | 8 * This task iterates through all resolved elements and builds [ir.Node]s. The |
| 9 * nodes are stored in the [nodes] map and accessible through [hasIr] and | 9 * nodes are stored in the [nodes] map and accessible through [hasIr] and |
| 10 * [getIr]. | 10 * [getIr]. |
| (...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 assert(irBuilder.isOpen); | 949 assert(irBuilder.isOpen); |
| 950 // If the user is trying to invoke the type literal or variable, | 950 // If the user is trying to invoke the type literal or variable, |
| 951 // it must be treated as a function call. | 951 // it must be treated as a function call. |
| 952 if (node.argumentsNode != null) { | 952 if (node.argumentsNode != null) { |
| 953 // TODO(sigurdm): Handle this to match proposed semantics of issue #19725. | 953 // TODO(sigurdm): Handle this to match proposed semantics of issue #19725. |
| 954 return giveup(node, 'Type literal invoked as function'); | 954 return giveup(node, 'Type literal invoked as function'); |
| 955 } | 955 } |
| 956 | 956 |
| 957 DartType type = elements.getTypeLiteralType(node); | 957 DartType type = elements.getTypeLiteralType(node); |
| 958 if (type is TypeVariableType) { | 958 if (type is TypeVariableType) { |
| 959 ir.Primitive prim = new ir.ReifyTypeVar(type.element); | 959 return buildReifyTypeVariable(new ir.This(), type); |
|
asgerf
2015/03/02 13:52:36
Use irBuilder.buildThis(), otherwise 'this' inside
karlklose
2015/03/05 09:54:58
Done.
| |
| 960 irBuilder.add(new ir.LetPrim(prim)); | |
| 961 return prim; | |
| 962 } else { | 960 } else { |
| 963 return translateConstant(node); | 961 return translateConstant(node); |
| 964 } | 962 } |
| 965 } | 963 } |
| 966 | 964 |
| 965 ir.Primitive buildReifyTypeVariable(ir.Primitive target, | |
| 966 TypeVariableType variable); | |
| 967 | |
| 967 ir.Primitive visitSendSet(ast.SendSet node) { | 968 ir.Primitive visitSendSet(ast.SendSet node) { |
| 968 assert(irBuilder.isOpen); | 969 assert(irBuilder.isOpen); |
| 969 Element element = elements[node]; | 970 Element element = elements[node]; |
| 970 ast.Operator op = node.assignmentOperator; | 971 ast.Operator op = node.assignmentOperator; |
| 971 // For complex operators, this is the result of getting (before assigning) | 972 // For complex operators, this is the result of getting (before assigning) |
| 972 ir.Primitive originalValue; | 973 ir.Primitive originalValue; |
| 973 // For []+= style operators, this saves the index. | 974 // For []+= style operators, this saves the index. |
| 974 ir.Primitive index; | 975 ir.Primitive index; |
| 975 ir.Primitive receiver; | 976 ir.Primitive receiver; |
| 976 // This is what gets assigned. | 977 // This is what gets assigned. |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1370 FunctionElement target, | 1371 FunctionElement target, |
| 1371 List<ir.Primitive> arguments) { | 1372 List<ir.Primitive> arguments) { |
| 1372 return arguments; | 1373 return arguments; |
| 1373 } | 1374 } |
| 1374 | 1375 |
| 1375 List<ir.Primitive> normalizeDynamicArguments( | 1376 List<ir.Primitive> normalizeDynamicArguments( |
| 1376 Selector selector, | 1377 Selector selector, |
| 1377 List<ir.Primitive> arguments) { | 1378 List<ir.Primitive> arguments) { |
| 1378 return arguments; | 1379 return arguments; |
| 1379 } | 1380 } |
| 1381 | |
| 1382 @override | |
| 1383 ir.Primitive buildReifyTypeVariable(ir.Primitive target, | |
| 1384 TypeVariableType variable) { | |
| 1385 assert(target is ir.This); | |
|
asgerf
2015/03/02 13:52:36
FYI I believe this assertion is still valid with t
karlklose
2015/03/05 09:54:58
Acknowledged.
| |
| 1386 ir.Primitive prim = new ir.ReifyTypeVar(variable.element); | |
| 1387 irBuilder.add(new ir.LetPrim(prim)); | |
| 1388 return prim; | |
| 1389 } | |
| 1380 } | 1390 } |
| 1381 | 1391 |
| 1382 /// IR builder specific to the JavaScript backend, coupled to the [JsIrBuilder]. | 1392 /// IR builder specific to the JavaScript backend, coupled to the [JsIrBuilder]. |
| 1383 class JsIrBuilderVisitor extends IrBuilderVisitor { | 1393 class JsIrBuilderVisitor extends IrBuilderVisitor { |
| 1384 /// Promote the type of [irBuilder] to [JsIrBuilder]. | 1394 /// Promote the type of [irBuilder] to [JsIrBuilder]. |
| 1385 JsIrBuilder get irBuilder => super.irBuilder; | 1395 JsIrBuilder get irBuilder => super.irBuilder; |
| 1386 | 1396 |
| 1387 /// Result of closure conversion for the current body of code. | 1397 /// Result of closure conversion for the current body of code. |
| 1388 /// | 1398 /// |
| 1389 /// Will be initialized upon entering the body of a function. | 1399 /// Will be initialized upon entering the body of a function. |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1896 result.add(arguments[i]); | 1906 result.add(arguments[i]); |
| 1897 } | 1907 } |
| 1898 for (String argName in selector.getOrderedNamedArguments()) { | 1908 for (String argName in selector.getOrderedNamedArguments()) { |
| 1899 int nameIndex = selector.namedArguments.indexOf(argName); | 1909 int nameIndex = selector.namedArguments.indexOf(argName); |
| 1900 int translatedIndex = selector.positionalArgumentCount + nameIndex; | 1910 int translatedIndex = selector.positionalArgumentCount + nameIndex; |
| 1901 result.add(arguments[translatedIndex]); | 1911 result.add(arguments[translatedIndex]); |
| 1902 } | 1912 } |
| 1903 return result; | 1913 return result; |
| 1904 } | 1914 } |
| 1905 | 1915 |
| 1916 | |
| 1917 @override | |
| 1918 ir.Primitive buildReifyTypeVariable(ir.Primitive target, | |
| 1919 TypeVariableType variable) { | |
| 1920 ClassElement context = variable.element.enclosingClass; | |
| 1921 irBuilder.add(new ir.LetPrim(target)); | |
| 1922 ir.Primitive typeArgument = | |
| 1923 new ir.ReadTypeVariable(variable, context, target); | |
|
asgerf
2015/03/02 13:52:36
This seems wrong. We are always passing variable.e
karlklose
2015/03/05 09:54:58
I removed the context. We do not need it until we
| |
| 1924 irBuilder.add(new ir.LetPrim(typeArgument)); | |
| 1925 var type = new ir.ReifyRuntimeType(typeArgument); | |
| 1926 irBuilder.add(new ir.LetPrim(type)); | |
| 1927 return type; | |
| 1928 } | |
| 1906 } | 1929 } |
| 1907 | 1930 |
| OLD | NEW |