| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- C A S I N G -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, 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 |
with Namet; use Namet; |
| 27 |
with Types; use Types; |
| 28 |
|
| 29 |
package Casing is |
| 30 |
|
| 31 |
-- This package contains data and subprograms to support the feature that |
| 32 |
-- recognizes the letter case styles used in the source program being |
| 33 |
-- compiled, and uses this information for error message formatting, and |
| 34 |
-- for recognizing reserved words that are misused as identifiers. |
| 35 |
|
| 36 |
------------------------------- |
| 37 |
-- Case Control Declarations -- |
| 38 |
------------------------------- |
| 39 |
|
| 40 |
-- Declaration of type for describing casing convention |
| 41 |
|
| 42 |
type Casing_Type is ( |
| 43 |
|
| 44 |
All_Upper_Case, |
| 45 |
-- All letters are upper case |
| 46 |
|
| 47 |
All_Lower_Case, |
| 48 |
-- All letters are lower case |
| 49 |
|
| 50 |
Mixed_Case, |
| 51 |
-- The initial letter, and any letters after underlines are upper case. |
| 52 |
-- All other letters are lower case |
| 53 |
|
| 54 |
Unknown |
| 55 |
-- Used if an identifier does not distinguish between the above cases, |
| 56 |
-- (e.g. X, Y_3, M4, A_B, or if it is inconsistent ABC_def). |
| 57 |
); |
| 58 |
|
| 59 |
subtype Known_Casing is Casing_Type range All_Upper_Case .. Mixed_Case; |
| 60 |
-- Exclude Unknown casing |
| 61 |
|
| 62 |
------------------------------ |
| 63 |
-- Case Control Subprograms -- |
| 64 |
------------------------------ |
| 65 |
|
| 66 |
procedure Set_Casing |
| 67 |
(Buf : in out Bounded_String; |
| 68 |
C : Casing_Type; |
| 69 |
D : Casing_Type := Mixed_Case); |
| 70 |
-- Takes the name stored in Buf and modifies it to be consistent with the |
| 71 |
-- casing given by C, or if C = Unknown, then with the casing given by |
| 72 |
-- D. The name is basically treated as an identifier, except that special |
| 73 |
-- separator characters other than underline are permitted and treated like |
| 74 |
-- underlines (this handles cases like minus and period in unit names, |
| 75 |
-- apostrophes in error messages, angle brackets in names like <any_type>, |
| 76 |
-- etc). |
| 77 |
|
| 78 |
procedure Set_Casing (C : Casing_Type; D : Casing_Type := Mixed_Case); |
| 79 |
-- Uses Buf => Global_Name_Buffer |
| 80 |
|
| 81 |
function Determine_Casing (Ident : Text_Buffer) return Casing_Type; |
| 82 |
-- Determines the casing of the identifier/keyword string Ident. A special |
| 83 |
-- test is made for SPARK_Mode which is considered to be mixed case, since |
| 84 |
-- this gives a better general behavior. |
| 85 |
|
| 86 |
end Casing; |