camfort / fortran-src

Fortran parsing and static analysis infrastructure
https://hackage.haskell.org/package/fortran-src
Other
48 stars 20 forks source link

Use '.' to separate scope from variable name instead of '_'. #280

Open dorchard opened 1 year ago

dorchard commented 1 year ago

At the moment, the renaming (Language.Fortran.Analysis.Renaming) generates names that use the scope and name and a freshid, but using _ to separate all of these. However since _ is a valid part of an identifier I think this is a little confusing when looking at outputs. Consider:

function area_of_circle(r) result(area)
  real, parameter :: pi = 3.14e0
  real, intent(in) :: r
  real :: area
  area = ((r * r) * pi)
end function area_of_circle

then we get things like


_area_of_circle_1                - Function
area_of_circle_area_2           Real 4 Variable
area_of_circle_pi_4             Real 4 Parameter
area_of_circle_r_3              Real 4 Variable

What about if instead we used .?, i.e.,

% fortran-src program.f90 --typecheck

.area_of_circle_1                - Function
area_of_circle.area_2           Real 4 Variable
area_of_circle.pi_4             Real 4 Parameter
area_of_circle.r_3              Real 4 Variable

Does that have any problems with generated names wanting to be used like actually variables anywhere (i.e., in generated code)? It doesn't appear so.

RaoulHC commented 1 year ago

I think more than being being confusing it could potentially lead to clashes couldn't it? @raehik eventually figured out that in #190 that some weird behaviour I was getting was due to the renaming not being quite unique.

I think for internal names using . would be fine, but for generated code this might cause problems with the syntax for field accessors. Using . is non standard but widely used (on account of virtually every other language using .).