[Qt-creator] C++ Plugin: Check word against C++ Code Model

Leandro T. C. Melo ltcmelo at gmail.com
Sat May 11 16:02:12 CEST 2013


On Fri, May 10, 2013 at 3:45 PM, Sergey Shambir <
sergey.shambir.auto at gmail.com> wrote:

>  CppModelManager class is a singleton. Use CppModelManager::document to
> get target Document instance, than use iteration over global symbols with
> globalSymbolCount/globalSymbolAt or scopeaAt(line, column) to get Scope.
>
> Scopes form a chain, you can get enclosing scope with
> Symbol::enclosingScope, and Scope is subclass of Symbol. Probably exact
> position of comment is in global or namespace scope, so use some heuristic
> like scanning until non-comment token appear.
>
> 10.05.13, 17:27, Carel Combrink пишет:
>
> Hi,
>
>  I am busy with a Qt Creator plugin for the C++ Editor.
>
>  How do I use the C++ code model to check if a word is a function, class,
> etc or 'just a word'? The plugin parses the comment tokens in a C++ Editor.
>
>  For an example: I have the following code:
> /* This is function myFunction */
> void myFunction(int arg1);
>
>  Parsing the comment gives me 4 words ("This", "is", "function" and
> "myFunction"). How do I know that "This" is just a word while "myFunction"
> is a token (part of the code model) in the scope of the comment?
>
>  My current, initial implementation checks a word against all tokens in
> the file that the comment appears in. I would like to make use of the code
> model instead, if possible.
>
>  Regards,
> Carel
>
>
>
Hi,

there's no direct way to get this information. Your wording is not totally
clear though. A comment is also a token and you can get its content. The
`myFunction' is also a token and more, it's the symbol for a particular
function in your code.

You could try something as Sergey mentioned through traversing the symbols
in the document and trying to match then. But depending on what exactly
you're doing there might be a shortcut (under certain assumptions and
limitations). For instance, in cases like that you could simply attempt to
parse the content that follows the comment as a declaration and if that
succeeds compare the identifiers from the function name, parameters, etc.

If you take a look at CppTools::DoxygenGenerator you'll notice that it does
more or less the same thing but in the other direction: Based on a
particular function, which is potentially located under the comment when
you start typing /**, it generates a doxygen comment from the information
it gathered.

Regards,
Leandro

--
http://www.ltcmelo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20130511/fea7a23e/attachment.html>


More information about the Qt-creator mailing list