-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from blorente/gdb
FInish basic debugging commands
- Loading branch information
Showing
67 changed files
with
1,009 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def out1 = 4; | ||
def obj = object { | ||
var in1 := 3; | ||
var in2 := 5; | ||
var in3 := 8; | ||
}; | ||
def out2 = 6; | ||
def out3 = 6; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var in1 := 3; | ||
var in2 := 5; | ||
var in3 := 8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
method add(a)to(b) { | ||
a + b; | ||
} | ||
var x := {ba, bb -> add(ba)to(bb);}.apply(2, 4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Copyright (c) 2017 by Borja Lorente. | ||
// Distributed under the GPLv3 license. | ||
// | ||
|
||
#ifndef NAYLANG_DEBUGSTATE_H | ||
#define NAYLANG_DEBUGSTATE_H | ||
enum DebugState { | ||
CONTINUE, | ||
STOP, | ||
STEP_IN, | ||
STEP_OVER, | ||
STEP_OVER_SKIP | ||
}; | ||
#endif //NAYLANG_DEBUGSTATE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// Copyright (c) 2016 by Borja Lorente. | ||
// Distributed under the GPLv3 license. | ||
// | ||
|
||
#include "Debugger.h" | ||
|
||
namespace naylang { | ||
|
||
Debugger::Debugger(DebugMode *mode, const std::string &code) : | ||
Interpreter(std::make_unique<ExecutionEvaluator>(this)), | ||
_frontend{mode}, | ||
_AST{parse(code)}{} | ||
|
||
void Debugger::run() { | ||
_eval->setDebugState(CONTINUE); | ||
_eval->evaluateAST(_AST); | ||
finish(); | ||
} | ||
|
||
void Debugger::setBreakpoint(int line) { | ||
_breakpoints.insert(line); | ||
std::cout << "Breakpoint set at line " << line << std::endl; | ||
} | ||
|
||
void Debugger::printEnvironment() { | ||
std::cout << "Current environment: " << std::endl; | ||
std::cout << _eval->currentScope()->prettyPrint(0) << std::endl; | ||
} | ||
|
||
void Debugger::resume() { | ||
_eval->setDebugState(CONTINUE); | ||
} | ||
|
||
void Debugger::debug(Statement *node) { | ||
if (node->stoppable()) { | ||
if (_breakpoints.count(node->line()) != 0) { | ||
std::cout << "Breakpoint found at line " << node->line() << ". Stop." << std::endl; | ||
_eval->setDebugState(STOP); | ||
} | ||
while(_eval->getDebugState() == STOP) { | ||
_frontend->executeNextCommand(); | ||
} | ||
} | ||
} | ||
|
||
void Debugger::stepIn() { | ||
_eval->setDebugState(STEP_IN); | ||
} | ||
|
||
void Debugger::stepOver() { | ||
_eval->setDebugState(STEP_OVER); | ||
} | ||
|
||
void Debugger::finish() { | ||
std::cout << "Process finished. Resulting environment: " << std::endl; | ||
std::cout << _eval->currentScope()->prettyPrint(0) << std::endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// Copyright (c) 2016 by Borja Lorente. | ||
// Distributed under the GPLv3 license. | ||
// | ||
|
||
#ifndef NAYLANG_DEBUGGER_H | ||
#define NAYLANG_DEBUGGER_H | ||
|
||
#include <frontends/modes/debug/DebugMode.h> | ||
#include <core/control/DebugState.h> | ||
#include "Interpreter.h" | ||
|
||
namespace naylang { | ||
class DebugMode; | ||
class Debugger : public Interpreter { | ||
|
||
GraceAST _AST; | ||
std::set<int> _breakpoints; | ||
DebugMode *_frontend; | ||
|
||
public: | ||
|
||
Debugger(DebugMode *frontend, const std::string &filename); | ||
|
||
void run(); | ||
void setBreakpoint(int line); | ||
void printEnvironment(); | ||
void resume(); | ||
void stepIn(); | ||
void stepOver(); | ||
|
||
void debug(Statement *node); | ||
|
||
private: | ||
|
||
void finish(); | ||
}; | ||
} | ||
|
||
#endif //NAYLANG_DEBUGGER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// Copyright (c) 2016 by Borja Lorente. | ||
// Distributed under the GPLv3 license. | ||
// | ||
|
||
#include "REPLInterpreter.h" | ||
#include <core/control/Debugger.h> | ||
|
||
namespace naylang { | ||
void REPLInterpreter::execute(std::string line) { | ||
colonize(line); | ||
_eval->evaluateAST(parse(line)); | ||
std::cout << _eval->currentScope()->prettyPrint(0) << std::endl; | ||
} | ||
|
||
REPLInterpreter::REPLInterpreter() : Interpreter(std::make_unique<ExecutionEvaluator>()) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Copyright (c) 2016 by Borja Lorente. | ||
// Distributed under the GPLv3 license. | ||
// | ||
|
||
#ifndef NAYLANG_REPLINTERPRETER_H | ||
#define NAYLANG_REPLINTERPRETER_H | ||
|
||
#include <core/parser/NaylangParserVisitor.h> | ||
#include "Interpreter.h" | ||
|
||
namespace naylang { | ||
class REPLInterpreter : public Interpreter { | ||
|
||
public: | ||
REPLInterpreter(); | ||
|
||
void execute(std::string line); | ||
}; | ||
} | ||
|
||
#endif //NAYLANG_REPLINTERPRETER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// Copyright (c) 2017 by Borja Lorente. | ||
// Distributed under the GPLv3 license. | ||
// | ||
|
||
#include "GraceAST.h" | ||
|
||
namespace naylang { | ||
StatementPtr GraceAST::operator[](int index) { | ||
return _nodes[index]; | ||
} | ||
|
||
void GraceAST::addNode(StatementPtr node) { | ||
_nodes.push_back(node); | ||
} | ||
|
||
const std::vector<StatementPtr> &GraceAST::nodes() const { | ||
return _nodes; | ||
} | ||
|
||
void GraceAST::addLineLink(StatementPtr node) { | ||
if (_nodeLinks.count(node->line()) == 0) { | ||
_nodeLinks[node->line()] = node; | ||
_lastLine = node->line() > _lastLine ? node->line() : _lastLine; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// Copyright (c) 2017 by Borja Lorente. | ||
// Distributed under the GPLv3 license. | ||
// | ||
|
||
#ifndef NAYLANG_ASTTREEDEFINITION_H | ||
#define NAYLANG_ASTTREEDEFINITION_H | ||
|
||
#include <core/model/ast/ASTNodeDefinitions.h> | ||
#include <map> | ||
|
||
namespace naylang { | ||
class GraceAST { | ||
std::vector<StatementPtr> _nodes; | ||
std::map<int, StatementPtr> _nodeLinks; | ||
int _lastLine = 0; | ||
|
||
public: | ||
|
||
virtual StatementPtr operator[](int index); | ||
void addNode(StatementPtr node); | ||
void addLineLink(StatementPtr node); | ||
const std::vector<StatementPtr> &nodes() const; | ||
|
||
}; | ||
} | ||
#endif //NAYLANG_ASTTREEDEFINITION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.