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

Side by Side Diff: frog/leg/ssa/builder.dart

Issue 9601014: Support for stack traces in catch blocks. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
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 class Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return compiler.findHelper(const SourceString('indexSet')); 86 return compiler.findHelper(const SourceString('indexSet'));
87 } 87 }
88 88
89 Element getEqualsNullInterceptor() { 89 Element getEqualsNullInterceptor() {
90 return compiler.findHelper(const SourceString('eqNull')); 90 return compiler.findHelper(const SourceString('eqNull'));
91 } 91 }
92 92
93 Element getExceptionUnwrapper() { 93 Element getExceptionUnwrapper() {
94 return compiler.findHelper(const SourceString('unwrapException')); 94 return compiler.findHelper(const SourceString('unwrapException'));
95 } 95 }
96
97 Element getTraceFromException() {
98 return compiler.findHelper(const SourceString('getTraceFromException'));
99 }
96 } 100 }
97 101
98 class SsaBuilderTask extends CompilerTask { 102 class SsaBuilderTask extends CompilerTask {
99 SsaBuilderTask(Compiler compiler) 103 SsaBuilderTask(Compiler compiler)
100 : super(compiler), interceptors = new Interceptors(compiler); 104 : super(compiler), interceptors = new Interceptors(compiler);
101 String get name() => 'SSA builder'; 105 String get name() => 'SSA builder';
102 Interceptors interceptors; 106 Interceptors interceptors;
103 107
104 HGraph build(WorkItem work) { 108 HGraph build(WorkItem work) {
105 return measure(() { 109 return measure(() {
(...skipping 2255 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 // Note that the name of this element is irrelevant. 2365 // Note that the name of this element is irrelevant.
2362 Element element = new Element( 2366 Element element = new Element(
2363 const SourceString('exception'), ElementKind.PARAMETER, work.element); 2367 const SourceString('exception'), ElementKind.PARAMETER, work.element);
2364 HParameterValue exception = new HParameterValue(element); 2368 HParameterValue exception = new HParameterValue(element);
2365 add(exception); 2369 add(exception);
2366 HInstruction oldRethrowableException = rethrowableException; 2370 HInstruction oldRethrowableException = rethrowableException;
2367 rethrowableException = exception; 2371 rethrowableException = exception;
2368 push(new HStatic(interceptors.getExceptionUnwrapper())); 2372 push(new HStatic(interceptors.getExceptionUnwrapper()));
2369 List<HInstruction> inputs = <HInstruction>[pop(), exception]; 2373 List<HInstruction> inputs = <HInstruction>[pop(), exception];
2370 HInvokeStatic unwrappedException = 2374 HInvokeStatic unwrappedException =
2371 new HInvokeStatic(Selector.INVOCATION_1, inputs); 2375 new HInvokeStatic(Selector.INVOCATION_1, inputs);
2372 add(unwrappedException); 2376 add(unwrappedException);
2373 2377
2374 tryInstruction.exception = exception; 2378 tryInstruction.exception = exception;
2379
2380 bool requiresTrace = false;
2381 for (CatchBlock block in node.catchBlocks) {
2382 if (block.trace != null) {
2383 requiresTrace = true;
2384 break;
2385 }
2386 }
2387
2388 HInstruction traceInstruction = null;
ahe 2012/03/06 12:24:07 This is unused.
ngeoffray 2012/03/06 12:29:40 Done.
2389 if (requiresTrace) {
ahe 2012/03/06 12:24:07 Remove this.
ngeoffray 2012/03/06 12:29:40 Done.
2390 }
2391
2375 Link<Node> link = node.catchBlocks.nodes; 2392 Link<Node> link = node.catchBlocks.nodes;
2376 2393
2377 void pushCondition(CatchBlock catchBlock) { 2394 void pushCondition(CatchBlock catchBlock) {
2378 VariableDefinitions declaration = catchBlock.formals.nodes.head; 2395 VariableDefinitions declaration = catchBlock.formals.nodes.head;
2379 HInstruction condition = null; 2396 HInstruction condition = null;
2380 if (declaration.type == null) { 2397 if (declaration.type == null) {
2381 condition = graph.addNewLiteralTrue(); 2398 condition = graph.addNewLiteralTrue();
2382 stack.add(condition); 2399 stack.add(condition);
2383 } else { 2400 } else {
2384 Element typeElement = elements[declaration.type]; 2401 Element typeElement = elements[declaration.type];
2385 if (typeElement == null) { 2402 if (typeElement == null) {
2386 compiler.cancel('Catch with unresolved type', node: catchBlock); 2403 compiler.cancel('Catch with unresolved type', node: catchBlock);
2387 } 2404 }
2388 condition = new HIs(typeElement, unwrappedException, nullOk: true); 2405 condition = new HIs(typeElement, unwrappedException, nullOk: true);
2389 push(condition); 2406 push(condition);
2390 } 2407 }
2391 } 2408 }
2392 2409
2393 void visitThen() { 2410 void visitThen() {
2394 CatchBlock catchBlock = link.head; 2411 CatchBlock catchBlock = link.head;
2395 link = link.tail; 2412 link = link.tail;
2396 VariableDefinitions declaration = catchBlock.formals.nodes.head; 2413 localsHandler.updateLocal(elements[catchBlock.exception],
2397 localsHandler.updateLocal(elements[declaration.definitions.nodes.head],
2398 unwrappedException); 2414 unwrappedException);
2415 Node trace = catchBlock.trace;
2416 if (trace != null) {
2417 push(new HStatic(interceptors.getTraceFromException()));
2418 HInstruction traceInstruction = new HInvokeStatic(
2419 Selector.INVOCATION_1, <HInstruction>[pop(), exception]);
2420 add(traceInstruction);
2421 localsHandler.updateLocal(elements[trace], traceInstruction);
2422 }
2399 visit(catchBlock); 2423 visit(catchBlock);
2400 } 2424 }
2401 2425
2402 void visitElse() { 2426 void visitElse() {
2403 if (link.isEmpty()) { 2427 if (link.isEmpty()) {
2404 close(new HThrow(exception, isRethrow: true)); 2428 close(new HThrow(exception, isRethrow: true));
2405 } else { 2429 } else {
2406 CatchBlock newBlock = link.head; 2430 CatchBlock newBlock = link.head;
2407 pushCondition(newBlock); 2431 pushCondition(newBlock);
2408 handleIf(visitThen, visitElse); 2432 handleIf(visitThen, visitElse);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 // Normally, we would call [close] here. However, then we hit 2477 // Normally, we would call [close] here. However, then we hit
2454 // another unimplemented feature: aborting loop body. Simply 2478 // another unimplemented feature: aborting loop body. Simply
2455 // calling [add] does not work as it asserts that the instruction 2479 // calling [add] does not work as it asserts that the instruction
2456 // isn't a control flow instruction. So we inline parts of [add]. 2480 // isn't a control flow instruction. So we inline parts of [add].
2457 current.addAfter(current.last, new HThrow(message)); 2481 current.addAfter(current.last, new HThrow(message));
2458 if (isExpression) { 2482 if (isExpression) {
2459 stack.add(graph.addNewLiteralNull()); 2483 stack.add(graph.addNewLiteralNull());
2460 } 2484 }
2461 } 2485 }
2462 } 2486 }
OLDNEW
« no previous file with comments | « frog/leg/lib/js_helper.dart ('k') | frog/leg/ssa/codegen.dart » ('j') | frog/leg/tree/nodes.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698