Skip to content
GitLab
    • GitLab: the DevOps platform
    • Explore GitLab
    • Install GitLab
    • How GitLab compares
    • Get started
    • GitLab docs
    • GitLab Learn
  • Pricing
  • Talk to an expert
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
    Projects Groups Snippets
  • Sign up now
  • Login
  • Sign in / Register
  • lfortran lfortran
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 432
    • Issues 432
    • List
    • Boards
    • Service Desk
    • Milestones
    • Requirements
  • Merge requests 72
    • Merge requests 72
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • lfortranlfortran
  • lfortranlfortran
  • Issues
  • #201
Closed
Open
Issue created Aug 31, 2020 by Ondřej Čertík@certikOwner

Do not print parentheses if not needed

Currently the formatter puts parentheses around expressions even if they are not needed:

$ lfortran fmt integration_tests/program_01.f90 
program program_01
integer, parameter :: dp=kind(0.d0)
real :: a
integer :: i
print *, "Normal random numbers:"
do i = 1, 10
    call rand(a)
    print *, a
end do

contains

    subroutine rand(x)
    real, intent(out) :: x
    logical, save :: first=.true.
    real, save :: u(2)
    real :: r2
    if (first) then
        do
            call random_number(u)
            u = ((2)*(u)) - (1)
            r2 = sum((u)**(2))
            if (((r2)<(1)).and.((r2)>(0))) then
                exit
            end if
        end do
        u = (u)*(sqrt(((-(2))*(log(r2)))/(r2)))
        x = u(1)
    else
        x = u(2)
    end if
    first = .not.(first)
    end subroutine rand

end program program_01

We should use Fortran semantics to only put parentheses when they are needed.

Assignee
Assign to
Time tracking