use of com.oracle.truffle.api.interop.StopIterationException in project graal by oracle.
the class InsightFilter method create.
static InsightFilter.Data create(AgentType at, Object[] arr) throws IllegalArgumentException, UnsupportedMessageException {
List<Class<? extends Tag>> allTags = new ArrayList<>();
String rootNameRegExp = null;
Object rootNameFn = null;
Object sourceFilterFn = null;
if (arr != null && arr.length > 2) {
Object config = arr[2];
final InteropLibrary iop = InteropLibrary.getFactory().getUncached();
Map<String, Object> map = new LinkedHashMap<>();
if (iop.hasHashEntries(config)) {
Object it = iop.getHashEntriesIterator(config);
while (iop.hasIteratorNextElement(it)) {
try {
Object keyAndValue = iop.getIteratorNextElement(it);
Object key;
Object value;
try {
key = iop.readArrayElement(keyAndValue, 0);
value = iop.readArrayElement(keyAndValue, 1);
} catch (InvalidArrayIndexException ex) {
throw CompilerDirectives.shouldNotReachHere(ex);
}
String type = iop.asString(key);
map.put(type, value);
} catch (StopIterationException ex) {
break;
}
}
} else {
Object allMembers = iop.getMembers(config, false);
long allMembersSize = iop.getArraySize(allMembers);
for (int i = 0; i < allMembersSize; i++) {
Object atI;
try {
atI = iop.readArrayElement(allMembers, i);
} catch (InvalidArrayIndexException ex) {
continue;
}
String type = iop.asString(atI);
Object value;
try {
value = iop.readMember(config, type);
} catch (UnknownIdentifierException ex) {
continue;
}
map.put(type, value);
}
}
for (Map.Entry<String, Object> entry : map.entrySet()) {
String type = entry.getKey();
switch(type) {
case "expressions":
if (isSet(iop, map, "expressions")) {
allTags.add(StandardTags.ExpressionTag.class);
}
break;
case "statements":
if (isSet(iop, map, "statements")) {
allTags.add(StandardTags.StatementTag.class);
}
break;
case "roots":
if (isSet(iop, map, "roots")) {
allTags.add(StandardTags.RootBodyTag.class);
}
break;
case "rootNameFilter":
{
Object fn = map.get("rootNameFilter");
if (fn != null && !iop.isNull(fn)) {
if (iop.isString(fn)) {
rootNameRegExp = iop.asString(fn);
} else {
if (!iop.isExecutable(fn)) {
throw new IllegalArgumentException("rootNameFilter should be a string, a regular expression!");
}
rootNameFn = fn;
}
}
break;
}
case "sourceFilter":
{
Object fn = map.get("sourceFilter");
if (fn != null && !iop.isNull(fn)) {
if (!iop.isExecutable(fn)) {
throw new IllegalArgumentException("sourceFilter has to be a function!");
}
sourceFilterFn = fn;
}
break;
}
default:
throw InsightException.unknownAttribute(type);
}
}
}
if (allTags.isEmpty()) {
throw new IllegalArgumentException("No elements specified to listen to for execution listener. Need to specify at least one element kind: expressions, statements or roots.");
}
allTags.sort((c1, c2) -> c1.getName().compareTo(c2.getName()));
InsightFilter filter = new InsightFilter(allTags, rootNameRegExp, rootNameFn != null, sourceFilterFn != null);
return new Data(at, filter, arr[1], rootNameFn, sourceFilterFn);
}
use of com.oracle.truffle.api.interop.StopIterationException in project graal by oracle.
the class DebugValue method getIteratorNextElement.
/**
* Returns the next element in the iteration. When the underlying data structure is modified the
* {@link #getIteratorNextElement()} may throw the {@link NoSuchElementException} despite the
* {@link #hasIteratorNextElement()} returned {@code true}.
*
* @throws DebugException if {@link #isIterator()} returns {@code false} or when the underlying
* iterator element exists but is not readable, or guest language code throws an
* exception.
* @throws NoSuchElementException if the iteration has no more elements.
*
* @see #isIterator()
* @see #hasIteratorNextElement()
* @see InteropLibrary#getIteratorNextElement(Object)
* @since 21.2
*/
public DebugValue getIteratorNextElement() throws NoSuchElementException, DebugException {
Object value = get();
Object next;
try {
next = INTEROP.getIteratorNextElement(value);
} catch (ThreadDeath td) {
throw td;
} catch (StopIterationException ex) {
throw new NoSuchElementException(ex.getLocalizedMessage());
} catch (Throwable ex) {
throw DebugException.create(getSession(), ex, resolveLanguage(), null, true, null);
}
return new DebugValue.HeapValue(getSession(), preferredLanguage, null, next);
}
Aggregations