111
|
1 ------------------------------------------------------------------------------
|
|
2 -- --
|
|
3 -- GNAT COMPILER COMPONENTS --
|
|
4 -- --
|
|
5 -- C A S I N G --
|
|
6 -- --
|
|
7 -- S p e c --
|
|
8 -- --
|
131
|
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
|
111
|
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. --
|
|
17 -- --
|
|
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
|
|
19 -- additional permissions described in the GCC Runtime Library Exception, --
|
|
20 -- version 3.1, as published by the Free Software Foundation. --
|
|
21 -- --
|
|
22 -- You should have received a copy of the GNU General Public License and --
|
|
23 -- a copy of the GCC Runtime Library Exception along with this program; --
|
|
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
|
|
25 -- <http://www.gnu.org/licenses/>. --
|
|
26 -- --
|
|
27 -- GNAT was originally developed by the GNAT team at New York University. --
|
|
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
|
|
29 -- --
|
|
30 ------------------------------------------------------------------------------
|
|
31
|
|
32 with Namet; use Namet;
|
|
33 with Types; use Types;
|
|
34
|
|
35 package Casing is
|
|
36
|
|
37 -- This package contains data and subprograms to support the feature that
|
|
38 -- recognizes the letter case styles used in the source program being
|
|
39 -- compiled, and uses this information for error message formatting, and
|
|
40 -- for recognizing reserved words that are misused as identifiers.
|
|
41
|
|
42 -------------------------------
|
|
43 -- Case Control Declarations --
|
|
44 -------------------------------
|
|
45
|
|
46 -- Declaration of type for describing casing convention
|
|
47
|
|
48 type Casing_Type is (
|
|
49
|
|
50 All_Upper_Case,
|
|
51 -- All letters are upper case
|
|
52
|
|
53 All_Lower_Case,
|
|
54 -- All letters are lower case
|
|
55
|
|
56 Mixed_Case,
|
|
57 -- The initial letter, and any letters after underlines are upper case.
|
|
58 -- All other letters are lower case
|
|
59
|
|
60 Unknown
|
|
61 -- Used if an identifier does not distinguish between the above cases,
|
|
62 -- (e.g. X, Y_3, M4, A_B, or if it is inconsistent ABC_def).
|
|
63 );
|
|
64
|
|
65 subtype Known_Casing is Casing_Type range All_Upper_Case .. Mixed_Case;
|
|
66 -- Exclude Unknown casing
|
|
67
|
|
68 ------------------------------
|
|
69 -- Case Control Subprograms --
|
|
70 ------------------------------
|
|
71
|
|
72 procedure Set_Casing
|
|
73 (Buf : in out Bounded_String;
|
|
74 C : Casing_Type;
|
|
75 D : Casing_Type := Mixed_Case);
|
|
76 -- Takes the name stored in Buf and modifies it to be consistent with the
|
|
77 -- casing given by C, or if C = Unknown, then with the casing given by
|
|
78 -- D. The name is basically treated as an identifier, except that special
|
|
79 -- separator characters other than underline are permitted and treated like
|
|
80 -- underlines (this handles cases like minus and period in unit names,
|
|
81 -- apostrophes in error messages, angle brackets in names like <any_type>,
|
|
82 -- etc).
|
|
83
|
|
84 procedure Set_Casing (C : Casing_Type; D : Casing_Type := Mixed_Case);
|
|
85 -- Uses Buf => Global_Name_Buffer
|
|
86
|
|
87 procedure Set_All_Upper_Case;
|
|
88 pragma Inline (Set_All_Upper_Case);
|
|
89 -- This procedure is called with an identifier name stored in Name_Buffer.
|
|
90 -- On return, the identifier is converted to all upper case. The call is
|
|
91 -- equivalent to Set_Casing (All_Upper_Case).
|
|
92
|
|
93 function Determine_Casing (Ident : Text_Buffer) return Casing_Type;
|
|
94 -- Determines the casing of the identifier/keyword string Ident. A special
|
|
95 -- test is made for SPARK_Mode which is considered to be mixed case, since
|
|
96 -- this gives a better general behavior.
|
|
97
|
|
98 end Casing;
|