[Qt-creator] Issue parsing QStringLiteral() in SpellChecker Plugin

Carel Combrink carel.combrink at gmail.com
Thu Jul 30 00:02:29 CEST 2015


First of all, thank you for taking the time to respond to my issue.

Regarding the code you have supplied, it is almost the same code that I am
using, but I am not getting the same result as you. Is there perhaps a
reason why this would be?

I don't know how you get the line and column information, but you should use
> the get* functions of CPlusPlus::TranslationUnit for this.


If you look at the original code on github for cppdocumentparser.cpp
<https://github.com/CJCombrink/SpellChecker-Plugin/blob/master/Parsers/CppParser/cppdocumentparser.cpp>
you
can check if I am doing the correct thing:

The following code will report 4 string literals (note the u""), assuming
> that
> document comes from CppTools::CppModelManager::documentUpdated():

line 83
<https://github.com/CJCombrink/SpellChecker-Plugin/blob/master/Parsers/CppParser/cppdocumentparser.cpp#L83>:
Connects to &CppTools::CppModelManager::documentUpdated
This then ends up calling CppDocumentParser::parseCppDocument
<https://github.com/CJCombrink/SpellChecker-Plugin/blob/master/Parsers/CppParser/cppdocumentparser.cpp#L186>
on line 186 if you follow the code for a valid file.


>   if (TranslationUnit *translationUnit = document->translationUnit()) {
>       for (unsigned i = 0; i < translationUnit->tokenCount(); ++i) {
>           const Token t = translationUnit->tokenAt(i);
>           if (t.isStringLiteral() && t.expanded()) {
>               unsigned line, column;
>               translationUnit->getTokenStartPosition(i, &line, &column);
>               qDebug() << "String:" << t.spell() << "at line:" << line <<
> "column:" << column;
>           }
>       }
>   }

On line 211
<https://github.com/CJCombrink/SpellChecker-Plugin/blob/master/Parsers/CppParser/cppdocumentparser.cpp#L211>
you get to the relevant code in my parser. I previously had the issue thus
for that version of the code I just skip the expanded tokens.

So I have now updated the relevant code locally and the code can be seen in
the attached screenshots:
issue_source.png: Shows the source file that my SpellChecker is parsing.
Note that the cursor is @ Line 6, Column 32
issue_code.png: Shows my code along with my qDebug() outputs at the bottom.
Note that the debug reports the literal @ Line 8, Column 41.

It seems to me that my code always reports both instances to start at line
'real' + 2 and column at some 'random' constant column, no matter where I
move the string literal.

Note that the quickfixes do operate on a slightly different document than
> the
> one that is emitted via CppModelManager::documentUpdated(). So you can't
> use
> that code.

Thanks for this information.



> The slower/correct solution involves:
>  1. Finding the CallAST for tr(). Choose one of:
>   1.a Use an ASTVisitor for this and override visit(CallAST *ast)
>       See CheckSymbols::visit(CallAST *ast) for an example.
>   1.b Use ASTPath - see how it's used in cppquickfixes.cpp
>       See how ASTPath is used in cppquickfixes.cpp ("interface.path()").
>  2. Making a lookup on the "tr" to ensure it's the right one.

I have looked at this quickly but not in depth yet, for now the
StringLiteral is my priority so i will focus on trying to get that solved.
Perhaps then if I have issues I will ask about tr() strings. Thank you for
this information so long.

Just to mention my environment:
Windows 7 x64
Building with Qt 5.4 using msvc 2013
Qt Creator sources version: 3.4.82 (Does not mean to much I think)
The git commit version: ((463566a...)) on Jul 24  from
https://github.com/qtproject/qt-creator.git
I have also just updated to latest commit (50e9ef6...) but no significant
changes...

Regards,
Carel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20150730/9868f72f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: issue_code.png
Type: image/png
Size: 151054 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20150730/9868f72f/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: issue_source.png
Type: image/png
Size: 63302 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20150730/9868f72f/attachment-0001.png>


More information about the Qt-creator mailing list