Skip to content

Commit 2a5acba

Browse files
committed
Improve lsp_gen to split lsp-input.adb into parts
Refs gnatstudio#200
1 parent 221d769 commit 2a5acba

File tree

4 files changed

+203
-73
lines changed

4 files changed

+203
-73
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ else
9191
endif
9292

9393
all: coverage-instrument
94-
$(GPRBUILD) -P gnat/lsp_3_17.gpr -p $(COVERAGE_BUILD_FLAGS) -c lsp-inputs.adb
9594
$(GPRBUILD) -P gnat/lsp_3_17.gpr -p $(COVERAGE_BUILD_FLAGS)
9695
$(GPRBUILD) -P gnat/tester.gpr -p $(BUILD_FLAGS)
9796
$(GPRBUILD) -d -ws -c -u -P gnat/lsp_server.gpr -p $(BUILD_FLAGS) s-memory.adb
@@ -105,6 +104,7 @@ endif
105104

106105
generate:
107106
python scripts/generate.py
107+
make -C source/lsp_gen
108108

109109
generate_io:
110110
python scripts/io_gen.py

source/lsp_gen/Makefile

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
1-
GEN_JSON = gen_json
2-
OUT_DIR = ./generated
3-
GNATPP_OPTS = -P ../../gnat/lsp_gen.gpr
4-
DOC = ../../doc
1+
# This file contains the build instructions to generate sources for
2+
# lsp_3_17.gpr from LSP metaModel.json using `gen_lsp-run` tool.
3+
# In its turn, part of `gen_lsp-run` sources are generated from
4+
# LSP JSON Schema (metaModel.schema.json) using `gen_json` tool.
5+
# Sources of `gen_json` tool are located in VSS repository.
6+
#
57

6-
all: create pretty build generate
8+
GEN_JSON = gen_json
9+
GEN_JSON_DIR = ./generated
10+
LSP_GEN_PRJ = -P ../../gnat/lsp_gen.gpr
11+
DOC = ../../doc
12+
TEMP_FILE ?= /tmp/sources.ada
13+
LSP317_DIR = ../lsp_3.17/generated
14+
LSP317_PRJ = -P ../../gnat/lsp_3_17.gpr
15+
LSP_GEN = ../../.obj/${SUPERPROJECT}/lsp_gen/lsp_gen-run
716

