Skip to content

Commit c75fe6e

Browse files
committed
Take supportsCustomValues prop into account
for enumeration types. For this types generate new string, integer or modular type. Fix corresponding array types and optional array types, I/O subprograms. Refs #1172
1 parent dcd8ed6 commit c75fe6e

File tree

6 files changed

+181
-30
lines changed

6 files changed

+181
-30
lines changed

source/lsp_gen/lsp_gen-enumerations.adb

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,65 @@ with LSP_Gen.Puts; use LSP_Gen.Puts;
2121
package body LSP_Gen.Enumerations is
2222

2323
procedure Write_Type (Enum : LSP_Gen.Entities.Enumeration);
24+
procedure Write_Pseudo_Enum (Enum : LSP_Gen.Entities.Enumeration);
25+
-- When enumeration supports custom values we can't use enumeration type,
26+
-- so instead create new string or integer types and set of functions
27+
-- for corresponding literals.
28+
29+
-----------------------
30+
-- Write_Pseudo_Enum --
31+
-----------------------
32+
33+
procedure Write_Pseudo_Enum (Enum : LSP_Gen.Entities.Enumeration) is
34+
Last : constant Positive := Enum.values.Length;
35+
begin
36+
Put ("type ");
37+
Put_Id (Enum.name);
38+
Put_Line (" is ");
39+
40+
case Enum.a_type.name is
41+
when LSP_Gen.Entities.Enum.string =>
42+
Put_Line ("new VSS.Strings.Virtual_String with null record");
43+
when LSP_Gen.Entities.Enum.integer =>
44+
Put_Line ("new Integer");
45+
when LSP_Gen.Entities.Enum.uinteger =>
46+
Put_Line ("mod 2 ** 16");
47+
end case;
48+
49+
Put_Line (";");
50+
Put_Lines (Enum.documentation.Split_Lines, " -- ");
51+
52+
for J in 1 .. Last loop
53+
declare
54+
Item : constant LSP_Gen.Entities.EnumerationEntry :=
55+
Enum.values (J);
56+
begin
57+
New_Line;
58+
Put ("function ");
59+
Put_Id (Item.name);
60+
Put (" return ");
61+
Put_Id (Enum.name);
62+
Put (" is (");
63+
64+
case Item.value.Is_String is
65+
when True =>
66+
Put ("""");
67+
Put (Item.value.String);
68+
Put ("""");
69+
when False =>
70+
Put (Item.value.Integer);
71+
end case;
72+
73+
Put_Line (");");
74+
75+
if not Item.documentation.Is_Empty then
76+
Put_Lines (Item.documentation.Split_Lines, " -- ");
77+
end if;
78+
end;
79+
end loop;
80+
81+
New_Line;
82+
end Write_Pseudo_Enum;
2483

2584
----------------
2685
-- Write_Type --
@@ -43,8 +102,6 @@ package body LSP_Gen.Enumerations is
43102
if J /= Last then
44103
Put (", ");
45104
end if;
46-
47-
-- Put_Lines (Item.documentation.Split_Lines, " -- ");
48105
end;
49106
end loop;
50107

@@ -77,11 +134,22 @@ package body LSP_Gen.Enumerations is
77134
begin
78135
Put_Lines (Model.License_Header, "-- ");
79136
New_Line;
137+
Put_Line ("with VSS.Strings;");
138+
New_Line;
80139
Put_Line ("package LSP.Enumerations is");
81140
Put_Line (" pragma Preelaborate;"); New_Line;
82141

83142
for Name of Model.Enumerations loop
84-
Write_Type (Model.Enumeration (Name));
143+
declare
144+
Enum : constant LSP_Gen.Entities.Enumeration :=
145+
Model.Enumeration (Name);
146+
begin
147+
if Enum.supportsCustomValues then
148+
Write_Pseudo_Enum (Enum);
149+
else
150+
Write_Type (Enum);
151+
end if;
152+
end;
85153
end loop;
86154

87155
Put_Line ("end LSP.Enumerations;");

source/lsp_gen/lsp_gen-inputs.adb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,22 @@ package body LSP_Gen.Inputs is
817817

818818
if Spec then
819819
Put_Line (";");
820+
elsif Info.supportsCustomValues then
821+
Put_Line (" is");
822+
Put_Line ("begin");
823+
824+
case Info.a_type.name is
825+
when LSP_Gen.Entities.Enum.string =>
826+
Put_Line ("Value := (Handler.String_Value with null record);");
827+
828+
when others =>
829+
Put ("Value := LSP.Enumerations.");
830+
Put_Id (Name);
831+
Put_Line (" (Handler.Number_Value.Integer_Value);");
832+
end case;
833+
834+
Put_Line ("Handler.Read_Next;");
835+
Put_Line ("end;");
820836
else
821837
Put_Line (" is");
822838
Put_Line ("begin");
@@ -1562,6 +1578,9 @@ package body LSP_Gen.Inputs is
15621578
is
15631579
use all type LSP_Gen.Mappings.Or_Mapping_Kind;
15641580

1581+
function Array_Element return LSP_Gen.Entities.AType is
1582+
(Tipe.Union.an_array.element.Value);
1583+
15651584
begin
15661585
if Name = "LSPArray" then
15671586
return; -- TBD
@@ -1636,7 +1655,12 @@ package body LSP_Gen.Inputs is
16361655
Put_Line (";");
16371656
Put_Line ("begin");
16381657

1639-
if Name.Ends_With ("_Set") then
1658+
if Name.Ends_With ("_Set")
1659+
and then
1660+
(Array_Element.Union.Kind /= reference
1661+
or else not Model.Is_Custom_Enumeration
1662+
(Array_Element.Union.reference.name))
1663+
then
16401664
Put_Line ("Set := (others => False);");
16411665
Put_Line (" while not Handler.Is_End_Array loop");
16421666
Write_Call (Done, Tipe.Union.an_array.element.Value, "");

source/lsp_gen/lsp_gen-meta_models.adb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,19 @@ package body LSP_Gen.Meta_Models is
442442
end case;
443443
end Is_Base_Type;
444444

445+
---------------------------
446+
-- Is_Custom_Enumeration --
447+
---------------------------
448+
449+
function Is_Custom_Enumeration
450+
(Self : Meta_Model'Class;
451+
Name : VSS.Strings.Virtual_String) return Boolean is
452+
begin
453+
return Self.Is_Enumeration (Name) and then
454+
Self.Model.enumerations (Self.Index (Name).Position)
455+
.supportsCustomValues;
456+
end Is_Custom_Enumeration;
457+
445458
--------------------
446459
-- Is_Enumeration --
447460
--------------------

source/lsp_gen/lsp_gen-meta_models.ads

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ package LSP_Gen.Meta_Models is
7171
(Self : Meta_Model'Class;
7272
Name : VSS.Strings.Virtual_String) return Boolean;
7373

74+
function Is_Custom_Enumeration
75+
(Self : Meta_Model'Class;
76+
Name : VSS.Strings.Virtual_String) return Boolean;
77+
-- Enumeration type that supports custom values
78+
7479
function Is_Base_Type
7580
(Self : Meta_Model'Class;
7681
Tipe : LSP_Gen.Entities.AType) return Boolean;

source/lsp_gen/lsp_gen-outputs.adb

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ package body LSP_Gen.Outputs is
111111
and then Tipe.Union.an_array.element.Value.Union.Kind = reference
112112
and then Model.Is_Enumeration
113113
(Tipe.Union.an_array.element.Value.Union.reference.name)
114+
and then not Model.Is_Custom_Enumeration
115+
(Tipe.Union.an_array.element.Value.Union.reference.name)
114116
and then not Tipe.Union.an_array.element.Value.Union.reference.name
115117
.Starts_With ("MarkupKind"));
116118

