[multiple changes]
[gcc.git] / gcc / ada / sem_prag.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ P R A G --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2013, 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 -- Pragma handling is isolated in a separate package
27 -- (logically this processing belongs in chapter 4)
28
29 with Namet; use Namet;
30 with Snames; use Snames;
31 with Types; use Types;
32
33 package Sem_Prag is
34
35 -- The following table lists all the implementation-defined pragmas that
36 -- may apply to a body stub (no language defined pragmas apply). The table
37 -- should be synchronized with Aspect_On_Body_Or_Stub_OK in unit Aspects if
38 -- the pragmas below implement an aspect.
39
40 Pragma_On_Body_Or_Stub_OK : constant array (Pragma_Id) of Boolean :=
41 (Pragma_Refined_Depends => True,
42 Pragma_Refined_Global => True,
43 Pragma_Refined_Post => True,
44 Pragma_Refined_Pre => True,
45 Pragma_SPARK_Mode => True,
46 Pragma_Warnings => True,
47 others => False);
48
49 -----------------
50 -- Subprograms --
51 -----------------
52
53 procedure Analyze_Pragma (N : Node_Id);
54 -- Analyze procedure for pragma reference node N
55
56 procedure Analyze_Contract_Cases_In_Decl_Part (N : Node_Id);
57 -- Perform full analysis and expansion of delayed pragma Contract_Cases
58
59 procedure Analyze_Depends_In_Decl_Part (N : Node_Id);
60 -- Perform full analysis of delayed pragma Depends
61
62 procedure Analyze_Global_In_Decl_Part (N : Node_Id);
63 -- Perform full analysis of delayed pragma Global
64
65 procedure Analyze_Pre_Post_Condition_In_Decl_Part
66 (Prag : Node_Id;
67 Subp_Id : Entity_Id);
68 -- Perform preanalysis of a [refined] precondition or postcondition that
69 -- appears on a subprogram declaration or body [stub]. Prag denotes the
70 -- pragma, Subp_Id is the entity of the related subprogram. The preanalysis
71 -- of the expression is done as "spec expression" (see section "Handling
72 -- of Default and Per-Object Expressions in Sem).
73
74 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id);
75 -- Preform full analysis of delayed pragma Refined_Depends
76
77 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id);
78 -- Perform full analysis of delayed pragma Refined_Global
79
80 procedure Analyze_Refined_State_In_Decl_Part (N : Node_Id);
81 -- Perform full analysis of delayed pragma Refined_State
82
83 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id; S : Entity_Id);
84 -- Perform preanalysis of pragma Test_Case that applies to a subprogram
85 -- declaration. Parameter N denotes the pragma, S is the entity of the
86 -- related subprogram. The preanalysis of the expression is done as "spec
87 -- expression" (see section "Handling of Default and Per-Object Expressions
88 -- in Sem).
89
90 procedure Check_Applicable_Policy (N : Node_Id);
91 -- N is either an N_Aspect or an N_Pragma node. There are two cases. If
92 -- the name of the aspect or pragma is not one of those recognized as
93 -- an assertion kind by an Assertion_Policy pragma, then the call has
94 -- no effect. Note that in the case of a pragma derived from an aspect,
95 -- the name we use for the purpose of this procedure is the aspect name,
96 -- which may be different from the pragma name (e.g. Precondition for
97 -- Pre aspect). In addition, 'Class aspects are recognized (and the
98 -- corresponding special names used in the processing).
99 --
100 -- If the name is a valid assertion kind name, then the Check_Policy pragma
101 -- chain is checked for a matching entry (or for an Assertion entry which
102 -- matches all possibilities). If a matching entry is found then the policy
103 -- is checked. If it is On or Check, then the Is_Checked flag is set in
104 -- the aspect or pragma node. If it is Off, Ignore, or Disable, then the
105 -- Is_Ignored flag is set in the aspect or pragma node. Additionally for
106 -- policy Disable, the Is_Disabled flag is set.
107 --
108 -- If no matching Check_Policy pragma is found then the effect depends on
109 -- whether -gnata was used, if so, then the call has no effect, otherwise
110 -- Is_Ignored (but not Is_Disabled) is set True.
111
112 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean;
113 -- N is a pragma appearing in a configuration pragma file. Most such
114 -- pragmas are analyzed when the file is read, before parsing and analyzing
115 -- the main unit. However, the analysis of certain pragmas results in
116 -- adding information to the compiled main unit, and this cannot be done
117 -- till the main unit is processed. Such pragmas return True from this
118 -- function and in Frontend pragmas where Delay_Config_Pragma_Analyze is
119 -- True have their analysis delayed until after the main program is parsed
120 -- and analyzed.
121
122 function Get_SPARK_Mode_Id (N : Node_Id) return SPARK_Mode_Id;
123 -- Given a pragma SPARK_Mode node, return the corresponding mode id
124
125 procedure Initialize;
126 -- Initializes data structures used for pragma processing. Must be called
127 -- before analyzing each new main source program.
128
129 function Is_Config_Static_String (Arg : Node_Id) return Boolean;
130 -- This is called for a configuration pragma that requires either string
131 -- literal or a concatenation of string literals. We cannot use normal
132 -- static string processing because it is too early in the case of the
133 -- pragma appearing in a configuration pragmas file. If Arg is of an
134 -- appropriate form, then this call obtains the string (doing any necessary
135 -- concatenations) and places it in Name_Buffer, setting Name_Len to its
136 -- length, and then returns True. If it is not of the correct form, then an
137 -- appropriate error message is posted, and False is returned.
138
139 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean;
140 -- Determine whether pragma SPARK_Mode appears in the statement part of a
141 -- package body.
142
143 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean;
144 -- The node N is a node for an entity and the issue is whether the
145 -- occurrence is a reference for the purposes of giving warnings about
146 -- unreferenced variables. This function returns True if the reference is
147 -- not a reference from this point of view (e.g. the occurrence in a pragma
148 -- Pack) and False if it is a real reference (e.g. the occurrence in a
149 -- pragma Export);
150
151 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean;
152 -- Given an N_Pragma_Argument_Association node, Par, which has the form of
153 -- an operator symbol, determines whether or not it should be treated as an
154 -- string literal. This is called by Sem_Ch6.Analyze_Operator_Symbol. If
155 -- True is returned, the argument is converted to a string literal. If
156 -- False is returned, then the argument is treated as an entity reference
157 -- to the operator.
158
159 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean;
160 -- Determine whether pragma SPARK_Mode appears in the private part of a
161 -- package.
162
163 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean;
164 -- Returns True if Nam is one of the names recognized as a valid assertion
165 -- kind by the Assertion_Policy pragma. Note that the 'Class cases are
166 -- represented by the corresponding special names Name_uPre, Name_uPost,
167 -- Name_uInviarnat, and Name_uType_Invariant (_Pre, _Post, _Invariant,
168 -- and _Type_Invariant).
169
170 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id);
171 -- This routine makes aspects from precondition or postcondition pragmas
172 -- that appear within a generic subprogram declaration. Decl is the generic
173 -- subprogram declaration node. Note that the aspects are attached to the
174 -- generic copy and also to the orginal tree.
175
176 procedure Process_Compilation_Unit_Pragmas (N : Node_Id);
177 -- Called at the start of processing compilation unit N to deal with any
178 -- special issues regarding pragmas. In particular, we have to deal with
179 -- Suppress_All at this stage, since it can appear after the unit instead
180 -- of before (actually we allow it to appear anywhere).
181
182 procedure Relocate_Pragmas_To_Body
183 (Subp_Body : Node_Id;
184 Target_Body : Node_Id := Empty);
185 -- Resocate all pragmas that follow and apply to subprogram body Subp_Body
186 -- to its own declaration list. Candidate pragmas are classified in table
187 -- Pragma_On_Body_Or_Stub_OK. If Target_Body is set, the pragma are moved
188 -- to the declarations of Target_Body. This formal should be set when
189 -- dealing with subprogram body stubs or expression functions.
190
191 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id);
192 -- This routine is used to set an encoded interface name. The node S is an
193 -- N_String_Literal node for the external name to be set, and E is an
194 -- entity whose Interface_Name field is to be set. In the normal case where
195 -- S contains a name that is a valid C identifier, then S is simply set as
196 -- the value of the Interface_Name. Otherwise it is encoded. See the body
197 -- for details of the encoding. This encoding is only done on VMS systems,
198 -- since it seems pretty silly, but is needed to pass some dubious tests in
199 -- the test suite.
200
201 end Sem_Prag;