def check(self, input, ast): for node in thinutils.constructs_iter(ast): k = iirs.Get_Kind(node) if k not in [ iirs.Iir_Kind.Architecture_Body, iirs.Iir_Kind.Block_Statement, iirs.Iir_Kind.Entity_Declaration, iirs.Iir_Kind.Generate_Statement_Body, iirs.Iir_Kind.Process_Statement, iirs.Iir_Kind.Sensitized_Process_Statement, iirs.Iir_Kind.Procedure_Body, iirs.Iir_Kind.Function_Body ]: continue beg_loc = elocations.Get_Begin_Location(node) end_loc = elocations.Get_End_Location(node) if beg_loc == thin.No_Location or end_loc == thin.No_Location: continue beg_file, beg_line, beg_col = Location_To_File_Line_Col(beg_loc) end_file, end_line, end_col = Location_To_File_Line_Col(end_loc) if end_col != beg_col: self.error( Location.from_location(end_loc), "'begin' and 'end' must be aligned on the same column") if k in iirs.Iir_Kinds.Subprogram_Body: if iirs.Get_Declaration_Chain(node) != thin.Null_Iir: is_loc = elocations.Get_Is_Location(node) is_file, is_ln, is_col = Location_To_File_Line_Col(is_loc) if is_col != beg_col: self.error( Location.from_location(is_loc), "'is' and 'begin' must be on the same column")
def check_entity(self, ent): decl = iirs.Get_Declaration_Chain(ent) if decl != thin.Null_Iir: self.error(Location.from_node(decl), "declaration not allowed in entity") first_stmt = iirs.Get_Concurrent_Statement_Chain(ent) for s in thinutils.chain_iter(first_stmt): k = iirs.Get_Kind(s) if k != iirs.Iir_Kind.Concurrent_Assertion_Statement: self.error(Location.from_node(s), "concurrent statement not allowed in entity")
def chk_concurrent(self, head, level): nlevel = level + self._l for n in thinutils.chain_iter(head): self.chk_level(n, iirs.Get_Location(n), level) k = iirs.Get_Kind(n) if k == iirs.Iir_Kind.Component_Instantiation_Statement: # TODO pass elif (k == iirs.Iir_Kind.Concurrent_Assertion_Statement or k == iirs.Iir_Kind.Concurrent_Simple_Signal_Assignment or k == iirs.Iir_Kind.Concurrent_Conditional_Signal_Assignment or k == iirs.Iir_Kind.Concurrent_Selected_Signal_Assignment): pass elif k == iirs.Iir_Kind.Concurrent_Procedure_Call_Statement: pass elif k == iirs.Iir_Kind.Block_Statement: 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) self.chk_level(n, elocs.Get_End_Location(n), level) elif k == iirs.Iir_Kind.For_Generate_Statement: self.chk_line_or_col( n, iirs.Get_Location(n), elocs.Get_Generate_Location(n)) self.chk_generate_body( iirs.Get_Generate_Statement_Body(n), level) self.chk_level(n, elocs.Get_End_Location(n), level) elif k == iirs.Iir_Kind.If_Generate_Statement: self.chk_line_or_col( n, iirs.Get_Location(n), elocs.Get_Generate_Location(n)) self.chk_generate_body( iirs.Get_Generate_Statement_Body(n), level) self.chk_level(n, elocs.Get_End_Location(n), level) elif (k == iirs.Iir_Kind.Sensitized_Process_Statement or k == iirs.Iir_Kind.Process_Statement): 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)
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)
def gather_identifiers(self, pkg): res = set() for d in thinutils.chain_iter(iirs.Get_Declaration_Chain(pkg)): k = iirs.Get_Kind(d) if d in iirs.Iir_Kinds.Specification: continue self.add_identifier(res, d) if k in [ iirs.Iir_Kind.Type_Declaration, iirs.Iir_Kind.Anonymous_Type_Declaration ]: typ = iirs.Get_Type_Definition(d) k = iirs.Get_Kind(typ) if k == iirs.Iir_Kind.Enumeration_Type_Definition: for lit in thinutils.list_iter( iirs.Get_Enumeration_Literal_List(typ)): self.add_identifier(res, lit) elif k == iirs.Iir_Kind.Physical_Type_Definition: for un in thinutils.chain_iter(iirs.Get_Unit_Chain(typ)): self.add_identifier(res, un) return res
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 constructs_iter(n): """Iterator on library unit, concurrent statements and declarations that appear directly within a declarative part.""" if n == thin.Null_Iir: return k = iirs.Get_Kind(n) if k == iirs.Iir_Kind.Design_File: for n1 in chain_iter(iirs.Get_First_Design_Unit(n)): for n2 in constructs_iter(n1): yield n2 elif k == iirs.Iir_Kind.Design_Unit: n1 = iirs.Get_Library_Unit(n) yield n1 for n2 in constructs_iter(n1): yield n2 elif k in [ iirs.Iir_Kind.Entity_Declaration, iirs.Iir_Kind.Architecture_Body, iirs.Iir_Kind.Block_Statement, iirs.Iir_Kind.Generate_Statement_Body ]: for n1 in chain_iter(iirs.Get_Declaration_Chain(n)): yield n1 for n2 in constructs_iter(n1): yield n2 for n1 in chain_iter(iirs.Get_Concurrent_Statement_Chain(n)): yield n1 for n2 in constructs_iter(n1): yield n2 elif k in [ iirs.Iir_Kind.Configuration_Declaration, iirs.Iir_Kind.Package_Declaration, iirs.Iir_Kind.Package_Body, iirs.Iir_Kind.Function_Body, iirs.Iir_Kind.Procedure_Body, iirs.Iir_Kind.Protected_Type_Declaration, iirs.Iir_Kind.Protected_Type_Body, iirs.Iir_Kind.Process_Statement, iirs.Iir_Kind.Sensitized_Process_Statement ]: for n1 in chain_iter(iirs.Get_Declaration_Chain(n)): yield n1 for n2 in constructs_iter(n1): yield n2 elif k == iirs.Iir_Kind.For_Generate_Statement: n1 = iirs.Get_Generate_Statement_Body(n) yield n1 for n2 in constructs_iter(n1): yield n2 elif k == iirs.Iir_Kind.If_Generate_Statement: while n != Null_Iir: n1 = iirs.Get_Generate_Statement_Body(n) yield n1 for n2 in constructs_iter(n1): yield n2 n = iirs.Get_Generate_Else_Clause(n) elif k == iirs.Iir_Kind.Case_Generate_Statement: alt = iirs.Get_Case_Statement_Alternative_Chain(n) for n1 in chain_iter(alt): blk = iirs.Get_Associated_Block(n1) if blk != Null_Iir: n2 = iirs.Get_Generate_Statement_Body(blk) yield n2 for n3 in constructs_iter(n2): yield n3
def declarations_iter(n): """Iterator on all declarations in n.""" k = iirs.Get_Kind(n) if nodes_meta.Has_Generic_Chain(k): for n1 in chain_iter(iirs.Get_Generic_Chain(n)): yield n1 if nodes_meta.Has_Port_Chain(k): for n1 in chain_iter(iirs.Get_Port_Chain(n)): yield n1 if nodes_meta.Has_Interface_Declaration_Chain(k): for n1 in chain_iter(iirs.Get_Interface_Declaration_Chain(n)): yield n1 if nodes_meta.Has_Declaration_Chain(k): for n1 in chain_iter(iirs.Get_Declaration_Chain(n)): k1 = iirs.Get_Kind(n1) if k1 in iirs.Iir_Kinds.Specification \ or k1 == iirs.Iir_Kind.Use_Clause: # Not a declaration pass elif k1 == iirs.Iir_Kind.Signal_Attribute_Declaration: # Not a declaration pass elif k1 in [ iirs.Iir_Kind.Type_Declaration, iirs.Iir_Kind.Anonymous_Type_Declaration ]: yield n1 # Handle nested declarations: record elements, physical units, # enumeration literals... typ = iirs.Get_Type_Definition(n1) for n2 in declarations_iter(n1): yield n2 else: yield n1 # There can be nested declarations (subprograms) for n2 in declarations_iter(n1): yield n2 if nodes_meta.Has_Concurrent_Statement_Chain(k): for n1 in chain_iter(iirs.Get_Concurrent_Statement_Chain(n)): for n2 in declarations_iter(n1): yield n2 if nodes_meta.Has_Sequential_Statement_Chain(k): for n1 in chain_iter(iirs.Get_Sequential_Statement_Chain(n)): for n2 in declarations_iter(n1): yield n2 if nodes_meta.Has_Parameter_Specification(k): yield iirs.Get_Parameter_Specification(n) if nodes_meta.Has_Generate_Statement_Body(k): for n1 in declarations_iter(iirs.Get_Generate_Statement_Body(n)): yield n1 if nodes_meta.Has_Else_Clause(k): n1 = iirs.Get_Else_Clause(n) if n1 != Null_Iir: for n2 in declarations_iter(n1): yield n2 if nodes_meta.Has_Generate_Else_Clause(k): n1 = iirs.Get_Generate_Else_Clause(n) if n1 != Null_Iir: for n2 in declarations_iter(n1): yield n2 if nodes_meta.Has_Block_Header(k): n1 = iirs.Get_Block_Header(n) if n1 != Null_Iir: for n2 in declarations_iter(n1): yield n2 # All these nodes are handled: if k in [ iirs.Iir_Kind.Entity_Declaration, iirs.Iir_Kind.Architecture_Body, iirs.Iir_Kind.Package_Declaration, iirs.Iir_Kind.Package_Body, iirs.Iir_Kind.Process_Statement, iirs.Iir_Kind.Sensitized_Process_Statement, iirs.Iir_Kind.Concurrent_Assertion_Statement, iirs.Iir_Kind.Concurrent_Simple_Signal_Assignment, iirs.Iir_Kind.Concurrent_Selected_Signal_Assignment, iirs.Iir_Kind.Concurrent_Conditional_Signal_Assignment, iirs.Iir_Kind.Concurrent_Procedure_Call_Statement, iirs.Iir_Kind.Block_Statement, iirs.Iir_Kind.Block_Header, iirs.Iir_Kind.For_Generate_Statement, iirs.Iir_Kind.If_Generate_Statement, iirs.Iir_Kind.Generate_Statement_Body, iirs.Iir_Kind.Assertion_Statement, iirs.Iir_Kind.Wait_Statement, iirs.Iir_Kind.Simple_Signal_Assignment_Statement, iirs.Iir_Kind.Variable_Assignment_Statement, iirs.Iir_Kind.For_Loop_Statement, iirs.Iir_Kind.While_Loop_Statement, iirs.Iir_Kind.Case_Statement, iirs.Iir_Kind.Null_Statement, iirs.Iir_Kind.Exit_Statement, iirs.Iir_Kind.Next_Statement, iirs.Iir_Kind.Procedure_Call_Statement, iirs.Iir_Kind.Signal_Declaration, iirs.Iir_Kind.Constant_Declaration, iirs.Iir_Kind.Variable_Declaration, iirs.Iir_Kind.File_Declaration, iirs.Iir_Kind.Object_Alias_Declaration, iirs.Iir_Kind.Attribute_Declaration, iirs.Iir_Kind.Component_Declaration, iirs.Iir_Kind.Use_Clause, iirs.Iir_Kind.If_Statement, iirs.Iir_Kind.Elsif, iirs.Iir_Kind.Return_Statement, iirs.Iir_Kind.Type_Declaration, iirs.Iir_Kind.Anonymous_Type_Declaration, iirs.Iir_Kind.Subtype_Declaration, iirs.Iir_Kind.Function_Declaration, iirs.Iir_Kind.Function_Body, iirs.Iir_Kind.Procedure_Declaration, iirs.Iir_Kind.Procedure_Body, iirs.Iir_Kind.Component_Instantiation_Statement, ]: return assert False, "unknown node of kind {}".format(kind_image(k))