How to use the ford.sourceform.FortranContainer function in FORD

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
if hasattr(self,'calls'):
                        callval = self.SUBCALL_RE.match(line).group(1)
                        if callval.lower() not in self.calls and callval.lower() not in INTRINSICS:
                            self.calls.append(callval.lower())
                    else:
                        raise Exception("Found procedure call in {}".format(type(self).__name__[7:].upper()))


        if not isinstance(self,FortranSourceFile):
            raise Exception("File ended while still nested.")

    def _cleanup(self):
        raise NotImplementedError()


class FortranCodeUnit(FortranContainer):
    """
    A class on which programs, modules, functions, and subroutines are based.
    """
    def correlate(self,project):
        # Add procedures, interfaces and types from parent to our lists
        if hasattr(self.parent,'all_procs'): self.all_procs.update(self.parent.all_procs)
        self.all_absinterfaces = getattr(self.parent,'all_absinterfaces',{})
        for ai in self.absinterfaces:
            self.all_absinterfaces[ai.name.lower()] = ai
        self.all_types = getattr(self.parent,'all_types',{})
        for dt in self.types:
            self.all_types[dt.name.lower()] = dt
        self.all_vars = getattr(self.parent,'all_vars',{})
        for var in self.variables:
            self.all_vars[var.name.lower()] = var
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
callval = self.SUBCALL_RE.match(line).group(1)
                    if callval.lower() not in self.calls and callval.lower() not in INTRINSICS:
                        self.calls.append(callval.lower())
                else:
                    raise ("Found procedure call in {}".format(type(self).__name__[7:].upper()))


        if not isinstance(self,FortranSourceFile):
            raise Exception("File ended while still nested.")

    def _cleanup(self):
        raise NotImplementedError()



class FortranCodeUnit(FortranContainer):
    """
    A class on which programs, modules, functions, and subroutines are based.
    """
    def correlate(self,project):
        # Add procedures, interfaces and types from parent to our lists
        if hasattr(self.parent,'all_procs'): self.all_procs.update(self.parent.all_procs)
        self.all_absinterfaces = getattr(self.parent,'all_absinterfaces',{})
        for ai in self.absinterfaces:
            self.all_absinterfaces[ai.name.lower()] = ai
        self.all_types = getattr(self.parent,'all_types',{})
        for dt in self.types:
            self.all_types[dt.name.lower()] = dt
        self.all_vars = getattr(self.parent,'all_vars',{})
        for var in self.variables:
            self.all_vars[var.name.lower()] = var
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
def _cleanup(self):
        self.all_procs = {}
        for p in self.routines:
            self.all_procs[p.name.lower()] = p
        for interface in self.interfaces:
            if not interface.abstract:
                self.all_procs[interface.name.lower()] = interface
            if interface.generic:
                for proc in interface.iterator('subroutines', 'functions'):
                    self.all_procs[proc.name.lower()] = proc
        self.process_attribs()
        self.variables = [v for v in self.variables if 'external' not in v.attribs]



class FortranType(FortranContainer):
    """
    An object representing a Fortran derived type and holding all of said type's
    components and type-bound procedures. It also contains information on the
    type's inheritance.
    """
    def _initialize(self,line):
        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:
                if EXTENDS_RE.search(attrib):
                    self.extends = EXTENDS_RE.search(attrib).group(1)
                elif attrib.strip().lower() == "public":
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
if hasattr(self,'modprocedures'):
                self.modprocedures = [obj for obj in self.modprocedures if to_include(obj)]
            if hasattr(self,'modsubroutines'):
                self.modsubroutines = [obj for obj in self.modsubroutines if to_include(obj)]
            if hasattr(self,'modfunctions'):
                self.modfunctions = [obj for obj in self.modfunctions if to_include(obj)]
        # Recurse
        for obj in self.absinterfaces:
            obj.visible = True
        for obj in self.iterator('functions', 'subroutines', 'types', 'interfaces', 'modprocedures', 'modfunctions', 'modsubroutines'):
            obj.visible = True
        for obj in self.iterator('functions', 'subroutines', 'types', 'modprocedures', 'modfunctions', 'modsubroutines'):
            obj.prune()


class FortranSourceFile(FortranContainer):
    """
    An object representing individual files containing Fortran code. A project
    will consist of a list of these objects. In turn, SourceFile objects will
    contains lists of all of that file's contents
    """
    def __init__(self,filepath,settings,preprocessor=None,fixed=False,**kwargs):
        # Hack to prevent FortranBase.__str__ to generate an anchor link to the source file in HTML output.
        self.visible = kwargs.get("incl_src",True)
        self.path = filepath.strip()
        self.name = os.path.basename(self.path)
        self.settings = settings
        self.fixed = fixed
        self.parent = None
        self.modules = []
        self.submodules = []
        self.functions = []
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
else:
            self.parobj = None
            self.settings = None
        self.obj = 'moduleprocedure'
        self.name = name
        self.procedure = None
        self.doc = []
        self.hierarchy = []
        cur = self.parent
        while cur:
            self.hierarchy.append(cur)
            cur = cur.parent
        self.hierarchy.reverse()


