Skip to content

Commit

Permalink
Merge branch 'master' of github.com:royqh1979/RedPanda-CPP
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Qu committed Mar 17, 2023
2 parents 7093722 + af80ee0 commit fdc7bce
Show file tree
Hide file tree
Showing 23 changed files with 4,000 additions and 910 deletions.
19 changes: 16 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@ Red Panda C++ Version 2.18
- enhancement: Warn user and stop compile if project has missing files.
- enhancement: Warn user when exit and save settings failed.
- change: Remove compiler set options that's rarely used.
- enhancement: Options in compiler set settings, to generate syntax error for large stack objects. (Enable for Debug settings by default)
- enhancement: Options in compiler set settings, to generate protection code for stack smashing attack. (Enable for Debug settings by default)
- enhancement: Options in compiler set settings, to enable address sanitizer. Not available in windows.(Enable for Debug settings by default)
- enhancement: Add option in the compiler set settings, to generate syntax error for large stack objects. (Enable for Debug settings by default)
- enhancement: Add option in the compiler set settings, to generate protection code for stack smashing attack. (Enable for Debug settings by default)
- enhancement: Add option in the compiler set settings, to enable address sanitizer. Not available in windows.(Enable for Debug settings by default)
- fix: The comboxbox to input search keyword in the search dialog is case insensitive.
- fix: The comboxbox to input replace text in the search dialog is case insensitive.
- fix: The comboxbox to input search keyword in the search in files dialog is case insensitive.
- fix: The comboxbox to input address expression in the debug panel's memory view is case insensitive.
- fix: The comboxbox to input evaluation expression in the debug panel is case insensitive.
- fix: The comboxbox to input replace text in the search panel is case insensitive.
- fix: None initialized std::vector is not correctly displayed in the gdb of the gcc distributed with redpanda-c++ (Windows 64bit).
- fix: Don't show completion info when input parameters for function definitions.
- fix: Don't show function info tips when typing class variable definitions.
- enhancement: Add option in the debug settings, to limit the length of the ouput generated by gdb for arrays.
- enhancement: Show shortcut info in toolbar's tooltip.
- change: Use F11 as the shortcut for "Run". (It's the old shortcut for "Compile&Run")


Red Panda C++ Version 2.17

Expand Down
112 changes: 69 additions & 43 deletions RedPandaIDE/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1780,7 +1780,7 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
}
}

if (changes.testFlag(QSynedit::scInsertMode) | changes.testFlag(QSynedit::scReadOnly))
if (changes.testFlag(QSynedit::scInsertMode) || changes.testFlag(QSynedit::scReadOnly))
pMainWindow->updateForStatusbarModeInfo();

pMainWindow->updateEditorActions();
Expand Down Expand Up @@ -3573,45 +3573,71 @@ void Editor::cleanAutoBackup()
}
}

bool Editor::testInFunc(int x, int y)
bool Editor::testInFunc(const QSynedit::BufferCoord& pos)
{
bool result = false;
QString s = document()->getLine(y);
int posY = y;
int posX = std::min(x,s.length()-1); // x is started from 1
int bracketLevel=0;
while (true) {
while (posX < 0) {
posY--;
if (posY < 0)
return false;
s = document()->getLine(posY);
posX = s.length()-1;
}
if (s[posX] == '>'
|| s[posX] == ']') {
bracketLevel++;
} else if (s[posX] == '<'
|| s[posX] == '[') {
bracketLevel--;
} else if (bracketLevel==0) {
switch (s[posX].unicode()) {
case '(':
return true;
case ';':
case '{':
return false;
}
if (!(isIdentChar(s[posX])
|| s[posX] == ' '
|| s[posX] == '\t'
|| s[posX] == '*'
|| s[posX] == '&'))
break;;
}
posX--;
}
return result;
int y=pos.line-1;
int x=pos.ch;
if (!syntaxer() || syntaxer()->language()!=QSynedit::ProgrammingLanguage::CPP)
return false;
if (y==0)
syntaxer()->resetState();
else
syntaxer()->setState(document()->getSyntaxState(y-1));
syntaxer()->setLine(document()->getLine(y),y);
// qDebug()<<x<<document()->getLine(y).length();
QSynedit::SyntaxState state = syntaxer()->getState();
while(!syntaxer()->eol()) {
int start = syntaxer()->getTokenPos();
QString token = syntaxer()->getToken();
int end = start + token.length();
// qDebug()<<syntaxer()->getToken()<<start<<end;
if (end>=x)
break;
state = syntaxer()->getState();
syntaxer()->next();
}
// qDebug()<<state.parenthesisLevel;
return state.parenthesisLevel>0;


// bool result = false;
// QString s = document()->getLine(y);
// int posY = y;
// int posX = std::min(x,s.length()-1); // x is started from 1
// int bracketLevel=0;

// while (true) {
// while (posX < 0) {
// posY--;
// if (posY < 0)
// return false;
// s = document()->getLine(posY);
// posX = s.length()-1;
// }
// if (s[posX] == '>'
// || s[posX] == ']') {
// bracketLevel++;
// } else if (s[posX] == '<'
// || s[posX] == '[') {
// bracketLevel--;
// } else if (bracketLevel==0) {
// switch (s[posX].unicode()) {
// case '(':
// return true;
// case ';':
// case '{':
// return false;
// }
// if (!(isIdentChar(s[posX])
// || s[posX] == ' '
// || s[posX] == '\t'
// || s[posX] == '*'
// || s[posX] == '&'))
// break;;
// }
// posX--;
// }
// return result;
}

