[Qt-creator] Need help understanding some qt-creator source

Simon Schäfer simonschaefer at posteo.de
Tue Sep 10 14:57:30 CEST 2013


Hello

I try to understand some of the code of the creator, because I would
like to remove it, it is the reason of a bug (QTCREATORBUG-8036, it
still effects master) that annoys me. I can't figure out what it is used
for. The code I am talking about is in pp-engine.cpp:

bool Preprocessor::handleIdentifier(PPToken *tk)

There the representations of some preprocessor macros are internally
replaced by their meanings. For Example __LINE__ is replaced by the text
"9". This leads to strange behaviour for highlighting and even
re-factoring, because the editor determines the length of a token not by
the space it uses in the view but by the length of its text. So for the
above example the length is 1 instead of 8.

The following example code can help you understand the Problem:

<snip>
#include <QCoreApplication> // line 1

#include <QDebug>

int main(int argc, char *argv[])
{
	int abcd = 0;

	qDebug () << __LINE__ << abcd; // line 9
	qDebug () << __LINE__ << abcd; // line 10
	return 0;
}
<snap>

If you click on abcd it will highlight a block of 4 chars within the
first __LINE__ and another block of 4 in the second __LINE__ (moved one
to the right). If you now use "Rename Symbol under cursor" and type
abcde strange stuff happens.

My basic question is why are those Preprocessor texts used instead of
the displayed texts?

Cheers
Simon




More information about the Qt-creator mailing list