mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
add method name to the WasmException
This commit is contained in:
parent
2f1c0f0706
commit
4c5c41eb5c
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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() );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user