-
Notifications
You must be signed in to change notification settings - Fork 10
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
Throw an error if there is an undeclared type or a template. #4
base: dev
Are you sure you want to change the base?
Throw an error if there is an undeclared type or a template. #4
Conversation
I'm currently very busy at work, but I also need to test this (before considering this PR done) with reflected templated classes (when our reflected class is used as a field, for example) so that this function will not backfire on our types. |
I've decided to only check for I don't have enough knowledge whether there is a better way to check all this but at least we will have protection for those types for now. |
Well, I've noticed that during parsing libclang's errors might break type information (so that |
libclang throws a lot of irrelevant errors and warnings so it's very complicated to exploit it to have a consistent and coherent behaviour. That being said, I upgraded the shipped libclang library version once and as far as I remember I haven't analysed clang logs since then. Having a generic implementation that handles all types at once sounds good to me, but I don't think handling types individually, even if they are std types is a viable solution. As for the macro errors, they will always be fired if the generated file doesn't exist. Since the generated file doesn't exist, the macro doesn't exist neither and libclang will throw a bunch of errors like this. In the case of a regeneration, such errors should not appear. |
You are right, this is why I started working on actually fixing libclang errors instead of looking for some std type errors. I will keep you updated about the process. |
So, here is what I've done now:
With this the type information will now be processed correctly and we will no longer have |
I've added a new parameter to You should update library integration example after this PR will be merged: https://github.com/jsoysouvanh/RefurekuIntegration/blob/master/LibraryIntegration/RefurekuSettings.toml |
I've found an issue, if we are using inheritance and we haven't generated parent's data while parsing child class we will fail with an error:
I think I know a way to fix this. |
So, I've split all process into 3 steps. First, we do pre-parsing on all files (that needs to be processed), this step fills generated files with reflection macros, then only after all pre-parsing tasks were finished we do the parsing. Only after all parsing tasks were finished we start code generation, we wait for all parsing tasks because on code generation step we would need to clear generated files from empty macros that we used for proper parsing. This fixes the issue I described above. I still need to test this with properties and test it on Linux (gcc, clang). |
After I've decided to completely ignore the iterations thing (reruning all steps multiple times) I decided to add a backwards compatibility. I've added a new parameter in the `KodgenSettings.toml` - `shouldFailCodeGenerationOnClangErrors` which is `false` by default. When this setting is turned off we use the old parsing algorithm (existed before this branch, ignores parsing errors), when it's turned on we use the new approach where we fail on any Clang error that occur during the parsing.
While running parsing for the tests I've noticed that there is a situation when 1 GENERATED macro is not captured in the pre-parsing step which fails the parsing step. I also noticed that this error might not occur due to the fact that pre-parsing step writes macros in parallel. Thus, I've made it so that the pre-parsing step writes found GENERATED macros in a single-threaded manner after the pre-parsing step but before the parsing step. Although this is indeed an improvement, it does not solved the issue where 1 GENERATED macro was not found. I then remembered about "iterations" thing and added a cycle. So now, files that failed the parsing step (only failed files) will be queued to be parsed again on the next cycle iteration. With this change, when we rerun the pre-parsing step for failed files we have enough info to find all GENERATED macros. Of cource I added a check where if the number of failed files stays the same we break out of the cycle and show an error.
When a parsing error occurres we now not only show path to the file where error occurred but also path to the file that was parsed. This actually helps when we are parsing file A and it includes file B and a parsing error occurres in the file B.
Well, I think this PR is at the finish line. I've managed to fix almost all test files (lots of them didn't included stuff that they were using) and now code generation for the new option There is still an issue with one test file:
other test files have no errors. I honestly don't know what's causing this issue. If I remove file
So I guess everything is fine? I also tested Refureku with In addition, I propose to set By default |
This PR is related to this Refureku PR.
This PR adds the function
findStandardTypesErrors
inFileParser
. This function looks for libclang errors that occurred during translation unit parsing and that might cause incorrect type information when using reflection. For example: you are usingstd::vector
as a field but you don't include<vector>
(this will cause this field's type to beint
).With this PR when such error occurs the generator will fail and will notify the user about his error.