8-
create: ${DOC}/metaModel.schema.json header.adt
17+
PHONY = all update_gen_json build generate
18+
19+
all: build generate
20+
21+
# Update `generated/` (from metaModel.schema.json) sources
22+
update_gen_json: ${DOC}/metaModel.schema.json header.adt
923
${GEN_JSON} \
1024
--root-package LSP_Gen.Entities --enum-package Enum \
1125
--header-file header.adt \
1226
--holder "#/definitions/ArrayType:element" \
1327
--holder "#/definitions/MapType:value" \
14-
${DOC}/metaModel.schema.json > ada.txt
15-
gnatchop -w ada.txt ${OUT_DIR}
16-
17-
pretty:
18-
gnatpp ${GNATPP_OPTS} ${OUT_DIR}/*.ad[sb]
28+
${DOC}/metaModel.schema.json > ${TEMP_FILE}
29+
gnatchop -w ${TEMP_FILE} ${GEN_JSON_DIR}
30+
gnatpp ${LSP_GEN_PRJ} ${GEN_JSON_DIR}/*.ad[sb]
1931

20-
build: pretty
21-
gprbuild ${GNATPP_OPTS}
32+
# Build gen_lsp-run
33+
build:
34+
gprbuild ${LSP_GEN_PRJ}
2235

2336
generate: build
24-
../../.obj/gs/lsp_gen/lsp_gen-run ${DOC}/metaModel.json config/3_17.json5 > /tmp/aaa.txt
37+
${LSP_GEN} ${DOC}/metaModel.json config/3_17.json5 > ${TEMP_FILE}
38+
sed -i -e '/^use MarkupContent_Or/s/^/-- /' ${TEMP_FILE}
39+
gnatchop -gnat2022 -w ${TEMP_FILE} ${LSP317_DIR}
40+
gnatpp ${LSP317_PRJ} ${LSP317_DIR}/*.ad[sb]

source/lsp_gen/lsp_gen-inputs.adb

Lines changed: 169 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ with LSP_Gen.String_Sets;
2626
package body LSP_Gen.Inputs is
2727

2828
use type VSS.Strings.Virtual_String;
29+
use type VSS.Strings.Hash_Type;
2930
use all type LSP_Gen.Entities.Enum.AType_Variant;
3031
use all type LSP_Gen.Entities.Enum.BaseTypes;
3132

@@ -57,7 +58,8 @@ package body LSP_Gen.Inputs is
5758
Done : LSP_Gen.Dependencies.Dependency_Map;
5859
Name : VSS.Strings.Virtual_String;
5960
Tipe : LSP_Gen.Entities.AType;
60-
Spec : Boolean);
61+
Spec : Boolean := False;
62+
Stub : Boolean := False);
6163

6264
function Get_Type_Map
6365
(Model : LSP_Gen.Meta_Models.Meta_Model;
@@ -589,10 +591,27 @@ package body LSP_Gen.Inputs is
589591

590592
procedure Write
591593
(Model : LSP_Gen.Meta_Models.Meta_Model;
592-
Done : LSP_Gen.Dependencies.Dependency_Map) is
594+
Done : LSP_Gen.Dependencies.Dependency_Map)
595+
is
596+
function Filter_Message
597+
(Item : LSP_Gen.Dependencies.Dependency_Info) return Boolean is
598+
(Item.Is_Message
599+
or else Item.Short_Name = "ConfigurationParams"
600+
or else Item.Short_Name = "Integer_Or_Virtual_String");
601+
602+
function Filter_Private
603+
(Tipe : LSP_Gen.Entities.AType;
604+
Item : LSP_Gen.Dependencies.Dependency_Info) return Boolean is
605+
(not Filter_Message (Item)
606+
and then Item.Owner.Is_Empty
607+
and then (Tipe.Union.Kind /= reference or else
608+
not Model.Is_Mixin (Tipe.Union.reference.name)));
609+
593610
begin
611+
-- Generating spec: LSP.Inputs
594612
Put_Lines (Model.License_Header, "-- ");
595613
New_Line;
614+
Put_Line ("with Interfaces;");
596615
Put_Line ("with VSS.JSON.Pull_Readers;");
597616
New_Line;
598617
Put_Line ("with LSP.Enumerations;");
@@ -602,10 +621,7 @@ package body LSP_Gen.Inputs is
602621
-- Put_Line (" pragma Preelaborate;"); New_Line;
603622

604623
for Item of Done loop
605-
if Item.Is_Message
606-
or else Item.Short_Name = "ConfigurationParams"
607-
or else Item.Short_Name = "Integer_Or_Virtual_String"
608-
then
624+
if Filter_Message (Item) then
609625
Write_Subprogram_Definition
610626
(Item.Short_Name,
611627
(if Model.Is_Enumeration (Item.Short_Name)
@@ -616,21 +632,7 @@ package body LSP_Gen.Inputs is
616632
end if;
617633
end loop;
618634

619-
Put_Line ("end LSP.Inputs;");
620-
621-
Put_Lines (Model.License_Header, "-- ");
622-
New_Line;
623-
Put_Line ("pragma Ada_2022;");
624-
Put_Line ("with Interfaces;");
625-
Put_Line ("with LSP.Input_Tools;");
626-
Put_Line ("with VSS.Strings;");
627-
Put_Line ("with VSS.JSON.Pull_Readers.Buffered;");
628-
Put_Line ("with Minimal_Perfect_Hash;");
629-
New_Line;
630-
631-
Put_Line ("package body LSP.Inputs is"); New_Line;
632-
Put_Line ("pragma Warnings (Off, ""is not referenced"");");
633-
Put_Line ("use type Interfaces.Integer_64;"); New_Line;
635+
Put_Line ("private");
634636

635637
for Cursor in Done.Iterate loop
636638
declare
@@ -639,59 +641,160 @@ package body LSP_Gen.Inputs is
639641
Item : constant LSP_Gen.Dependencies.Dependency_Info :=
640642
Done (Cursor);
641643
begin
642-
if not Item.Is_Message
643-
and then Item.Short_Name /= "ConfigurationParams"
644-
and then Item.Short_Name /= "Integer_Or_Virtual_String"
645-
and then Item.Owner.Is_Empty
646-
and then (Tipe.Union.Kind /= reference or else
647-
not Model.Is_Mixin (Tipe.Union.reference.name))
648-
then
644+
if Filter_Private (Tipe, Item) then
649645
Write_Type (Model, Done, Item.Short_Name, Tipe, Spec => True);
650646
end if;
651647
end;
652648
end loop;
653649

650+
Put ("function ""-"" (L, R : Interfaces.Integer_64) ");
651+
Put_Line ("return Interfaces.Integer_64");
652+
Put_Line ("renames Interfaces.""-"";"); New_Line;
653+
654+
Put ("function ""+"" (L, R : Interfaces.Integer_64) ");
655+
Put_Line ("return Interfaces.Integer_64");
656+
Put_Line ("renames Interfaces.""+"";"); New_Line;
657+
658+
Put_Line ("end LSP.Inputs;");
659+
660+
-- Generating body: LSP.Inputs
661+
662+
Put_Lines (Model.License_Header, "-- ");
663+
New_Line;
664+
665+
for J in 1 .. Part_Count loop
666+
Put ("with LSP.Inputs.Part_");
667+
Put (J);
668+
Put_Line (";");
669+
end loop;
670+
671+
New_Line;
672+
Put_Line ("package body LSP.Inputs is");
673+
654674
for Cursor in Done.Iterate loop
655675
declare
656676
Tipe : constant LSP_Gen.Entities.AType :=
657677
LSP_Gen.Dependencies.Dependency_Maps.Key (Cursor);
658678
Item : constant LSP_Gen.Dependencies.Dependency_Info :=
659679
Done (Cursor);
660680
begin
661-
if Tipe.Union.Kind = reference then
662-
declare
663-
Value : constant LSP_Gen.Meta_Models.Top_Type :=
664-
Model.Get (Tipe.Union.reference.name);
665-
begin
666-
case Value.Kind is
667-
when LSP_Gen.Meta_Models.Structure =>
668-
if not Model.Is_Mixin (Tipe.Union.reference.name) then
669-
Write_Type_Map (Model, Done, Tipe, Item.Short_Name);
670-
Write_Structure
671-
(Model, Done, Tipe.Union.reference.name);
672-
end if;
673-
when LSP_Gen.Meta_Models.Type_Alias =>
674-
Write_Type_Map
675-
(Model,
676-
Done,
677-
Value.Type_Alias.a_type,
678-
Item.Short_Name);
679-
680-
Write_Type
681-
(Model, Done, Tipe.Union.reference.name,
682-
Value.Type_Alias.a_type, Spec => False);
683-
when LSP_Gen.Meta_Models.Enumeration =>
684-
Write_Enum (Value.Enumeration, Spec => False);
685-
end case;
686-
end;
687-
elsif Item.Owner.Is_Empty then
688-
Write_Type_Map (Model, Done, Tipe, Item.Short_Name);
689-
Write_Type (Model, Done, Item.Short_Name, Tipe, Spec => False);
681+
if Filter_Message (Item) or else Filter_Private (Tipe, Item) then
682+
-- Generate procedure NAME renames Part_X.NAME;
683+
Write_Type (Model, Done, Item.Short_Name, Tipe, Stub => True);
690684
end if;
691685
end;
692686
end loop;
693687

694688
Put_Line ("end LSP.Inputs;");
689+
690+
-- Generating spec: LSP.Inputs.Part_X
691+
for J in 1 .. Part_Count loop
692+
Put_Lines (Model.License_Header, "-- ");
693+
New_Line;
694+
Put ("package LSP.Inputs.Part_");
695+
Put (J);
696+
Put_Line (" is"); New_Line;
697+
698+
for Cursor in Done.Iterate loop
699+
declare
700+
Tipe : constant LSP_Gen.Entities.AType :=
701+
LSP_Gen.Dependencies.Dependency_Maps.Key (Cursor);
702+
Item : constant LSP_Gen.Dependencies.Dependency_Info :=
703+
Done (Cursor);
704+
begin
705+
if Natural (Item.Short_Name.Hash mod Part_Count) = J - 1
706+
and then
707+
(Filter_Message (Item) or else Filter_Private (Tipe, Item))
708+
then
709+
Write_Type
710+
(Model, Done, Item.Short_Name, Tipe, Spec => True);
711+
end if;
712+
end;
713+
end loop;
714+
715+
Put ("end LSP.Inputs.Part_");
716+
Put (J);
717+
Put_Line (";");
718+
end loop;
719+
720+
-- Generating body: LSP.Inputs.Part_X
721+
for J in 1 .. Part_Count loop
722+
Put_Lines (Model.License_Header, "-- ");
723+
New_Line;
724+
Put_Line ("pragma Ada_2022;");
725+
Put_Line ("pragma Warnings (Off, ""is not referenced"");");
726+
Put_Line ("with Interfaces;");
727+
Put_Line ("with LSP.Input_Tools;");
728+
Put_Line ("with VSS.Strings;");
729+
Put_Line ("with VSS.JSON.Pull_Readers.Buffered;");
730+
Put_Line ("with Minimal_Perfect_Hash;");
731+
New_Line;
732+
733+
Put ("package body LSP.Inputs.Part_");
734+
Put (J);
735+
Put_Line (" is");
736+
New_Line;
737+
738+
for Cursor in Done.Iterate loop
739+
declare
740+
Tipe : constant LSP_Gen.Entities.AType :=
741+
LSP_Gen.Dependencies.Dependency_Maps.Key (Cursor);
742+
Item : constant LSP_Gen.Dependencies.Dependency_Info :=
743+
Done (Cursor);
744+
begin
745+
if Natural (Item.Short_Name.Hash mod Part_Count) /= J - 1
746+
or else
747+
(not Filter_Message (Item)
748+
and then not Filter_Private (Tipe, Item))
749+
then
750+
null; -- Skip
751+
752+
elsif Tipe.Union.Kind = reference then
753+
declare
754+
Value : constant LSP_Gen.Meta_Models.Top_Type :=
755+
Model.Get (Tipe.Union.reference.name);
756+
begin
757+
case Value.Kind is
758+
759+
when LSP_Gen.Meta_Models.Structure =>
760+
if not
761+
Model.Is_Mixin (Tipe.Union.reference.name)
762+
then
763+
Write_Type_Map
764+
(Model, Done, Tipe, Item.Short_Name);
765+
766+
Write_Structure
767+
(Model, Done, Tipe.Union.reference.name);
768+
end if;
769+
770+
when LSP_Gen.Meta_Models.Type_Alias =>
771+
Write_Type_Map
772+
(Model,
773+
Done,
774+
Value.Type_Alias.a_type,
775+
Item.Short_Name);
776+
777+
Write_Type
778+
(Model, Done, Tipe.Union.reference.name,
779+
Value.Type_Alias.a_type, Spec => False);
780+
781+
when LSP_Gen.Meta_Models.Enumeration =>
782+
Write_Enum (Value.Enumeration, Spec => False);
783+
end case;
784+
end;
785+
elsif Item.Owner.Is_Empty then
786+
Write_Type_Map (Model, Done, Tipe, Item.Short_Name);
787+
788+
Write_Type
789+
(Model, Done, Item.Short_Name, Tipe, Spec => False);
790+
end if;
791+
end;
792+
end loop;
793+
794+
Put ("end LSP.Inputs.Part_");
795+
Put (J);
796+
Put_Line (";");
797+
end loop;
695798
end Write;
696799

697800
----------------
@@ -1574,7 +1677,8 @@ package body LSP_Gen.Inputs is
15741677
Done : LSP_Gen.Dependencies.Dependency_Map;
15751678
Name : VSS.Strings.Virtual_String;
15761679
Tipe : LSP_Gen.Entities.AType;
1577-
Spec : Boolean)
1680+
Spec : Boolean := False;
1681+
Stub : Boolean := False)
15781682
is
15791683
use all type LSP_Gen.Mappings.Or_Mapping_Kind;
15801684

@@ -1606,6 +1710,13 @@ package body LSP_Gen.Inputs is
16061710

16071711
if Spec then
16081712
Put_Line (";");
1713+
elsif Stub then
1714+
New_Line;
1715+
Put (" renames Part_");
1716+
Put (Natural (Name.Hash mod Part_Count) + 1);
1717+
Put (".Read_");
1718+
Put (Name);
1719+
Put_Line (";");
16091720
elsif Tipe.Union.Kind = reference then
16101721
Put_Line (" renames");
16111722
Write_Subprogram_Name (Done, Tipe);

source/lsp_gen/lsp_gen.ads

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717

1818
package LSP_Gen is
1919
pragma Pure;
20+
21+
Part_Count : constant := 32;
22+
2023
end LSP_Gen;

0 commit comments

Comments
 (0)