Search in sources :

Example 1 with AbstractOp

use of uk.me.parabola.mkgmap.osmstyle.eval.AbstractOp in project mkgmap by openstreetmap.

the class RuleSet method compileOp.

private Op compileOp(HashMap<String, Op> tests, Op op) {
    if (op instanceof AbstractBinaryOp) {
        AbstractBinaryOp binOp = (AbstractBinaryOp) op;
        binOp.setFirst(compileOp(tests, binOp.getFirst()));
        binOp.setSecond(compileOp(tests, binOp.getSecond()));
    }
    if (op instanceof LinkedOp) {
        // LinkedOp is referenced by other OPs, don't replace it
        return op;
    }
    String test = op.toString();
    Op commonOp = tests.get(test);
    if (commonOp == null) {
        if (op instanceof AbstractOp)
            ((AbstractOp) op).resetCache();
        tests.put(test, op);
        commonOp = op;
    }
    return commonOp;
}
Also used : LinkedBinaryOp(uk.me.parabola.mkgmap.osmstyle.eval.LinkedBinaryOp) AbstractBinaryOp(uk.me.parabola.mkgmap.osmstyle.eval.AbstractBinaryOp) AbstractOp(uk.me.parabola.mkgmap.osmstyle.eval.AbstractOp) Op(uk.me.parabola.mkgmap.osmstyle.eval.Op) LinkedOp(uk.me.parabola.mkgmap.osmstyle.eval.LinkedOp) AbstractOp(uk.me.parabola.mkgmap.osmstyle.eval.AbstractOp) LinkedOp(uk.me.parabola.mkgmap.osmstyle.eval.LinkedOp) AbstractBinaryOp(uk.me.parabola.mkgmap.osmstyle.eval.AbstractBinaryOp)

Example 2 with AbstractOp

use of uk.me.parabola.mkgmap.osmstyle.eval.AbstractOp in project mkgmap by openstreetmap.

the class RuleSet method compile.

/**
 * Compile the rules and reset caches. Detect common sub-expressions and
 * make sure that all rules use the same instance of these common
 * sub-expressions.
 */
private void compile() {
    HashMap<String, Op> tests = new HashMap<String, Op>();
    for (Rule rule : rules) {
        Op op;
        if (rule instanceof ExpressionRule)
            op = ((ExpressionRule) rule).getOp();
        else if (rule instanceof ActionRule)
            op = ((ActionRule) rule).getOp();
        else {
            log.error("unexpected rule instance");
            continue;
        }
        if (op instanceof AbstractBinaryOp) {
            AbstractBinaryOp binOp = (AbstractBinaryOp) op;
            binOp.setFirst(compileOp(tests, binOp.getFirst()));
            binOp.setSecond(compileOp(tests, binOp.getSecond()));
            op = compileOp(tests, binOp);
        } else if (op instanceof AbstractOp) {
            op = compileOp(tests, op);
        } else if (op instanceof LinkedBinaryOp) {
            ((LinkedBinaryOp) op).setFirst(compileOp(tests, ((LinkedBinaryOp) op).getFirst()));
            ((LinkedBinaryOp) op).setSecond(compileOp(tests, ((LinkedBinaryOp) op).getSecond()));
        } else if (op instanceof LinkedOp) {
            Op wrappedOp = compileOp(tests, ((LinkedOp) op).getFirst());
            op.setFirst(wrappedOp);
        } else {
            log.error("unexpected op instance");
            continue;
        }
        if (rule instanceof ExpressionRule)
            ((ExpressionRule) rule).setOp(op);
        else if (rule instanceof ActionRule)
            ((ActionRule) rule).setOp(op);
        else {
            log.error("unexpected rule instance");
            continue;
        }
    }
    cacheId = 0;
    compiled = true;
}
Also used : LinkedBinaryOp(uk.me.parabola.mkgmap.osmstyle.eval.LinkedBinaryOp) AbstractBinaryOp(uk.me.parabola.mkgmap.osmstyle.eval.AbstractBinaryOp) AbstractOp(uk.me.parabola.mkgmap.osmstyle.eval.AbstractOp) Op(uk.me.parabola.mkgmap.osmstyle.eval.Op) LinkedOp(uk.me.parabola.mkgmap.osmstyle.eval.LinkedOp) AbstractOp(uk.me.parabola.mkgmap.osmstyle.eval.AbstractOp) HashMap(java.util.HashMap) LinkedOp(uk.me.parabola.mkgmap.osmstyle.eval.LinkedOp) AbstractBinaryOp(uk.me.parabola.mkgmap.osmstyle.eval.AbstractBinaryOp) LinkedBinaryOp(uk.me.parabola.mkgmap.osmstyle.eval.LinkedBinaryOp) Rule(uk.me.parabola.mkgmap.reader.osm.Rule)

Aggregations

AbstractBinaryOp (uk.me.parabola.mkgmap.osmstyle.eval.AbstractBinaryOp)2 AbstractOp (uk.me.parabola.mkgmap.osmstyle.eval.AbstractOp)2 LinkedBinaryOp (uk.me.parabola.mkgmap.osmstyle.eval.LinkedBinaryOp)2 LinkedOp (uk.me.parabola.mkgmap.osmstyle.eval.LinkedOp)2 Op (uk.me.parabola.mkgmap.osmstyle.eval.Op)2 HashMap (java.util.HashMap)1 Rule (uk.me.parabola.mkgmap.reader.osm.Rule)1