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 chk_declarations(self, head, level): nlevel = level + self._l for n in thinutils.chain_iter(head): k = iirs.Get_Kind(n) if k == iirs.Iir_Kind.Constant_Declaration \ or k == iirs.Iir_Kind.Signal_Declaration \ or k == iirs.Iir_Kind.Variable_Declaration \ or k == iirs.Iir_Kind.File_Declaration \ or k == iirs.Iir_Kind.Object_Alias_Declaration \ or k == iirs.Iir_Kind.Attribute_Declaration \ or k == iirs.Iir_Kind.Attribute_Specification: self.chk_level(n, elocs.Get_Start_Location(n), level) elif (k == iirs.Iir_Kind.Configuration_Specification or k == iirs.Iir_Kind.Disconnection_Specification): self.chk_level(n, iirs.Get_Location(n), level) elif (k == iirs.Iir_Kind.Subtype_Declaration or k == iirs.Iir_Kind.Type_Declaration or k == iirs.Iir_Kind.Anonymous_Type_Declaration): self.chk_level(n, elocs.Get_Start_Location(n), level) elif k == iirs.Iir_Kind.Component_Declaration: self.chk_level(n, elocs.Get_Start_Location(n), level) self.chk_level(n, elocs.Get_Generic_Location(n), nlevel) self.chk_level(n, elocs.Get_Port_Location(n), nlevel) self.chk_level(n, elocs.Get_End_Location(n), level) elif (k == iirs.Iir_Kind.Function_Declaration or k == iirs.Iir_Kind.Procedure_Declaration): self.chk_level(n, elocs.Get_Start_Location(n), level) elif (k == iirs.Iir_Kind.Function_Body or k == iirs.Iir_Kind.Procedure_Body): self.chk_declarations(iirs.Get_Declaration_Chain(n), nlevel) self.chk_level(n, elocs.Get_Begin_Location(n), level) self.chk_sequential( iirs.Get_Sequential_Statement_Chain(n), nlevel) self.chk_level(n, elocs.Get_End_Location(n), level) # check start elif k == iirs.Iir_Kind.Use_Clause: self.chk_level(n, iirs.Get_Location(n), level) else: assert False, "unhandled declaration {}".format( thinutils.kind_image(k))
def check_declarations(self, decl): decl_col = -1 colon_col = -1 subtype_col = -1 assign_col = -1 line = -1 while decl != thin.Null_Iir: loc = elocations.Get_Start_Location(decl) fe, ln, co = utils.Location_To_File_Line_Col(loc) if ln <= line: self.error(Location.from_node(decl), "one generic/port per line") else: if co != decl_col and decl_col >= 0: self.error(Location.from_node(decl), "name is not aligned with previous one") # Check alignment of ':' colon_loc = elocations.Get_Colon_Location(decl) _, ln1, colon_co = utils.Location_To_File_Line_Col(colon_loc) if colon_co != colon_col and colon_col >= 0: self.error(Location.from_node(decl), "':' is not aligned with previous one") colon_col = colon_co # Check alignment of subtype. st = iirs.Get_Subtype_Indication(decl) if st != thin.Null_Iir: st_loc = thinutils.leftest_location(st) _, ln1, st_co = utils.Location_To_File_Line_Col(st_loc) if st_co != subtype_col and subtype_col >= 0: self.error(Location.from_node(decl), "subtype is not aligned with previous one") subtype_col = st_co # Check alignment of ':=' assign_loc = elocations.Get_Assign_Location(decl) if assign_loc != thin.No_Location: _, ln1, assign_co = \ utils.Location_To_File_Line_Col(assign_loc) if assign_co != assign_col and assign_col >= 0: self.error(Location.from_node(decl), "':=' is not aligned with previous one") assign_col = assign_co decl_col = co line = ln decl = iirs.Get_Chain(decl)
def chk_library_unit(self, n, level): k = iirs.Get_Kind(n) nlevel = level + self._l self.chk_level(n, elocs.Get_Start_Location(n), level) if k == iirs.Iir_Kind.Package_Declaration \ or k == iirs.Iir_Kind.Package_Body: self.chk_declarations(iirs.Get_Declaration_Chain(n), nlevel) elif k == iirs.Iir_Kind.Entity_Declaration: self.chk_level(n, elocs.Get_Generic_Location(n), nlevel) self.chk_level(n, elocs.Get_Port_Location(n), nlevel) self.chk_declarations(iirs.Get_Declaration_Chain(n), nlevel) self.chk_level(n, elocs.Get_Begin_Location(n), level) self.chk_concurrent(iirs.Get_Concurrent_Statement_Chain(n), nlevel) elif k == iirs.Iir_Kind.Architecture_Body: self.chk_declarations(iirs.Get_Declaration_Chain(n), nlevel) self.chk_level(n, elocs.Get_Begin_Location(n), level) self.chk_concurrent(iirs.Get_Concurrent_Statement_Chain(n), nlevel) elif k == iirs.Iir_Kind.Configuration_Declaration: self.chk_declarations(iirs.Get_Declaration_Chain(n), nlevel) # TODO: block configuration else: assert False, "unhandled unit {}".format(thinutils.kind_image(k)) self.chk_level(n, elocs.Get_End_Location(n), level)