class FortranBlockData(FortranContainer):
    """
    An object representing a block-data unit. Now obsolete due to modules,
    block data units allowed variables held in common blocks to be initialized
    outside of an executing program unit.
    """
    def _initialize(self,line):
        self.name = line.group(1)
        if not self.name: self.name = '<em>unnamed</em>'
        self.uses = []
        self.variables = []
        self.types = []
        self.common = []
        self.visible = True
        self.attr_dict = dict()
        self.param_dict = dict()
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
if isinstance(bind,(FortranFunction,FortranSubroutine)): self.num_lines_all += bind.num_lines
                elif isinstance(bind,FortranBoundProcedure):
                    for b in bind.bindings:
                        if isinstance(b,(FortranFunction,FortranSubroutine)): self.num_lines_all += b.num_lines

    def prune(self):
        """
        Remove anything which shouldn't be displayed.
        """
        self.boundprocs = [ obj for obj in self.boundprocs if obj.permission in self.display ]
        self.variables = [ obj for obj in self.variables if obj.permission in self.display ]
        for obj in self.boundprocs + self.variables:
            obj.visible = True


class FortranEnum(FortranContainer):
    """
    An object representing a Fortran enumeration. Contains the individual
    enumerators as variables.
    """
    def _initialize(self,line):
        self.variables = []

    def _cleanup(self):
        prev_val = -1
        for var in self.variables:
            if not var.initial: var.initial = prev_val + 1
            try:
                prev_val = int(var.initial)
            except ValueError:
                raise Exception('Non-integer assigned to enumerator.')
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
self.functions = []
        self.subroutines = []
        self.programs = []
        self.blockdata = []
        self.doc = []
        self.hierarchy = []
        self.obj = 'sourcefile'
        self.display = settings['display']

        source = ford.reader.FortranReader(self.path,settings['docmark'],
                    settings['predocmark'],settings['docmark_alt'],
                    settings['predocmark_alt'],fixed,
                    settings['fixed_length_limit'].lower()=='true',preprocessor,
                    settings['macro'],settings['include'])

        FortranContainer.__init__(self,source,"")
        readobj = open(self.path,'r')
        self.raw_src = readobj.read()
        if self.fixed:
            self.src = highlight(self.raw_src,FortranFixedLexer(),
                                 HtmlFormatter(lineanchors='ln', cssclass='hl'))
        else:
            self.src = highlight(self.raw_src,FortranLexer(),
                                 HtmlFormatter(lineanchors='ln', cssclass='hl'))
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
if hasattr(self,'modprocedures'):
                self.modprocedures = [obj for obj in self.modprocedures if obj.permission in self.display]
            if hasattr(self,'modsubroutines'):
                self.modsubroutines = [obj for obj in self.modsubroutines if obj.permission in self.display]
            if hasattr(self,'modfunctions'):
                self.modfunctions = [obj for obj in self.modfunctions if obj.permission in self.display]
        # Recurse
        for obj in self.absinterfaces:
            obj.visible = True
        for obj in self.functions + self.subroutines + self.types + self.interfaces + getattr(self,'modprocedures',[]) + getattr(self,'modfunctions',[]) + getattr(self,'modsubroutines',[]):
            obj.visible = True
        for obj in self.functions + self.subroutines + self.types + getattr(self,'modprocedures',[]) + getattr(self,'modfunctions',[]) + getattr(self,'modsubroutines',[]):
            obj.prune()


class FortranSourceFile(FortranContainer):
    """
    An object representing individual files containing Fortran code. A project
    will consist of a list of these objects. In turn, SourceFile objects will
    contains lists of all of that file's contents
    """
    def __init__(self,filepath,settings,preprocessor=None,fixed=False):
        self.path = filepath.strip()
        self.name = os.path.basename(self.path)
        self.settings = settings
        self.fixed = fixed
        self.parent = None
        self.modules = []
        self.submodules = []
        self.functions = []
        self.subroutines = []
        self.programs = []
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
self.submodules = []
        self.functions = []
        self.subroutines = []
        self.programs = []
        self.blockdata = []
        self.doc = []
        self.hierarchy = []
        self.obj = 'sourcefile'
        self.display = settings['display']

        source = ford.reader.FortranReader(self.path,settings['docmark'],
                    settings['predocmark'],settings['docmark_alt'],
                    settings['predocmark_alt'],fixed,preprocessor,
                    settings['macro'],settings['include'])

        FortranContainer.__init__(self,source,"")
        readobj = open(self.path,'r')
        self.raw_src = readobj.read()
        if self.fixed:
            self.src = highlight(self.raw_src,FortranFixedLexer(),
                                 HtmlFormatter(lineanchors='ln', cssclass='hl'))
        else:
            self.src = highlight(self.raw_src,FortranLexer(),
                                 HtmlFormatter(lineanchors='ln', cssclass='hl'))
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
if isinstance(bind,(FortranFunction,FortranSubroutine)): self.num_lines_all += bind.num_lines
                elif isinstance(bind,FortranBoundProcedure):
                    for b in bind.bindings:
                        if isinstance(b,(FortranFunction,FortranSubroutine)): self.num_lines_all += b.num_lines

    def prune(self):
        """
        Remove anything which shouldn't be displayed.
        """
        self.boundprocs = [ obj for obj in self.boundprocs if obj.permission in self.display ]
        self.variables = [ obj for obj in self.variables if obj.permission in self.display ]
        for obj in self.boundprocs + self.variables:
            obj.visible = True


class FortranEnum(FortranContainer):
    """
    An object representing a Fortran enumeration. Contains the individual
    enumerators as variables.
    """
    def _initialize(self,line):
        self.variables = []

    def _cleanup(self):
        prev_val = -1
        for var in self.variables:
            if not var.initial: var.initial = prev_val + 1
            try:
                prev_val = int(var.initial)
            except ValueError:
                raise Exception('Non-integer assigned to enumerator.')