Skip to content

Commit

Permalink
zhangShashaMapping visualisierung
Browse files Browse the repository at this point in the history
SQUASHED: AUTO-COMMIT-demos-zhangShashaMapping.md,AUTO-COMMIT-src-client-reactive-babel-plugin-ILA-index.js,AUTO-COMMIT-src-external-babel-plugin-var-recorder.js,AUTO-COMMIT-src-external-tree-edit-distance-zhang-shasha.js,
  • Loading branch information
JensLincke committed Oct 10, 2023
1 parent e1eca8b commit 1a0a85f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
34 changes: 21 additions & 13 deletions demos/zhangShashaMapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// editor1.value = `let a = 3 + 4`
editor1.value = `let a = 3`
// editor2.value = `let a = 3 + 4\na++`
editor2.value = `{let a = 2+4}`
editor2.value = `let a = 3 + 4}`

editor1.editor.on("change", (() => update()).debounce(500));
editor2.editor.on("change", (() => update()).debounce(500));
Expand All @@ -31,7 +31,7 @@
function update() {
vis.tree2 = parser.parse(editor2.value );
vis.tree1 = parser.parse(editor1.value);
var mappings = []


function label(node) {

Expand All @@ -41,6 +41,18 @@
return node.type
}

function updateVis(vis, zsMappings) {
var mappings = []

for (let candidate of zsMappings) {
if (candidate.t1 && candidate.t2) {
mappings.push({ node1: candidate.t1, node2: candidate.t2, type: candidate.type })
}
}
vis.matches = mappings
vis.update()
}



let zsMappings = zhangShashaMapping(vis.tree1.rootNode, vis.tree2.rootNode,
Expand All @@ -64,23 +76,16 @@
operationsMatrix = operations
treedistMatrix = treedist
});
debugger

for (let candidate of zsMappings) {
if (candidate.t1 && candidate.t2) {
mappings.push({ node1: candidate.t1, node2: candidate.t2 })
}
}

vis.matches = mappings
updateVis(vis, zsMappings)

// lively.openInspector(vis.matches)

table.textContent = ""



debugger

for(let i in treedistMatrix) {
let row = treedistMatrix[i]
let tr = <tr></tr>
Expand All @@ -90,13 +95,16 @@
let operations = operationsMatrix[i][j]
tr.appendChild(<td click={ () => {
operationsList.textContent = ""
operations.forEach(ea => operationsList.appendChild(<span style="padding:2px">{ea.type}</span>))
operations.forEach(ea => operationsList.appendChild(<span style="padding:2px" click={evt => {
lively.openInspector(operations)
}}>{ea.type}</span>))

updateVis(vis, operations)
}}>{ea}</td>)
}
table.appendChild(tr)
}

vis.update()
}


Expand Down
15 changes: 7 additions & 8 deletions src/client/reactive/babel-plugin-ILA/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { getSourceLocation } from 'src/client/reactive/babel-plugin-active-expression-rewriting/index.js'

import babelDefault from 'src/external/babel/babel7default.js'
const { template } = babelDefault.babel;

export default function (babel) {
const { types: t, template, transformFromAst, traverse } = babel;
const buildAEGenerator = template(`(cond, layer) => aexpr(cond, {isILA: true, ila: layer})`);
const buildFunctionDebugInfo = template(`({ location: LOCATION, code: CODE })`)

const buildAEGenerator = template(`(cond, layer) => aexpr(cond, {isILA: true, ila: layer})`);
export default function (babel) {
const { types: t } = babel;

function parentStatement(path) {
while(!t.isStatement(path.node)) {
Expand All @@ -31,8 +33,6 @@ export default function (babel) {
path.replaceWith(callExpression)
}

const buildFunctionDebugInfo = template(`({ location: LOCATION, code: CODE })`)

function addRefineInfo(callExpression, path, state) {
const debugInfos = [];
const objectExpressionPath = path.get("arguments")[1];
Expand All @@ -51,7 +51,6 @@ export default function (babel) {
path.pushContainer('arguments', t.objectExpression(debugInfos));
}


return {
name: "data-binding",
visitor: {
Expand All @@ -73,7 +72,7 @@ export default function (babel) {
// We assume this call expression is for an ILA
createILA(node, path);
} else if (t.isIdentifier(node.callee.property, { name: "refineObject" }) ||
t.isIdentifier(node.callee.property, { name: "refineClass" })) {
t.isIdentifier(node.callee.property, { name: "refineClass" })) {
addRefineInfo(node, path, state);
} else {
// Wrong name or computed property access which is probably wrong
Expand Down
2 changes: 1 addition & 1 deletion src/external/tree-edit-distance/zhang-shasha.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function zhangShasha(isMapping, rootOfT1, rootOfT2,

if (debugInfo) debugInfo(operations, treedist)


if(isMapping) {
return operations[orderOfT1 - 1][orderOfT2 - 1].reverse()
} else {
Expand Down

0 comments on commit 1a0a85f

Please sign in to comment.