1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- Pragma handling is isolated in a separate package
27 -- (logically this processing belongs in chapter 4)
29 with Namet
; use Namet
;
30 with Types
; use Types
;
38 procedure Analyze_Pragma
(N
: Node_Id
);
39 -- Analyze procedure for pragma reference node N
41 procedure Analyze_Contract_Cases_In_Decl_Part
(N
: Node_Id
);
42 -- Perform full analysis and expansion of delayed pragma Contract_Cases
44 procedure Analyze_Depends_In_Decl_Part
(N
: Node_Id
);
45 -- Perform full analysis of delayed pragma Depends
47 procedure Analyze_Global_In_Decl_Part
(N
: Node_Id
);
48 -- Perform full analysis of delayed pragma Global
50 procedure Analyze_PPC_In_Decl_Part
(N
: Node_Id
; S
: Entity_Id
);
51 -- Special analyze routine for precondition/postcondition pragma that
52 -- appears within a declarative part where the pragma is associated
53 -- with a subprogram specification. N is the pragma node, and S is the
54 -- entity for the related subprogram. This procedure does a preanalysis
55 -- of the expressions in the pragma as "spec expressions" (see section
56 -- in Sem "Handling of Default and Per-Object Expressions...").
58 procedure Analyze_Test_Case_In_Decl_Part
(N
: Node_Id
; S
: Entity_Id
);
59 -- Special analyze routine for contract-case and test-case pragmas that
60 -- appears within a declarative part where the pragma is associated with
61 -- a subprogram specification. N is the pragma node, and S is the entity
62 -- for the related subprogram. This procedure does a preanalysis of the
63 -- expressions in the pragma as "spec expressions" (see section in Sem
64 -- "Handling of Default and Per-Object Expressions...").
66 function Check_Kind
(Nam
: Name_Id
) return Name_Id
;
67 -- This function is used in connection with pragmas Assert, Check,
68 -- and assertion aspects and pragmas, to determine if Check pragmas
69 -- (or corresponding assertion aspects or pragmas) are currently active
70 -- as determined by the presence of -gnata on the command line (which
71 -- sets the default), and the appearance of pragmas Check_Policy and
72 -- Assertion_Policy as configuration pragmas either in a configuration
73 -- pragma file, or at the start of the current unit, or locally given
74 -- Check_Policy and Assertion_Policy pragmas that are currently active.
76 -- The value returned is one of the names Check, Ignore, Disable (On
77 -- returns Check, and Off returns Ignore).
79 -- Note: for assertion kinds Pre'Class, Post'Class, Invariant'Class,
80 -- and Type_Invariant'Class, the name passed is Name_uPre, Name_uPost,
81 -- Name_uInvariant, or Name_uType_Invariant, which corresponds to _Pre,
82 -- _Post, _Invariant, or _Type_Invariant, which are special names used
83 -- in identifiers to represent these attribute references.
85 procedure Check_Applicable_Policy
(N
: Node_Id
);
86 -- N is either an N_Aspect or an N_Pragma node. There are two cases. If
87 -- the name of the aspect or pragma is not one of those recognized as
88 -- an assertion kind by an Assertion_Policy pragma, then the call has
89 -- no effect. Note that in the case of a pragma derived from an aspect,
90 -- the name we use for the purpose of this procedure is the aspect name,
91 -- which may be different from the pragma name (e.g. Precondition for
92 -- Pre aspect). In addition, 'Class aspects are recognized (and the
93 -- corresponding special names used in the processing).
95 -- If the name is a valid assertion kind name, then the Check_Policy pragma
96 -- chain is checked for a matching entry (or for an Assertion entry which
97 -- matches all possibilities). If a matching entry is found then the policy
98 -- is checked. If it is Off, Ignore, or Disable, then the Is_Ignored flag
99 -- is set in the aspect or pragma node. Additionally for policy Disable,
100 -- the Is_Disabled flag is set.
102 -- If no matching Check_Policy pragma is found then the effect depends on
103 -- whether -gnata was used, if so, then the call has no effect, otherwise
104 -- Is_Ignored (but not Is_Disabled) is set True.
106 function Delay_Config_Pragma_Analyze
(N
: Node_Id
) return Boolean;
107 -- N is a pragma appearing in a configuration pragma file. Most such
108 -- pragmas are analyzed when the file is read, before parsing and analyzing
109 -- the main unit. However, the analysis of certain pragmas results in
110 -- adding information to the compiled main unit, and this cannot be done
111 -- till the main unit is processed. Such pragmas return True from this
112 -- function and in Frontend pragmas where Delay_Config_Pragma_Analyze is
113 -- True have their analysis delayed until after the main program is parsed
116 procedure Initialize
;
117 -- Initializes data structures used for pragma processing. Must be called
118 -- before analyzing each new main source program.
120 function Is_Config_Static_String
(Arg
: Node_Id
) return Boolean;
121 -- This is called for a configuration pragma that requires either string
122 -- literal or a concatenation of string literals. We cannot use normal
123 -- static string processing because it is too early in the case of the
124 -- pragma appearing in a configuration pragmas file. If Arg is of an
125 -- appropriate form, then this call obtains the string (doing any necessary
126 -- concatenations) and places it in Name_Buffer, setting Name_Len to its
127 -- length, and then returns True. If it is not of the correct form, then an
128 -- appropriate error message is posted, and False is returned.
130 function Is_Non_Significant_Pragma_Reference
(N
: Node_Id
) return Boolean;
131 -- The node N is a node for an entity and the issue is whether the
132 -- occurrence is a reference for the purposes of giving warnings about
133 -- unreferenced variables. This function returns True if the reference is
134 -- not a reference from this point of view (e.g. the occurrence in a pragma
135 -- Pack) and False if it is a real reference (e.g. the occurrence in a
138 function Is_Pragma_String_Literal
(Par
: Node_Id
) return Boolean;
139 -- Given an N_Pragma_Argument_Association node, Par, which has the form of
140 -- an operator symbol, determines whether or not it should be treated as an
141 -- string literal. This is called by Sem_Ch6.Analyze_Operator_Symbol. If
142 -- True is returned, the argument is converted to a string literal. If
143 -- False is returned, then the argument is treated as an entity reference
146 function Is_Valid_Assertion_Kind
(Nam
: Name_Id
) return Boolean;
147 -- Returns True if Nam is one of the names recognized as a valid assertion
148 -- kind by the Assertion_Policy pragma. Note that the 'Class cases are
149 -- represented by the corresponding special names Name_uPre, Name_uPost,
150 -- Name_uInviarnat, and Name_uType_Invariant (_Pre, _Post, _Invariant,
151 -- and _Type_Invariant).
153 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl
(Decl
: Node_Id
);
154 -- This routine makes aspects from precondition or postcondition pragmas
155 -- that appear within a generic subprogram declaration. Decl is the generic
156 -- subprogram declaration node. Note that the aspects are attached to the
157 -- generic copy and also to the orginal tree.
159 procedure Process_Compilation_Unit_Pragmas
(N
: Node_Id
);
160 -- Called at the start of processing compilation unit N to deal with any
161 -- special issues regarding pragmas. In particular, we have to deal with
162 -- Suppress_All at this stage, since it can appear after the unit instead
163 -- of before (actually we allow it to appear anywhere).
165 procedure Set_Encoded_Interface_Name
(E
: Entity_Id
; S
: Node_Id
);
166 -- This routine is used to set an encoded interface name. The node S is an
167 -- N_String_Literal node for the external name to be set, and E is an
168 -- entity whose Interface_Name field is to be set. In the normal case where
169 -- S contains a name that is a valid C identifier, then S is simply set as
170 -- the value of the Interface_Name. Otherwise it is encoded. See the body
171 -- for details of the encoding. This encoding is only done on VMS systems,
172 -- since it seems pretty silly, but is needed to pass some dubious tests in