From 4c5c41eb5cb4591b25f8a62432c84b4747f67c97 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Fri, 10 Apr 2020 22:22:45 +0200 Subject: [PATCH] add method name to the WasmException --- src/de/inetsoftware/jwebassembly/WasmException.java | 13 +++++++++++-- .../jwebassembly/module/BranchManger.java | 10 +++++----- .../jwebassembly/module/LocaleVariableManager.java | 2 +- .../jwebassembly/module/ModuleGenerator.java | 13 +++++++++---- .../jwebassembly/module/StaticCodeBuilder.java | 2 +- .../jwebassembly/module/WasmConstInstruction.java | 2 +- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/WasmException.java b/src/de/inetsoftware/jwebassembly/WasmException.java index 9c6d207..a15eb8d 100644 --- a/src/de/inetsoftware/jwebassembly/WasmException.java +++ b/src/de/inetsoftware/jwebassembly/WasmException.java @@ -29,6 +29,8 @@ public class WasmException extends RuntimeException { private String className; + private String methodName; + /** * Create a new instance. * @@ -94,7 +96,7 @@ public class WasmException extends RuntimeException { * @return a new instance */ public static WasmException create( Throwable cause, int lineNumber ) { - return create( cause, null, null, lineNumber ); + return create( cause, null, null, null, lineNumber ); } /** @@ -110,7 +112,7 @@ public class WasmException extends RuntimeException { * the line number in Java Code * @return a new instance */ - public static WasmException create( Throwable cause, String sourceFile, String className, int lineNumber ) { + public static WasmException create( Throwable cause, String sourceFile, String className, String methodName, int lineNumber ) { WasmException wasmEx = create( cause ); if( wasmEx.sourceFile == null ) { wasmEx.sourceFile = sourceFile; @@ -118,6 +120,9 @@ public class WasmException extends RuntimeException { if( wasmEx.className == null ) { wasmEx.className = className; } + if( wasmEx.methodName == null ) { + wasmEx.methodName = methodName; + } if( wasmEx.lineNumber < 0 ) { wasmEx.lineNumber = lineNumber; } @@ -173,6 +178,10 @@ public class WasmException extends RuntimeException { str += "\n\tat "; if( className != null ) { str += className.replace( '/', '.' ).replace( '$', '.' ); + str += '.'; + } + if( methodName != null ) { + str += methodName; } str += "("; str += (sourceFile != null ? sourceFile : "line"); diff --git a/src/de/inetsoftware/jwebassembly/module/BranchManger.java b/src/de/inetsoftware/jwebassembly/module/BranchManger.java index 76d9283..3427e9b 100644 --- a/src/de/inetsoftware/jwebassembly/module/BranchManger.java +++ b/src/de/inetsoftware/jwebassembly/module/BranchManger.java @@ -164,7 +164,7 @@ class BranchManger { loop.endPosition = parsedBlock.nextPosition; break; default: - throw new WasmException( "Unimplemented loop code operation: " + parsedBlock.op, null, null, parsedBlock.lineNumber ); + throw new WasmException( "Unimplemented loop code operation: " + parsedBlock.op, parsedBlock.lineNumber ); } } else { switch ( parsedBlock.op ) { @@ -285,7 +285,7 @@ class BranchManger { calculateTry( parent, (TryCatchParsedBlock)parsedBlock, parsedOperations ); break; default: - throw new WasmException( "Unimplemented block code operation: " + parsedBlock.op, null, null, parsedBlock.lineNumber ); + throw new WasmException( "Unimplemented block code operation: " + parsedBlock.op, parsedBlock.lineNumber ); } } } @@ -798,7 +798,7 @@ class BranchManger { return; } } - throw new WasmException( "GOTO code without target loop/block", null, null, gotoBlock.lineNumber ); + throw new WasmException( "GOTO code without target loop/block", gotoBlock.lineNumber ); } /** @@ -879,7 +879,7 @@ class BranchManger { if( parsedBlock.op == JavaBlockOperator.TRY ) { TryCatchFinally tryCatch2 = ((TryCatchParsedBlock)parsedBlock).tryCatch; if( tryCatch.getStart() == tryCatch2.getStart() && tryCatch.getEnd() == tryCatch2.getEnd() ) { - throw new WasmException( "Try with multiple catch blocks can't compile currently.", null, null, tryBlock.lineNumber ); + throw new WasmException( "Try with multiple catch blocks can't compile currently.", tryBlock.lineNumber ); } } @@ -1049,7 +1049,7 @@ class BranchManger { newOp = NumericOperator.ref_eq; break; default: - throw new WasmException( "Not a compare operation: " + instr.numOp, null, null, lineNumber ); + throw new WasmException( "Not a compare operation: " + instr.numOp, lineNumber ); } instr.numOp = newOp; } diff --git a/src/de/inetsoftware/jwebassembly/module/LocaleVariableManager.java b/src/de/inetsoftware/jwebassembly/module/LocaleVariableManager.java index 4e2b3b7..92c18a7 100644 --- a/src/de/inetsoftware/jwebassembly/module/LocaleVariableManager.java +++ b/src/de/inetsoftware/jwebassembly/module/LocaleVariableManager.java @@ -260,7 +260,7 @@ class LocaleVariableManager { var.startPos = javaCodePos; } else if( types.isFinish() ) { throw new WasmException( "Redefine local variable '" + var.name + "' type from " + var.valueType + " to " + valueType + " in slot " + var.idx - + ". Compile the Java code with debug information to correct this problem.", null, null, -1 ); + + ". Compile the Java code with debug information to correct this problem.", -1 ); } else { return; // in the scan phase not all types are known } diff --git a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java index 290b367..c3bd590 100644 --- a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java +++ b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java @@ -70,6 +70,8 @@ public class ModuleGenerator { private String className; + private String methodName; + private final FunctionManager functions; private final TypeManager types; @@ -196,6 +198,7 @@ public class ModuleGenerator { NEXT: while( (next = functions.nextScannLater()) != null ) { className = next.className; + methodName = next.methodName; JWebAssembly.LOGGER.fine( "scan " + next.signatureName ); if( next instanceof SyntheticFunctionName ) { SyntheticFunctionName synth = (SyntheticFunctionName)next; @@ -367,6 +370,7 @@ public class ModuleGenerator { FunctionName next = it.next(); sourceFile = null; // clear previous value for the case an IO exception occur className = next.className; + methodName = next.methodName; if( next instanceof SyntheticFunctionName ) { writeMethodImpl( next, ((SyntheticFunctionName)next).getCodeBuilder( watParser ) ); } else { @@ -393,7 +397,7 @@ public class ModuleGenerator { writeMethod( next, method ); } } catch (Throwable ex){ - throw WasmException.create( ex, sourceFile, className, -1 ); + throw WasmException.create( ex, sourceFile, className, methodName, -1 ); } } else { if( functions.needToWrite( next ) ) { @@ -427,7 +431,7 @@ public class ModuleGenerator { handler.accept( method ); } } catch( IOException ioex ) { - throw WasmException.create( ioex, sourceFile, className, -1 ); + throw WasmException.create( ioex, sourceFile, className, methodName, -1 ); } } @@ -442,6 +446,7 @@ public class ModuleGenerator { private void prepareMethod( MethodInfo method ) throws WasmException { try { FunctionName name = new FunctionName( method ); + methodName = name.methodName; if( functions.isKnown( name ) ) { return; } @@ -467,7 +472,7 @@ public class ModuleGenerator { return; } } catch( Exception ioex ) { - throw WasmException.create( ioex, sourceFile, className, -1 ); + throw WasmException.create( ioex, sourceFile, className, methodName, -1 ); } } @@ -540,7 +545,7 @@ public class ModuleGenerator { } } catch( Exception ioex ) { int lineNumber = code == null ? -1 : code.getFirstLineNr(); - throw WasmException.create( ioex, sourceFile, className, lineNumber ); + throw WasmException.create( ioex, sourceFile, className, methodName, lineNumber ); } } diff --git a/src/de/inetsoftware/jwebassembly/module/StaticCodeBuilder.java b/src/de/inetsoftware/jwebassembly/module/StaticCodeBuilder.java index a899d17..45751fe 100644 --- a/src/de/inetsoftware/jwebassembly/module/StaticCodeBuilder.java +++ b/src/de/inetsoftware/jwebassembly/module/StaticCodeBuilder.java @@ -150,7 +150,7 @@ class StaticCodeBuilder { } ); } } catch( IOException ex ) { - throw WasmException.create( ex, sourceFile, className, instr == null ? -1 : instr.getLineNumber() ); + throw WasmException.create( ex, sourceFile, className, name.methodName, instr == null ? -1 : instr.getLineNumber() ); } } diff --git a/src/de/inetsoftware/jwebassembly/module/WasmConstInstruction.java b/src/de/inetsoftware/jwebassembly/module/WasmConstInstruction.java index 8fdff86..0a177b3 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmConstInstruction.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmConstInstruction.java @@ -95,7 +95,7 @@ class WasmConstInstruction extends WasmInstruction { } else if( clazz == Double.class ) { return ValueType.f64; } else { - throw new WasmException( "Not supported constant type: " + clazz, null, null, -1 ); + throw new WasmException( "Not supported constant type: " + clazz, -1 ); } }