- fix: Can't correctly handle definitions for "operator,"

This commit is contained in:
Roy Qu 2023-02-05 20:36:10 +08:00
parent 6b1b9443c4
commit ca5916a4b1
2 changed files with 21 additions and 9 deletions

View File

@ -1,3 +1,7 @@
Red Panda C++ Version 2.11
- fix: Can't correctly handle definitions for "operator,"
Red Panda C++ Version 2.10 Red Panda C++ Version 2.10
- fix: When restored from minimization, info on statusbar not correctly restored. - fix: When restored from minimization, info on statusbar not correctly restored.

View File

@ -1454,7 +1454,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()==2)
// qDebug()<<"++add scope"<<mCurrentFile<<line<<mCurrentClassScope.count(); // qDebug()<<"++add scope"<<mCurrentFile<<line<<mCurrentClassScope.count();
#endif #endif
} }
@ -1465,7 +1465,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()==2)
// qDebug()<<"--remove scope"<<mCurrentFile<<line<<mCurrentClassScope.count(); // qDebug()<<"--remove scope"<<mCurrentFile<<line<<mCurrentClassScope.count();
#endif #endif
PStatement currentScope = getCurrentScope(); PStatement currentScope = getCurrentScope();
@ -1920,8 +1920,6 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
QString sType = currentText; // should contain type "int" QString sType = currentText; // should contain type "int"
QString sName = ""; // should contain function name "foo::function" QString sName = ""; // should contain function name "foo::function"
// Gather data for the string parts // Gather data for the string parts
while (mIndex+1 < mTokenizer.tokenCount()) { while (mIndex+1 < mTokenizer.tokenCount()) {
if (mTokenizer[mIndex + 1]->text == '(') { if (mTokenizer[mIndex + 1]->text == '(') {
@ -1939,7 +1937,8 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
} }
//if it's like: foo(...)(...) //if it's like: foo(...)(...)
if (mTokenizer[indexAfter]->text=='(') { if (mTokenizer[indexAfter]->text=='(') {
if (mTokenizer[mIndex]->text=="operator") { if (mTokenizer[mIndex]->text=="operator"
|| mTokenizer[mIndex]->text.endsWith("::operator")) {
//operator()() , it's an operator overload for () //operator()() , it's an operator overload for ()
handleMethod(StatementKind::skFunction,sType, handleMethod(StatementKind::skFunction,sType,
"operator()",indexAfter,isStatic,false); "operator()",indexAfter,isStatic,false);
@ -1985,7 +1984,7 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
return; return;
} }
} }
sName = mTokenizer[mIndex]->text; sName = sName+mTokenizer[mIndex]->text;
mIndex++; mIndex++;
handleMethod(StatementKind::skFunction,sType, handleMethod(StatementKind::skFunction,sType,
@ -1998,8 +1997,15 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
||mTokenizer[mIndex + 1]->text == ':' ||mTokenizer[mIndex + 1]->text == ':'
||mTokenizer[mIndex + 1]->text == '{' ||mTokenizer[mIndex + 1]->text == '{'
|| mTokenizer[mIndex + 1]->text == '=') { || mTokenizer[mIndex + 1]->text == '=') {
handleVar(sType,isExtern,isStatic); QString s = mTokenizer[mIndex]->text;
return; if (s == "operator"
|| s.endsWith("::operator")) {
sName = s;
mIndex++;
} else {
handleVar(sType,isExtern,isStatic);
return;
}
} else { } else {
QString s = mTokenizer[mIndex]->text; QString s = mTokenizer[mIndex]->text;
if (s == "static") if (s == "static")
@ -3101,7 +3107,9 @@ bool CppParser::handleStatement()
// } else if (checkForLambda()) { // is lambda // } else if (checkForLambda()) { // is lambda
// handleLambda(); // handleLambda();
} else if (mTokenizer[mIndex]->text=='(') { } else if (mTokenizer[mIndex]->text=='(') {
if (mIndex+1<mTokenizer.tokenCount() && mTokenizer[mIndex+1]->text=="operator") { if (mIndex+1<mTokenizer.tokenCount() &&
(mTokenizer[mIndex+1]->text=="operator"
|| mTokenizer[mIndex+1]->text.endsWith("::operator"))) {
// things like (operator int) // things like (operator int)
mIndex++; //just skip '(' mIndex++; //just skip '('
} else } else