Commit 0e76ba49 authored by yann300's avatar yann300

cache variableDeclaration

parent 6417483d
...@@ -16,8 +16,8 @@ class LocalDecoder { ...@@ -16,8 +16,8 @@ class LocalDecoder {
traceAnalyserEvent.register('onOp', function (index, step, callStack, cache) { traceAnalyserEvent.register('onOp', function (index, step, callStack, cache) {
self.push(index, step, callStack, cache) self.push(index, step, callStack, cache)
}) })
traceAnalyserEvent.register('finishAnalysing', function (index, step) { traceAnalyserEvent.register('finishAnalysing', function (index, step) {})
}) this.variableDeclarationByFile = {}
} }
push (index, step, callStack, cache) { push (index, step, callStack, cache) {
...@@ -28,22 +28,23 @@ class LocalDecoder { ...@@ -28,22 +28,23 @@ class LocalDecoder {
if (error) { if (error) {
console.log(error) console.log(error)
} else { } else {
var ast = this.solidityProxy.ast(result) if (!this.variableDeclarationByFile[result.file]) {
var ast = this.solidityProxy.ast(result)
this.variableDeclarationByFile[result.file] = extractVariableDeclarations(ast, this.astWalker)
}
var variableDeclarations = this.variableDeclarationByFile[result.file]
this.solidityProxy.extractStateVariablesAt(index, (error, stateVars) => { // cached this.solidityProxy.extractStateVariablesAt(index, (error, stateVars) => { // cached
if (error) { if (error) {
console.log(error) console.log(error)
} else { } else {
this.astWalker.walk(ast, (node) => { for (var dec of variableDeclarations) {
if (node.name === 'VariableDeclaration' && node.src.indexOf(result.start + ':' + result.length) === 0) { if (dec.src.indexOf(result.start + ':' + result.length) === 0) {
this.locals[node.attributes.name] = { this.locals[dec.attributes.name] = {
type: decodeInfo.parseType(node.attributes.type, stateVars), type: decodeInfo.parseType(dec.attributes.type, stateVars),
stack: step.stack stack: step.stack
} }
return false
} else {
return true
} }
}) }
} }
}) })
} }
...@@ -53,7 +54,19 @@ class LocalDecoder { ...@@ -53,7 +54,19 @@ class LocalDecoder {
clear () { clear () {
this.locals = {} this.locals = {}
this.variableDeclarationByFile = {}
} }
} }
function extractVariableDeclarations (ast, astWalker) {
var ret = []
astWalker.walk(ast, (node) => {
if (node.name === 'VariableDeclaration') {
ret.push(node)
}
return true
})
return ret
}
module.exports = LocalDecoder module.exports = LocalDecoder
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment