@@ -503,9 +503,9 @@ def wrap_sites(spec, issite, tname):
503503 else :
504504 raise ICE (issite , 'unknown node type %r %r' % (asttype , stmt ))
505505 composite_wrapped = [
506- (objtype , name , arrayinfo ,
506+ (objtype , name , arrayinfo , is_extension ,
507507 ObjectSpec (* wrap_sites (spec , issite , tname )))
508- for (objtype , name , arrayinfo , spec ) in composite ]
508+ for (objtype , name , arrayinfo , is_extension , spec ) in composite ]
509509 blocks .append ((preconds , shallow_wrapped , composite_wrapped ))
510510
511511 return (TemplateSite (spec .site , issite , tname ), spec .rank ,
@@ -833,8 +833,8 @@ def sort_method_implementations(implementations, obj_specs):
833833 return traits .sort_method_implementations (implementations )
834834
835835def merge_subobj_defs (def1 , def2 , parent ):
836- (objtype , name , arrayinfo , obj_specs1 ) = def1
837- (objtype2 , name2 , arrayinfo2 , obj_specs2 ) = def2
836+ (objtype , name , arrayinfo , extension_status1 , obj_specs1 ) = def1
837+ (objtype2 , name2 , arrayinfo2 , extension_status2 , obj_specs2 ) = def2
838838 assert name == name2
839839
840840 site1 = obj_specs1 [0 ].site
@@ -844,6 +844,26 @@ def merge_subobj_defs(def1, def2, parent):
844844 report (ENAMECOLL (site1 , site2 , name ))
845845 return def1
846846
847+ # extension status:
848+ # None -> dual extension and decl
849+ # True -> extension
850+ # False -> explicit decl
851+ if extension_status1 is extension_status2 is False :
852+ # Blame the one with higher rank if possible. Otherwise, blame the
853+ # new def.
854+ (decl_site_1 , decl_site_2 ) = (
855+ (site1 , site2 ) if (
856+ obj_specs2 [0 ].rank in obj_specs1 [0 ].rank .inferior )
857+ else (site2 , site1 ))
858+ report (EMULTIOBJDECL (decl_site_1 , decl_site_2 , objtype , name ))
859+ # One is explicit decl: merged is explicit decl
860+ elif extension_status1 is False or extension_status2 is False :
861+ extension_status1 = False
862+ # If either is dual, make dual
863+ elif extension_status1 is None or extension_status2 is None :
864+ extension_status1 = None
865+ # Otherwise, both are explicit extensions. Keep explicit extension.
866+
847867 if len (arrayinfo ) != len (arrayinfo2 ):
848868 raise EAINCOMP (site1 , site2 , name ,
849869 "mixing declarations with different number "
@@ -870,7 +890,8 @@ def merge_subobj_defs(def1, def2, parent):
870890 merged_arrayinfo .append ((idxvar1 , len1 ))
871891
872892
873- return (objtype , name , merged_arrayinfo , obj_specs1 + obj_specs2 )
893+ return (objtype , name , merged_arrayinfo , extension_status1 ,
894+ obj_specs1 + obj_specs2 )
874895
875896def method_is_std (node , methname ):
876897 """
@@ -1708,13 +1729,14 @@ def mkobj2(obj, obj_specs, params, each_stmts):
17081729
17091730 for (stmts , obj_spec ) in composite_subobjs :
17101731 for s in stmts :
1711- (objtype , ident , arrayinfo , subobj_spec ) = s
1732+ (objtype , ident , arrayinfo , is_extension , subobj_spec ) = s
17121733
17131734 if ident is None :
17141735 assert (dml .globals .dml_version == (1 , 2 )
17151736 and objtype in {'bank' , 'field' })
17161737
1717- subobj_def = (objtype , ident , arrayinfo , [subobj_spec ])
1738+ subobj_def = (objtype , ident , arrayinfo , is_extension ,
1739+ [subobj_spec ])
17181740 if ident in subobj_defs :
17191741 subobj_defs [ident ] = merge_subobj_defs (subobj_defs [ident ],
17201742 subobj_def , obj )
@@ -1724,7 +1746,10 @@ def mkobj2(obj, obj_specs, params, each_stmts):
17241746 symbols [ident ] = subobj_spec .site
17251747 subobj_defs [ident ] = subobj_def
17261748
1727- for (_ , _ , arrayinfo , specs ) in subobj_defs .values ():
1749+ for (_ , ident , arrayinfo , extension_status , specs ) in subobj_defs .values ():
1750+ if extension_status is True :
1751+ for spec in specs :
1752+ report (EEXTENSION (spec .site , ident ))
17281753 for (i , (idx , dimsize_ast )) in enumerate (arrayinfo ):
17291754 if dimsize_ast is None :
17301755 idxref = (f" (with index variable '{ idx .args [0 ]} ')"
@@ -1814,7 +1839,7 @@ def mkobj2(obj, obj_specs, params, each_stmts):
18141839 # the whole register.
18151840 if obj .objtype == 'register' and not any (
18161841 objtype == 'field'
1817- for (objtype , _ , _ , _ ) in list (subobj_defs .values ())):
1842+ for (objtype , _ , _ , _ , _ ) in list (subobj_defs .values ())):
18181843 # The implicit field instantiates the built-in field
18191844 # template and does nothing else.
18201845 subobjs .append (mkobj (
@@ -1856,7 +1881,7 @@ def mkobj2(obj, obj_specs, params, each_stmts):
18561881 subobj_name_defs = {}
18571882
18581883 for name in sorted (subobj_defs , key = lambda name : name or '' ):
1859- (objtype , ident , arrayinfo , subobj_specs ) = subobj_defs [name ]
1884+ (objtype , ident , arrayinfo , _ , subobj_specs ) = subobj_defs [name ]
18601885 if (not obj .accepts_child_type (objtype )
18611886 # HACK: disallow non-toplevel banks in DML 1.2, see SIMICS-19009
18621887 or (dml .globals .dml_version == (1 , 2 )
0 commit comments