How to use FORD - 10 common examples

To help you get started, we’ve selected a few FORD examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
elif tmp_attribs[i].lower() == "parameter": parameter = True
            elif tmp_attribs[i].lower().replace(' ','') == "intent(in)":
                intent = 'in'
            elif tmp_attribs[i].lower().replace(' ','') == "intent(out)":
                intent = 'out'
            elif tmp_attribs[i].lower().replace(' ','') == "intent(inout)":
                intent = 'inout'
            else: attribs.append(tmp_attribs[i])
    else:
        declarestr = ATTRIBSPLIT2_RE.match(rest).group(2)
    declarations = ford.utils.paren_split(",",declarestr)

    varlist = []
    for dec in declarations:
        dec = re.sub(" ","",dec)
        split = ford.utils.paren_split('=',dec)
        if len(split) > 1:
            name = split[0]
            if split[1][0] == '>':
                initial = split[1][1:]
                points = True
            else:
                initial = split[1]
                points = False
        else:
            name = dec.strip()
            initial = None
            points = False

        if initial:
            initial = COMMA_RE.sub(', ',initial)
            search_from = 0
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
elif attr == 'dimension' or attr == 'allocatable' or attr == 'pointer':
                        names = ford.utils.paren_split(',',match.group(2))
                        for name in names:
                            name = name.strip().lower()
                            i = name.index('(')
                            n = name[:i]
                            sh = name[i:]
                            if n in self.attr_dict:
                                self.attr_dict[n].append(attr+sh)
                            else:
                                self.attr_dict[n] = [attr+sh]
                    else:
                        stmnt = match.group(2)
                        if attr == 'parameter':
                            stmnt = stmnt[1:-1].strip()
                        names = ford.utils.paren_split(',',stmnt)
                        search_from = 0
                        while QUOTES_RE.search(attr[search_from:]):
                            num = int(QUOTES_RE.search(attr[search_from:]).group()[1:-1])
                            attr = attr[0:search_from] + QUOTES_RE.sub(self.strings[num],attr[search_from:],count=1)
                            search_from += QUOTES_RE.search(attr[search_from:]).end(0)
                        for name in names:
                            if attr == 'parameter':
                                split = ford.utils.paren_split('=',name)
                                name = split[0].strip().lower()
                                self.param_dict[name] = split[1]
                            name = name.strip().lower()
                            if name in self.attr_dict:
                                self.attr_dict[name].append(attr)
                            else:
                                self.attr_dict[name] = [attr]
                elif attr.lower() == 'data' and self.obj == 'sourcefile':
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
def _initialize(self,line):
        self.name = line.group(1)
        if not self.name: self.name = ''
        self.other_uses = []
        self.variables = [v.strip() for v in ford.utils.paren_split(',',line.group(2))]
        self.visible = True
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
elif attr == 'dimension' or attr == 'allocatable' or attr == 'pointer':
                        names = ford.utils.paren_split(',',match.group(2))
                        for name in names:
                            name = name.strip().lower()
                            i = name.index('(')
                            n = name[:i]
                            sh = name[i:]
                            if n in self.attr_dict:
                                self.attr_dict[n].append(attr+sh)
                            else:
                                self.attr_dict[n] = [attr+sh]
                    else:
                        stmnt = match.group(2)
                        if attr == 'parameter':
                            stmnt = stmnt[1:-1].strip()
                        names = ford.utils.paren_split(',',stmnt)
                        search_from = 0
                        while QUOTES_RE.search(attr[search_from:]):
                            num = int(QUOTES_RE.search(attr[search_from:]).group()[1:-1])
                            attr = attr[0:search_from] + QUOTES_RE.sub(self.strings[num],attr[search_from:],count=1)
                            search_from += QUOTES_RE.search(attr[search_from:]).end(0)
                        for name in names:
                            if attr == 'parameter':
                                split = ford.utils.paren_split('=',name)
                                name = split[0].strip().lower()
                                self.param_dict[name] = split[1]
                            name = name.strip().lower()
                            if name in self.attr_dict:
                                self.attr_dict[name].append(attr)
                            else:
                                self.attr_dict[name] = [attr]
                elif attr.lower() == 'data' and self.obj == 'sourcefile':
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
self.attr_dict[n].append(attr+sh)
                            else:
                                self.attr_dict[n] = [attr+sh]
                    else:
                        stmnt = match.group(2)
                        if attr == 'parameter':
                            stmnt = stmnt[1:-1].strip()
                        names = ford.utils.paren_split(',',stmnt)
                        search_from = 0
                        while QUOTES_RE.search(attr[search_from:]):
                            num = int(QUOTES_RE.search(attr[search_from:]).group()[1:-1])
                            attr = attr[0:search_from] + QUOTES_RE.sub(self.strings[num],attr[search_from:],count=1)
                            search_from += QUOTES_RE.search(attr[search_from:]).end(0)
                        for name in names:
                            if attr == 'parameter':
                                split = ford.utils.paren_split('=',name)
                                name = split[0].strip().lower()
                                self.param_dict[name] = split[1]
                            name = name.strip().lower()
                            if name in self.attr_dict:
                                self.attr_dict[name].append(attr)
                            else:
                                self.attr_dict[name] = [attr]
                elif attr.lower() == 'data' and self.obj == 'sourcefile':
                    # TODO: This is just a fix to keep FORD from crashing on encountering a block data structure. At some point I should actually implement support for them.
                    continue
                else:
                    raise Exception("Found {} statement in {}".format(attr.upper(),type(self).__name__[7:].upper()))
            elif self.END_RE.match(line):
                if isinstance(self,FortranSourceFile):
                    raise Exception("END statement outside of any nesting")
                endtype = self.END_RE.match(line).group(1)
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
raise Exception("CONTAINS statement in {}".format(type(self).__name__[7:].upper()))
            elif line.lower() == "public": permission = "public"
            elif line.lower() == "private": permission = "private"
            elif line.lower() == "protected": permission = "protected"
            elif line.lower() == "sequence":
                if type(self) == FortranType: self.sequence = True
            elif self.ATTRIB_RE.match(line) and blocklevel == 0:
                match = self.ATTRIB_RE.match(line)
                attr = match.group(1).lower().replace(" ", "")
                if len(attr) >= 4 and attr[0:4].lower() == 'bind':
                    attr = attr.replace(",",", ")
                if hasattr(self,'attr_dict'):
                    if attr == 'data':
                        pass
                    elif attr == 'dimension' or attr == 'allocatable' or attr == 'pointer':
                        names = ford.utils.paren_split(',',match.group(2))
                        for name in names:
                            name = name.strip().lower()
                            i = name.index('(')
                            n = name[:i]
                            sh = name[i:]
                            if n in self.attr_dict:
                                self.attr_dict[n].append(attr+sh)
                            else:
                                self.attr_dict[n] = [attr+sh]
                    else:
                        stmnt = match.group(2)
                        if attr == 'parameter':
                            stmnt = stmnt[1:-1].strip()
                        names = ford.utils.paren_split(',',stmnt)
                        search_from = 0
                        while QUOTES_RE.search(attr[search_from:]):
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
"""
    Returns a list of variables declared in the provided line of code. The
    line of code should be provided as a string.
    """
    vartype, kind, strlen, proto, rest = parse_type(line,parent.strings,parent.settings)
    attribs = []
    intent = ""
    optional = False
    permission = inherit_permission
    parameter = False

    attribmatch = ATTRIBSPLIT_RE.match(rest)
    if attribmatch:
        attribstr = attribmatch.group(1).strip()
        declarestr = attribmatch.group(2).strip()
        tmp_attribs = ford.utils.paren_split(",",attribstr)
        for i in range(len(tmp_attribs)):
            tmp_attribs[i] = tmp_attribs[i].strip()
            if tmp_attribs[i].lower() == "public": permission = "public"
            elif tmp_attribs[i].lower() == "private": permission = "private"
            elif tmp_attribs[i].lower() == "protected": permission = "protected"
            elif tmp_attribs[i].lower() == "optional": optional = True
            elif tmp_attribs[i].lower() == "parameter": parameter = True
            elif tmp_attribs[i].lower().replace(' ','') == "intent(in)":
                intent = 'in'
            elif tmp_attribs[i].lower().replace(' ','') == "intent(out)":
                intent = 'out'
            elif tmp_attribs[i].lower().replace(' ','') == "intent(inout)":
                intent = 'inout'
            else: attribs.append(tmp_attribs[i])
    else:
        declarestr = ATTRIBSPLIT2_RE.match(rest).group(2)
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
elif tmp_attribs[i].lower() == "parameter": parameter = True
            elif tmp_attribs[i].lower().replace(' ','') == "intent(in)":
                intent = 'in'
            elif tmp_attribs[i].lower().replace(' ','') == "intent(out)":
                intent = 'out'
            elif tmp_attribs[i].lower().replace(' ','') == "intent(inout)":
                intent = 'inout'
            else: attribs.append(tmp_attribs[i])
    else:
        declarestr = ATTRIBSPLIT2_RE.match(rest).group(2)
    declarations = ford.utils.paren_split(",",declarestr)

    varlist = []
    for dec in declarations:
        dec = re.sub(" ","",dec)
        split = ford.utils.paren_split('=',dec)
        if len(split) > 1:
            name = split[0]
            if split[1][0] == '>':
                initial = split[1][1:]
                points = True
            else:
                initial = split[1]
                points = False
        else:
            name = dec.strip()
            initial = None
            points = False

        if initial:
            initial = COMMA_RE.sub(', ',initial)
            search_from = 0
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
return []

    def __len__(self):
        return 0

    def __contains__(self, item):
        return False

    def __getattr__(self, name):
        return []

    def __str__(self):
        return self.name


class GenericSource(FortranBase):
    """
    Represent a non-Fortran source file. The contents of the file will
    not be analyzed, but documentation can be extracted.
    """

    def __init__(self, filename, settings):
        self.obj = 'sourcefile'
        self.parobj = None
        self.parent = None
        self.hierarchy = []
        self.settings = settings
        self.num_lines = 0
        extra_filetypes = settings['extra_filetypes'][filename.split('.')[-1]]
        comchar = extra_filetypes[0]
        if (len(extra_filetypes)>1):
            self.lexer_str = extra_filetypes[1]
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
elif attr[0:6] == 'intent':
                    var.intent = attr[7:-1]
                elif DIM_RE.match(attr) and ('pointer' in attr or 'allocatable' in attr):
                    i = attr.index('(')
                    var.attribs.append(attr[0:i])
                    var.dimension = attr[i:]
                elif attr == 'parameter':
                    var.attribs.append(attr)
                    var.initial = self.param_dict[var.name.lower()]
                else:
                    var.attribs.append(attr)
        del self.attr_dict



class FortranCommon(FortranBase):
    """
    An object representing a common block. This is a legacy feature.
    """
    def _initialize(self,line):
        self.name = line.group(1)
        if not self.name: self.name = ''
        self.other_uses = []
        self.variables = [v.strip() for v in ford.utils.paren_split(',',line.group(2))]
        self.visible = True

    def correlate(self,project):
        for i in range(len(self.variables)):
            if self.variables[i] in self.parent.all_vars:
                self.variables[i] = self.parent.all_vars[self.variables[i]]
                try:
                    self.parent.variables.remove(self.variables[i])