From c6c7d92e1c4358f32657a55a8f5b3f540fea1b3b Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 14 Apr 2024 10:17:17 +0800 Subject: [PATCH] - enhancement: Auto type induction for "std::make_shared"/"std::make_unique" --- NEWS.md | 1 + RedPandaIDE/parser/cppparser.cpp | 33 ++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index 797380ef..ae0100fe 100644 --- a/NEWS.md +++ b/NEWS.md @@ -141,6 +141,7 @@ Red Panda C++ Version 2.27 - fix: Shouldn't consider preceeding '&'/'*' when popping completion suggest list for variable members. - fix: Positions of current matching parenthesis not correctly updated. - fix: Can't show correct completion info for vars declared with template parameters ending with ">>". + - enhancement: Auto type induction for "std::make_shared"/"std::make_unique". Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 12b84f8f..5271747f 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -4108,8 +4108,18 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic, if(aliasStatement) { if (aliasStatement->typeStatement) { addedVar->type = aliasStatement->typeStatement->fullName; - if (!addedVar->type.endsWith(">")) - addedVar->type += aliasStatement->templateParams; + if (!aliasStatement->templateParams.isEmpty()) { + if (!addedVar->type.endsWith(">")) { + addedVar->type += aliasStatement->templateParams; + } else { + QString type = addedVar->type; + int pos = type.indexOf('<'); + if (pos>=0) { + type = type.left(pos); + addedVar->type = type + aliasStatement->templateParams; + } + } + } if (aliasStatement->typeStatement && STLIterators.contains(aliasStatement->typeStatement->command) && !aliasStatement->templateParams.isEmpty()) { @@ -5379,13 +5389,17 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName, pos++; } result->pointerLevel = pointerLevel; + } else if (result && result->kind == EvalStatementKind::Function + && postemplateParams = ""; + int oldPos = pos; + doSkipInExpression(phraseExpression,pos,"<",">"); + for(int i=oldPos;itemplateParams+=phraseExpression[i]; + } } } -// qDebug()<type; + if (funcStatement->fullName == "std::make_unique") + type = "unique_ptr"; PStatement effetiveTypeStatement = doParseEvalTypeInfo( fileName, funcStatement->parentScope.lock(), - funcStatement->type, + type, baseType, typeStatement, pointerLevel,