Skip to content

Fix several ICG class template bugs #1871

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

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

Conversation

ninotarantino
Copy link
Contributor

@ninotarantino ninotarantino commented Apr 2, 2025

Closes #1001, #540, #1169

@coveralls
Copy link

coveralls commented Apr 3, 2025

Coverage Status

coverage: 55.877% (-0.06%) from 55.933%
when pulling 3ba8d8b on ninotarantino:1169-io_src-templates
into 46b4817 on nasa:master.

@ninotarantino ninotarantino force-pushed the 1169-io_src-templates branch from ab4c0e9 to 23bead3 Compare April 4, 2025 01:37
- Fixed an issue where io_src code for some templates was being placed in the
  wrong file.
- Fixed an issue with templates being instantiated with templates as parameters.
- Fixed an issue with templates that instantiate templates.

Added additional tests to cover these cases.
@ninotarantino ninotarantino force-pushed the 1169-io_src-templates branch from 23bead3 to 47df1a2 Compare April 4, 2025 14:32
@ninotarantino
Copy link
Contributor Author

@hchen99 This is ready for review. This addresses the issues with templates in io_src code I was seeing locally. It also addresses a few other related issues. It still doesn't fix #1860, though.

There was a spot in FieldVisitor where the filename for certain templates was being overridden. That was causing the io_src code to be placed in the wrong file sometimes (#540). That fixes most of the problems in those three issues.

I also added a new function that saves header dependencies for template arguments, then writes those additional #include statements to the right io_src file if needed. That handles the last edge case where some model C instantiates a template A<B>. A doesn't know about B, and B doesn't know about A. The io_src code will go in A's io_src file, and will now #include the header file defining B.

@hchen99
Copy link
Contributor

hchen99 commented Apr 4, 2025

@ninotarantino Sounds great, thank you! Will review

template_spec_cvis.get_class_data()->setName(in_name) ;
template_spec_cvis.get_class_data()->setFileName(fdes->getFileName()) ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to remove this line? Seems working either way. Just wondering

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably put that in before I got the new includes working. That fixed the issue in #540 where the io_src was being put in the wrong file. But yeah it looks like this should work with or without this line now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Very reasonable 👍

@hchen99
Copy link
Contributor

hchen99 commented Apr 8, 2025

@hchen99 This is ready for review. This addresses the issues with templates in io_src code I was seeing locally. It also addresses a few other related issues. It still doesn't fix #1860, though.

For #1860, it seems like the header dependencies template arguments are already obtained for a ClassValue, however, PrintFileContents10 might print other ClassValue earlier than the one that has header dependencies info for the template arguments. So, the dependencies set for template arguments also needs to be kept in PrintFileContents10 that they can be print at the end of printIOHeader.

@hchen99
Copy link
Contributor

hchen99 commented Apr 8, 2025

@ninotarantino I did a quick test using a map to store header template argument dependencies for each applicable header in PrintFileContents10, replacing the set previously stored in ClassValue. The header dependency set is printed in the same location as before in PrintFileContents10, and it seems to work, including for the case in #1860. Also added logic to avoid including the same dependency multiple times. You probably have a different approach in mind. Thought to just let you know.

@ninotarantino
Copy link
Contributor Author

Oh awesome! Yeah that sounds like a better solution since it'll keep the headers at the top of the file every time. I have no preference personally, just wanted to get a working prototype for my branch. I probably won't be able to focus on this for a while so if you want to make those changes that's fine with me! Or I can do it when I have some time again.

@hchen99
Copy link
Contributor

hchen99 commented Apr 8, 2025

Oh awesome! Yeah that sounds like a better solution since it'll keep the headers at the top of the file every time. I have no preference personally, just wanted to get a working prototype for my branch. I probably won't be able to focus on this for a while so if you want to make those changes that's fine with me! Or I can do it when I have some time again.

Understand. No problem and thanks for making this PR. I’ll go ahead and make the update to your branch. When you have time, feel free to test it to make sure it works with your sim—I might’ve missed something.

hchen99 added 2 commits April 8, 2025 15:38
…ues to PrintFileContents10 so they can be printed to the io_ file regardless of the order in which class info is printed.
…ues to PrintFileContents10 so they can be printed to the io_ file regardless of the order in which class info is printed.

Moved the list of template argument header dependencies from ClassValues to PrintFileContents10 so they can be printed to the io_ file regardless of the order in which class info is printed.
@hchen99
Copy link
Contributor

hchen99 commented Apr 8, 2025

@ninotarantino When you have a chance, it’d be great if you could test it with your sim and let me know if you notice anything. Some of your code was commented out during relocation in case still needed and can be deleted once tested.

@ninotarantino
Copy link
Contributor Author

@hchen99 My sim still works with your changes! Everything looks good.

… some commented code.

Added support to handle template enum class type argument and removed some commented code.
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.

ICG produces uncompilable code for some template cases
3 participants