/** * @param n * @param prefix * @return * @throws AbortException */ private ExprNode generateNewBuiltInNode(OpApplNode n, String prefix) throws AbortException { switch (getOpCode(n.getOperator().getName())) { case OPCODE_exc: { // Except OpApplNode newNode = new OpApplNode(n.getOperator().getName(), null, n.getTreeNode(), null); n.setToolObject(substitutionId, newNode); // needed for @ node ExprOrOpArgNode[] newArgs = new ExprOrOpArgNode[n.getArgs().length]; newArgs[0] = generateNewExprOrOpArgNode(n.getArgs()[0], prefix); for (int i = 1; i < n.getArgs().length; i++) { OpApplNode pair = (OpApplNode) n.getArgs()[i]; OpApplNode newPair = new OpApplNode(pair.getOperator().getName(), null, pair.getTreeNode(), null); // needed for @ node: we have to set a reference from the old // pair to the new pair // before evaluation the arguments which may be contains a @ // node pair.setToolObject(substitutionId, newPair); newPair.setArgs(generateNewArgs(pair.getArgs(), prefix)); newArgs[i] = newPair; } newNode.setArgs(newArgs); return newNode; } case OPCODE_uc: { // CHOOSE x : P FormalParamNode[] oldSymbols = n.getUnbdedQuantSymbols(); FormalParamNode[] newSymbols = new FormalParamNode[oldSymbols.length]; for (int i = 0; i < n.getUnbdedQuantSymbols().length; i++) { FormalParamNode f = oldSymbols[i]; newSymbols[i] = new FormalParamNode(f.getName(), f.getArity(), f.getTreeNode(), null, null); f.setToolObject(substitutionId, newSymbols[i]); } OpApplNode newNode = new OpApplNode( n.getOperator().getName(), newSymbols, generateNewArgs(n.getArgs(), prefix), null, null, null, n.getTreeNode(), null); return newNode; } case OPCODE_rfs: case OPCODE_nrfs: case OPCODE_fc: // Represents [x \in S |-> e] case OPCODE_be: // \E x \in S : P case OPCODE_bf: // \A x \in S : P case OPCODE_bc: // CHOOSE x \in S: P case OPCODE_sso: // $SubsetOf Represents {x \in S : P} case OPCODE_soa: // $SetOfAll Represents {e : p1 \in S, p2,p3 \in S2} { // new formalparamnodes FormalParamNode[][] oldParams = n.getBdedQuantSymbolLists(); FormalParamNode[][] newParams = new FormalParamNode[oldParams.length][0]; for (int i = 0; i < oldParams.length; i++) { FormalParamNode[] temp = new FormalParamNode[oldParams[i].length]; for (int j = 0; j < oldParams[i].length; j++) { FormalParamNode f = oldParams[i][j]; temp[j] = new FormalParamNode(f.getName(), f.getArity(), f.getTreeNode(), null, null); // set reference the old param to the new f.setToolObject(substitutionId, temp[j]); } newParams[i] = temp; } // new ranges ExprNode[] ranges = new ExprNode[n.getBdedQuantBounds().length]; for (int i = 0; i < n.getBdedQuantBounds().length; i++) { ranges[i] = generateNewExprNode(n.getBdedQuantBounds()[i], prefix); } OpApplNode newNode = new OpApplNode( n.getOperator().getName(), null, generateNewArgs(n.getArgs(), prefix), newParams, n.isBdedQuantATuple(), ranges, n.getTreeNode(), null); return newNode; } default: { // = OpApplNode newNode = new OpApplNode( n.getOperator(), generateNewArgs(n.getArgs(), prefix), n.getTreeNode(), null); return newNode; } } }
/** * @param n * @param prefix * @return * @throws AbortException */ private ExprNode generateNewOpApplNode(OpApplNode n, String prefix) throws AbortException { switch (n.getOperator().getKind()) { case VariableDeclKind: case ConstantDeclKind: { ExprOrOpArgNode e = (ExprOrOpArgNode) n.getOperator().getToolObject(substitutionId); if (e != null) { if (e instanceof ExprNode) { // TODO newprefix, witout last prefix return generateNewExprNode((ExprNode) e, ""); } else { OpArgNode opArg = (OpArgNode) e; while (opArg.getOp().getToolObject(substitutionId) != null) { opArg = (OpArgNode) opArg.getOp().getToolObject(substitutionId); } return new OpApplNode( opArg.getOp(), generateNewArgs(n.getArgs(), prefix), n.getTreeNode(), null); } } else { return new OpApplNode( n.getOperator(), generateNewArgs(n.getArgs(), prefix), n.getTreeNode(), null); } } case FormalParamKind: { FormalParamNode f = (FormalParamNode) n.getOperator().getToolObject(substitutionId); if (f == null) { throw new RuntimeException(); } return new OpApplNode(f, generateNewArgs(n.getArgs(), prefix), n.getTreeNode(), null); } case BuiltInKind: { return generateNewBuiltInNode(n, prefix); } case UserDefinedOpKind: { // in case of a call of a LetInNode OpDefNode letOp = (OpDefNode) n.getOperator().getToolObject(substitutionId); if (letOp != null) { return new OpApplNode( letOp, generateNewArgs(n.getArgs(), prefix), n.getTreeNode(), null); } // in case of a call of BBuiltInOp e.g. +, - if (BBuiltInOPs.contains(n.getOperator().getName())) { return new OpApplNode( n.getOperator(), generateNewArgs(n.getArgs(), prefix), n.stn, null); } // normal userdefined Operator String opName = prefix + n.getOperator().getName().toString(); OpDefNode op = defsHash.get(opName); if (op == null) { throw new RuntimeException(); } return new OpApplNode(op, generateNewArgs(n.getArgs(), prefix), n.getTreeNode(), null); } } throw new RuntimeException("OpApplkind not implemented jet"); }