clean code

refactor: rename fileIncludes to fileInfo
This commit is contained in:
Roy Qu 2024-04-06 18:10:49 +08:00
parent fd062e2f34
commit 17fddff91b
11 changed files with 99 additions and 179 deletions

View File

@ -384,11 +384,11 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
QString objStr = escapeFilenameForMakefilePrerequisite(shortFileName); QString objStr = escapeFilenameForMakefilePrerequisite(shortFileName);
// if we have scanned it, use scanned info // if we have scanned it, use scanned info
if (parser && parser->fileScanned(unit->fileName())) { if (parser && parser->fileScanned(unit->fileName())) {
QSet<QString> fileIncludes = parser->getIncludedFiles(unit->fileName()); QSet<QString> includedFiles = parser->getIncludedFiles(unit->fileName());
foreach(const PProjectUnit &unit2, projectUnits) { foreach(const PProjectUnit &unit2, projectUnits) {
if (unit2==unit) if (unit2==unit)
continue; continue;
if (fileIncludes.contains(unit2->fileName())) { if (includedFiles.contains(unit2->fileName())) {
if (mProject->options().usePrecompiledHeader && if (mProject->options().usePrecompiledHeader &&
unit2->fileName() == mProject->options().precompiledHeader) unit2->fileName() == mProject->options().precompiledHeader)
precompileStr = " $(PCH) "; precompileStr = " $(PCH) ";

View File

@ -219,11 +219,11 @@ void SDCCProjectCompiler::writeMakeObjFilesRules(QFile &file)
QString objStr = escapeFilenameForMakefilePrerequisite(shortFileName); QString objStr = escapeFilenameForMakefilePrerequisite(shortFileName);
// if we have scanned it, use scanned info // if we have scanned it, use scanned info
if (parser && parser->fileScanned(unit->fileName())) { if (parser && parser->fileScanned(unit->fileName())) {
QSet<QString> fileIncludes = parser->getIncludedFiles(unit->fileName()); QSet<QString> includedFiles = parser->getIncludedFiles(unit->fileName());
foreach(const PProjectUnit &unit2, projectUnits) { foreach(const PProjectUnit &unit2, projectUnits) {
if (unit2==unit) if (unit2==unit)
continue; continue;
if (fileIncludes.contains(unit2->fileName())) { if (includedFiles.contains(unit2->fileName())) {
QString header = extractRelativePath(mProject->makeFileName(),unit2->fileName()); QString header = extractRelativePath(mProject->makeFileName(),unit2->fileName());
objStr = objStr + ' ' + escapeFilenameForMakefilePrerequisite(header); objStr = objStr + ' ' + escapeFilenameForMakefilePrerequisite(header);
} }

View File

@ -1307,13 +1307,6 @@ bool Editor::onGetSpecialLineColors(int Line, QColor &foreground, QColor &backgr
backgroundColor = mBreakpointBackgroundColor; backgroundColor = mBreakpointBackgroundColor;
return true; return true;
} }
// end else if Line = fErrorLine then begin
// StrToThemeColor(tc, devEditor.Syntax.Values[cErr]);
// BG := tc.Background;
// FG := tc.Foreground;
// if (BG <> clNone) or (FG<>clNone) then
// Special := TRUE;
// end;
return false; return false;
} }
@ -2789,8 +2782,6 @@ bool Editor::handleParentheseCompletion()
} }
return true; return true;
} }
// if (status == QuoteStatus::NotQuote) && FunctionTipAllowed then
// fFunctionTip.Activated := true;
return false; return false;
} }
@ -4150,7 +4141,6 @@ QString Editor::getParserHint(const QStringList& expression,const QString &/*s*/
} else { // hard defines } else { // hard defines
result = mParser->prettyPrintStatement(statement, mFilename); result = mParser->prettyPrintStatement(statement, mFilename);
} }
// Result := StringReplace(Result, '|', #5, [rfReplaceAll]);
return result; return result;
} }

View File

