- fix: Parser: invalidating file may lost class inheritance infos.
This commit is contained in:
parent
1728e953bf
commit
2743e6f682
|
@ -1613,6 +1613,8 @@ void CppParser::setInheritance(int index, const PStatement& classStatement, bool
|
|||
inheritanceInfo->handled = false;
|
||||
|
||||
mClassInheritances.append(inheritanceInfo);
|
||||
|
||||
handleInheritance(classStatement, inheritanceInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4373,6 +4375,29 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
|
|||
mIndex++;
|
||||
}
|
||||
|
||||
void CppParser::handleInheritance(PStatement derivedStatement, PClassInheritanceInfo inheritanceInfo)
|
||||
{
|
||||
if (inheritanceInfo->handled)
|
||||
return;
|
||||
PStatement statement = doFindStatementOf(
|
||||
inheritanceInfo->file,
|
||||
inheritanceInfo->parentClassName,
|
||||
inheritanceInfo->isGlobal?PStatement():derivedStatement->parentScope.lock());
|
||||
|
||||
if (statement && statement->kind == StatementKind::skClass) {
|
||||
inheritClassStatement(derivedStatement,
|
||||
inheritanceInfo->isStruct,
|
||||
statement,
|
||||
inheritanceInfo->visibility);
|
||||
// inheritanceInfo->parentClassFilename = statement->fileName;
|
||||
inheritanceInfo->handled = true;
|
||||
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(statement->fileName);
|
||||
Q_ASSERT(fileIncludes!=nullptr);
|
||||
fileIncludes->handledInheritances.append(inheritanceInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CppParser::handleInheritances()
|
||||
{
|
||||
for (int i=mClassInheritances.length()-1;i>=0;i--) {
|
||||
|
@ -4387,21 +4412,7 @@ void CppParser::handleInheritances()
|
|||
}
|
||||
continue;
|
||||
}
|
||||
if (inheritanceInfo->handled)
|
||||
continue;
|
||||
PStatement statement = doFindStatementOf(
|
||||
inheritanceInfo->file,
|
||||
inheritanceInfo->parentClassName,
|
||||
inheritanceInfo->isGlobal?PStatement():derivedStatement->parentScope.lock());
|
||||
|
||||
if (statement && statement->kind == StatementKind::skClass) {
|
||||
inheritClassStatement(derivedStatement,
|
||||
inheritanceInfo->isStruct,
|
||||
statement,
|
||||
inheritanceInfo->visibility);
|
||||
inheritanceInfo->parentClassFilename = statement->fileName;
|
||||
inheritanceInfo->handled = true;
|
||||
}
|
||||
handleInheritance(derivedStatement, inheritanceInfo);
|
||||
}
|
||||
//mClassInheritances.clear();
|
||||
}
|
||||
|
@ -5982,6 +5993,15 @@ void CppParser::internalInvalidateFile(const QString &fileName)
|
|||
}
|
||||
}
|
||||
p->statements.clear();
|
||||
|
||||
//invalidate all handledInheritances
|
||||
for (std::weak_ptr<ClassInheritanceInfo> &pWeakInfo: p->handledInheritances) {
|
||||
PClassInheritanceInfo info = pWeakInfo.lock();
|
||||
if (info) {
|
||||
info->handled = false;
|
||||
}
|
||||
}
|
||||
p->handledInheritances.clear();
|
||||
}
|
||||
|
||||
//remove all statements from namespace cache
|
||||
|
@ -6000,10 +6020,10 @@ void CppParser::internalInvalidateFile(const QString &fileName)
|
|||
}
|
||||
// class inheritance
|
||||
// invalid class inheritance infos (derived class is not valid) whould be auto removed in handleInheritances()
|
||||
foreach (const PClassInheritanceInfo& info, mClassInheritances) {
|
||||
if (info->handled && info->parentClassFilename == fileName)
|
||||
info->handled = false;
|
||||
}
|
||||
// foreach (const PClassInheritanceInfo& info, mClassInheritances) {
|
||||
// if (info->handled && info->parentClassFilename == fileName)
|
||||
// info->handled = false;
|
||||
// }
|
||||
// delete it from scannedfiles
|
||||
mPreprocessor.removeScannedFile(fileName);
|
||||
}
|
||||
|
|
|
@ -516,6 +516,7 @@ private:
|
|||
void handleStructs(bool isTypedef = false);
|
||||
void handleUsing();
|
||||
void handleVar(const QString& typePrefix,bool isExtern,bool isStatic);
|
||||
void handleInheritance(PStatement derivedClass, PClassInheritanceInfo pInfo);
|
||||
void handleInheritances();
|
||||
void skipRequires();
|
||||
void internalParse(const QString& fileName);
|
||||
|
|
|
@ -295,6 +295,7 @@ private:
|
|||
QVector<PCppScope> mScopes;
|
||||
};
|
||||
|
||||
struct ClassInheritanceInfo;
|
||||
struct FileIncludes {
|
||||
QString baseFile;
|
||||
QMap<QString, bool> includeFiles; // true means the file is directly included, false means included indirectly
|
||||
|
@ -304,6 +305,7 @@ struct FileIncludes {
|
|||
StatementMap declaredStatements; // statements declared in this file (full name as key)
|
||||
CppScopes scopes; // int is start line of the statement scope
|
||||
QMap<int,bool> branches;
|
||||
QList<std::weak_ptr<ClassInheritanceInfo>> handledInheritances;
|
||||
bool isLineVisible(int line);
|
||||
};
|
||||
using PFileIncludes = std::shared_ptr<FileIncludes>;
|
||||
|
|
|
@ -60,7 +60,7 @@ struct ClassInheritanceInfo {
|
|||
bool isGlobal;
|
||||
bool isStruct;
|
||||
StatementAccessibility visibility;
|
||||
QString parentClassFilename;
|
||||
// QString parentClassFilename;
|
||||
bool handled;
|
||||
};
|
||||
|
||||
|
|
|
@ -22,29 +22,6 @@
|
|||
|
||||
namespace QSynedit {
|
||||
|
||||
QSet<QString> QSynEditPainter::OperatorGlyphs {
|
||||
"-",
|
||||
"+",
|
||||
"*",
|
||||
"/",
|
||||
"\\",
|
||||
"~",
|
||||
"!",
|
||||
"@",
|
||||
"#",
|
||||
"$",
|
||||
"%",
|
||||
"^",
|
||||
"&",
|
||||
"|",
|
||||
"=",
|
||||
"<",
|
||||
">",
|
||||
"?",
|
||||
":",
|
||||
};
|
||||
|
||||
|
||||
QSynEditPainter::QSynEditPainter(QSynEdit *edit, QPainter *painter, int firstRow, int lastRow, int left, int right):
|
||||
mEdit{edit},
|
||||
mPainter{painter},
|
||||
|
|
|
@ -109,8 +109,6 @@ private:
|
|||
QRect mClip;
|
||||
int mFirstRow, mLastRow, mLeft, mRight;
|
||||
SynTokenAccu mTokenAccu;
|
||||
|
||||
static QSet<QString> OperatorGlyphs;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue