work save

This commit is contained in:
royqh1979@gmail.com 2021-08-27 23:51:42 +08:00
parent a5239aea48
commit 19e37b6ae7
12 changed files with 148 additions and 87 deletions

View File

@ -69,6 +69,7 @@ SOURCES += \
utils.cpp \
widgets/coloredit.cpp \
widgets/consolewidget.cpp \
widgets/elidedlabel.cpp \
widgets/issuestable.cpp \
widgets/qconsole.cpp \
widgets/qpatchedcombobox.cpp \
@ -134,6 +135,7 @@ HEADERS += \
common.h \
widgets/coloredit.h \
widgets/consolewidget.h \
widgets/elidedlabel.h \
widgets/issuestable.h \
widgets/qconsole.h \
widgets/qpatchedcombobox.h \

View File

@ -1620,6 +1620,7 @@ static int getWatchIndex(WatchVar* var, const QList<PWatchVar> list) {
return i;
}
}
return -1;
}
QModelIndex WatchModel::parent(const QModelIndex &index) const

View File

@ -741,7 +741,7 @@ void Editor::onStatusChanged(SynStatusChanges changes)
pMainWindow->checkSyntaxInBack(this);
}
mLineCount = lines()->count();
// if (not (scOpenFile in Changes)) and (fText.Lines.Count <> fLineCount)
// if (not (scOpenFile in Changes)) and (fText.Lines.Count <> fLineCount)
// and (fText.Lines.Count <> 0) and ((fLineCount>0) or (fText.Lines.Count>1)) then begin
// if devCodeCompletion.Enabled
// and SameStr(mainForm.ClassBrowser.CurrentFile,FileName) // Don't reparse twice

View File

