sem_ch12.adb (Save_Entity_Descendant): Use syntactic field names on known node types...
authorGeert Bosch <bosch@gcc.gnu.org>
Wed, 12 Dec 2001 23:51:11 +0000 (00:51 +0100)
committerGeert Bosch <bosch@gcc.gnu.org>
Wed, 12 Dec 2001 23:51:11 +0000 (00:51 +0100)
* sem_ch12.adb (Save_Entity_Descendant): Use syntactic field names
on known node types, rather than untyped fields. Further cleanups.

* sem_ch12.adb:
(Save_Entity_Descendant): Minor comment update.
(Copy_Generic_Node): Deal with incorrect reference to Associated_Node
 of an N_Attribute_Reference node. As per note below, this does not
eliminate need for Associated_Node in attribute ref nodes.
(Associated_Node): Documentation explicitly mentions attribute
reference nodes, since this field is used in such nodes.

* sem_ch12.adb (Associated_Node): Minor documentation cleanup.

From-SVN: r47954

gcc/ada/ChangeLog
gcc/ada/sem_ch12.adb

index c92ffb9e64be0c1c1026ead1ecb32aa3abfbb530..c30170598fa611a2c7fdc4028a276d2012badde1 100644 (file)
@@ -1,3 +1,20 @@
+2001-12-12  Ed Schonberg <schonber@gnat.com>
+
+       * sem_ch12.adb (Save_Entity_Descendant): Use syntactic field names 
+       on known node types, rather than untyped fields. Further cleanups.
+       
+2001-12-12  Robert Dewar <dewar@gnat.com>
+
+       * sem_ch12.adb:
+       (Save_Entity_Descendant): Minor comment update.
+       (Copy_Generic_Node): Deal with incorrect reference to Associated_Node
+        of an N_Attribute_Reference node. As per note below, this does not 
+       eliminate need for Associated_Node in attribute ref nodes.
+       (Associated_Node): Documentation explicitly mentions attribute 
+       reference nodes, since this field is used in such nodes.
+       
+       * sem_ch12.adb (Associated_Node): Minor documentation cleanup.
+
 2001-12-12  Robert Dewar <dewar@gnat.com>
 
        * s-stalib.adb: Add more comments on with statements being needed
index 71604f68c56ea9e60559cfc2dfd5e6f5f8c3fcbf..655291f1d0a8686aefc75e8b705dc26924ddd05e 100644 (file)
@@ -534,8 +534,10 @@ package body Sem_Ch12 is
 
    --  Three kinds of source nodes have associated nodes:
 
-   --    a) those that contain entities, that is to say identifiers,
-   --       expanded_names, and operators (N_Has_Entity)
+   --    a) those that can reference (denote) entities, that is identifiers,
+   --       character literals, expanded_names, operator symbols, operators,
+   --       and attribute reference nodes. These nodes have an Entity field
+   --       and are the set of nodes that are in N_Has_Entity.
 
    --    b) aggregates (N_Aggregate and N_Extension_Aggregate)
 
@@ -4660,6 +4662,7 @@ package body Sem_Ch12 is
 
       elsif Nkind (N) = N_Allocator
         and then Nkind (Expression (N)) = N_Qualified_Expression
+        and then Is_Entity_Name (Subtype_Mark (Expression (N)))
         and then Instantiating
       then
          declare
@@ -8207,8 +8210,13 @@ package body Sem_Ch12 is
 
       procedure Save_Entity_Descendants (N : Node_Id);
       --  Apply Save_Global_References to the two syntactic descendants of
-      --  nodes that carry entities, i.e. identifiers, character literals,
-      --  expanded names, and operators.
+      --  non-terminal nodes that carry an Associated_Node and are processed
+      --  through Reset_Entity. Once the global entity (if any) has been
+      --  captured together with its type, only two syntactic descendants
+      --  need to be traversed to complete the processing of the tree rooted
+      --  at N. This applies to Selected_Components, Expanded_Names, and to
+      --  Operator nodes. N can also be a character literal, identifier, or
+      --  operator symbol node, but the call has no effect in these cases.
 
       procedure Save_Global_Defaults (N1, N2 : Node_Id);
       --  Default actuals in nested instances must be handled specially
@@ -8449,14 +8457,25 @@ package body Sem_Ch12 is
       -----------------------------
 
       procedure Save_Entity_Descendants (N : Node_Id) is
+      begin
+         case Nkind (N) is
+            when N_Binary_Op =>
+               Save_Global_Descendant (Union_Id (Left_Opnd (N)));
+               Save_Global_Descendant (Union_Id (Right_Opnd (N)));
 
-         use Atree.Unchecked_Access;
-         --  This code section is part of the implementation of an untyped
-         --  tree traversal, so it needs direct access to node fields.
+            when N_Unary_Op =>
+               Save_Global_Descendant (Union_Id (Right_Opnd (N)));
 
-      begin
-         Save_Global_Descendant (Field2 (N));
-         Save_Global_Descendant (Field3 (N));
+            when N_Expanded_Name | N_Selected_Component =>
+               Save_Global_Descendant (Union_Id (Prefix (N)));
+               Save_Global_Descendant (Union_Id (Selector_Name (N)));
+
+            when N_Identifier | N_Character_Literal | N_Operator_Symbol =>
+               null;
+
+            when others =>
+               raise Program_Error;
+         end case;
       end Save_Entity_Descendants;
 
       --------------------------
@@ -8715,9 +8734,12 @@ package body Sem_Ch12 is
                end if;
             end if;
 
-            --  Complete the check on operands
+            --  Complete the check on operands, if node has not been
+            --  constant-folded.
 
-            Save_Entity_Descendants (N);
+            if Nkind (N) in N_Op then
+               Save_Entity_Descendants (N);
+            end if;
 
          elsif Nkind (N) = N_Identifier then
             if Nkind (N) = Nkind (Get_Associated_Node (N)) then