Type nextType = arrayRef.getType();
int count = idxList.size() - 1;
for (Expression expr : idxList) {
int idx = ((Number) expr.interpret(helper)).intValue();
if (array == null) {
throw new ExecuteException("ArrayExpression.interpret : attempted array indirection through null value " + arrayRef.token.getText() + getPos());
}
if (count-- > 0) {
array = Array.get(array, idx);
nextType = nextType.getBaseType();
} else {
Array.set(array, idx, value);
}
}
return value;
} catch (ExecuteException e) {
throw e;
} catch (IllegalArgumentException e) {
throw new ExecuteException("ArrayExpression.interpret : failed to evaluate expression " + arrayRef.token.getText() + getPos(), e);
} catch (ArrayIndexOutOfBoundsException e) {
throw new ExecuteException("ArrayExpression.interpret : invalid index for array " + arrayRef.token.getText() + getPos(), e);
} catch (ClassCastException e) {
throw new ExecuteException("ArrayExpression.interpret : invalid index dereferencing array " + arrayRef.token.getText() + getPos(), e);
} catch (Exception e) {
throw new ExecuteException("ArrayExpression.interpret : unexpected exception dereferencing array " + arrayRef.token.getText() + getPos(), e);
}
}