svoid dm_gazelle_matchStatements_v2(L l, O... _) { bool debug = boolPar debug(_) || boolPar matchStatementsDebug(_); for (GazelleTree t : l) { if (t.rule() == null) continue; RuleEngine2_MatchedRule mr = t.mr; LS in = t.rule().in; int iCond = t.mr.iCond; if (debug) print("matchStatements: iCond=" + iCond + " in " + in); if (iCond >= l(in)) continue; LS conditions = dropFirst(iCond, in); if (debug) print("Remaining conditions for " + t.ruleID() + " with " + t.mr.map + ": " + conditions); new Matches m; if (!matchAny("in " + (iCond+1) + " = statement *", t.rule().comments, m)) continue; S subRuleID = $1; if (debug) print("Found subrule: " + subRuleID); // load all known fulfillments L fulfillments = dm_gazelle_fulfillmentsForRule(subRuleID); // find best fulfillment new Lowest bestMap; if (debug) print("Have " + n2(fulfillments, "fulfillment") + "."); for (O f : fulfillments) { SS varMap = asCIMap(safeUnstructMap(getString varMap(f))); if (debug) print("fulfillment => " + sfu(varMap)); // self-vars hack to fix John Doe problem bool selfVarsFix = boolPar selfVarsFix(_, true); if (selfVarsFix) { S cond = first(conditions); for (S x : identifiersOnly(codeTokens(mr.tokenize(cond)))) if (!varMap.containsKey(x)) { if (debug) print("Self-linking " + x); varMap.put(x, x); } } if (debug) print("Original map: " + t.mr.map); SS newMap = mergeMapsStrictlyIC(asCIMap(t.mr.map), varMap); if (newMap == null) { if (debug) printIndent("Can't merge maps"); continue; } if (debug) printIndent("Maps merged! => " + sfu(newMap)); newMap = ciMapWithoutKeysEqualToValues(newMap); if (debug) printIndent("Map simplified => " + sfu(newMap)); continue if gazelle_isRecentlyUsedMapping(t, newMap, _); bestMap.put(newMap, l(newMap)); } SS newMap = bestMap!; if (newMap == null) { if (debug) print("No matching statement found"); continue; } t.mr.map = newMap; t.mr.iCond++; t.mr.remainingConditions = dropFirst(t.mr.remainingConditions); // XX: also should rewrite with new vars t.mr.remainingConditionsWithType = dropFirst(t.mr.remainingConditionsWithType); t.mr.out = null; t.line = t.mr.outText(); if (debug) print("Rewrote " + t.mr.rule.out + " to: " + t.line); } }