mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +01:00
Convert ValueTypeParser to an Iterator
This commit is contained in:
parent
1376af2f3f
commit
b677355c0f
@ -20,6 +20,7 @@ import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
@ -354,10 +355,10 @@ public class ModuleGenerator {
|
||||
if( !isStatic ) {
|
||||
writer.writeMethodParam( "param", ValueType.anyref, "this" );
|
||||
}
|
||||
ValueTypeParser parser = new ValueTypeParser( signature );
|
||||
Iterator<AnyType> parser = new ValueTypeParser( signature );
|
||||
AnyType type;
|
||||
for( String kind : new String[] {"param","result"}) {
|
||||
while( (type = parser.next()) != null ) {
|
||||
while( parser.hasNext() && (type = parser.next()) != null ) {
|
||||
String paramName = null;
|
||||
if( kind == "param" ) {
|
||||
if( variables != null ) {
|
||||
|
@ -17,10 +17,12 @@
|
||||
package de.inetsoftware.jwebassembly.module;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.classparser.Member;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueTypeParser;
|
||||
|
||||
@ -103,15 +105,14 @@ class WasmCallInstruction extends WasmInstruction {
|
||||
if( paramCount >= 0 ) {
|
||||
return;
|
||||
}
|
||||
ValueTypeParser parser = new ValueTypeParser( method.getType() );
|
||||
Iterator<AnyType> parser = new ValueTypeParser( method.getType() );
|
||||
paramCount = 0;
|
||||
while( parser.next() != null ) {
|
||||
paramCount++;
|
||||
}
|
||||
valueType = (ValueType)parser.next();
|
||||
ValueType type;
|
||||
while( (type = (ValueType)parser.next()) != null ) {
|
||||
valueType = type;
|
||||
while( parser.hasNext() ) {
|
||||
valueType = (ValueType)parser.next();
|
||||
paramCount--;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,9 @@
|
||||
*/
|
||||
package de.inetsoftware.jwebassembly.wasm;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
import de.inetsoftware.jwebassembly.module.TypeManager;
|
||||
|
||||
@ -23,7 +26,7 @@ import de.inetsoftware.jwebassembly.module.TypeManager;
|
||||
*
|
||||
* @author Volker Berlin
|
||||
*/
|
||||
public class ValueTypeParser {
|
||||
public class ValueTypeParser implements Iterator<AnyType> {
|
||||
private final String sig;
|
||||
|
||||
private int idx;
|
||||
@ -56,14 +59,21 @@ public class ValueTypeParser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return idx < sig.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next value in the signature or null if the parameter are end or the signature is end.
|
||||
*
|
||||
* @return next type or null
|
||||
*/
|
||||
public AnyType next() {
|
||||
if( idx >= sig.length() ) {
|
||||
return null;
|
||||
if( !hasNext() ) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
switch( sig.charAt( idx++ ) ) {
|
||||
case ')':
|
||||
|
Loading…
x
Reference in New Issue
Block a user