OSDN Git Service

2011-12-21 Javier Miranda <miranda@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_ch3.ads
index 076966a..7b4d2a9 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2008, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -28,6 +28,7 @@ with Types;  use Types;
 
 package Sem_Ch3 is
    procedure Analyze_Component_Declaration         (N : Node_Id);
+   procedure Analyze_Full_Type_Declaration         (N : Node_Id);
    procedure Analyze_Incomplete_Type_Decl          (N : Node_Id);
    procedure Analyze_Itype_Reference               (N : Node_Id);
    procedure Analyze_Number_Declaration            (N : Node_Id);
@@ -35,7 +36,6 @@ package Sem_Ch3 is
    procedure Analyze_Others_Choice                 (N : Node_Id);
    procedure Analyze_Private_Extension_Declaration (N : Node_Id);
    procedure Analyze_Subtype_Indication            (N : Node_Id);
-   procedure Analyze_Type_Declaration              (N : Node_Id);
    procedure Analyze_Variant_Part                  (N : Node_Id);
 
    procedure Analyze_Subtype_Declaration
@@ -64,6 +64,11 @@ package Sem_Ch3 is
    --  the signature of the implicit type works like the profile of a regular
    --  subprogram.
 
+   procedure Add_Internal_Interface_Entities (Tagged_Type : Entity_Id);
+   --  Add to the list of primitives of Tagged_Type the internal entities
+   --  associated with covered interface primitives. These entities link the
+   --  interface primitives with the tagged type primitives that cover them.
+
    procedure Analyze_Declarations (L : List_Id);
    --  Called to analyze a list of declarations (in what context ???). Also
    --  performs necessary freezing actions (more description needed ???)
@@ -79,24 +84,40 @@ package Sem_Ch3 is
    procedure Access_Type_Declaration (T : Entity_Id; Def : Node_Id);
    --  Process an access type declaration
 
+   procedure Build_Itype_Reference (Ityp : Entity_Id; Nod : Node_Id);
+   --  Create a reference to an internal type, for use by Gigi. The back-end
+   --  elaborates itypes on demand, i.e. when their first use is seen. This can
+   --  lead to scope anomalies if the first use is within a scope that is
+   --  nested within the scope that contains the point of definition of the
+   --  itype. The Itype_Reference node forces the elaboration of the itype
+   --  in the proper scope. The node is inserted after Nod, which is the
+   --  enclosing declaration that generated Ityp.
+   --
+   --  A related mechanism is used during expansion, for itypes created in
+   --  branches of conditionals. See Ensure_Defined in exp_util.
+   --  Could both mechanisms be merged ???
+
    procedure Check_Abstract_Overriding (T : Entity_Id);
-   --  Check that all abstract subprograms inherited from T's parent type
-   --  have been overridden as required, and that nonabstract subprograms
-   --  have not been incorrectly overridden with an abstract subprogram.
+   --  Check that all abstract subprograms inherited from T's parent type have
+   --  been overridden as required, and that nonabstract subprograms have not
+   --  been incorrectly overridden with an abstract subprogram.
 
    procedure Check_Aliased_Component_Types (T : Entity_Id);
    --  Given an array type or record type T, check that if the type is
-   --  nonlimited, then the nominal subtype of any components of T
-   --  that have discriminants must be constrained.
+   --  nonlimited, then the nominal subtype of any components of T that
+   --  have discriminants must be constrained.
 
    procedure Check_Completion (Body_Id : Node_Id := Empty);
