+2014-10-17 Ed Schonberg <schonberg@adacore.com>
+
+ * sem_ch13.adb (Add_Invariants, Replace_Type_References): Do
+ not perform the replacement on the expression for an inherited
+ class-wide invariant if in ASIS_Mode and the type reference is
+ already the prefix of a 'Class attribute reference: the expression
+ has already been preanalyzed and the replacement performed when
+ first encountered on the declaration of the parent type.
+
2014-10-17 Robert Dewar <dewar@adacore.com>
* sem_ch5.adb, sem_ch7.adb, prj-nmsc.adb, sem_ch13.adb, exp_ch3.adb:
end if;
-- Invariant'Class, replace with T'Class (obj)
+ -- In ASIS mode, an inherited item is analyzed already, and the
+ -- replacement has been done, so do not repeat transformation
+ -- to prevent ill-formed tree.
if Class_Present (Ritem) then
- Rewrite (N,
- Make_Type_Conversion (Sloc (N),
- Subtype_Mark =>
- Make_Attribute_Reference (Sloc (N),
- Prefix => New_Occurrence_Of (T, Sloc (N)),
- Attribute_Name => Name_Class),
- Expression => Make_Identifier (Sloc (N), Object_Name)));
-
- Set_Entity (Expression (N), Object_Entity);
- Set_Etype (Expression (N), Typ);
+ if ASIS_Mode
+ and then Nkind (Parent (N)) = N_Attribute_Reference
+ and then Attribute_Name (Parent (N)) = Name_Class
+ then
+ null;
+
+ else
+ Rewrite (N,
+ Make_Type_Conversion (Sloc (N),
+ Subtype_Mark =>
+ Make_Attribute_Reference (Sloc (N),
+ Prefix => New_Occurrence_Of (T, Sloc (N)),
+ Attribute_Name => Name_Class),
+ Expression =>
+ Make_Identifier (Sloc (N), Object_Name)));
+
+ Set_Entity (Expression (N), Object_Entity);
+ Set_Etype (Expression (N), Typ);
+ end if;
-- Invariant, replace with obj