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

scanner.py: add support for "original_type" attribute of "Argument" XML tag #194

Merged
merged 2 commits into from
Sep 28, 2024

Conversation

pdatkinson
Copy link
Contributor

@pdatkinson pdatkinson commented Sep 26, 2024

scanner.py: add support for "original_type" attribute of "Argument" XML tag. For array args this means avoiding losing the delcared width of the array and having its decl_type show as pointer_t.

Fall back on "type" (current default-no-matter-what) attribute when "original_type" is not present.

XML generated by pygccxml+CastXML:
image
image
image

Behaviour:

classes_obj                       = global_ns.classes()
class_im_looking_for              = [d for d in classes_obj.declarations if "class_im_looking_for" in d.name][0]
method_im_looking_for_declaration = [d for d in class_im_looking_for.declarations if d.name == "method_name"][0]
method_arguments                  = method_im_looking_for_declaration.arguments
argument                          = method_arguments[0]

# pre-PR this gives:
argument.decl_type.decl_string
Out[2]: '::my_namespace::my_type *'
pygccxml.declarations.type_traits.array_size(argument.decl_type)
#AssertionError: 
#> path/to/site-packages/pygccxml/declarations/type_traits.py(293)array_size()
#    291     nake_type = remove_reference(nake_type)
#    292     nake_type = remove_cv(nake_type)
#--> 293     assert isinstance(nake_type, cpptypes.array_t)
#    294     return nake_type.size

# post-PR this gives:
argument.decl_type.decl_string
Out[4]: '::my_namespace::my_type[1024]'
pygccxml.declarations.type_traits.array_size(argument.decl_type)
Out[5]: 1024

@pdatkinson
Copy link
Contributor Author

Overwrote previous commit to avoid linter complaints.

…ags in XML. For array args this means avoiding losing the delcared width of the array and having its decl_type show as pointer_t
@pdatkinson
Copy link
Contributor Author

Overwrote previous commit to fix silly oversight where decl_type fallback assignment value was XML_AN_TYPE ("type" literal) and not the value in attrs mapped to by XML_AN_TYPE.

@iMichka
Copy link
Contributor

iMichka commented Sep 27, 2024

Looks great. Please ignore the macos runner errors, these are pre-existing.

Do you think you could add a test for this?

Most of the tests are now in the tests folder (ran with pytest), and some legacy tests are in the unitest folder. Either one of these can be extended or a new one can be written.

pdatkinson added a commit to pdatkinson/pygccxml that referenced this pull request Sep 27, 2024
pdatkinson added a commit to pdatkinson/pygccxml that referenced this pull request Sep 27, 2024
@pdatkinson
Copy link
Contributor Author

Overwrote previous commit to include tests/test_array_argument.py (left out of first commit of the pair - kind of important I guess 😋)

@pdatkinson
Copy link
Contributor Author

Overwrote previous commit to avoid the stern gaze of the linter.

@iMichka iMichka merged commit 4f3fe0c into CastXML:develop Sep 28, 2024
7 of 8 checks passed
@iMichka
Copy link
Contributor

iMichka commented Sep 28, 2024

Thanks for the test!

How quickly do you need this in a new release? I will probably do one before end of 2024, if you need the change in a release faster than that, I can do one next week.

@pdatkinson
Copy link
Contributor Author

Thanks for the merge!

No rush re a release. I'm working off of a local copy currently and can continue to do so.

@iMichka
Copy link
Contributor

iMichka commented Nov 17, 2024

@pdatkinson v2.6.0 is out and contains the change

@pdatkinson
Copy link
Contributor Author

@iMichka awesome - thank you!

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.

2 participants