work save

This commit is contained in:
Roy Qu 2023-06-20 10:58:14 +08:00
parent 1928783cbd
commit 9e7d82fc52
4 changed files with 92 additions and 64 deletions

View File

@ -6,6 +6,7 @@ Red Panda C++ Version 2.23
- enhancement: Close other editors. - enhancement: Close other editors.
- fix: Goto definition/Goto declaration/Info tips can't be correctly triggered when mouse pointer is at the last half character of current word. - fix: Goto definition/Goto declaration/Info tips can't be correctly triggered when mouse pointer is at the last half character of current word.
- fix: Use "/" as path seperator when starting app by double clicking c/c++ files in the explorer. - fix: Use "/" as path seperator when starting app by double clicking c/c++ files in the explorer.
- enhancement: differenciate -> and . when displaying completion suggestion infos.
Red Panda C++ Version 2.22 Red Panda C++ Version 2.22

View File

@ -4400,7 +4400,7 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName,
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command; // qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
if (typeStatement) { if (typeStatement) {
result = doCreateEvalType(fileName,typeStatement); result = doCreateEvalType(fileName,typeName,parentScope);
result->definitionString=typeName; result->definitionString=typeName;
result->kind = EvalStatementKind::Variable; result->kind = EvalStatementKind::Variable;
} else { } else {
@ -4411,7 +4411,7 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName,
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command; // qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
if (typeStatement) { if (typeStatement) {
result = doCreateEvalType(fileName,typeStatement); result = doCreateEvalType(fileName,typeName,parentScope);
result->definitionString=typeName; result->definitionString=typeName;
result->kind = EvalStatementKind::Variable; result->kind = EvalStatementKind::Variable;
} else { } else {
@ -4435,7 +4435,7 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName,
// qDebug()<<"typeName"<<typeName; // qDebug()<<"typeName"<<typeName;
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
if (typeStatement) { if (typeStatement) {
result = doCreateEvalType(fileName,typeStatement); result = doCreateEvalType(fileName,typeName,parentScope);
result->definitionString=typeName; result->definitionString=typeName;
result->kind = EvalStatementKind::Variable; result->kind = EvalStatementKind::Variable;
} else { } else {
@ -4582,7 +4582,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
if (!typeName.isEmpty()) if (!typeName.isEmpty())
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
if (typeStatement) { if (typeStatement) {
result = doCreateEvalType(fileName,typeStatement); result = doCreateEvalType(fileName,typeName,parentScope);
result->definitionString = typeName; result->definitionString = typeName;
result->kind = EvalStatementKind::Variable; result->kind = EvalStatementKind::Variable;
lastResult = result; lastResult = result;
@ -4601,7 +4601,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
if (!typeName.isEmpty()) if (!typeName.isEmpty())
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
if (typeStatement) { if (typeStatement) {
result = doCreateEvalType(fileName,typeStatement); result = doCreateEvalType(fileName,typeName,parentScope);
result->definitionString = typeName; result->definitionString = typeName;
result->kind = EvalStatementKind::Variable; result->kind = EvalStatementKind::Variable;
lastResult = result; lastResult = result;
@ -4635,7 +4635,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
typeStatement = doFindTypeDefinitionOf(fileName, typeName, typeStatement = doFindTypeDefinitionOf(fileName, typeName,
parentScope); parentScope);
if (typeStatement) { if (typeStatement) {
result = doCreateEvalType(fileName,typeStatement); result = doCreateEvalType(fileName,typeName,parentScope);
result->definitionString=typeName; result->definitionString=typeName;
result->kind = EvalStatementKind::Variable; result->kind = EvalStatementKind::Variable;
lastResult = result; lastResult = result;
@ -4652,7 +4652,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
typeStatement = doFindTypeDefinitionOf(fileName, typeName, typeStatement = doFindTypeDefinitionOf(fileName, typeName,
parentScope); parentScope);
if (typeStatement) { if (typeStatement) {
result = doCreateEvalType(fileName,typeStatement); result = doCreateEvalType(fileName,typeName,parentScope);
result->definitionString=typeName; result->definitionString=typeName;
result->kind = EvalStatementKind::Variable; result->kind = EvalStatementKind::Variable;
lastResult = result; lastResult = result;
@ -4688,7 +4688,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command; // qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
if (typeStatement) { if (typeStatement) {
result = doCreateEvalType(fileName,typeStatement); result = doCreateEvalType(fileName,typeName,parentScope);
result->definitionString=typeName; result->definitionString=typeName;
result->kind = EvalStatementKind::Variable; result->kind = EvalStatementKind::Variable;
} else { } else {
@ -4699,7 +4699,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
// qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command; // qDebug()<<"typeName"<<typeName<<lastResult->baseStatement->type<<lastResult->baseStatement->command;
PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); PStatement typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
if (typeStatement) { if (typeStatement) {
result = doCreateEvalType(fileName,typeStatement); result = doCreateEvalType(fileName,typeName,parentScope);
result->definitionString=typeName; result->definitionString=typeName;
result->kind = EvalStatementKind::Variable; result->kind = EvalStatementKind::Variable;
} else { } else {
@ -4722,7 +4722,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName,
// qDebug()<<"typeName"<<typeName; // qDebug()<<"typeName"<<typeName;
typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope); typeStatement=doFindTypeDefinitionOf(fileName, typeName,parentScope);
if (typeStatement) { if (typeStatement) {
result = doCreateEvalType(fileName,typeStatement); result = doCreateEvalType(fileName,typeName,parentScope);
result->definitionString=typeName; result->definitionString=typeName;
result->kind = EvalStatementKind::Variable; result->kind = EvalStatementKind::Variable;
} else { } else {
@ -5085,6 +5085,31 @@ PEvalStatement CppParser::doCreateEvalNamespace(const PStatement &namespaceState
namespaceStatement); namespaceStatement);
} }
PEvalStatement CppParser::doCreateEvalType(const QString &fileName, const QString &typeName, const PStatement& parentScope) const
{
QString baseType;
PStatement typeStatement;
int pointerLevel=0;
QString templateParams;
PStatement effectiveTypeStatement = doParseEvalTypeInfo(
fileName,
parentScope,
typeName,
baseType,
typeStatement,
pointerLevel,
templateParams);
return std::make_shared<EvalStatement>(
baseType,
EvalStatementKind::Type,
PStatement(),
typeStatement,
effectiveTypeStatement,
pointerLevel,
templateParams
);
}
PEvalStatement CppParser::doCreateEvalType(const QString& fileName,const PStatement &typeStatement) const PEvalStatement CppParser::doCreateEvalType(const QString& fileName,const PStatement &typeStatement) const
{ {
if (!typeStatement) if (!typeStatement)
@ -5325,55 +5350,55 @@ PStatement CppParser::doParseEvalTypeInfo(
position--; position--;
} }
typeStatement = doFindStatementOf(fileName,baseType,scope); typeStatement = doFindStatementOf(fileName,baseType,scope);
PStatement effectiveTypeStatement = typeStatement;
int level=0; int level=0;
while (typeStatement && (typeStatement->kind == StatementKind::skTypedef while (effectiveTypeStatement && (effectiveTypeStatement->kind == StatementKind::skTypedef
|| typeStatement->kind == StatementKind::skPreprocessor)) { || effectiveTypeStatement->kind == StatementKind::skPreprocessor)) {
if (level >20) // prevent infinite loop if (level >20) // prevent infinite loop
break; break;
level++; level++;
baseType=""; baseType="";
syntaxer.resetState(); syntaxer.resetState();
syntaxer.setLine(typeStatement->type,0); syntaxer.setLine(effectiveTypeStatement->type,0);
int bracketLevel = 0; int bracketLevel = 0;
int templateLevel = 0; int templateLevel = 0;
while(!syntaxer.eol()) { while(!syntaxer.eol()) {
QString token = syntaxer.getToken(); QString token = syntaxer.getToken();
if (bracketLevel == 0 && templateLevel ==0) { if (bracketLevel == 0 && templateLevel ==0) {
if (token == "*") if (token == "*")
pointerLevel++; pointerLevel++;
else if (token == "&") else if (token == "&")
pointerLevel--; pointerLevel--;
else if (syntaxer.getTokenAttribute()->tokenType() == QSynedit::TokenType::Identifier) { else if (syntaxer.getTokenAttribute()->tokenType() == QSynedit::TokenType::Identifier) {
baseType += token; baseType += token;
} else if (token == "[") { } else if (token == "[") {
pointerLevel++; pointerLevel++;
bracketLevel++; bracketLevel++;
} else if (token == "<") { } else if (token == "<") {
templateLevel++; templateLevel++;
templateParams += token; templateParams += token;
} else if (token == "::") { } else if (token == "::") {
baseType += token; baseType += token;
} }
} else if (bracketLevel > 0) { } else if (bracketLevel > 0) {
if (token == "[") { if (token == "[") {
bracketLevel++; bracketLevel++;
} else if (token == "]") { } else if (token == "]") {
bracketLevel--; bracketLevel--;
} }
} else if (templateLevel > 0) { } else if (templateLevel > 0) {
if (token == "<") { if (token == "<") {
templateLevel++; templateLevel++;
} else if (token == ">") { } else if (token == ">") {
templateLevel--; templateLevel--;
} }
templateParams += token; }
} syntaxer.next();
syntaxer.next(); }
} effectiveTypeStatement = doFindStatementOf(fileName,baseType, effectiveTypeStatement->parentScope.lock());
typeStatement = doFindStatementOf(fileName,baseType, typeStatement->parentScope.lock());
} }
typeStatement = getTypeDef(typeStatement,fileName,baseType); effectiveTypeStatement = getTypeDef(effectiveTypeStatement,fileName,baseType);
return typeStatement; return effectiveTypeStatement;
} }
int CppParser::getBracketEnd(const QString &s, int startAt) const int CppParser::getBracketEnd(const QString &s, int startAt) const

View File

@ -356,6 +356,7 @@ private:
PEvalStatement doCreateEvalNamespace(const PStatement& namespaceStatement) const; PEvalStatement doCreateEvalNamespace(const PStatement& namespaceStatement) const;
PEvalStatement doCreateEvalType(const QString& fileName,const QString& typeName, const PStatement& parentScope) const;
PEvalStatement doCreateEvalType(const QString& fileName,const PStatement& typeStatement) const; PEvalStatement doCreateEvalType(const QString& fileName,const PStatement& typeStatement) const;
PEvalStatement doCreateEvalType(const QString& primitiveType) const; PEvalStatement doCreateEvalType(const QString& primitiveType) const;

View File

@ -773,12 +773,11 @@ void CodeCompletionPopup::getCompletionFor(
if (!classTypeStatement) if (!classTypeStatement)
return; return;
} }
} } else if (STLPointers.contains(classTypeStatement->fullName)
//is a smart pointer
if (STLPointers.contains(classTypeStatement->fullName)
&& (memberOperator == "->" && (memberOperator == "->"
|| memberOperator == "->*") || memberOperator == "->*")
&& ownerStatement->baseStatement) { && ownerStatement->baseStatement) {
//is a smart pointer
QString typeName= mParser->findFirstTemplateParamOf( QString typeName= mParser->findFirstTemplateParamOf(
fileName, fileName,
ownerStatement->baseStatement->type, ownerStatement->baseStatement->type,
@ -789,14 +788,16 @@ void CodeCompletionPopup::getCompletionFor(
scope); scope);
if (!classTypeStatement) if (!classTypeStatement)
return; return;
} else {
//normal member access
if (memberOperator=="." && ownerStatement->pointerLevel !=0)
return;
if (memberOperator=="->" && ownerStatement->pointerLevel!=1)
return;
} }
if (!isIncluded(classTypeStatement->fileName) && if (!isIncluded(classTypeStatement->fileName) &&
!isIncluded(classTypeStatement->definitionFileName)) !isIncluded(classTypeStatement->definitionFileName))
return; return;
if (memberOperator=="." && ownerStatement->pointerLevel !=0)
return;
if (memberOperator=="->" && ownerStatement->pointerLevel!=1)
return;
if ((classTypeStatement == scopeTypeStatement) || (ownerStatement->effectiveTypeStatement->command == "this")) { if ((classTypeStatement == scopeTypeStatement) || (ownerStatement->effectiveTypeStatement->command == "this")) {
//we can use all members //we can use all members
addChildren(classTypeStatement,fileName,-1); addChildren(classTypeStatement,fileName,-1);