@ -5940,10 +5940,6 @@ void MainWindow::onCompileIssue(PCompileIssue issue)
return; return;
ui->tableIssues->addIssue(issue); ui->tableIssues->addIssue(issue);
// Update tab caption
// if CompilerOutput.Items.Count = 1 then
// CompSheet.Caption := Lang[ID_SHEET_COMP] + ' (' + IntToStr(CompilerOutput.Items.Count) + ')';
if (issue->type == CompileIssueType::Error || issue->type == if (issue->type == CompileIssueType::Error || issue->type ==
CompileIssueType::Warning) { CompileIssueType::Warning) {
Editor* e = mEditorList->getOpenedEditorByFilename(issue->filename); Editor* e = mEditorList->getOpenedEditorByFilename(issue->filename);
@ -7183,8 +7179,6 @@ void MainWindow::on_actionNew_Project_triggered()
} }
} }
// if cbDefault.Checked then
// devData.DefCpp := rbCpp.Checked;
QDir projectDir = QDir(location); QDir projectDir = QDir(location);
if (!projectDir.isEmpty()) { if (!projectDir.isEmpty()) {
if (QMessageBox::question( if (QMessageBox::question(

View File

@ -200,20 +200,20 @@ PStatement CppParser::findScopeStatement(const QString &filename, int line)
PStatement CppParser::doFindScopeStatement(const QString &filename, int line) const PStatement CppParser::doFindScopeStatement(const QString &filename, int line) const
{ {
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(filename); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(filename);
if (!fileIncludes) if (!fileInfo)
return PStatement(); return PStatement();
return fileIncludes->scopes.findScopeAtLine(line); return fileInfo->scopes.findScopeAtLine(line);
} }
PParsedFileInfo CppParser::findFileIncludes(const QString &filename, bool deleteIt) PParsedFileInfo CppParser::findFileIncludes(const QString &filename, bool deleteIt)
{ {
QMutexLocker locker(&mMutex); QMutexLocker locker(&mMutex);
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(filename); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(filename);
if (deleteIt && fileIncludes) if (deleteIt && fileInfo)
mPreprocessor.removeFileIncludes(filename); mPreprocessor.removeFileIncludes(filename);
return fileIncludes; return fileInfo;
} }
QString CppParser::findFirstTemplateParamOf(const QString &fileName, const QString &phrase, const PStatement& currentScope) QString CppParser::findFirstTemplateParamOf(const QString &fileName, const QString &phrase, const PStatement& currentScope)
{ {
@ -234,10 +234,10 @@ QString CppParser::findTemplateParamOf(const QString &fileName, const QString &p
PStatement CppParser::findFunctionAt(const QString &fileName, int line) PStatement CppParser::findFunctionAt(const QString &fileName, int line)
{ {
QMutexLocker locker(&mMutex); QMutexLocker locker(&mMutex);
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(fileName); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(fileName);
if (!fileIncludes) if (!fileInfo)
return PStatement(); return PStatement();
for (PStatement& statement : fileIncludes->statements) { for (PStatement& statement : fileInfo->statements) {
if (statement->kind != StatementKind::Function if (statement->kind != StatementKind::Function
&& statement->kind != StatementKind::Constructor && statement->kind != StatementKind::Constructor
&& statement->kind != StatementKind::Destructor) && statement->kind != StatementKind::Destructor)
@ -664,15 +664,15 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement, QSet<S
return PStatement(); return PStatement();
QString nsName=statement->type.mid(0,pos); QString nsName=statement->type.mid(0,pos);
QString name = statement->type.mid(pos+2); QString name = statement->type.mid(pos+2);
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(statement->fileName); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(statement->fileName);
if (!fileIncludes) if (!fileInfo)
return PStatement(); return PStatement();
foundSet.insert(statement.get()); foundSet.insert(statement.get());
PStatement result; PStatement result;
if (nsName.isEmpty()) { if (nsName.isEmpty()) {
QList<PStatement> resultList = findMembersOfStatement(name,PStatement()); QList<PStatement> resultList = findMembersOfStatement(name,PStatement());
foreach(const PStatement& resultStatement,resultList) { foreach(const PStatement& resultStatement,resultList) {
if (fileIncludes->includeFiles.contains(resultStatement->fileName)) { if (fileInfo->includeFiles.contains(resultStatement->fileName)) {
result = resultStatement; result = resultStatement;
break; break;
} }
@ -685,7 +685,7 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement, QSet<S
QList<PStatement> resultList = findMembersOfStatement(name,namespaceStatement); QList<PStatement> resultList = findMembersOfStatement(name,namespaceStatement);
foreach(const PStatement& resultStatement,resultList) { foreach(const PStatement& resultStatement,resultList) {
if (fileIncludes->includeFiles.contains(resultStatement->fileName)) { if (fileInfo->includeFiles.contains(resultStatement->fileName)) {
result = resultStatement; result = resultStatement;
break; break;
} }
@ -838,10 +838,10 @@ QStringList CppParser::getFileDirectIncludes(const QString &filename)
return QStringList(); return QStringList();
if (filename.isEmpty()) if (filename.isEmpty())
return QStringList(); return QStringList();
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(filename); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(filename);
if (fileIncludes) { if (fileInfo) {
return fileIncludes->directIncludes; return fileInfo->directIncludes;
} }
return QStringList(); return QStringList();
@ -854,10 +854,10 @@ QSet<QString> CppParser::internalGetIncludedFiles(const QString &filename) const
if (filename.isEmpty()) if (filename.isEmpty())
return list; return list;
list.insert(filename); list.insert(filename);
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(filename); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(filename);
if (fileIncludes) { if (fileInfo) {
foreach (const QString& file, fileIncludes->includeFiles.keys()) { foreach (const QString& file, fileInfo->includeFiles.keys()) {
list.insert(file); list.insert(file);
} }
} }
@ -883,13 +883,13 @@ QSet<QString> CppParser::internalGetFileUsings(const QString &filename) const
return result; return result;
// if (mParsing) // if (mParsing)
// return result; // return result;
PParsedFileInfo fileIncludes= mPreprocessor.findFileIncludes(filename); PParsedFileInfo fileInfo= mPreprocessor.findFileInfo(filename);
if (fileIncludes) { if (fileInfo) {
foreach (const QString& usingName, fileIncludes->usings) { foreach (const QString& usingName, fileInfo->usings) {
result.insert(usingName); result.insert(usingName);
} }
foreach (const QString& subFile,fileIncludes->includeFiles.keys()){ foreach (const QString& subFile,fileInfo->includeFiles.keys()){
PParsedFileInfo subIncludes = mPreprocessor.findFileIncludes(subFile); PParsedFileInfo subIncludes = mPreprocessor.findFileInfo(subFile);
if (subIncludes) { if (subIncludes) {
foreach (const QString& usingName, subIncludes->usings) { foreach (const QString& usingName, subIncludes->usings) {
result.insert(usingName); result.insert(usingName);
@ -939,10 +939,10 @@ bool CppParser::isLineVisible(const QString &fileName, int line)
if (mParsing) { if (mParsing) {
return true; return true;
} }
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(fileName); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(fileName);
if (!fileIncludes) if (!fileInfo)
return true; return true;
return fileIncludes->isLineVisible(line); return fileInfo->isLineVisible(line);
} }
void CppParser::invalidateFile(const QString &fileName) void CppParser::invalidateFile(const QString &fileName)
@ -1436,9 +1436,9 @@ PStatement CppParser::addStatement(const PStatement& parent,
if (oldStatement && !oldStatement->hasDefinition()) { if (oldStatement && !oldStatement->hasDefinition()) {
oldStatement->setHasDefinition(true); oldStatement->setHasDefinition(true);
if (oldStatement->fileName!=fileName) { if (oldStatement->fileName!=fileName) {
PParsedFileInfo fileIncludes=mPreprocessor.findFileIncludes(fileName); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(fileName);
if (fileIncludes) { if (fileInfo) {
fileIncludes->statements.insert(oldStatement->fullName, fileInfo->statements.insert(oldStatement->fullName,
oldStatement); oldStatement);
} }
} }
@ -1497,9 +1497,9 @@ PStatement CppParser::addStatement(const PStatement& parent,
} }
if (result->kind!= StatementKind::Block) { if (result->kind!= StatementKind::Block) {
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(fileName); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(fileName);
if (fileIncludes) { if (fileInfo) {
fileIncludes->statements.insert(result->fullName,result); fileInfo->statements.insert(result->fullName,result);
} }
} }
return result; return result;
@ -1744,10 +1744,10 @@ void CppParser::addSoloScopeLevel(PStatement& statement, int line, bool shouldRe
mCurrentScope.append(statement); mCurrentScope.append(statement);
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(mCurrentFile); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(mCurrentFile);
if (fileIncludes) { if (fileInfo) {
fileIncludes->scopes.addScope(line,statement); fileInfo->scopes.addScope(line,statement);
} }
// Set new scope // Set new scope
@ -1776,17 +1776,17 @@ void CppParser::removeScopeLevel(int line, int maxIndex)
// qDebug()<<"--remove scope"<<mCurrentFile<<line<<mCurrentClassScope.count(); // qDebug()<<"--remove scope"<<mCurrentFile<<line<<mCurrentClassScope.count();
#endif #endif
PStatement currentScope = getCurrentScope(); PStatement currentScope = getCurrentScope();
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(mCurrentFile); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(mCurrentFile);
if (currentScope) { if (currentScope) {
if (currentScope->kind == StatementKind::Block) { if (currentScope->kind == StatementKind::Block) {
if (currentScope->children.isEmpty()) { if (currentScope->children.isEmpty()) {
// remove no children block // remove no children block
if (fileIncludes) if (fileInfo)
fileIncludes->scopes.removeLastScope(); fileInfo->scopes.removeLastScope();
mStatementList.deleteStatement(currentScope); mStatementList.deleteStatement(currentScope);
} else { } else {
if (fileIncludes) if (fileInfo)
fileIncludes->statements.insert(currentScope->fullName,currentScope); fileInfo->statements.insert(currentScope->fullName,currentScope);
} }
} else if (currentScope->kind == StatementKind::Class) { } else if (currentScope->kind == StatementKind::Class) {
mIndex=indexOfNextSemicolon(mIndex, maxIndex); mIndex=indexOfNextSemicolon(mIndex, maxIndex);
@ -1797,9 +1797,8 @@ void CppParser::removeScopeLevel(int line, int maxIndex)
// Set new scope // Set new scope
currentScope = getCurrentScope(); currentScope = getCurrentScope();
// fileIncludes:=FindFileIncludes(fCurrentFile); if (fileInfo && fileInfo->scopes.lastScope()!=currentScope) {
if (fileIncludes && fileIncludes->scopes.lastScope()!=currentScope) { fileInfo->scopes.addScope(line,currentScope);
fileIncludes->scopes.addScope(line,currentScope);
} }
if (!currentScope) { if (!currentScope) {
@ -1841,10 +1840,10 @@ QStringList CppParser::sortFilesByIncludeRelations(const QSet<QString> &files)
while (!fileSet.isEmpty()) { while (!fileSet.isEmpty()) {
bool found=false; bool found=false;
foreach (const QString& file,fileSet) { foreach (const QString& file,fileSet) {
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(file); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(file);
bool hasInclude=false; bool hasInclude=false;
if (fileIncludes) { if (fileInfo) {
foreach(const QString& inc,fileIncludes->includeFiles.keys()) { foreach(const QString& inc,fileInfo->includeFiles.keys()) {
if (fileSet.contains(inc)) { if (fileSet.contains(inc)) {
hasInclude=true; hasInclude=true;
break; break;
@ -3391,9 +3390,9 @@ void CppParser::handlePreprocessor()
if (delimPos>=0) { if (delimPos>=0) {
// qDebug()<<mCurrentScope.size()<<mCurrentFile<<mTokenizer[mIndex]->line<<s.mid(0,delimPos).trimmed(); // qDebug()<<mCurrentScope.size()<<mCurrentFile<<mTokenizer[mIndex]->line<<s.mid(0,delimPos).trimmed();
mCurrentFile = s.mid(0,delimPos).trimmed(); mCurrentFile = s.mid(0,delimPos).trimmed();
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(mCurrentFile); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(mCurrentFile);
if (fileIncludes) { if (fileInfo) {
mCurrentFile = fileIncludes->baseFile; mCurrentFile = fileInfo->baseFile;
} else { } else {
mCurrentFile.squeeze(); mCurrentFile.squeeze();
} }
@ -3974,7 +3973,7 @@ void CppParser::handleUsing(int maxIndex)
scopeStatement->usingList.insert(fullName); scopeStatement->usingList.insert(fullName);
} }
} else { } else {
PParsedFileInfo fileInfo = mPreprocessor.findFileIncludes(mCurrentFile); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(mCurrentFile);
if (!fileInfo) if (!fileInfo)
return; return;
if (mNamespaces.contains(usingName)) { if (mNamespaces.contains(usingName)) {
@ -4281,9 +4280,9 @@ void CppParser::handleInheritance(PStatement derivedStatement, PClassInheritance
inheritanceInfo->visibility); inheritanceInfo->visibility);
// inheritanceInfo->parentClassFilename = statement->fileName; // inheritanceInfo->parentClassFilename = statement->fileName;
inheritanceInfo->handled = true; inheritanceInfo->handled = true;
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(statement->fileName); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(statement->fileName);
Q_ASSERT(fileIncludes!=nullptr); Q_ASSERT(fileInfo!=nullptr);
fileIncludes->handledInheritances.append(inheritanceInfo); fileInfo->handledInheritances.append(inheritanceInfo);
} }
} }
@ -4479,7 +4478,7 @@ PStatement CppParser::findMacro(const QString &phrase, const QString &fileName)
if (statementMap.isEmpty()) if (statementMap.isEmpty())
return PStatement(); return PStatement();
StatementList statements = statementMap.values(phrase); StatementList statements = statementMap.values(phrase);
PParsedFileInfo includes = mPreprocessor.findFileIncludes(fileName); PParsedFileInfo includes = mPreprocessor.findFileInfo(fileName);
foreach (const PStatement& s, statements) { foreach (const PStatement& s, statements) {
if (s->kind == StatementKind::Preprocessor) { if (s->kind == StatementKind::Preprocessor) {
if (includes && fileName != s->fileName && !includes->includeFiles.contains(s->fileName)) if (includes && fileName != s->fileName && !includes->includeFiles.contains(s->fileName))
@ -4542,14 +4541,14 @@ PStatement CppParser::findMemberOfStatement(const QString& filename,
return statementMap.value(s,PStatement()); return statementMap.value(s,PStatement());
} else { } else {
QList<PStatement> stats = statementMap.values(s); QList<PStatement> stats = statementMap.values(s);
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(filename); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(filename);
foreach(const PStatement &s,stats) { foreach(const PStatement &s,stats) {
if (s->line==-1) { if (s->line==-1) {
return s; // hard defines return s; // hard defines
} if (s->fileName == filename || s->definitionFileName==filename) { } if (s->fileName == filename || s->definitionFileName==filename) {
return s; return s;
} else if (fileIncludes && (fileIncludes->includeFiles.contains(s->fileName) } else if (fileInfo && (fileInfo->includeFiles.contains(s->fileName)
|| fileIncludes->includeFiles.contains(s->definitionFileName))) { || fileInfo->includeFiles.contains(s->definitionFileName))) {
return s; return s;
} }
} }
@ -5963,8 +5962,8 @@ QSet<QString> CppParser::calculateFilesToBeReparsed(const QString &fileName)
QSet<QString> result; QSet<QString> result;
result.insert(fileName); result.insert(fileName);
foreach (const QString& file, mProjectFiles) { foreach (const QString& file, mProjectFiles) {
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(file); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(file);
if (fileIncludes && fileIncludes->includeFiles.contains(fileName)) { if (fileInfo && fileInfo->includeFiles.contains(fileName)) {
result.insert(file); result.insert(file);
} }
} }

View File

@ -33,7 +33,7 @@ void CppPreprocessor::clear()
//Result across processings. //Result across processings.
//used by parser even preprocess finished //used by parser even preprocess finished
mIncludesList.clear(); mFileInfos.clear();
mFileDefines.clear(); //dictionary to save defines for each headerfile; mFileDefines.clear(); //dictionary to save defines for each headerfile;
mFileUndefines.clear(); //dictionary to save undefines for each headerfile; mFileUndefines.clear(); //dictionary to save undefines for each headerfile;
mScannedFiles.clear(); mScannedFiles.clear();
@ -57,7 +57,7 @@ void CppPreprocessor::clearTempResults()
mFileName=""; mFileName="";
mBuffer.clear(); mBuffer.clear();
mResult.clear(); mResult.clear();
mCurrentIncludes=nullptr; mCurrentFileInfo=nullptr;
mIncludes.clear(); // stack of files we've stepped into. last one is current file, first one is source file mIncludes.clear(); // stack of files we've stepped into. last one is current file, first one is source file
mBranchResults.clear();// stack of branch results (boolean). last one is current branch, first one is outermost branch mBranchResults.clear();// stack of branch results (boolean). last one is current branch, first one is outermost branch
//mDefines.clear(); // working set, editable //mDefines.clear(); // working set, editable
@ -224,8 +224,8 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const
QFile file(fileName); QFile file(fileName);
if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) { if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) {
QTextStream stream(&file); QTextStream stream(&file);
for (const PParsedFileInfo& fileIncludes:mIncludesList) { for (const PParsedFileInfo& fileInfo:mFileInfos) {
stream<<fileIncludes->baseFile<<" : " stream<<fileInfo->baseFile<<" : "
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0) #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl; <<Qt::endl;
#else #else
@ -237,7 +237,7 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const
#else #else
<<endl; <<endl;
#endif #endif
foreach (const QString& s,fileIncludes->includeFiles.keys()) { foreach (const QString& s,fileInfo->includeFiles.keys()) {
stream<<"\t--"+s stream<<"\t--"+s
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0) #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl; <<Qt::endl;
@ -245,49 +245,6 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const
<<endl; <<endl;
#endif #endif
} }
stream<<"\t**depends on:**"
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl;
#else
<<endl;
#endif
stream<<"\t**depended by:**"
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl;
#else
<<endl;
#endif
// stream<<"\t**using:**"
// #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
// <<Qt::endl;
// #else
// <<endl;
// #endif
// foreach (const QString& s,fileIncludes->usings) {
// stream<<"\t++"+s
// #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
// <<Qt::endl;
// #else
// <<endl;
// #endif
// }
// stream<<"\t**statements:**"
// #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
// <<Qt::endl;
// #else
// <<endl;
// #endif
// foreach (const PStatement& statement,fileIncludes->statements) {
// if (statement) {
// stream<<QString("\t**%1 , %2")
// .arg(statement->command,statement->fullName)
// #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
// <<Qt::endl;
// #else
// <<endl;
// #endif
// }
// }
} }
} }
} }
@ -324,7 +281,7 @@ void CppPreprocessor::removeScannedFile(const QString &filename)
{ {
invalidDefinesInFile(filename); invalidDefinesInFile(filename);
mScannedFiles.remove(filename); mScannedFiles.remove(filename);
mIncludesList.remove(filename); mFileInfos.remove(filename);
mFileDefines.remove(filename); mFileDefines.remove(filename);
mFileUndefines.remove(filename); mFileUndefines.remove(filename);
} }
@ -478,7 +435,7 @@ void CppPreprocessor::handleInclude(const QString &line, bool fromNext)
if (fileName.isEmpty()) if (fileName.isEmpty())
return; return;
PParsedFileInfo oldCurrentIncludes = mCurrentIncludes; PParsedFileInfo oldCurrentIncludes = mCurrentFileInfo;
openInclude(fileName); openInclude(fileName);
} }
@ -803,9 +760,9 @@ void CppPreprocessor::removeGCCAttribute(const QString &line, QString &newLine,
void CppPreprocessor::openInclude(QString fileName) void CppPreprocessor::openInclude(QString fileName)
{ {
PParsedFileInfo fileIncludes = getFileIncludesEntry(fileName); PParsedFileInfo fileInfo = findFileInfo(fileName);
if (fileIncludes) { if (fileInfo) {
fileName = fileIncludes->baseFile; fileName = fileInfo->baseFile;
} else { } else {
fileName.squeeze(); fileName.squeeze();
} }
@ -818,15 +775,15 @@ void CppPreprocessor::openInclude(QString fileName)
// } // }
bool alreadyIncluded = false; bool alreadyIncluded = false;
for (PParsedFile& parsedFile:mIncludes) { for (PParsedFile& parsedFile:mIncludes) {
if (parsedFile->fileIncludes->includeFiles.contains(fileName)) { if (parsedFile->fileInfo->includeFiles.contains(fileName)) {
alreadyIncluded = true; alreadyIncluded = true;
continue; continue;
} }
parsedFile->fileIncludes->includeFiles.insert(fileName,false); parsedFile->fileInfo->includeFiles.insert(fileName,false);
} }
PParsedFile innerMostFile = mIncludes.back(); PParsedFile innerMostFile = mIncludes.back();
innerMostFile->fileIncludes->includeFiles.insert(fileName,true); innerMostFile->fileInfo->includeFiles.insert(fileName,true);
innerMostFile->fileIncludes->directIncludes.append(fileName); innerMostFile->fileInfo->directIncludes.append(fileName);
if (alreadyIncluded) if (alreadyIncluded)
return; return;
// Backup old position if we're entering a new file // Backup old position if we're entering a new file
@ -844,14 +801,14 @@ void CppPreprocessor::openInclude(QString fileName)
// Keep track of files we include here // Keep track of files we include here
// Only create new items for files we have NOT scanned yet // Only create new items for files we have NOT scanned yet
mCurrentIncludes = getFileIncludesEntry(fileName); mCurrentFileInfo = findFileInfo(fileName);
if (!mCurrentIncludes) { if (!mCurrentFileInfo) {
// do NOT create a new item for a file that's already in the list // do NOT create a new item for a file that's already in the list
mCurrentIncludes = std::make_shared<ParsedFileInfo>(); mCurrentFileInfo = std::make_shared<ParsedFileInfo>();
mCurrentIncludes->baseFile = fileName; mCurrentFileInfo->baseFile = fileName;
mIncludesList.insert(fileName,mCurrentIncludes); mFileInfos.insert(fileName,mCurrentFileInfo);
} }
parsedFile->fileIncludes = mCurrentIncludes; parsedFile->fileInfo = mCurrentFileInfo;
// Don't parse stuff we have already parsed // Don't parse stuff we have already parsed
if (!mScannedFiles.contains(fileName)) { if (!mScannedFiles.contains(fileName)) {
@ -872,11 +829,11 @@ void CppPreprocessor::openInclude(QString fileName)
} else { } else {
//add defines of already parsed including headers; //add defines of already parsed including headers;
addDefinesInFile(fileName); addDefinesInFile(fileName);
PParsedFileInfo fileIncludes = getFileIncludesEntry(fileName); PParsedFileInfo fileInfo = findFileInfo(fileName);
if (fileIncludes) { if (fileInfo) {
for (PParsedFile& file:mIncludes) { for (PParsedFile& file:mIncludes) {
foreach (const QString& incFile,fileIncludes->includeFiles.keys()) { foreach (const QString& incFile,fileInfo->includeFiles.keys()) {
file->fileIncludes->includeFiles.insert(incFile,false); file->fileInfo->includeFiles.insert(incFile,false);
} }
} }
} }
@ -924,8 +881,7 @@ void CppPreprocessor::closeInclude()
// Start augmenting previous include list again // Start augmenting previous include list again
//fCurrentIncludes := GetFileIncludesEntry(fFileName); mCurrentFileInfo = parsedFile->fileInfo;
mCurrentIncludes = parsedFile->fileIncludes;
// Update result file (we've left the previous file) // Update result file (we've left the previous file)
mResult.append( mResult.append(
@ -959,9 +915,9 @@ void CppPreprocessor::addDefinesInFile(const QString &fileName)
} }
} }
PParsedFileInfo fileIncludes = getFileIncludesEntry(fileName); PParsedFileInfo fileInfo = findFileInfo(fileName);
if (fileIncludes) { if (fileInfo) {
foreach (const QString& file, fileIncludes->includeFiles.keys()) { foreach (const QString& file, fileInfo->includeFiles.keys()) {
addDefinesInFile(file); addDefinesInFile(file);
} }
} }

View File

@ -41,7 +41,7 @@ struct ParsedFile {
QString fileName; // Record filename, but not used now QString fileName; // Record filename, but not used now
QStringList buffer; // do not concat them all QStringList buffer; // do not concat them all
int branches; //branch levels; int branches; //branch levels;
PParsedFileInfo fileIncludes; // includes of this file PParsedFileInfo fileInfo; // info of this file
}; };
using PParsedFile = std::shared_ptr<ParsedFile>; using PParsedFile = std::shared_ptr<ParsedFile>;
@ -91,12 +91,12 @@ public:
return mResult; return mResult;
}; };
PParsedFileInfo findFileIncludes(const QString& fileName) const { PParsedFileInfo findFileInfo(const QString& fileName) const {
return mIncludesList.value(fileName); return mFileInfos.value(fileName);
} }
void removeFileIncludes(const QString& fileName) { void removeFileIncludes(const QString& fileName) {
mIncludesList.remove(fileName); mFileInfos.remove(fileName);
} }
bool fileScanned(const QString& fileName) const { bool fileScanned(const QString& fileName) const {
@ -169,7 +169,7 @@ private:
} }
void setCurrentBranch(BranchResult value){ void setCurrentBranch(BranchResult value){
if (!sameResultWithCurrentBranch(value)) { if (!sameResultWithCurrentBranch(value)) {
mCurrentIncludes->branches.insert(mIndex+1,value==BranchResult::isTrue); mCurrentFileInfo->branches.insert(mIndex+1,value==BranchResult::isTrue);
} }
mBranchResults.append(value); mBranchResults.append(value);
} }
@ -179,13 +179,9 @@ private:
mBranchResults.pop_back(); mBranchResults.pop_back();
} }
if (!sameResultWithCurrentBranch(value)) { if (!sameResultWithCurrentBranch(value)) {
mCurrentIncludes->branches.insert(mIndex,getCurrentBranch()==BranchResult::isTrue); mCurrentFileInfo->branches.insert(mIndex,getCurrentBranch()==BranchResult::isTrue);
} }
} }
// include stuff
PParsedFileInfo getFileIncludesEntry(const QString& fileName){
return mIncludesList.value(fileName,PParsedFileInfo());
}
void addDefinesInFile(const QString& fileName); void addDefinesInFile(const QString& fileName);
void addDefineByParts(const QString& name, const QString& args, void addDefineByParts(const QString& name, const QString& args,
const QString& value, bool hardCoded); const QString& value, bool hardCoded);
@ -262,7 +258,7 @@ private:
QString mFileName; QString mFileName;
QStringList mBuffer; QStringList mBuffer;
QStringList mResult; QStringList mResult;
PParsedFileInfo mCurrentIncludes; PParsedFileInfo mCurrentFileInfo;
int mPreProcIndex; int mPreProcIndex;
QList<PParsedFile> mIncludes; // stack of files we've stepped into. last one is current file, first one is source file QList<PParsedFile> mIncludes; // stack of files we've stepped into. last one is current file, first one is source file
QList<BranchResult> mBranchResults;// stack of branch results (boolean). last one is current branch, first one is outermost branch QList<BranchResult> mBranchResults;// stack of branch results (boolean). last one is current branch, first one is outermost branch
@ -272,7 +268,7 @@ private:
//Result across processings. //Result across processings.
//used by parser even preprocess finished //used by parser even preprocess finished
QHash<QString,PParsedFileInfo> mIncludesList; QHash<QString, PParsedFileInfo> mFileInfos;
QHash<QString, PDefineMap> mFileDefines; //dictionary to save defines for each headerfile; QHash<QString, PDefineMap> mFileDefines; //dictionary to save defines for each headerfile;
QHash<QString, PDefineMap> mFileUndefines; //dictionary to save defines for each headerfile; QHash<QString, PDefineMap> mFileUndefines; //dictionary to save defines for each headerfile;
QSet<QString> mScannedFiles; QSet<QString> mScannedFiles;

View File

@ -437,8 +437,6 @@ QString CppTokenizer::getPreprocessor()
QString CppTokenizer::getWord() QString CppTokenizer::getWord()
{ {
bool bFoundTemplate = false; bool bFoundTemplate = false;
// bIsSmartPointer:=False;
// Skip spaces // Skip spaces
skipToNextToken(); skipToNextToken();

View File

@ -238,9 +238,6 @@ void resetCppParser(std::shared_ptr<CppParser> parser, int compilerSetIndex)
return; return;
// Configure parser // Configure parser
parser->resetParser(); parser->resetParser();
//paser->enabled = pSettings-> devCodeCompletion.Enabled;
// CppParser.ParseLocalHeaders := devCodeCompletion.ParseLocalHeaders;
// CppParser.ParseGlobalHeaders := devCodeCompletion.ParseGlobalHeaders;
parser->setEnabled(true); parser->setEnabled(true);
parser->setParseGlobalHeaders(true); parser->setParseGlobalHeaders(true);
parser->setParseLocalHeaders(true); parser->setParseLocalHeaders(true);

View File

@ -88,7 +88,6 @@ void CodeCompletionPopup::prepareSearch(
QMutexLocker locker(&mMutex); QMutexLocker locker(&mMutex);
if (!isEnabled()) if (!isEnabled())
return; return;
//Screen.Cursor := crHourglass;
QCursor oldCursor = cursor(); QCursor oldCursor = cursor();
setCursor(Qt::CursorShape::WaitCursor); setCursor(Qt::CursorShape::WaitCursor);

View File

@ -63,7 +63,6 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
mFontDummy.setStyleStrategy(QFont::PreferAntialias); mFontDummy.setStyleStrategy(QFont::PreferAntialias);
mDocument = std::make_shared<Document>(mFontDummy, this); mDocument = std::make_shared<Document>(mFontDummy, this);
//fPlugins := TList.Create;
mMouseMoved = false; mMouseMoved = false;
mMouseOrigin = QPoint(0,0); mMouseOrigin = QPoint(0,0);
mUndoing = false; mUndoing = false;
@ -103,11 +102,7 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
mGutter.setRightOffset(21); mGutter.setRightOffset(21);
mGutter.connect(&mGutter, &Gutter::changed, this, &QSynEdit::onGutterChanged); mGutter.connect(&mGutter, &Gutter::changed, this, &QSynEdit::onGutterChanged);
mGutterWidth = mGutter.realGutterWidth(charWidth()); mGutterWidth = mGutter.realGutterWidth(charWidth());
//ControlStyle := ControlStyle + [csOpaque, csSetCaption, csNeedsBorderPaint];
//Height := 150;
//Width := 200;
this->setCursor(Qt::CursorShape::IBeamCursor); this->setCursor(Qt::CursorShape::IBeamCursor);
//TabStop := True;
mInserting = true; mInserting = true;
mLineSpacingFactor = 1.0; mLineSpacingFactor = 1.0;
@ -121,9 +116,6 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
//stop qt to auto fill background //stop qt to auto fill background
setAutoFillBackground(false); setAutoFillBackground(false);
//fFocusList := TList.Create;
//fKbdHandler := TSynEditKbdHandler.Create;
//fMarkList.OnChange := MarkListChange;
setDefaultKeystrokes(); setDefaultKeystrokes();
mRightEdgeColor = Qt::lightGray; mRightEdgeColor = Qt::lightGray;
@ -1158,7 +1150,6 @@ void QSynEdit::processGutterClick(QMouseEvent *event)
PCodeFoldingRange foldRange = foldStartAtLine(line); PCodeFoldingRange foldRange = foldStartAtLine(line);
if (foldRange) { if (foldRange) {
// See if we actually clicked on the rectangle... // See if we actually clicked on the rectangle...
//rect.Left := Gutter.RealGutterWidth(CharWidth) - Gutter.RightOffset;
QRect rect; QRect rect;
rect.setLeft(mGutterWidth - mGutter.rightOffset()); rect.setLeft(mGutterWidth - mGutter.rightOffset());
rect.setRight(rect.left() + mGutter.rightOffset() - 4); rect.setRight(rect.left() + mGutter.rightOffset() - 4);