diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 9ff973e3..a31654b3 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -672,7 +672,7 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement, QSet resultList = findMembersOfStatement(name,PStatement()); foreach(const PStatement& resultStatement,resultList) { - if (fileInfo->includeFiles.contains(resultStatement->fileName)) { + if (fileInfo->includes.contains(resultStatement->fileName)) { result = resultStatement; break; } @@ -685,7 +685,7 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement, QSet resultList = findMembersOfStatement(name,namespaceStatement); foreach(const PStatement& resultStatement,resultList) { - if (fileInfo->includeFiles.contains(resultStatement->fileName)) { + if (fileInfo->includes.contains(resultStatement->fileName)) { result = resultStatement; break; } @@ -857,7 +857,7 @@ QSet CppParser::internalGetIncludedFiles(const QString &filename) const PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(filename); if (fileInfo) { - foreach (const QString& file, fileInfo->includeFiles.keys()) { + foreach (const QString& file, fileInfo->includes.keys()) { list.insert(file); } } @@ -888,7 +888,7 @@ QSet CppParser::internalGetFileUsings(const QString &filename) const foreach (const QString& usingName, fileInfo->usings) { result.insert(usingName); } - foreach (const QString& subFile,fileInfo->includeFiles.keys()){ + foreach (const QString& subFile,fileInfo->includes.keys()){ PParsedFileInfo subIncludes = mPreprocessor.findFileInfo(subFile); if (subIncludes) { foreach (const QString& usingName, subIncludes->usings) { @@ -1843,7 +1843,7 @@ QStringList CppParser::sortFilesByIncludeRelations(const QSet &files) PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(file); bool hasInclude=false; if (fileInfo) { - foreach(const QString& inc,fileInfo->includeFiles.keys()) { + foreach(const QString& inc,fileInfo->includes.keys()) { if (fileSet.contains(inc)) { hasInclude=true; break; @@ -3397,7 +3397,7 @@ void CppParser::handlePreprocessor() mCurrentFile = s.mid(0,delimPos).trimmed(); PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(mCurrentFile); if (fileInfo) { - mCurrentFile = fileInfo->baseFile; + mCurrentFile = fileInfo->fileName; } else { mCurrentFile.squeeze(); } @@ -4486,7 +4486,7 @@ PStatement CppParser::findMacro(const QString &phrase, const QString &fileName) PParsedFileInfo includes = mPreprocessor.findFileInfo(fileName); foreach (const PStatement& s, statements) { if (s->kind == StatementKind::Preprocessor) { - if (includes && fileName != s->fileName && !includes->includeFiles.contains(s->fileName)) + if (includes && fileName != s->fileName && !includes->includes.contains(s->fileName)) continue; return s; } @@ -4552,8 +4552,8 @@ PStatement CppParser::findMemberOfStatement(const QString& filename, return s; // hard defines } if (s->fileName == filename || s->definitionFileName==filename) { return s; - } else if (fileInfo && (fileInfo->includeFiles.contains(s->fileName) - || fileInfo->includeFiles.contains(s->definitionFileName))) { + } else if (fileInfo && (fileInfo->includes.contains(s->fileName) + || fileInfo->includes.contains(s->definitionFileName))) { return s; } } @@ -5907,7 +5907,7 @@ void CppParser::internalInvalidateFile(const QString &fileName) PParsedFileInfo p = findFileIncludes(fileName, true); if (p) { //fPreprocessor.InvalidDefinesInFile(FileName); //we don't need this, since we reset defines after each parse - //p->includeFiles.clear(); + //p->includes.clear(); //p->usings.clear(); for (PStatement& statement:p->statements) { if (statement->fileName==fileName) { @@ -5968,7 +5968,7 @@ QSet CppParser::calculateFilesToBeReparsed(const QString &fileName) result.insert(fileName); foreach (const QString& file, mProjectFiles) { PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(file); - if (fileInfo && fileInfo->includeFiles.contains(fileName)) { + if (fileInfo && fileInfo->includes.contains(fileName)) { result.insert(file); } } diff --git a/RedPandaIDE/parser/cpppreprocessor.cpp b/RedPandaIDE/parser/cpppreprocessor.cpp index 3e760625..0acf9fd9 100644 --- a/RedPandaIDE/parser/cpppreprocessor.cpp +++ b/RedPandaIDE/parser/cpppreprocessor.cpp @@ -225,7 +225,7 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) { QTextStream stream(&file); for (const PParsedFileInfo& fileInfo:mFileInfos) { - stream<baseFile<<" : " + stream<fileName<<" : " #if QT_VERSION >= QT_VERSION_CHECK(5,15,0) <includeFiles.keys()) { + foreach (const QString& s,fileInfo->includes.keys()) { stream<<"\t--"+s #if QT_VERSION >= QT_VERSION_CHECK(5,15,0) <baseFile; + fileName = fileInfo->fileName; } else { fileName.squeeze(); } if (mIncludes.size()>0) { // PParsedFile topFile = mIncludes.front(); - // if (topFile->fileIncludes->includeFiles.contains(fileName)) { + // if (topFile->fileIncludes->includes.contains(fileName)) { // PParsedFile innerMostFile = mIncludes.back(); - // innerMostFile->fileIncludes->includeFiles.insert(fileName, false); + // innerMostFile->fileIncludes->includes.insert(fileName, false); // return; //already included // } bool alreadyIncluded = false; for (PParsedFile& parsedFile:mIncludes) { - if (parsedFile->fileInfo->includeFiles.contains(fileName)) { + if (parsedFile->fileInfo->includes.contains(fileName)) { alreadyIncluded = true; continue; } - parsedFile->fileInfo->includeFiles.insert(fileName,false); + parsedFile->fileInfo->includes.insert(fileName,false); } PParsedFile innerMostFile = mIncludes.back(); - innerMostFile->fileInfo->includeFiles.insert(fileName,true); + innerMostFile->fileInfo->includes.insert(fileName,true); innerMostFile->fileInfo->directIncludes.append(fileName); if (alreadyIncluded) return; @@ -805,7 +805,7 @@ void CppPreprocessor::openInclude(QString fileName) if (!mCurrentFileInfo) { // do NOT create a new item for a file that's already in the list mCurrentFileInfo = std::make_shared(); - mCurrentFileInfo->baseFile = fileName; + mCurrentFileInfo->fileName = fileName; mFileInfos.insert(fileName,mCurrentFileInfo); } parsedFile->fileInfo = mCurrentFileInfo; @@ -832,8 +832,8 @@ void CppPreprocessor::openInclude(QString fileName) PParsedFileInfo fileInfo = findFileInfo(fileName); if (fileInfo) { for (PParsedFile& file:mIncludes) { - foreach (const QString& incFile,fileInfo->includeFiles.keys()) { - file->fileInfo->includeFiles.insert(incFile,false); + foreach (const QString& incFile,fileInfo->includes.keys()) { + file->fileInfo->includes.insert(incFile,false); } } } @@ -917,7 +917,7 @@ void CppPreprocessor::addDefinesInFile(const QString &fileName) PParsedFileInfo fileInfo = findFileInfo(fileName); if (fileInfo) { - foreach (const QString& file, fileInfo->includeFiles.keys()) { + foreach (const QString& file, fileInfo->includes.keys()) { addDefinesInFile(file); } } diff --git a/RedPandaIDE/parser/cpppreprocessor.h b/RedPandaIDE/parser/cpppreprocessor.h index 130ad1b7..2cb1afb3 100644 --- a/RedPandaIDE/parser/cpppreprocessor.h +++ b/RedPandaIDE/parser/cpppreprocessor.h @@ -43,6 +43,7 @@ struct ParsedFile { int branches; //branch levels; PParsedFileInfo fileInfo; // info of this file }; + using PParsedFile = std::shared_ptr; class CppPreprocessor diff --git a/RedPandaIDE/parser/parserutils.cpp b/RedPandaIDE/parser/parserutils.cpp index 6b995fe3..3d9eef01 100644 --- a/RedPandaIDE/parser/parserutils.cpp +++ b/RedPandaIDE/parser/parserutils.cpp @@ -778,3 +778,20 @@ bool ParsedFileInfo::isLineVisible(int line) } return lastI<0?true:branches[lastI]; } + +void ParsedFileInfo::includeFile(const QString &fileName) +{ + int count = includes.value(fileName,0); + count++; + includes.insert(fileName,count); +} + +void ParsedFileInfo::unincludeFile(const QString &fileName) +{ + int count = includes.value(fileName,0); + count--; + if (count<=0) + includes.remove(fileName); + else + includes.insert(fileName,count); +} diff --git a/RedPandaIDE/parser/parserutils.h b/RedPandaIDE/parser/parserutils.h index 462d42d9..efd52478 100644 --- a/RedPandaIDE/parser/parserutils.h +++ b/RedPandaIDE/parser/parserutils.h @@ -318,8 +318,8 @@ struct ClassInheritanceInfo { using PClassInheritanceInfo = std::shared_ptr; struct ParsedFileInfo { - QString baseFile; - QMap includeFiles; // true means the file is directly included, false means included indirectly + QString fileName; + QMap includes; QStringList directIncludes; // QSet usings; // namespaces it usings StatementMap statements; // but we don't save temporary statements (full name as key) @@ -328,6 +328,8 @@ struct ParsedFileInfo { QMap branches; QList> handledInheritances; bool isLineVisible(int line); + void includeFile(const QString &fileName); + void unincludeFile(const QString& fileName); }; using PParsedFileInfo = std::shared_ptr;