1------------------------------------------------------------------------------ 2-- -- 3-- GNAT COMPILER COMPONENTS -- 4-- -- 5-- U N A M E -- 6-- -- 7-- S p e c -- 8-- -- 9-- Copyright (C) 1992-2020, 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 26with Namet; use Namet; 27with Types; use Types; 28 29package Uname is 30 31 --------------------------- 32 -- Unit Name Conventions -- 33 --------------------------- 34 35 -- Units are associated with a unique ASCII name as follows. First we have 36 -- the fully expanded name of the unit, with lower case letters (except 37 -- for the use of upper case letters for encoding upper half and wide 38 -- characters, as described in Namet), and periods. Following this is one 39 -- of the following suffixes: 40 41 -- %s for package/subprogram/generic declarations (specs) 42 -- %b for package/subprogram/generic bodies and subunits 43 44 -- Unit names are stored in the names table, and referred to by the 45 -- corresponding Name_Id values. The type Unit_Name_Type, derived from 46 -- Name_Id, is used to indicate that a Name_Id value that holds a unit name 47 -- (as defined above) is expected. 48 49 -- Note: as far as possible the conventions for unit names are encapsulated 50 -- in this package. The one exception is that package Fname, which provides 51 -- conversion routines from unit names to file names must be aware of the 52 -- precise conventions that are used. 53 54 ------------------- 55 -- Display Names -- 56 ------------------- 57 58 -- For display purposes, unit names are printed out with the suffix 59 -- " (body)" for a body and " (spec)" for a spec. These formats are 60 -- used for the Write_Unit_Name and Get_Unit_Name_String subprograms. 61 62 ----------------- 63 -- Subprograms -- 64 ----------------- 65 66 function Get_Body_Name (N : Unit_Name_Type) return Unit_Name_Type; 67 -- Given the name of a spec, this function returns the name of the 68 -- corresponding body, i.e. characters %s replaced by %b 69 70 function Get_Parent_Body_Name (N : Unit_Name_Type) return Unit_Name_Type; 71 -- Given the name of a subunit, returns the name of the parent body 72 73 function Get_Parent_Spec_Name (N : Unit_Name_Type) return Unit_Name_Type; 74 -- Given the name of a child unit spec or body, returns the unit name 75 -- of the parent spec. Returns No_Name if the given name is not the name 76 -- of a child unit. 77 78 procedure Get_External_Unit_Name_String (N : Unit_Name_Type); 79 -- Given the name of a body or spec unit, this procedure places in 80 -- Name_Buffer the name of the unit with periods replaced by double 81 -- underscores. The spec/body indication is eliminated. The length 82 -- of the stored name is placed in Name_Len. All letters are lower 83 -- case, corresponding to the string used in external names. 84 85 function Get_Spec_Name (N : Unit_Name_Type) return Unit_Name_Type; 86 -- Given the name of a body, this function returns the name of the 87 -- corresponding spec, i.e. characters %b replaced by %s 88 89 function Get_Unit_Name (N : Node_Id) return Unit_Name_Type; 90 -- This procedure returns the unit name that corresponds to the given node, 91 -- which is one of the following: 92 -- 93 -- N_Subprogram_Declaration (spec) cases 94 -- N_Package_Declaration 95 -- N_Generic_Declaration 96 -- N_With_Clause 97 -- N_Function_Instantiation 98 -- N_Package_Instantiation 99 -- N_Procedure_Instantiation 100 -- N_Pragma (Elaborate case) 101 -- 102 -- N_Package_Body (body) cases 103 -- N_Subprogram_Body 104 -- N_Identifier 105 -- N_Selected_Component 106 -- 107 -- N_Subprogram_Body_Stub (subunit) cases 108 -- N_Package_Body_Stub 109 -- N_Task_Body_Stub 110 -- N_Protected_Body_Stub 111 -- N_Subunit 112 113 procedure Get_Unit_Name_String 114 (N : Unit_Name_Type; 115 Suffix : Boolean := True); 116 -- Places the display name of the unit in Name_Buffer and sets Name_Len to 117 -- the length of the stored name, i.e. it uses the same interface as the 118 -- Get_Name_String routine in the Namet package. The name is decoded and 119 -- contains an indication of spec or body if Boolean parameter Suffix is 120 -- True. 121 122 function Is_Body_Name (N : Unit_Name_Type) return Boolean; 123 -- Returns True iff the given name is the unit name of a body (i.e. if 124 -- it ends with the characters %b). 125 126 function Is_Child_Name (N : Unit_Name_Type) return Boolean; 127 -- Returns True iff the given name is a child unit name (of either a 128 -- body or a spec). 129 130 function Is_Internal_Unit_Name 131 (Name : String; 132 Renamings_Included : Boolean := True) return Boolean; 133 -- Same as Fname.Is_Internal_File_Name, except it works with the name of 134 -- the unit, rather than the file name. 135 136 function Is_Predefined_Unit_Name 137 (Name : String; 138 Renamings_Included : Boolean := True) return Boolean; 139 -- Same as Fname.Is_Predefined_File_Name, except it works with the name of 140 -- the unit, rather than the file name. 141 142 function Is_Spec_Name (N : Unit_Name_Type) return Boolean; 143 -- Returns True iff the given name is the unit name of a specification 144 -- (i.e. if it ends with the characters %s). 145 146 function Name_To_Unit_Name (N : Name_Id) return Unit_Name_Type; 147 -- Given the Id of the Ada name of a unit, this function returns the 148 -- corresponding unit name of the spec (by appending %s to the name). 149 150 function New_Child 151 (Old : Unit_Name_Type; 152 Newp : Unit_Name_Type) return Unit_Name_Type; 153 -- Old is a child unit name (for either a body or spec). Newp is the unit 154 -- name of the actual parent (this may be different from the parent in 155 -- old). The returned unit name is formed by taking the parent name from 156 -- Newp and the child unit name from Old, with the result being a body or 157 -- spec depending on Old. For example: 158 -- 159 -- Old = A.B.C (body) 160 -- Newp = A.R (spec) 161 -- result = A.R.C (body) 162 -- 163 -- See spec of Load_Unit for extensive discussion of why this routine 164 -- needs to be used (the call in the body of Load_Unit is the only one). 165 166 function Uname_Ge (Left, Right : Unit_Name_Type) return Boolean; 167 function Uname_Gt (Left, Right : Unit_Name_Type) return Boolean; 168 function Uname_Le (Left, Right : Unit_Name_Type) return Boolean; 169 function Uname_Lt (Left, Right : Unit_Name_Type) return Boolean; 170 -- These functions perform lexicographic ordering of unit names. The 171 -- ordering is suitable for printing, and is not quite a straightforward 172 -- comparison of the names, since the convention is that specs appear 173 -- before bodies. Note that the standard = and /= operators work fine 174 -- because all unit names are hashed into the name table, so if two names 175 -- are the same, they always have the same Name_Id value. 176 177 procedure Write_Unit_Name (N : Unit_Name_Type); 178 -- Given a unit name, this procedure writes the display name to the 179 -- standard output file. Name_Buffer and Name_Len are set as described 180 -- above for the Get_Unit_Name_String call on return. 181 182end Uname; 183