The version you requested (4.8.0-36.36~16.04.1) is not available, but a newer one is (4.8.0-58.63~16.04.1). We redirected you there.
This file is indexed.

/usr/share/ada/adainclude/asis/asis-extensions-strings.adb is in libasis2014-dev 2014-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
------------------------------------------------------------------------------
--                                                                          --
--                     ASIS UTILITY LIBRARY COMPONENTS                      --
--                                                                          --
--              A S I S . E X T E N S I O N S . S T R I N G S               --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--                    Copyright (C) 2004-2013, AdaCore                      --
--                                                                          --
-- ASIS-for-GNAT is free software; you can redistribute it and/or modify it --
-- under terms of the  GNU General Public License  as published by the Free --
-- Software Foundation;  either version 2,  or  (at your option)  any later --
-- version. ASIS-for-GNAT is distributed  in the hope  that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY or  FITNESS FOR A PARTICULAR  PURPOSE.  See the GNU General --
-- Public License for more details.  You should have received a copy of the --
-- GNU  General  Public  License  distributed with ASIS-for-GNAT;  see file --
-- COPYING.  If not,  write  to the  Free Software Foundation,  51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, USA.                         --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
-- ASIS-for-GNAT was originally developed  by the ASIS-for-GNAT team at the --
-- Software  Engineering  Laboratory  of  the Swiss  Federal  Institute  of --
-- Technology (LGL-EPFL) in Lausanne,  Switzerland, in cooperation with the --
-- Scientific  Research  Computer  Center of  Moscow State University (SRCC --
-- MSU), Russia,  with funding partially provided  by grants from the Swiss --
-- National  Science  Foundation  and  the  Swiss  Academy  of  Engineering --
-- Sciences.  ASIS-for-GNAT is now maintained by  AdaCore                   --
-- (http://www.adacore.com).                                                --
--                                                                          --
------------------------------------------------------------------------------

--  This package was a part of ASIS Utility Library (as ASIS_UL.Strings). It
--  has been moved into Asis.Extensions hierarchy to optimize dependencies on
--  GNATCOOL sources.

with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Strings;             use Ada.Strings;
with Ada.Strings.Fixed;       use Ada.Strings.Fixed;
with Table;

with Asis.Elements;           use Asis.Elements;
with Asis.Set_Get;            use Asis.Set_Get;

with Atree;                   use Atree;
with Namet;                   use Namet;
with Sinput;                  use Sinput;

package body Asis.Extensions.Strings is

   package Chars is new Table.Table (
     Table_Component_Type => Character,
     Table_Index_Type     => Integer,
     Table_Low_Bound      => 1,
     Table_Initial        => 10000,
     Table_Increment      => 1000,
     Table_Name           => "character container");

   Table : Chars.Table_Ptr renames Chars.Table;

   -------------------------
   -- Build_GNAT_Location --
   -------------------------

   function Build_GNAT_Location_Old
     (For_Elem : Asis.Element;
      Line     : Natural := 0;
      Column   : Natural := 0)
      return     String_Loc
   is
      S     :          String_Loc := Nil_String_Loc;
      First : constant Natural    := Chars.Last + 1;

      P              : Source_Ptr;
      Sindex         : Source_File_Index;
      Instance_Depth : Natural := 0;

      function Strip_Space (S : String) return String;
      pragma Inline (Strip_Space);
      --  Is applied to the result of 'Img attribute. Cuts out the leading
      --  space.

      function Strip_Space (S : String) return String is
         First_Idx : constant Positive := S'First + 1;
         Result    : constant String := S (First_Idx .. S'Last);
      begin
         return Result;
      end Strip_Space;

      procedure Enter_Sloc
        (Line     : Natural := 0;
         Column   : Natural := 0);
      --  For the current value of P, sets in the string table the string
      --  of the form file_name:line_number. Also computes Sindex as the
      --  Id of the sourse file of P. If Line and Column are equal to zero,
      --  computes line and column number from P.

      procedure Enter_Sloc
        (Line     : Natural := 0;
         Column   : Natural := 0)
       is
         F_Name : File_Name_Type;
      begin
         Sindex := Get_Source_File_Index (P);
         F_Name := File_Name (Sindex);

         Get_Name_String (F_Name);

         S := Enter_String (Name_Buffer (1 .. Name_Len) & ":");

         if Line = 0 then
            S := Enter_String (Strip_Space (Get_Physical_Line_Number (P)'Img));
         else
            S := Enter_String (Strip_Space (Line'Img));
         end if;

         S := Enter_String (":");

         if Column = 0 then
            S := Enter_String (Strip_Space (Get_Column_Number (P)'Img));
         else
            S := Enter_String (Strip_Space (Column'Img));
         end if;

      end Enter_Sloc;

      procedure Enter_Node_Sloc
        (Line     : Natural := 0;
         Column   : Natural := 0);
      --  Enter the whole SLOC starting from the current value of P. This
      --  value should be created from the node of interest.

      procedure Enter_Node_Sloc
        (Line     : Natural := 0;
         Column   : Natural := 0)
      is
      begin
         if P = No_Location then
            S := Enter_String ("no location");
         elsif P <= Standard_Location then
            S := Enter_String ("Standard location");
         else
            Enter_Sloc (Line, Column);

            P := Instantiation (Sindex);

            while P /= No_Location loop
               pragma Assert (Line = 0 and then Column = 0);

               S              := Enter_String ("[");
               Instance_Depth := Instance_Depth + 1;

               Enter_Sloc;

               P := Instantiation (Sindex);
            end loop;

            for J in 1 .. Instance_Depth loop
               S := Enter_String ("]");
            end loop;

         end if;
      end Enter_Node_Sloc;

   begin
      --  The implementation is adopted from
      --  Gnatelim.Asis_Utilities.Build_Sloc_Trace

      P := Sloc (Node (For_Elem));

      Enter_Node_Sloc (Line, Column);

      if Is_Part_Of_Inherited (For_Elem) then
         S := Enter_String ("(");
         P := Sloc (Node_Field_1 (For_Elem));
         Enter_Node_Sloc (Line, Column);
         S := Enter_String (")");
      end if;

      S.First := First;
      S.Last  := Chars.Last;

      return S;
   end Build_GNAT_Location_Old;

   function Build_GNAT_Location_Old
     (For_Elem : Asis.Element;
      Line     : Natural := 0;
      Column   : Natural := 0)
      return     String
   is
      Last_Backup : constant Integer    := Chars.Last;
      Res_Sloc    : constant String_Loc :=
        Build_GNAT_Location (For_Elem, Line, Column);
   begin

      declare
         Result : constant String := Get_String (Res_Sloc);
      begin
         Chars.Set_Last (Last_Backup);
         return Result;
      end;

   end Build_GNAT_Location_Old;

   -----------------------------
   -- Build_GNAT_Location_New --
   -----------------------------

   function Build_GNAT_Location
     (For_Elem : Asis.Element;
      Line     : Natural := 0;
      Column   : Natural := 0)
      return     String_Loc
   is
      S     :          String_Loc := Nil_String_Loc;
      First : constant Natural    := Chars.Last + 1;

      P      : Source_Ptr;
      Sindex : Source_File_Index;

--      function Strip_Space (S : String) return String;
--      pragma Inline (Strip_Space);
--      --  Is applied to the result of 'Img attribute. Cuts out the leading
--      --  space.

--      function Strip_Space (S : String) return String is
--         First_Idx : constant Positive := S'First + 1;
--         Result    : constant String := S (First_Idx .. S'Last);
--      begin
--         return Result;
--      end Strip_Space;

      procedure Enter_Sloc
        (Line     : Natural := 0;
         Column   : Natural := 0);
      --  For the current value of P, sets in the string table the string
      --  of the form file_name:line_number. Also computes Sindex as the
      --  Id of the sourse file of P. If Line and Column are equal to zero,
      --  computes line and column number from P.

      procedure Enter_Sloc
        (Line     : Natural := 0;
         Column   : Natural := 0)
       is
         F_Name : File_Name_Type;
      begin
         Sindex := Get_Source_File_Index (P);
         F_Name := File_Name (Sindex);

         Get_Name_String (F_Name);

         S := Enter_String (Name_Buffer (1 .. Name_Len) & ":");

         if Line = 0 then
            S := Enter_String (Trim (Get_Physical_Line_Number (P)'Img, Left));
         else
            S := Enter_String (Trim (Line'Img, Left));
         end if;

         S := Enter_String (":");

         if Column = 0 then
            S := Enter_String (Trim (Get_Column_Number (P)'Img, Left));
         else
            S := Enter_String (Trim (Column'Img, Left));
         end if;

      end Enter_Sloc;

      procedure Enter_Node_Sloc
        (Line     : Natural := 0;
         Column   : Natural := 0);
      --  Enter the whole SLOC starting from the current value of P. This
      --  value should be created from the node of interest.

      procedure Enter_Node_Sloc
        (Line     : Natural := 0;
         Column   : Natural := 0)
      is
      begin
         if P = No_Location then
            S := Enter_String ("no location");
         elsif P <= Standard_Location then
            S := Enter_String ("Standard location");
         else
            Enter_Sloc (Line, Column);

            P := Instantiation (Sindex);

            while P /= No_Location loop
               pragma Assert (Line = 0 and then Column = 0);
               S := Enter_String (Instance_SLOC_Txt);

               Enter_Sloc;

               P := Instantiation (Sindex);
            end loop;

         end if;
      end Enter_Node_Sloc;

   begin
      --  The implementation is adopted from
      --  Gnatelim.Asis_Utilities.Build_Sloc_Trace

      P := Sloc (Node (For_Elem));

      Enter_Node_Sloc (Line, Column);

      if Is_Part_Of_Inherited (For_Elem) then
         S := Enter_String ("(");
         P := Sloc (Node_Field_1 (For_Elem));
         Enter_Node_Sloc (Line, Column);
         S := Enter_String (")");
      end if;

      S.First := First;
      S.Last  := Chars.Last;

      return S;
   end Build_GNAT_Location;

   function Build_GNAT_Location
     (For_Elem : Asis.Element;
      Line     : Natural := 0;
      Column   : Natural := 0)
      return     String
   is
      Last_Backup : constant Integer    := Chars.Last;
      Res_Sloc    : constant String_Loc :=
        Build_GNAT_Location (For_Elem, Line, Column);
   begin

      declare
         Result : constant String := Get_String (Res_Sloc);
      begin
         Chars.Set_Last (Last_Backup);
         return Result;
      end;

   end Build_GNAT_Location;

   ------------------
   -- Enter_String --
   ------------------

   function Enter_String (S : String) return String_Loc is
      Len   : constant Integer := S'Length;
      F     :          Integer;
   begin

      if Len = 0 then
         return Nil_String_Loc;
      else
         Chars.Increment_Last;
         F := Chars.Last;
         Chars.Set_Last (F + Len - 1);

         Table (F .. F + Len - 1) := Chars.Table_Type (S);

         return (F, F + Len - 1);
      end if;

   end Enter_String;

   ----------------
   -- Get_String --
   ----------------

   function Get_String (SL : String_Loc) return String is
   begin

      if SL = Nil_String_Loc then
         return "";
      else
         return String (Table (SL.First .. SL.Last));
      end if;

   end Get_String;

   ----------
   -- Init --
   ----------

   procedure Init is
   begin
      Chars.Init;
   end Init;

   --------------
   -- Is_Equal --
   --------------

   function Is_Equal (S : String; SL : String_Loc) return Boolean is
      Result : Boolean := False;
   begin

      if SL.First in 1 .. Chars.Last
        and then
         SL.Last in 1 .. Chars.Last
        and then
         SL.Last - SL.First + 1 = S'Length
      then
         Result := S = Get_String (SL);
      end if;

      return Result;

   end Is_Equal;

   ----------------
   -- Old_Format --
   ----------------

   function Old_Format (SLOC : String) return String is
      Result     :          String (SLOC'Range);
      Res_Idx    :          Natural := Result'First;
      Count      :          Natural := 0;
      SLOC_Start :          Natural;
      SLOC_End   :          Natural;
      SLOC_Last  : constant Natural := SLOC'Last;
   begin
      SLOC_End := Index (SLOC, Instance_SLOC_Txt);

      if SLOC_End = 0 then
         return SLOC;
      end if;

      SLOC_Start := SLOC'First;

      while SLOC_End /= 0 loop
         SLOC_End   := SLOC_End - 1;
         Result (Res_Idx .. Res_Idx + (SLOC_End - SLOC_Start)) :=
            SLOC (SLOC_Start .. SLOC_End);
         Res_Idx          := Res_Idx + (SLOC_End - SLOC_Start + 1);
         Result (Res_Idx) := '[';
         Res_Idx          := Res_Idx + 1;
         Count            := Count + 1;

         SLOC_Start := SLOC_End + Instance_SLOC_Txt'Length + 1;
         SLOC_End   :=
           Index (SLOC (SLOC_Start + 1 .. SLOC_Last), Instance_SLOC_Txt);
      end loop;

      Result (Res_Idx .. Res_Idx + (SLOC_Last - SLOC_Start)) :=
         SLOC (SLOC_Start .. SLOC_Last);
      Res_Idx          := Res_Idx + (SLOC_Last - SLOC_Start);

      for J in 1 .. Count loop
         Res_Idx          := Res_Idx + 1;
         Result (Res_Idx) := ']';
      end loop;

      return Result (Result'First .. Res_Idx);

   end Old_Format;

   --------------------
   -- SLOC_Less_Than --
   --------------------

   function SLOC_Less_Than (L, R : String) return Boolean is

      L_Start : Natural := L'First;
      R_Start : Natural := R'First;

      L_End   : Natural := Index (L, ":");
      R_End   : Natural := Index (R, ":");
      L_Val   : Positive;
      R_Val   : Positive;
   begin
      --  When comparing SLOCs we have the following problems:
      --  1. file names may be in different casing, and X.ads < a.ads for
      --     predefined "<"
      --  2. ':' that separates file name, line and column is greater than
      --     any digit, so for the predefined "<" a.ads:50:20 is less than
      --     a.ads 5:20
      --
      --  3. we cannot use alphabetical comparision for the whole SLOC, because
      --     line and column numbers should be compared as digits

      if L_End = 0 or else R_End = 0 then
         return False;
      elsif To_Lower (L (L_Start .. L_End)) <
            To_Lower (R (R_Start .. R_End))
      then
         return True;
      elsif To_Lower (L (L_Start .. L_End)) >
            To_Lower (R (R_Start .. R_End))
      then
         return False;
      else
         --  file names are the same, we have to compare line and column
         --  numbers
         L_Start := L_End + 1;
         R_Start := R_End + 1;
         L_End   := Index (L (L_Start .. L'Last), ":") - 1;
         R_End   := Index (R (R_Start .. R'Last), ":") - 1;
         L_Val   := Positive'Value (L (L_Start .. L_End));
         R_Val   := Positive'Value (R (R_Start .. R_End));

         if L_Val < R_Val then
            return True;
         elsif L_Val > R_Val then
            return False;
         else
            --  line numbers are also the same
            L_Start := L_End + 2;
            R_Start := R_End + 2;

            L_End   := Index (L (L_Start .. L'Last), Instance_SLOC_Txt);
            R_End   := Index (R (R_Start .. R'Last), Instance_SLOC_Txt);

            --  For old SLOC format:
            --
            --  L_End   := Index (L (L_Start .. L'Last), "[");
            --  R_End   := Index (R (R_Start .. R'Last), "[");

            if L_End = 0 then
               L_End   := L'Last;
            else
               --  SLOC from instantiation
               L_End := L_End - 1;
            end if;

            if R_End = 0 then
               R_End   := R'Last;
            else
               --  SLOC from instantiation
               R_End := R_End - 1;
            end if;

            L_Val   := Positive'Value (L (L_Start .. L_End));
            R_Val   := Positive'Value (R (R_Start .. R_End));

            if L_Val < R_Val then
               return True;
            else
               return False;
            end if;

         end if;
      end if;

   end SLOC_Less_Than;

end Asis.Extensions.Strings;