Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: lib/src/codegen/js_codegen.dart

Issue 1062823004: Fix a couple codegen crashers (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Address comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/codegen/cascade.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, HashMap; 7 import 'dart:collection' show HashSet, HashMap;
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 1742 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 if (expr is IndexExpression) { 1753 if (expr is IndexExpression) {
1754 IndexExpression index = expr; 1754 IndexExpression index = expr;
1755 return new IndexExpression.forTarget( 1755 return new IndexExpression.forTarget(
1756 _bindValue(scope, 'o', index.target, context: context), 1756 _bindValue(scope, 'o', index.target, context: context),
1757 index.leftBracket, 1757 index.leftBracket,
1758 _bindValue(scope, 'i', index.index, context: context), 1758 _bindValue(scope, 'i', index.index, context: context),
1759 index.rightBracket)..staticType = expr.staticType; 1759 index.rightBracket)..staticType = expr.staticType;
1760 } else if (expr is PropertyAccess) { 1760 } else if (expr is PropertyAccess) {
1761 PropertyAccess prop = expr; 1761 PropertyAccess prop = expr;
1762 return new PropertyAccess( 1762 return new PropertyAccess(
1763 _bindValue(scope, 'o', prop.target, context: context), prop.operator, 1763 _bindValue(scope, 'o', _getTarget(prop), context: context),
1764 prop.propertyName)..staticType = expr.staticType; 1764 prop.operator, prop.propertyName)..staticType = expr.staticType;
1765 } else if (expr is PrefixedIdentifier) { 1765 } else if (expr is PrefixedIdentifier) {
1766 PrefixedIdentifier ident = expr; 1766 PrefixedIdentifier ident = expr;
1767 return new PrefixedIdentifier( 1767 return new PrefixedIdentifier(
1768 _bindValue(scope, 'o', ident.prefix, context: context), ident.period, 1768 _bindValue(scope, 'o', ident.prefix, context: context), ident.period,
1769 ident.identifier)..staticType = expr.staticType; 1769 ident.identifier)..staticType = expr.staticType;
1770 } 1770 }
1771 return expr as SimpleIdentifier; 1771 return expr as SimpleIdentifier;
1772 } 1772 }
1773 1773
1774 /// Creates a temporary to contain the value of [expr]. The temporary can be 1774 /// Creates a temporary to contain the value of [expr]. The temporary can be
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 _visit(node.finallyBlock)); 2015 _visit(node.finallyBlock));
2016 } 2016 }
2017 2017
2018 _visitCatch(NodeList<CatchClause> clauses) { 2018 _visitCatch(NodeList<CatchClause> clauses) {
2019 if (clauses == null || clauses.isEmpty) return null; 2019 if (clauses == null || clauses.isEmpty) return null;
2020 2020
2021 // TODO(jmesserly): need a better way to get a temporary variable. 2021 // TODO(jmesserly): need a better way to get a temporary variable.
2022 // This could incorrectly shadow a user's name. 2022 // This could incorrectly shadow a user's name.
2023 var savedCatch = _catchParameter; 2023 var savedCatch = _catchParameter;
2024 2024
2025 if (clauses.length == 1) { 2025 if (clauses.length == 1 && clauses.single.exceptionParameter != null) {
2026 // Special case for a single catch. 2026 // Special case for a single catch.
2027 _catchParameter = clauses.single.exceptionParameter; 2027 _catchParameter = clauses.single.exceptionParameter;
2028 } else { 2028 } else {
2029 _catchParameter = _createTemporary('e', rules.provider.dynamicType); 2029 _catchParameter = _createTemporary('e', rules.provider.dynamicType);
2030 } 2030 }
2031 2031
2032 JS.Statement catchBody = null; 2032 JS.Statement catchBody = js.statement('throw #;', _visit(_catchParameter));
2033 for (var clause in clauses.reversed) { 2033 for (var clause in clauses.reversed) {
2034 catchBody = _catchClauseGuard(clause, catchBody); 2034 catchBody = _catchClauseGuard(clause, catchBody);
2035 } 2035 }
2036 2036
2037 var catchVarDecl = _visit(_catchParameter); 2037 var catchVarDecl = _visit(_catchParameter);
2038 _catchParameter = savedCatch; 2038 _catchParameter = savedCatch;
2039 return new JS.Catch(catchVarDecl, new JS.Block([catchBody])); 2039 return new JS.Catch(catchVarDecl, new JS.Block([catchBody]));
2040 } 2040 }
2041 2041
2042 JS.Statement _catchClauseGuard(CatchClause clause, JS.Statement otherwise) { 2042 JS.Statement _catchClauseGuard(CatchClause clause, JS.Statement otherwise) {
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
2569 if (parent is MethodInvocation && 2569 if (parent is MethodInvocation &&
2570 identical(parent.methodName, node)) return; 2570 identical(parent.methodName, node)) return;
2571 if (parent is ConstructorName) return; 2571 if (parent is ConstructorName) return;
2572 if (parent is Label) return; 2572 if (parent is Label) return;
2573 2573
2574 if (node.inSetterContext() && node.staticElement == _variable) { 2574 if (node.inSetterContext() && node.staticElement == _variable) {
2575 _potentiallyMutated = true; 2575 _potentiallyMutated = true;
2576 } 2576 }
2577 } 2577 }
2578 } 2578 }
OLDNEW
« no previous file with comments | « no previous file | test/codegen/cascade.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698