From 96201e7c0bde708dfe92af7bd2a7bacfe3b4b11f Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Wed, 21 Nov 2018 13:14:18 +0000 Subject: [PATCH] Debug display of skeleton Index --- packages/core/src/skeleton.js | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/packages/core/src/skeleton.js b/packages/core/src/skeleton.js index 983bde3..45b6686 100644 --- a/packages/core/src/skeleton.js +++ b/packages/core/src/skeleton.js @@ -279,6 +279,57 @@ Index.prototype.sendMessage = function(v) { }); }; +Node.prototype._debugString = function () { + const pieces = []; + const inspect = require('util').inspect; + function line(indent, content) { + pieces.push(indent); + pieces.push(content); + } + function walkNode(indent, n) { + line(indent, ' Continuation:'); + walkContinuation(indent+' ', n.continuation); + if (!n.edges.isEmpty()) line(indent, ' Edges:'); + n.edges.forEach((table, selector) => { + line(indent+' ', `pop ${selector.popCount} index ${selector.index}`); + table.forEach((nextNode, cls) => { + line(indent+' ', inspect(cls)); + walkNode(indent+' ', nextNode); + }); + }); + } + function walkCache(indent, cache) { + if (!cache.isEmpty()) line(indent, 'Cache:') + cache.forEach((v,k) => { + line(indent+' ', (k ? k.toString() + ': ' : '') + v && v.toString()); + }); + } + function walkContinuation(indent, c) { + walkCache(indent, c.cachedAssertions); + c.leafMap.forEach((constValMap, constPaths) => { + line(indent, constPaths.toString() + ' =?= ...'); + constValMap.forEach((leaf, constVals) => { + line(indent+' ', constVals.toString()); + walkLeaf(indent+' ', leaf); + }); + }); + } + function walkLeaf(indent, l) { + walkCache(indent, l.cachedAssertions); + l.handlerMap.forEach((handler, capturePaths) => { + line(indent, capturePaths.toString() + ' ==> ...'); + walkHandler(indent+' ', handler); + }); + } + function walkHandler(indent, h) { + walkCache(indent, h.cachedCaptures); + line(indent, '' + h.callbacks.size + ' callback(s)'); + } + line('', 'INDEX ROOT'); + walkNode('\n', this); + return pieces.join(''); +}; + /////////////////////////////////////////////////////////////////////////// function analyzeAssertion(a) {