work save
This commit is contained in:
parent
83116306a9
commit
25e0245146
|
@ -515,6 +515,130 @@ PStatement CppParser::getCurrentScope()
|
||||||
return mCurrentScope.back();
|
return mCurrentScope.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppParser::getFullNameSpace(const QString &phrase, QString &sNamespace, QString &member)
|
||||||
|
{
|
||||||
|
sNamespace = "";
|
||||||
|
member = phrase;
|
||||||
|
int strLen = phrase.length();
|
||||||
|
if (strLen==0)
|
||||||
|
return;
|
||||||
|
int lastI =-1;
|
||||||
|
int i=0;
|
||||||
|
while (i<strLen) {
|
||||||
|
if ((i+1<strLen) && (phrase[i]==':') && (phrase[i+1]==':') ) {
|
||||||
|
if (!mNamespaces.contains(sNamespace)) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
lastI = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sNamespace += phrase[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i>=strLen) {
|
||||||
|
if (mNamespaces.contains(sNamespace)) {
|
||||||
|
sNamespace = phrase;
|
||||||
|
member = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lastI >= 0) {
|
||||||
|
sNamespace = phrase.mid(0,lastI);
|
||||||
|
member = phrase.mid(lastI+2);
|
||||||
|
} else {
|
||||||
|
sNamespace = "";
|
||||||
|
member = phrase;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CppParser::getFullStatementName(const QString &command, PStatement parent)
|
||||||
|
{
|
||||||
|
PStatement scopeStatement=parent;
|
||||||
|
while (scopeStatement && !isNamedScope(scopeStatement->kind))
|
||||||
|
scopeStatement = scopeStatement->parentScope.lock();
|
||||||
|
if (scopeStatement)
|
||||||
|
return scopeStatement->fullName + "::" + command;
|
||||||
|
else
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
PStatement CppParser::getIncompleteClass(const QString &command, PStatement parentScope)
|
||||||
|
{
|
||||||
|
QString s=command;
|
||||||
|
//remove template parameter
|
||||||
|
int p = s.indexOf('<');
|
||||||
|
if (p>=0) {
|
||||||
|
s.truncate(p);
|
||||||
|
}
|
||||||
|
PStatement result = findStatementOf(mCurrentFile,s,parentScope,true);
|
||||||
|
if (result && result->kind!=StatementKind::skClass)
|
||||||
|
return PStatement();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
StatementScope CppParser::getScope()
|
||||||
|
{
|
||||||
|
// Don't blindly trust levels. Namespaces and externs can have levels too
|
||||||
|
PStatement currentScope = getCurrentScope();
|
||||||
|
|
||||||
|
// Invalid class or namespace/extern
|
||||||
|
if (!currentScope || (currentScope->kind == StatementKind::skNamespace))
|
||||||
|
return StatementScope::ssGlobal;
|
||||||
|
else if (currentScope->kind == StatementKind::skClass)
|
||||||
|
return StatementScope::ssClassLocal;
|
||||||
|
else
|
||||||
|
return StatementScope::ssLocal;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CppParser::getStatementKey(const QString &sName, const QString &sType, const QString &sNoNameArgs)
|
||||||
|
{
|
||||||
|
return sName + "--" + sType + "--" + sNoNameArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppParser::handleCatchBlock()
|
||||||
|
{
|
||||||
|
int startLine= mTokenizer[mIndex]->line;
|
||||||
|
mIndex++; // skip for/catch;
|
||||||
|
if not ((fIndex < fTokenizer.Tokens.Count) and (fTokenizer[fIndex]^.Text[1] = '(')) then
|
||||||
|
Exit;
|
||||||
|
//skip params
|
||||||
|
i2:=fIndex+1;
|
||||||
|
if i2>=fTokenizer.Tokens.Count then
|
||||||
|
Exit;
|
||||||
|
if fTokenizer[i2].Text[1] = '{' then begin
|
||||||
|
fBlockBeginSkips.Add(i2);
|
||||||
|
i:=SkipBraces(i2);
|
||||||
|
if i=i2 then
|
||||||
|
fBlockEndSkips.Add(fTokenizer.Tokens.Count)
|
||||||
|
else
|
||||||
|
fBlockEndSkips.Add(i);
|
||||||
|
end else begin
|
||||||
|
i:=i2;
|
||||||
|
while (i<fTokenizer.Tokens.Count) and (fTokenizer[i].Text[1]<>';') do
|
||||||
|
inc(i);
|
||||||
|
fBlockEndSkips.Add(i);
|
||||||
|
end;
|
||||||
|
// add a block
|
||||||
|
block := AddStatement(
|
||||||
|
GetCurrentScope,
|
||||||
|
fCurrentFile,
|
||||||
|
'', // override hint
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
startLine,
|
||||||
|
skBlock,
|
||||||
|
GetScope,
|
||||||
|
fClassScope,
|
||||||
|
True,
|
||||||
|
nil,
|
||||||
|
False);
|
||||||
|
AddSoloScopeLevel(block,startLine);
|
||||||
|
if not containsStr('...',fTokenizer[fIndex]^.Text) then
|
||||||
|
scanMethodArgs(block,fTokenizer[fIndex]^.Text);
|
||||||
|
}
|
||||||
|
|
||||||
QString CppParser::expandMacroType(const QString &name)
|
QString CppParser::expandMacroType(const QString &name)
|
||||||
{
|
{
|
||||||
//its done in the preprocessor
|
//its done in the preprocessor
|
||||||
|
@ -750,7 +874,6 @@ bool CppParser::isLineChar(const QChar &ch)
|
||||||
|
|
||||||
bool CppParser::isNotFuncArgs(const QString &args)
|
bool CppParser::isNotFuncArgs(const QString &args)
|
||||||
{
|
{
|
||||||
bool result = true;
|
|
||||||
int i=1; //skip '('
|
int i=1; //skip '('
|
||||||
int endPos = args.length()-1;//skip ')'
|
int endPos = args.length()-1;//skip ')'
|
||||||
bool lastCharIsId=false;
|
bool lastCharIsId=false;
|
||||||
|
@ -791,10 +914,32 @@ bool CppParser::isNotFuncArgs(const QString &args)
|
||||||
}
|
}
|
||||||
PStatement statement =findStatementOf(mCurrentFile,word,getCurrentScope(),true);
|
PStatement statement =findStatementOf(mCurrentFile,word,getCurrentScope(),true);
|
||||||
if (statement &&
|
if (statement &&
|
||||||
!(statement->kind == StatementKind::skClass
|
!isTypeStatement(statement->kind))
|
||||||
|| statement->kind == StatementKind::skTypedef
|
|
||||||
|| statement->kind == StatementKind::skEnum
|
|
||||||
|| statement->kind == StatementKind::skEnumType))
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CppParser::isNamedScope(StatementKind kind)
|
||||||
|
{
|
||||||
|
switch(kind) {
|
||||||
|
case StatementKind::skClass:
|
||||||
|
case StatementKind::skNamespace:
|
||||||
|
case StatementKind::skFunction:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CppParser::isTypeStatement(StatementKind kind)
|
||||||
|
{
|
||||||
|
switch(kind) {
|
||||||
|
case StatementKind::skClass:
|
||||||
|
case StatementKind::skTypedef:
|
||||||
|
case StatementKind::skEnum:
|
||||||
|
case StatementKind::skEnumType:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -169,38 +169,38 @@ private:
|
||||||
int getCurrentBlockEndSkip();
|
int getCurrentBlockEndSkip();
|
||||||
int getCurrentInlineNamespaceEndSkip();
|
int getCurrentInlineNamespaceEndSkip();
|
||||||
PStatement getCurrentScope(); // gets last item from last level
|
PStatement getCurrentScope(); // gets last item from last level
|
||||||
QString getFullStatementName(
|
|
||||||
const QString& command,
|
|
||||||
PStatement parent);
|
|
||||||
void getFullNameSpace(
|
void getFullNameSpace(
|
||||||
const QString& phrase,
|
const QString& phrase,
|
||||||
QString& sNamespace,
|
QString& sNamespace,
|
||||||
QString& member);
|
QString& member);
|
||||||
|
QString getFullStatementName(
|
||||||
|
const QString& command,
|
||||||
|
PStatement parent);
|
||||||
PStatement getIncompleteClass(
|
PStatement getIncompleteClass(
|
||||||
const QString& command,
|
const QString& command,
|
||||||
PStatement parentScope);
|
PStatement parentScope);
|
||||||
StatementScope getScope();
|
StatementScope getScope();
|
||||||
void handlePreprocessor();
|
QString getStatementKey(const QString& sName,
|
||||||
void handleOtherTypedefs();
|
const QString& sType,
|
||||||
void handleStructs(bool isTypedef = false);
|
const QString& sNoNameArgs);
|
||||||
|
void handleCatchBlock();
|
||||||
|
void handleEnum();
|
||||||
|
void handleKeyword();
|
||||||
|
void handleForBlock();
|
||||||
void HandleMethod(
|
void HandleMethod(
|
||||||
const QString& sType,
|
const QString& sType,
|
||||||
const QString& sName,
|
const QString& sName,
|
||||||
const QString& sArgs,
|
const QString& sArgs,
|
||||||
bool isStatic,
|
bool isStatic,
|
||||||
bool isFriend);
|
bool isFriend);
|
||||||
void scanMethodArgs(
|
|
||||||
PStatement functionStatement,
|
|
||||||
const QString& argStr);
|
|
||||||
void handleScope();
|
|
||||||
void handleKeyword();
|
|
||||||
void handleVar();
|
|
||||||
void handleEnum();
|
|
||||||
void handleNamespace();
|
void handleNamespace();
|
||||||
void handleUsing();
|
void handleOtherTypedefs();
|
||||||
void handleForBlock();
|
void handlePreprocessor();
|
||||||
void handleCatchBlock();
|
void handleScope();
|
||||||
bool handleStatement();
|
bool handleStatement();
|
||||||
|
void handleStructs(bool isTypedef = false);
|
||||||
|
void handleUsing();
|
||||||
|
void handleVar();
|
||||||
void internalParse(
|
void internalParse(
|
||||||
const QString& fileName,
|
const QString& fileName,
|
||||||
bool manualUpdate = false);
|
bool manualUpdate = false);
|
||||||
|
@ -225,11 +225,11 @@ private:
|
||||||
// function GetOperator(const Phrase: AnsiString): AnsiString;
|
// function GetOperator(const Phrase: AnsiString): AnsiString;
|
||||||
// function GetRemainder(const Phrase: AnsiString): AnsiString;
|
// function GetRemainder(const Phrase: AnsiString): AnsiString;
|
||||||
// }
|
// }
|
||||||
|
void scanMethodArgs(
|
||||||
|
PStatement functionStatement,
|
||||||
|
const QString& argStr);
|
||||||
QString splitPhrase(const QString& phrase, QString& sClazz, QString &sMember,
|
QString splitPhrase(const QString& phrase, QString& sClazz, QString &sMember,
|
||||||
QString& sOperator);
|
QString& sOperator);
|
||||||
QString getStatementKey(const QString& sName,
|
|
||||||
const QString& sType,
|
|
||||||
const QString& sNoNameArgs);
|
|
||||||
|
|
||||||
QString removeArgNames(const QString& args);
|
QString removeArgNames(const QString& args);
|
||||||
|
|
||||||
|
@ -251,11 +251,27 @@ private:
|
||||||
|
|
||||||
bool isNotFuncArgs(const QString& args);
|
bool isNotFuncArgs(const QString& args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Test if a statement is a class/struct/union/namespace/function
|
||||||
|
* @param kind
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool isNamedScope(StatementKind kind);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Test if a statement is a class/struct/union/enum/enum class/typedef
|
||||||
|
* @param kind
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool isTypeStatement(StatementKind kind);
|
||||||
|
|
||||||
void onProgress(const QString& fileName, int total, int current);
|
void onProgress(const QString& fileName, int total, int current);
|
||||||
void onBusy();
|
void onBusy();
|
||||||
void onStartParsing();
|
void onStartParsing();
|
||||||
void onEndParsing(int total, int updateView);
|
void onEndParsing(int total, int updateView);
|
||||||
void updateSerialId();
|
void updateSerialId();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int mParserId;
|
int mParserId;
|
||||||
int mSerialCount;
|
int mSerialCount;
|
||||||
|
|
Loading…
Reference in New Issue