@ -43,15 +43,12 @@ MainWindow::MainWindow(QWidget *parent)
mFileInfoStatus=new QLabel();
mFileEncodingStatus = new QLabel();
mFileModeStatus = new QLabel();
mParsingInfoStatus = new QLabel();
mFileInfoStatus->setStyleSheet("margin-left:10px; margin-right:10px");
mFileEncodingStatus->setStyleSheet("margin-left:10px; margin-right:10px");
mFileModeStatus->setStyleSheet("margin-left:10px; margin-right:10px");
mParsingInfoStatus->setStyleSheet("margin-left:10px; margin-right:10px");
ui->statusbar->addWidget(mFileInfoStatus);
ui->statusbar->addWidget(mFileEncodingStatus);
ui->statusbar->addWidget(mFileModeStatus);
ui->statusbar->addWidget(mParsingInfoStatus);
ui->statusbar->insertPermanentWidget(0,mFileModeStatus);
ui->statusbar->insertPermanentWidget(0,mFileEncodingStatus);
ui->statusbar->insertPermanentWidget(0,mFileInfoStatus);
mEditorList = new EditorList(ui->EditorTabsLeft,
ui->EditorTabsRight,
ui->splitterEditorPanel,
@ -463,7 +460,7 @@ void MainWindow::updateForStatusbarModeInfo()
void MainWindow::updateStatusBarForParsing(const QString &s)
{
mParsingInfoStatus->setText(s);
ui->statusbar->showMessage(s);
}
void MainWindow::openFiles(const QStringList &files)

View File

@ -5,6 +5,7 @@
#include "common.h"
#include "widgets/searchresultview.h"
#include "widgets/classbrowser.h"
#include "widgets/elidedlabel.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
@ -220,7 +221,6 @@ private:
QLabel *mFileInfoStatus;
QLabel *mFileEncodingStatus;
QLabel *mFileModeStatus;
QLabel *mParsingInfoStatus;
QMenu *mMenuEncoding;
QMenu *mMenuEncodingList;
QMenu *mMenuRecentFiles;

View File

@ -77,7 +77,7 @@
<widget class="QTabWidget" name="tabInfos">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>1</horstretch>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
@ -85,7 +85,7 @@
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>2</number>
<number>1</number>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
@ -168,7 +168,7 @@
<widget class="QWidget" name="EditorPanel" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>2</horstretch>
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
@ -190,6 +190,12 @@
</property>
<item>
<widget class="QSplitter" name="splitterEditorPanel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -197,6 +203,12 @@
<number>1</number>
</property>
<widget class="QTabWidget" name="EditorTabsLeft">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>-1</number>
</property>

View File

@ -2929,15 +2929,13 @@ void CppParser::internalParse(const QString &fileName)
// mPreprocessor.setIncludePaths(mIncludePaths);
// mPreprocessor.setProjectIncludePaths(mProjectIncludePaths);
mPreprocessor.setScanOptions(mParseGlobalHeaders, mParseLocalHeaders);
logToFile("preprocess + 1:","f:\\log.txt");
mPreprocessor.preprocess(fileName, buffer);
StringsToFile(mPreprocessor.result(),"f:\\preprocess.txt");
// Tokenize the preprocessed buffer file
mTokenizer.tokenize(mPreprocessor.result());
if (mTokenizer.tokenCount() == 0)
return;
mTokenizer.dumpTokens("f:\\tokens.txt");
// Process the token list
mCurrentScope.clear();
@ -2952,10 +2950,16 @@ void CppParser::internalParse(const QString &fileName)
if (!handleStatement())
break;
}
// mPreprocessor.dumpDefinesTo("f:\\defines.txt");
// mPreprocessor.dumpIncludesListTo("f:\\includes.txt");
//#ifdef QT_DEBUG
StringsToFile(mPreprocessor.result(),"f:\\preprocess.txt");
mPreprocessor.dumpDefinesTo("f:\\defines.txt");
mPreprocessor.dumpIncludesListTo("f:\\includes.txt");
mStatementList.dump("f:\\stats.txt");
// mStatementList.dumpAll("f:\\all-stats.txt");
mTokenizer.dumpTokens("f:\\tokens.txt");
//#endif
#ifdef QT_DEBUG
mStatementList.dumpAll("f:\\all-stats.txt");
#endif
}
}
@ -3120,8 +3124,6 @@ PStatement CppParser::doFindStatementInScope(const QString &name, const QString
void CppParser::internalInvalidateFile(const QString &fileName)
{
logToFile(QString("invalidate %1 start:").arg(fileName),"f:\\log.txt");
if (fileName.isEmpty())
return;
@ -3140,10 +3142,8 @@ void CppParser::internalInvalidateFile(const QString &fileName)
mNamespaces.remove(key);
}
}
logToFile(QString("invalidate %1 1:").arg(fileName),"f:\\log.txt");
// delete it from scannedfiles
mPreprocessor.scannedFiles().remove(fileName);
logToFile(QString("invalidate %1 2:").arg(fileName),"f:\\log.txt");
// remove its include files list
PFileIncludes p = findFileIncludes(fileName, true);
@ -3160,12 +3160,10 @@ void CppParser::internalInvalidateFile(const QString &fileName)
statement->hasDefinition = false;
}
}
logToFile(QString("invalidate %1 3:").arg(fileName),"f:\\log.txt");
for (PStatement statement:p->declaredStatements) {
mStatementList.deleteStatement(statement);
}
logToFile(QString("invalidate %1 4:").arg(fileName),"f:\\log.txt");
//p->declaredStatements.clear();
//p->statements.clear();
@ -3173,15 +3171,11 @@ void CppParser::internalInvalidateFile(const QString &fileName)
//p->dependedFiles.clear();
//p->dependingFiles.clear();
}
logToFile(QString("invalidate %1 10:").arg(fileName),"f:\\log.txt");
logToFile(QString("invalidate %1 end:").arg(fileName),"f:\\log.txt");
}
void CppParser::internalInvalidateFiles(const QSet<QString> &files)
{
for (QString file:files)
for (const QString& file:files)
internalInvalidateFile(file);
}

View File