-   --  At the end of a declarative part, verify that all entities that
-   --  require completion have received one. If Body_Id is absent, the
-   --  error indicating a missing completion is placed on the declaration
-   --  that needs completion. If Body_Id is present, it is the defining
-   --  identifier of a package body, and errors are posted on that node,
-   --  rather than on the declarations that require completion in the package
-   --  declaration.
+   --  At the end of a declarative part, verify that all entities that require
+   --  completion have received one. If Body_Id is absent, the error indicating
+   --  a missing completion is placed on the declaration that needs completion.
+   --  If Body_Id is present, it is the defining identifier of a package body,
+   --  and errors are posted on that node, rather than on the declarations that
+   --  require completion in the package declaration.
+
+   procedure Check_CPP_Type (T : Entity_Id);
+   --  Check that components of imported CPP type T do not have default
+   --  expressions because the constructor (if any) is on the C++ side.
 
    procedure Derive_Subprogram
      (New_Subp     : in out Entity_Id;
@@ -123,8 +144,8 @@ package Sem_Ch3 is
    --  the derived subprograms are aliased to those of the actual, not those of
    --  the ancestor.
    --
-   --  Note: one might expect this to be private to the package body, but
-   --  there is one rather unusual usage in package Exp_Dist.
+   --  Note: one might expect this to be private to the package body, but there
+   --  is one rather unusual usage in package Exp_Dist.
 
    function Find_Hidden_Interface
      (Src  : Elist_Id;
@@ -140,15 +161,24 @@ package Sem_Ch3 is
    function Find_Type_Name (N : Node_Id) return Entity_Id;
    --  Enter the identifier in a type definition, or find the entity already
    --  declared, in the case of the full declaration of an incomplete or
-   --  private type.
+   --  private type. If the previous declaration is tagged then the class-wide
+   --  entity is propagated to the identifier to prevent multiple incompatible
+   --  class-wide types that may be created for self-referential anonymous
+   --  access components.
 
    function Get_Discriminant_Value
      (Discriminant       : Entity_Id;
       Typ_For_Constraint : Entity_Id;
       Constraint         : Elist_Id) return Node_Id;
    --  ??? MORE DOCUMENTATION
-   --  Given a discriminant somewhere in the Typ_For_Constraint tree
-   --  and a Constraint, return the value of that discriminant.
+   --  Given a discriminant somewhere in the Typ_For_Constraint tree and a
+   --  Constraint, return the value of that discriminant.
+
+   function Is_Constant_Bound (Exp : Node_Id) return Boolean;
+   --  Exp is the expression for an array bound. Determines whether the
+   --  bound is a compile-time known value, or a constant entity, or an
+   --  enumeration literal, or an expression composed of constant-bound
+   --  subexpressions which are evaluated by means of standard operators.
 
    function Is_Null_Extension (T : Entity_Id) return Boolean;
    --  Returns True if the tagged type T has an N_Full_Type_Declaration that
@@ -166,34 +196,43 @@ package Sem_Ch3 is
      (I            : Node_Id;
       Related_Nod  : Node_Id;
       Related_Id   : Entity_Id := Empty;
-      Suffix_Index : Nat := 1);
+      Suffix_Index : Nat := 1;
+      In_Iter_Schm : Boolean := False);
    --  Process an index that is given in an array declaration, an entry
    --  family declaration or a loop iteration. The index is given by an
    --  index declaration (a 'box'), or by a discrete range. The later can
    --  be the name of a discrete type, or a subtype indication.
    --
    --  Related_Nod is the node where the potential generated implicit types
-   --  will be inserted. The 2 last parameters are used for creating the name.
+   --  will be inserted. The next last parameters are used for creating the
+   --  name. In_Iter_Schm is True if Make_Index is called on the discrete
+   --  subtype definition in an iteration scheme.
 
    procedure Make_Class_Wide_Type (T : Entity_Id);
    --  A Class_Wide_Type is created for each tagged type definition. The
-   --  attributes of a class wide type are inherited from those of the type T.
+   --  attributes of a class-wide type are inherited from those of the type T.
    --  If T is introduced by a private declaration, the corresponding class
    --  wide type is created at the same time, and therefore there is a private
-   --  and a full declaration for the class wide type as well.
-
-   function OK_For_Limited_Init_In_05 (Exp : Node_Id) return Boolean;
-   --  Presuming Exp is an expression of an inherently limited type, returns
-   --  True if the expression is allowed in an initialization context by the
-   --  rules of Ada 2005. We use the rule in RM-7.5(2.1/2), "...it is an
-   --  aggregate, a function_call, or a parenthesized expression or
-   --  qualified_expression whose operand is permitted...". Note that in Ada
-   --  95 mode, we sometimes wish to give warnings based on whether the
-   --  program _would_ be legal in Ada 2005. Note that Exp must already have
-   --  been resolved, so we can know whether it's a function call (as opposed
-   --  to an indexed component, for example).
-
-   function OK_For_Limited_Init (Exp : Node_Id) return Boolean;
+   --  and a full declaration for the class-wide type as well.
+
+   function OK_For_Limited_Init_In_05
+     (Typ : Entity_Id;
+      Exp : Node_Id) return Boolean;
+   --  Presuming Exp is an expression of an inherently limited type Typ,
+   --  returns True if the expression is allowed in an initialization context
+   --  by the rules of Ada 2005. We use the rule in RM-7.5(2.1/2), "...it is an
+   --  aggregate, a function_call, or a parenthesized expression or qualified
+   --  expression whose operand is permitted...". Note that in Ada 95 mode,
+   --  we sometimes wish to give warnings based on whether the program _would_
+   --  be legal in Ada 2005. Note that Exp must already have been resolved,
+   --  so we can know whether it's a function call (as opposed to an indexed
+   --  component, for example). In the case where Typ is a limited interface's
+   --  class-wide type, then the expression is allowed to be of any kind if its
+   --  type is a nonlimited descendant of the interface.
+
+   function OK_For_Limited_Init
+     (Typ : Entity_Id;
+      Exp : Node_Id) return Boolean;
    --  Always False in Ada 95 mode. Equivalent to OK_For_Limited_Init_In_05 in
    --  Ada 2005 mode.
 
