Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dev_compiler.src.codegen.js_codegen; | 5 library dev_compiler.src.codegen.js_codegen; |
| 6 | 6 |
| 7 import 'dart:collection' show HashSet; | 7 import 'dart:collection' show HashSet; |
| 8 import 'dart:io' show Directory, File; | 8 import 'dart:io' show Directory, File; |
| 9 | 9 |
| 10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
| (...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1234 return js.call('#$op', _visit(expr)); | 1234 return js.call('#$op', _visit(expr)); |
| 1235 } | 1235 } |
| 1236 } | 1236 } |
| 1237 | 1237 |
| 1238 assert(op.lexeme == '++' || op.lexeme == '--'); | 1238 assert(op.lexeme == '++' || op.lexeme == '--'); |
| 1239 return _emitPostfixIncrement(expr, op); | 1239 return _emitPostfixIncrement(expr, op); |
| 1240 } | 1240 } |
| 1241 | 1241 |
| 1242 JS.Expression _emitPrefixIncrement(Token op, Expression expr) { | 1242 JS.Expression _emitPrefixIncrement(Token op, Expression expr) { |
| 1243 var one = AstBuilder.integerLiteral(1); | 1243 var one = AstBuilder.integerLiteral(1); |
| 1244 one.staticType = rules.provider.intType; | |
| 1244 var increment = AstBuilder.binaryExpression(expr, op.lexeme[0], one); | 1245 var increment = AstBuilder.binaryExpression(expr, op.lexeme[0], one); |
| 1245 return _emitAssignment(expr, increment); | 1246 return _emitAssignment(expr, increment); |
| 1246 } | 1247 } |
| 1247 | 1248 |
| 1248 @override | 1249 @override |
| 1249 JS.Expression visitPrefixExpression(PrefixExpression node) { | 1250 JS.Expression visitPrefixExpression(PrefixExpression node) { |
| 1250 return _emitPrefixExpression(node.operator, node.operand); | 1251 return _emitPrefixExpression(node.operator, node.operand); |
| 1251 } | 1252 } |
| 1252 | 1253 |
| 1253 JS.Expression _emitPrefixExpression(Token op, Expression expr) { | 1254 JS.Expression _emitPrefixExpression(Token op, Expression expr) { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1509 | 1510 |
| 1510 if (clauses.length == 1) { | 1511 if (clauses.length == 1) { |
| 1511 // Special case for a single catch. | 1512 // Special case for a single catch. |
| 1512 var clause = clauses.single; | 1513 var clause = clauses.single; |
| 1513 if (clause.exceptionParameter != null) { | 1514 if (clause.exceptionParameter != null) { |
| 1514 _catchParameter = clause.exceptionParameter.name; | 1515 _catchParameter = clause.exceptionParameter.name; |
| 1515 } | 1516 } |
| 1516 } | 1517 } |
| 1517 | 1518 |
| 1518 var catchVarDecl = new JS.VariableDeclaration(_catchParameter); | 1519 var catchVarDecl = new JS.VariableDeclaration(_catchParameter); |
| 1519 var catchBody = _statement(_visitList(clauses)); | 1520 var catchBody = new JS.Block(_visitList(clauses)); |
|
vsm
2015/03/10 13:34:47
The js ast code asserts this is a block.
Jennifer Messerly
2015/03/10 15:04:08
funny! we must've only hit the code path for >2 st
| |
| 1520 _catchParameter = savedCatch; | 1521 _catchParameter = savedCatch; |
| 1521 | 1522 |
| 1522 return new JS.Catch(catchVarDecl, catchBody); | 1523 return new JS.Catch(catchVarDecl, catchBody); |
| 1523 } | 1524 } |
| 1524 | 1525 |
| 1525 JS.Statement _statement(Iterable stmts) { | 1526 JS.Statement _statement(Iterable stmts) { |
| 1526 var s = stmts is List ? stmts : new List<JS.Statement>.from(stmts); | 1527 var s = stmts is List ? stmts : new List<JS.Statement>.from(stmts); |
| 1527 // TODO(jmesserly): empty block singleton? | 1528 // TODO(jmesserly): empty block singleton? |
| 1528 if (s.length == 0) return new JS.Block([]); | 1529 if (s.length == 0) return new JS.Block([]); |
| 1529 if (s.length == 1) return s[0]; | 1530 if (s.length == 1) return s[0]; |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2034 | 2035 |
| 2035 // TODO(jmesserly): in many cases marking the end will be unncessary. | 2036 // TODO(jmesserly): in many cases marking the end will be unncessary. |
| 2036 printer.mark(_location(node.end)); | 2037 printer.mark(_location(node.end)); |
| 2037 } | 2038 } |
| 2038 | 2039 |
| 2039 String _getIdentifier(AstNode node) { | 2040 String _getIdentifier(AstNode node) { |
| 2040 if (node is SimpleIdentifier) return node.name; | 2041 if (node is SimpleIdentifier) return node.name; |
| 2041 return null; | 2042 return null; |
| 2042 } | 2043 } |
| 2043 } | 2044 } |
| OLD | NEW |