/** * {@inheritDoc} * * <p/>Replaces all of the free variables in the clause with stack variables. */ public Variable transform(Variable variable) { StackVariable stackVar = varMapping.get(variable); // Check if a stack variable for the variable has not been created yet, and if so create a new stack variable, // setting the clause that it is in as its binding context supplier. if (stackVar == null) { stackVar = new StackVariable(variable.getName(), null, variable.isAnonymous(), offset++, context); varMapping.put(variable, stackVar); } return stackVar; } }
/** * Determine whether a term is a free variable. * * @param term The object to test for predicate membership. * * @return <tt>true</tt> if the term is a free variable, <tt>false</tt> otherwise. */ public boolean evaluate(Term term) { if (term.isVar() && (term instanceof Variable)) { Variable var = (Variable) term; return !var.isBound() && !var.isAnonymous(); } return false; } }
/** * Determine whether a term is a free variable. * * @param term The object to test for predicate membership. * * @return <tt>true</tt> if the term is a free variable, <tt>false</tt> otherwise. */ public boolean evaluate(Term term) { if (term.isVar() && (term instanceof Variable)) { Variable var = (Variable) term; return !var.isBound() && !var.isAnonymous(); } return false; } }
/** {@inheritDoc} */ public String toString(VariableAndFunctorInterner interner, boolean printVarName, boolean printBindings) { Term value = null; String textName; if (isAnonymous()) { textName = "_" + id; } else { textName = interner.getVariableName(name); } if (printBindings) { value = getValue(); } if (!printBindings || (value == this)) { return textName; } else if (printVarName) { return textName + "/" + value.toString(interner, printVarName, printBindings); } else { return value.toString(interner, printVarName, printBindings); } }
/** {@inheritDoc} */ public String toString(VariableAndFunctorInterner interner, boolean printVarName, boolean printBindings) { Term value = null; String textName; if (isAnonymous()) { textName = "_" + id; } else { textName = interner.getVariableName(name); } if (printBindings) { value = getValue(); } if (!printBindings || (value == this)) { return textName; } else if (printVarName) { return textName + "/" + value.toString(interner, printVarName, printBindings); } else { return value.toString(interner, printVarName, printBindings); } }
/** * {@inheritDoc} * * <p/>Allocates unallocated variables to stack slots. */ public void visit(Variable variable) { if (symbolTable.get(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_ALLOCATION) == null) { if (variable.isAnonymous()) { /*log.fine("Query variable " + variable + " is temporary.");*/ int allocation = (lastAllocatedTempReg++ & (0xff)) | (REG_ADDR << 8); symbolTable.put(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_ALLOCATION, allocation); varNames.put((byte) allocation, variable.getName()); } else { /*log.fine("Query variable " + variable + " is permanent.");*/ int allocation = (numPermanentVars++ & (0xff)) | (WAMInstruction.STACK_ADDR << 8); symbolTable.put(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_ALLOCATION, allocation); varNames.put((byte) allocation, variable.getName()); } } super.visit(variable); } }