work save

This commit is contained in:
Roy Qu 2021-12-04 18:38:54 +08:00
parent 8a2d40f6d7
commit 2e54b4460d
3 changed files with 91 additions and 3 deletions

View File

@ -338,7 +338,6 @@ PStatement CppParser::findStatementOf(const QString &fileName, const QString &ph
if (!statement) if (!statement)
return PStatement(); return PStatement();
} }
qDebug()<<"-----";
PStatement lastScopeStatement; PStatement lastScopeStatement;
QString typeName; QString typeName;
PStatement typeStatement; PStatement typeStatement;
@ -404,6 +403,18 @@ PStatement CppParser::findStatementOf(const QString &fileName, const QString &ph
return statement; return statement;
} }
PStatement CppParser::findStatement(
const QString &fileName,
const QStringList &phraseExpression,
const PStatement &currentScope)
{
QMutexLocker locker(&mMutex);
if (mParsing)
return PStatement();
int pos = 0;
return doFindStatement(fileName,phraseExpression,pos,currentScope,PStatement());
}
PStatement CppParser::findStatementOf(const QString &fileName, const QString &phrase, const PStatement& currentClass, bool force) PStatement CppParser::findStatementOf(const QString &fileName, const QString &phrase, const PStatement& currentClass, bool force)
{ {
PStatement statementParentType; PStatement statementParentType;
@ -3345,6 +3356,66 @@ PStatement CppParser::findStatementInNamespace(const QString &name, const QStrin
return PStatement(); return PStatement();
} }
PStatement CppParser::doParseSubExpression3(const QString &fileName,
const QStringList &phraseExpression,
int &pos,
const PStatement &currentScope,
const PStatement &ownerStatement)
{
if (pos>=phraseExpression.length())
return PStatement();
if (phraseExpression[pos]=="*") {
pos++;
return doParseSubExpression3(fileName,
phraseExpression,
pos,
currentScope,
ownerStatement);
} else if (phraseExpression[pos]=="&") {
pos++;
return doParseSubExpression3(fileName,
phraseExpression,
pos,
currentScope,
ownerStatement);
}
return doParseSubExpression2(fileName,
phraseExpression,
pos,
currentScope,
ownerStatement);
}
PStatement CppParser::doFindStatement(const QString &fileName,
const QStringList &phraseExpression,
int& pos,
const PStatement &currentScope,
const PStatement &ownerStatement)
{
if (pos>=phraseExpression.length())
return PStatement();
//find the start scope statement
PStatement currentStatement = doParseSubExpression3(fileName,phraseExpression,pos,currentScope, ownerStatement);
while (pos < phraseExpression.length() ) {
if (currentStatement &&
(currentStatement->kind == StatementKind::skVariable
|| currentStatement->kind == StatementKind::skFunction)
&& (phraseExpression[pos]==".*"
|| phraseExpression[pos]=="->*")) {
pos++; // skip '::';
PStatement currentStatementScope = findTypeDefinitionOf(
fileName,
currentStatement->type,
currentStatement->parentScope.lock());
currentStatement = doParseSubExpression3(fileName,phraseExpression,pos,currentScope, currentStatementScope);
} else {
break;
}
}
return currentStatement;
}
int CppParser::getBracketEnd(const QString &s, int startAt) int CppParser::getBracketEnd(const QString &s, int startAt)
{ {
int i = startAt; int i = startAt;

View File

@ -49,6 +49,9 @@ public:
const QString& phrase, const QString& phrase,
const PStatement& currentClass, const PStatement& currentClass,
bool force = false); bool force = false);
PStatement findStatement(const QString& fileName,
const QStringList& phraseExpression,
const PStatement& currentScope);
//{Find statement starting from startScope} //{Find statement starting from startScope}
PStatement findStatementStartingFrom(const QString& fileName, PStatement findStatementStartingFrom(const QString& fileName,
const QString& phrase, const QString& phrase,
@ -198,6 +201,18 @@ private:
PStatement findStatementInNamespace( PStatement findStatementInNamespace(
const QString& name, const QString& name,
const QString& namespaceName); const QString& namespaceName);
PStatement doParseSubExpression3(
const QString& fileName,
const QStringList& phraseExpression,
int &pos,
const PStatement& currentScope,
const PStatement& ownerStatement);
PStatement doFindStatement(const QString& fileName,
const QStringList& phraseExpression,
int &pos,
const PStatement& currentScope,
const PStatement& ownerStatement);
int getBracketEnd(const QString& s, int startAt); int getBracketEnd(const QString& s, int startAt);
StatementClassScope getClassScope(int index); StatementClassScope getClassScope(int index);
int getCurrentBlockBeginSkip(); int getCurrentBlockBeginSkip();
@ -311,6 +326,8 @@ private:
bool isTypeStatement(StatementKind kind); bool isTypeStatement(StatementKind kind);
void updateSerialId(); void updateSerialId();
private: private:
int mParserId; int mParserId;
int mSerialCount; int mSerialCount;

View File

@ -37,7 +37,7 @@ public:
const QStringList& memberExpression, const QStringList& memberExpression,
const QString& filename, const QString& filename,
int line); int line);
bool search(const QString& phrase, bool autoHideOnSingleResult); bool search(const QString& memberPhrase, bool autoHideOnSingleResult);
PStatement selectedStatement(); PStatement selectedStatement();
@ -86,7 +86,7 @@ private:
const QStringList& memberExpression, const QStringList& memberExpression,
const QString& fileName, const QString& fileName,
int line); int line);
void getFullCompletionListFor(const QString& preWord); void getCompletionListForPreWord(const QString& preWord);
void addKeyword(const QString& keyword); void addKeyword(const QString& keyword);
bool isIncluded(const QString& fileName); bool isIncluded(const QString& fileName);
private: private: