- fix: function pointers not correctly handle in code parser;
- fix: var assignment not correctly handled in code parser; - fix: function args not correctly handled in code parser;
This commit is contained in:
parent
faf25f4f1d
commit
bcc1b8dc09
3
NEWS.md
3
NEWS.md
|
@ -10,6 +10,9 @@ Red Panda C++ Version 2.4
|
||||||
- enhancement: Rename filenames in bookmarks/breakpoints after a file is save-ased.
|
- enhancement: Rename filenames in bookmarks/breakpoints after a file is save-ased.
|
||||||
- fix: Can't goto definition of classes and namespaces displayed in the class browser on whole project mode.
|
- fix: Can't goto definition of classes and namespaces displayed in the class browser on whole project mode.
|
||||||
- fix: macro defines parsed before not correctly applied in the succeeding parse.
|
- fix: macro defines parsed before not correctly applied in the succeeding parse.
|
||||||
|
- fix: function pointers not correctly handle in code parser;
|
||||||
|
- fix: var assignment not correctly handled in code parser;
|
||||||
|
- fix: function args not correctly handled in code parser;
|
||||||
|
|
||||||
Red Panda C++ Version 2.3
|
Red Panda C++ Version 2.3
|
||||||
|
|
||||||
|
|
|
@ -1293,7 +1293,7 @@ PStatement CppParser::addStatement(const PStatement &parent, const QString &file
|
||||||
if (this->isIdentChar(ch)) {
|
if (this->isIdentChar(ch)) {
|
||||||
QString spaces=(i>argStart)?" ":"";
|
QString spaces=(i>argStart)?" ":"";
|
||||||
args+=spaces;
|
args+=spaces;
|
||||||
word += mTokenizer[i]->text[0];
|
word += mTokenizer[i]->text;
|
||||||
if (!typeGetted) {
|
if (!typeGetted) {
|
||||||
noNameArgs+=spaces+word;
|
noNameArgs+=spaces+word;
|
||||||
if (mCppTypeKeywords.contains(word) || !isCppKeyword(word))
|
if (mCppTypeKeywords.contains(word) || !isCppKeyword(word))
|
||||||
|
@ -1900,7 +1900,7 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// function call, skip it
|
// function call, skip it
|
||||||
mIndex=moveToNextBraceOrSkipNextSemicolon(mIndex,true);
|
mIndex=moveToEndOfStatement(mIndex,true);
|
||||||
}
|
}
|
||||||
} else if (mTokenizer[mIndex]->text.startsWith('*')
|
} else if (mTokenizer[mIndex]->text.startsWith('*')
|
||||||
|| mTokenizer[mIndex]->text.startsWith('&')
|
|| mTokenizer[mIndex]->text.startsWith('&')
|
||||||
|
@ -2573,11 +2573,7 @@ void CppParser::handleLambda(int index, int endIndex)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i=moveToNextBraceOrSkipNextSemicolon(i, true, bodyEnd);
|
i=moveToEndOfStatement(i, true, bodyEnd);
|
||||||
if (i<bodyEnd && mTokenizer[i]->text=='{') {
|
|
||||||
//skip '}'
|
|
||||||
i=mTokenizer[i]->matchIndex+1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
removeScopeLevel(mTokenizer[bodyEnd]->line);
|
removeScopeLevel(mTokenizer[bodyEnd]->line);
|
||||||
}
|
}
|
||||||
|
@ -3095,13 +3091,14 @@ bool CppParser::handleStatement()
|
||||||
handleMethod(StatementKind::skDestructor, "", '~'+mTokenizer[mIndex]->text, mIndex+1, false, false);
|
handleMethod(StatementKind::skDestructor, "", '~'+mTokenizer[mIndex]->text, mIndex+1, false, false);
|
||||||
} else {
|
} else {
|
||||||
//error
|
//error
|
||||||
mIndex=moveToNextBraceOrSkipNextSemicolon(mIndex,false);
|
mIndex=moveToEndOfStatement(mIndex,false);
|
||||||
}
|
}
|
||||||
} else if (!isIdentChar(mTokenizer[mIndex]->text[0])) {
|
} else if (!isIdentChar(mTokenizer[mIndex]->text[0])) {
|
||||||
mIndex=moveToNextBraceOrSkipNextSemicolon(mIndex,false);
|
mIndex=moveToEndOfStatement(mIndex,true);
|
||||||
} else if (mTokenizer[mIndex]->text.endsWith('.')
|
} else if (mTokenizer[mIndex]->text.endsWith('.')
|
||||||
|| mTokenizer[mIndex]->text.endsWith("->")) {
|
|| mTokenizer[mIndex]->text.endsWith("->")) {
|
||||||
mIndex=moveToNextBraceOrSkipNextSemicolon(mIndex,true);
|
mIndex=moveToEndOfStatement(mIndex,true);
|
||||||
|
|
||||||
} else if (checkForKeyword(keywordType)) { // includes template now
|
} else if (checkForKeyword(keywordType)) { // includes template now
|
||||||
handleKeyword(keywordType);
|
handleKeyword(keywordType);
|
||||||
} else if (keywordType==KeywordType::For) { // (for/catch)
|
} else if (keywordType==KeywordType::For) { // (for/catch)
|
||||||
|
@ -3581,7 +3578,6 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
bool varAdded = false;
|
|
||||||
QString tempType;
|
QString tempType;
|
||||||
while(mIndex<mTokenizer.tokenCount()) {
|
while(mIndex<mTokenizer.tokenCount()) {
|
||||||
// Skip bit identifiers,
|
// Skip bit identifiers,
|
||||||
|
@ -3600,54 +3596,25 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
|
||||||
mIndex++;
|
mIndex++;
|
||||||
} else if (mTokenizer[mIndex]->text==';') {
|
} else if (mTokenizer[mIndex]->text==';') {
|
||||||
break;
|
break;
|
||||||
} else if (mTokenizer[mIndex]->text=='('
|
|
||||||
&& mTokenizer[mIndex]->matchIndex+1<mTokenizer.tokenCount()
|
|
||||||
&& mTokenizer[mTokenizer[mIndex]->matchIndex+1]->text=='(') {
|
|
||||||
//function pointer
|
|
||||||
QString cmd=mTokenizer[mIndex]->text;
|
|
||||||
int argStart=mTokenizer[mIndex]->matchIndex+1;
|
|
||||||
int argEnd=mTokenizer[argStart]->matchIndex;
|
|
||||||
if (cmd.startsWith('*'))
|
|
||||||
cmd=cmd.mid(1);
|
|
||||||
if (!cmd.isEmpty()) {
|
|
||||||
addChildStatement(
|
|
||||||
getCurrentScope(),
|
|
||||||
mCurrentFile,
|
|
||||||
lastType,
|
|
||||||
cmd,
|
|
||||||
mergeArgs(argStart,argEnd),
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
mTokenizer[mIndex]->line,
|
|
||||||
StatementKind::skVariable,
|
|
||||||
getScope(),
|
|
||||||
mClassScope,
|
|
||||||
//True,
|
|
||||||
!isExtern,
|
|
||||||
isStatic); // TODO: not supported to pass list
|
|
||||||
varAdded = true;
|
|
||||||
tempType="";
|
|
||||||
}
|
|
||||||
mIndex=argEnd+1;
|
|
||||||
} else if (isWordChar(mTokenizer[mIndex]->text[0])) {
|
} else if (isWordChar(mTokenizer[mIndex]->text[0])) {
|
||||||
QString cmd=mTokenizer[mIndex]->text;
|
QString cmd=mTokenizer[mIndex]->text;
|
||||||
while (cmd.startsWith('*')) {
|
if (mTokenizer[mIndex+1]->text=='('
|
||||||
cmd=cmd.mid(1);
|
&& mTokenizer[mIndex+1]->matchIndex+1<mTokenizer.tokenCount()
|
||||||
}
|
&& mTokenizer[mTokenizer[mIndex+1]->matchIndex+1]->text=='(') {
|
||||||
if (cmd=="const") {
|
//function pointer
|
||||||
tempType=mTokenizer[mIndex]->text;
|
cmd = mTokenizer[mIndex+2]->text;
|
||||||
} else {
|
int argStart=mTokenizer[mIndex+1]->matchIndex+1;
|
||||||
QString suffix;
|
int argEnd=mTokenizer[argStart]->matchIndex;
|
||||||
QString args;
|
if (cmd.startsWith("*"))
|
||||||
cmd=mTokenizer[mIndex]->text;
|
cmd = cmd.mid(1);
|
||||||
parseCommandTypeAndArgs(cmd,suffix,args);
|
|
||||||
if (!cmd.isEmpty()) {
|
if (!cmd.isEmpty()) {
|
||||||
|
QString type=lastType;
|
||||||
addChildStatement(
|
addChildStatement(
|
||||||
getCurrentScope(),
|
getCurrentScope(),
|
||||||
mCurrentFile,
|
mCurrentFile,
|
||||||
(lastType+' '+tempType+suffix).trimmed(),
|
(lastType+" "+tempType+" "+mTokenizer[mIndex]->text).trimmed(),
|
||||||
cmd,
|
cmd,
|
||||||
args,
|
mergeArgs(argStart,argEnd),
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
mTokenizer[mIndex]->line,
|
mTokenizer[mIndex]->line,
|
||||||
|
@ -3656,12 +3623,43 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
|
||||||
mClassScope,
|
mClassScope,
|
||||||
//True,
|
//True,
|
||||||
!isExtern,
|
!isExtern,
|
||||||
isStatic); // TODO: not supported to pass list
|
isStatic);
|
||||||
varAdded = true;
|
|
||||||
tempType="";
|
|
||||||
}
|
}
|
||||||
|
tempType="";
|
||||||
|
mIndex=indexOfNextSemicolonOrLeftBrace(argEnd+1);
|
||||||
|
} else {
|
||||||
|
//normal var
|
||||||
|
while (cmd.startsWith('*')) {
|
||||||
|
cmd=cmd.mid(1);
|
||||||
|
}
|
||||||
|
if (cmd=="const") {
|
||||||
|
tempType=mTokenizer[mIndex]->text;
|
||||||
|
} else {
|
||||||
|
QString suffix;
|
||||||
|
QString args;
|
||||||
|
cmd=mTokenizer[mIndex]->text;
|
||||||
|
parseCommandTypeAndArgs(cmd,suffix,args);
|
||||||
|
if (!cmd.isEmpty()) {
|
||||||
|
addChildStatement(
|
||||||
|
getCurrentScope(),
|
||||||
|
mCurrentFile,
|
||||||
|
(lastType+' '+tempType+suffix).trimmed(),
|
||||||
|
cmd,
|
||||||
|
args,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
mTokenizer[mIndex]->line,
|
||||||
|
StatementKind::skVariable,
|
||||||
|
getScope(),
|
||||||
|
mClassScope,
|
||||||
|
//True,
|
||||||
|
!isExtern,
|
||||||
|
isStatic);
|
||||||
|
tempType="";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mIndex++;
|
||||||
}
|
}
|
||||||
mIndex++;
|
|
||||||
} else if (mTokenizer[mIndex]->text=='(') {
|
} else if (mTokenizer[mIndex]->text=='(') {
|
||||||
mIndex=mTokenizer[mIndex]->matchIndex+1;
|
mIndex=mTokenizer[mIndex]->matchIndex+1;
|
||||||
} else if (mTokenizer[mIndex]->text=='=') {
|
} else if (mTokenizer[mIndex]->text=='=') {
|
||||||
|
@ -5073,6 +5071,25 @@ int CppParser::indexOfNextSemicolon(int index, int endIndex)
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CppParser::indexOfNextPeriodOrSemicolon(int index, int endIndex)
|
||||||
|
{
|
||||||
|
if (endIndex<0)
|
||||||
|
endIndex=mTokenizer.tokenCount();
|
||||||
|
while (index<endIndex) {
|
||||||
|
switch(mTokenizer[index]->text[0].unicode()) {
|
||||||
|
case ';':
|
||||||
|
case ',':
|
||||||
|
return index;
|
||||||
|
case '(':
|
||||||
|
index = mTokenizer[index]->matchIndex+1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
int CppParser::indexOfNextSemicolonOrLeftBrace(int index)
|
int CppParser::indexOfNextSemicolonOrLeftBrace(int index)
|
||||||
{
|
{
|
||||||
while (index<mTokenizer.tokenCount()) {
|
while (index<mTokenizer.tokenCount()) {
|
||||||
|
@ -5169,29 +5186,81 @@ void CppParser::skipNextSemicolon(int index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CppParser::moveToNextBraceOrSkipNextSemicolon(int index, bool checkLambda, int endIndex)
|
//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 startIndex=index;
|
int startIndex=index;
|
||||||
if (endIndex<0)
|
if (endIndex<0)
|
||||||
endIndex=mTokenizer.tokenCount();
|
endIndex=mTokenizer.tokenCount();
|
||||||
bool stop=false;
|
if (index>=endIndex)
|
||||||
while (index<endIndex && !stop) {
|
return index;
|
||||||
switch(mTokenizer[index]->text[0].unicode()) {
|
index--; // compensate for the first loop
|
||||||
case ';':
|
|
||||||
index++;
|
bool skip=true;
|
||||||
stop=true;
|
do {
|
||||||
break;
|
index++;
|
||||||
case '{':
|
bool stop = false;
|
||||||
stop=true;
|
while (index<endIndex && !stop) {
|
||||||
break;
|
switch(mTokenizer[index]->text[0].unicode()) {
|
||||||
case '(':
|
case ';':
|
||||||
index = mTokenizer[index]->matchIndex+1;
|
stop=true;
|
||||||
break;
|
break;
|
||||||
default:
|
case '=':
|
||||||
index++;
|
stop=true;
|
||||||
|
break;
|
||||||
|
case '}':
|
||||||
|
stop=true;
|
||||||
|
skip=false; //don't skip the orphan '}' that we found
|
||||||
|
break;
|
||||||
|
case '{':
|
||||||
|
//move to '}'
|
||||||
|
index=mTokenizer[index]->matchIndex;
|
||||||
|
stop=true;
|
||||||
|
break;
|
||||||
|
case '(':
|
||||||
|
index = mTokenizer[index]->matchIndex+1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
index++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} while (index<mTokenizer.tokenCount() && mTokenizer[index]->text=='=');
|
||||||
if (stop && checkLambda) {
|
if (index<endIndex && checkLambda) {
|
||||||
while (mTokenizer.lambdasCount()>0 && mTokenizer.indexOfFirstLambda()<index) {
|
while (mTokenizer.lambdasCount()>0 && mTokenizer.indexOfFirstLambda()<index) {
|
||||||
int i=mTokenizer.indexOfFirstLambda();
|
int i=mTokenizer.indexOfFirstLambda();
|
||||||
mTokenizer.removeFirstLambda();
|
mTokenizer.removeFirstLambda();
|
||||||
|
@ -5200,6 +5269,8 @@ int CppParser::moveToNextBraceOrSkipNextSemicolon(int index, bool checkLambda, i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (skip)
|
||||||
|
index++;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -589,6 +589,7 @@ private:
|
||||||
void updateSerialId();
|
void updateSerialId();
|
||||||
|
|
||||||
int indexOfNextSemicolon(int index, int endIndex=-1);
|
int indexOfNextSemicolon(int index, int endIndex=-1);
|
||||||
|
int indexOfNextPeriodOrSemicolon(int index, int endIndex=-1);
|
||||||
int indexOfNextSemicolonOrLeftBrace(int index);
|
int indexOfNextSemicolonOrLeftBrace(int index);
|
||||||
int indexOfNextColon(int index);
|
int indexOfNextColon(int index);
|
||||||
int indexOfNextLeftBrace(int index);
|
int indexOfNextLeftBrace(int index);
|
||||||
|
@ -596,7 +597,8 @@ private:
|
||||||
int indexPassBraces(int index);
|
int indexPassBraces(int index);
|
||||||
int skipAssignment(int index, int endIndex);
|
int skipAssignment(int index, int endIndex);
|
||||||
void skipNextSemicolon(int index);
|
void skipNextSemicolon(int index);
|
||||||
int moveToNextBraceOrSkipNextSemicolon(int index, bool checkLambda, int endIndex=-1);
|
int moveToEndOfStatement(int index, bool checkLambda, int endIndex=-1);
|
||||||
|
// int moveToNextAssignmentOrEndOfStatement(int index, bool checkLambda, int endIndex=-1);
|
||||||
void skipParenthesis(int index);
|
void skipParenthesis(int index);
|
||||||
QString mergeArgs(int startIndex, int endIndex);
|
QString mergeArgs(int startIndex, int endIndex);
|
||||||
void parseCommandTypeAndArgs(QString& command,
|
void parseCommandTypeAndArgs(QString& command,
|
||||||
|
|
Loading…
Reference in New Issue