Commit b53d5628 authored by Leandro Melo's avatar Leandro Melo

C++: Take multiline strings into account when preprocessing

It was creating extra line(s)...

Change-Id: If28a9ccf16195c71747479db838a5589ea6683a0
Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent e148d030
...@@ -1137,9 +1137,9 @@ void Preprocessor::trackExpansionCycles(PPToken *tk) ...@@ -1137,9 +1137,9 @@ void Preprocessor::trackExpansionCycles(PPToken *tk)
} }
} }
static void adjustForCommentNewlines(unsigned *currentLine, const PPToken &tk) static void adjustForCommentOrStringNewlines(unsigned *currentLine, const PPToken &tk)
{ {
if (tk.is(T_COMMENT) || tk.is(T_DOXY_COMMENT)) if (tk.is(T_COMMENT) || tk.is(T_DOXY_COMMENT) || tk.isStringLiteral())
(*currentLine) += tk.asByteArrayRef().count('\n'); (*currentLine) += tk.asByteArrayRef().count('\n');
} }
...@@ -1147,7 +1147,7 @@ void Preprocessor::synchronizeOutputLines(const PPToken &tk, bool forceLine) ...@@ -1147,7 +1147,7 @@ void Preprocessor::synchronizeOutputLines(const PPToken &tk, bool forceLine)
{ {
if (m_state.m_expansionStatus != NotExpanding if (m_state.m_expansionStatus != NotExpanding
|| (!forceLine && m_env->currentLine == tk.lineno)) { || (!forceLine && m_env->currentLine == tk.lineno)) {
adjustForCommentNewlines(&m_env->currentLine, tk); adjustForCommentOrStringNewlines(&m_env->currentLine, tk);
return; return;
} }
...@@ -1164,7 +1164,7 @@ void Preprocessor::synchronizeOutputLines(const PPToken &tk, bool forceLine) ...@@ -1164,7 +1164,7 @@ void Preprocessor::synchronizeOutputLines(const PPToken &tk, bool forceLine)
} }
m_env->currentLine = tk.lineno; m_env->currentLine = tk.lineno;
adjustForCommentNewlines(&m_env->currentLine, tk); adjustForCommentOrStringNewlines(&m_env->currentLine, tk);
} }
void Preprocessor::removeTrailingOutputLines() void Preprocessor::removeTrailingOutputLines()
......
...@@ -336,6 +336,8 @@ private slots: ...@@ -336,6 +336,8 @@ private slots:
void comments_within2_data(); void comments_within2_data();
void multitokens_argument(); void multitokens_argument();
void multitokens_argument_data(); void multitokens_argument_data();
void multiline_strings();
void multiline_strings_data();
}; };
// Remove all #... lines, and 'simplify' string, to allow easily comparing the result // Remove all #... lines, and 'simplify' string, to allow easily comparing the result
...@@ -1298,6 +1300,27 @@ void tst_Preprocessor::comments_within2_data() ...@@ -1298,6 +1300,27 @@ void tst_Preprocessor::comments_within2_data()
QTest::newRow("case 4") << original << expected; QTest::newRow("case 4") << original << expected;
} }
void tst_Preprocessor::multiline_strings()
{
compare_input_output();
}
void tst_Preprocessor::multiline_strings_data()
{
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QByteArray>("output");
QByteArray original;
QByteArray expected;
original = "const char *s = \"abc\\\n"
"xyz\";\n";
expected = "# 1 \"<stdin>\"\n"
"const char *s = \"abc\\\n"
"xyz\";\n";
QTest::newRow("case 1") << original << expected;
}
void tst_Preprocessor::compare_input_output(bool keepComments) void tst_Preprocessor::compare_input_output(bool keepComments)
{ {
QFETCH(QByteArray, input); QFETCH(QByteArray, input);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment