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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 1355873003: Throw Error on unreachable code rather than a String. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 ssa; 5 part of ssa;
6 6
7 class SsaFunctionCompiler implements FunctionCompiler { 7 class SsaFunctionCompiler implements FunctionCompiler {
8 final SsaCodeGeneratorTask generator; 8 final SsaCodeGeneratorTask generator;
9 final SsaBuilderTask builder; 9 final SsaBuilderTask builder;
10 final SsaOptimizerTask optimizer; 10 final SsaOptimizerTask optimizer;
(...skipping 1614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 .buildImplicitReturn(functionElement))); 1625 .buildImplicitReturn(functionElement)));
1626 }, 1626 },
1627 visitElse: null, 1627 visitElse: null,
1628 sourceInformation: sourceInformationBuilder.buildIf(function.body)); 1628 sourceInformation: sourceInformationBuilder.buildIf(function.body));
1629 } 1629 }
1630 } 1630 }
1631 if (const bool.fromEnvironment('unreachable-throw') == true) { 1631 if (const bool.fromEnvironment('unreachable-throw') == true) {
1632 var emptyParameters = parameters.values.where((p) => 1632 var emptyParameters = parameters.values.where((p) =>
1633 p.instructionType.isEmpty && !p.instructionType.isNullable); 1633 p.instructionType.isEmpty && !p.instructionType.isNullable);
1634 if (emptyParameters.length > 0) { 1634 if (emptyParameters.length > 0) {
1635 String message = compiler.enableMinification 1635 addComment('${emptyParameters} inferred as [empty]');
1636 ? 'unreachable' 1636 pushInvokeStatic(function.body, backend.assertUnreachableMethod, []);
1637 : 'unreachable: ${functionElement} because: ${emptyParameters}'; 1637 pop();
1638 // TODO(sra): Use a library function that throws a proper error object.
1639 push(new HForeignCode(
1640 js.js.parseForeignJS('throw "$message"'),
1641 backend.dynamicType,
1642 <HInstruction>[],
1643 isStatement: true));
1644 return closeFunction(); 1638 return closeFunction();
1645 } 1639 }
1646 } 1640 }
1647 function.body.accept(this); 1641 function.body.accept(this);
1648 return closeFunction(); 1642 return closeFunction();
1649 } 1643 }
1650 1644
1645 /// Adds a JavaScript comment to the output. The comment will be omitted in
1646 /// minified mode. Each line in [text] is preceded with `//` and indented.
1647 /// Use sparingly. In order for the comment to be retained it is modeled as
1648 /// having side effects which will inhibit code motion.
1649 // TODO(sra): Figure out how to keep comment anchored without effects.
1650 void addComment(String text) {
1651 add(new HForeignCode(
1652 js.js.statementTemplateYielding(new js.Comment(text)),
1653 backend.dynamicType,
1654 <HInstruction>[],
1655 isStatement: true));
1656 }
1657
1651 HGraph buildCheckedSetter(VariableElement field) { 1658 HGraph buildCheckedSetter(VariableElement field) {
1652 openFunction(field, field.node); 1659 openFunction(field, field.node);
1653 HInstruction thisInstruction = localsHandler.readThis(); 1660 HInstruction thisInstruction = localsHandler.readThis();
1654 // Use dynamic type because the type computed by the inferrer is 1661 // Use dynamic type because the type computed by the inferrer is
1655 // narrowed to the type annotation. 1662 // narrowed to the type annotation.
1656 HInstruction parameter = new HParameterValue(field, backend.dynamicType); 1663 HInstruction parameter = new HParameterValue(field, backend.dynamicType);
1657 // Add the parameter as the last instruction of the entry block. 1664 // Add the parameter as the last instruction of the entry block.
1658 // If the method is intercepted, we want the actual receiver 1665 // If the method is intercepted, we want the actual receiver
1659 // to be the first parameter. 1666 // to be the first parameter.
1660 graph.entry.addBefore(graph.entry.last, parameter); 1667 graph.entry.addBefore(graph.entry.last, parameter);
(...skipping 7306 matching lines...) Expand 10 before | Expand all | Expand 10 after
8967 if (unaliased is TypedefType) throw 'unable to unalias $type'; 8974 if (unaliased is TypedefType) throw 'unable to unalias $type';
8968 unaliased.accept(this, builder); 8975 unaliased.accept(this, builder);
8969 } 8976 }
8970 8977
8971 void visitDynamicType(DynamicType type, SsaBuilder builder) { 8978 void visitDynamicType(DynamicType type, SsaBuilder builder) {
8972 JavaScriptBackend backend = builder.compiler.backend; 8979 JavaScriptBackend backend = builder.compiler.backend;
8973 ClassElement cls = backend.findHelper('DynamicRuntimeType'); 8980 ClassElement cls = backend.findHelper('DynamicRuntimeType');
8974 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); 8981 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld)));
8975 } 8982 }
8976 } 8983 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/type_variable_handler.dart ('k') | sdk/lib/_internal/js_runtime/lib/js_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698