@@ -158,12 +160,12 @@ package body LSP_Gen.Outputs is
158160
New_Line;
159161
Put_Line ("with Ada.Containers;");
160162
Put_Line ("with Interfaces;");
163+
Put_Line ("with VSS.Strings;");
161164
Put_Line ("with LSP.Output_Tools;");
162165
New_Line;
163166

164167
Put_Line ("package body LSP.Outputs is"); New_Line;
165168
Put_Line ("pragma Warnings (Off, ""is not referenced"");");
166-
Put_Line ("use type Interfaces.Integer_64;"); New_Line;
167169
Put_Line ("use type Ada.Containers.Count_Type;"); New_Line;
168170

169171
for Cursor in Done.Iterate loop
@@ -299,6 +301,23 @@ package body LSP_Gen.Outputs is
299301

300302
if Spec then
301303
Put_Line (";");
304+
305+
elsif Info.supportsCustomValues then
306+
Put_Line (" is");
307+
Put_Line ("begin");
308+
309+
case Info.a_type.name is
310+
when LSP_Gen.Entities.Enum.string =>
311+
Put ("Handler.String_Value");
312+
Put_Line (" (VSS.Strings.Virtual_String (Value));");
313+
314+
when others =>
315+
Put ("Handler.Integer_Value (LSP.Enumerations.");
316+
Put_Id (Name);
317+
Put_Line ("'Pos (Value));");
318+
end case;
319+
320+
Put_Line ("end;");
302321
else
303322
Put_Line (" is");
304323
Put_Line ("begin");
@@ -609,7 +628,11 @@ package body LSP_Gen.Outputs is
609628
Done : LSP_Gen.Dependencies.Dependency_Map;
610629
Name : VSS.Strings.Virtual_String;
611630
Tipe : LSP_Gen.Entities.AType;
612-
Spec : Boolean) is
631+
Spec : Boolean)
632+
is
633+
function Array_Element return LSP_Gen.Entities.AType is
634+
(Tipe.Union.an_array.element.Value);
635+
613636
begin
614637
if Name = "LSPArray" then
615638
return; -- TBD
@@ -656,15 +679,24 @@ package body LSP_Gen.Outputs is
656679
when an_array =>
657680
Put_Line ("Handler.Start_Array;");
658681