@@ -204,6 +243,8 @@ package Sem_Ch3 is
    --  In_Default_Expression flag. See the documentation section entitled
    --  "Handling of Default and Per-Object Expressions" in sem.ads for full
    --  details. N is the expression to be analyzed, T is the expected type.
+   --  This mechanism is also used for aspect specifications that have an
+   --  expression parameter that needs similar preanalysis.
 
    procedure Process_Full_View (N : Node_Id; Full_T, Priv_T : Entity_Id);
    --  Process some semantic actions when the full view of a private type is
@@ -211,27 +252,29 @@ package Sem_Ch3 is
    --  of the dependant private subtypes. The second action is to recopy the
    --  primitive operations of the private view (in the tagged case).
    --  N is the N_Full_Type_Declaration node.
-
+   --
    --    Full_T is the full view of the type whose full declaration is in N.
    --
    --    Priv_T is the private view of the type whose full declaration is in N.
 
    procedure Process_Range_Expr_In_Decl
-     (R           : Node_Id;
-      T           : Entity_Id;
-      Check_List  : List_Id := Empty_List;
-      R_Check_Off : Boolean := False);
+     (R            : Node_Id;
+      T            : Entity_Id;
+      Check_List   : List_Id := Empty_List;
+      R_Check_Off  : Boolean := False;
+      In_Iter_Schm : Boolean := False);
    --  Process a range expression that appears in a declaration context. The
-   --  range is analyzed and resolved with the base type of the given type,
-   --  and an appropriate check for expressions in non-static contexts made
-   --  on the bounds. R is analyzed and resolved using T, so the caller should
-   --  if necessary link R into the tree before the call, and in particular in
-   --  the case of a subtype declaration, it is appropriate to set the parent
-   --  pointer of R so that the types get properly frozen. The Check_List
-   --  parameter is used when the subprogram is called from
-   --  Build_Record_Init_Proc and is used to return a set of constraint
-   --  checking statements generated by the Checks package. R_Check_Off is set
-   --  to True when the call to Range_Check is to be skipped.
+   --  range is analyzed and resolved with the base type of the given type, and
+   --  an appropriate check for expressions in non-static contexts made on the
+   --  bounds. R is analyzed and resolved using T, so the caller should if
+   --  necessary link R into the tree before the call, and in particular in the
+   --  case of a subtype declaration, it is appropriate to set the parent
+   --  pointer of R so that the types get properly frozen. Check_List is used
+   --  when the subprogram is called from Build_Record_Init_Proc and is used to
+   --  return a set of constraint checking statements generated by the Checks
+   --  package. R_Check_Off is set to True when the call to Range_Check is to
+   --  be skipped. In_Iter_Schm is True if Process_Range_Expr_In_Decl is called
+   --  on the discrete subtype definition in an iteration scheme.
 
    function Process_Subtype
      (S           : Node_Id;
@@ -249,6 +292,10 @@ package Sem_Ch3 is
    --  Process the discriminants contained in an N_Full_Type_Declaration or
    --  N_Incomplete_Type_Decl node N. If the declaration is a completion,
    --  Prev is entity on the partial view, on which references are posted.
+   --  However, note that Process_Discriminants is called for a completion only
+   --  if partial view had no discriminants (else we just check conformance
+   --  between the two views and do not call Process_Discriminants again for
+   --  the completion).
 
    function Replace_Anonymous_Access_To_Protected_Subprogram
      (N : Node_Id) return Entity_Id;