@ -215,7 +215,6 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const
QString CppPreprocessor::getNextPreprocessor()
{
logToFile("next preprocessor:","f:\\log.txt");
skipToPreprocessor(); // skip until # at start of line
int preProcFrom = mIndex;
if (preProcFrom >= mBuffer.count())
@ -229,7 +228,7 @@ QString CppPreprocessor::getNextPreprocessor()
// Assemble whole line, convert newlines to space
QString result;
for (int i=preProcFrom;i<=preProcTo;i++) {
if (mBuffer[i].endsWith('/')) {
if (mBuffer[i].endsWith('\\')) {
result+=mBuffer[i].mid(0,mBuffer[i].size()-1)+' ';
} else {
result+=mBuffer[i]+' ';
@ -736,67 +735,112 @@ void CppPreprocessor::parseArgs(PDefine define)
define->argList[i]=define->argList[i].trimmed();
define->argUsed.append(false);
}
QStringList tokens = tokenizeValue(define->value);
QList<PDefineArgToken> tokens = tokenizeValue(define->value);
QString formatStr = "";
QString lastToken = "##";
for (QString token: tokens) {
if (lastToken != "##" && token!="##") {
formatStr += ' ';
}
int index = define->argList.indexOf(token);
if (index>=0) {
define->argUsed[index] = true;
if (lastToken == "#") {
formatStr+= "\"%"+QString("%1").arg(index+1)+"\"";
} else {
formatStr+= "%"+QString("%1").arg(index+1);
DefineArgTokenType lastTokenType=DefineArgTokenType::Other;
int index;
for (PDefineArgToken token: tokens) {
switch(token->type) {
case DefineArgTokenType::Identifier:
index = define->argList.indexOf(token->value);
if (index>=0) {
define->argUsed[index] = true;
if (lastTokenType == DefineArgTokenType::Sharp) {
formatStr+= "\"%"+QString("%1").arg(index+1)+"\"";
break;
} else {
formatStr+= "%"+QString("%1").arg(index+1);
break;
}
}
} else if (token == "%"){
formatStr+="%%";
} else if (token!="##" && token!="#"){
formatStr+=token;
formatStr += token->value;
break;
case DefineArgTokenType::DSharp:
case DefineArgTokenType::Sharp:
break;
case DefineArgTokenType::Space:
case DefineArgTokenType::Symbol:
formatStr+=token->value;
break;
}
lastToken = token;
lastTokenType = token->type;
}
define->formatValue = formatStr;
}
QStringList CppPreprocessor::tokenizeValue(const QString &value)
QList<PDefineArgToken> CppPreprocessor::tokenizeValue(const QString &value)
{
int i=0;
QString token;
QStringList tokens;
PDefineArgToken token = std::make_shared<DefineArgToken>();
token->type = DefineArgTokenType::Other;
QList<PDefineArgToken> tokens;
bool skipSpaces=false;
while (i<value.length()) {
QChar ch = value[i];
if (isSpaceChar(ch)) {
if(!token.isEmpty())
if (token->type==DefineArgTokenType::Other) {
token->value = " ";
token->type = DefineArgTokenType::Space;
} else if (token->type!=DefineArgTokenType::Space) {
tokens.append(token);
token = "";
token = std::make_shared<DefineArgToken>();
token->value = " ";
token->type = DefineArgTokenType::Space;
}
i++;
} else if (ch=='#') {
if(!token.isEmpty())
if (token->type!=DefineArgTokenType::Other
&& token->type!=DefineArgTokenType::Space) {
tokens.append(token);
token = "";
token = std::make_shared<DefineArgToken>();
}
if ((i+1<value.length()) && (value[i+1]=='#')) {
i+=2;
tokens.append("##");
token->value = "##";
token->type = DefineArgTokenType::DSharp;
} else {
i++;
tokens.append("#");
token->value = "#";
token->type = DefineArgTokenType::Sharp;
}
skipSpaces=true;
tokens.append(token);
token = std::make_shared<DefineArgToken>();
token->value = "";
token->type = DefineArgTokenType::Other;
} else if (isWordChar(ch)) {
token+=ch;
if (token->type==DefineArgTokenType::Other) {
token->value = ch ;
token->type = DefineArgTokenType::Identifier;
} else if (token->type==DefineArgTokenType::Identifier) {
token->value+=ch;
} else if (skipSpaces && token->type==DefineArgTokenType::Space) {
//dont use space;
token->value = ch ;
token->type = DefineArgTokenType::Identifier;
} else {
tokens.append(token);
token = std::make_shared<DefineArgToken>();
token->value = ch ;
token->type = DefineArgTokenType::Identifier;
}
skipSpaces=false;
i++;
} else {
if(!token.isEmpty())
if (skipSpaces && token->type==DefineArgTokenType::Space) {
//dont use space;
} else if (token->type!=DefineArgTokenType::Other) {
tokens.append(token);
token = "";
tokens.append(ch);
token = std::make_shared<DefineArgToken>();
}
skipSpaces=false;
token->value = ch ;
token->type = DefineArgTokenType::Symbol;
i++;
}
}
if(!token.isEmpty())
if(token->type!=DefineArgTokenType::Other)
tokens.append(token);
return tokens;
}
@ -901,7 +945,11 @@ QStringList CppPreprocessor::removeComments(const QStringList &text)
ch = line[pos];
s+=ch;
}
break;
default:
s+=ch;
}
break;
default:
s+=ch;
}
@ -940,17 +988,13 @@ void CppPreprocessor::skipToEndOfPreprocessor()
void CppPreprocessor::skipToPreprocessor()
{
logToFile("skip:","f:\\log.txt");
// Increment until a line begins with a #
while ((mIndex < mBuffer.count()) && !mBuffer[mIndex].startsWith('#')) {
logToFile(QString("tt %1 tt").arg(mIndex),"f:\\log.txt");
logToFile(QString("tt %1 tt").arg(mBuffer[mIndex]),"f:\\log.txt");
// if (getCurrentBranch()) // if not skipping, expand current macros
// mResult.append(expandMacros(mBuffer[mIndex],1));
// else // If skipping due to a failed branch, clear line
// mResult.append("");
mResult.append(mBuffer[mIndex]);
if (getCurrentBranch()) // if not skipping, expand current macros
mResult.append(expandMacros(mBuffer[mIndex],1));
else // If skipping due to a failed branch, clear line
mResult.append("");
mIndex++;
}
}
@ -1163,11 +1207,8 @@ QString CppPreprocessor::expandFunction(PDefine define, QString args)
{
// Replace function by this string
QString result = define->formatValue;
if (args.startsWith('(')) {
args.remove(0,1);
}
if (args.endsWith(')')) {
args.remove(args.length()-1,1);
if (args.startsWith('(') && args.endsWith(')')) {
args = args.mid(1,args.length()-2);
}
QStringList argValues = args.split(",");

View File

@ -6,6 +6,19 @@
#include "parserutils.h"
#define MAX_DEFINE_EXPAND_DEPTH 20
enum class DefineArgTokenType{
Symbol,
Identifier,
Space,
Sharp,
DSharp,
Other
};
struct DefineArgToken {
QString value;
DefineArgTokenType type;
};
using PDefineArgToken = std::shared_ptr<DefineArgToken>;
struct ParsedFile {
int index; // 0-based for programming convenience
@ -91,7 +104,7 @@ private:
void addDefinesInFile(const QString& fileName);
void parseArgs(PDefine define);
QStringList tokenizeValue(const QString& value);
QList<PDefineArgToken> tokenizeValue(const QString& value);
QStringList removeComments(const QStringList& text);
/*

View File

@ -114,7 +114,6 @@ int StatementModel::deleteMember(StatementMap &map, PStatement statement)
{
if (!statement)
return 0;
//return map.remove(statement->command,statement);
return map.remove(statement->command,statement);
}

View File

@ -15,6 +15,7 @@
#include <QGuiApplication>
#include <QInputMethodEvent>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QStyleHints>
SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent)
@ -1291,7 +1292,7 @@ void SynEdit::doSelectAll()
}
setCaretAndSelection(caretXY(), BufferCoord{1, 1}, LastPt);
// Selection should have changed...
statusChanged(SynStatusChange::scSelection);
emit statusChanged(SynStatusChange::scSelection);
}
void SynEdit::doComment()
@ -2494,7 +2495,7 @@ void SynEdit::ensureCursorPosVisibleEx(bool ForceToMiddle)
}
}
void SynEdit::scrollWindow(int dx, int dy)
void SynEdit::scrollWindow(int , int )
{
// int nx = horizontalScrollBar()->value()+dx;
// int ny = verticalScrollBar()->value()+dy;
@ -3886,6 +3887,7 @@ QString SynEdit::selText()
}
}
}
return "";
}
QString SynEdit::lineBreak()
@ -4213,7 +4215,6 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS
searchEngine->setOptions(sOptions);
searchEngine->setPattern(sSearch);
// search while the current search position is inside of the search range
int nReplaceLen = 0;
bool dobatchReplace = false;
doOnPaintTransient(SynTransientType::ttBefore);
{
@ -5162,7 +5163,7 @@ void SynEdit::paintEvent(QPaintEvent *event)
paintCaret(painter, rcCaret);
}
void SynEdit::resizeEvent(QResizeEvent *)
void SynEdit::resizeEvent(QResizeEvent *e)
{
//resize the cache image
std::shared_ptr<QImage> image = std::make_shared<QImage>(clientWidth(),clientHeight(),
@ -5402,11 +5403,11 @@ void SynEdit::wheelEvent(QWheelEvent *event)
bool SynEdit::viewportEvent(QEvent * event)
{
switch (event->type()) {
case QEvent::Resize:
sizeOrFontChanged(false);
break;
}
// switch (event->type()) {
// case QEvent::Resize:
// sizeOrFontChanged(false);
// break;
// }
return QAbstractScrollArea::viewportEvent(event);
}

View File

@ -378,4 +378,5 @@ QString SynExporter::lineBreak()
case FileEndingType::Mac:
return "\r";
}
return "\n";
}