- fix: foreach-loops are not correctly parsed.
This commit is contained in:
parent
2114206e76
commit
7e3ee41546
1
NEWS.md
1
NEWS.md
|
@ -2,6 +2,7 @@ Red Panda C++ Version 2.22
|
|||
|
||||
- fix: Crash at startup when current problem in the problem set is connected with source file.
|
||||
- fix: Double-clicking on touchpad can't select current word.
|
||||
- fix: foreach-loops are not correctly parsed.
|
||||
|
||||
Red Panda C++ Version 2.21
|
||||
|
||||
|
|
|
@ -2428,8 +2428,15 @@ void CppParser::handleForBlock()
|
|||
mIndex++; // skip for/catch;
|
||||
if (mIndex >= tokenCount)
|
||||
return;
|
||||
if (mTokenizer[mIndex]->text!="(")
|
||||
return;
|
||||
int i=indexOfNextSemicolon(mIndex);
|
||||
int i2 = i+1; //skip over ';' (tokenizer have change for(;;) to for(;)
|
||||
|
||||
// for(int x:vec)
|
||||
if (i2 > mTokenizer[mIndex]->matchIndex)
|
||||
i2 = mTokenizer[mIndex]->matchIndex+1;
|
||||
|
||||
if (i2>=tokenCount)
|
||||
return;
|
||||
if (mTokenizer[i2]->text.startsWith('{')) {
|
||||
|
@ -3955,7 +3962,7 @@ void CppParser::internalParse(const QString &fileName)
|
|||
|
||||
QStringList preprocessResult = mPreprocessor.result();
|
||||
#ifdef QT_DEBUG
|
||||
// stringsToFile(mPreprocessor.result(),QString("r:\\preprocess-%1.txt").arg(extractFileName(fileName)));
|
||||
stringsToFile(mPreprocessor.result(),QString("r:\\preprocess-%1.txt").arg(extractFileName(fileName)));
|
||||
// mPreprocessor.dumpDefinesTo("r:\\defines.txt");
|
||||
// mPreprocessor.dumpIncludesListTo("r:\\includes.txt");
|
||||
#endif
|
||||
|
@ -3974,7 +3981,7 @@ void CppParser::internalParse(const QString &fileName)
|
|||
if (mTokenizer.tokenCount() == 0)
|
||||
return;
|
||||
#ifdef QT_DEBUG
|
||||
// mTokenizer.dumpTokens(QString("r:\\tokens-%1.txt").arg(extractFileName(fileName)));
|
||||
mTokenizer.dumpTokens(QString("r:\\tokens-%1.txt").arg(extractFileName(fileName)));
|
||||
#endif
|
||||
#ifdef QT_DEBUG
|
||||
mLastIndex = -1;
|
||||
|
@ -3987,8 +3994,8 @@ void CppParser::internalParse(const QString &fileName)
|
|||
}
|
||||
// qDebug()<<"parse"<<timer.elapsed();
|
||||
#ifdef QT_DEBUG
|
||||
// mStatementList.dumpAll(QString("r:\\all-stats-%1.txt").arg(extractFileName(fileName)));
|
||||
// mStatementList.dump(QString("r:\\stats-%1.txt").arg(extractFileName(fileName)));
|
||||
mStatementList.dumpAll(QString("r:\\all-stats-%1.txt").arg(extractFileName(fileName)));
|
||||
mStatementList.dump(QString("r:\\stats-%1.txt").arg(extractFileName(fileName)));
|
||||
#endif
|
||||
//reduce memory usage
|
||||
internalClear();
|
||||
|
|
|
@ -540,29 +540,29 @@ QString CppPreprocessor::expandMacros(const QString &line, int depth)
|
|||
void CppPreprocessor::expandMacro(const QString &line, QString &newLine, QString &word, int &i, int depth)
|
||||
{
|
||||
int lenLine = line.length();
|
||||
if (word.startsWith("__")
|
||||
&& word.endsWith("__")) {
|
||||
// if (word == "__attribute__") {
|
||||
//skip gcc __attribute__
|
||||
while ((i<lenLine) && (line[i] == ' ' || line[i]=='\t'))
|
||||
i++;
|
||||
if ((i<lenLine) && (line[i]=="(")) {
|
||||
int level=0;
|
||||
while (i<lenLine) {
|
||||
switch(line[i].unicode()) {
|
||||
case '(':
|
||||
level++;
|
||||
break;
|
||||
case ')':
|
||||
level--;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
if (level==0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if (word.startsWith("__")
|
||||
// && word.endsWith("__")) {
|
||||
//// if (word == "__attribute__") {
|
||||
// //skip gcc __attribute__
|
||||
// while ((i<lenLine) && (line[i] == ' ' || line[i]=='\t'))
|
||||
// i++;
|
||||
// if ((i<lenLine) && (line[i]=="(")) {
|
||||
// int level=0;
|
||||
// while (i<lenLine) {
|
||||
// switch(line[i].unicode()) {
|
||||
// case '(':
|
||||
// level++;
|
||||
// break;
|
||||
// case ')':
|
||||
// level--;
|
||||
// break;
|
||||
// }
|
||||
// i++;
|
||||
// if (level==0)
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
PDefine define = getDefine(word);
|
||||
if (define && define->args=="" ) {
|
||||
if (define->value != word )
|
||||
|
@ -601,7 +601,7 @@ void CppPreprocessor::expandMacro(const QString &line, QString &newLine, QString
|
|||
} else {
|
||||
newLine += word;
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
QString CppPreprocessor::removeGCCAttributes(const QString &line)
|
||||
|
|
Loading…
Reference in New Issue