- enhancement: Auto type induction for "std::make_shared"/"std::make_unique"

This commit is contained in:
Roy Qu 2024-04-14 10:17:17 +08:00
parent 5d1b874bdf
commit c6c7d92e1c
2 changed files with 26 additions and 8 deletions

View File

@ -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.

View File

@ -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
&& pos<phraseExpression.length()
&& phraseExpression[pos]=='<') {
result->templateParams = "";
int oldPos = pos;
doSkipInExpression(phraseExpression,pos,"<",">");
for(int i=oldPos;i<pos;i++) {
result->templateParams+=phraseExpression[i];
}
}
}
// qDebug()<<pos<<" term end";
// if (!result) {
// qDebug()<<"not found !!!!";
// }
return result;
}
@ -5698,10 +5712,13 @@ PEvalStatement CppParser::doCreateEvalFunction(
int pointerLevel=0;
QString templateParams;
PStatement typeStatement;
QString type = funcStatement->type;
if (funcStatement->fullName == "std::make_unique")
type = "unique_ptr";
PStatement effetiveTypeStatement = doParseEvalTypeInfo(
fileName,
funcStatement->parentScope.lock(),
funcStatement->type,
type,
baseType,
typeStatement,
pointerLevel,