Skip to content

Commit

Permalink
[FIXED] warn if the source code is not compiled after the change befo…
Browse files Browse the repository at this point in the history
…re run / debug

[FIXED] warn if the source code is changed and not save before run / debug
[FIXED] the document is in read-only mode during the debugging
[FIXED] #636 - IDE bugs
  • Loading branch information
arakov committed Mar 6, 2024
1 parent 83dc4c4 commit 7eeece0
Show file tree
Hide file tree
Showing 25 changed files with 397 additions and 171 deletions.
13 changes: 2 additions & 11 deletions doc/todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In development:
opt: #601,#602
maint:tools:backlog,#616, system module warnings, #622
exp:snake game : text / gui version, using expression trees in real-life apps (see c#)
ide:backlog (#617), vm debugger, debugger watch - struct
ide:backlog (#617), vm debugger, include / exclude files
tools:work with elt in ide
prom:#635,elena in nutshell every 2 week
port:x86 mt, x86-64 vm,elenavm / elt for linux
Expand All @@ -29,16 +29,7 @@ In development:
- step over - to the same row - must be auto skipped?
- fix #634
--------------------------------------

- Applying changes to the source file via the IDE and trying to run it does not produce the expected results. Also adding syntax errors intentionally does not affect the execution
- solution - do not run if the program is not saved. Warn if the source code is younger than the modules


- I put the code in a file (not a project) and tried to use Debug --> Run to execute it, there is a window that opens and closes very quickly but the output is not redirected in any of the available panels (Output, Messages, Interactive). In the Interactive panel there is an error message: Redirect console error: 2
- I set a breakpoint using F5, but Debug->Run ignores the breakpoint
- F8 (Step Over) leads to an error "The source code is not found. Do you want to continue?"

- #636
- highlight error - set a focus on textview

- Sorting algorithms/Sleep sort

Expand Down
6 changes: 5 additions & 1 deletion elenasrc3/gui/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ void TextViewController :: undo(TextViewModelBase* model)
{
DocumentChangeStatus status = {};
auto docView = model->DocView();
if (docView->isReadOnly())
return;

docView->undo(status);

Expand All @@ -114,6 +116,8 @@ void TextViewController :: redo(TextViewModelBase* model)
auto docView = model->DocView();

docView->redo(status);
if (docView->isReadOnly())
return;

notifyTextModelChange(model, status);
}
Expand Down Expand Up @@ -468,7 +472,7 @@ bool TextViewController :: replaceText(TextViewModelBase* model, FindModel* find
DocumentChangeStatus docStatus = {};

auto docView = model->DocView();
if (docView) {
if (docView && !docView->isReadOnly()) {
docView->insertLine(docStatus, findModel->newText.str(), findModel->newText.length());
notifyTextModelChange(model, docStatus);

Expand Down
6 changes: 6 additions & 0 deletions elenasrc3/gui/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace elena_lang
bool formatterChanged;
bool textChanged;
bool modifiedChanged;
bool readOnlyChanged;

bool isViewChanged()
{
Expand All @@ -120,6 +121,7 @@ namespace elena_lang
selelectionChanged = false;
formatterChanged = false;
textChanged = false;
readOnlyChanged = false;
}

DocumentChangeStatus()
Expand Down Expand Up @@ -284,6 +286,10 @@ namespace elena_lang
{
setCaret(caret.x, caret.y, selecting, changeStatus);
}
void setReadOnlyMode(bool mode)
{
status.readOnly = mode;
}

int getRowCount() const { return _text->getRowCount(); }
int getMaxColumn() const { return _maxColumn; }
Expand Down
24 changes: 23 additions & 1 deletion elenasrc3/gui/view.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------------
// E L E N A P r o j e c t: ELENA IDE
// IDE View class header File
// (C)2021-2022, by Aleksey Rakov
// (C)2021-2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#ifndef VIEW_H
Expand Down Expand Up @@ -81,6 +81,28 @@ namespace elena_lang

void resize(Point size) override;

bool isAnyDocumentModified()
{
auto it = _documents.start();
while (!it.eof()) {
if ((*it)->documentView->isModified())
return true;

it++;
}
return false;
}

void setReadOnlyMode(bool mode)
{
auto it = _documents.start();
while (!it.eof()) {
(*it)->documentView->setReadOnlyMode(mode);

it++;
}
}

TextViewModel();
virtual ~TextViewModel() = default;
};
Expand Down
22 changes: 21 additions & 1 deletion elenasrc3/gui/windows/wincommon.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
//---------------------------------------------------------------------------
// E L E N A P r o j e c t: ELENA IDE
// WinAPI Common Body File
// (C)2021-2022, by Aleksey Rakov
// (C)2021-2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#include "wincommon.h"

using namespace elena_lang;

// --- DateTime ---

DateTime DateTime::getFileTime(const wchar_t* path)
{
DateTime dt;

HANDLE hFile = ::CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile) {
FILETIME ftCreate, ftAccess, ftWrite;

if (::GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite)) {
FileTimeToSystemTime(&ftWrite, &dt._time);
}

::CloseHandle(hFile);
}

return dt;
}

// --- ControlBase ---

HWND ControlBase :: create(HINSTANCE instance, wstr_t className, ControlBase* owner)
Expand Down
53 changes: 53 additions & 0 deletions elenasrc3/gui/windows/wincommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,59 @@

namespace elena_lang
{
// --- DateTime ---

struct DateTime
{
private:
SYSTEMTIME _time;

public:
static DateTime getFileTime(const wchar_t* path);

bool operator > (const DateTime dt) const
{
if (_time.wYear > dt._time.wYear)
return true;

if (_time.wYear == dt._time.wYear) {
if (_time.wMonth > dt._time.wMonth)
return true;

if (_time.wMonth == dt._time.wMonth) {
if (_time.wDay > dt._time.wDay)
return true;

if (_time.wDay == dt._time.wDay) {
if (_time.wHour > dt._time.wHour)
return true;

if (_time.wHour == dt._time.wHour) {
if (_time.wMinute > dt._time.wMinute)
return true;

if (_time.wMinute == dt._time.wMinute) {
if (_time.wSecond > dt._time.wSecond)
return true;

if (_time.wSecond == dt._time.wSecond) {
return (_time.wMilliseconds > dt._time.wMilliseconds);
}
}
}
}
}
}
return false;
}

DateTime()
{
_time.wYear = 0;
//memset(&_time, 0, sizeof(_time));
}
};

// --- Cursor types ---
constexpr int CURSOR_TEXT = 0;
constexpr int CURSOR_ARROW = 1;
Expand Down
10 changes: 8 additions & 2 deletions elenasrc3/gui/windows/wintextview.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------------
// E L E N A P r o j e c t: ELENA IDE
// WinAPI TextView Control Body File
// (C)2021-2023, by Aleksey Rakov
// (C)2021-2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#include "wintextview.h"
Expand Down Expand Up @@ -43,7 +43,8 @@ void ViewStyles::release()
// --- TextViewWindow ---

TextViewWindow :: TextViewWindow(NotifierBase* notifier, TextViewModelBase* model,
TextViewControllerBase* controller, ViewStyles* styles, ContextInvoker contextInvoker)
TextViewControllerBase* controller, ViewStyles* styles,
ContextInvoker contextInvoker, MarginInvoker marginInvoker)
: WindowBase(nullptr, 50, 50)
{
_notifier = notifier;
Expand All @@ -57,6 +58,7 @@ TextViewWindow :: TextViewWindow(NotifierBase* notifier, TextViewModelBase* mode
_mouseCaptured = false;
_caret_x = 0;
_contextInvoker = contextInvoker;
_marginInvoker = marginInvoker;
}

TextViewWindow :: ~TextViewWindow()
Expand Down Expand Up @@ -457,6 +459,10 @@ void TextViewWindow :: onButtonDown(Point point, bool kbShift)

_controller->moveToFrame(_model, col, row, kbShift);

if (margin && _marginInvoker) {
_marginInvoker(_notifier);
}

captureMouse();
}

Expand Down
7 changes: 5 additions & 2 deletions elenasrc3/gui/windows/wintextview.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------------
// E L E N A P r o j e c t: ELENA IDE
// WinAPI TextView Control Header File
// (C)2021-2022, by Aleksey Rakov
// (C)2021-2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#ifndef WINTEXTVIEW_H
Expand Down Expand Up @@ -75,11 +75,13 @@ namespace elena_lang
{
public:
typedef void(*ContextInvoker)(NotifierBase*, int, int, bool);
typedef void(*MarginInvoker)(NotifierBase*);

protected:
NotifierBase* _notifier;

ContextInvoker _contextInvoker;
MarginInvoker _marginInvoker;

TextViewModelBase* _model;
ViewStyles* _styles;
Expand Down Expand Up @@ -161,7 +163,8 @@ namespace elena_lang

LRESULT proceed(UINT message, WPARAM wParam, LPARAM lParam) override;

TextViewWindow(NotifierBase* notifier, TextViewModelBase* model, TextViewControllerBase* controller, ViewStyles* styles, ContextInvoker contextInvoker);
TextViewWindow(NotifierBase* notifier, TextViewModelBase* model, TextViewControllerBase* controller, ViewStyles* styles,
ContextInvoker contextInvoker, MarginInvoker marginInvoker);
virtual ~TextViewWindow();
};
}
Expand Down
15 changes: 9 additions & 6 deletions elenasrc3/ide/debugcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,9 @@ void DebugController :: onCurrentStep(DebugLineInfo* lineInfo, ustr_t moduleName
found = _sourceController->selectSource(_model, _sourceModel, moduleName, *path);
}

_sourceController->traceSource(_sourceModel, found, lineInfo->row);
_sourceController->traceStep(_sourceModel, found, lineInfo->row);
}
else _sourceController->traceSource(_sourceModel, false, -1);
else _sourceController->traceStep(_sourceModel, false, -1);
}

