lojix/wam_prolog/src/main/com/thesett/aima/logic/fol/wam/compiler/PositionAndOccurrenceVisitor.java
protected void enterVariable(Variable variable)
    {
        // Initialize the count to one or add one to an existing count.
        Integer count = (Integer) symbolTable.get(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_VAR_OCCURRENCE_COUNT);
        count = (count == null) ? 1 : (count + 1);
        symbolTable.put(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_VAR_OCCURRENCE_COUNT, count);

        /*log.fine("Variable " + variable + " has count " + count + ".");*/

        // Get the nonArgPosition flag, or initialize it to true.
        Boolean nonArgPositionOnly =
            (Boolean) symbolTable.get(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_VAR_NON_ARG);
        nonArgPositionOnly = (nonArgPositionOnly == null) ? true : nonArgPositionOnly;

        // Clear the nonArgPosition flag if the variable occurs in an argument position.
        nonArgPositionOnly = inTopLevelFunctor(traverser) ? false : nonArgPositionOnly;
        symbolTable.put(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_VAR_NON_ARG, nonArgPositionOnly);

        /*log.fine("Variable " + variable + " nonArgPosition is " + nonArgPositionOnly + ".");*/

        // If in an argument position, record the parent body functor against the variable, as potentially being
        // the last one it occurs in, in a purely argument position.
        // If not in an argument position, clear any parent functor recorded against the variable, as this current
        // last position of occurrence is not purely in argument position.
        if (inTopLevelFunctor(traverser))
        {
            symbolTable.put(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_VAR_LAST_ARG_FUNCTOR, topLevelBodyFunctor);
        }
        else
        {
            symbolTable.put(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_VAR_LAST_ARG_FUNCTOR, null);
        }
    }
protected void enterVariable(Variable variable)
    {
        // Initialize the count to one or add one to an existing count.
        Integer count = (Integer) symbolTable.get(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_VAR_OCCURRENCE_COUNT);
        count = (count == null) ? 1 : (count + 1);
        symbolTable.put(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_VAR_OCCURRENCE_COUNT, count);

        /*log.fine("Variable " + variable + " has count " + count + ".");*/

        // Get the nonArgPosition flag, or initialize it to true.
        Boolean nonArgPositionOnly =
            (Boolean) symbolTable.get(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_VAR_NON_ARG);
        nonArgPositionOnly = (nonArgPositionOnly == null) ? true : nonArgPositionOnly;

        // Clear the nonArgPosition flag if the variable occurs in an argument position.
        nonArgPositionOnly = inTopLevelFunctor(traverser) ? false : nonArgPositionOnly;
        symbolTable.put(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_VAR_NON_ARG, nonArgPositionOnly);

        /*log.fine("Variable " + variable + " nonArgPosition is " + nonArgPositionOnly + ".");*/

        // If in an argument position, record the parent body functor against the variable, as potentially being
        // the last one it occurs in, in a purely argument position.
        // If not in an argument position, clear any parent functor recorded against the variable, as this current
        // last position of occurrence is not purely in argument position.
        if (inTopLevelFunctor(traverser))
        {
            symbolTable.put(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_VAR_LAST_ARG_FUNCTOR, topLevelBodyFunctor);
        }
        else
        {
            symbolTable.put(variable.getSymbolKey(), SymbolTableKeys.SYMKEY_VAR_LAST_ARG_FUNCTOR, null);
        }
    }
{@inheritDoc}

<p/>Counts variable occurrences and detects if the variable ever appears in an argument position.