@Override public ProvaList getAssignedWithOffset() { if (offset == 0) return assigned; ProvaObject[] newFixed = Arrays.copyOfRange(assigned.getFixed(), offset, assigned.getFixed().length); return ProvaListImpl.create(newFixed); }
private ProvaLiteral[] rebuildNewGoals(final ProvaDerivationNode node) { if (target.getBody() == null || target.getBody().length == 0) return new ProvaLiteral[0]; boolean allGround = true; for (ProvaVariable var : targetVariables) { if (!var.getRecursivelyAssigned().isGround()) { allGround = false; break; } } final ProvaLiteral[] body = target.getGuardedBody(source.getBody()[0]); final int bodyLength = body == null ? 0 : body.length; final ProvaLiteral[] goals = new ProvaLiteralImpl[bodyLength]; for (int i = 0; i < bodyLength; i++) { if ("cut".equals(body[i].getPredicate().getSymbol())) { final ProvaVariablePtr any = (ProvaVariablePtr) body[i].getTerms().getFixed()[0]; final ProvaConstantImpl cutnode = ProvaConstantImpl.create(node); if (any.getRuleId() == source.getRuleId()) sourceVariables.get(any.getIndex()).setAssigned(cutnode); else targetVariables.get(any.getIndex()).setAssigned(cutnode); goals[i] = new ProvaLiteralImpl( body[i].getPredicate(), ProvaListImpl.create(new ProvaObject[] {cutnode})); continue; } goals[i] = body[i].rebuild(this); goals[i].setLine(body[i].getLine()); if (allGround) goals[i].setGround(true); } return goals; }
@Override public ProvaObject cloneWithBoundVariables( final List<ProvaVariable> variables, final List<Boolean> isConstant) { final ProvaObject[] fixed = assigned.getFixed(); final ProvaObject[] newFixed = new ProvaObject[fixed.length - offset]; System.arraycopy(fixed, offset, newFixed, 0, newFixed.length); return ProvaListImpl.create(newFixed).cloneWithBoundVariables(variables, isConstant); }