void DebugController :: onStop()
Expand All @@ -682,7 +682,7 @@ void DebugController :: onStop()
_currentModule.clear();
_currentPath = nullptr;

_sourceController->onProgramFinish(_sourceModel);
_sourceController->traceFinish(_sourceModel);
}

void DebugController :: run()
Expand Down Expand Up @@ -726,13 +726,16 @@ void DebugController :: runToCursor(ustr_t ns, ustr_t path, int row)
_process->setEvent(DEBUG_RESUME);
}

void DebugController :: addBreakpoint(Breakpoint* bp)
void DebugController :: toggleBreakpoint(Breakpoint* bp, bool adding)
{
ModuleBase* currentModule = _provider.resolveModule(*bp->module);
if (currentModule != nullptr) {
addr_t address = _provider.findNearestAddress(currentModule, *bp->source, bp->row);
if (address != INVALID_ADDR) {
_process->addBreakpoint(address);
if (adding) {
_process->addBreakpoint(address);
}
else _process->removeBreakpoint(address);
}
}
}
Expand Down Expand Up @@ -858,7 +861,7 @@ void DebugController :: loadDebugSection(StreamReader& reader, bool starting)
if (!reader.eof()) {
_provider.load(reader, starting, _process);

_sourceController->onProgramStart(_model);
_sourceController->traceStart(_model);

_provider.setDebugInfoSize(reader.position());

Expand Down
9 changes: 5 additions & 4 deletions elenasrc3/ide/debugcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ namespace elena_lang
class DebugSourceController
{
public:
virtual void traceSource(SourceViewModel* sourceModel, bool found, int row) = 0;
virtual void traceStart(ProjectModel* model) = 0;

virtual void traceStep(SourceViewModel* sourceModel, bool found, int row) = 0;

virtual bool selectSource(ProjectModel* model, SourceViewModel* sourceModel,
ustr_t moduleName, path_t sourcePath) = 0;

virtual void onProgramStart(ProjectModel* model) = 0;
virtual void onProgramFinish(SourceViewModel* sourceModel) = 0;
virtual void traceFinish(SourceViewModel* sourceModel) = 0;

virtual ~DebugSourceController() = default;
};
Expand Down Expand Up @@ -275,7 +276,7 @@ namespace elena_lang
void stepInto();
void stop();
void runToCursor(ustr_t name, ustr_t path, int row);
void addBreakpoint(Breakpoint* bp);
void toggleBreakpoint(Breakpoint* bp, bool adding);

void readAutoContext(ContextBrowserBase* watch, int level, WatchItems* refreshedItems);
void readContext(ContextBrowserBase* watch, void* parentItem, addr_t address, int level);
Expand Down
5 changes: 4 additions & 1 deletion elenasrc3/ide/eng/messages.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------------
// E L E N A P r o j e c t: ELENA IDE Messages
//
// (C)2021-2023, by Aleksex Rakov
// (C)2021-2024, by Aleksex Rakov
//---------------------------------------------------------------------------

#ifndef MESSAGES_H
Expand All @@ -19,6 +19,9 @@ namespace elena_lang
constexpr auto QUESTION_CLOSE_UNSAVED = _T("Close the tab anyway");
constexpr auto QUESTION_NOSOURCE_CONTINUE = _T("The source code is not found. Do you want to continue?");

constexpr auto INFO_RUN_OUT_OF_DATE = _T("The project modules are out of date\nPlease recompile the project");
constexpr auto INFO_RUN_UNSAVED_PROJECT = _T("The project files are not saved\nPlease save them and recompile the project");

constexpr auto NOT_FOUND_TEXT = _T("Search string not found");
constexpr auto REPLACE_TEXT = _T("Replace this occurence?");

Expand Down
Loading

0 comments on commit 7eeece0

Please sign in to comment.