diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 48447db9..c0e8fb10 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1660,15 +1660,19 @@ QStringList Editor::getOwnerExpressionAndMemberAtPositionForCompletion( } } + QStringList ownerExpression; if (lastMemberOperatorPos<0) { memberOperator = ""; memberExpression = expression; - return QStringList(); } else { memberOperator = expression[lastMemberOperatorPos]; memberExpression = expression.mid(lastMemberOperatorPos+1); - return expression.mid(0,lastMemberOperatorPos); + ownerExpression = expression.mid(0,lastMemberOperatorPos); } + if (memberExpression.length()>1) { + memberExpression = memberExpression.mid(memberExpression.length()-1,1); + } + return ownerExpression; } QStringList Editor::getExpressionAtPositionForCompletion( @@ -2674,6 +2678,7 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete) caretXY(), memberOperator, memberExpression); + qDebug()<prepareSearch( preWord, @@ -2681,14 +2686,14 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete) memberOperator, memberExpression, mFilename, - pBeginPos.Line); + caretY()); } else { QStringList memberExpression; memberExpression.append(word); mCompletionPopup->prepareSearch(preWord, QStringList(), "", - memberExpression, mFilename, pBeginPos.Line); + memberExpression, mFilename, caretY()); } // Filter the whole statement list diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 7d494d12..2fff3f41 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -403,7 +403,7 @@ PEvalStatement CppParser::evalExpression( QMutexLocker locker(&mMutex); if (mParsing) return PEvalStatement(); - qDebug()<pointerLevel--; + if (result->pointerLevel==0) { + PStatement typeStatement = result->effectiveTypeStatement; + if ((typeStatement) + && STLPointers.contains(typeStatement->fullName) + && result->kind == EvalStatementKind::Variable + && result->baseStatement) { + PStatement parentScope = result->baseStatement->parentScope.lock(); + QString typeName=findFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope); +// qDebug()<<"typeName"<kind = EvalStatementKind::Variable; + } + } + } else + result->pointerLevel--; } } else if (phraseExpression[pos]=="&") { pos++; //skip "&" @@ -3510,7 +3526,7 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName, //parse int startPos = pos; pos++; - qDebug()<<"parse type cast ()"; +// qDebug()<<"parse type cast ()"; PEvalStatement evalType = doEvalExpression( fileName, phraseExpression, @@ -3518,13 +3534,13 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName, scope, PEvalStatement(), true); - qDebug()<= phraseExpression.length() || phraseExpression[pos]!=")") { return PEvalStatement(); } else if (evalType && (evalType->kind == EvalStatementKind::Type)) { pos++; // skip ")" - qDebug()<<"parse type cast exp"; +// qDebug()<<"parse type cast exp"; //it's a type cast result = doEvalCCast(fileName, phraseExpression, @@ -3533,7 +3549,7 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName, previousResult, freeScoped); if (result) { - qDebug()<<"type cast"; +// qDebug()<<"type cast"; result->assignType(evalType); } } else //it's not a type cast @@ -3552,11 +3568,11 @@ PEvalStatement CppParser::doEvalCCast(const QString &fileName, scope, previousResult, freeScoped); - if (result) { - qDebug()<kind<baseType; - } else { - qDebug()<<"!!!!!!!!!!!not found"; - } +// if (result) { +// qDebug()<kind<baseType; +// } else { +// qDebug()<<"!!!!!!!!!!!not found"; +// } return result; } @@ -3572,6 +3588,7 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName, PEvalStatement result; if (pos>=phraseExpression.length()) return result; + PEvalStatement lastResult = previousResult; result = doEvalScopeResolution( fileName, phraseExpression, @@ -3602,17 +3619,52 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName, result = newResult; } else if (result->kind == EvalStatementKind::Function) { doSkipInExpression(phraseExpression,pos,"(",")"); - //function call +// qDebug()<<"????"<<(result->baseStatement!=nullptr)<<(lastResult!=nullptr); + if (result->baseStatement && lastResult && lastResult->baseStatement) { + PStatement parentScope = result->baseStatement->parentScope.lock(); + if (parentScope + && STLContainers.contains(parentScope->fullName) + && STLElementMethods.contains(result->baseStatement->command) + ) { + //stl container methods + PStatement typeStatement = result->effectiveTypeStatement; + QString typeName=findFirstTemplateParamOf(fileName,lastResult->baseStatement->type, parentScope); +// qDebug()<<"typeName"<baseStatement->type<baseStatement->command; + typeStatement=findTypeDefinitionOf(fileName, typeName,parentScope); + if (typeStatement) { + result = doCreateEvalType(fileName,typeStatement); + result->kind = EvalStatementKind::Variable; + } + } + } result->kind = EvalStatementKind::Variable; } else result = PEvalStatement(); } else if (phraseExpression[pos] == "[") { //skip to "]" doSkipInExpression(phraseExpression,pos,"[","]"); - //todo: STL container; - result->pointerLevel--; + if (result->pointerLevel>0) + result->pointerLevel--; + else { + PStatement typeStatement = result->effectiveTypeStatement; + if (typeStatement + && STLContainers.contains(typeStatement->fullName) + && result->kind == EvalStatementKind::Variable + && result->baseStatement) { + PStatement parentScope = result->baseStatement->parentScope.lock(); + QString typeName = findFirstTemplateParamOf(fileName,result->baseStatement->type, + parentScope); + typeStatement = findTypeDefinitionOf(fileName, typeName, + parentScope); + if (typeStatement) { + result = doCreateEvalType(fileName,typeStatement); + result->kind = EvalStatementKind::Variable; + } + } + } } else if (phraseExpression[pos] == ".") { pos++; + lastResult = result; result = doEvalScopeResolution( fileName, phraseExpression, @@ -3620,11 +3672,29 @@ PEvalStatement CppParser::doEvalMemberAccess(const QString &fileName, scope, result, false); - qDebug()<<(result!=nullptr)<") { pos++; - //todo: STL container - result->pointerLevel--; +// qDebug()<<"pointer level"<pointerLevel; + if (result->pointerLevel==0) { + PStatement typeStatement = result->effectiveTypeStatement; + if ((typeStatement) + && STLPointers.contains(typeStatement->fullName) + && result->kind == EvalStatementKind::Variable + && result->baseStatement) { + PStatement parentScope = result->baseStatement->parentScope.lock(); + QString typeName=findFirstTemplateParamOf(fileName,result->baseStatement->type, parentScope); +// qDebug()<<"typeName"<kind = EvalStatementKind::Variable; + } + } + } else { + result->pointerLevel--; + } + lastResult = result; result = doEvalScopeResolution( fileName, phraseExpression, @@ -3700,11 +3770,11 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName, const PEvalStatement& previousResult, bool freeScoped) { - if (previousResult) { - qDebug()<<"eval term "<baseType<baseType<=phraseExpression.length()) return result; @@ -3753,11 +3823,11 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName, if (!previousResult) { statement = findStatementInScope(phraseExpression[pos],PStatement()); } else { - if (previousResult->effectiveTypeStatement) { - qDebug()<effectiveTypeStatement->fullName; - } else { - qDebug()<effectiveTypeStatement) { +// qDebug()<effectiveTypeStatement->fullName; +// } else { +// qDebug()<effectiveTypeStatement); // if (!statement) { // qDebug()<<"not found!"; @@ -3773,6 +3843,14 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName, case StatementKind::skNamespace: result = doCreateEvalNamespace(statement); break; + case StatementKind::skAlias: { + PStatement parentScopeType; + statement = findStatementOf(fileName, statement->type, + scope, parentScopeType, true); + if (statement) + result = doCreateEvalNamespace(statement); + } + break; case StatementKind::skVariable: case StatementKind::skParameter: result = doCreateEvalVariable(fileName,statement); @@ -3805,9 +3883,9 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName, pos++; } else return result; - if (result) { - qDebug()<<"term kind:"<<(int)result->kind; - } +// if (result) { +// qDebug()<<"term kind:"<<(int)result->kind; +// } if (result && result->kind == EvalStatementKind::Type) { //skip "struct", "const", "static", etc while(pos < phraseExpression.length()) { @@ -3850,7 +3928,7 @@ PEvalStatement CppParser::doCreateEvalType(const QString& fileName,const PStatem PStatement statement = doParseEvalTypeInfo( fileName, typeStatement->parentScope.lock(), - typeStatement->type, + typeStatement->type + typeStatement->args, baseType, pointerLevel); return std::make_shared( @@ -3887,9 +3965,10 @@ PEvalStatement CppParser::doCreateEvalVariable(const QString &fileName, PStateme PStatement typeStatement = doParseEvalTypeInfo( fileName, varStatement->parentScope.lock(), - varStatement->type, + varStatement->type+ varStatement->args, baseType, pointerLevel); +// qDebug()<<"parse ..."<( baseType, EvalStatementKind::Variable, @@ -3938,8 +4017,10 @@ void CppParser::doSkipInExpression(const QStringList &expression, int &pos, cons level++; } else if (token == endSymbol) { level--; - if (level==0) + if (level==0) { + pos++; return; + } } pos++; } @@ -3989,7 +4070,8 @@ PStatement CppParser::doParseEvalTypeInfo( int &pointerLevel) { // Remove pointer stuff from type - QString s = type; // 'Type' is a keyword + QString s = type; +// qDebug()<<"eval type info"< 0) { if (token == "<") { templateLevel++; } else if (token == ">") { - templateLevel++; + templateLevel--; } } highlighter.next(); diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index a7e1562d..810b5a14 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -559,7 +559,7 @@ void CodeCompletionPopup::getCompletionFor( // qDebug()<effectiveTypeStatement) { - qDebug()<<"statement not found!"; +// qDebug()<<"statement not found!"; return; } // qDebug()<<"found: "<fullName; @@ -595,10 +595,11 @@ void CodeCompletionPopup::getCompletionFor( //is a smart pointer if (STLPointers.contains(classTypeStatement->fullName) && (memberOperator == "->" - || memberOperator == "->*")) { + || memberOperator == "->*") + && ownerStatement->baseStatement) { QString typeName= mParser->findFirstTemplateParamOf( fileName, - ownerStatement->baseType, + ownerStatement->baseStatement->type, scope); classTypeStatement = mParser->findTypeDefinitionOf( fileName,