def check_assocs(self, n, inters, assocs): if assocs == thin.Null_Iir: # Also cover the case of no interfaces return inter = inters for assoc in thinutils.chain_iter(assocs): if iirs.Get_Kind(assoc) \ == iirs.Iir_Kind.Association_Element_By_Individual: continue formal = iirs.Get_Formal(assoc) if formal == thin.Null_Iir: self.error( Location.from_node(assoc), "association by position for {}".format( nodeutils.get_identifier_str(inter))) # Should the tool report all errors ? return assoc_inter = thin.Iirs_Utils.Get_Interface_Of_Formal(formal) while assoc_inter != inter: if inter == thin.Null_Iir: self.error( Location.from_node(assoc), "incorrect association order for {}".format( nodeutils.get_identifier_str(assoc_inter))) return inter = iirs.Get_Chain(inter) if iirs.Get_Whole_Association_Flag(assoc): inter = iirs.Get_Chain(inter)
def check(self, input, node): if nodeutils.is_port(node): s = nodeutils.get_identifier_str(node) self.check_name(node, s) elif iirs.Get_Kind(node) == iirs.Iir_Kind.Signal_Declaration: s = nodeutils.get_identifier_str(node) self.check_name(node, s)
def check(self, input, dsgn): if self._standard_ids is None: self._standard_ids = self.gather_identifiers( thin.Standard_Package.value) pkgs = nodeutils.extract_packages_from_context_clause(dsgn) for pkg in pkgs: lib = iirs.Get_Library( iirs.Get_Design_File(iirs.Get_Design_Unit(pkg))) if iirs.Get_Identifier(lib) == std_names.Name.Ieee \ and pkg not in self._ieee_pkgs: self._ieee_pkgs.append(pkg) self._ieee_ids = self._ieee_ids.union( self.gather_identifiers(pkg)) lu = iirs.Get_Library_Unit(dsgn) for d in thinutils.declarations_iter(lu): id = iirs.Get_Identifier(d) if id in self._standard_ids: self.error( Location.from_node(d), "declaration of {} uses a standard name".format( nodeutils.get_identifier_str(d))) if id in self._ieee_ids: self.error( Location.from_node(d), "declaration of {} uses an ieee name".format( nodeutils.get_identifier_str(d)))
def check(self, input, node): if nodeutils.is_port(node): mode = iirs.Get_Mode(node) if mode == iirs.Iir_Mode.Buffer_Mode: self.error( Location.from_node(node), "buffer port '{0}' not allowed".format( nodeutils.get_identifier_str(node))) elif mode == iirs.Iir_Mode.Linkage_Mode: self.error( Location.from_node(node), "linkage port '{0}' not allowed".format( nodeutils.get_identifier_str(node)))
def report_unused(self, unit): for n in thinutils.declarations_iter(unit): if n in self._used \ or nodeutils.is_predefined_node(n): # Node is used (or not user defined) continue k = iirs.Get_Kind(n) if k in [iirs.Iir_Kind.Function_Body, iirs.Iir_Kind.Procedure_Body]: # Bodies are never referenced. continue if self.is_second_subprogram(n): # Subprogram specification of a body is never referenced. continue if k in iirs.Iir_Kinds.Interface_Object_Declaration: p = iirs.Get_Parent(n) if p != thin.Null_Iir \ and self.is_second_subprogram(p): # Interfaces without parent are from implicit subprograms. # Interfaces of the subprg spec of the body aren't # referenced. continue if k in [iirs.Iir_Kind.Anonymous_Type_Declaration]: # Anonymous types are never referenced. continue if k == iirs.Iir_Kind.Iterator_Declaration \ and thin.Get_Name_Length(iirs.Get_Identifier(n)) == 1: # Loop iterator with a very short name (for i in ...) # Allow it to be unused. continue self.error( Location.from_node(n), "{} is not used".format( nodeutils.get_identifier_str(n)))
def check(self, input, node): if iirs.Get_Kind(node) == iirs.Iir_Kind.Enumeration_Literal: s = nodeutils.get_identifier_str(node) if not s.isupper(): self.error( Location.from_node(node), "enumeration literal '{0}' must be in upper case".format( s))
def check(self, input, node): if iirs.Get_Kind(node) == iirs.Iir_Kind.Attribute_Declaration: s = nodeutils.get_identifier_str(node) if string.lower(s) not in self.allowed: self.error( Location.from_node(node), "user attribute declaration for '{0}' not allowed".format( s))
def check(self, input, node): if iirs.Get_Kind(node) == self.kind: s = nodeutils.get_identifier_str(node) if isinstance(self.predicate, list): for p in self.predicate: if self.check_predicate(p, node, s): break else: self.check_predicate(self.predicate, node, s)
def check(self, input, node): k = iirs.Get_Kind(node) if k == iirs.Iir_Kind.Signal_Declaration \ or k == iirs.Iir_Kind.Interface_Signal_Declaration: if iirs.Get_Guarded_Signal_Flag(node): self.error( Location.from_node(node), "signal '{0}' must not be guarded".format( nodeutils.get_identifier_str(node)))
def check(self, input, node): if nodeutils.is_generic(node): s = nodeutils.get_identifier_str(node) if not s.startswith("g_"): self.error(Location.from_node(node), "generic '{0}' must start with 'g_'".format(s)) if not s[2:].isupper(): self.error( Location.from_node(node), "generic '{0}' must be in upper case after 'g_'".format(s))
def check(self, input, ast): if 'top' not in input.props: return unit = iirs.Get_Library_Unit(ast) if iirs.Get_Kind(unit) != iirs.Iir_Kind.Entity_Declaration: return for port in thinutils.chain_iter(iirs.Get_Port_Chain(unit)): if not self.check_type(iirs.Get_Type(port)): self.error( Location.from_node(port), "type of port '{0}' must be std_logic/_vector".format( nodeutils.get_identifier_str(port)))
def check_identifier(self, node, dfn): if dfn == 0: # Can happen for architecture in entity aspect return ref_str = nodeutils.get_identifier_str(node) handler = self.find_handler(dfn) def_str = handler(dfn, ref_str) if ref_str == def_str: # OK! return if iirs.Get_Kind(dfn) == iirs.Iir_Kind.Guard_Signal_Declaration: # Guard signals are implicitely declared def_str = "GUARD" if ref_str == def_str: return self.error( Location.from_node(node), "{} is not the correct spelling for '{}'".format(ref_str, def_str))
def check_clause(self, cl): name = iirs.Get_Selected_Name(cl) if iirs.Get_Kind(name) == iirs.Iir_Kind.Selected_By_All_Name: name = iirs.Get_Prefix(name) if iirs.Get_Kind(name) != iirs.Iir_Kind.Selected_Name: self.error(Location.from_node(name), "unhandled use clause form") return lib = iirs.Get_Prefix(name) if iirs.Get_Kind(lib) != iirs.Iir_Kind.Simple_Name: self.error(Location.from_node(name), "unhandled use clause form") return if iirs.Get_Identifier(lib) != std_names.Name.Ieee: # User package ? return if iirs.Get_Identifier(name) not in self._allowed_id: self.error( Location.from_node(name), "non-allowed use of IEEE package {}".format( nodeutils.get_identifier_str(name)))
def check(self, input, node): if nodeutils.is_port(node): s = nodeutils.get_identifier_str(node) mode = iirs.Get_Mode(node) if mode == iirs.Iir_Mode.Out_Mode: if not s.endswith('_o'): self.error(Location.from_node(node), "out port '{0}' must end with '_o'".format(s)) elif mode == iirs.Iir_Mode.In_Mode: if not s.endswith('_i'): self.error(Location.from_node(node), "in port '{0}' must end with '_i'".format(s)) elif mode == iirs.Iir_Mode.Inout_Mode: if not s.endswith('_b'): self.error(Location.from_node(node), "inout port '{0}' must end with '_b'".format(s)) elif mode == iirs.Iir_Mode.Buffer_Mode: self.error(Location.from_node(node), "buffer port '{0}' not allowed".format(s)) elif mode == iirs.Iir_Mode.Linkage_Mode: self.error(Location.from_node(node), "linkage port '{0}' not allowed".format(s))
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)))
def get_user(self, dfn, s): """Referenced identifier must match its definition.""" return nodeutils.get_identifier_str(dfn)
def check(self, input, node): if iirs.Get_Kind(node) == iirs.Iir_Kind.Attribute_Name: s = nodeutils.get_identifier_str(node) if string.lower(s) not in self.predefined: self.error(Location.from_node(node), "attribute name '{0}' not allowed".format(s))