8000 Add a static analysis check to catch duplicated variables in `constructorAssign` directives by abensonca · Pull Request #849 · galacticusorg/galacticus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add a static analysis check to catch duplicated variables in constructorAssign directives #849

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

Merged
merged 1 commit into from
May 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion scripts/aux/staticAnalyzer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
my $depth = 0;
my $status = 0;
while ( $node ) {
# Class/type pointers in derived types should be null initialized.
if ( $node->{'type'} eq "declaration" ) {
foreach my $declaration ( @{$node->{'declarations'}} ) {
if ( $node->{'parent'}->{'type'} eq "type" && ( $declaration->{'intrinsic'} eq "type" || $declaration->{'intrinsic'} eq "class" ) && grep {$_ eq "pointer"} @{$declaration->{'attributes'}} ) {
# Class/type pointers in derived types should be null initialized.
for(my $i=0;$i<scalar(@{$declaration->{'variables'}});++$i) {
next
if ( $declaration->{'variables'}->[$i] =~ m/=>null\(\)$/ );
Expand All @@ -34,6 +34,20 @@
}
}
}
# Look for duplicated assignments in `constructorAssign` directives.
if ( $node->{'type'} eq "constructorAssign" ) {
my @variables = split(/\s*,\s*/,$node->{'directive'}->{'variables'});
my %countAssignments;
foreach my $variable ( @variables ) {
++$countAssignments{$variable};
}
foreach my $variable ( keys(%countAssignments) ) {
if ( $countAssignments{$variable} > 1 ) {
print "Duplicated assignment of '".$variable."' in `constructorAssign` directive in file '".$fileName."'\n";
$status = 1;
}
}
}
# Walk to the next node in the tree.
$node = &Galacticus::Build::SourceTree::Walk_Tree($node,\$depth);
}
Expand Down
0