work save
This commit is contained in:
parent
2e54b4460d
commit
4d6f78b0fc
|
@ -252,7 +252,11 @@ PStatement CppParser::findStatementOf(const QString &fileName, const QString &ph
|
||||||
return findStatementOf(fileName,phrase,findAndScanBlockAt(fileName,line));
|
return findStatementOf(fileName,phrase,findAndScanBlockAt(fileName,line));
|
||||||
}
|
}
|
||||||
|
|
||||||
PStatement CppParser::findStatementOf(const QString &fileName, const QString &phrase, const PStatement& currentScope, PStatement &parentScopeType, bool force)
|
PStatement CppParser::findStatementOf(const QString &fileName,
|
||||||
|
const QString &phrase,
|
||||||
|
const PStatement& currentScope,
|
||||||
|
PStatement &parentScopeType,
|
||||||
|
bool force)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mMutex);
|
QMutexLocker locker(&mMutex);
|
||||||
PStatement result;
|
PStatement result;
|
||||||
|
@ -412,7 +416,7 @@ PStatement CppParser::findStatement(
|
||||||
if (mParsing)
|
if (mParsing)
|
||||||
return PStatement();
|
return PStatement();
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
return doFindStatement(fileName,phraseExpression,pos,currentScope,PStatement());
|
return doFindStatement(fileName,phraseExpression,pos,currentScope,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -3360,7 +3364,7 @@ PStatement CppParser::doParseSubExpression3(const QString &fileName,
|
||||||
const QStringList &phraseExpression,
|
const QStringList &phraseExpression,
|
||||||
int &pos,
|
int &pos,
|
||||||
const PStatement ¤tScope,
|
const PStatement ¤tScope,
|
||||||
const PStatement &ownerStatement)
|
bool freeScoped)
|
||||||
{
|
{
|
||||||
if (pos>=phraseExpression.length())
|
if (pos>=phraseExpression.length())
|
||||||
return PStatement();
|
return PStatement();
|
||||||
|
@ -3370,45 +3374,156 @@ PStatement CppParser::doParseSubExpression3(const QString &fileName,
|
||||||
phraseExpression,
|
phraseExpression,
|
||||||
pos,
|
pos,
|
||||||
currentScope,
|
currentScope,
|
||||||
ownerStatement);
|
freeScoped);
|
||||||
} else if (phraseExpression[pos]=="&") {
|
} else if (phraseExpression[pos]=="&") {
|
||||||
pos++;
|
pos++;
|
||||||
return doParseSubExpression3(fileName,
|
return doParseSubExpression3(fileName,
|
||||||
phraseExpression,
|
phraseExpression,
|
||||||
pos,
|
pos,
|
||||||
currentScope,
|
currentScope,
|
||||||
ownerStatement);
|
freeScoped);
|
||||||
|
} else if (phraseExpression[pos]=="++"
|
||||||
|
|| phraseExpression[pos]=="--") {
|
||||||
|
pos++;
|
||||||
|
return doParseSubExpression3(fileName,
|
||||||
|
phraseExpression,
|
||||||
|
pos,
|
||||||
|
currentScope,
|
||||||
|
freeScoped);
|
||||||
}
|
}
|
||||||
return doParseSubExpression2(fileName,
|
return doParseSubExpression2(fileName,
|
||||||
phraseExpression,
|
phraseExpression,
|
||||||
pos,
|
pos,
|
||||||
currentScope,
|
currentScope,
|
||||||
ownerStatement);
|
freeScoped);
|
||||||
|
}
|
||||||
|
|
||||||
|
PStatement CppParser::doParseSubExpression2(const QString &fileName,
|
||||||
|
const QStringList &phraseExpression,
|
||||||
|
int &pos, const PStatement ¤tScope,
|
||||||
|
bool freeScoped)
|
||||||
|
{
|
||||||
|
if (pos>=phraseExpression.length())
|
||||||
|
return PStatement();
|
||||||
|
PStatement current = doParseSubExpression1(fileName,
|
||||||
|
phraseExpression,
|
||||||
|
pos,
|
||||||
|
currentScope,
|
||||||
|
freeScoped);
|
||||||
|
if (!current)
|
||||||
|
return PStatement();
|
||||||
|
pos++;
|
||||||
|
while (pos<phraseExpression.length()) {
|
||||||
|
if (phraseExpression[pos]=="++" || phraseExpression[pos]=="--") {
|
||||||
|
pos++;
|
||||||
|
} else if (phraseExpression[pos] == "(") {
|
||||||
|
//skip to ")"
|
||||||
|
if (current->kind == StatementKind::skClass) {
|
||||||
|
//type cast
|
||||||
|
} else if (current->kind == StatementKind::skFunction) {
|
||||||
|
//function call
|
||||||
|
}
|
||||||
|
} else if (phraseExpression[pos] == "[") {
|
||||||
|
//skip to "]"
|
||||||
|
} else if (phraseExpression[pos] == ".") {
|
||||||
|
pos++;
|
||||||
|
current = doParseSubExpression1(fileName,
|
||||||
|
phraseExpression,
|
||||||
|
pos,
|
||||||
|
current,
|
||||||
|
false);
|
||||||
|
} else if (phraseExpression[pos] == "->") {
|
||||||
|
pos++;
|
||||||
|
current = doParseSubExpression1(fileName,
|
||||||
|
phraseExpression,
|
||||||
|
pos,
|
||||||
|
current,
|
||||||
|
false);
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PStatement CppParser::doParseSubExpression1(const QString &fileName,
|
||||||
|
const QStringList &phraseExpression,
|
||||||
|
int &pos,
|
||||||
|
const PStatement ¤tScope,
|
||||||
|
bool freeScoped)
|
||||||
|
{
|
||||||
|
if (pos>=phraseExpression.length())
|
||||||
|
return PStatement();
|
||||||
|
PStatement current = doParseSubExpression0(fileName,
|
||||||
|
phraseExpression,
|
||||||
|
pos,
|
||||||
|
currentScope,
|
||||||
|
freeScoped);
|
||||||
|
pos++;
|
||||||
|
while (pos<phraseExpression.length()) {
|
||||||
|
if (phraseExpression[pos]=="::" ) {
|
||||||
|
pos++;
|
||||||
|
if (!current) {
|
||||||
|
//global scope
|
||||||
|
} else if (current->kind == StatementKind::skClass) {
|
||||||
|
//static member
|
||||||
|
} else if (current->kind == StatementKind::skNamespace) {
|
||||||
|
|
||||||
|
} else if (current->kind == StatementKind::skNamespaceAlias) {
|
||||||
|
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
PStatement CppParser::doParseSubExpression0(const QString &fileName,
|
||||||
|
const QStringList &phraseExpression,
|
||||||
|
int &pos, const PStatement ¤tScope,
|
||||||
|
bool freeScoped)
|
||||||
|
{
|
||||||
|
if (pos>=phraseExpression.length())
|
||||||
|
return PStatement();
|
||||||
|
if (phraseExpression[pos]=="(") {
|
||||||
|
pos++;
|
||||||
|
PStatement statement = doFindStatement(fileName,phraseExpression,pos,currentScope,freeScoped);
|
||||||
|
if (pos >= phraseExpression.length() || phraseExpression[pos]!=")")
|
||||||
|
return PStatement();
|
||||||
|
else
|
||||||
|
return statement;
|
||||||
|
} else if (isIdentifier(phraseExpression[pos])) {
|
||||||
|
|
||||||
|
} else if (isIntegerLiteral(phraseExpression[pos])) {
|
||||||
|
} else if (isIntegerLiteral(phraseExpression[pos])) {
|
||||||
|
} else if (isFloatLiteral(phraseExpression[pos])) {
|
||||||
|
} else if (isStringLiteral(phraseExpression[pos])) {
|
||||||
|
|
||||||
|
} else
|
||||||
|
return PStatement();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PStatement CppParser::doFindStatement(const QString &fileName,
|
PStatement CppParser::doFindStatement(const QString &fileName,
|
||||||
const QStringList &phraseExpression,
|
const QStringList &phraseExpression,
|
||||||
int& pos,
|
int& pos,
|
||||||
const PStatement ¤tScope,
|
const PStatement ¤tScope,
|
||||||
const PStatement &ownerStatement)
|
bool freeScoped)
|
||||||
{
|
{
|
||||||
if (pos>=phraseExpression.length())
|
if (pos>=phraseExpression.length())
|
||||||
return PStatement();
|
return PStatement();
|
||||||
//find the start scope statement
|
//find the start scope statement
|
||||||
PStatement currentStatement = doParseSubExpression3(fileName,phraseExpression,pos,currentScope, ownerStatement);
|
PStatement currentStatement = doParseSubExpression3(fileName,phraseExpression,pos,currentScope, freeScoped);
|
||||||
while (pos < phraseExpression.length() ) {
|
while (pos < phraseExpression.length() ) {
|
||||||
if (currentStatement &&
|
if (currentStatement &&
|
||||||
(currentStatement->kind == StatementKind::skVariable
|
(currentStatement->kind == StatementKind::skVariable)
|
||||||
|| currentStatement->kind == StatementKind::skFunction)
|
|
||||||
&& (phraseExpression[pos]==".*"
|
&& (phraseExpression[pos]==".*"
|
||||||
|| phraseExpression[pos]=="->*")) {
|
|| phraseExpression[pos]=="->*")) {
|
||||||
pos++; // skip '::';
|
pos++;
|
||||||
PStatement currentStatementScope = findTypeDefinitionOf(
|
PStatement currentStatementScope = findTypeDefinitionOf(
|
||||||
fileName,
|
fileName,
|
||||||
currentStatement->type,
|
currentStatement->type,
|
||||||
currentStatement->parentScope.lock());
|
currentStatement->parentScope.lock());
|
||||||
currentStatement = doParseSubExpression3(fileName,phraseExpression,pos,currentScope, currentStatementScope);
|
currentStatement = doParseSubExpression3(fileName,phraseExpression,pos,currentStatementScope,false);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,12 +207,42 @@ private:
|
||||||
const QStringList& phraseExpression,
|
const QStringList& phraseExpression,
|
||||||
int &pos,
|
int &pos,
|
||||||
const PStatement& currentScope,
|
const PStatement& currentScope,
|
||||||
const PStatement& ownerStatement);
|
bool freeScoped);
|
||||||
|
PStatement doParseSubExpression2(
|
||||||
|
const QString& fileName,
|
||||||
|
const QStringList& phraseExpression,
|
||||||
|
int &pos,
|
||||||
|
const PStatement& currentScope,
|
||||||
|
bool freeScoped);
|
||||||
|
PStatement doParseSubExpression1(
|
||||||
|
const QString& fileName,
|
||||||
|
const QStringList& phraseExpression,
|
||||||
|
int &pos,
|
||||||
|
const PStatement& currentScope,
|
||||||
|
bool freeScoped);
|
||||||
|
PStatement doParseSubExpression0(
|
||||||
|
const QString& fileName,
|
||||||
|
const QStringList& phraseExpression,
|
||||||
|
int &pos,
|
||||||
|
const PStatement& currentScope,
|
||||||
|
bool freeScoped);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief find the expression's corresponding statement in the specified file and scope
|
||||||
|
* If the statement is free scoped, if it's not member of the currentScope,
|
||||||
|
* we'll search it in the currentScope's outer scope recursively
|
||||||
|
* @param fileName
|
||||||
|
* @param phraseExpression
|
||||||
|
* @param pos
|
||||||
|
* @param currentScope
|
||||||
|
* @param freeScope if the statement is free scoped.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
PStatement doFindStatement(const QString& fileName,
|
PStatement doFindStatement(const QString& fileName,
|
||||||
const QStringList& phraseExpression,
|
const QStringList& phraseExpression,
|
||||||
int &pos,
|
int &pos,
|
||||||
const PStatement& currentScope,
|
const PStatement& currentScope,
|
||||||
const PStatement& ownerStatement);
|
bool freeScoped);
|
||||||
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();
|
||||||
|
|
Loading…
Reference in New Issue