prettier_ada_25.0.0_a67a3337/src/prettier_ada-documents.adb

  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
--
--  Copyright (C) 2023, AdaCore
--  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--

with Ada.Strings;       use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Unchecked_Deallocation;

with Prettier_Ada.Documents.Implementation;

package body Prettier_Ada.Documents is

   ---------
   -- "=" --
   ---------

   function "=" (Left, Right : Document_Type) return Boolean
     renames Prettier_Ada.Documents.Implementation."=";

   ------------
   -- Format --
   ------------

   function Format
     (Document : Document_Type;
      Options  : Format_Options_Type := Default_Format_Options)
      return Ada.Strings.Unbounded.Unbounded_String
     renames Prettier_Ada.Documents.Implementation.Format;

   ----------
   -- Hash --
   ----------

   function Hash (Document : Document_Type) return Ada.Containers.Hash_Type
     renames Prettier_Ada.Documents.Implementation.Hash;

   ----------
   -- Hash --
   ----------

   function Hash (Symbol : Symbol_Type) return Ada.Containers.Hash_Type
     renames Prettier_Ada.Documents.Implementation.Hash;

   -----------
   -- Image --
   -----------

   function Image (Symbol : Symbol_Type) return String is
   begin
      return Trim (Symbol'Image, Left);
   end Image;

   ----------------
   -- New_Symbol --
   ----------------

   function New_Symbol return Symbol_Type
     renames Prettier_Ada.Documents.Implementation.New_Symbol;

   ----------------------
   -- To_Document_Type --
   ----------------------

   function To_Document_Type (Text : Wide_Wide_String) return Document_Type
     renames Prettier_Ada.Documents.Implementation.To_Document_Type;

   ------------
   -- Adjust --
   ------------

   overriding procedure Adjust (Self : in out Document_Type) is
   begin
      if Self.Bare_Document /= null then
         Self.Bare_Document.Ref_Count := @ + 1;
      end if;
   end Adjust;

   --------------
   -- Finalize --
   --------------

   overriding procedure Finalize (Self : in out Document_Type) is
      use Prettier_Ada.Documents.Implementation;

      procedure Free is new Ada.Unchecked_Deallocation
        (Bare_Document_Record, Bare_Document_Access);
      procedure Free is new Ada.Unchecked_Deallocation
        (Command_Type, Command_Access);
   begin
      if Self.Bare_Document /= null then
         if Self.Bare_Document.Ref_Count = 1 then
            if Self.Bare_Document.Kind = Document_Command then
               Free (Self.Bare_Document.Command);
            end if;
            Free (Self.Bare_Document);
         else
            Self.Bare_Document.Ref_Count := @ - 1;
         end if;
      end if;
   end Finalize;

end Prettier_Ada.Documents;