refactor
This commit is contained in:
parent
4f1cc3d50d
commit
edbe230bf7
|
@ -672,7 +672,7 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement, QSet<S
|
|||
if (nsName.isEmpty()) {
|
||||
QList<PStatement> 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<S
|
|||
QList<PStatement> 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<QString> 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<QString> 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<QString> &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<QString> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<<fileInfo->baseFile<<" : "
|
||||
stream<<fileInfo->fileName<<" : "
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
||||
<<Qt::endl;
|
||||
#else
|
||||
|
@ -237,7 +237,7 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const
|
|||
#else
|
||||
<<endl;
|
||||
#endif
|
||||
foreach (const QString& s,fileInfo->includeFiles.keys()) {
|
||||
foreach (const QString& s,fileInfo->includes.keys()) {
|
||||
stream<<"\t--"+s
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
||||
<<Qt::endl;
|
||||
|
@ -762,27 +762,27 @@ void CppPreprocessor::openInclude(QString fileName)
|
|||
{
|
||||
PParsedFileInfo fileInfo = findFileInfo(fileName);
|
||||
if (fileInfo) {
|
||||
fileName = fileInfo->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<ParsedFileInfo>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ struct ParsedFile {
|
|||
int branches; //branch levels;
|
||||
PParsedFileInfo fileInfo; // info of this file
|
||||
};
|
||||
|
||||
using PParsedFile = std::shared_ptr<ParsedFile>;
|
||||
|
||||
class CppPreprocessor
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -318,8 +318,8 @@ struct ClassInheritanceInfo {
|
|||
using PClassInheritanceInfo = std::shared_ptr<ClassInheritanceInfo>;
|
||||
|
||||
struct ParsedFileInfo {
|
||||
QString baseFile;
|
||||
QMap<QString, bool> includeFiles; // true means the file is directly included, false means included indirectly
|
||||
QString fileName;
|
||||
QMap<QString, int> includes;
|
||||
QStringList directIncludes; //
|
||||
QSet<QString> usings; // namespaces it usings
|
||||
StatementMap statements; // but we don't save temporary statements (full name as key)
|
||||
|
@ -328,6 +328,8 @@ struct ParsedFileInfo {
|
|||
QMap<int,bool> branches;
|
||||
QList<std::weak_ptr<ClassInheritanceInfo>> handledInheritances;
|
||||
bool isLineVisible(int line);
|
||||
void includeFile(const QString &fileName);
|
||||
void unincludeFile(const QString& fileName);
|
||||
};
|
||||
using PParsedFileInfo = std::shared_ptr<ParsedFileInfo>;
|
||||
|
||||
|
|
Loading…
Reference in New Issue