- refactor: for/catch processing
- fix: Link in the project options dialog / precompiled header pages is not clickable.
This commit is contained in:
parent
30cabe2faa
commit
c3352ad661
1
NEWS.md
1
NEWS.md
|
@ -9,6 +9,7 @@ Red Panda C++ Version 2.26
|
|||
- fix: Code suggestions in namespace.
|
||||
- enhancement: Code suggestions for namespace alias.
|
||||
- fix: Correctly handle statements like 'using xxx::operator()'.
|
||||
- fix: Link in the project options dialog / precompiled header pages is not clickable.
|
||||
|
||||
Red Panda C++ Version 2.25
|
||||
|
||||
|
|
|
@ -1091,8 +1091,8 @@ void CppParser::resetParser()
|
|||
mStatementList.clear();
|
||||
|
||||
mProjectFiles.clear();
|
||||
mBlockBeginSkips.clear(); //list of for/catch block begin token index;
|
||||
mBlockEndSkips.clear(); //list of for/catch block end token index;
|
||||
// mBlockBeginSkips.clear(); //list of for/catch block begin token index;
|
||||
// mBlockEndSkips.clear(); //list of for/catch block end token index;
|
||||
mInlineNamespaceEndSkips.clear(); // list for inline namespace end token index;
|
||||
mFilesToScan.clear(); // list of base files to scan
|
||||
mNamespaces.clear(); // namespace and the statements in its scope
|
||||
|
@ -1717,8 +1717,8 @@ void CppParser::internalClear()
|
|||
mMemberAccessibilities.clear();
|
||||
mIndex = 0;
|
||||
mCurrentMemberAccessibility = StatementAccessibility::None;
|
||||
mBlockBeginSkips.clear();
|
||||
mBlockEndSkips.clear();
|
||||
// mBlockBeginSkips.clear();
|
||||
// mBlockEndSkips.clear();
|
||||
mInlineNamespaceEndSkips.clear();
|
||||
}
|
||||
|
||||
|
@ -2406,19 +2406,19 @@ QString CppParser::doFindTemplateParamOf(const QString &fileName, const QString
|
|||
return getTemplateParam(statement,fileName, phrase,index, currentScope);
|
||||
}
|
||||
|
||||
int CppParser::getCurrentBlockEndSkip() const
|
||||
{
|
||||
if (mBlockEndSkips.isEmpty())
|
||||
return mTokenizer.tokenCount()+1;
|
||||
return mBlockEndSkips.back();
|
||||
}
|
||||
//int CppParser::getCurrentBlockEndSkip() const
|
||||
//{
|
||||
// if (mBlockEndSkips.isEmpty())
|
||||
// return mTokenizer.tokenCount()+1;
|
||||
// return mBlockEndSkips.back();
|
||||
//}
|
||||
|
||||
int CppParser::getCurrentBlockBeginSkip() const
|
||||
{
|
||||
if (mBlockBeginSkips.isEmpty())
|
||||
return mTokenizer.tokenCount()+1;
|
||||
return mBlockBeginSkips.back();
|
||||
}
|
||||
//int CppParser::getCurrentBlockBeginSkip() const
|
||||
//{
|
||||
// if (mBlockBeginSkips.isEmpty())
|
||||
// return mTokenizer.tokenCount()+1;
|
||||
// return mBlockBeginSkips.back();
|
||||
//}
|
||||
|
||||
int CppParser::getCurrentInlineNamespaceEndSkip() const
|
||||
{
|
||||
|
@ -2541,43 +2541,43 @@ PStatement CppParser::getTypeDef(const PStatement& statement,
|
|||
return PStatement();
|
||||
}
|
||||
|
||||
void CppParser::handleCatchBlock()
|
||||
{
|
||||
int tokenCount = mTokenizer.tokenCount();
|
||||
int startLine= mTokenizer[mIndex]->line;
|
||||
mIndex++; // skip for/catch;
|
||||
if (!((mIndex < tokenCount) && (mTokenizer[mIndex]->text.startsWith('('))))
|
||||
return;
|
||||
//skip params
|
||||
int i2=mTokenizer[mIndex]->matchIndex+1;
|
||||
if (i2>=tokenCount)
|
||||
return;
|
||||
if (mTokenizer[i2]->text.startsWith('{')) {
|
||||
mBlockBeginSkips.append(i2);
|
||||
int i = indexOfMatchingBrace(i2);
|
||||
mBlockEndSkips.append(i);
|
||||
} else {
|
||||
int i=indexOfNextSemicolon(i2);
|
||||
mBlockEndSkips.append(i);
|
||||
}
|
||||
// add a block
|
||||
PStatement block = addStatement(
|
||||
getCurrentScope(),
|
||||
mCurrentFile,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
startLine,
|
||||
StatementKind::skBlock,
|
||||
getScope(),
|
||||
mCurrentMemberAccessibility,
|
||||
StatementProperty::spHasDefinition);
|
||||
addSoloScopeLevel(block,startLine);
|
||||
scanMethodArgs(block,mIndex);
|
||||
mIndex=mTokenizer[mIndex]->matchIndex+1;
|
||||
}
|
||||
//void CppParser::handleCatchBlock()
|
||||
//{
|
||||
// int tokenCount = mTokenizer.tokenCount();
|
||||
// int startLine= mTokenizer[mIndex]->line;
|
||||
// mIndex++; // skip for/catch;
|
||||
// if (!((mIndex < tokenCount) && (mTokenizer[mIndex]->text.startsWith('('))))
|
||||
// return;
|
||||
// //skip params
|
||||
// int i2=mTokenizer[mIndex]->matchIndex+1;
|
||||
// if (i2>=tokenCount)
|
||||
// return;
|
||||
// if (mTokenizer[i2]->text.startsWith('{')) {
|
||||
// mBlockBeginSkips.append(i2);
|
||||
// int i = indexOfMatchingBrace(i2);
|
||||
// mBlockEndSkips.append(i);
|
||||
// } else {
|
||||
// int i=indexOfNextSemicolon(i2);
|
||||
// mBlockEndSkips.append(i);
|
||||
// }
|
||||
// // add a block
|
||||
// PStatement block = addStatement(
|
||||
// getCurrentScope(),
|
||||
// mCurrentFile,
|
||||
// "",
|
||||
// "",
|
||||
// "",
|
||||
// "",
|
||||
// "",
|
||||
// startLine,
|
||||
// StatementKind::skBlock,
|
||||
// getScope(),
|
||||
// mCurrentMemberAccessibility,
|
||||
// StatementProperty::spHasDefinition);
|
||||
// addSoloScopeLevel(block,startLine);
|
||||
// scanMethodArgs(block,mIndex);
|
||||
// mIndex=mTokenizer[mIndex]->matchIndex+1;
|
||||
//}
|
||||
|
||||
void CppParser::handleConcept()
|
||||
{
|
||||
|
@ -2807,45 +2807,23 @@ void CppParser::handleForBlock()
|
|||
mIndex++; // skip for/catch;
|
||||
if (mIndex >= tokenCount)
|
||||
return;
|
||||
if (mTokenizer[mIndex]->text!="(")
|
||||
if (mTokenizer[mIndex]->text!='(')
|
||||
return;
|
||||
int i=indexOfNextSemicolon(mIndex);
|
||||
int i2 = i+1; //skip over ';' (tokenizer have change for(;;) to for(;)
|
||||
|
||||
// for(int x:vec)
|
||||
if (i2 > mTokenizer[mIndex]->matchIndex)
|
||||
i2 = mTokenizer[mIndex]->matchIndex+1;
|
||||
|
||||
int i=mTokenizer[mIndex]->matchIndex; //")"
|
||||
int i2 = i+1;
|
||||
if (i2>=tokenCount)
|
||||
return;
|
||||
if (mTokenizer[i2]->text.startsWith('{')) {
|
||||
mBlockBeginSkips.append(i2);
|
||||
i=indexOfMatchingBrace(i2);
|
||||
// tokenizer will handle unbalanced braces, no need check here
|
||||
// if (i==i2)
|
||||
// mBlockEndSkips.append(mTokenizer.tokenCount());
|
||||
// else
|
||||
mBlockEndSkips.append(i);
|
||||
if (mTokenizer[i2]->text=='{') {
|
||||
mTokenizer[mIndex]->text="{";
|
||||
mTokenizer[mIndex]->matchIndex = mTokenizer[i2]->matchIndex;
|
||||
mTokenizer[mTokenizer[mIndex]->matchIndex]->matchIndex = mIndex;
|
||||
mTokenizer[i]->text=";";
|
||||
mTokenizer[i2]->text=";";
|
||||
} else {
|
||||
i=indexOfNextSemicolon(i2);
|
||||
mBlockEndSkips.append(i);
|
||||
mTokenizer[mIndex]->text=";";
|
||||
mTokenizer[i]->text=";";
|
||||
mIndex++; //skip ';'
|
||||
}
|
||||
// add a block
|
||||
PStatement block = addStatement(
|
||||
getCurrentScope(),
|
||||
mCurrentFile,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
startLine,
|
||||
StatementKind::skBlock,
|
||||
getScope(),
|
||||
mCurrentMemberAccessibility,
|
||||
StatementProperty::spHasDefinition);
|
||||
|
||||
addSoloScopeLevel(block,startLine);
|
||||
}
|
||||
|
||||
void CppParser::handleKeyword(KeywordType skipType)
|
||||
|
@ -3535,8 +3513,8 @@ void CppParser::handleAccessibilitySpecifiers(KeywordType keywordType)
|
|||
bool CppParser::handleStatement()
|
||||
{
|
||||
QString funcType,funcName;
|
||||
int idx=getCurrentBlockEndSkip();
|
||||
int idx2=getCurrentBlockBeginSkip();
|
||||
// int idx=getCurrentBlockEndSkip();
|
||||
// int idx2=getCurrentBlockBeginSkip();
|
||||
int idx3=getCurrentInlineNamespaceEndSkip();
|
||||
KeywordType keywordType;
|
||||
#ifdef QT_DEBUG
|
||||
|
@ -3546,21 +3524,22 @@ bool CppParser::handleStatement()
|
|||
#endif
|
||||
int tokenCount = mTokenizer.tokenCount();
|
||||
|
||||
if (mIndex >= idx2) {
|
||||
//skip (previous handled) block begin
|
||||
mBlockBeginSkips.pop_back();
|
||||
if (mIndex == idx2)
|
||||
mIndex++;
|
||||
else if (mIndex<tokenCount) //error happens, but we must remove an (error) added scope
|
||||
removeScopeLevel(mTokenizer[mIndex]->line);
|
||||
} else if (mIndex >= idx) {
|
||||
//skip (previous handled) block end
|
||||
mBlockEndSkips.pop_back();
|
||||
if (idx+1 < tokenCount)
|
||||
removeScopeLevel(mTokenizer[idx+1]->line);
|
||||
if (mIndex == idx)
|
||||
mIndex++;
|
||||
} else if (mIndex >= idx3) {
|
||||
// if (mIndex >= idx2) {
|
||||
// //skip (previous handled) block begin
|
||||
// mBlockBeginSkips.pop_back();
|
||||
// if (mIndex == idx2)
|
||||
// mIndex++;
|
||||
// else if (mIndex<tokenCount) //error happens, but we must remove an (error) added scope
|
||||
// removeScopeLevel(mTokenizer[mIndex]->line);
|
||||
// } else if (mIndex >= idx) {
|
||||
// //skip (previous handled) block end
|
||||
// mBlockEndSkips.pop_back();
|
||||
// if (idx+1 < tokenCount)
|
||||
// removeScopeLevel(mTokenizer[idx+1]->line);
|
||||
// if (mIndex == idx)
|
||||
// mIndex++;
|
||||
// } else
|
||||
if (mIndex >= idx3) {
|
||||
//skip (previous handled) inline name space end
|
||||
mInlineNamespaceEndSkips.pop_back();
|
||||
if (mIndex == idx3)
|
||||
|
@ -3619,10 +3598,8 @@ bool CppParser::handleStatement()
|
|||
handleConcept();
|
||||
} else if (keywordType==KeywordType::Requires) {
|
||||
skipRequires();
|
||||
} else if (keywordType==KeywordType::For) { // (for/catch)
|
||||
} else if (keywordType==KeywordType::For || keywordType==KeywordType::Catch) { // (for/catch)
|
||||
handleForBlock();
|
||||
} else if (keywordType==KeywordType::Catch) { // (for/catch)
|
||||
handleCatchBlock();
|
||||
} else if (checkForAccessibilitySpecifiers(keywordType)) { // public /private/proteced
|
||||
handleAccessibilitySpecifiers(keywordType);
|
||||
} else if (keywordType==KeywordType::Enum) {
|
||||
|
@ -4388,17 +4365,17 @@ void CppParser::skipRequires()
|
|||
mIndex++; // skip '::';
|
||||
}
|
||||
}
|
||||
if (mIndex>=tokenCount)
|
||||
if (mIndex+1>=tokenCount)
|
||||
return;
|
||||
if (mTokenizer[mIndex]->text!="&&")
|
||||
if (mTokenizer[mIndex]->text!="&" || mTokenizer[mIndex+1]->text!="&")
|
||||
break;
|
||||
mIndex++; // skip '&&';
|
||||
mIndex+=2; // skip '&&';
|
||||
}
|
||||
if (mIndex>=tokenCount)
|
||||
if (mIndex+1>=tokenCount)
|
||||
return;
|
||||
if (mTokenizer[mIndex]->text!="||")
|
||||
if (mTokenizer[mIndex]->text!="|" || mTokenizer[mIndex+1]->text!="|")
|
||||
break;
|
||||
mIndex++; // skip '||';
|
||||
mIndex+=2; // skip '||';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4422,9 +4399,9 @@ void CppParser::internalParse(const QString &fileName)
|
|||
|
||||
QStringList preprocessResult = mPreprocessor.result();
|
||||
#ifdef QT_DEBUG
|
||||
// stringsToFile(mPreprocessor.result(),QString("r:\\preprocess-%1.txt").arg(extractFileName(fileName)));
|
||||
// mPreprocessor.dumpDefinesTo("r:\\defines.txt");
|
||||
// mPreprocessor.dumpIncludesListTo("r:\\includes.txt");
|
||||
stringsToFile(mPreprocessor.result(),QString("r:\\preprocess-%1.txt").arg(extractFileName(fileName)));
|
||||
mPreprocessor.dumpDefinesTo("r:\\defines.txt");
|
||||
mPreprocessor.dumpIncludesListTo("r:\\includes.txt");
|
||||
#endif
|
||||
//qDebug()<<"preprocess"<<timer.elapsed();
|
||||
//reduce memory usage
|
||||
|
@ -4441,7 +4418,7 @@ void CppParser::internalParse(const QString &fileName)
|
|||
if (mTokenizer.tokenCount() == 0)
|
||||
return;
|
||||
#ifdef QT_DEBUG
|
||||
// mTokenizer.dumpTokens(QString("r:\\tokens-%1.txt").arg(extractFileName(fileName)));
|
||||
mTokenizer.dumpTokens(QString("r:\\tokens-%1.txt").arg(extractFileName(fileName)));
|
||||
#endif
|
||||
#ifdef QT_DEBUG
|
||||
mLastIndex = -1;
|
||||
|
@ -4454,8 +4431,8 @@ void CppParser::internalParse(const QString &fileName)
|
|||
}
|
||||
// qDebug()<<"parse"<<timer.elapsed();
|
||||
#ifdef QT_DEBUG
|
||||
// mStatementList.dumpAll(QString("r:\\all-stats-%1.txt").arg(extractFileName(fileName)));
|
||||
// mStatementList.dump(QString("r:\\stats-%1.txt").arg(extractFileName(fileName)));
|
||||
mStatementList.dumpAll(QString("r:\\all-stats-%1.txt").arg(extractFileName(fileName)));
|
||||
mStatementList.dump(QString("r:\\stats-%1.txt").arg(extractFileName(fileName)));
|
||||
#endif
|
||||
//reduce memory usage
|
||||
internalClear();
|
||||
|
|
|
@ -462,8 +462,8 @@ private:
|
|||
int getBracketEnd(const QString& s, int startAt) const;
|
||||
StatementAccessibility getClassMemberAccessibility(const QString& text) const;
|
||||
StatementAccessibility getClassMemberAccessibility(KeywordType keywordType) const;
|
||||
int getCurrentBlockBeginSkip() const;
|
||||
int getCurrentBlockEndSkip() const;
|
||||
// int getCurrentBlockBeginSkip() const;
|
||||
// int getCurrentBlockEndSkip() const;
|
||||
int getCurrentInlineNamespaceEndSkip() const;
|
||||
PStatement getCurrentScope() const; // gets last item from last level
|
||||
QString getTemplateParam(const PStatement& statement, const QString& filename,
|
||||
|
@ -488,7 +488,7 @@ private:
|
|||
const QString& sNoNameArgs) const;
|
||||
PStatement getTypeDef(const PStatement& statement,
|
||||
const QString& fileName, const QString& aType) const;
|
||||
void handleCatchBlock();
|
||||
// void handleCatchBlock();
|
||||
void handleConcept();
|
||||
void handleEnum(bool isTypedef);
|
||||
void handleForBlock();
|
||||
|
@ -705,8 +705,8 @@ private:
|
|||
CppTokenizer mTokenizer;
|
||||
CppPreprocessor mPreprocessor;
|
||||
QSet<QString> mProjectFiles;
|
||||
QVector<int> mBlockBeginSkips; //list of for/catch block begin token index;
|
||||
QVector<int> mBlockEndSkips; //list of for/catch block end token index;
|
||||
// QVector<int> mBlockBeginSkips; //list of for/catch block begin token index;
|
||||
// QVector<int> mBlockEndSkips; //list of for/catch block end token index;
|
||||
QVector<int> mInlineNamespaceEndSkips; // list for inline namespace end token index;
|
||||
QSet<QString> mFilesToScan; // list of base files to scan
|
||||
int mFilesScannedCount; // count of files that have been scanned
|
||||
|
|
|
@ -158,30 +158,30 @@ void CppTokenizer::countLines()
|
|||
}
|
||||
}
|
||||
|
||||
QString CppTokenizer::getForInit()
|
||||
{
|
||||
QChar* startOffset = mCurrent;
|
||||
//QString CppTokenizer::getForInit()
|
||||
//{
|
||||
// QChar* startOffset = mCurrent;
|
||||
|
||||
// Step into the init statement
|
||||
mCurrent++;
|
||||
// // Step into the init statement
|
||||
// mCurrent++;
|
||||
|
||||
TokenType tokenType;
|
||||
// Process until ; or end of file
|
||||
while (true) {
|
||||
QString s = getNextToken(&tokenType);
|
||||
simplify(s);
|
||||
if (!s.isEmpty())
|
||||
addToken(s,mCurrentLine,tokenType);
|
||||
if ( (s == "") || (s == ";") || (s==")") || (s=="("))
|
||||
break;
|
||||
// : is used in for-each loop
|
||||
}
|
||||
// TokenType tokenType;
|
||||
// // Process until ; or end of file
|
||||
// while (true) {
|
||||
// QString s = getNextToken(&tokenType);
|
||||
// simplify(s);
|
||||
// if (!s.isEmpty())
|
||||
// addToken(s,mCurrentLine,tokenType);
|
||||
// if ( (s == "") || (s == ";") || (s==")") || (s=="("))
|
||||
// break;
|
||||
// // : is used in for-each loop
|
||||
// }
|
||||
|
||||
// Skip to end of for loop
|
||||
mCurrent = startOffset;
|
||||
skipPair('(', ')');
|
||||
return "";
|
||||
}
|
||||
// // Skip to end of for loop
|
||||
// mCurrent = startOffset;
|
||||
// skipPair('(', ')');
|
||||
// return "";
|
||||
//}
|
||||
|
||||
QString CppTokenizer::getNextToken(TokenType *pTokenType)
|
||||
{
|
||||
|
@ -203,10 +203,10 @@ QString CppTokenizer::getNextToken(TokenType *pTokenType)
|
|||
}
|
||||
}
|
||||
done = (result != "");
|
||||
} else if (isForInit()) {
|
||||
countLines();
|
||||
result = getForInit();
|
||||
done = (result != "");
|
||||
// } else if (isForInit()) {
|
||||
// countLines();
|
||||
// result = getForInit();
|
||||
// done = (result != "");
|
||||
// } else if (isArguments()) {
|
||||
// countLines();
|
||||
// result = getArguments();
|
||||
|
@ -526,10 +526,10 @@ bool CppTokenizer::isArguments()
|
|||
return *mCurrent == '(';
|
||||
}
|
||||
|
||||
bool CppTokenizer::isForInit()
|
||||
{
|
||||
return (*mCurrent == '(') && (mLastToken == "for");
|
||||
}
|
||||
//bool CppTokenizer::isForInit()
|
||||
//{
|
||||
// return (*mCurrent == '(') && (mLastToken == "for");
|
||||
//}
|
||||
|
||||
bool CppTokenizer::isNumber()
|
||||
{
|
||||
|
|
|
@ -75,14 +75,14 @@ private:
|
|||
void countLines();
|
||||
PToken getToken(int index);
|
||||
|
||||
QString getForInit();
|
||||
// QString getForInit();
|
||||
QString getNextToken(
|
||||
TokenType *pTokenType);
|
||||
QString getNumber();
|
||||
QString getPreprocessor();
|
||||
QString getWord();
|
||||
bool isArguments();
|
||||
bool isForInit();
|
||||
// bool isForInit();
|
||||
bool isNumber();
|
||||
bool isPreprocessor();
|
||||
bool isWord();
|
||||
|
|
|
@ -78,6 +78,9 @@
|
|||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
Loading…
Reference in New Issue