 Chromium Code Reviews
 Chromium Code Reviews Issue 1342213003:
  Add optional message to assert in Dart2js - continued  (Closed) 
  Base URL: https://github.com/dart-lang/sdk.git@master
    
  
    Issue 1342213003:
  Add optional message to assert in Dart2js - continued  (Closed) 
  Base URL: https://github.com/dart-lang/sdk.git@master| OLD | NEW | 
|---|---|
| 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 2590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2601 void visit(ast.Node node) { | 2601 void visit(ast.Node node) { | 
| 2602 if (node != null) node.accept(this); | 2602 if (node != null) node.accept(this); | 
| 2603 } | 2603 } | 
| 2604 | 2604 | 
| 2605 /// Visit [node] and pop the resulting [HInstruction]. | 2605 /// Visit [node] and pop the resulting [HInstruction]. | 
| 2606 HInstruction visitAndPop(ast.Node node) { | 2606 HInstruction visitAndPop(ast.Node node) { | 
| 2607 node.accept(this); | 2607 node.accept(this); | 
| 2608 return pop(); | 2608 return pop(); | 
| 2609 } | 2609 } | 
| 2610 | 2610 | 
| 2611 visitAssert(ast.Assert node) { | |
| 2612 if (!compiler.enableUserAssertions) return; | |
| 2613 | |
| 2614 if (!node.hasMessage) { | |
| 
Lasse Reichstein Nielsen
2015/09/16 06:00:56
Document that this does
  assertHelper(condition);
 
sra1
2015/09/17 03:47:54
Done.
 | |
| 2615 visit(node.condition); | |
| 2616 pushInvokeStatic(node, backend.assertHelperMethod, [pop()]); | |
| 2617 pop(); | |
| 2618 return; | |
| 2619 } | |
| 2620 // Assert has message. Generate: | |
| 2621 // | |
| 2622 // if (assertTest(condition)) assertThrow(message); | |
| 2623 // | |
| 2624 void buildCondition() { | |
| 2625 visit(node.condition); | |
| 2626 pushInvokeStatic(node, backend.assertTestMethod, [pop()]); | |
| 2627 } | |
| 2628 void fail() { | |
| 2629 visit(node.message); | |
| 2630 pushInvokeStatic(node, backend.assertThrowMethod, [pop()]); | |
| 2631 pop(); | |
| 2632 } | |
| 2633 handleIf(node, | |
| 2634 visitCondition: buildCondition, | |
| 2635 visitThen: fail); | |
| 2636 } | |
| 2637 | |
| 2611 visitBlock(ast.Block node) { | 2638 visitBlock(ast.Block node) { | 
| 2612 assert(!isAborted()); | 2639 assert(!isAborted()); | 
| 2613 if (!isReachable) return; // This can only happen when inlining. | 2640 if (!isReachable) return; // This can only happen when inlining. | 
| 2614 for (Link<ast.Node> link = node.statements.nodes; | 2641 for (Link<ast.Node> link = node.statements.nodes; | 
| 2615 !link.isEmpty; | 2642 !link.isEmpty; | 
| 2616 link = link.tail) { | 2643 link = link.tail) { | 
| 2617 visit(link.head); | 2644 visit(link.head); | 
| 2618 if (!isReachable) { | 2645 if (!isReachable) { | 
| 2619 // The block has been aborted by a return or a throw. | 2646 // The block has been aborted by a return or a throw. | 
| 2620 if (!stack.isEmpty) { | 2647 if (!stack.isEmpty) { | 
| (...skipping 2555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5176 DartType instance = type.asInstanceOf(supertype.element); | 5203 DartType instance = type.asInstanceOf(supertype.element); | 
| 5177 compiler.types.checkTypeVariableBounds(instance, | 5204 compiler.types.checkTypeVariableBounds(instance, | 
| 5178 addTypeVariableBoundCheck); | 5205 addTypeVariableBoundCheck); | 
| 5179 if (definitelyFails) { | 5206 if (definitelyFails) { | 
| 5180 return true; | 5207 return true; | 
| 5181 } | 5208 } | 
| 5182 } | 5209 } | 
| 5183 return false; | 5210 return false; | 
| 5184 } | 5211 } | 
| 5185 | 5212 | 
| 5186 @override | |
| 5187 visitAssert(ast.Send node, ast.Node expression, _) { | |
| 5188 if (!compiler.enableUserAssertions) { | |
| 5189 stack.add(graph.addConstantNull(compiler)); | |
| 5190 return; | |
| 5191 } | |
| 5192 assert(invariant(node, node.arguments.tail.isEmpty, | |
| 5193 message: "Invalid assertion: $node")); | |
| 5194 generateStaticFunctionInvoke( | |
| 5195 node, backend.assertMethod, CallStructure.ONE_ARG); | |
| 5196 } | |
| 5197 | |
| 5198 visitStaticSend(ast.Send node) { | 5213 visitStaticSend(ast.Send node) { | 
| 5199 internalError(node, "Unexpected visitStaticSend"); | 5214 internalError(node, "Unexpected visitStaticSend"); | 
| 5200 } | 5215 } | 
| 5201 | 5216 | 
| 5202 /// Generate an invocation to the static or top level [function]. | 5217 /// Generate an invocation to the static or top level [function]. | 
| 5203 void generateStaticFunctionInvoke( | 5218 void generateStaticFunctionInvoke( | 
| 5204 ast.Send node, | 5219 ast.Send node, | 
| 5205 FunctionElement function, | 5220 FunctionElement function, | 
| 5206 CallStructure callStructure) { | 5221 CallStructure callStructure) { | 
| 5207 List<HInstruction> inputs = makeStaticArgumentList( | 5222 List<HInstruction> inputs = makeStaticArgumentList( | 
| (...skipping 3096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8304 void visitConstantInvoke( | 8319 void visitConstantInvoke( | 
| 8305 ast.Send node, | 8320 ast.Send node, | 
| 8306 ConstantExpression constant, | 8321 ConstantExpression constant, | 
| 8307 ast.NodeList arguments, | 8322 ast.NodeList arguments, | 
| 8308 CallStructure callStreucture, | 8323 CallStructure callStreucture, | 
| 8309 _) { | 8324 _) { | 
| 8310 visitNode(node); | 8325 visitNode(node); | 
| 8311 } | 8326 } | 
| 8312 | 8327 | 
| 8313 @override | 8328 @override | 
| 8314 void errorInvalidAssert( | |
| 8315 ast.Send node, | |
| 8316 ast.NodeList arguments, | |
| 8317 _) { | |
| 8318 visitNode(node); | |
| 8319 } | |
| 8320 | |
| 8321 @override | |
| 8322 void errorUndefinedBinaryExpression( | 8329 void errorUndefinedBinaryExpression( | 
| 8323 ast.Send node, | 8330 ast.Send node, | 
| 8324 ast.Node left, | 8331 ast.Node left, | 
| 8325 ast.Operator operator, | 8332 ast.Operator operator, | 
| 8326 ast.Node right, | 8333 ast.Node right, | 
| 8327 _) { | 8334 _) { | 
| 8328 visitNode(node); | 8335 visitNode(node); | 
| 8329 } | 8336 } | 
| 8330 | 8337 | 
| 8331 @override | 8338 @override | 
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8940 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 8947 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 
| 8941 unaliased.accept(this, builder); | 8948 unaliased.accept(this, builder); | 
| 8942 } | 8949 } | 
| 8943 | 8950 | 
| 8944 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 8951 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 
| 8945 JavaScriptBackend backend = builder.compiler.backend; | 8952 JavaScriptBackend backend = builder.compiler.backend; | 
| 8946 ClassElement cls = backend.findHelper('DynamicRuntimeType'); | 8953 ClassElement cls = backend.findHelper('DynamicRuntimeType'); | 
| 8947 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 8954 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 
| 8948 } | 8955 } | 
| 8949 } | 8956 } | 
| OLD | NEW |