From 8fe15dab8ab1b8f8d4ed516dcbd49df6376eee13 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 19 Oct 2023 19:32:08 +0800 Subject: [PATCH] - enhancment: Code suggestion for embedded std::vectors. --- NEWS.md | 3 ++ RedPandaIDE/parser/cppparser.cpp | 49 +++++++++++++------------------- RedPandaIDE/parser/cppparser.h | 2 ++ 3 files changed, 24 insertions(+), 30 deletions(-) diff --git a/NEWS.md b/NEWS.md index 6813960f..6a409040 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +Red Panda C++ Version 2.26 + - enhancment: Code suggestion for embedded std::vectors. + Red Panda C++ Version 2.25 - fix: Symbol completion of '(' before selection may fail, if cursor is at the beginning of the selection. diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index dc84bc60..9093a217 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -4749,9 +4749,7 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName, // qDebug()<<"typeName"<baseStatement->type<baseStatement->command; PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); if (typeStatement) { - result = doCreateEvalType(fileName,typeName,parentScope); - result->definitionString=typeName; - result->kind = EvalStatementKind::Variable; + result = doCreateTypedEvalVar(fileName,typeName,parentScope, result->baseStatement); } else { result = PEvalStatement(); } @@ -4760,9 +4758,7 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName, // qDebug()<<"typeName"<baseStatement->type<baseStatement->command; PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); if (typeStatement) { - result = doCreateEvalType(fileName,typeName,parentScope); - result->definitionString=typeName; - result->kind = EvalStatementKind::Variable; + result = doCreateTypedEvalVar(fileName,typeName,parentScope,result->baseStatement); } else { result = PEvalStatement(); } @@ -4784,9 +4780,7 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName, // qDebug()<<"typeName"<definitionString=typeName; - result->kind = EvalStatementKind::Variable; + result = doCreateTypedEvalVar(fileName,typeName,parentScope,result->baseStatement); } else { result = PEvalStatement(); } @@ -4931,9 +4925,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName, if (!typeName.isEmpty()) typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); if (typeStatement) { - result = doCreateEvalType(fileName,typeName,parentScope); - result->definitionString = typeName; - result->kind = EvalStatementKind::Variable; + result = doCreateTypedEvalVar(fileName,typeName,parentScope,result->baseStatement); lastResult = result; } else { return PEvalStatement(); @@ -4950,9 +4942,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName, if (!typeName.isEmpty()) typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); if (typeStatement) { - result = doCreateEvalType(fileName,typeName,parentScope); - result->definitionString = typeName; - result->kind = EvalStatementKind::Variable; + result = doCreateTypedEvalVar(fileName,typeName,parentScope,result->baseStatement); lastResult = result; } else { return PEvalStatement(); @@ -4984,9 +4974,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName, typeStatement = doFindTypeDefinitionOf(fileName, typeName, parentScope); if (typeStatement) { - result = doCreateEvalType(fileName,typeName,parentScope); - result->definitionString=typeName; - result->kind = EvalStatementKind::Variable; + result = doCreateTypedEvalVar(fileName,typeName,parentScope,result->baseStatement); lastResult = result; } else { return PEvalStatement(); @@ -5001,9 +4989,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName, typeStatement = doFindTypeDefinitionOf(fileName, typeName, parentScope); if (typeStatement) { - result = doCreateEvalType(fileName,typeName,parentScope); - result->definitionString=typeName; - result->kind = EvalStatementKind::Variable; + result = doCreateTypedEvalVar(fileName,typeName,parentScope,result->baseStatement); lastResult = result; } else { return PEvalStatement(); @@ -5037,9 +5023,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName, // qDebug()<<"typeName"<baseStatement->type<baseStatement->command; PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); if (typeStatement) { - result = doCreateEvalType(fileName,typeName,parentScope); - result->definitionString=typeName; - result->kind = EvalStatementKind::Variable; + result = doCreateTypedEvalVar(fileName,typeName,parentScope,result->baseStatement); } else { result = PEvalStatement(); } @@ -5048,9 +5032,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName, // qDebug()<<"typeName"<baseStatement->type<baseStatement->command; PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); if (typeStatement) { - result = doCreateEvalType(fileName,typeName,parentScope); - result->definitionString=typeName; - result->kind = EvalStatementKind::Variable; + result = doCreateTypedEvalVar(fileName,typeName,parentScope,result->baseStatement); } else { result = PEvalStatement(); } @@ -5071,9 +5053,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName, // qDebug()<<"typeName"<definitionString=typeName; - result->kind = EvalStatementKind::Variable; + result = doCreateTypedEvalVar(fileName,typeName,parentScope,result->baseStatement); } else { return PEvalStatement(); } @@ -5512,6 +5492,15 @@ PEvalStatement CppParser::doCreateEvalType(const QString &primitiveType) const PStatement()); } +PEvalStatement CppParser::doCreateTypedEvalVar(const QString &fileName, const QString &typeName, const PStatement &parentScope, const PStatement &baseStatement) const +{ + PEvalStatement result = doCreateEvalType(fileName,typeName,parentScope); + result->definitionString=typeName; + result->kind = EvalStatementKind::Variable; + result->baseStatement = baseStatement; + return result; +} + PEvalStatement CppParser::doCreateEvalVariable( const QString &fileName, const PStatement& varStatement, diff --git a/RedPandaIDE/parser/cppparser.h b/RedPandaIDE/parser/cppparser.h index 5e3a93b0..5f93fa46 100644 --- a/RedPandaIDE/parser/cppparser.h +++ b/RedPandaIDE/parser/cppparser.h @@ -375,6 +375,8 @@ private: PEvalStatement doCreateEvalType(const QString& fileName,const PStatement& typeStatement) const; PEvalStatement doCreateEvalType(const QString& primitiveType) const; + PEvalStatement doCreateTypedEvalVar(const QString& fileName,const QString& typeName, const PStatement& parentScope, const PStatement &baseStatement) const; + PEvalStatement doCreateEvalVariable( const QString& fileName, const PStatement& varStatement,