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

Simon Schäfer simonschaefer at posteo.de
Tue Sep 10 18:31:45 CEST 2013


Am 10.09.13 16:28, schrieb Erik Verbruggen:
> On Sep 10, 2013, at 14:57, Simon Schäfer <simonschaefer at posteo.de> wrote:
>
>> 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?
> Um, because semantic highlighting uses information from the parser to find out that a piece of text is an identifier, and actually the identifier it needs to highlight? Or did I misunderstand the question?
How does it help the semantic highlighter that __LINE__ is replaced by a
string representation of the current line number or __FILE__ is for
example: "helloworld.cpp"?
What I would like to commit is the following: http://pastebin.com/3AZvPj2e
What keeps me holding it back is that the txt's where there for a reason
in the first place, but I can't figure out what they are for.

Cheers
Simon



More information about the Qt-creator mailing list