Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ctags parse header #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

Muream
Copy link
Contributor

@Muream Muream commented Jul 10, 2021

So, I went down a rabbit hole...

parse_header.py was failing on some header files required for #25.
I tried upgrading it but didn't feel like handling a billion edge cases like manually parsing C++ seems to be like

I ended up relying on Universal Ctags which outputs a list of all the classes, methods, etc. that are in a given file.

It's not perfect but it works on all the files I've tested so far

Some things that are not supported yet:

  1. Functions declared out of the scope of a class
  2. Properties
  3. Nested classes
  4. Enums

I'll probably leave it at that for this PR though and we can improve on that as we need.

I've made a separate parse_header_ctags.py script in case parse_header.py still produces better results on some files

And of course, ctags needs to be installed and available in your path

@mottosso
Copy link
Owner

ctags? Interesting. :) I might use this for other things too, didn't know this existed.

Can you give some examples of what it failed on before, and what it looks like now?

@Muream
Copy link
Contributor Author

Muream commented Jul 11, 2021

the current parse_header script fails to generate the inl file for MPxNode with this stack trace:

Traceback (most recent call last):
  File "scripts\parse_header.py", line 534, in <module>
    main()
  File "scripts\parse_header.py", line 524, in main
    parse_header(opts.header)
  File "scripts\parse_header.py", line 181, in parse_header
    arguments)
  File "scripts\parse_header.py", line 325, in parse_method
    raise RuntimeError("Cannot parse signature: {}".format(signature))
RuntimeError: Cannot parse signature: MDataBlock                                _forceCache             ()                 { return forceCache(); } void                                    _setDoNotWrite  ( bool flag )   { setDoNotWrite(flag); } bool                                       _doNotWrite             ()                              { return doNotWrite

I won't paste the generated file of parse_header_ctags here because it's 650 lines long but it works.
The file won't compile out of the box though as some types like PostEvaluationType should be MPxNode::PostEvaluationType and possibly a few more things to clean up.

Running it against classes like MDagPath produces files that compile directly, however.

One thing to note: I'm only including methods that exist in maya.OpenMaya because ctags would list a lot more things including private methods. This felt like a sensible way to filter all that out but I'm not 100% sure if maya.OpenMaya has 100% parity with the C++ API.

@mottosso
Copy link
Owner

I'm not 100% sure if maya.OpenMaya has 100% parity with the C++ API.

It's lacking a ton of stuff, so it won't get us all the way there. But if it helps.. But, why do we need to involve maya.OpenMaya here at all? :O Sorry I haven't looked more closely at the contents of this PR yet. But I would have thought all we need are the C++ headers? If we can use maya.OpenMaya, could we not fetch members and argument signatures directly from there via Python?

@Muream
Copy link
Contributor Author

Muream commented Jul 15, 2021

haha That was my quick way of filtering out some garbage that ctags was picking up on, I thought maya.OpenMaya was feature complete.
I can definitely remove that filter and see where that takes us 👍
I know ctags was confused on things like the OPENMAYA_DEPRECATED statements and a few other things that are in the header files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants