예제 #1
0
 def sfe_to_document(self, sfe):
     """Get the document correspond to :param sfe: source file.
     Can create the document if needed."""
     assert sfe != 0
     doc = self._fe_map.get(sfe, None)
     if doc is None:
         # Could be a document from outside...
         filename = pyutils.name_image(files_map.Get_File_Name(sfe))
         if not os.path.isabs(filename):
             dirname = pyutils.name_image(files_map.Get_Directory_Name(sfe))
             filename = os.path.join(dirname, filename)
         doc = self.create_document_from_sfe(sfe, filename)
     return doc
예제 #2
0
 def x_show_all_files(self):
     res = []
     for fe in range(1, files_map.Get_Last_Source_File_Entry() + 1):
         doc = self._fe_map.get(fe, None)
         res.append({
             "fe":
             fe,
             "uri":
             doc.uri if doc is not None else None,
             "name":
             pyutils.name_image(files_map.Get_File_Name(fe)),
             "dir":
             pyutils.name_image(files_map.Get_Directory_Name(fe)),
         })
     return res
예제 #3
0
 def obsolete_dependent_units(self, unit, antideps):
     """Obsolete units that depends of :param unit:"""
     udeps = antideps.get(unit, None)
     if udeps is None:
         # There are no units.
         return
     # Avoid infinite recursion
     antideps[unit] = None
     for un in udeps:
         log.debug("obsolete %d %s", un,
                   pyutils.name_image(nodes.Get_Identifier(un)))
         # Recurse
         self.obsolete_dependent_units(un, antideps)
         if nodes.Set_Date_State(un) == nodes.Date_State.Disk:
             # Already obsolete!
             continue
         # FIXME: just de-analyze ?
         nodes.Set_Date_State(un, nodes.Date_State.Disk)
         sem_lib.Free_Dependence_List(un)
         loc = nodes.Get_Location(un)
         fil = files_map.Location_To_File(loc)
         pos = files_map.Location_File_To_Pos(loc, fil)
         line = files_map.Location_File_To_Line(loc, fil)
         col = files_map.Location_File_Line_To_Offset(loc, fil, line)
         nodes.Set_Design_Unit_Source_Pos(un, pos)
         nodes.Set_Design_Unit_Source_Line(un, line)
         nodes.Set_Design_Unit_Source_Col(un, col)
예제 #4
0
 def x_get_all_entities(self):
     res = []
     lib = libraries.Get_Libraries_Chain()
     while lib != nodes.Null_Iir:
         files = nodes.Get_Design_File_Chain(lib)
         ents = []
         while files != nodes.Null_Iir:
             units = nodes.Get_First_Design_Unit(files)
             while units != nodes.Null_Iir:
                 unitlib = nodes.Get_Library_Unit(units)
                 if nodes.Get_Kind(
                         unitlib) == nodes.Iir_Kind.Entity_Declaration:
                     ents.append(unitlib)
                 units = nodes.Get_Chain(units)
             files = nodes.Get_Chain(files)
         ents = [pyutils.name_image(nodes.Get_Identifier(e)) for e in ents]
         lib_name = pyutils.name_image(nodes.Get_Identifier(lib))
         res.extend([{"name": n, "library": lib_name} for n in ents])
         lib = nodes.Get_Chain(lib)
     return res
예제 #5
0
파일: symbols.py 프로젝트: umarcor/ghdl
def get_symbols(fe, n):
    if n == nodes.Null_Iir:
        return None
    k = nodes.Get_Kind(n)
    if k == nodes.Iir_Kind.Design_Unit:
        return get_symbols(fe, nodes.Get_Library_Unit(n))
    m = SYMBOLS_MAP.get(k, None)
    if m is None:
        raise AssertionError("get_symbol: unhandled {}".format(
            pyutils.kind_image(k)))
    kind = m["kind"]
    if kind is None:
        return None
    if k in [
            nodes.Iir_Kind.Procedure_Declaration,
            nodes.Iir_Kind.Function_Declaration
    ]:
        # Discard implicit declarations.
        if nodes.Get_Implicit_Definition(n) < nodes.Iir_Predefined.PNone:
            return None
        if nodes.Get_Has_Body(n):
            # Use the body instead.
            # FIXME: but get interface from the spec!
            return None
    res = {"kind": kind}
    detail = m.get("detail")
    if detail is not None:
        res["detail"] = detail
    # Get the name
    if k in [nodes.Iir_Kind.Function_Body, nodes.Iir_Kind.Procedure_Body]:
        nid = nodes.Get_Identifier(nodes.Get_Subprogram_Specification(n))
    else:
        nid = nodes.Get_Identifier(n)
    if nid == name_table.Null_Identifier:
        name = None
    else:
        name = pyutils.name_image(nid)
    # Get the range.  Use elocations when possible.
    if k in (
            nodes.Iir_Kind.Architecture_Body,
            nodes.Iir_Kind.Entity_Declaration,
            nodes.Iir_Kind.Package_Declaration,
            nodes.Iir_Kind.Package_Body,
            nodes.Iir_Kind.Component_Declaration,
            nodes.Iir_Kind.Process_Statement,
            nodes.Iir_Kind.Sensitized_Process_Statement,
            nodes.Iir_Kind.If_Generate_Statement,
            nodes.Iir_Kind.For_Generate_Statement,
    ):
        start_loc = elocations.Get_Start_Location(n)
        end_loc = elocations.Get_End_Location(n)
        if end_loc == files_map.No_Location:
            # Can happen in case of parse error
            end_loc = start_loc
    else:
        start_loc = nodes.Get_Location(n)
        end_loc = start_loc + name_table.Get_Name_Length(nid)
    res["range"] = {
        "start": location_to_position(fe, start_loc),
        "end": location_to_position(fe, end_loc),
    }

    # Gather children.
    # FIXME: should we use a list of fields to inspect ?
    children = []
    # if nodes_meta.Has_Generic_Chain(k):
    #    children.extend(get_symbols_chain(fe, nodes.Get_Generic_Chain(n)))
    # if nodes_meta.Has_Port_Chain(k):
    #    children.extend(get_symbols_chain(fe, nodes.Get_Port_Chain(n)))
    # if nodes_meta.Has_Interface_Declaration_Chain(k):
    #    children.extend(get_symbols_chain(fe, nodes.Get_Interface_Declaration_Chain(n)))
    if k in (nodes.Iir_Kind.Package_Declaration, nodes.Iir_Kind.Package_Body):
        children.extend(get_symbols_chain(fe, nodes.Get_Declaration_Chain(n)))
    if nodes_meta.Has_Concurrent_Statement_Chain(k):
        children.extend(
            get_symbols_chain(fe, nodes.Get_Concurrent_Statement_Chain(n)))
    if nodes_meta.Has_Generate_Statement_Body(k):
        children.extend(
            get_symbols_chain(
                fe,
                nodes.Get_Concurrent_Statement_Chain(
                    nodes.Get_Generate_Statement_Body(n)),
            ))

    if children:
        res["children"] = children
    else:
        # Discard anonymous symbols without children.
        if name is None:
            return None
    res["name"] = name if name is not None else "<anon>"
    return res