Example #1
0
 def chk_context_clauses(self, parent, level):
     for n in thinutils.chain_iter(iirs.Get_Context_Items(parent)):
         k = iirs.Get_Kind(n)
         if k == iirs.Iir_Kind.Library_Clause:
             self.chk_level(n, elocs.Get_Start_Location(n), level)
             # Check: same line for next clauses
         elif k == iirs.Iir_Kind.Use_Clause:
             self.chk_level(n, iirs.Get_Location(n), level)
             # Check: same line for next clauses
         else:
             assert False, "unhandled context clause"
 def check(self, input, file):
     if self._allowed_id is None:
         self._allowed_id = [
             thin.Get_Identifier(n) for n in self._allowed_name
         ]
     for unit in thinutils.chain_iter(iirs.Get_First_Design_Unit(file)):
         for n in thinutils.chain_iter(iirs.Get_Context_Items(unit)):
             if iirs.Get_Kind(n) != iirs.Iir_Kind.Use_Clause:
                 continue
             cl = n
             while cl != thin.Null_Iir:
                 self.check_clause(cl)
                 cl = iirs.Get_Use_Clause_Chain(cl)
 def check(self, input, file):
     for unit in thinutils.chain_iter(iirs.Get_First_Design_Unit(file)):
         # Extract the list of clauses
         clauses = []
         for cl in thinutils.chain_iter(iirs.Get_Context_Items(unit)):
             k = iirs.Get_Kind(cl)
             if k == iirs.Iir_Kind.Library_Clause:
                 clauses.extend(self.extract_library(cl))
             elif k == iirs.Iir_Kind.Use_Clause:
                 clauses.extend(self.extract_use(cl))
             else:
                 assert False, "unknown context clause"
         if clauses:
             self.check_group(clauses)
Example #4
0
def extract_packages_from_context_clause(dsgn):
    """Return a list of package declarations from design unit dsgn (which must
    have been analyzed)."""
    res = []
    for n in thinutils.chain_iter(iirs.Get_Context_Items(dsgn)):
        if iirs.Get_Kind(n) != iirs.Iir_Kind.Use_Clause:
            continue
        cl = n
        while cl != thin.Null_Iir:
            name = iirs.Get_Selected_Name(cl)
            if iirs.Get_Kind(name) == iirs.Iir_Kind.Selected_By_All_Name:
                name = iirs.Get_Prefix(name)
            name = iirs.Get_Named_Entity(name)
            assert name != thin.Null_Iir, "unit not analyzed"
            if iirs.Get_Kind(name) == iirs.Iir_Kind.Package_Declaration:
                res.append(name)
            cl = iirs.Get_Use_Clause_Chain(cl)
    return res
Example #5
0
 def check(self, input, ast):
     # Build the list of use'd packages.
     pkgs = []
     for n in thinutils.chain_iter(iirs.Get_Context_Items(ast)):
         if iirs.Get_Kind(n) != iirs.Iir_Kind.Use_Clause:
             continue
         cl = n
         while cl != thin.Null_Iir:
             name = iirs.Get_Selected_Name(cl)
             if iirs.Get_Kind(name) == iirs.Iir_Kind.Selected_By_All_Name:
                 name = iirs.Get_Prefix(name)
             p = iirs.Get_Named_Entity(name)
             if iirs.Get_Kind(p) == iirs.Iir_Kind.Package_Declaration:
                 pkgs.append(p)
             cl = iirs.Get_Use_Clause_Chain(cl)
     # Check dependences
     for du in thinutils.list_iter(iirs.Get_Dependence_List(ast)):
         lu = iirs.Get_Library_Unit(du)
         if iirs.Get_Kind(lu) == iirs.Iir_Kind.Package_Declaration:
             if lu != thin.Standard_Package.value and lu not in pkgs:
                 self.error(
                     Location.from_node(ast),
                     "unit depends on '{}' but not by a use clause".format(
                         nodeutils.get_identifier_str(lu)))