Skip to content
Snippets Groups Projects
Commit 00ac132d authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

don't accidentally write into scopes

we get no reliable end-of-block location from the token stream, so we
have to do it ourselves. the solution is qmake-worthy, to put it that
way ...

Task-number: QTCREATORBUG-4049
parent ed3e000f
No related branches found
No related tags found
No related merge requests found
......@@ -210,8 +210,6 @@ bool ProWriter::locateVarValues(const ushort *tokPtr,
}
}
}
if (inScope || *scopeStart < 0)
*bestLine = qMax(lineNo - 1, 0);
return false;
}
......@@ -268,6 +266,7 @@ void ProWriter::putVarValues(ProFile *profile, QStringList *lines,
} else {
// Create & append new variable item
QString added;
int lNo = lines->count();
if (!scope.isEmpty()) {
if (scopeStart < 0) {
added = QLatin1Char('\n') + scope + QLatin1String(" {");
......@@ -276,11 +275,29 @@ void ProWriter::putVarValues(ProFile *profile, QStringList *lines,
if (rx.exactMatch(lines->at(scopeStart))) {
(*lines)[scopeStart].replace(0, rx.cap(1).length(),
QString(scope + QLatin1String(" {\n ")));
lNo = skipContLines(lines, scopeStart, false);
scopeStart = -1;
}
}
}
int lNo = skipContLines(lines, lineNo, false);
if (scopeStart >= 0) {
lNo = scopeStart;
int braces = 0;
do {
const QString &line = (*lines).at(lNo);
for (int i = 0; i < line.size(); i++)
// This is pretty sick, but qmake does pretty much the same ...
if (line.at(i) == QLatin1Char('{')) {
++braces;
} else if (line.at(i) == QLatin1Char('}')) {
if (!--braces)
break;
} else if (line.at(i) == QLatin1Char('#')) {
break;
}
} while (braces && ++lNo < lines->size());
}
for (; lNo > scopeStart + 1 && lines->at(lNo - 1).isEmpty(); lNo--) ;
if (lNo != scopeStart + 1)
added += QLatin1Char('\n');
added += indent + var + QLatin1String((flags & AppendOperator) ? " +=" : " =");
......
......@@ -191,6 +191,19 @@ void tst_ProFileWriter::adds_data()
"SOURCES += \\\n"
" foo"
},
{
PW::AppendValues|PW::AppendOperator|PW::MultiLine,
"add new after some scope", f_foo, 0,
"unix {\n"
" SOMEVAR = foo\n"
"}",
"unix {\n"
" SOMEVAR = foo\n"
"}\n"
"\n"
"SOURCES += \\\n"
" foo"
},
{
PW::AppendValues|PW::AppendOperator|PW::MultiLine,
"add to existing (wrong operator)", f_foo, 0,
......@@ -346,6 +359,41 @@ void tst_ProFileWriter::adds_data()
" SOURCES += foo\n"
"}"
},
{
PW::AppendValues|PW::AppendOperator|PW::OneLine,
"scoped new / extend oneline scope with multiline body", f_foo, "dog",
"# test file\n"
"dog:HEADERS += yo \\\n"
" you\n"
"\n"
"blubb()",
"# test file\n"
"dog {\n"
" HEADERS += yo \\\n"
" you\n"
"\n"
" SOURCES += foo\n"
"}\n"
"\n"
"blubb()"
},
{
PW::AppendValues|PW::AppendOperator|PW::MultiLine,
"add new after some scope inside scope", f_foo, "dog",
"dog {\n"
" unix {\n"
" SOMEVAR = foo\n"
" }\n"
"}",
"dog {\n"
" unix {\n"
" SOMEVAR = foo\n"
" }\n"
"\n"
" SOURCES += \\\n"
" foo\n"
"}"
},
{
PW::AppendValues|PW::AppendOperator|PW::MultiLine,
"scoped append", f_foo, "dog",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment