- enhancement: improve parse result for STL <random>

This commit is contained in:
Roy Qu 2022-11-12 12:14:19 +08:00
parent edfd09191c
commit 6a6dc126a4
4 changed files with 29 additions and 7 deletions

View File

@ -25,10 +25,11 @@ Red Panda C++ Version 2.4
- fix: &operator= functions are not correctly parsed; - fix: &operator= functions are not correctly parsed;
- fix: Code Formatter's "add indent to continueous lines" option is not correctly saved. - fix: Code Formatter's "add indent to continueous lines" option is not correctly saved.
- fix: _Pragma is not correctly handled; - fix: _Pragma is not correctly handled;
- enhancement: improve parse result for STL <random>
- change: the default value for UI font size : 11 - change: the default value for UI font size : 11
- change: the default value for add leading zeros to line numbers : false - change: the default value for add leading zeros to line numbers : false
- upgrade integrated libturtle. fix: nothing is drawed when set background color to BLACK
- upgrade integrate fmtlib. fix: imcompatible with GBK encoding
Red Panda C++ Version 2.3 Red Panda C++ Version 2.3

View File

@ -1457,7 +1457,7 @@ void CppParser::addSoloScopeLevel(PStatement& statement, int line, bool shouldRe
mClassScope = StatementClassScope::Public; // structs are public by default mClassScope = StatementClassScope::Public; // structs are public by default
mCurrentClassScope.append(mClassScope); mCurrentClassScope.append(mClassScope);
#ifdef QT_DEBUG #ifdef QT_DEBUG
//if (mCurrentClassScope.count()==1) // if (mCurrentClassScope.count()==1)
// qDebug()<<"++add scope"<<mCurrentFile<<line<<mCurrentClassScope.count(); // qDebug()<<"++add scope"<<mCurrentFile<<line<<mCurrentClassScope.count();
#endif #endif
} }
@ -1468,7 +1468,7 @@ void CppParser::removeScopeLevel(int line)
if (mCurrentScope.isEmpty()) if (mCurrentScope.isEmpty())
return; // TODO: should be an exception return; // TODO: should be an exception
#ifdef QT_DEBUG #ifdef QT_DEBUG
//if (mCurrentClassScope.count()==1) // if (mCurrentClassScope.count()==1)
// qDebug()<<"--remove scope"<<mCurrentFile<<line<<mCurrentClassScope.count(); // qDebug()<<"--remove scope"<<mCurrentFile<<line<<mCurrentClassScope.count();
#endif #endif
PStatement currentScope = getCurrentScope(); PStatement currentScope = getCurrentScope();
@ -3618,7 +3618,7 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
break; break;
} else if (isWordChar(mTokenizer[mIndex]->text[0])) { } else if (isWordChar(mTokenizer[mIndex]->text[0])) {
QString cmd=mTokenizer[mIndex]->text; QString cmd=mTokenizer[mIndex]->text;
if (mTokenizer[mIndex+1]->text=='(' if (mIndex+1< mTokenizer.tokenCount() && mTokenizer[mIndex+1]->text=='('
&& mTokenizer[mIndex+1]->matchIndex+1<mTokenizer.tokenCount() && mTokenizer[mIndex+1]->matchIndex+1<mTokenizer.tokenCount()
&& mTokenizer[mTokenizer[mIndex+1]->matchIndex+1]->text=='(') { && mTokenizer[mTokenizer[mIndex+1]->matchIndex+1]->text=='(') {
//function pointer //function pointer

View File

@ -201,7 +201,6 @@ QString CppTokenizer::getForInit()
QString CppTokenizer::getNextToken(TokenType *pTokenType, bool bSkipArray, bool bSkipBlock) QString CppTokenizer::getNextToken(TokenType *pTokenType, bool bSkipArray, bool bSkipBlock)
{ {
QString result; QString result;
int backupIndex;
bool done = false; bool done = false;
*pTokenType=TokenType::Normal; *pTokenType=TokenType::Normal;
while (true) { while (true) {
@ -759,7 +758,28 @@ void CppTokenizer::skipTemplateArgs()
if (*mCurrent != '<') if (*mCurrent != '<')
return; return;
skipPair('<', '>'); if (skipAngleBracketPair())
return;
QChar* lastBracketPos = mCurrent;
bool shouldExit=false;
while (true) {
switch(mCurrent->unicode()) {
case '\0':
case ';':
case '}':
case '{':
shouldExit=true;
break;
case '>':
lastBracketPos = mCurrent;
break;
}
if (shouldExit)
break;
mCurrent++;
}
if (*lastBracketPos=='>')
mCurrent = lastBracketPos+1; //skip '>';
} }
void CppTokenizer::skipToEOL() void CppTokenizer::skipToEOL()

View File

@ -82,6 +82,7 @@ private:
void skipAssignment(); void skipAssignment();
void skipDoubleQuotes(); void skipDoubleQuotes();
void skipPair(const QChar& cStart, const QChar cEnd); void skipPair(const QChar& cStart, const QChar cEnd);
void skipParenthesis();
bool skipAngleBracketPair(); bool skipAngleBracketPair();
void skipRawString(); void skipRawString();
void skipSingleQuote(); void skipSingleQuote();