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 library dart2js.ir_builder; | 5 library dart2js.ir_builder; |
| 6 | 6 |
| 7 import 'ir_nodes.dart' as ir; | 7 import 'ir_nodes.dart' as ir; |
| 8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
| 9 import '../dart2jslib.dart'; | 9 import '../dart2jslib.dart'; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1295 | 1295 |
| 1296 ir.Primitive visitSuperSend(ast.Send node) { | 1296 ir.Primitive visitSuperSend(ast.Send node) { |
| 1297 assert(isOpen); | 1297 assert(isOpen); |
| 1298 if (node.isPropertyAccess) { | 1298 if (node.isPropertyAccess) { |
| 1299 return visitGetterSend(node); | 1299 return visitGetterSend(node); |
| 1300 } else { | 1300 } else { |
| 1301 return visitDynamicSend(node); | 1301 return visitDynamicSend(node); |
| 1302 } | 1302 } |
| 1303 } | 1303 } |
| 1304 | 1304 |
| 1305 ir.Primitive visitTypeReferenceSend(ast.Send node) { | 1305 visitTypePrefixSend(ast.Send node) { |
| 1306 compiler.internalError(node, "visitTypePrefixSend should not be called."); | |
| 1307 } | |
| 1308 | |
| 1309 ir.Primitive visitTypeLiteralSend(ast.Send node) { | |
| 1306 assert(isOpen); | 1310 assert(isOpen); |
| 1307 Element element = elements[node]; | |
| 1308 assert(element is TypeDeclarationElement || element.isTypeVariable); | |
| 1309 | |
| 1310 // If the user is trying to invoke the type literal or variable, | 1311 // If the user is trying to invoke the type literal or variable, |
| 1311 // it must be treated as a function call. | 1312 // it must be treated as a function call. |
| 1312 if (node.argumentsNode != null) { | 1313 if (node.argumentsNode != null) { |
| 1314 // TODO(asgerf): Change this to match proposed semantics of issue #19725. | |
|
sigurdm
2014/07/01 09:39:55
Maybe this should not be assigned to asger as he i
Johnni Winther
2014/07/01 10:53:00
Assigned to you instead ;)
| |
| 1313 return visitDynamicSend(node); | 1315 return visitDynamicSend(node); |
| 1314 } | 1316 } |
| 1315 | 1317 |
| 1316 if (element is TypeDeclarationElement) { | 1318 DartType type = elements.getTypeLiteralType(node); |
| 1317 return translateConstant(node); | 1319 if (type is TypeVariableType) { |
| 1318 } else { | 1320 ir.Primitive prim = new ir.ReifyTypeVar(type.element); |
| 1319 ir.Primitive prim = new ir.ReifyTypeVar(element); | |
| 1320 add(new ir.LetPrim(prim)); | 1321 add(new ir.LetPrim(prim)); |
| 1321 return prim; | 1322 return prim; |
| 1323 } else { | |
| 1324 return translateConstant(node); | |
| 1322 } | 1325 } |
| 1323 } | 1326 } |
| 1324 | 1327 |
| 1325 ir.Primitive visitSendSet(ast.SendSet node) { | 1328 ir.Primitive visitSendSet(ast.SendSet node) { |
| 1326 assert(isOpen); | 1329 assert(isOpen); |
| 1327 Element element = elements[node]; | 1330 Element element = elements[node]; |
| 1328 ast.Operator op = node.assignmentOperator; | 1331 ast.Operator op = node.assignmentOperator; |
| 1329 // For complex operators, this is the result of getting (before assigning) | 1332 // For complex operators, this is the result of getting (before assigning) |
| 1330 ir.Primitive originalValue; | 1333 ir.Primitive originalValue; |
| 1331 // For []+= style operators, this saves the index. | 1334 // For []+= style operators, this saves the index. |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1590 } | 1593 } |
| 1591 if (Elements.isLocal(element) || | 1594 if (Elements.isLocal(element) || |
| 1592 Elements.isStaticOrTopLevelField(element)) { | 1595 Elements.isStaticOrTopLevelField(element)) { |
| 1593 // If the constant is small, inline it instead of using the declared const | 1596 // If the constant is small, inline it instead of using the declared const |
| 1594 Constant value = constantCompiler.getConstantForVariable(element); | 1597 Constant value = constantCompiler.getConstantForVariable(element); |
| 1595 if (isSmallConstant(value)) | 1598 if (isSmallConstant(value)) |
| 1596 return new PrimitiveConstExp(value); | 1599 return new PrimitiveConstExp(value); |
| 1597 else | 1600 else |
| 1598 return new VariableConstExp(element); | 1601 return new VariableConstExp(element); |
| 1599 } | 1602 } |
| 1600 if (Elements.isClass(element) || Elements.isTypedef(element)) { | 1603 DartType type = elements.getTypeLiteralType(node); |
| 1601 return new TypeConstExp(element); | 1604 if (type != null) { |
| 1605 return new TypeConstExp(type); | |
| 1602 } | 1606 } |
| 1603 throw "Unexpected constant Send: $node"; | 1607 throw "Unexpected constant Send: $node"; |
| 1604 } | 1608 } |
| 1605 | 1609 |
| 1606 ConstExp visitParenthesizedExpression(ast.ParenthesizedExpression node) { | 1610 ConstExp visitParenthesizedExpression(ast.ParenthesizedExpression node) { |
| 1607 return visit(node.expression); | 1611 return visit(node.expression); |
| 1608 } | 1612 } |
| 1609 | 1613 |
| 1610 ConstExp visitLiteralList(ast.LiteralList node) { | 1614 ConstExp visitLiteralList(ast.LiteralList node) { |
| 1611 List<ConstExp> values = node.elements.nodes.mapToList(visit); | 1615 List<ConstExp> values = node.elements.nodes.mapToList(visit); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1651 ConstExp visitConditional(ast.Conditional node) { | 1655 ConstExp visitConditional(ast.Conditional node) { |
| 1652 BoolConstant condition = computeConstant(node.condition); | 1656 BoolConstant condition = computeConstant(node.condition); |
| 1653 return visit(condition.isTrue ? node.thenExpression : node.elseExpression); | 1657 return visit(condition.isTrue ? node.thenExpression : node.elseExpression); |
| 1654 } | 1658 } |
| 1655 | 1659 |
| 1656 ConstExp visitNode(ast.Node node) { | 1660 ConstExp visitNode(ast.Node node) { |
| 1657 throw "Unexpected constant: $node"; | 1661 throw "Unexpected constant: $node"; |
| 1658 } | 1662 } |
| 1659 | 1663 |
| 1660 } | 1664 } |
| OLD | NEW |