Commit 9bb4a102 authored by Iuri Matias's avatar Iuri Matias

add methods needed for solidity code navigation

parent cbfcccf0
...@@ -81,9 +81,18 @@ class CmdLine { ...@@ -81,9 +81,18 @@ class CmdLine {
return source return source
} }
getCurrentLine() {
let lineColumnPos = this.lineColumnPos
if (!lineColumnPos) return ""
let currentLineNumber = lineColumnPos.start.line
let content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split("\n")
return content[currentLineNumber]
}
startDebug(txNumber, filename, cb) { startDebug(txNumber, filename, cb) {
const self = this const self = this
this.filename = filename this.filename = filename
this.txHash = txNumber
this.debugger.debug(null, txNumber, null, () => { this.debugger.debug(null, txNumber, null, () => {
self.debugger.event.register('newSourceLocation', function (lineColumnPos, rawLocation) { self.debugger.event.register('newSourceLocation', function (lineColumnPos, rawLocation) {
...@@ -111,6 +120,13 @@ class CmdLine { ...@@ -111,6 +120,13 @@ class CmdLine {
}) })
} }
getVars() {
return {
locals: this.solidityLocals,
contract: this.solidityState
}
}
triggerSourceUpdate() { triggerSourceUpdate() {
this.events.emit("source", [this.lineColumnPos, this.rawLocation]) this.events.emit("source", [this.lineColumnPos, this.rawLocation])
} }
...@@ -144,13 +160,43 @@ class CmdLine { ...@@ -144,13 +160,43 @@ class CmdLine {
} }
getTraceLength() { getTraceLength() {
if (!this.debugger.step_manager) return 0;
return this.debugger.step_manager.traceLength return this.debugger.step_manager.traceLength
} }
getCodeFirstStep() {
if (!this.debugger.step_manager) return 0;
return this.debugger.step_manager.calculateFirstStep()
}
getCodeTraceLength() {
if (!this.debugger.step_manager) return 0;
return this.debugger.step_manager.calculateCodeLength()
}
nextStep() {
if (!this.debugger.step_manager) return 0;
return this.debugger.step_manager.nextStep()
}
previousStep() {
if (!this.debugger.step_manager) return 0;
return this.debugger.step_manager.previousStep()
}
currentStep() { currentStep() {
if (!this.debugger.step_manager) return 0;
return this.debugger.step_manager.currentStepIndex return this.debugger.step_manager.currentStepIndex
} }
canGoNext() {
return this.currentStep() < this.getCodeTraceLength()
}
canGoPrevious() {
return this.currentStep() > this.getCodeFirstStep()
}
unload() { unload() {
return this.debugger.unload() return this.debugger.unload()
} }
......
...@@ -10,6 +10,7 @@ class DebuggerStepManager { ...@@ -10,6 +10,7 @@ class DebuggerStepManager {
this.traceManager = traceManager this.traceManager = traceManager
this.currentStepIndex = 0 this.currentStepIndex = 0
this.traceLength = 0 this.traceLength = 0
this.codeTraceLength = 0
this.revertionPoint = null this.revertionPoint = null
this.listenToEvents() this.listenToEvents()
...@@ -26,6 +27,7 @@ class DebuggerStepManager { ...@@ -26,6 +27,7 @@ class DebuggerStepManager {
if (self.traceLength !== newLength) { if (self.traceLength !== newLength) {
self.event.trigger('traceLengthChanged', [newLength]) self.event.trigger('traceLengthChanged', [newLength])
self.traceLength = newLength self.traceLength = newLength
self.codeTraceLength = self.calculateCodeLength()
} }
self.jumpTo(0) self.jumpTo(0)
}) })
...@@ -156,6 +158,37 @@ class DebuggerStepManager { ...@@ -156,6 +158,37 @@ class DebuggerStepManager {
this.debugger.breakpointManager.jumpPreviousBreakpoint(this.currentStepIndex, true) this.debugger.breakpointManager.jumpPreviousBreakpoint(this.currentStepIndex, true)
} }
calculateFirstStep() {
let step = this.resolveToReducedTrace(0, 1)
return this.resolveToReducedTrace(step, 1)
}
calculateCodeStepList() {
let step = 0
let steps = []
while (step < this.traceLength) {
let _step = this.resolveToReducedTrace(step, 1)
if (!_step) break;
steps.push(_step)
step += 1
}
steps = steps.filter((item, pos, self) => { return steps.indexOf(item) === pos })
return steps
}
calculateCodeLength() {
let steps = this.calculateCodeStepList().reverse()
return this.calculateCodeStepList().reverse()[1] || this.traceLength;
}
nextStep() {
return this.resolveToReducedTrace(this.currentStepIndex, 1);
}
previousStep() {
return this.resolveToReducedTrace(this.currentStepIndex, -1);
}
resolveToReducedTrace (value, incr) { resolveToReducedTrace (value, incr) {
if (this.debugger.callTree.reducedTrace.length) { if (this.debugger.callTree.reducedTrace.length) {
var nextSource = util.findClosestIndex(value, this.debugger.callTree.reducedTrace) var nextSource = util.findClosestIndex(value, this.debugger.callTree.reducedTrace)
......
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