Commit c4f06bdb authored by Victor Yacovlev's avatar Victor Yacovlev

Implemented run to cursor

parent 85257035
......@@ -284,12 +284,12 @@ Right click to navigate target</source>
</message>
<message>
<location filename="../../../src/plugins/coregui/guisettingspage.cpp" line="139"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="60"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="61"/>
<source>Regular run</source>
<translation>Обычное выполнение</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="74"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="75"/>
<source>Testing run</source>
<translation>Запустить тестирование</translation>
</message>
......@@ -299,7 +299,7 @@ Right click to navigate target</source>
</message>
<message>
<location filename="../../../src/plugins/coregui/guisettingspage.cpp" line="167"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="91"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="92"/>
<source>Step in</source>
<translation>шаг</translation>
</message>
......@@ -309,18 +309,18 @@ Right click to navigate target</source>
</message>
<message>
<location filename="../../../src/plugins/coregui/guisettingspage.cpp" line="145"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="115"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="124"/>
<source>Stop</source>
<translation>Остановить выполнение</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/guisettingspage.cpp" line="133"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="138"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="147"/>
<source>Blind run</source>
<translation>Без показа на полях</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="287"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="299"/>
<source>This program does not have testing algorithm</source>
<translation>У этой программы нет тестирующего алгоритма</translation>
</message>
......@@ -329,23 +329,33 @@ Right click to navigate target</source>
<translation type="obsolete">Программа не содержит тестирующего алгоритма</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="89"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="90"/>
<source>Do big step</source>
<translation>ШАГ</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="101"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="102"/>
<source>Do small step</source>
<translation>шаг</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="117"/>
<source>Run to cursor</source>
<translation>Выполнить до курсора</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="119"/>
<source>Run until the line editor cursor in</source>
<translation>Выполнить программу до строки, в которой находится курсор редактирования</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/guisettingspage.cpp" line="173"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="103"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="104"/>
<source>Step to end</source>
<translation>До конца алгоритма</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="113"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="114"/>
<source>Run to end of algorhitm</source>
<translation>До конца алгоритма</translation>
</message>
......@@ -354,23 +364,23 @@ Right click to navigate target</source>
<translation type="obsolete">Нераспознанная ошибка</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="455"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="481"/>
<source>Evaluation error</source>
<translation>Ошибка выполнения</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="464"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="490"/>
<source>Evaluation finished</source>
<translation>Выполнение завершено</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="446"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="472"/>
<source>Evaluation terminated</source>
<translation>Выполнение прервано</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/guisettingspage.cpp" line="161"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="79"/>
<location filename="../../../src/plugins/coregui/kumirprogram.cpp" line="80"/>
<source>Step over</source>
<translation>ШАГ</translation>
</message>
......
......@@ -25,6 +25,7 @@ KumirProgram::KumirProgram(QObject *parent)
, stepRunAction_(0)
, stepInAction_(0)
, stepOutAction_(0)
, runToCursorAction_(0)
, stopAction_(0)
, toggleBreakpointAction_(0)
, actions_(0)
......@@ -112,6 +113,14 @@ void KumirProgram::createActions()
#endif
stepOutAction_->setToolTip(tr("Run to end of algorhitm")+" <b>"+stepOutAction_->shortcut().toString()+"</b>");
if (runner()->hasBreakpointsSupport()) {
runToCursorAction_ = new QAction(tr("Run to cursor"), this);
runToCursorAction_->setShortcut(QKeySequence("F4"));
runToCursorAction_->setToolTip(tr("Run until the line editor cursor in")
+ "<b>" + runToCursorAction_->shortcut().toString() + "</b>");
connect(runToCursorAction_, SIGNAL(triggered()), this, SLOT(runToCursor()));
}
stopAction_ = new QAction(tr("Stop"), this);
stopAction_->setObjectName("run-stop");
// stopAction_->setIcon(QIcon(qtcreatorIconsPath+"stop.png"));
......@@ -158,6 +167,9 @@ void KumirProgram::createActions()
actions_->addAction(stepRunAction_);
actions_->addAction(stepInAction_);
actions_->addAction(stepOutAction_);
if (runToCursorAction_) {
actions_->addAction(runToCursorAction_);
}
}
Shared::RunInterface * KumirProgram::runner()
......@@ -408,6 +420,20 @@ void KumirProgram::stepOut()
runner()->runToEnd();
}
void KumirProgram::runToCursor()
{
using namespace Shared;
if (state_==Idle) {
emit giveMeAProgram();
prepareRunner(GeneratorInterface::LinesAndVariables);
state_ = RegularRun;
}
const quint32 currentLineNumber = editorInstance()->currentLineNumber();
const QString sourceProgramPath = editor_->documentContents().sourceUrl.toLocalFile();
runner()->insertSingleHitBreakpoint(sourceProgramPath, currentLineNumber);
regularRun();
}
void KumirProgram::stop()
{
if (state_==StepRun || state_==RegularRun || state_==TestingRun || state_==BlindRun) {
......
......@@ -60,6 +60,7 @@ public slots:
void stepRun();
void stepIn();
void stepOut();
void runToCursor();
void stop();
void switchGlobalState(ExtensionSystem::GlobalState old, ExtensionSystem::GlobalState cur);
void handleLineChanged(int lineNo, quint32 colStart, quint32 colEnd);
......@@ -91,6 +92,7 @@ private /*fields*/:
QAction * stepRunAction_;
QAction * stepInAction_;
QAction * stepOutAction_;
QAction * runToCursorAction_;
QAction * stopAction_;
QAction * toggleBreakpointAction_;
QActionGroup * actions_;
......
......@@ -1160,6 +1160,11 @@ void EditorInstance::saveDocument(QIODevice *device)
doc_->undoStack()->setClean();
}
uint32_t EditorInstance::currentLineNumber() const
{
return cursor_->row();
}
quint32 EditorInstance::errorLinesCount() const
{
QSet<int> lines;
......
......@@ -60,6 +60,7 @@ public:
void saveDocument(const QString &fileName);
void saveDocument(QIODevice * device);
uint32_t currentLineNumber() const;
void setKumFile(const Shared::Analizer::SourceFileInterface::Data & data);
void setPlainText(const QString & data);
void setDocumentId(int id);
......
......@@ -304,6 +304,12 @@ void Run::insertOrChangeBreakpoint(bool enabled, const QString &fileName, quint3
vm->insertOrChangeBreakpoint(enabled, wFileName, lineNo, ignoreCount, wCondition);
}
void Run::insertSingleHitBreakpoint(const QString &fileName, quint32 lineNo)
{
const String wFileName = fileName.toStdWString();
vm->insertSingleHitBreakpoint(wFileName, lineNo);
}
void Run::removeBreakpoint(const QString &fileName, quint32 lineNo)
{
const String wFileName = fileName.toStdWString();
......
......@@ -114,6 +114,7 @@ public slots:
void removeAllBreakpoints();
void insertOrChangeBreakpoint(bool enabled, const QString &fileName, quint32 lineNo, quint32 ignoreCount, const QString &condition);
void insertSingleHitBreakpoint(const QString &fileName, quint32 lineNo);
void removeBreakpoint(const QString &fileName, quint32 lineNo);
......
......@@ -454,6 +454,11 @@ void KumirRunPlugin::insertOrChangeBreakpoint(bool enabled, const QString &fileN
pRun_->insertOrChangeBreakpoint(enabled, fileName, lineNo, ignoreCount, condition);
}
void KumirRunPlugin::insertSingleHitBreakpoint(const QString &fileName, quint32 lineNo)
{
pRun_->insertSingleHitBreakpoint(fileName, lineNo);
}
void KumirRunPlugin::removeBreakpoint(const QString &fileName, quint32 lineNo)
{
pRun_->removeBreakpoint(fileName, lineNo);
......
......@@ -77,6 +77,7 @@ public slots:
void removeAllBreakpoints();
void insertOrChangeBreakpoint(bool enabled, const QString &fileName, quint32 lineNo, quint32 ignoreCount, const QString &condition);
void insertSingleHitBreakpoint(const QString & fileName, quint32 lineNo);
void removeBreakpoint(const QString &fileName, quint32 lineNo);
......
......@@ -64,6 +64,7 @@ public:
virtual QAction * toggleBreakpointAction() const = 0;
virtual QList<Breakpoint> breakpoints() const = 0;
virtual uint32_t currentLineNumber() const = 0;
};
......
......@@ -65,6 +65,8 @@ public:
quint32 /*lineNo*/, quint32 /*ignoreCount*/,
const QString & /*condition*/) {}
inline virtual void insertSingleHitBreakpoint(const QString &/*fileName*/, quint32 /*lineNo*/) {}
inline virtual void removeBreakpoint(const QString & /*fileName*/, quint32 /*lineNo*/) {}
};
......
......@@ -62,6 +62,7 @@ public /*methods*/:
/** Breakpoint operations */
inline void removeAllBreakpoints();
inline void insertOrChangeBreakpoint(const bool enabled, const String &fileName, const uint32_t lineNo, const uint32_t ignoreCount, const String &condition);
inline void insertSingleHitBreakpoint(const String &fileName, uint32_t lineNo);
inline void removeBreakpoint(const String &fileName, const uint32_t lineNo);
/** Sets the Debugging Interaction handler for this VM */
......@@ -725,6 +726,13 @@ void KumirVM::insertOrChangeBreakpoint(const bool enabled, const Kumir::String &
if (stacksMutex_) stacksMutex_->unlock();
}
void KumirVM::insertSingleHitBreakpoint(const Kumir::String &fileName, uint32_t lineNo)
{
if (stacksMutex_) stacksMutex_->lock();
breakpointsTable_.insertSingleHitBreakpoint(fileName, lineNo);
if (stacksMutex_) stacksMutex_->unlock();
}
void KumirVM::removeBreakpoint(const Kumir::String &fileName, const uint32_t lineNo)
{
if (stacksMutex_) stacksMutex_->lock();
......@@ -2912,7 +2920,7 @@ void KumirVM::do_line(const Bytecode::Instruction & instr)
if (!blindMode_ && debugHandler_) {
const uint8_t modId = currentContext().moduleId;
const int lineNo = currentContext().lineNo;
if (breakpointsTable_.isBreakpointHit(modId, lineNo, nullptr)) {
if (breakpointsTable_.processBreakpointHit(modId, lineNo, nullptr)) {
const String & sourceFileName = breakpointsTable_.registeredSourceFileName(modId);
debugHandler_->debuggerNoticeOnBreakpointHit(sourceFileName, uint32_t(lineNo));
}
......
......@@ -32,7 +32,7 @@ struct BreakpointData {
class BreakpointsTable {
public:
inline bool isBreakpointHit(const uint8_t modId, const int lineNo, const BreakpointConditionChecker * conditionChecker) const;
inline bool processBreakpointHit(const uint8_t modId, const int lineNo, const BreakpointConditionChecker * conditionChecker);
inline void reset();
inline void registerSourceFileName(const String & sourceFileName, const uint8_t modId);
......@@ -40,6 +40,7 @@ public:
inline void removeAllBreakpoints();
inline void insertOrChangeBreakpoint(const bool enabled, const String &fileName, const uint32_t lineNo, const uint32_t ignoreCount, const BreakpointCondition & condition);
inline void insertSingleHitBreakpoint(const Kumir::String &fileName, uint32_t lineNo);
inline void removeBreakpoint(const String &fileName, const uint32_t lineNo);
private:
......@@ -48,24 +49,32 @@ private:
typedef std::map<uint8_t,String> IdsToSourcesTable;
BreaksTable breakpoints_;
BreaksTable singleHits_;
SourcesToIdsTable sourceToIds_;
IdsToSourcesTable idsToSources_;
};
// ------------ INLINE IMPLEMENTATION
bool BreakpointsTable::isBreakpointHit(const uint8_t modId, const int lineNo, const BreakpointConditionChecker *conditionChecker) const
bool BreakpointsTable::processBreakpointHit(const uint8_t modId, const int lineNo, const BreakpointConditionChecker *conditionChecker)
{
if (-1 == lineNo)
return false;
bool result = false;
const BreakpointLocation loc(modId, lineNo);
BreaksTable::const_iterator locIt = breakpoints_.find(loc);
if (breakpoints_.end() != locIt) {
const BreakpointData & data = locIt->second;
if (data.enabled) {
result = true; // TODO check for hit count and condition
BreaksTable::iterator shitIt = singleHits_.find(loc);
if (singleHits_.end() != shitIt) {
result = true;
singleHits_.erase(shitIt);
}
if (!result) {
BreaksTable::const_iterator locIt = breakpoints_.find(loc);
if (breakpoints_.end() != locIt) {
const BreakpointData & data = locIt->second;
if (data.enabled) {
result = true; // TODO check for hit count and condition
}
}
}
return result;
......@@ -74,6 +83,7 @@ bool BreakpointsTable::isBreakpointHit(const uint8_t modId, const int lineNo, co
void BreakpointsTable::reset()
{
breakpoints_.clear();
singleHits_.clear();
sourceToIds_.clear();
idsToSources_.clear();
}
......@@ -91,6 +101,7 @@ const String &BreakpointsTable::registeredSourceFileName(const uint8_t &modId) c
void BreakpointsTable::removeAllBreakpoints()
{
singleHits_.clear();
breakpoints_.clear();
}
......@@ -117,6 +128,21 @@ void BreakpointsTable::insertOrChangeBreakpoint(const bool enabled, const String
}
}
void BreakpointsTable::insertSingleHitBreakpoint(const Kumir::String &fileName, uint32_t lineNo)
{
SourcesToIdsTable::const_iterator fnIt = sourceToIds_.find(fileName);
if (sourceToIds_.end() != fnIt) {
const uint8_t modId = fnIt->second;
const BreakpointLocation loc(modId, lineNo);
BreakpointData data;
data.condition = 0;
data.ignoreCount = 0;
data.hitCount = 0;
data.enabled = true;
singleHits_[loc] = data;
}
}
void BreakpointsTable::removeBreakpoint(const String &fileName, const uint32_t lineNo)
{
SourcesToIdsTable::const_iterator fnIt = sourceToIds_.find(fileName);
......
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