camfort / fortran-src

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

Localise module maps #286

Closed dorchard closed 2 months ago

dorchard commented 2 months ago

A problem arose in CamFort with the location of declarations being misreported to the wrong file (https://github.com/camfort/camfort/issues/185). It turns out this comes down to the structure of mod file analysis, where all the used modules get their name space inserted into the module map and so it cannot be distinguished whether a variable was declared in this module or an imported one. This PR fixes this by adding information into the NameType data structure about whether a variable is Local or Imported. A module map can then be 'localised' with localisedModuleMap which removes from a mod map any imported declarations. This fixes the bug in CamFort. An accompanying test was added in ModFileSpec

The genUniqNameToFilenameMap :: ModFiles -> M.Map F.Name String applies this localisation.

dorchard commented 2 months ago

(note this is rebased off https://github.com/camfort/fortran-src/pull/285)