Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Malmahrouqi3
Copy link
Collaborator

@Malmahrouqi3 Malmahrouqi3 commented Jun 16, 2025

Description

This is subsequent to (#882) with the mere addition of filtering out inline comments and commented lines. For the PMD details, check out the original issue (#646)

To show off the difference:
Filter-off: pmd-old branch https://github.com/Malmahrouqi3/MFC-mo2/actions/runs/15693861383/job/44214858621
Filter-on: pmd-new branch https://github.com/Malmahrouqi3/MFC-mo2/actions/runs/15694477828/job/44216673771

Improves PMD.

else
# Overwrite the original file with the processed content
mv "$TMP_FILE" "$file"
echo -e "Successfully processed $file"
Copy link
Member

Choose a reason for hiding this comment

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

remove

@Malmahrouqi3
Copy link
Collaborator Author

Malmahrouqi3 commented Jun 16, 2025

@sbryngelson the number of violations is identical (63) whether the filter is on or off.

@sbryngelson
Copy link
Member

strange

@Malmahrouqi3
Copy link
Collaborator Author

I guess it should now presumably detect more duplicate lines if they are exactly the same operation but split out into lines differently.

q_sf(j, k, l) = q_sf(j, k, l)+q_prim_vf0(mom_idx%beg)%sf(j, k, l)*fd_coeff_x(r, j)*q_prim_vf0(mom_idx%beg)%sf(r+j, k, l)+q_prim_vf0(mom_idx%beg+1)%sf(j, k, l)*fd_coeff_y(r, k)*q_prim_vf0(mom_idx%beg)%sf(j, r+k, l)+q_prim_vf0(mom_idx%end)%sf(j, k, l)*fd_coeff_z(r, l)*q_prim_vf0(mom_idx%beg)%sf(j, k, r+l)/y_cc(k)

@sbryngelson
Copy link
Member

yes that's what i was thinking. you could even strip spaces (maybe?)

@sbryngelson
Copy link
Member

this is actually a very valuable tool!

@Malmahrouqi3
Copy link
Collaborator Author

I left behind = .or. .and. and few subtle things.
Other than that, all spaces should be taken off around math/comparison operators, inside indexing parentheses and brackets.

@sbryngelson
Copy link
Member

I left behind = .or. .and. and few subtle things. Other than that, all spaces should be taken off around math/comparison operators, inside indexing parentheses and brackets.

yes agreed. so you already did this or not yet?

@Malmahrouqi3
Copy link
Collaborator Author

yup, you can check out the last commit PMD check.

@Malmahrouqi3
Copy link
Collaborator Author

Filter Full Implementation

                  sed -E '
                    # First handle & continuation style (modern Fortran)
                    :ampersand_loop
                    /&[[:space:]]*$/ {
                      N
                      s/&[[:space:]]*\n[[:space:]]*(&)?/ /g
                      tampersand_loop
                    }

                    # Handle fixed-form continuation (column 6 indicator)
                    :fixed_form_loop
                    /^[[:space:]]{0,5}[^[:space:]!&]/ {
                      N
                      s/\n[[:space:]]{5}[^[:space:]]/ /g
                      tfixed_form_loop
                    }

                    # Remove any remaining continuation markers
                    s/&//g

                    # Normalize spacing - replace multiple spaces with single space
                    s/[[:space:]]{2,}/ /g

                    # Remove spaces around mathematical operators
                    s/[[:space:]]*\*[[:space:]]*/*/g
                    s/[[:space:]]*\+[[:space:]]*/+/g
                    s/[[:space:]]*-[[:space:]]*/-/g
                    s/[[:space:]]*\/[[:space:]]*/\//g
                    s/[[:space:]]*\*\*[[:space:]]*/\*\*/g

                    # Remove spaces in common Fortran constructs (array indexing, function calls)
                    s/\([[:space:]]*([^,)[:space:]]+)[[:space:]]*,/(\1,/g      # First argument
                    s/,[[:space:]]*([^,)[:space:]]+)[[:space:]]*,/,\1,/g       # Middle arguments
                    s/,[[:space:]]*([^,)[:space:]]+)[[:space:]]*\)/,\1)/g      # Last argument
                    s/\([[:space:]]*([^,)[:space:]]+)[[:space:]]*\)/(\1)/g     # Single argument

                    # Remove spaces around brackets and parentheses
                    s/\[[[:space:]]*/</g
                    s/\[[[:space:]]*/>/g
                    s/\[[[:space:]]*/</g
                    s/[[:space:]]*\]/]/g
                    s/\([[:space:]]*/(/g
                    s/[[:space:]]*\)/)/g

                    # Remove spaces around comparison operators
                    s/[[:space:]]*<=[[:space:]]*/</g
                    s/[[:space:]]*>=[[:space:]]*/>/g
                    s/[[:space:]]*<[[:space:]]*/</g
                    s/[[:space:]]*>[[:space:]]*/>/g
                    s/[[:space:]]*==[[:space:]]*/==/g

                    # Remove full-line comments
                    /^\s*!/d
                    /^[cC*dD]/d
                    /^[ \t]*[cC*dD]/d

                    # Remove end-of-line comments, preserving quoted strings
                    s/([^"'\''\\]*("[^"]*")?('\''[^'\'']*'\''?)?[^"'\''\\]*)[!].*$/\1/
                  ' "$file" > "$TMP_FILE"

@sbryngelson
Copy link
Member

i just realized that once you have removed any line continuations, you can delete all blank lines and spaces in the source code... they don't actually mean anything and the code doesn't have to compile, it just has to be parsed by PMD. by doing this we ensure we find all duplicate patterns

@Malmahrouqi3
Copy link
Collaborator Author

Yup yup, it is kinda reasonable to think this way if you would rather unveil longer patterns than just ones with few lines.

@sbryngelson
Copy link
Member

sbryngelson commented Jun 18, 2025

Yup yup, it is kinda reasonable to think this way if you would rather unveil longer patterns than just ones with few lines.

cool should be easier to do this as well. don't see a new commit yet but will look at the PR once it's updated. I did notice that the current run appears to have shorter "worst" offenders at the top of PMD output (fewer tokens). is this because you stripped their whitespace / comments and the code is the same as it was before (so # tokens dropped but the Fortran part is the same)? or is it not finding the worst offenders it was a few commits ago? I remember seeing > 200 tokens as the worst cases

Edit: I checked myself. The violations (the first few worst ones) are the same, so you didn't break anything 👍 .

@Malmahrouqi3
Copy link
Collaborator Author

Added to remove blank lines
/^[[:space:]]*$/d

@sbryngelson
Copy link
Member

Looks pretty good to me. Do you have any other modifications planned?

@Malmahrouqi3
Copy link
Collaborator Author

Nope

@sbryngelson sbryngelson merged commit 82b2dea into MFlowCode:master Jun 18, 2025
18 checks passed
prathi-wind pushed a commit to prathi-wind/MFC-prathi that referenced this pull request Jul 13, 2025
Co-authored-by: mohdsaid497566 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants