refactor: ParsedFileInfo
This commit is contained in:
parent
edbe230bf7
commit
9ef6d1f3e6
|
@ -204,7 +204,7 @@ PStatement CppParser::doFindScopeStatement(const QString &filename, int line) co
|
||||||
if (!fileInfo)
|
if (!fileInfo)
|
||||||
return PStatement();
|
return PStatement();
|
||||||
|
|
||||||
return fileInfo->scopes.findScopeAtLine(line);
|
return fileInfo->findScopeAtLine(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
PParsedFileInfo CppParser::findFileIncludes(const QString &filename, bool deleteIt)
|
PParsedFileInfo CppParser::findFileIncludes(const QString &filename, bool deleteIt)
|
||||||
|
@ -237,7 +237,7 @@ PStatement CppParser::findFunctionAt(const QString &fileName, int line)
|
||||||
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(fileName);
|
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(fileName);
|
||||||
if (!fileInfo)
|
if (!fileInfo)
|
||||||
return PStatement();
|
return PStatement();
|
||||||
for (PStatement& statement : fileInfo->statements) {
|
for (const 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)
|
||||||
|
@ -672,7 +672,7 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement, QSet<S
|
||||||
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 (fileInfo->includes.contains(resultStatement->fileName)) {
|
if (fileInfo->including(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 (fileInfo->includes.contains(resultStatement->fileName)) {
|
if (fileInfo->including(resultStatement->fileName)) {
|
||||||
result = resultStatement;
|
result = resultStatement;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -841,7 +841,7 @@ QStringList CppParser::getFileDirectIncludes(const QString &filename)
|
||||||
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(filename);
|
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(filename);
|
||||||
|
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
return fileInfo->directIncludes;
|
return fileInfo->directIncludes();
|
||||||
}
|
}
|
||||||
return QStringList();
|
return QStringList();
|
||||||
|
|
||||||
|
@ -857,7 +857,7 @@ QSet<QString> CppParser::internalGetIncludedFiles(const QString &filename) const
|
||||||
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(filename);
|
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(filename);
|
||||||
|
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
foreach (const QString& file, fileInfo->includes.keys()) {
|
foreach (const QString& file, fileInfo->includes()) {
|
||||||
list.insert(file);
|
list.insert(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -885,13 +885,13 @@ QSet<QString> CppParser::internalGetFileUsings(const QString &filename) const
|
||||||
// return result;
|
// return result;
|
||||||
PParsedFileInfo fileInfo= mPreprocessor.findFileInfo(filename);
|
PParsedFileInfo fileInfo= mPreprocessor.findFileInfo(filename);
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
foreach (const QString& usingName, fileInfo->usings) {
|
foreach (const QString& usingName, fileInfo->usings()) {
|
||||||
result.insert(usingName);
|
result.insert(usingName);
|
||||||
}
|
}
|
||||||
foreach (const QString& subFile,fileInfo->includes.keys()){
|
foreach (const QString& subFile,fileInfo->includes()){
|
||||||
PParsedFileInfo subIncludes = mPreprocessor.findFileInfo(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1438,8 +1438,7 @@ PStatement CppParser::addStatement(const PStatement& parent,
|
||||||
if (oldStatement->fileName!=fileName) {
|
if (oldStatement->fileName!=fileName) {
|
||||||
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(fileName);
|
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(fileName);
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
fileInfo->statements.insert(oldStatement->fullName,
|
fileInfo->addStatement(oldStatement);
|
||||||
oldStatement);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oldStatement->definitionLine = line;
|
oldStatement->definitionLine = line;
|
||||||
|
@ -1499,7 +1498,7 @@ PStatement CppParser::addStatement(const PStatement& parent,
|
||||||
if (result->kind!= StatementKind::Block) {
|
if (result->kind!= StatementKind::Block) {
|
||||||
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(fileName);
|
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(fileName);
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
fileInfo->statements.insert(result->fullName,result);
|
fileInfo->addStatement(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -1747,7 +1746,7 @@ void CppParser::addSoloScopeLevel(PStatement& statement, int line, bool shouldRe
|
||||||
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(mCurrentFile);
|
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(mCurrentFile);
|
||||||
|
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
fileInfo->scopes.addScope(line,statement);
|
fileInfo->addScope(line,statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set new scope
|
// Set new scope
|
||||||
|
@ -1782,11 +1781,11 @@ void CppParser::removeScopeLevel(int line, int maxIndex)
|
||||||
if (currentScope->children.isEmpty()) {
|
if (currentScope->children.isEmpty()) {
|
||||||
// remove no children block
|
// remove no children block
|
||||||
if (fileInfo)
|
if (fileInfo)
|
||||||
fileInfo->scopes.removeLastScope();
|
fileInfo->removeLastScope();
|
||||||
mStatementList.deleteStatement(currentScope);
|
mStatementList.deleteStatement(currentScope);
|
||||||
} else {
|
} else {
|
||||||
if (fileInfo)
|
if (fileInfo)
|
||||||
fileInfo->statements.insert(currentScope->fullName,currentScope);
|
fileInfo->addStatement(currentScope);
|
||||||
}
|
}
|
||||||
} else if (currentScope->kind == StatementKind::Class) {
|
} else if (currentScope->kind == StatementKind::Class) {
|
||||||
mIndex=indexOfNextSemicolon(mIndex, maxIndex);
|
mIndex=indexOfNextSemicolon(mIndex, maxIndex);
|
||||||
|
@ -1797,8 +1796,8 @@ void CppParser::removeScopeLevel(int line, int maxIndex)
|
||||||
|
|
||||||
// Set new scope
|
// Set new scope
|
||||||
currentScope = getCurrentScope();
|
currentScope = getCurrentScope();
|
||||||
if (fileInfo && fileInfo->scopes.lastScope()!=currentScope) {
|
if (fileInfo && fileInfo->lastScope()!=currentScope) {
|
||||||
fileInfo->scopes.addScope(line,currentScope);
|
fileInfo->addScope(line,currentScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!currentScope) {
|
if (!currentScope) {
|
||||||
|
@ -1843,7 +1842,7 @@ QStringList CppParser::sortFilesByIncludeRelations(const QSet<QString> &files)
|
||||||
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(file);
|
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(file);
|
||||||
bool hasInclude=false;
|
bool hasInclude=false;
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
foreach(const QString& inc,fileInfo->includes.keys()) {
|
foreach(const QString& inc,fileInfo->includes()) {
|
||||||
if (fileSet.contains(inc)) {
|
if (fileSet.contains(inc)) {
|
||||||
hasInclude=true;
|
hasInclude=true;
|
||||||
break;
|
break;
|
||||||
|
@ -3397,7 +3396,7 @@ void CppParser::handlePreprocessor()
|
||||||
mCurrentFile = s.mid(0,delimPos).trimmed();
|
mCurrentFile = s.mid(0,delimPos).trimmed();
|
||||||
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(mCurrentFile);
|
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(mCurrentFile);
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
mCurrentFile = fileInfo->fileName;
|
mCurrentFile = fileInfo->fileName();
|
||||||
} else {
|
} else {
|
||||||
mCurrentFile.squeeze();
|
mCurrentFile.squeeze();
|
||||||
}
|
}
|
||||||
|
@ -3982,7 +3981,7 @@ void CppParser::handleUsing(int maxIndex)
|
||||||
if (!fileInfo)
|
if (!fileInfo)
|
||||||
return;
|
return;
|
||||||
if (mNamespaces.contains(usingName)) {
|
if (mNamespaces.contains(usingName)) {
|
||||||
fileInfo->usings.insert(usingName);
|
fileInfo->addUsing(usingName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//skip ;
|
//skip ;
|
||||||
|
@ -4287,7 +4286,7 @@ void CppParser::handleInheritance(PStatement derivedStatement, PClassInheritance
|
||||||
inheritanceInfo->handled = true;
|
inheritanceInfo->handled = true;
|
||||||
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(statement->fileName);
|
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(statement->fileName);
|
||||||
Q_ASSERT(fileInfo!=nullptr);
|
Q_ASSERT(fileInfo!=nullptr);
|
||||||
fileInfo->handledInheritances.append(inheritanceInfo);
|
fileInfo->addHandledInheritances(inheritanceInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4486,7 +4485,7 @@ PStatement CppParser::findMacro(const QString &phrase, const QString &fileName)
|
||||||
PParsedFileInfo includes = mPreprocessor.findFileInfo(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->includes.contains(s->fileName))
|
if (includes && fileName != s->fileName && !includes->including(s->fileName))
|
||||||
continue;
|
continue;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -4552,8 +4551,8 @@ PStatement CppParser::findMemberOfStatement(const QString& filename,
|
||||||
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 (fileInfo && (fileInfo->includes.contains(s->fileName)
|
} else if (fileInfo && (fileInfo->including(s->fileName)
|
||||||
|| fileInfo->includes.contains(s->definitionFileName))) {
|
|| fileInfo->including(s->definitionFileName))) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5909,7 +5908,7 @@ void CppParser::internalInvalidateFile(const QString &fileName)
|
||||||
//fPreprocessor.InvalidDefinesInFile(FileName); //we don't need this, since we reset defines after each parse
|
//fPreprocessor.InvalidDefinesInFile(FileName); //we don't need this, since we reset defines after each parse
|
||||||
//p->includes.clear();
|
//p->includes.clear();
|
||||||
//p->usings.clear();
|
//p->usings.clear();
|
||||||
for (PStatement& statement:p->statements) {
|
for(PStatement statement:p->statements()) {
|
||||||
if (statement->fileName==fileName) {
|
if (statement->fileName==fileName) {
|
||||||
mStatementList.deleteStatement(statement);
|
mStatementList.deleteStatement(statement);
|
||||||
} else {
|
} else {
|
||||||
|
@ -5918,16 +5917,16 @@ void CppParser::internalInvalidateFile(const QString &fileName)
|
||||||
statement->definitionLine = statement->line;
|
statement->definitionLine = statement->line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p->statements.clear();
|
p->clearStatements();
|
||||||
|
|
||||||
//invalidate all handledInheritances
|
//invalidate all handledInheritances
|
||||||
for (std::weak_ptr<ClassInheritanceInfo> &pWeakInfo: p->handledInheritances) {
|
for (std::weak_ptr<ClassInheritanceInfo> pWeakInfo: p->handledInheritances()) {
|
||||||
PClassInheritanceInfo info = pWeakInfo.lock();
|
PClassInheritanceInfo info = pWeakInfo.lock();
|
||||||
if (info) {
|
if (info) {
|
||||||
info->handled = false;
|
info->handled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p->handledInheritances.clear();
|
p->clearHandledInheritances();
|
||||||
}
|
}
|
||||||
|
|
||||||
//remove all statements from namespace cache
|
//remove all statements from namespace cache
|
||||||
|
@ -5968,7 +5967,7 @@ QSet<QString> CppParser::calculateFilesToBeReparsed(const QString &fileName)
|
||||||
result.insert(fileName);
|
result.insert(fileName);
|
||||||
foreach (const QString& file, mProjectFiles) {
|
foreach (const QString& file, mProjectFiles) {
|
||||||
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(file);
|
PParsedFileInfo fileInfo = mPreprocessor.findFileInfo(file);
|
||||||
if (fileInfo && fileInfo->includes.contains(fileName)) {
|
if (fileInfo && fileInfo->including(fileName)) {
|
||||||
result.insert(file);
|
result.insert(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,7 +225,7 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const
|
||||||
if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) {
|
if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) {
|
||||||
QTextStream stream(&file);
|
QTextStream stream(&file);
|
||||||
for (const PParsedFileInfo& fileInfo:mFileInfos) {
|
for (const PParsedFileInfo& fileInfo:mFileInfos) {
|
||||||
stream<<fileInfo->fileName<<" : "
|
stream<<fileInfo->fileName()<<" : "
|
||||||
#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,fileInfo->includes.keys()) {
|
foreach (const QString& s,fileInfo->includes()) {
|
||||||
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;
|
||||||
|
@ -762,7 +762,7 @@ void CppPreprocessor::openInclude(QString fileName)
|
||||||
{
|
{
|
||||||
PParsedFileInfo fileInfo = findFileInfo(fileName);
|
PParsedFileInfo fileInfo = findFileInfo(fileName);
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
fileName = fileInfo->fileName;
|
fileName = fileInfo->fileName();
|
||||||
} else {
|
} else {
|
||||||
fileName.squeeze();
|
fileName.squeeze();
|
||||||
}
|
}
|
||||||
|
@ -775,15 +775,14 @@ void CppPreprocessor::openInclude(QString fileName)
|
||||||
// }
|
// }
|
||||||
bool alreadyIncluded = false;
|
bool alreadyIncluded = false;
|
||||||
for (PParsedFile& parsedFile:mIncludes) {
|
for (PParsedFile& parsedFile:mIncludes) {
|
||||||
if (parsedFile->fileInfo->includes.contains(fileName)) {
|
if (parsedFile->fileInfo->including(fileName)) {
|
||||||
alreadyIncluded = true;
|
alreadyIncluded = true;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
parsedFile->fileInfo->includes.insert(fileName,false);
|
parsedFile->fileInfo->include(fileName);
|
||||||
}
|
}
|
||||||
PParsedFile innerMostFile = mIncludes.back();
|
PParsedFile innerMostFile = mIncludes.back();
|
||||||
innerMostFile->fileInfo->includes.insert(fileName,true);
|
innerMostFile->fileInfo->include(fileName);
|
||||||
innerMostFile->fileInfo->directIncludes.append(fileName);
|
innerMostFile->fileInfo->directInclude(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
|
||||||
|
@ -804,8 +803,7 @@ void CppPreprocessor::openInclude(QString fileName)
|
||||||
mCurrentFileInfo = findFileInfo(fileName);
|
mCurrentFileInfo = findFileInfo(fileName);
|
||||||
if (!mCurrentFileInfo) {
|
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
|
||||||
mCurrentFileInfo = std::make_shared<ParsedFileInfo>();
|
mCurrentFileInfo = std::make_shared<ParsedFileInfo>(fileName);
|
||||||
mCurrentFileInfo->fileName = fileName;
|
|
||||||
mFileInfos.insert(fileName,mCurrentFileInfo);
|
mFileInfos.insert(fileName,mCurrentFileInfo);
|
||||||
}
|
}
|
||||||
parsedFile->fileInfo = mCurrentFileInfo;
|
parsedFile->fileInfo = mCurrentFileInfo;
|
||||||
|
@ -832,8 +830,8 @@ void CppPreprocessor::openInclude(QString fileName)
|
||||||
PParsedFileInfo fileInfo = findFileInfo(fileName);
|
PParsedFileInfo fileInfo = findFileInfo(fileName);
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
for (PParsedFile& file:mIncludes) {
|
for (PParsedFile& file:mIncludes) {
|
||||||
foreach (const QString& incFile,fileInfo->includes.keys()) {
|
foreach (const QString& incFile,fileInfo->includes()) {
|
||||||
file->fileInfo->includes.insert(incFile,false);
|
file->fileInfo->include(incFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -917,7 +915,7 @@ void CppPreprocessor::addDefinesInFile(const QString &fileName)
|
||||||
|
|
||||||
PParsedFileInfo fileInfo = findFileInfo(fileName);
|
PParsedFileInfo fileInfo = findFileInfo(fileName);
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
foreach (const QString& file, fileInfo->includes.keys()) {
|
foreach (const QString& file, fileInfo->includes()) {
|
||||||
addDefinesInFile(file);
|
addDefinesInFile(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,7 @@ private:
|
||||||
}
|
}
|
||||||
void setCurrentBranch(BranchResult value){
|
void setCurrentBranch(BranchResult value){
|
||||||
if (!sameResultWithCurrentBranch(value)) {
|
if (!sameResultWithCurrentBranch(value)) {
|
||||||
mCurrentFileInfo->branches.insert(mIndex+1,value==BranchResult::isTrue);
|
mCurrentFileInfo->insertBranch(mIndex+1,value==BranchResult::isTrue);
|
||||||
}
|
}
|
||||||
mBranchResults.append(value);
|
mBranchResults.append(value);
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ private:
|
||||||
mBranchResults.pop_back();
|
mBranchResults.pop_back();
|
||||||
}
|
}
|
||||||
if (!sameResultWithCurrentBranch(value)) {
|
if (!sameResultWithCurrentBranch(value)) {
|
||||||
mCurrentFileInfo->branches.insert(mIndex,getCurrentBranch()==BranchResult::isTrue);
|
mCurrentFileInfo->insertBranch(mIndex,getCurrentBranch()==BranchResult::isTrue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void addDefinesInFile(const QString& fileName);
|
void addDefinesInFile(const QString& fileName);
|
||||||
|
|
|
@ -544,7 +544,7 @@ bool isCFile(const QString& filename)
|
||||||
return CppSourceExts->contains(fileInfo.suffix().toLower());
|
return CppSourceExts->contains(fileInfo.suffix().toLower());
|
||||||
}
|
}
|
||||||
|
|
||||||
PStatement CppScopes::findScopeAtLine(int line)
|
PStatement CppScopes::findScopeAtLine(int line) const
|
||||||
{
|
{
|
||||||
if (mScopes.isEmpty())
|
if (mScopes.isEmpty())
|
||||||
return PStatement();
|
return PStatement();
|
||||||
|
@ -582,7 +582,7 @@ void CppScopes::addScope(int line, PStatement scopeStatement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PStatement CppScopes::lastScope()
|
PStatement CppScopes::lastScope() const
|
||||||
{
|
{
|
||||||
if (mScopes.isEmpty())
|
if (mScopes.isEmpty())
|
||||||
return PStatement();
|
return PStatement();
|
||||||
|
@ -767,31 +767,129 @@ bool isTypeKind(StatementKind kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParsedFileInfo::isLineVisible(int line)
|
ParsedFileInfo::ParsedFileInfo(const QString &fileName):
|
||||||
|
mFileName { fileName }
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParsedFileInfo::insertBranch(int level, bool branchTrue)
|
||||||
|
{
|
||||||
|
mBranches.insert(level, branchTrue);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParsedFileInfo::isLineVisible(int line) const
|
||||||
{
|
{
|
||||||
int lastI=-1;
|
int lastI=-1;
|
||||||
foreach(int i,branches.keys()) {
|
foreach(int i,mBranches.keys()) {
|
||||||
if (line<i)
|
if (line<i)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
lastI = i;
|
lastI = i;
|
||||||
}
|
}
|
||||||
return lastI<0?true:branches[lastI];
|
return lastI<0?true:mBranches[lastI];
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParsedFileInfo::includeFile(const QString &fileName)
|
void ParsedFileInfo::include(const QString &fileName)
|
||||||
{
|
{
|
||||||
int count = includes.value(fileName,0);
|
int count = mIncludeCounts.value(fileName,0);
|
||||||
count++;
|
count++;
|
||||||
includes.insert(fileName,count);
|
mIncludeCounts.insert(fileName,count);
|
||||||
|
mIncludes.insert(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParsedFileInfo::unincludeFile(const QString &fileName)
|
void ParsedFileInfo::uninclude(const QString &fileName)
|
||||||
{
|
{
|
||||||
int count = includes.value(fileName,0);
|
int count = mIncludeCounts.value(fileName,0);
|
||||||
count--;
|
count--;
|
||||||
if (count<=0)
|
if (count<=0) {
|
||||||
includes.remove(fileName);
|
mIncludeCounts.remove(fileName);
|
||||||
else
|
mIncludes.remove(fileName);
|
||||||
includes.insert(fileName,count);
|
} else
|
||||||
|
mIncludeCounts.insert(fileName,count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParsedFileInfo::directInclude(const QString &fileName)
|
||||||
|
{
|
||||||
|
mDirectIncludes.append(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParsedFileInfo::including(const QString &fileName) const
|
||||||
|
{
|
||||||
|
return mIncludes.contains(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QSet<QString>& ParsedFileInfo::includes() const
|
||||||
|
{
|
||||||
|
return mIncludes;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<std::weak_ptr<ClassInheritanceInfo> >& ParsedFileInfo::handledInheritances() const
|
||||||
|
{
|
||||||
|
return mHandledInheritances;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ParsedFileInfo::fileName() const
|
||||||
|
{
|
||||||
|
return mFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
PStatement ParsedFileInfo::findScopeAtLine(int line) const
|
||||||
|
{
|
||||||
|
return mScopes.findScopeAtLine(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParsedFileInfo::addStatement(const PStatement &statement)
|
||||||
|
{
|
||||||
|
mStatements.insert(statement->fullName,statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParsedFileInfo::clearStatements()
|
||||||
|
{
|
||||||
|
mStatements.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParsedFileInfo::addScope(int line, const PStatement &scope)
|
||||||
|
{
|
||||||
|
mScopes.addScope(line,scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParsedFileInfo::removeLastScope()
|
||||||
|
{
|
||||||
|
mScopes.removeLastScope();
|
||||||
|
}
|
||||||
|
|
||||||
|
PStatement ParsedFileInfo::lastScope() const
|
||||||
|
{
|
||||||
|
return mScopes.lastScope();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParsedFileInfo::addUsing(const QString &usingSymbol)
|
||||||
|
{
|
||||||
|
mUsings.insert(usingSymbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParsedFileInfo::addHandledInheritances(std::weak_ptr<ClassInheritanceInfo> classInheritanceInfo)
|
||||||
|
{
|
||||||
|
mHandledInheritances.append(classInheritanceInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParsedFileInfo::clearHandledInheritances()
|
||||||
|
{
|
||||||
|
mHandledInheritances.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
const StatementMap& ParsedFileInfo::statements() const
|
||||||
|
{
|
||||||
|
return mStatements;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QSet<QString>& ParsedFileInfo::usings() const
|
||||||
|
{
|
||||||
|
return mUsings;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QStringList& ParsedFileInfo::directIncludes() const
|
||||||
|
{
|
||||||
|
return mDirectIncludes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,9 +295,9 @@ using PCppScope = std::shared_ptr<CppScope>;
|
||||||
class CppScopes {
|
class CppScopes {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PStatement findScopeAtLine(int line);
|
PStatement findScopeAtLine(int line) const;
|
||||||
void addScope(int line, PStatement scopeStatement);
|
void addScope(int line, PStatement scopeStatement);
|
||||||
PStatement lastScope();
|
PStatement lastScope() const;
|
||||||
void removeLastScope();
|
void removeLastScope();
|
||||||
void clear();
|
void clear();
|
||||||
private:
|
private:
|
||||||
|
@ -317,19 +317,46 @@ struct ClassInheritanceInfo {
|
||||||
|
|
||||||
using PClassInheritanceInfo = std::shared_ptr<ClassInheritanceInfo>;
|
using PClassInheritanceInfo = std::shared_ptr<ClassInheritanceInfo>;
|
||||||
|
|
||||||
struct ParsedFileInfo {
|
class ParsedFileInfo {
|
||||||
QString fileName;
|
public:
|
||||||
QMap<QString, int> includes;
|
ParsedFileInfo(const QString& fileName);
|
||||||
QStringList directIncludes; //
|
ParsedFileInfo(const ParsedFileInfo&)=delete;
|
||||||
QSet<QString> usings; // namespaces it usings
|
ParsedFileInfo& operator=(const ParsedFileInfo&)=delete;
|
||||||
StatementMap statements; // but we don't save temporary statements (full name as key)
|
void insertBranch(int level, bool branchTrue);
|
||||||
StatementMap declaredStatements; // statements declared in this file (full name as key)
|
bool isLineVisible(int line) const;
|
||||||
CppScopes scopes; // int is start line of the statement scope
|
void include(const QString &fileName);
|
||||||
QMap<int,bool> branches;
|
void uninclude(const QString &fileName);
|
||||||
QList<std::weak_ptr<ClassInheritanceInfo>> handledInheritances;
|
void directInclude(const QString &fileName);
|
||||||
bool isLineVisible(int line);
|
bool including(const QString &fileName) const;
|
||||||
void includeFile(const QString &fileName);
|
PStatement findScopeAtLine(int line) const;
|
||||||
void unincludeFile(const QString& fileName);
|
void addStatement(const PStatement &statement);
|
||||||
|
void clearStatements();
|
||||||
|
void addScope(int line, const PStatement &scope);
|
||||||
|
void removeLastScope();
|
||||||
|
PStatement lastScope() const;
|
||||||
|
void addUsing(const QString &usingSymbol);
|
||||||
|
void addHandledInheritances(std::weak_ptr<ClassInheritanceInfo> classInheritanceInfo);
|
||||||
|
void clearHandledInheritances();
|
||||||
|
|
||||||
|
QString fileName() const;
|
||||||
|
const StatementMap& statements() const;
|
||||||
|
const QSet<QString>& usings() const;
|
||||||
|
const QStringList& directIncludes() const;
|
||||||
|
const QSet<QString>& includes() const;
|
||||||
|
const QList<std::weak_ptr<ClassInheritanceInfo> >& handledInheritances() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString mFileName;
|
||||||
|
QMap<QString, int> mIncludeCounts;
|
||||||
|
QSet<QString> mIncludes;
|
||||||
|
QStringList mDirectIncludes; //We need order here.
|
||||||
|
QSet<QString> mUsings; // namespaces it usings
|
||||||
|
StatementMap mStatements; // but we don't save temporary statements (full name as key)
|
||||||
|
StatementMap mDeclaredStatements; // statements declared in this file (full name as key)
|
||||||
|
CppScopes mScopes; // int is start line of the statement scope
|
||||||
|
QMap<int,bool> mBranches;
|
||||||
|
QList<std::weak_ptr<ClassInheritanceInfo>> mHandledInheritances;
|
||||||
|
|
||||||
};
|
};
|
||||||
using PParsedFileInfo = std::shared_ptr<ParsedFileInfo>;
|
using PParsedFileInfo = std::shared_ptr<ParsedFileInfo>;
|
||||||
|
|
||||||
|
|
|
@ -286,7 +286,7 @@ void ClassBrowserModel::addMembers()
|
||||||
PParsedFileInfo p = mParser->findFileIncludes(mCurrentFile);
|
PParsedFileInfo p = mParser->findFileIncludes(mCurrentFile);
|
||||||
if (!p)
|
if (!p)
|
||||||
return;
|
return;
|
||||||
filterChildren(mRoot,p->statements);
|
filterChildren(mRoot,p->statements());
|
||||||
} else {
|
} else {
|
||||||
if (mParser->projectFiles().isEmpty())
|
if (mParser->projectFiles().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
@ -294,7 +294,7 @@ void ClassBrowserModel::addMembers()
|
||||||
PParsedFileInfo p = mParser->findFileIncludes(file);
|
PParsedFileInfo p = mParser->findFileIncludes(file);
|
||||||
if (!p)
|
if (!p)
|
||||||
return;
|
return;
|
||||||
filterChildren(mRoot,p->statements);
|
filterChildren(mRoot,p->statements());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sortNode(mRoot);
|
sortNode(mRoot);
|
||||||
|
|
Loading…
Reference in New Issue