Commit 68471c21 authored by Francois Ferrand's avatar Francois Ferrand Committed by Roberto Raggi
Browse files

Preprocessor: fix macro definition line.



The line corresponding to the macro definition is simply the token's
line. This caused errors in the macro definitions, since there were
multiple macros defined on the same line of the same file.

Task-number: QTCREATORBUG-7217
Change-Id: I56d17eeba677ac51f9eed283c0e964019bdfe4b7
Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent fcb825d4
......@@ -1189,7 +1189,7 @@ void Preprocessor::handleDefineDirective(PPToken *tk)
Macro macro;
macro.setFileName(m_env->currentFile);
macro.setLine(m_env->currentLine);
macro.setLine(tk->lineno);
QByteArray macroName = tk->asByteArrayRef().toByteArray();
macro.setName(macroName);
macro.setOffset(tk->offset);
......
......@@ -104,7 +104,11 @@ public:
virtual ~MockClient() {}
virtual void macroAdded(const Macro &/*macro*/) {}
virtual void macroAdded(const Macro & macro)
{
m_definedMacros.append(macro.name());
m_definedMacrosLine.append(macro.line());
}
virtual void passedMacroDefinitionCheck(unsigned /*offset*/, const Macro &/*macro*/) {}
virtual void failedMacroDefinitionCheck(unsigned /*offset*/, const QByteArray &/*name*/) {}
......@@ -216,6 +220,12 @@ public:
QList<unsigned> expandedMacrosOffset() const
{ return m_expandedMacrosOffset; }
QList<QByteArray> definedMacros() const
{ return m_definedMacros; }
QList<unsigned> definedMacrosLine() const
{ return m_definedMacrosLine; }
private:
Environment *m_env;
QByteArray *m_output;
......@@ -226,6 +236,8 @@ private:
QList<Include> m_recordedIncludes;
QList<QByteArray> m_expandedMacros;
QList<unsigned> m_expandedMacrosOffset;
QList<QByteArray> m_definedMacros;
QList<unsigned> m_definedMacrosLine;
};
namespace QTest {
......@@ -436,6 +448,8 @@ void tst_Preprocessor::macro_uses()
QCOMPARE(simplified(preprocessed), QString("void test(){int x=8;int y=9;}"));
QCOMPARE(client.expandedMacros(), QList<QByteArray>() << QByteArray("FOO") << QByteArray("BAR"));
QCOMPARE(client.expandedMacrosOffset(), QList<unsigned>() << buffer.indexOf("FOO;") << buffer.indexOf("BAR;"));
QCOMPARE(client.definedMacros(), QList<QByteArray>() << QByteArray("FOO") << QByteArray("BAR"));
QCOMPARE(client.definedMacrosLine(), QList<unsigned>() << 2 << 3);
}
void tst_Preprocessor::macro_definition_lineno()
......
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