-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDebugDispatcher.cpp
More file actions
97 lines (78 loc) · 2.63 KB
/
DebugDispatcher.cpp
File metadata and controls
97 lines (78 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "DebugDispatcher.h"
#include <iostream>
DebugDispatcher::DebugDispatcher(DebuggerInputInterface *_inputController){
pausableNodeTypes = {AST_TAG_STMT, AST_TAG_CALL};
breakpoints = {};
mode = NORMAL;
skipCalls = false;
newInlines = false;
inputController = _inputController;
stackTrace = std::vector<std::pair<unsigned, const Object*>>();
}
const Value DebugDispatcher::eval(Object &node){
std::string nodeType = node[AST_TAG_TYPE_KEY]->toString();
unsigned nodeLine = node[AST_TAG_LINE_KEY]->toNumber();
currLine = nodeLine;
Value ret = Value(Value::NilType);
if(nodeType == AST_TAG_CALL)
stackTrace.push_back(std::pair<unsigned, const Object *>(currLine, getTopEnvinroment()));
if(nodeType == AST_TAG_INLINE)
newInlines = true;
if(pausableNodeTypes.find(nodeType) != pausableNodeTypes.end() &&
(breakpoints.find(nodeLine) != breakpoints.end() || mode != NORMAL) && !skipCalls && (nodeType != AST_TAG_CALL || mode != NORMAL)){
mode = PAUSED;
inputController->handleInput(this);
while(mode == PAUSED);
if(nodeType == AST_TAG_CALL && mode == STEP_OVER)
skipCalls = true;
ret = evals[node[AST_TAG_SUBTYPE_KEY]->toString()](node);
skipCalls = false;
}
else
ret = evals[node[AST_TAG_SUBTYPE_KEY]->toString()](node);
if(nodeType == AST_TAG_CALL)
stackTrace.pop_back();
return ret;
}
void DebugDispatcher::addBreakpoint(unsigned lineNo){
breakpoints.insert(lineNo);
}
void DebugDispatcher::removeBreakpoint(unsigned lineNo){
breakpoints.erase(lineNo);
}
void DebugDispatcher::removeAllBreakpoints(){
breakpoints.clear();
}
void DebugDispatcher::setExecutionMode(ExecutionModes m){
mode = m;
}
unsigned DebugDispatcher::getCurrLine(){
return currLine;
}
void DebugDispatcher::setInterpreter(Interpreter *_i){
i = _i;
}
const Value* DebugDispatcher::getVarByName(std::string id){
return i->getVarByName(id);
}
const Value* DebugDispatcher::getGlobalVarByName(std::string id){
return i->getGlobalVarByName(id);
}
const Value* DebugDispatcher::getLocalVarByName(std::string id){
return i->getLocalVarByName(id);
}
const Object* DebugDispatcher::getTopEnvinroment(){
return i->getTopEnvinroment();
}
const Object* DebugDispatcher::getGlobalEnvinroment(){
return i->getGlobalEnvinroment();
}
const std::vector<std::pair<unsigned, const Object*>>& DebugDispatcher::getStackTrace(){
return stackTrace;
}
bool DebugDispatcher::hasNewInlines(){
return newInlines;
}
void DebugDispatcher::allInlinesProcessed(){
newInlines = false;
}