diff --git a/NEWS.md b/NEWS.md index 0da98cef..56f1db44 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ Red Panda C++ Version 2.19 - fix: Crash when drag the selection beyond the end of the document. - enhancement: Drag the selection beyond the end of the document, and move/copy it beyond the last line. - enhancement: Open Containing folder will auto select the file in windows file explore. + - fix: Class constructor & destructor is not correctly handled. Red Panda C++ Version 2.18 diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index db9b1873..82d0fea5 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -1930,10 +1930,14 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType) return; } } + bool isDestructor = false; if (!sName.isEmpty()) { if (sName.endsWith("::")) sName+=mTokenizer[mIndex]->text; - else { + else if (sName.endsWith("~")) { + isDestructor=true; + sName+=mTokenizer[mIndex]->text; + } else { sType += " "+sName; sName = mTokenizer[mIndex]->text; } @@ -1941,8 +1945,18 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType) sName = mTokenizer[mIndex]->text; mIndex++; - handleMethod(StatementKind::skFunction,sType, + if (isDestructor) + handleMethod(StatementKind::skDestructor,sType, + sName,mIndex,false,isFriend); + else { + sType=sType.trimmed(); + if (sType.isEmpty()) + handleMethod(StatementKind::skConstructor,sType, + sName,mIndex,false,isFriend); + else + handleMethod(StatementKind::skFunction,sType, sName,mIndex,isStatic,isFriend); + } return; } else if ( @@ -1956,6 +1970,9 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType) } else if ( mTokenizer[mIndex + 1]->text == "::") { sName = sName + mTokenizer[mIndex]->text+ "::"; mIndex+=2; + } else if (mTokenizer[mIndex]->text == "~") { + sName = sName + "~"; + mIndex++; } else { QString s = mTokenizer[mIndex]->text; if (sName.endsWith("::")) { @@ -3178,10 +3195,11 @@ bool CppParser::handleStatement() mIndex++; } else if (mTokenizer[mIndex]->text.startsWith('~')) { //it should be a destructor - if (mIndex+1text=='(') { + if (mIndex+2text[0]) + && mTokenizer[mIndex+2]->text=='(') { //dont further check to speed up - handleMethod(StatementKind::skDestructor, "", '~'+mTokenizer[mIndex]->text, mIndex+1, false, false); + handleMethod(StatementKind::skDestructor, "", '~'+mTokenizer[mIndex+1]->text, mIndex+2, false, false); } else { //error mIndex=moveToEndOfStatement(mIndex,false);