Fortran-FOSS-Programmers / ford

Automatically generates FORtran Documentation from comments within the code.
https://forddocs.readthedocs.io
GNU General Public License v3.0
402 stars 131 forks source link

Some attributes are missing from derived types #624

Closed mscfd closed 5 months ago

mscfd commented 5 months ago

In the example listed in https://github.com/Fortran-FOSS-Programmers/ford/issues/620#issuecomment-1959103633 the "abstract" attribute from derived type "base" is missing in its type page.

The reason is that "class FortranType" in sourceform.py stores the list of attributes as "self.attributes", but template type_page.html expects "self.attribs".

After adding the last block in the code snippet below to set self.attribs in "_initialize" of "FortranType", the abstract keyword appears as expected:

    def _initialize(self, line: re.Match) -> None:
        self.name = line.group(2)
        self.extends = None
        self.attributes = []
        if line.group(1):
            attribstr = line.group(1)[1:].strip()
            attriblist = self.SPLIT_RE.split(attribstr.strip())
            for attrib in attriblist:
                attrib_lower = attrib.strip().lower()
                if extends := EXTENDS_RE.search(attrib):
                    self.extends = extends["base"]
                elif attrib_lower in ["public", "private"]:
                    self.permission = attrib_lower
                elif attrib_lower == "external":
                    self.attributes.append("external")
                else:
                    self.attributes.append(attrib.strip())

            if len(self.attributes) == 0:
                self.attribs = []
            else:
                self.attribs = [""] + self.attributes

Note that I prepend an empty string to convince the join(", ") in type_page.html to prepend a commata if the list is non-empty. This is a hack, there msut be a better way to do this.