1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT COMPILER COMPONENTS                         --
4--                                                                          --
5--                              S E M _ C A T                               --
6--                                                                          --
7--                                 S p e c                                  --
8--                                                                          --
9--          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
10--                                                                          --
11-- GNAT is free software;  you can  redistribute it  and/or modify it under --
12-- terms of the  GNU General Public License as published  by the Free Soft- --
13-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17-- for  more details.  You should have  received  a copy of the GNU General --
18-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19-- http://www.gnu.org/licenses for a complete copy of the license.          --
20--                                                                          --
21-- GNAT was originally developed  by the GNAT team at  New York University. --
22-- Extensive contributions were provided by Ada Core Technologies Inc.      --
23--                                                                          --
24------------------------------------------------------------------------------
25
26--  This unit contains the routines used for checking for conformance with
27--  the semantic restrictions required for the categorization pragmas:
28--
29--    Preelaborate
30--    Pure,
31--    Remote_Call_Interface
32--    Remote_Types
33--    Shared_Passive
34--
35--  Note that we treat Preelaborate as a categorization pragma, even though
36--  strictly, according to RM E.2(2,3), the term does not apply in this case.
37
38with Exp_Tss; use Exp_Tss;
39with Types;   use Types;
40
41package Sem_Cat is
42
43   function Has_Stream_Attribute_Definition
44     (Typ          : Entity_Id;
45      Nam          : TSS_Name_Type;
46      At_Any_Place : Boolean := False) return Boolean;
47   --  True when there is a attribute definition clause specifying attribute
48   --  Nam for Typ. In Ada 2005 mode, returns True only when the attribute
49   --  definition clause is visible, unless At_Any_Place is True (in which case
50   --  no visibility test is made, and True is returned as long as an attribute
51   --  is visible at any place). Note that attribute definition clauses
52   --  inherited from parent types are taken into account by this predicate
53   --  (to test for presence of an attribute definition clause for one
54   --  specific type, excluding inherited definitions, the flags
55   --  Has_Specified_Stream_* can be used instead).
56
57   function In_Preelaborated_Unit return Boolean;
58   --  Determines if the current scope is within a preelaborated compilation
59   --  unit, that is one to which one of the pragmas Preelaborate, Pure,
60   --  Shared_Passive, Remote_Types, or inside a unit other than a package
61   --  body with pragma Remote_Call_Interface.
62
63   function In_Pure_Unit return Boolean;
64   pragma Inline (In_Pure_Unit);
65   --  Determines if the current scope is within pure compilation unit,
66   --  that is, one to which the pragmas Pure is applied.
67
68   function In_Subprogram_Task_Protected_Unit return Boolean;
69   --  Determines if the current scope is within a subprogram, task
70   --  or protected unit. Used to validate if the library unit is Pure
71   --  (RM 10.2.1(16)).
72
73   procedure Set_Categorization_From_Pragmas (N : Node_Id);
74   --  Since validation of categorization dependency is done during Analyze,
75   --  categorization flags from following pragmas should be set before
76   --  validation begin. N is the N_Compilation_Unit node.
77
78   procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id);
79   --  Set categorization flags Pure, Remote_Call_Interface and Remote_Types
80   --  on entity E according to those of Scop.
81
82   procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id);
83   --  Validate all constraints against declaration of access types in
84   --  categorized library units. Usually this is a violation in Pure unit,
85   --  Shared_Passive unit. N is the declaration node.
86
87   procedure Validate_Ancestor_Part (N : Node_Id);
88   --  Checks that a type given as the ancestor in an extension aggregate
89   --  satisfies the restriction of 10.2.1(9).
90
91   procedure Validate_Categorization_Dependency (N : Node_Id; E : Entity_Id);
92   --  There are restrictions on lib unit that semantically depends on other
93   --  units (RM E.2(5), 10.2.1(11). This procedure checks the restrictions
94   --  on categorizations. N is the current unit node, and E is the current
95   --  library unit entity.
96
97   procedure Validate_Controlled_Object (E : Entity_Id);
98   --  Given an entity for a library level controlled object, check that it is
99   --  not in a preelaborated unit (prohibited by RM 10.2.1(9)).
100
101   procedure Validate_Null_Statement_Sequence (N : Node_Id);
102   --  Given N, a package body node, check that a handled statement sequence
103   --  in a preelaborable body contains no statements other than labels or
104   --  null statements, as required by RM 10.2.1(6).
105
106   procedure Validate_Object_Declaration (N : Node_Id);
107   --  Given N, an object declaration node, validates all the constraints in
108   --  a preelaborable library unit, including creation of task objects etc.
109   --  Note that this is called when the corresponding object is frozen since
110   --  the checks cannot be made before knowing if the object is imported.
111
112   procedure Validate_RCI_Declarations (P : Entity_Id);
113   --  Apply semantic checks given in  E2.3(10-14)
114
115   procedure Validate_RCI_Subprogram_Declaration (N : Node_Id);
116   --  Check RCI subprogram declarations for illegal inlining and formals not
117   --  supporting external streaming.
118
119   procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id);
120   --  Checks that Storage_Pool and Storage_Size attribute references are
121   --  not applied to remote access-to-class-wide types. And the expected
122   --  type for an allocator shall not be a remote access-to-class-wide
123   --  type. And a remote access-to-class-wide type shall not be an actual
124   --  parameter for a generic formal access type. RM E.2.3(22).
125
126   procedure Validate_RT_RAT_Component (N : Node_Id);
127   --  Given N, the package library unit declaration node, we should check
128   --  against RM:9.95 E.2.2(8): the full view of a type declared in the
129   --  visible part of a Remote Types unit has a part that is of a non-remote
130   --  access type which has no read/write.
131
132   procedure Validate_Remote_Type_Type_Conversion (N : Node_Id);
133   --  Check for remote-type type conversion constraints. First, a value of
134   --  a remote access-to-subprogram type can be converted only to another
135   --  type conformant remote access-to-subprogram type. Secondly, a value
136   --  of a remote access-to-class-wide type can be converted only to another
137   --  remote access-to-class-wide type (RM E.2.3(17,20)).
138
139   procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id);
140   --  Check validity of declaration if shared passive unit. It should not
141   --  contain the declaration of an access-to-object type whose designated
142   --  type is a class-wide type ,task type or protected type. E.2.1(7).
143   --  T is the entity of the declared type.
144
145   procedure Validate_Static_Object_Name (N : Node_Id);
146   --  In the elaboration code of a preelaborated library unit, check that we
147   --  do not have the evaluation of a primary that is a name of an object,
148   --  unless the name is a static expression (RM 10.2.1(8)). Non-static
149   --  constant and variable are the targets, generic parameters are not
150   --  are not included because the generic declaration and body are
151   --  preelaborable.
152
153   procedure Validate_RACW_Primitives (T : Entity_Id);
154   --  Enforce constraints on primitive operations of the designated type of
155   --  an RACW. Note that since the complete set of primitive operations of the
156   --  designated type needs to be known, we must defer these checks until the
157   --  designated type is frozen.
158
159end Sem_Cat;
160