Wise exception propagation for inlines errors

This commit is contained in:
Mikhael Bogdanov
2013-12-02 17:18:03 +04:00
parent f475f3ba31
commit 769f559adf
3 changed files with 45 additions and 8 deletions
@@ -132,13 +132,13 @@ public class InlineCodegen implements ParentCodegenAware, CallGenerator {
throw e; throw e;
} }
catch (Exception e) { catch (Exception e) {
String text = getNodeText(node); boolean generateNodeText = !(e instanceof InlineException);
PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, this.codegen.getContext().getContextDescriptor()); PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, this.codegen.getContext().getContextDescriptor());
throw new CompilationException("Couldn't inline method call '" + throw new CompilationException("Couldn't inline method call '" +
functionDescriptor.getName() + functionDescriptor.getName() +
"' into \n" + (element != null ? element.getText() : "null psi element " + this.codegen.getContext().getContextDescriptor()) + "' into \n" + (element != null ? element.getText() : "null psi element " + this.codegen.getContext().getContextDescriptor()) +
"\ncause: " + (generateNodeText ? ("\ncause: " + getNodeText(node)) : ""),
text, e, call.getCallElement()); e, call.getCallElement());
} }
@@ -213,7 +213,7 @@ public class InlineCodegen implements ParentCodegenAware, CallGenerator {
codegen.getInlineNameGenerator().subGenerator(functionDescriptor.getName().asString()), codegen.getInlineNameGenerator().subGenerator(functionDescriptor.getName().asString()),
codegen.getContext(), call, Collections.<String, String>emptyMap(), false, false); codegen.getContext(), call, Collections.<String, String>emptyMap(), false, false);
MethodInliner inliner = new MethodInliner(node, parameters, info, new FieldRemapper(null, null, parameters), isSameModule, "InlineCodegenRoot " + call.getCallElement()); //with captured MethodInliner inliner = new MethodInliner(node, parameters, info, new FieldRemapper(null, null, parameters), isSameModule, "Method inlining " + call.getCallElement().getText()); //with captured
VarRemapper.ParamRemapper remapper = new VarRemapper.ParamRemapper(parameters, initialFrameSize); VarRemapper.ParamRemapper remapper = new VarRemapper.ParamRemapper(parameters, initialFrameSize);
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.codegen.inline;
public class InlineException extends RuntimeException {
public InlineException(String message) {
super(message);
}
public InlineException(String message, Throwable cause) {
super(message, cause);
}
}
@@ -94,9 +94,9 @@ public class MethodInliner {
transformedNode.accept(visitor); transformedNode.accept(visitor);
} }
catch (Exception e) { catch (Exception e) {
throw new RuntimeException(errorPrefix + ": couldn't inline method call " + transformedNode + "\ncause: " + throw wrapException(e, transformedNode, "couldn't inline method call");
InlineCodegen.getNodeText(transformedNode), e);
} }
visitor.visitLabel(end); visitor.visitLabel(end);
return result; return result;
@@ -277,8 +277,7 @@ public class MethodInliner {
sources = analyzer.analyze("fake", node); sources = analyzer.analyze("fake", node);
} }
catch (AnalyzerException e) { catch (AnalyzerException e) {
throw new RuntimeException("Couldn't inline method call " + node + "\ncause: " + throw wrapException(e, node, "couldn't inline method call");
InlineCodegen.getNodeText(node), e);
} }
AbstractInsnNode cur = node.instructions.getFirst(); AbstractInsnNode cur = node.instructions.getFirst();
@@ -482,4 +481,14 @@ public class MethodInliner {
} }
return type; return type;
} }
public RuntimeException wrapException(@NotNull Exception originalException, @NotNull MethodNode node, @NotNull String errorSuffix) {
if (originalException instanceof InlineException) {
return new InlineException(errorPrefix + ": " + errorSuffix, originalException);
} else {
return new InlineException(errorPrefix + ": " + errorSuffix + "\ncause: " +
InlineCodegen.getNodeText(node), originalException);
}
}
} }