mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +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 className;
|
||||||
|
|
||||||
|
private String methodName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*
|
*
|
||||||
@ -94,7 +96,7 @@ public class WasmException extends RuntimeException {
|
|||||||
* @return a new instance
|
* @return a new instance
|
||||||
*/
|
*/
|
||||||
public static WasmException create( Throwable cause, int lineNumber ) {
|
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
|
* the line number in Java Code
|
||||||
* @return a new instance
|
* @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 );
|
WasmException wasmEx = create( cause );
|
||||||
if( wasmEx.sourceFile == null ) {
|
if( wasmEx.sourceFile == null ) {
|
||||||
wasmEx.sourceFile = sourceFile;
|
wasmEx.sourceFile = sourceFile;
|
||||||
@ -118,6 +120,9 @@ public class WasmException extends RuntimeException {
|
|||||||
if( wasmEx.className == null ) {
|
if( wasmEx.className == null ) {
|
||||||
wasmEx.className = className;
|
wasmEx.className = className;
|
||||||
}
|
}
|
||||||
|
if( wasmEx.methodName == null ) {
|
||||||
|
wasmEx.methodName = methodName;
|
||||||
|
}
|
||||||
if( wasmEx.lineNumber < 0 ) {
|
if( wasmEx.lineNumber < 0 ) {
|
||||||
wasmEx.lineNumber = lineNumber;
|
wasmEx.lineNumber = lineNumber;
|
||||||
}
|
}
|
||||||
@ -173,6 +178,10 @@ public class WasmException extends RuntimeException {
|
|||||||
str += "\n\tat ";
|
str += "\n\tat ";
|
||||||
if( className != null ) {
|
if( className != null ) {
|
||||||
str += className.replace( '/', '.' ).replace( '$', '.' );
|
str += className.replace( '/', '.' ).replace( '$', '.' );
|
||||||
|
str += '.';
|
||||||
|
}
|
||||||
|
if( methodName != null ) {
|
||||||
|
str += methodName;
|
||||||
}
|
}
|
||||||
str += "(";
|
str += "(";
|
||||||
str += (sourceFile != null ? sourceFile : "line");
|
str += (sourceFile != null ? sourceFile : "line");
|
||||||
|
@ -164,7 +164,7 @@ class BranchManger {
|
|||||||
loop.endPosition = parsedBlock.nextPosition;
|
loop.endPosition = parsedBlock.nextPosition;
|
||||||
break;
|
break;
|
||||||
default:
|
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 {
|
} else {
|
||||||
switch ( parsedBlock.op ) {
|
switch ( parsedBlock.op ) {
|
||||||
@ -285,7 +285,7 @@ class BranchManger {
|
|||||||
calculateTry( parent, (TryCatchParsedBlock)parsedBlock, parsedOperations );
|
calculateTry( parent, (TryCatchParsedBlock)parsedBlock, parsedOperations );
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
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 ) {
|
if( parsedBlock.op == JavaBlockOperator.TRY ) {
|
||||||
TryCatchFinally tryCatch2 = ((TryCatchParsedBlock)parsedBlock).tryCatch;
|
TryCatchFinally tryCatch2 = ((TryCatchParsedBlock)parsedBlock).tryCatch;
|
||||||
if( tryCatch.getStart() == tryCatch2.getStart() && tryCatch.getEnd() == tryCatch2.getEnd() ) {
|
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;
|
newOp = NumericOperator.ref_eq;
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
instr.numOp = newOp;
|
||||||
}
|
}
|
||||||
|
@ -260,7 +260,7 @@ class LocaleVariableManager {
|
|||||||
var.startPos = javaCodePos;
|
var.startPos = javaCodePos;
|
||||||
} else if( types.isFinish() ) {
|
} else if( types.isFinish() ) {
|
||||||
throw new WasmException( "Redefine local variable '" + var.name + "' type from " + var.valueType + " to " + valueType + " in slot " + var.idx
|
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 {
|
} else {
|
||||||
return; // in the scan phase not all types are known
|
return; // in the scan phase not all types are known
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,8 @@ public class ModuleGenerator {
|
|||||||
|
|
||||||
private String className;
|
private String className;
|
||||||
|
|
||||||
|
private String methodName;
|
||||||
|
|
||||||
private final FunctionManager functions;
|
private final FunctionManager functions;
|
||||||
|
|
||||||
private final TypeManager types;
|
private final TypeManager types;
|
||||||
@ -196,6 +198,7 @@ public class ModuleGenerator {
|
|||||||
NEXT:
|
NEXT:
|
||||||
while( (next = functions.nextScannLater()) != null ) {
|
while( (next = functions.nextScannLater()) != null ) {
|
||||||
className = next.className;
|
className = next.className;
|
||||||
|
methodName = next.methodName;
|
||||||
JWebAssembly.LOGGER.fine( "scan " + next.signatureName );
|
JWebAssembly.LOGGER.fine( "scan " + next.signatureName );
|
||||||
if( next instanceof SyntheticFunctionName ) {
|
if( next instanceof SyntheticFunctionName ) {
|
||||||
SyntheticFunctionName synth = (SyntheticFunctionName)next;
|
SyntheticFunctionName synth = (SyntheticFunctionName)next;
|
||||||
@ -367,6 +370,7 @@ public class ModuleGenerator {
|
|||||||
FunctionName next = it.next();
|
FunctionName next = it.next();
|
||||||
sourceFile = null; // clear previous value for the case an IO exception occur
|
sourceFile = null; // clear previous value for the case an IO exception occur
|
||||||
className = next.className;
|
className = next.className;
|
||||||
|
methodName = next.methodName;
|
||||||
if( next instanceof SyntheticFunctionName ) {
|
if( next instanceof SyntheticFunctionName ) {
|
||||||
writeMethodImpl( next, ((SyntheticFunctionName)next).getCodeBuilder( watParser ) );
|
writeMethodImpl( next, ((SyntheticFunctionName)next).getCodeBuilder( watParser ) );
|
||||||
} else {
|
} else {
|
||||||
@ -393,7 +397,7 @@ public class ModuleGenerator {
|
|||||||
writeMethod( next, method );
|
writeMethod( next, method );
|
||||||
}
|
}
|
||||||
} catch (Throwable ex){
|
} catch (Throwable ex){
|
||||||
throw WasmException.create( ex, sourceFile, className, -1 );
|
throw WasmException.create( ex, sourceFile, className, methodName, -1 );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if( functions.needToWrite( next ) ) {
|
if( functions.needToWrite( next ) ) {
|
||||||
@ -427,7 +431,7 @@ public class ModuleGenerator {
|
|||||||
handler.accept( method );
|
handler.accept( method );
|
||||||
}
|
}
|
||||||
} catch( IOException ioex ) {
|
} 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 {
|
private void prepareMethod( MethodInfo method ) throws WasmException {
|
||||||
try {
|
try {
|
||||||
FunctionName name = new FunctionName( method );
|
FunctionName name = new FunctionName( method );
|
||||||
|
methodName = name.methodName;
|
||||||
if( functions.isKnown( name ) ) {
|
if( functions.isKnown( name ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -467,7 +472,7 @@ public class ModuleGenerator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch( Exception ioex ) {
|
} 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 ) {
|
} catch( Exception ioex ) {
|
||||||
int lineNumber = code == null ? -1 : code.getFirstLineNr();
|
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 ) {
|
} 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 ) {
|
} else if( clazz == Double.class ) {
|
||||||
return ValueType.f64;
|
return ValueType.f64;
|
||||||
} else {
|
} 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