Skip to content

Conversation

@firewave
Copy link
Collaborator

@firewave firewave commented Jan 28, 2023

valueflow.cpp is very monolithic which makes it hard to manage. This is splitting several parts into separate files as discussed in #4642.

@firewave
Copy link
Collaborator Author

@pfultz2 Please have a look.
This is the initial approach which works quite well. I already did further functions up to the first more complex case valueFlowForwardLifetime() were it gets quite granular but we can discuss this after decided if this approach is fine.

I will also get rid of the using namespace ValueFlow within the split files since it makes things harder to understand when the increased granularity kicks in.

@firewave
Copy link
Collaborator Author

I am reworking this a bit and will fix the matchcompiler and CMake.

@firewave
Copy link
Collaborator Author

Still needs matchcompiler support.

Also need to make sure it doesn't impact the performance negatively now the code is no longer completely visible to some of the callers.


#include "common.h"

void ValueFlow::number(TokenList *tokenlist) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think we should shorten the names like that as this could conflict with other functions in the future. I understand why we wouldn't want ValueFlow::valueFlowNumber, but we should have a clear naming scheme so they wont conflict.

Copy link
Contributor

Choose a reason for hiding this comment

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

The other transformations have a naming scheme like simplifySomething. I am thinking something like analyzeNumber or assignNumber?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That sounds good. Will adjust.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

#include "token.h"
#include "valueflow.h"

void ValueFlow::enumValue(SymbolDatabase * symboldatabase, const Settings * settings)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be inside namespace ValueFlow{ ... }. This will simplify calling the other functions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had using namespace ValueFlow; in the source files which is better since it doesn't increase the indentation. But I went back on it. I guess I add it back.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

lib/vf/number.h Outdated

namespace ValueFlow
{
void number(TokenList *tokenlist);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only used be valueflow.cpp. I think it would be better to put all the declarations in valueflow.cpp or in a single header that valueflow.cpp includes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Everything in the vf folder is only used by valueflow.cpp. But having a convenience header with all of them in it would be fine I guess.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

lib/vf/common.h Outdated

std::string debugString(const ValueFlow::Value& v);

void setSourceLocation(ValueFlow::Value& v,
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think setSourceLocation or debugString need to be put in the header as its only used by setTokenValue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They will be used in more than one of the split off source file. Otherwise I could have directly moved those in. There's probably room for more cleanups/refactoring after it is all done.

SourceLocation loc = SourceLocation::current());
}

#endif // vfCommonH
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to name the header settokenvalue.h. Using a common header can bring in a lot of unnecessary dependencies.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I plan to split up common later on. It helps with the incremental approach of the changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since we only split internals of valueflow.cpp into separate files which are only included by valueflow.cpp there will be no additional dependencies compared to before. It is correct though that they might be unneeded in scope of the newly created smaller parts though. That should not cause any issues though and can be cleaned up afterwards.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Already done in this PR since it involves a lot of code.

@pfultz2
Copy link
Contributor

pfultz2 commented Feb 4, 2023

I will also get rid of the using namespace ValueFlow within the split files since it makes things harder to understand when the increased granularity kicks in.

Wrapping in namespace ValueFlow { ... } will get rid of that.

@firewave
Copy link
Collaborator Author

firewave commented Feb 4, 2023

I will also get rid of the using namespace ValueFlow within the split files since it makes things harder to understand when the increased granularity kicks in.

Wrapping in namespace ValueFlow { ... } will get rid of that.

I don't like that the indentation is being increased by that. I think it's nicer to simply add a single line and having them all aligned to the first line.

@firewave
Copy link
Collaborator Author

firewave commented Feb 4, 2023

This currently doesn't play well with the matchcompiler. I have it working in CMake but the regular make is still an issue. It also seems there's some code in it which we don't need anymore.

@firewave firewave force-pushed the vf-inc branch 3 times, most recently from 3b494c2 to 4f10788 Compare February 6, 2023 11:03
@pfultz2
Copy link
Contributor

pfultz2 commented Feb 10, 2023

I don't like that the indentation is being increased by that. I think it's nicer to simply add a single line and having them all aligned to the first line.

We should update the formatting to not indent for namespace scopes.

@firewave
Copy link
Collaborator Author

I will give this another stab after #6298 has been merged.

@firewave
Copy link
Collaborator Author

Since it complicates things and does not match the structure the project has been using all along I will omit introducing a subfolder and introduce an underscore in the filenames instead (although that also doesn't match what has been done so far).

@firewave firewave force-pushed the vf-inc branch 2 times, most recently from b336045 to 5bba4f5 Compare April 21, 2024 13:14
@firewave
Copy link
Collaborator Author

Re-did the first commit, will re-add the others later.

Having this in individual files might also allow us to write unit (and maybe performance tests) for the respective analyze steps.

@firewave firewave changed the title ValueFlow: split into multiple files ValueFlow: start splitting it into multiple files Apr 22, 2024
@firewave
Copy link
Collaborator Author

We could already merge this as a start or I could move yet another step. IMO this change is way too big to do it in a single commit.

After all the steps have been moved out I will do the further suggested split of the common code.

firewave added a commit that referenced this pull request Apr 22, 2024
#4748 exposed a different order of files using the Windows code. This
was caused by it only sorting the files in case of recursive parsing.
But we need to sort all the files and not just the directory contents as
the directory order might also be different dependent on the filesystem.
This also allows the code to be a bit closer between the
implementations.
@firewave firewave force-pushed the vf-inc branch 6 times, most recently from f7748a0 to 88bff95 Compare April 26, 2024 15:40
@firewave firewave marked this pull request as ready for review April 26, 2024 15:46
@firewave
Copy link
Collaborator Author

firewave commented May 6, 2024

Any feedback on this? I would like to proceed on this so it is done within this dev cycle. Also so we could maybe do some work on #6097.

Copy link
Owner

@danmar danmar left a comment

Choose a reason for hiding this comment

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

lgtm.

@firewave firewave merged commit 98d56b8 into danmar:main May 26, 2024
@firewave firewave deleted the vf-inc branch May 26, 2024 19:15
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.

3 participants