+ function Matches_Limited_With_View
+ (Typ_1 : Entity_Id;
+ Typ_2 : Entity_Id) return Boolean
+ is
+ function Is_Matching_Limited_View
+ (Typ : Entity_Id;
+ View : Entity_Id) return Boolean;
+ -- Determine whether non-limited view View denotes type Typ in some
+ -- conformant fashion.
+
+ ------------------------------
+ -- Is_Matching_Limited_View --
+ ------------------------------
+
+ function Is_Matching_Limited_View
+ (Typ : Entity_Id;
+ View : Entity_Id) return Boolean
+ is
+ Root_Typ : Entity_Id;
+ Root_View : Entity_Id;
+
+ begin
+ -- The non-limited view directly denotes the type
+
+ if Typ = View then
+ return True;
+
+ -- The type is a subtype of the non-limited view
+
+ elsif Is_Subtype_Of (Typ, View) then
+ return True;
+
+ -- Both the non-limited view and the type denote class-wide types
+
+ elsif Is_Class_Wide_Type (Typ)
+ and then Is_Class_Wide_Type (View)
+ then
+ Root_Typ := Root_Type (Typ);
+ Root_View := Root_Type (View);
+
+ if Root_Typ = Root_View then
+ return True;
+
+ -- An incomplete tagged type and its full view may receive two
+ -- distinct class-wide types when the related package has not
+ -- been analyzed yet.
+
+ -- package Pack is
+ -- type T is tagged; -- CW_1
+ -- type T is tagged null record; -- CW_2
+ -- end Pack;
+
+ -- This is because the package lacks any semantic information
+ -- that may eventually link both views of T. As a consequence,
+ -- a client of the limited view of Pack will see CW_2 while a
+ -- client of the non-limited view of Pack will see CW_1.
+
+ elsif Is_Incomplete_Type (Root_Typ)
+ and then Present (Full_View (Root_Typ))
+ and then Full_View (Root_Typ) = Root_View
+ then
+ return True;
+
+ elsif Is_Incomplete_Type (Root_View)
+ and then Present (Full_View (Root_View))
+ and then Full_View (Root_View) = Root_Typ
+ then
+ return True;
+ end if;
+ end if;
+
+ return False;
+ end Is_Matching_Limited_View;
+
+ -- Start of processing for Matches_Limited_With_View
+