svoid dm_gazelle_matchStatements_v2(L<GazelleTree> 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<SS> 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); } }
Began life as a copy of #1021772
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1021998 |
Snippet name: | dm_gazelle_matchStatements_v2 - take smallest mapping (old) |
Eternal ID of this version: | #1021998/12 |
Text MD5: | 7d974ce210bf2edb698f7918f1f07506 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-03-16 20:02:30 |
Source code size: | 2626 bytes / 72 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 272 / 318 |
Version history: | 11 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1022399 - dm_gazelle_matchStep_statement - take smallest mapping |