659-
if Name.Ends_With ("_Set") then
682+
if Array_Element.Union.Kind = reference
683+
and then Model.Is_Custom_Enumeration
684+
(Array_Element.Union.reference.name)
685+
then
686+
Put_Line
687+
("for J in Value.First_Index .. Value.Last_Index loop");
688+
Write_Call (Done, Array_Element, " (J)");
689+
Put_Line ("end loop;");
690+
691+
elsif Name.Ends_With ("_Set") then
660692
Put_Line ("declare");
661693
Put ("Set : LSP.Structures.");
662694
Put (Name);
663695
Put_Line (" renames Value;");
664696
Put_Line ("begin");
665697
Put_Line (" for Value in Set'Range loop");
666698
Put_Line (" if Set (Value) then");
667-
Write_Call (Done, Tipe.Union.an_array.element.Value, "");
699+
Write_Call (Done, Array_Element, "");
668700
Put_Line (" end if;");
669701
Put_Line (" end loop;");
670702
Put_Line ("end;");
@@ -678,8 +710,7 @@ package body LSP_Gen.Outputs is
678710
("for J in Value.First_Index .. Value.Last_Index loop");
679711
end if;
680712

681-
Write_Call
682-
(Done, Tipe.Union.an_array.element.Value, " (J)");
713+
Write_Call (Done, Array_Element, " (J)");
683714
Put_Line ("end loop;");
684715
end if;
685716
Put_Line ("Handler.End_Array;");

source/lsp_gen/lsp_gen-structures.adb

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ package body LSP_Gen.Structures is
7676
Done : Dependency_Map);
7777
procedure Write_Optional_Type (Name : VSS.Strings.Virtual_String);
7878
procedure Write_Vector_Type
79-
(Model : LSP_Gen.Meta_Models.Meta_Model;
80-
Name : VSS.Strings.Virtual_String;
81-
Item : VSS.Strings.Virtual_String);
79+
(Model : LSP_Gen.Meta_Models.Meta_Model;
80+
Name : VSS.Strings.Virtual_String;
81+
Element : LSP_Gen.Entities.AType;
82+
Fallback : VSS.Strings.Virtual_String);
8283
procedure Write_Enumeration
8384
(Name : VSS.Strings.Virtual_String;
8485
List : LSP_Gen.Entities.AType_Vector);
@@ -1010,19 +1011,12 @@ package body LSP_Gen.Structures is
10101011
null;
10111012
end case;
10121013
when an_array =>
1013-
declare
1014-
Element : constant VSS.Strings.Virtual_String :=
1015-
Short_Name
1016-
(Model,
1017-
Item.Union.an_array.element.Value,
1018-
Fallback & "_Item");
1019-
begin
1020-
if Name /= "LSPAny_Vector"
1021-
and Name /= "Virtual_String_Vector"
1022-
then
1023-
Write_Vector_Type (Model, Name, Element);
1024-
end if;
1025-
end;
1014+
if Name /= "LSPAny_Vector"
1015+
and Name /= "Virtual_String_Vector"
1016+
then
1017+
Write_Vector_Type
1018+
(Model, Name, Item.Union.an_array.element.Value, Fallback);
1019+
end if;
10261020
when map =>
10271021
declare
10281022
Element : constant VSS.Strings.Virtual_String := Short_Name
@@ -1775,11 +1769,16 @@ package body LSP_Gen.Structures is
17751769
-----------------------
17761770

17771771
procedure Write_Vector_Type
1778-
(Model : LSP_Gen.Meta_Models.Meta_Model;
1779-
Name : VSS.Strings.Virtual_String;
1780-
Item : VSS.Strings.Virtual_String)
1772+
(Model : LSP_Gen.Meta_Models.Meta_Model;
1773+
Name : VSS.Strings.Virtual_String;
1774+
Element : LSP_Gen.Entities.AType;
1775+
Fallback : VSS.Strings.Virtual_String)
17811776
is
1782-
pragma Unreferenced (Model);
1777+
Item : constant VSS.Strings.Virtual_String :=
1778+
Short_Name
1779+
(Model,
1780+
Element,
1781+
Fallback & "_Item");
17831782
begin
17841783
if Name = "DocumentSymbol_Vector" or Name = "SelectionRange_Vector" then
17851784
declare
@@ -1797,6 +1796,17 @@ package body LSP_Gen.Structures is
17971796
New_Line;
17981797
return;
17991798
end;
1799+
1800+
elsif Element.Union.Kind = reference
1801+
and then Model.Is_Custom_Enumeration (Element.Union.reference.name)
1802+
then
1803+
-- array of enum that supports custom values.
1804+
--
1805+
-- For string-based enumeration do nothing and create ordinary
1806+
-- vector of enum (strings). Current LSP doesn't have non-string
1807+
-- "custom" enums in arrays.
1808+
null;
1809+
18001810
elsif Name.Ends_With ("_Set") then
18011811
-- It looks like any enum array in LSP is a set. Let's define them
18021812
-- as sets.

0 commit comments

Comments
 (0)