diff --git a/NEWS.md b/NEWS.md index a330843f..101f8e67 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +Version 0.2.2 + - enhancement: support C++ using type alias; + Version 0.2.1 - fix: crash when load last opens diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index a04230a8..bb5c560b 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -2814,6 +2814,35 @@ void CppParser::handleUsing() mIndex++; //skip 'using' + //handle things like 'using vec = std::vector; ' + if (mIndex+1 < mTokenizer.tokenCount() + && mTokenizer[mIndex+1]->text == "=") { + QString fullName = mTokenizer[mIndex]->text; + QString aliasName; + mIndex+=2; + while (mIndextext!=';') { + aliasName += mTokenizer[mIndex]->text; + mIndex++; + } + addStatement( + getCurrentScope(), + mCurrentFile, + "using "+fullName+" = " + aliasName, //hint text + aliasName, // name of the alias (type) + fullName, // command + "", // args + "", // values + startLine, + StatementKind::skTypedef, + getScope(), + mClassScope, + true, + false); + // skip ; + mIndex++; + return; + } //handle things like 'using std::vector;' if ((mIndex+2>=mTokenizer.tokenCount()) || (mTokenizer[mIndex]->text != "namespace")) { @@ -3078,12 +3107,12 @@ void CppParser::internalParse(const QString &fileName) break; } #ifdef QT_DEBUG -// StringsToFile(mPreprocessor.result(),"f:\\preprocess.txt"); -// mPreprocessor.dumpDefinesTo("f:\\defines.txt"); -// mPreprocessor.dumpIncludesListTo("f:\\includes.txt"); -// mStatementList.dump("f:\\stats.txt"); -// mTokenizer.dumpTokens("f:\\tokens.txt"); -// mStatementList.dumpAll("f:\\all-stats.txt"); + StringsToFile(mPreprocessor.result(),"f:\\preprocess.txt"); + mPreprocessor.dumpDefinesTo("f:\\defines.txt"); + mPreprocessor.dumpIncludesListTo("f:\\includes.txt"); + mStatementList.dump("f:\\stats.txt"); + mTokenizer.dumpTokens("f:\\tokens.txt"); + mStatementList.dumpAll("f:\\all-stats.txt"); #endif } } diff --git a/RedPandaIDE/parser/cpptokenizer.cpp b/RedPandaIDE/parser/cpptokenizer.cpp index ab556f3b..9e55148b 100644 --- a/RedPandaIDE/parser/cpptokenizer.cpp +++ b/RedPandaIDE/parser/cpptokenizer.cpp @@ -578,9 +578,15 @@ void CppTokenizer::advance() else mCurrent++; break; - case '=': - skipAssignment(); + case '=': { + if (mTokenList.size()>2 + && mTokenList[mTokenList.size()-2]->text == "using") { + addToken("=",mCurrentLine); + mCurrent++; + } else + skipAssignment(); break; + } case '&': case '*': case '!':