refactor: rename FileIncludes to ParsedFileInfo
This commit is contained in:
parent
6b6c19574d
commit
fd062e2f34
|
@ -200,17 +200,17 @@ PStatement CppParser::findScopeStatement(const QString &filename, int line)
|
|||
|
||||
PStatement CppParser::doFindScopeStatement(const QString &filename, int line) const
|
||||
{
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(filename);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(filename);
|
||||
if (!fileIncludes)
|
||||
return PStatement();
|
||||
|
||||
return fileIncludes->scopes.findScopeAtLine(line);
|
||||
}
|
||||
|
||||
PFileIncludes CppParser::findFileIncludes(const QString &filename, bool deleteIt)
|
||||
PParsedFileInfo CppParser::findFileIncludes(const QString &filename, bool deleteIt)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(filename);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(filename);
|
||||
if (deleteIt && fileIncludes)
|
||||
mPreprocessor.removeFileIncludes(filename);
|
||||
return fileIncludes;
|
||||
|
@ -234,7 +234,7 @@ QString CppParser::findTemplateParamOf(const QString &fileName, const QString &p
|
|||
PStatement CppParser::findFunctionAt(const QString &fileName, int line)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(fileName);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(fileName);
|
||||
if (!fileIncludes)
|
||||
return PStatement();
|
||||
for (PStatement& statement : fileIncludes->statements) {
|
||||
|
@ -664,7 +664,7 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement, QSet<S
|
|||
return PStatement();
|
||||
QString nsName=statement->type.mid(0,pos);
|
||||
QString name = statement->type.mid(pos+2);
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(statement->fileName);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(statement->fileName);
|
||||
if (!fileIncludes)
|
||||
return PStatement();
|
||||
foundSet.insert(statement.get());
|
||||
|
@ -838,7 +838,7 @@ QStringList CppParser::getFileDirectIncludes(const QString &filename)
|
|||
return QStringList();
|
||||
if (filename.isEmpty())
|
||||
return QStringList();
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(filename);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(filename);
|
||||
|
||||
if (fileIncludes) {
|
||||
return fileIncludes->directIncludes;
|
||||
|
@ -854,7 +854,7 @@ QSet<QString> CppParser::internalGetIncludedFiles(const QString &filename) const
|
|||
if (filename.isEmpty())
|
||||
return list;
|
||||
list.insert(filename);
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(filename);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(filename);
|
||||
|
||||
if (fileIncludes) {
|
||||
foreach (const QString& file, fileIncludes->includeFiles.keys()) {
|
||||
|
@ -883,13 +883,13 @@ QSet<QString> CppParser::internalGetFileUsings(const QString &filename) const
|
|||
return result;
|
||||
// if (mParsing)
|
||||
// return result;
|
||||
PFileIncludes fileIncludes= mPreprocessor.findFileIncludes(filename);
|
||||
PParsedFileInfo fileIncludes= mPreprocessor.findFileIncludes(filename);
|
||||
if (fileIncludes) {
|
||||
foreach (const QString& usingName, fileIncludes->usings) {
|
||||
result.insert(usingName);
|
||||
}
|
||||
foreach (const QString& subFile,fileIncludes->includeFiles.keys()){
|
||||
PFileIncludes subIncludes = mPreprocessor.findFileIncludes(subFile);
|
||||
PParsedFileInfo subIncludes = mPreprocessor.findFileIncludes(subFile);
|
||||
if (subIncludes) {
|
||||
foreach (const QString& usingName, subIncludes->usings) {
|
||||
result.insert(usingName);
|
||||
|
@ -939,7 +939,7 @@ bool CppParser::isLineVisible(const QString &fileName, int line)
|
|||
if (mParsing) {
|
||||
return true;
|
||||
}
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(fileName);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(fileName);
|
||||
if (!fileIncludes)
|
||||
return true;
|
||||
return fileIncludes->isLineVisible(line);
|
||||
|
@ -1436,7 +1436,7 @@ PStatement CppParser::addStatement(const PStatement& parent,
|
|||
if (oldStatement && !oldStatement->hasDefinition()) {
|
||||
oldStatement->setHasDefinition(true);
|
||||
if (oldStatement->fileName!=fileName) {
|
||||
PFileIncludes fileIncludes=mPreprocessor.findFileIncludes(fileName);
|
||||
PParsedFileInfo fileIncludes=mPreprocessor.findFileIncludes(fileName);
|
||||
if (fileIncludes) {
|
||||
fileIncludes->statements.insert(oldStatement->fullName,
|
||||
oldStatement);
|
||||
|
@ -1497,7 +1497,7 @@ PStatement CppParser::addStatement(const PStatement& parent,
|
|||
}
|
||||
|
||||
if (result->kind!= StatementKind::Block) {
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(fileName);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(fileName);
|
||||
if (fileIncludes) {
|
||||
fileIncludes->statements.insert(result->fullName,result);
|
||||
}
|
||||
|
@ -1744,7 +1744,7 @@ void CppParser::addSoloScopeLevel(PStatement& statement, int line, bool shouldRe
|
|||
|
||||
mCurrentScope.append(statement);
|
||||
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(mCurrentFile);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(mCurrentFile);
|
||||
|
||||
if (fileIncludes) {
|
||||
fileIncludes->scopes.addScope(line,statement);
|
||||
|
@ -1776,7 +1776,7 @@ void CppParser::removeScopeLevel(int line, int maxIndex)
|
|||
// qDebug()<<"--remove scope"<<mCurrentFile<<line<<mCurrentClassScope.count();
|
||||
#endif
|
||||
PStatement currentScope = getCurrentScope();
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(mCurrentFile);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(mCurrentFile);
|
||||
if (currentScope) {
|
||||
if (currentScope->kind == StatementKind::Block) {
|
||||
if (currentScope->children.isEmpty()) {
|
||||
|
@ -1841,7 +1841,7 @@ QStringList CppParser::sortFilesByIncludeRelations(const QSet<QString> &files)
|
|||
while (!fileSet.isEmpty()) {
|
||||
bool found=false;
|
||||
foreach (const QString& file,fileSet) {
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(file);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(file);
|
||||
bool hasInclude=false;
|
||||
if (fileIncludes) {
|
||||
foreach(const QString& inc,fileIncludes->includeFiles.keys()) {
|
||||
|
@ -3391,7 +3391,7 @@ void CppParser::handlePreprocessor()
|
|||
if (delimPos>=0) {
|
||||
// qDebug()<<mCurrentScope.size()<<mCurrentFile<<mTokenizer[mIndex]->line<<s.mid(0,delimPos).trimmed();
|
||||
mCurrentFile = s.mid(0,delimPos).trimmed();
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(mCurrentFile);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(mCurrentFile);
|
||||
if (fileIncludes) {
|
||||
mCurrentFile = fileIncludes->baseFile;
|
||||
} else {
|
||||
|
@ -3974,7 +3974,7 @@ void CppParser::handleUsing(int maxIndex)
|
|||
scopeStatement->usingList.insert(fullName);
|
||||
}
|
||||
} else {
|
||||
PFileIncludes fileInfo = mPreprocessor.findFileIncludes(mCurrentFile);
|
||||
PParsedFileInfo fileInfo = mPreprocessor.findFileIncludes(mCurrentFile);
|
||||
if (!fileInfo)
|
||||
return;
|
||||
if (mNamespaces.contains(usingName)) {
|
||||
|
@ -4281,7 +4281,7 @@ void CppParser::handleInheritance(PStatement derivedStatement, PClassInheritance
|
|||
inheritanceInfo->visibility);
|
||||
// inheritanceInfo->parentClassFilename = statement->fileName;
|
||||
inheritanceInfo->handled = true;
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(statement->fileName);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(statement->fileName);
|
||||
Q_ASSERT(fileIncludes!=nullptr);
|
||||
fileIncludes->handledInheritances.append(inheritanceInfo);
|
||||
}
|
||||
|
@ -4479,7 +4479,7 @@ PStatement CppParser::findMacro(const QString &phrase, const QString &fileName)
|
|||
if (statementMap.isEmpty())
|
||||
return PStatement();
|
||||
StatementList statements = statementMap.values(phrase);
|
||||
PFileIncludes includes = mPreprocessor.findFileIncludes(fileName);
|
||||
PParsedFileInfo includes = mPreprocessor.findFileIncludes(fileName);
|
||||
foreach (const PStatement& s, statements) {
|
||||
if (s->kind == StatementKind::Preprocessor) {
|
||||
if (includes && fileName != s->fileName && !includes->includeFiles.contains(s->fileName))
|
||||
|
@ -4542,7 +4542,7 @@ PStatement CppParser::findMemberOfStatement(const QString& filename,
|
|||
return statementMap.value(s,PStatement());
|
||||
} else {
|
||||
QList<PStatement> stats = statementMap.values(s);
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(filename);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(filename);
|
||||
foreach(const PStatement &s,stats) {
|
||||
if (s->line==-1) {
|
||||
return s; // hard defines
|
||||
|
@ -5900,7 +5900,7 @@ void CppParser::internalInvalidateFile(const QString &fileName)
|
|||
return;
|
||||
|
||||
// remove its include files list
|
||||
PFileIncludes p = findFileIncludes(fileName, true);
|
||||
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();
|
||||
|
@ -5963,7 +5963,7 @@ QSet<QString> CppParser::calculateFilesToBeReparsed(const QString &fileName)
|
|||
QSet<QString> result;
|
||||
result.insert(fileName);
|
||||
foreach (const QString& file, mProjectFiles) {
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(file);
|
||||
PParsedFileInfo fileIncludes = mPreprocessor.findFileIncludes(file);
|
||||
if (fileIncludes && fileIncludes->includeFiles.contains(fileName)) {
|
||||
result.insert(file);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
const QString& phrase,
|
||||
int line);
|
||||
PStatement findScopeStatement(const QString& filename, int line);
|
||||
PFileIncludes findFileIncludes(const QString &filename, bool deleteIt = false);
|
||||
PParsedFileInfo findFileIncludes(const QString &filename, bool deleteIt = false);
|
||||
QString findFirstTemplateParamOf(const QString& fileName,
|
||||
const QString& phrase,
|
||||
const PStatement& currentScope);
|
||||
|
|
|
@ -224,7 +224,7 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const
|
|||
QFile file(fileName);
|
||||
if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) {
|
||||
QTextStream stream(&file);
|
||||
for (const PFileIncludes& fileIncludes:mIncludesList) {
|
||||
for (const PParsedFileInfo& fileIncludes:mIncludesList) {
|
||||
stream<<fileIncludes->baseFile<<" : "
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
||||
<<Qt::endl;
|
||||
|
@ -478,7 +478,7 @@ void CppPreprocessor::handleInclude(const QString &line, bool fromNext)
|
|||
if (fileName.isEmpty())
|
||||
return;
|
||||
|
||||
PFileIncludes oldCurrentIncludes = mCurrentIncludes;
|
||||
PParsedFileInfo oldCurrentIncludes = mCurrentIncludes;
|
||||
openInclude(fileName);
|
||||
}
|
||||
|
||||
|
@ -803,7 +803,7 @@ void CppPreprocessor::removeGCCAttribute(const QString &line, QString &newLine,
|
|||
|
||||
void CppPreprocessor::openInclude(QString fileName)
|
||||
{
|
||||
PFileIncludes fileIncludes = getFileIncludesEntry(fileName);
|
||||
PParsedFileInfo fileIncludes = getFileIncludesEntry(fileName);
|
||||
if (fileIncludes) {
|
||||
fileName = fileIncludes->baseFile;
|
||||
} else {
|
||||
|
@ -847,7 +847,7 @@ void CppPreprocessor::openInclude(QString fileName)
|
|||
mCurrentIncludes = getFileIncludesEntry(fileName);
|
||||
if (!mCurrentIncludes) {
|
||||
// do NOT create a new item for a file that's already in the list
|
||||
mCurrentIncludes = std::make_shared<FileIncludes>();
|
||||
mCurrentIncludes = std::make_shared<ParsedFileInfo>();
|
||||
mCurrentIncludes->baseFile = fileName;
|
||||
mIncludesList.insert(fileName,mCurrentIncludes);
|
||||
}
|
||||
|
@ -872,7 +872,7 @@ void CppPreprocessor::openInclude(QString fileName)
|
|||
} else {
|
||||
//add defines of already parsed including headers;
|
||||
addDefinesInFile(fileName);
|
||||
PFileIncludes fileIncludes = getFileIncludesEntry(fileName);
|
||||
PParsedFileInfo fileIncludes = getFileIncludesEntry(fileName);
|
||||
if (fileIncludes) {
|
||||
for (PParsedFile& file:mIncludes) {
|
||||
foreach (const QString& incFile,fileIncludes->includeFiles.keys()) {
|
||||
|
@ -959,7 +959,7 @@ void CppPreprocessor::addDefinesInFile(const QString &fileName)
|
|||
}
|
||||
}
|
||||
|
||||
PFileIncludes fileIncludes = getFileIncludesEntry(fileName);
|
||||
PParsedFileInfo fileIncludes = getFileIncludesEntry(fileName);
|
||||
if (fileIncludes) {
|
||||
foreach (const QString& file, fileIncludes->includeFiles.keys()) {
|
||||
addDefinesInFile(file);
|
||||
|
|
|
@ -41,7 +41,7 @@ struct ParsedFile {
|
|||
QString fileName; // Record filename, but not used now
|
||||
QStringList buffer; // do not concat them all
|
||||
int branches; //branch levels;
|
||||
PFileIncludes fileIncludes; // includes of this file
|
||||
PParsedFileInfo fileIncludes; // includes of this file
|
||||
};
|
||||
using PParsedFile = std::shared_ptr<ParsedFile>;
|
||||
|
||||
|
@ -91,7 +91,7 @@ public:
|
|||
return mResult;
|
||||
};
|
||||
|
||||
PFileIncludes findFileIncludes(const QString& fileName) const {
|
||||
PParsedFileInfo findFileIncludes(const QString& fileName) const {
|
||||
return mIncludesList.value(fileName);
|
||||
}
|
||||
|
||||
|
@ -183,8 +183,8 @@ private:
|
|||
}
|
||||
}
|
||||
// include stuff
|
||||
PFileIncludes getFileIncludesEntry(const QString& fileName){
|
||||
return mIncludesList.value(fileName,PFileIncludes());
|
||||
PParsedFileInfo getFileIncludesEntry(const QString& fileName){
|
||||
return mIncludesList.value(fileName,PParsedFileInfo());
|
||||
}
|
||||
void addDefinesInFile(const QString& fileName);
|
||||
void addDefineByParts(const QString& name, const QString& args,
|
||||
|
@ -262,7 +262,7 @@ private:
|
|||
QString mFileName;
|
||||
QStringList mBuffer;
|
||||
QStringList mResult;
|
||||
PFileIncludes mCurrentIncludes;
|
||||
PParsedFileInfo mCurrentIncludes;
|
||||
int mPreProcIndex;
|
||||
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
|
||||
|
@ -272,7 +272,7 @@ private:
|
|||
|
||||
//Result across processings.
|
||||
//used by parser even preprocess finished
|
||||
QHash<QString,PFileIncludes> mIncludesList;
|
||||
QHash<QString,PParsedFileInfo> mIncludesList;
|
||||
QHash<QString, PDefineMap> mFileDefines; //dictionary to save defines for each headerfile;
|
||||
QHash<QString, PDefineMap> mFileUndefines; //dictionary to save defines for each headerfile;
|
||||
QSet<QString> mScannedFiles;
|
||||
|
|
|
@ -767,7 +767,7 @@ bool isTypeKind(StatementKind kind)
|
|||
}
|
||||
}
|
||||
|
||||
bool FileIncludes::isLineVisible(int line)
|
||||
bool ParsedFileInfo::isLineVisible(int line)
|
||||
{
|
||||
int lastI=-1;
|
||||
foreach(int i,branches.keys()) {
|
||||
|
|
|
@ -317,7 +317,7 @@ struct ClassInheritanceInfo {
|
|||
|
||||
using PClassInheritanceInfo = std::shared_ptr<ClassInheritanceInfo>;
|
||||
|
||||
struct FileIncludes {
|
||||
struct ParsedFileInfo {
|
||||
QString baseFile;
|
||||
QMap<QString, bool> includeFiles; // true means the file is directly included, false means included indirectly
|
||||
QStringList directIncludes; //
|
||||
|
@ -329,7 +329,7 @@ struct FileIncludes {
|
|||
QList<std::weak_ptr<ClassInheritanceInfo>> handledInheritances;
|
||||
bool isLineVisible(int line);
|
||||
};
|
||||
using PFileIncludes = std::shared_ptr<FileIncludes>;
|
||||
using PParsedFileInfo = std::shared_ptr<ParsedFileInfo>;
|
||||
|
||||
extern QStringList CppDirectives;
|
||||
extern QStringList JavadocTags;
|
||||
|
|
|
@ -283,7 +283,7 @@ void ClassBrowserModel::addMembers()
|
|||
if (mCurrentFile.isEmpty())
|
||||
return;
|
||||
// show statements in the file
|
||||
PFileIncludes p = mParser->findFileIncludes(mCurrentFile);
|
||||
PParsedFileInfo p = mParser->findFileIncludes(mCurrentFile);
|
||||
if (!p)
|
||||
return;
|
||||
filterChildren(mRoot,p->statements);
|
||||
|
@ -291,7 +291,7 @@ void ClassBrowserModel::addMembers()
|
|||
if (mParser->projectFiles().isEmpty())
|
||||
return;
|
||||
foreach(const QString& file,mParser->projectFiles()) {
|
||||
PFileIncludes p = mParser->findFileIncludes(file);
|
||||
PParsedFileInfo p = mParser->findFileIncludes(file);
|
||||
if (!p)
|
||||
return;
|
||||
filterChildren(mRoot,p->statements);
|
||||
|
|
Loading…
Reference in New Issue