void Editor::completionInsert(bool appendFunc)
Expand Down Expand Up @@ -4188,7 +4214,6 @@ void Editor::updateFunctionTip(bool showTip)
QSynedit::BufferCoord pWordBegin, pWordEnd;

QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation);

int x = pWordBegin.ch-1-1;
QString line = document()->getLine(pWordBegin.line-1);
bool hasPreviousWord=false;
Expand All @@ -4206,9 +4231,10 @@ void Editor::updateFunctionTip(bool showTip)
break;
}

//handle class initializer
if (x >= 0 && hasPreviousWord) {
QSynedit::BufferCoord pos = pWordBegin;
pos.ch = x+1;
pos.ch = pWordBegin.ch;
QString previousWord = getPreviousWordAtPositionForSuggestion(pos);

PStatement statement = mParser->findStatementOf(
Expand Down Expand Up @@ -4779,7 +4805,7 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo
if ((p.line<1) || (p.line>document()->count())) {
return "";
}
bool inFunc = testInFunc(p.ch-1,p.line-1);
bool inFunc = testInFunc(p);

QString s = document()->getLine(p.line - 1);
int wordBegin;
Expand All @@ -4800,7 +4826,7 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo
else
return "";
} else if (bracketLevel==0) {
//we can't differentiate multiple definition and function parameter define here , so we don't handle ','
//Differentiate multiple definition and function parameter define here
if (s[wordEnd] == ',') {
if (inFunc) // in func, dont skip ','
break;
Expand Down
2 changes: 1 addition & 1 deletion RedPandaIDE/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private slots:
void saveAutoBackup();
void cleanAutoBackup();

bool testInFunc(int x,int y);
bool testInFunc(const QSynedit::BufferCoord& pos);

void completionInsert(bool appendFunc=false);

Expand Down
8 changes: 7 additions & 1 deletion RedPandaIDE/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include <QMimeDatabase>
#include <QMimeType>
#include <QToolTip>
#include <QCompleter>

#include "mainwindow.h"
#include <QScrollBar>
Expand Down Expand Up @@ -260,6 +261,11 @@ MainWindow::MainWindow(QWidget *parent)
// updateEditorActions();
// updateCaretActions();

ui->cbReplaceInHistory->completer()->setCaseSensitivity(Qt::CaseSensitive);
ui->cbEvaluate->completer()->setCaseSensitivity(Qt::CaseSensitive);
ui->cbMemoryAddress->completer()->setCaseSensitivity(Qt::CaseSensitive);
ui->cbFilesPath->completer()->setCaseSensitivity(Qt::CaseInsensitive);

connect(ui->debugConsole,&QConsole::commandInput,this,&MainWindow::onDebugCommandInput);
connect(ui->cbEvaluate->lineEdit(), &QLineEdit::returnPressed,
this, &MainWindow::onDebugEvaluateInput);
Expand Down Expand Up @@ -2389,7 +2395,7 @@ void MainWindow::debug()
mDebugger->sendCommand("-gdb-set", "width 0"); // don't wrap output, very annoying
mDebugger->sendCommand("-gdb-set", "confirm off");
mDebugger->sendCommand("-gdb-set", "print repeats 0"); // don't repeat elements
mDebugger->sendCommand("-gdb-set", "print elements 0"); // don't limit elements
mDebugger->sendCommand("-gdb-set", QString("print elements %1").arg(pSettings->debugger().arrayElements())); // limit array elements to 500
mDebugger->sendCommand("-environment-cd", QString("\"%1\"").arg(extractFileDir(filePath))); // restore working directory
if (pSettings->debugger().useGDBServer()) {
mDebugger->sendCommand("-target-select",QString("remote localhost:%1").arg(pSettings->debugger().GDBServerPort()));
Expand Down
7 changes: 3 additions & 4 deletions RedPandaIDE/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
Expand Down Expand Up @@ -971,7 +971,6 @@
<widget class="IssuesTable" name="tableIssues">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
Expand Down Expand Up @@ -1133,7 +1132,7 @@
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<widget class="QWidget" name="tabDebugConsole">
<attribute name="title">
Expand Down Expand Up @@ -2167,7 +2166,7 @@
<string>Run</string>
</property>
<property name="shortcut">
<string>F10</string>
<string>F11</string>
</property>
</action>
<action name="actionUndo">
Expand Down
11 changes: 8 additions & 3 deletions RedPandaIDE/parser/statementmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void StatementModel::clear() {
#endif
}

#ifdef QT_DEBUG
void StatementModel::dump(const QString &logFile)
{
QFile file(logFile);
Expand All @@ -93,7 +94,6 @@ void StatementModel::dump(const QString &logFile)
}
}

#ifdef QT_DEBUG
void StatementModel::dumpAll(const QString &logFile)
{
QFile file(logFile);
Expand All @@ -104,11 +104,16 @@ void StatementModel::dumpAll(const QString &logFile)
.arg(statement->command).arg(int(statement->kind))
.arg(statement->type).arg(statement->fullName)
.arg((size_t)(statement->parentScope.lock().get()))
.arg((int)statement->classScope)
.arg((int)statement->accessibility)
.arg(statement->fileName)
.arg(statement->line)
.arg(statement->definitionFileName)
.arg(statement->definitionLine)<<endl;
.arg(statement->definitionLine)<<
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
Qt::endl;
#else
endl;
#endif
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion RedPandaIDE/parser/statementmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class StatementModel : public QObject
const StatementMap& childrenStatements(const PStatement& statement = PStatement()) const;
const StatementMap& childrenStatements(std::weak_ptr<Statement> statement) const;
void clear();
void dump(const QString& logFile);
#ifdef QT_DEBUG
void dump(const QString& logFile);
void dumpAll(const QString& logFile);
#endif
private:
Expand Down
12 changes: 12 additions & 0 deletions RedPandaIDE/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4020,6 +4020,16 @@ void Settings::Debugger::setAutosave(bool newAutosave)
mAutosave = newAutosave;
}

int Settings::Debugger::arrayElements() const
{
return mArrayElements;
}

void Settings::Debugger::setArrayElements(int newArrayElements)
{
mArrayElements = newArrayElements;
}

bool Settings::Debugger::useIntelStyle() const
{
return mUseIntelStyle;
Expand Down Expand Up @@ -4068,6 +4078,7 @@ void Settings::Debugger::doSave()
saveValue("gdb_server_port",mGDBServerPort);
saveValue("memory_view_rows",mMemoryViewRows);
saveValue("memory_view_columns",mMemoryViewColumns);
saveValue("array_elements",mArrayElements);
}

void Settings::Debugger::doLoad()
Expand Down Expand Up @@ -4096,6 +4107,7 @@ void Settings::Debugger::doLoad()
mGDBServerPort = intValue("gdb_server_port",41234);
mMemoryViewRows = intValue("memory_view_rows",16);
mMemoryViewColumns = intValue("memory_view_columns",16);
mArrayElements = intValue("array_elements",300);
}

Settings::CodeCompletion::CodeCompletion(Settings *settings):_Base(settings, SETTING_CODE_COMPLETION)
Expand Down
4 changes: 4 additions & 0 deletions RedPandaIDE/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,9 @@ class Settings
bool autosave() const;
void setAutosave(bool newAutosave);

int arrayElements() const;
void setArrayElements(int newArrayElements);

private:
bool mEnableDebugConsole;
bool mShowDetailLog;
Expand All @@ -1298,6 +1301,7 @@ class Settings
int mGDBServerPort;
int mMemoryViewRows;
int mMemoryViewColumns;
int mArrayElements;

// _Base interface
protected:
Expand Down
3 changes: 3 additions & 0 deletions RedPandaIDE/settingsdialog/debuggeneralwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void DebugGeneralWidget::doLoad()
ui->spinGDBServerPort->setValue(pSettings->debugger().GDBServerPort());
ui->spinMemoryViewRows->setValue(pSettings->debugger().memoryViewRows());
ui->spinMemoryViewColumns->setValue(pSettings->debugger().memoryViewColumns());
ui->spinArrayElements->setValue(pSettings->debugger().arrayElements());
}

void DebugGeneralWidget::doSave()
Expand All @@ -78,6 +79,8 @@ void DebugGeneralWidget::doSave()
pSettings->debugger().setGDBServerPort(ui->spinGDBServerPort->value());
pSettings->debugger().setMemoryViewRows(ui->spinMemoryViewRows->value());
pSettings->debugger().setMemoryViewColumns(ui->spinMemoryViewColumns->value());
pSettings->debugger().setArrayElements(ui->spinArrayElements->value());

pSettings->debugger().save();
pMainWindow->updateDebuggerSettings();
}
Expand Down
Loading

0 comments on commit fdc7bce

Please sign in to comment.