optimization for cpp parser

This commit is contained in:
Roy Qu 2023-03-12 23:45:03 +08:00
parent f37a9908ba
commit 586e6a6185
2 changed files with 123 additions and 135 deletions

View File

@ -212,14 +212,15 @@ PStatement CppParser::findFunctionAt(const QString &fileName, int line)
int CppParser::findLastOperator(const QString &phrase) const int CppParser::findLastOperator(const QString &phrase) const
{ {
int i = phrase.length()-1; int phraseLength = phrase.length();
int i = phraseLength-1;
// Obtain stuff after first operator // Obtain stuff after first operator
while (i>=0) { while (i>=0) {
if ((i+1<phrase.length()) && if ((i+1<phraseLength) &&
(phrase[i + 1] == '>') && (phrase[i] == '-')) (phrase[i + 1] == '>') && (phrase[i] == '-'))
return i; return i;
else if ((i+1<phrase.length()) && else if ((i+1<phraseLength) &&
(phrase[i + 1] == ':') && (phrase[i] == ':')) (phrase[i + 1] == ':') && (phrase[i] == ':'))
return i; return i;
else if (phrase[i] == '.') else if (phrase[i] == '.')
@ -1403,6 +1404,7 @@ PStatement CppParser::addStatement(const PStatement &parent,
void CppParser::setInheritance(int index, const PStatement& classStatement, bool isStruct) void CppParser::setInheritance(int index, const PStatement& classStatement, bool isStruct)
{ {
int tokenCount = mTokenizer.tokenCount();
// Clear it. Assume it is assigned // Clear it. Assume it is assigned
StatementAccessibility lastInheritScopeType = StatementAccessibility::None; StatementAccessibility lastInheritScopeType = StatementAccessibility::None;
// Assemble a list of statements in text form we inherit from // Assemble a list of statements in text form we inherit from
@ -1432,7 +1434,7 @@ void CppParser::setInheritance(int index, const PStatement& classStatement, bool
} }
index++; index++;
lastInheritScopeType = inheritScopeType; lastInheritScopeType = inheritScopeType;
if (index >= mTokenizer.tokenCount()) if (index >= tokenCount)
break; break;
if (mTokenizer[index]->text.front() == '{' if (mTokenizer[index]->text.front() == '{'
|| mTokenizer[index]->text.front() == ';') || mTokenizer[index]->text.front() == ';')
@ -1680,13 +1682,19 @@ bool CppParser::checkForStructs(KeywordType keywordType)
|| keywordType == KeywordType::Public || keywordType == KeywordType::Public
|| keywordType == KeywordType::Private) { || keywordType == KeywordType::Private) {
dis = 1; dis = 1;
if (mIndex+dis>=mTokenizer.tokenCount()) {
mIndex++;
return false;
}
result = (mCppKeywords.value(mTokenizer[mIndex+dis]->text,KeywordType::None)==KeywordType::Struct); result = (mCppKeywords.value(mTokenizer[mIndex+dis]->text,KeywordType::None)==KeywordType::Struct);
} else { } else {
result = (keywordType==KeywordType::Struct); result = (keywordType==KeywordType::Struct);
} }
if (result) { if (result) {
if (mIndex >= mTokenizer.tokenCount() - 2 - dis) int tokenCount = mTokenizer.tokenCount();
if (mIndex >= tokenCount - 2 - dis)
return false; return false;
if (mTokenizer[mIndex + 2+dis]->text[0] != ';') { // not: class something; if (mTokenizer[mIndex + 2+dis]->text[0] != ';') { // not: class something;
int i = mIndex+dis +1; int i = mIndex+dis +1;
@ -1696,7 +1704,7 @@ bool CppParser::checkForStructs(KeywordType keywordType)
// {"info", 0, 0, 'i'}, // {"info", 0, 0, 'i'},
// ... // ...
// }; // };
while (i < mTokenizer.tokenCount()) { while (i < tokenCount) {
QChar ch = mTokenizer[i]->text.back(); QChar ch = mTokenizer[i]->text.back();
if (ch=='{' || ch == ':') if (ch=='{' || ch == ':')
break; break;
@ -1741,11 +1749,6 @@ bool CppParser::checkForTypedefStruct()
return false; return false;
return (mCppKeywords.value(mTokenizer[mIndex+1]->text,KeywordType::None)==KeywordType::Struct); return (mCppKeywords.value(mTokenizer[mIndex+1]->text,KeywordType::None)==KeywordType::Struct);
// QString word = mTokenizer[mIndex + 1]->text;
// int keyLen = calcKeyLenForStruct(word);
// if (keyLen<0)
// return false;
// return (word.length() == keyLen) || isSpaceChar(word[keyLen]) || word[keyLen]=='[';
} }
bool CppParser::checkForUsing(KeywordType keywordType) bool CppParser::checkForUsing(KeywordType keywordType)
@ -1755,7 +1758,9 @@ bool CppParser::checkForUsing(KeywordType keywordType)
void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType) void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
{ {
if (mIndex+2>=mTokenizer.tokenCount()) { int tokenCount = mTokenizer.tokenCount();
if (mIndex+2>=tokenCount) {
mIndex+=2; // let's finish; mIndex+=2; // let's finish;
return; return;
} }
@ -1781,7 +1786,7 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
//next token must be */&/word/(/{ //next token must be */&/word/(/{
if (mTokenizer[mIndex]->text=='(') { if (mTokenizer[mIndex]->text=='(') {
int indexAfterParentheis=mTokenizer[mIndex]->matchIndex+1; int indexAfterParentheis=mTokenizer[mIndex]->matchIndex+1;
if (indexAfterParentheis>=mTokenizer.tokenCount()) { if (indexAfterParentheis>=tokenCount) {
//error //error
mIndex=indexAfterParentheis; mIndex=indexAfterParentheis;
} else if (mTokenizer[indexAfterParentheis]->text=='(') { } else if (mTokenizer[indexAfterParentheis]->text=='(') {
@ -1868,7 +1873,7 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
} }
// Gather data for the string parts // Gather data for the string parts
while (mIndex+1 < mTokenizer.tokenCount()) { while (mIndex+1 < tokenCount) {
if (mTokenizer[mIndex]->text=="operator") { if (mTokenizer[mIndex]->text=="operator") {
handleOperatorOverloading(sType, handleOperatorOverloading(sType,
//sName, //sName,
@ -1876,14 +1881,14 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
isStatic); isStatic);
return; return;
} else if (mTokenizer[mIndex + 1]->text == '(') { } else if (mTokenizer[mIndex + 1]->text == '(') {
if (mIndex+2<mTokenizer.tokenCount() && mTokenizer[mIndex+2]->text == '*') { if (mIndex+2<tokenCount && mTokenizer[mIndex+2]->text == '*') {
//foo(*blabla), it's a function pointer var //foo(*blabla), it's a function pointer var
handleVar(sType+" "+sName,isExtern,isStatic); handleVar(sType+" "+sName,isExtern,isStatic);
return; return;
} }
int indexAfter=mTokenizer[mIndex + 1]->matchIndex+1; int indexAfter=mTokenizer[mIndex + 1]->matchIndex+1;
if (indexAfter>=mTokenizer.tokenCount()) { if (indexAfter>=tokenCount) {
//error //error
mIndex=indexAfter; mIndex=indexAfter;
return; return;
@ -2176,20 +2181,18 @@ PStatement CppParser::getTypeDef(const PStatement& statement,
void CppParser::handleCatchBlock() void CppParser::handleCatchBlock()
{ {
int tokenCount = mTokenizer.tokenCount();
int startLine= mTokenizer[mIndex]->line; int startLine= mTokenizer[mIndex]->line;
mIndex++; // skip for/catch; mIndex++; // skip for/catch;
if (!((mIndex < mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text.startsWith('(')))) if (!((mIndex < tokenCount) && (mTokenizer[mIndex]->text.startsWith('('))))
return; return;
//skip params //skip params
int i2=mTokenizer[mIndex]->matchIndex+1; int i2=mTokenizer[mIndex]->matchIndex+1;
if (i2>=mTokenizer.tokenCount()) if (i2>=tokenCount)
return; return;
if (mTokenizer[i2]->text.startsWith('{')) { if (mTokenizer[i2]->text.startsWith('{')) {
mBlockBeginSkips.append(i2); mBlockBeginSkips.append(i2);
int i = indexOfMatchingBrace(i2); int i = indexOfMatchingBrace(i2);
// if (i==i2) {
// mBlockEndSkips.append(mTokenizer.tokenCount());
// } else {
mBlockEndSkips.append(i); mBlockEndSkips.append(i);
} else { } else {
int i=indexOfNextSemicolon(i2); int i=indexOfNextSemicolon(i2);
@ -2216,12 +2219,13 @@ void CppParser::handleCatchBlock()
void CppParser::handleEnum(bool isTypedef) void CppParser::handleEnum(bool isTypedef)
{ {
int tokenCount = mTokenizer.tokenCount();
QString enumName = ""; QString enumName = "";
bool isEnumClass = false; bool isEnumClass = false;
int startLine = mTokenizer[mIndex]->line; int startLine = mTokenizer[mIndex]->line;
mIndex++; //skip 'enum' mIndex++; //skip 'enum'
if (mIndex < mTokenizer.tokenCount() && mTokenizer[mIndex]->text == "class") { if (mIndex < tokenCount && mTokenizer[mIndex]->text == "class") {
//enum class //enum class
isEnumClass = true; isEnumClass = true;
mIndex++; //skip class mIndex++; //skip class
@ -2229,11 +2233,11 @@ void CppParser::handleEnum(bool isTypedef)
} }
bool isAdhocVar=false; bool isAdhocVar=false;
int endIndex=-1; int endIndex=-1;
if ((mIndex< mTokenizer.tokenCount()) && mTokenizer[mIndex]->text.startsWith('{')) { // enum {...} NAME if ((mIndex< tokenCount) && mTokenizer[mIndex]->text.startsWith('{')) { // enum {...} NAME
// Skip to the closing brace // Skip to the closing brace
int i = indexOfMatchingBrace(mIndex); int i = indexOfMatchingBrace(mIndex);
// Have we found the name? // Have we found the name?
if (i + 1 < mTokenizer.tokenCount()) { if (i + 1 < tokenCount) {
enumName = mTokenizer[i + 1]->text.trimmed(); enumName = mTokenizer[i + 1]->text.trimmed();
if (!isIdentifierOrPointer(enumName)) { if (!isIdentifierOrPointer(enumName)) {
//not a valid enum, skip to j //not a valid enum, skip to j
@ -2252,7 +2256,7 @@ void CppParser::handleEnum(bool isTypedef)
} }
} }
endIndex=i+1; endIndex=i+1;
} else if (mIndex+1< mTokenizer.tokenCount() && mTokenizer[mIndex+1]->text.startsWith('{')){ // enum NAME {...}; } else if (mIndex+1< tokenCount && mTokenizer[mIndex+1]->text.startsWith('{')){ // enum NAME {...};
enumName = mTokenizer[mIndex]->text; enumName = mTokenizer[mIndex]->text;
} else { } else {
// enum NAME blahblah // enum NAME blahblah
@ -2296,7 +2300,7 @@ void CppParser::handleEnum(bool isTypedef)
// Skip to the closing brace // Skip to the closing brace
int i = indexOfMatchingBrace(mIndex)+1; int i = indexOfMatchingBrace(mIndex)+1;
QString typeSuffix=""; QString typeSuffix="";
while (i<mTokenizer.tokenCount()) { while (i<tokenCount) {
QString name=mTokenizer[i]->text; QString name=mTokenizer[i]->text;
if (isIdentifierOrPointer(name)) { if (isIdentifierOrPointer(name)) {
QString suffix; QString suffix;
@ -2336,7 +2340,7 @@ void CppParser::handleEnum(bool isTypedef)
QString cmd; QString cmd;
QString args; QString args;
if (mTokenizer[mIndex]->text!='}') { if (mTokenizer[mIndex]->text!='}') {
while ((mIndex < mTokenizer.tokenCount()) && while ((mIndex < tokenCount) &&
mTokenizer[mIndex]->text!='}') { mTokenizer[mIndex]->text!='}') {
if (mTokenizer[mIndex]->text=="=") { if (mTokenizer[mIndex]->text=="=") {
mIndex=indexOfNextPeriodOrSemicolon(mIndex); mIndex=indexOfNextPeriodOrSemicolon(mIndex);
@ -2401,13 +2405,15 @@ void CppParser::handleEnum(bool isTypedef)
void CppParser::handleForBlock() void CppParser::handleForBlock()
{ {
int tokenCount = mTokenizer.tokenCount();
int startLine = mTokenizer[mIndex]->line; int startLine = mTokenizer[mIndex]->line;
mIndex++; // skip for/catch; mIndex++; // skip for/catch;
if (!(mIndex < mTokenizer.tokenCount())) if (mIndex >= tokenCount)
return; return;
int i=indexOfNextSemicolon(mIndex); int i=indexOfNextSemicolon(mIndex);
int i2 = i+1; //skip over ';' (tokenizer have change for(;;) to for(;) int i2 = i+1; //skip over ';' (tokenizer have change for(;;) to for(;)
if (i2>=mTokenizer.tokenCount()) if (i2>=tokenCount)
return; return;
if (mTokenizer[i2]->text.startsWith('{')) { if (mTokenizer[i2]->text.startsWith('{')) {
mBlockBeginSkips.append(i2); mBlockBeginSkips.append(i2);
@ -2540,7 +2546,7 @@ void CppParser::handleLambda(int index, int endIndex)
// as // as
// unsigned short bAppReturnCode,reserved,fBusy,fAck // unsigned short bAppReturnCode,reserved,fBusy,fAck
if (mTokenizer[i]->text.front() == ':') { if (mTokenizer[i]->text.front() == ':') {
while ( (i < mTokenizer.tokenCount()) while ( (i < bodyEnd)
&& !( && !(
mTokenizer[i]->text==',' mTokenizer[i]->text==','
|| mTokenizer[i]->text==';' || mTokenizer[i]->text==';'
@ -2578,7 +2584,7 @@ void CppParser::handleLambda(int index, int endIndex)
} else if (mTokenizer[i]->text=='(') { } else if (mTokenizer[i]->text=='(') {
i=mTokenizer[i]->matchIndex+1; i=mTokenizer[i]->matchIndex+1;
} else if (mTokenizer[i]->text.endsWith('=')) { } else if (mTokenizer[i]->text.endsWith('=')) {
i = skipAssignment(i, mTokenizer.tokenCount()); i = skipAssignment(i, bodyEnd);
} else if (mTokenizer[i]->text=='{') { } else if (mTokenizer[i]->text=='{') {
tempType=""; tempType="";
i=mTokenizer[i]->matchIndex+1; i=mTokenizer[i]->matchIndex+1;
@ -2599,9 +2605,11 @@ void CppParser::handleOperatorOverloading(const QString &sType,
int operatorTokenIndex, bool isStatic) int operatorTokenIndex, bool isStatic)
{ {
//operatorTokenIndex is the token index of "operator" //operatorTokenIndex is the token index of "operator"
int tokenCount = mTokenizer.tokenCount();
int index=operatorTokenIndex+1; int index=operatorTokenIndex+1;
QString op=""; QString op="";
if (index>=mTokenizer.tokenCount()) { if (index>=tokenCount) {
mIndex=index; mIndex=index;
return; return;
} }
@ -2612,7 +2620,7 @@ void CppParser::handleOperatorOverloading(const QString &sType,
|| mTokenizer[index]->text=="delete") { || mTokenizer[index]->text=="delete") {
op=mTokenizer[index]->text; op=mTokenizer[index]->text;
index++; index++;
if (index<mTokenizer.tokenCount() if (index<tokenCount
&& mTokenizer[index]->text=="[]") { && mTokenizer[index]->text=="[]") {
op+="[]"; op+="[]";
index++; index++;
@ -2624,10 +2632,10 @@ void CppParser::handleOperatorOverloading(const QString &sType,
&& mTokenizer[index]->text != "(") && mTokenizer[index]->text != "(")
index++; index++;
} }
while (index<mTokenizer.tokenCount() while (index<tokenCount
&& mTokenizer[index]->text == ")") && mTokenizer[index]->text == ")")
index++; index++;
if (index>=mTokenizer.tokenCount() if (index>=tokenCount
|| mTokenizer[index]->text!="(") { || mTokenizer[index]->text!="(") {
mIndex=index; mIndex=index;
return; return;
@ -2654,12 +2662,13 @@ void CppParser::handleOperatorOverloading(const QString &sType,
void CppParser::handleMethod(StatementKind functionKind,const QString &sType, const QString &sName, int argStart, bool isStatic, bool isFriend,bool isOperatorOverload) void CppParser::handleMethod(StatementKind functionKind,const QString &sType, const QString &sName, int argStart, bool isStatic, bool isFriend,bool isOperatorOverload)
{ {
int tokenCount = mTokenizer.tokenCount();
bool isValid = true; bool isValid = true;
bool isDeclaration = false; // assume it's not a prototype bool isDeclaration = false; // assume it's not a prototype
int startLine = mTokenizer[mIndex]->line; int startLine = mTokenizer[mIndex]->line;
int argEnd = mTokenizer[argStart]->matchIndex; int argEnd = mTokenizer[argStart]->matchIndex;
if (mIndex >= mTokenizer.tokenCount()) // not finished define, just skip it; if (mIndex >= tokenCount) // not finished define, just skip it;
return; return;
PStatement scopeStatement = getCurrentScope(); PStatement scopeStatement = getCurrentScope();
@ -2667,7 +2676,7 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
//find start of the function body; //find start of the function body;
bool foundColon=false; bool foundColon=false;
mIndex=argEnd+1; mIndex=argEnd+1;
while ((mIndex < mTokenizer.tokenCount()) && !isblockChar(mTokenizer[mIndex]->text.front())) { while ((mIndex < tokenCount) && !isblockChar(mTokenizer[mIndex]->text.front())) {
if (mTokenizer[mIndex]->text=='(') { if (mTokenizer[mIndex]->text=='(') {
mIndex=mTokenizer[mIndex]->matchIndex+1; mIndex=mTokenizer[mIndex]->matchIndex+1;
}else if (mTokenizer[mIndex]->text==':') { }else if (mTokenizer[mIndex]->text==':') {
@ -2678,7 +2687,7 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
} }
if (foundColon) { if (foundColon) {
mIndex++; mIndex++;
while ((mIndex < mTokenizer.tokenCount()) && !isblockChar(mTokenizer[mIndex]->text.front())) { while ((mIndex < tokenCount) && !isblockChar(mTokenizer[mIndex]->text.front())) {
if (isWordChar(mTokenizer[mIndex]->text[0]) if (isWordChar(mTokenizer[mIndex]->text[0])
&& mIndex+1<mTokenizer.tokenCount() && mIndex+1<mTokenizer.tokenCount()
&& mTokenizer[mIndex+1]->text=='{') { && mTokenizer[mIndex+1]->text=='{') {
@ -2691,7 +2700,7 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
} }
} }
if (mIndex>=mTokenizer.tokenCount()) if (mIndex>=tokenCount)
return; return;
// Check if this is a prototype // Check if this is a prototype
@ -2802,10 +2811,10 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
} }
if ((mIndex < mTokenizer.tokenCount()) && mTokenizer[mIndex]->text.startsWith('{')) { if ((mIndex < tokenCount) && mTokenizer[mIndex]->text.startsWith('{')) {
addSoloScopeLevel(functionStatement,startLine); addSoloScopeLevel(functionStatement,startLine);
mIndex++; //skip '{' mIndex++; //skip '{'
} else if ((mIndex < mTokenizer.tokenCount()) && mTokenizer[mIndex]->text.startsWith(';')) { } else if ((mIndex < tokenCount) && mTokenizer[mIndex]->text.startsWith(';')) {
addSoloScopeLevel(functionStatement,startLine); addSoloScopeLevel(functionStatement,startLine);
if (mTokenizer[mIndex]->line != startLine) if (mTokenizer[mIndex]->line != startLine)
removeScopeLevel(mTokenizer[mIndex]->line+1); removeScopeLevel(mTokenizer[mIndex]->line+1);
@ -2817,6 +2826,7 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
void CppParser::handleNamespace(KeywordType skipType) void CppParser::handleNamespace(KeywordType skipType)
{ {
int tokenCount = mTokenizer.tokenCount();
bool isInline=false; bool isInline=false;
int startLine = mTokenizer[mIndex]->line; int startLine = mTokenizer[mIndex]->line;
@ -2841,10 +2851,10 @@ void CppParser::handleNamespace(KeywordType skipType)
// if (command.startsWith("__")) // hack for inline namespaces // if (command.startsWith("__")) // hack for inline namespaces
// isInline = true; // isInline = true;
mIndex++; mIndex++;
if (mIndex>=mTokenizer.tokenCount()) if (mIndex>=tokenCount)
return; return;
QString aliasName; QString aliasName;
if ((mIndex+2<mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text == '=')) { if ((mIndex+2<tokenCount) && (mTokenizer[mIndex]->text == '=')) {
aliasName=mTokenizer[mIndex+1]->text; aliasName=mTokenizer[mIndex+1]->text;
//namespace alias //namespace alias
addStatement( addStatement(
@ -2866,14 +2876,14 @@ void CppParser::handleNamespace(KeywordType skipType)
} else if (isInline) { } else if (isInline) {
//inline namespace , just skip it //inline namespace , just skip it
// Skip to '{' // Skip to '{'
while ((mIndex<mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text != '{')) while ((mIndex<tokenCount) && (mTokenizer[mIndex]->text != '{'))
mIndex++; mIndex++;
int i =indexOfMatchingBrace(mIndex); //skip '}' int i =indexOfMatchingBrace(mIndex); //skip '}'
if (i==mIndex) if (i==mIndex)
mInlineNamespaceEndSkips.append(mTokenizer.tokenCount()); mInlineNamespaceEndSkips.append(tokenCount);
else else
mInlineNamespaceEndSkips.append(i); mInlineNamespaceEndSkips.append(i);
if (mIndex<mTokenizer.tokenCount()) if (mIndex<tokenCount)
mIndex++; //skip '{' mIndex++; //skip '{'
} else { } else {
PStatement namespaceStatement = addStatement( PStatement namespaceStatement = addStatement(
@ -2892,7 +2902,7 @@ void CppParser::handleNamespace(KeywordType skipType)
// find next '{' or ';' // find next '{' or ';'
mIndex = indexOfNextSemicolonOrLeftBrace(mIndex); mIndex = indexOfNextSemicolonOrLeftBrace(mIndex);
if (mIndex<mTokenizer.tokenCount() && mTokenizer[mIndex]->text=='{') if (mIndex<tokenCount && mTokenizer[mIndex]->text=='{')
addSoloScopeLevel(namespaceStatement,startLine); addSoloScopeLevel(namespaceStatement,startLine);
//skip it //skip it
mIndex++; mIndex++;
@ -2901,11 +2911,12 @@ void CppParser::handleNamespace(KeywordType skipType)
void CppParser::handleOtherTypedefs() void CppParser::handleOtherTypedefs()
{ {
int tokenCount = mTokenizer.tokenCount();
int startLine = mTokenizer[mIndex]->line; int startLine = mTokenizer[mIndex]->line;
// Skip typedef word // Skip typedef word
mIndex++; mIndex++;
if (mIndex>=mTokenizer.tokenCount()) if (mIndex>=tokenCount)
return; return;
if (mTokenizer[mIndex]->text == '(' if (mTokenizer[mIndex]->text == '('
@ -2915,7 +2926,7 @@ void CppParser::handleOtherTypedefs()
mIndex=indexOfNextSemicolon(mIndex)+1; mIndex=indexOfNextSemicolon(mIndex)+1;
return; return;
} }
if ((mIndex+1<mTokenizer.tokenCount()) if ((mIndex+1<tokenCount)
&& (mTokenizer[mIndex+1]->text == ';')) { && (mTokenizer[mIndex+1]->text == ';')) {
//no old type, not valid //no old type, not valid
mIndex+=2; //skip ; mIndex+=2; //skip ;
@ -2932,7 +2943,7 @@ void CppParser::handleOtherTypedefs()
else else
oldType += ' ' + mTokenizer[mIndex]->text; oldType += ' ' + mTokenizer[mIndex]->text;
mIndex++; mIndex++;
if (mIndex+1>=mTokenizer.tokenCount()) { if (mIndex+1>=tokenCount) {
//not valid, just exit //not valid, just exit
return; return;
} }
@ -2952,14 +2963,14 @@ void CppParser::handleOtherTypedefs()
return; return;
} }
QString newType; QString newType;
while(mIndex+1<mTokenizer.tokenCount()) { while(mIndex+1<tokenCount) {
if (mTokenizer[mIndex]->text == ',' ) { if (mTokenizer[mIndex]->text == ',' ) {
mIndex++; mIndex++;
} else if (mTokenizer[mIndex]->text == ';' ) { } else if (mTokenizer[mIndex]->text == ';' ) {
break; break;
} else if (mTokenizer[mIndex]->text == '(') { } else if (mTokenizer[mIndex]->text == '(') {
int paramStart=mTokenizer[mIndex]->matchIndex+1; int paramStart=mTokenizer[mIndex]->matchIndex+1;
if (paramStart>=mTokenizer.tokenCount() if (paramStart>=tokenCount
|| mTokenizer[paramStart]->text!='(') { || mTokenizer[paramStart]->text!='(') {
//not valid function pointer (no args) //not valid function pointer (no args)
//skip over next ; //skip over next ;
@ -3111,18 +3122,19 @@ bool CppParser::handleStatement()
Q_ASSERT(mIndex>=mLastIndex); Q_ASSERT(mIndex>=mLastIndex);
mLastIndex=mIndex; mLastIndex=mIndex;
#endif #endif
int tokenCount = mTokenizer.tokenCount();
if (mIndex >= idx2) { if (mIndex >= idx2) {
//skip (previous handled) block begin //skip (previous handled) block begin
mBlockBeginSkips.pop_back(); mBlockBeginSkips.pop_back();
if (mIndex == idx2) if (mIndex == idx2)
mIndex++; mIndex++;
else if (mIndex<mTokenizer.tokenCount()) //error happens, but we must remove an (error) added scope else if (mIndex<tokenCount) //error happens, but we must remove an (error) added scope
removeScopeLevel(mTokenizer[mIndex]->line); removeScopeLevel(mTokenizer[mIndex]->line);
} else if (mIndex >= idx) { } else if (mIndex >= idx) {
//skip (previous handled) block end //skip (previous handled) block end
mBlockEndSkips.pop_back(); mBlockEndSkips.pop_back();
if (idx+1 < mTokenizer.tokenCount()) if (idx+1 < tokenCount)
removeScopeLevel(mTokenizer[idx+1]->line); removeScopeLevel(mTokenizer[idx+1]->line);
if (mIndex == idx) if (mIndex == idx)
mIndex++; mIndex++;
@ -3156,7 +3168,7 @@ bool CppParser::handleStatement()
// } else if (checkForLambda()) { // is lambda // } else if (checkForLambda()) { // is lambda
// handleLambda(); // handleLambda();
} else if (mTokenizer[mIndex]->text=='(') { } else if (mTokenizer[mIndex]->text=='(') {
if (mIndex+1<mTokenizer.tokenCount() && if (mIndex+1<tokenCount &&
mTokenizer[mIndex+1]->text=="operator") { mTokenizer[mIndex+1]->text=="operator") {
// things like (operator int) // things like (operator int)
mIndex++; //just skip '(' mIndex++; //just skip '('
@ -3166,7 +3178,7 @@ bool CppParser::handleStatement()
mIndex++; mIndex++;
} else if (mTokenizer[mIndex]->text.startsWith('~')) { } else if (mTokenizer[mIndex]->text.startsWith('~')) {
//it should be a destructor //it should be a destructor
if (mIndex+1<mTokenizer.tokenCount() if (mIndex+1<tokenCount
&& mTokenizer[mIndex+1]->text=='(') { && mTokenizer[mIndex+1]->text=='(') {
//dont further check to speed up //dont further check to speed up
handleMethod(StatementKind::skDestructor, "", '~'+mTokenizer[mIndex]->text, mIndex+1, false, false); handleMethod(StatementKind::skDestructor, "", '~'+mTokenizer[mIndex]->text, mIndex+1, false, false);
@ -3189,7 +3201,7 @@ bool CppParser::handleStatement()
} else if (keywordType==KeywordType::Enum) { } else if (keywordType==KeywordType::Enum) {
handleEnum(false); handleEnum(false);
} else if (keywordType==KeywordType::Typedef) { } else if (keywordType==KeywordType::Typedef) {
if (mIndex+1 < mTokenizer.tokenCount()) { if (mIndex+1 < tokenCount) {
if (checkForTypedefStruct()) { // typedef struct something if (checkForTypedefStruct()) { // typedef struct something
mIndex++; // skip 'typedef' mIndex++; // skip 'typedef'
handleStructs(true); handleStructs(true);
@ -3228,7 +3240,7 @@ bool CppParser::handleStatement()
//todo: remove mSkipList (we can check '}''s statement type instead) //todo: remove mSkipList (we can check '}''s statement type instead)
// checkForSkipStatement(); // checkForSkipStatement();
return mIndex < mTokenizer.tokenCount(); return mIndex < tokenCount;
} }
@ -3244,15 +3256,16 @@ void CppParser::handleStructs(bool isTypedef)
prefix = mTokenizer[mIndex]->text; prefix = mTokenizer[mIndex]->text;
bool isStruct = ("class" != prefix); //struct/union bool isStruct = ("class" != prefix); //struct/union
int startLine = mTokenizer[mIndex]->line; int startLine = mTokenizer[mIndex]->line;
int tokenCount = mTokenizer.tokenCount();
mIndex++; //skip struct/class/union mIndex++; //skip struct/class/union
if (mIndex>=mTokenizer.tokenCount()) if (mIndex>=tokenCount)
return; return;
// Do not modifiy index // Do not modifiy index
int i=indexOfNextSemicolonOrLeftBrace(mIndex); int i=indexOfNextSemicolonOrLeftBrace(mIndex);
if (i >= mTokenizer.tokenCount()) { if (i >= tokenCount) {
//error //error
mIndex=i; mIndex=i;
return; return;
@ -3264,7 +3277,7 @@ void CppParser::handleStructs(bool isTypedef)
QString oldType = mTokenizer[mIndex]->text; QString oldType = mTokenizer[mIndex]->text;
while(true) { while(true) {
// Add definition statement for the synonym // Add definition statement for the synonym
if ((mIndex + 1 < mTokenizer.tokenCount()) if ((mIndex + 1 < tokenCount)
&& (mTokenizer[mIndex + 1]->text=="," && (mTokenizer[mIndex + 1]->text==","
|| mTokenizer[mIndex + 1]->text==";")) { || mTokenizer[mIndex + 1]->text==";")) {
QString newType = mTokenizer[mIndex]->text; QString newType = mTokenizer[mIndex]->text;
@ -3283,7 +3296,7 @@ void CppParser::handleStructs(bool isTypedef)
StatementProperty::spHasDefinition); StatementProperty::spHasDefinition);
} }
mIndex++; mIndex++;
if (mIndex >= mTokenizer.tokenCount()) if (mIndex >= tokenCount)
break; break;
if (mTokenizer[mIndex]->text.front() == ';') if (mTokenizer[mIndex]->text.front() == ';')
break; break;
@ -3306,12 +3319,12 @@ void CppParser::handleStructs(bool isTypedef)
PStatement firstSynonym; PStatement firstSynonym;
// Add class/struct name BEFORE opening brace // Add class/struct name BEFORE opening brace
if (mTokenizer[mIndex]->text != "{") { if (mTokenizer[mIndex]->text != "{") {
while(mIndex < mTokenizer.tokenCount()) { while(mIndex < tokenCount) {
if (mTokenizer[mIndex]->text == ":" if (mTokenizer[mIndex]->text == ":"
|| mTokenizer[mIndex]->text == "{" || mTokenizer[mIndex]->text == "{"
|| mTokenizer[mIndex]->text == ";") { || mTokenizer[mIndex]->text == ";") {
break; break;
} else if ((mIndex + 1 < mTokenizer.tokenCount()) } else if ((mIndex + 1 < tokenCount)
&& (mTokenizer[mIndex + 1]->text == "," && (mTokenizer[mIndex + 1]->text == ","
|| mTokenizer[mIndex + 1]->text == ";" || mTokenizer[mIndex + 1]->text == ";"
|| mTokenizer[mIndex + 1]->text == "{" || mTokenizer[mIndex + 1]->text == "{"
@ -3345,7 +3358,7 @@ void CppParser::handleStructs(bool isTypedef)
} }
mIndex++; mIndex++;
break; break;
} else if ((mIndex + 2 < mTokenizer.tokenCount()) } else if ((mIndex + 2 < tokenCount)
&& (mTokenizer[mIndex + 1]->text == "final") && (mTokenizer[mIndex + 1]->text == "final")
&& (mTokenizer[mIndex + 2]->text=="," && (mTokenizer[mIndex + 2]->text==","
|| mTokenizer[mIndex + 2]->text==":" || mTokenizer[mIndex + 2]->text==":"
@ -3376,7 +3389,7 @@ void CppParser::handleStructs(bool isTypedef)
} }
// Walk to opening brace if we encountered inheritance statements // Walk to opening brace if we encountered inheritance statements
if ((mIndex < mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text == ":")) { if ((mIndex < tokenCount) && (mTokenizer[mIndex]->text == ":")) {
if (firstSynonym) if (firstSynonym)
setInheritance(mIndex, firstSynonym, isStruct); // set the _InheritanceList value setInheritance(mIndex, firstSynonym, isStruct); // set the _InheritanceList value
mIndex=indexOfNextLeftBrace(mIndex); mIndex=indexOfNextLeftBrace(mIndex);
@ -3388,7 +3401,7 @@ void CppParser::handleStructs(bool isTypedef)
// Walk to closing brace // Walk to closing brace
i = indexOfMatchingBrace(mIndex); // step onto closing brace i = indexOfMatchingBrace(mIndex); // step onto closing brace
if ((i + 1 < mTokenizer.tokenCount()) && !( if ((i + 1 < tokenCount) && !(
mTokenizer[i + 1]->text.front() == ';' mTokenizer[i + 1]->text.front() == ';'
|| mTokenizer[i + 1]->text.front() == '}')) { || mTokenizer[i + 1]->text.front() == '}')) {
// When encountering names again after struct body scanning, skip it // When encountering names again after struct body scanning, skip it
@ -3470,7 +3483,7 @@ void CppParser::handleStructs(bool isTypedef)
} }
command = ""; command = "";
} }
if (i >= mTokenizer.tokenCount() - 1) if (i >= tokenCount - 1)
break; break;
if (mTokenizer[i]->text=='{' if (mTokenizer[i]->text=='{'
|| mTokenizer[i]->text== ';') || mTokenizer[i]->text== ';')
@ -3484,7 +3497,7 @@ void CppParser::handleStructs(bool isTypedef)
if (!firstSynonym) { if (!firstSynonym) {
PStatement scope = getCurrentScope(); PStatement scope = getCurrentScope();
if (scope && scope->kind == StatementKind::skClass if (scope && scope->kind == StatementKind::skClass
&& mIndex<mTokenizer.tokenCount() && mTokenizer[mIndex]->text=="{") { && mIndex<tokenCount && mTokenizer[mIndex]->text=="{") {
//C11 anonymous union/struct //C11 anonymous union/struct
addSoloScopeLevel(scope, mTokenizer[mIndex]->line); addSoloScopeLevel(scope, mTokenizer[mIndex]->line);
//skip { //skip {
@ -3507,13 +3520,13 @@ void CppParser::handleStructs(bool isTypedef)
StatementProperty::spHasDefinition); StatementProperty::spHasDefinition);
} }
} }
if (mIndex < mTokenizer.tokenCount()) if (mIndex < tokenCount)
addSoloScopeLevel(firstSynonym,mTokenizer[mIndex]->line); addSoloScopeLevel(firstSynonym,mTokenizer[mIndex]->line);
else else
addSoloScopeLevel(firstSynonym,startLine); addSoloScopeLevel(firstSynonym,startLine);
// Step over { // Step over {
if ((mIndex < mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text == "{")) if ((mIndex < tokenCount) && (mTokenizer[mIndex]->text == "{"))
mIndex++; mIndex++;
} }
} }
@ -3526,16 +3539,17 @@ void CppParser::handleUsing()
mIndex=indexOfNextSemicolon(mIndex)+1; mIndex=indexOfNextSemicolon(mIndex)+1;
return; return;
} }
int tokenCount = mTokenizer.tokenCount();
mIndex++; //skip 'using' mIndex++; //skip 'using'
//handle things like 'using vec = std::vector; ' //handle things like 'using vec = std::vector; '
if (mIndex+1 < mTokenizer.tokenCount() if (mIndex+1 < tokenCount
&& mTokenizer[mIndex+1]->text == "=") { && mTokenizer[mIndex+1]->text == "=") {
QString fullName = mTokenizer[mIndex]->text; QString fullName = mTokenizer[mIndex]->text;
QString aliasName; QString aliasName;
mIndex+=2; mIndex+=2;
while (mIndex<mTokenizer.tokenCount() && while (mIndex<tokenCount &&
mTokenizer[mIndex]->text!=';') { mTokenizer[mIndex]->text!=';') {
aliasName += mTokenizer[mIndex]->text; aliasName += mTokenizer[mIndex]->text;
mIndex++; mIndex++;
@ -3558,11 +3572,11 @@ void CppParser::handleUsing()
return; return;
} }
//handle things like 'using std::vector;' //handle things like 'using std::vector;'
if ((mIndex+2>=mTokenizer.tokenCount()) if ((mIndex+2>=tokenCount)
|| (mTokenizer[mIndex]->text != "namespace")) { || (mTokenizer[mIndex]->text != "namespace")) {
QString fullName; QString fullName;
QString usingName; QString usingName;
while (mIndex<mTokenizer.tokenCount() && while (mIndex<tokenCount &&
mTokenizer[mIndex]->text!=';') { mTokenizer[mIndex]->text!=';') {
fullName += mTokenizer[mIndex]->text; fullName += mTokenizer[mIndex]->text;
usingName = mTokenizer[mIndex]->text; usingName = mTokenizer[mIndex]->text;
@ -3591,7 +3605,7 @@ void CppParser::handleUsing()
PStatement scopeStatement = getCurrentScope(); PStatement scopeStatement = getCurrentScope();
QString usingName; QString usingName;
while (mIndex<mTokenizer.tokenCount() && while (mIndex<tokenCount &&
mTokenizer[mIndex]->text!=';') { mTokenizer[mIndex]->text!=';') {
usingName += mTokenizer[mIndex]->text; usingName += mTokenizer[mIndex]->text;
mIndex++; mIndex++;
@ -3631,7 +3645,9 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
PStatement addedVar; PStatement addedVar;
QString tempType; QString tempType;
while(mIndex<mTokenizer.tokenCount()) { int tokenCount = mTokenizer.tokenCount();
while(mIndex<tokenCount) {
switch(mTokenizer[mIndex]->text[0].unicode()) { switch(mTokenizer[mIndex]->text[0].unicode()) {
case ':': case ':':
if (mTokenizer[mIndex]->text.length()>1) { if (mTokenizer[mIndex]->text.length()>1) {
@ -3645,7 +3661,7 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
// unsigned short bAppReturnCode:8,reserved:6,fBusy:1,fAck:1 // unsigned short bAppReturnCode:8,reserved:6,fBusy:1,fAck:1
// as // as
// unsigned short bAppReturnCode,reserved,fBusy,fAck // unsigned short bAppReturnCode,reserved,fBusy,fAck
if (mIndex+1<mTokenizer.tokenCount() if (mIndex+1<tokenCount
&& isIdentifier(mTokenizer[mIndex+1]->text) && isIdentifier(mTokenizer[mIndex+1]->text)
&& isIdentChar(mTokenizer[mIndex+1]->text.back()) && isIdentChar(mTokenizer[mIndex+1]->text.back())
&& addedVar && addedVar
@ -3674,7 +3690,7 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
} }
addedVar.reset(); addedVar.reset();
bool should_exit=false; bool should_exit=false;
while (mIndex < mTokenizer.tokenCount()) { while (mIndex < tokenCount) {
switch(mTokenizer[mIndex]->text[0].unicode()) { switch(mTokenizer[mIndex]->text[0].unicode()) {
case ',': case ',':
case ';': case ';':
@ -3699,7 +3715,7 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
mIndex++; mIndex++;
return; return;
case '=': case '=':
if (mIndex+1<mTokenizer.tokenCount() if (mIndex+1<tokenCount
&& isIdentifier(mTokenizer[mIndex+1]->text) && isIdentifier(mTokenizer[mIndex+1]->text)
&& addedVar && addedVar
&& !(addedVar->properties & StatementProperty::spFunctionPointer) && !(addedVar->properties & StatementProperty::spFunctionPointer)
@ -3707,7 +3723,7 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
//handle e.g.: auto x=blahblah; //handle e.g.: auto x=blahblah;
int pos = 0; int pos = 0;
int endIndex = skipAssignment(mIndex, mTokenizer.tokenCount()); int endIndex = skipAssignment(mIndex, tokenCount);
QStringList phraseExpression; QStringList phraseExpression;
for (int i=mIndex+1;i<endIndex;i++) { for (int i=mIndex+1;i<endIndex;i++) {
QString cmd = mTokenizer[i]->text; QString cmd = mTokenizer[i]->text;
@ -3753,7 +3769,7 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
} }
mIndex = endIndex; mIndex = endIndex;
} else } else
mIndex = skipAssignment(mIndex, mTokenizer.tokenCount()); mIndex = skipAssignment(mIndex, tokenCount);
addedVar.reset(); addedVar.reset();
break; break;
case '*': case '*':
@ -3762,7 +3778,7 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
mIndex++; mIndex++;
break; break;
case '(': case '(':
if (mTokenizer[mIndex]->matchIndex+1<mTokenizer.tokenCount() if (mTokenizer[mIndex]->matchIndex+1<tokenCount
&& mTokenizer[mTokenizer[mIndex]->matchIndex+1]->text=='(') { && mTokenizer[mTokenizer[mIndex]->matchIndex+1]->text=='(') {
//function pointer //function pointer
QString cmd = findFunctionPointerName(mIndex); QString cmd = findFunctionPointerName(mIndex);
@ -3801,7 +3817,7 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
//not function pointer, fall through //not function pointer, fall through
case '{': case '{':
tempType=""; tempType="";
if (mIndex+1<mTokenizer.tokenCount() if (mIndex+1<tokenCount
&& isIdentifier(mTokenizer[mIndex+1]->text) && isIdentifier(mTokenizer[mIndex+1]->text)
&& addedVar && addedVar
&& !(addedVar->properties & StatementProperty::spFunctionPointer) && !(addedVar->properties & StatementProperty::spFunctionPointer)
@ -5362,10 +5378,11 @@ QString CppParser::splitPhrase(const QString &phrase, QString &sClazz,
sOperator=""; sOperator="";
QString result=""; QString result="";
int bracketLevel = 0; int bracketLevel = 0;
int phraseLength = phrase.length();
// Obtain stuff before first operator // Obtain stuff before first operator
int firstOpStart = phrase.length() + 1; int firstOpStart = phraseLength + 1;
int firstOpEnd = phrase.length() + 1; int firstOpEnd = phraseLength + 1;
for (int i = 0; i<phrase.length();i++) { for (int i = 0; i<phraseLength;i++) {
if ((i+1<phrase.length()) && (phrase[i] == '-') && (phrase[i + 1] == '>') && (bracketLevel==0)) { if ((i+1<phrase.length()) && (phrase[i] == '-') && (phrase[i + 1] == '>') && (bracketLevel==0)) {
firstOpStart = i; firstOpStart = i;
firstOpEnd = i+2; firstOpEnd = i+2;
@ -5398,11 +5415,11 @@ QString CppParser::splitPhrase(const QString &phrase, QString &sClazz,
// ... and before second op, if there is one // ... and before second op, if there is one
int secondOp = 0; int secondOp = 0;
bracketLevel = 0; bracketLevel = 0;
for (int i = firstOpEnd; i<phrase.length();i++) { for (int i = firstOpEnd; i<phraseLength;i++) {
if ((i+1<phrase.length()) && (phrase[i] == '-') && (phrase[i + 1] == '>') && (bracketLevel=0)) { if ((i+1<phraseLength) && (phrase[i] == '-') && (phrase[i + 1] == '>') && (bracketLevel=0)) {
secondOp = i; secondOp = i;
break; break;
} else if ((i+1<phrase.length()) && (phrase[i] == ':') && (phrase[i + 1] == ':') && (bracketLevel=0)) { } else if ((i+1<phraseLength) && (phrase[i] == ':') && (phrase[i + 1] == ':') && (bracketLevel=0)) {
secondOp = i; secondOp = i;
break; break;
} else if ((phrase[i] == '.') && (bracketLevel=0)) { } else if ((phrase[i] == '.') && (bracketLevel=0)) {
@ -5614,7 +5631,8 @@ int CppParser::indexOfNextPeriodOrSemicolon(int index, int endIndex)
int CppParser::indexOfNextSemicolonOrLeftBrace(int index) int CppParser::indexOfNextSemicolonOrLeftBrace(int index)
{ {
while (index<mTokenizer.tokenCount()) { int tokenCount = mTokenizer.tokenCount();
while (index<tokenCount) {
switch(mTokenizer[index]->text[0].unicode()) { switch(mTokenizer[index]->text[0].unicode()) {
case ';': case ';':
case '{': case '{':
@ -5631,7 +5649,8 @@ int CppParser::indexOfNextSemicolonOrLeftBrace(int index)
int CppParser::indexOfNextColon(int index) int CppParser::indexOfNextColon(int index)
{ {
while (index<mTokenizer.tokenCount()) { int tokenCount = mTokenizer.tokenCount();
while (index<tokenCount) {
QString s =mTokenizer[index]->text; QString s =mTokenizer[index]->text;
switch(s[0].unicode()) { switch(s[0].unicode()) {
case ':': case ':':
@ -5652,7 +5671,8 @@ int CppParser::indexOfNextColon(int index)
int CppParser::indexOfNextLeftBrace(int index) int CppParser::indexOfNextLeftBrace(int index)
{ {
while (index<mTokenizer.tokenCount()) { int tokenCount = mTokenizer.tokenCount();
while (index<tokenCount) {
switch(mTokenizer[index]->text[0].unicode()) { switch(mTokenizer[index]->text[0].unicode()) {
case '{': case '{':
return index; return index;
@ -5668,7 +5688,8 @@ int CppParser::indexOfNextLeftBrace(int index)
int CppParser::indexPassParenthesis(int index) int CppParser::indexPassParenthesis(int index)
{ {
while (index<mTokenizer.tokenCount()) { int tokenCount = mTokenizer.tokenCount();
while (index<tokenCount) {
if (mTokenizer[index]->text=='(') { if (mTokenizer[index]->text=='(') {
return mTokenizer[index]->matchIndex+1; return mTokenizer[index]->matchIndex+1;
} }
@ -5679,7 +5700,8 @@ int CppParser::indexPassParenthesis(int index)
int CppParser::indexPassBraces(int index) int CppParser::indexPassBraces(int index)
{ {
while (index<mTokenizer.tokenCount()) { int tokenCount = mTokenizer.tokenCount();
while (tokenCount) {
switch(mTokenizer[index]->text[0].unicode()) { switch(mTokenizer[index]->text[0].unicode()) {
case '{': case '{':
return mTokenizer[index]->matchIndex+1; return mTokenizer[index]->matchIndex+1;
@ -5695,8 +5717,9 @@ int CppParser::indexPassBraces(int index)
void CppParser::skipNextSemicolon(int index) void CppParser::skipNextSemicolon(int index)
{ {
int tokenCount = mTokenizer.tokenCount();
mIndex=index; mIndex=index;
while (mIndex<mTokenizer.tokenCount()) { while (mIndex<tokenCount) {
switch(mTokenizer[mIndex]->text[0].unicode()) { switch(mTokenizer[mIndex]->text[0].unicode()) {
case ';': case ';':
mIndex++; mIndex++;
@ -5713,42 +5736,6 @@ void CppParser::skipNextSemicolon(int index)
} }
} }
//int CppParser::moveToEndOfStatement(int index, bool checkLambda, int endIndex)
//{
// int startIndex=index;
// if (endIndex<0)
// endIndex=mTokenizer.tokenCount();
// bool stop=false;
// while (index<endIndex && !stop) {
// switch(mTokenizer[index]->text[0].unicode()) {
// case ';':
// index++;
// stop=true;
// break;
// case '{':
// //skip '}'
// index = mTokenizer[index]->matchIndex+1;
// stop = true;
// break;
// case '(':
// index = mTokenizer[index]->matchIndex+1;
// break;
// default:
// index++;
// }
// }
// if (stop && checkLambda) {
// while (mTokenizer.lambdasCount()>0 && mTokenizer.indexOfFirstLambda()<index) {
// int i=mTokenizer.indexOfFirstLambda();
// mTokenizer.removeFirstLambda();
// if (i>=startIndex) {
// handleLambda(i,index);
// }
// }
// }
// return index;
//}
int CppParser::moveToEndOfStatement(int index, bool checkLambda, int endIndex) int CppParser::moveToEndOfStatement(int index, bool checkLambda, int endIndex)
{ {
int startIndex=index; int startIndex=index;
@ -5803,8 +5790,9 @@ int CppParser::moveToEndOfStatement(int index, bool checkLambda, int endIndex)
void CppParser::skipParenthesis(int index) void CppParser::skipParenthesis(int index)
{ {
int tokenCount = mTokenizer.tokenCount();
mIndex=index; mIndex=index;
while (mIndex<mTokenizer.tokenCount()) { while (mIndex<tokenCount) {
if (mTokenizer[mIndex]->text=='(') { if (mTokenizer[mIndex]->text=='(') {
mIndex=mTokenizer[mIndex]->matchIndex+1; mIndex=mTokenizer[mIndex]->matchIndex+1;
return; return;
@ -5854,7 +5842,7 @@ QString CppParser::mergeArgs(int startIndex, int endIndex)
return result; return result;
} }
void CppParser::parseCommandTypeAndArgs(QString &command, QString &typeSuffix, QString &args) void CppParser::parseCommandTypeAndArgs(QString &command, QString &typeSuffix, QString &args) const
{ {
int prefix=0; int prefix=0;
while (prefix<command.length() && (command[prefix]=='*' || command[prefix]=='&')) { while (prefix<command.length() && (command[prefix]=='*' || command[prefix]=='&')) {

View File

@ -652,7 +652,7 @@ private:
QString mergeArgs(int startIndex, int endIndex); QString mergeArgs(int startIndex, int endIndex);
void parseCommandTypeAndArgs(QString& command, void parseCommandTypeAndArgs(QString& command,
QString& typeSuffix, QString& typeSuffix,
QString& args); QString& args) const;
private: private:
int mParserId; int mParserId;
ParserLanguage mLanguage; ParserLanguage mLanguage;