/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#pushLongLocal(de.fosd.typechef.featureexpr.FeatureExpr, int) */ @Override public void pushLongLocal(FeatureExpr ctx, int index) { Conditional<Entry> value = locals[index]; if (value == null) { value = new One<>(new Entry(0, false)); } stack.pushEntry(ctx, value); value = locals[index + 1]; if (value == null) { value = new One<>(new Entry(0, false)); } stack.pushEntry(ctx, value); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#getSlots(de.fosd.typechef.featureexpr.FeatureExpr) */ @Override public int[] getSlots(FeatureExpr ctx) { int[] slots = new int[length]; int i = 0; for (Conditional<Entry> l : locals) { if (l == null) { slots[i++] = MJIEnv.NULL; continue; } slots[i++] = l.simplify(ctx).getValue(true).value; } int[] stackSlots; stackSlots = stack.getSlots(ctx); if (stackSlots.length == 0) return slots; int j = 0; while (i < length && j < stackSlots.length) { slots[i++] = stackSlots[j++]; } while (i < length) { slots[i++] = MJIEnv.NULL; } return slots; }
@SuppressWarnings("unchecked") public StackHandler(FeatureExpr ctx, Stack st, Entry[] locals) { stack = StackFactory.createVStack(); this.setCtx(ctx); stack.init(st); this.locals = new Conditional[locals.length]; for (int i = 0; i < locals.length; i++) { this.locals[i] = new One<>(locals[i]); } length = st.slots.length + locals.length; }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#hasAnyRef(de.fosd.typechef.featureexpr.FeatureExpr) */ @Override public boolean hasAnyRef(FeatureExpr ctx) { for (Conditional<Entry> local : locals) { if (local == null) { continue; } for (Entry entry : local.simplify(ctx).toList()) { if (entry.isRef) { return true; } } } return false || stack.hasAnyRef(ctx); }
@Override public Set<Integer> getAllReferences() { Set<Integer> references = new HashSet<>(); for (Conditional<Entry> cl : locals) { for (Entry l : cl.toList()) { if (l.isRef) { references.add(l.value); } } } references.addAll(stack.getAllReferences()); return references; }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#getLocal(de.fosd.typechef.featureexpr.FeatureExpr, int) */ @Override public Conditional<Integer> getLocal(FeatureExpr ctx, final int index) { if (index < 0) { return new One<>(-1); } if (index < locals.length) { if (locals[index] == null) { return One.MJIEnvNULL; } return locals[index].simplify(ctx).map(GetLocal).simplifyValues(); } else { final int i = index - locals.length; return stack.getInteger(ctx, i); } }
@SuppressWarnings("unchecked") public StackHandler(FeatureExpr ctx, int nLocals, int nOperands) { if (ctx == null) { // if loading class inside jetty, the ctx is null System.err.println("CAUTIOUS! CTX == NULL, creating True"); ctx = FeatureExprFactory.True(); // throw new RuntimeException("CTX == NULL"); } length = nLocals + nOperands; locals = new Conditional[nLocals]; Arrays.fill(locals, nullValue); // stack = new One<>(new Stack(nOperands)); stack = StackFactory.createVStack(nOperands); stack.setCtx(ctx); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#isRefLocal(de.fosd.typechef.featureexpr.FeatureExpr, int) */ @Override public boolean isRefLocal(FeatureExpr ctx, final int index) { if (index < 0) { return false; } if (index < locals.length) { if (locals[index] == null) { return false; } // TODO check calls of isRefLocal for (boolean b : locals[index].simplify(ctx).map(IsRefLocal).toList()) { if (b) { return true; } } return false; // return locals[index].simplify(ctx).map(new IsRefLocal()).simplifyValues().getValue(); } else { final int i = index - locals.length; return stack.isRefLocal(ctx, i); } }
@Override public Conditional<Stack> getStack() { return stack.getStack(); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#swap(de.fosd.typechef.featureexpr.FeatureExpr) */ @Override public void swap(final FeatureExpr ctx) { stack.swap(ctx); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#dup_x2(de.fosd.typechef.featureexpr.FeatureExpr) */ @Override public void dup_x2(final FeatureExpr ctx) { stack.dup_x2(ctx); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#dup2_x1(de.fosd.typechef.featureexpr.FeatureExpr) */ @Override public void dup2_x1(final FeatureExpr ctx) { stack.dup2_x1(ctx); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#push(de.fosd.typechef.featureexpr.FeatureExpr, java.lang.Object, boolean) */ @Override @SuppressWarnings("unchecked") public void push(final FeatureExpr ctx, final Object value, final boolean isRef) { stack.push(ctx, value, isRef); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#setTop(de.fosd.typechef.featureexpr.FeatureExpr, int) */ @Override public void setTop(final FeatureExpr ctx, final int i) { stack.setTop(ctx, i); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#getStackWidth() */ @Override public int getStackWidth() { return stack.getStackWidth(); }
@SuppressWarnings("unchecked") public StackHandler() { locals = new Conditional[0]; stack = StackFactory.createVStack(); stack.setCtx(FeatureExprFactory.True()); }
@Override public void setCtx(FeatureExpr ctx) { stack.setCtx(ctx); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#isRef(de.fosd.typechef.featureexpr.FeatureExpr, int) */ @Override public boolean isRef(final FeatureExpr ctx, final int offset) { // change to Conditional<Boolean> return stack.isRef(ctx, offset); }
protected <T> Conditional<T> peek(FeatureExpr ctx, final int offset, final Type t) { return stack.peek(ctx, offset, t); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#pop(de.fosd.typechef.featureexpr.FeatureExpr, int) */ @Override public void pop(FeatureExpr ctx, final int n) { stack.pop(ctx, n); }
private Conditional<Entry> popEntry(FeatureExpr ctx, final boolean copyRef) { return stack.popEntry(ctx, copyRef); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#clear(de.fosd.typechef.featureexpr.FeatureExpr) */ @Override public void clear(final FeatureExpr ctx) { stack.clear(ctx); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#set(de.fosd.typechef.featureexpr.FeatureExpr, int, int, boolean) */ @Override public void set(final FeatureExpr ctx, final int offset, final int value, final boolean isRef) { stack.set(ctx, offset, value, isRef); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#pop(de.fosd.typechef.featureexpr.FeatureExpr, gov.nasa.jpf.vm.StackHandler.Type) */ @Override public <T> Conditional<T> pop(final FeatureExpr ctx, final Type t) { return stack.pop(ctx, t); }
/* (non-Javadoc) * @see gov.nasa.jpf.vm.IStackHandler#getTop() */ @Override public Conditional<Integer> getTop() { return stack.getTop(); }
@Override public FeatureExpr getCtx() { return stack.getCtx(); }