From 92ac5a866e8752381332cdb1ac6d5f4e7b5a42a0 Mon Sep 17 00:00:00 2001 From: Joao Azevedo Date: Tue, 30 Jul 2024 07:28:13 +0000 Subject: [PATCH] Try to fit f_subp_spec, f_aspects and 'is' on the same line --- extensions/default_unparsing_config.json | 31 +++++++++++-------- testsuite/tests/unparsing/decl_block/test.out | 3 +- .../unparsing/exception_handler/test.out | 3 +- .../unparsing/object_decl/table/test.out | 3 +- .../protected_body/simple_body/test.out | 6 ++-- .../protected_body/with_entry/test.out | 3 +- .../subp_body/long_subp_spec/input.ada | 3 ++ .../subp_body/long_subp_spec/test.out | 5 +++ .../subp_body/long_subp_spec/test.yaml | 5 +++ .../input.ada | 5 +++ .../long_subp_spec_with_short_aspect/test.out | 7 +++++ .../test.yaml | 5 +++ .../unparsing/subp_body/no_end_name/test.out | 3 +- .../unparsing/subp_body/with_decls/test.out | 3 +- .../subp_body/with_long_aspect/input.ada | 8 +++++ .../subp_body/with_long_aspect/test.out | 9 ++++++ .../subp_body/with_long_aspect/test.yaml | 5 +++ .../subp_body/with_short_aspect/input.ada | 5 +++ .../subp_body/with_short_aspect/test.out | 5 +++ .../subp_body/with_short_aspect/test.yaml | 5 +++ .../subp_body/without_decls/test.out | 3 +- testsuite/tests/unparsing/subunit/test.out | 3 +- 22 files changed, 95 insertions(+), 33 deletions(-) create mode 100644 testsuite/tests/unparsing/subp_body/long_subp_spec/input.ada create mode 100644 testsuite/tests/unparsing/subp_body/long_subp_spec/test.out create mode 100644 testsuite/tests/unparsing/subp_body/long_subp_spec/test.yaml create mode 100644 testsuite/tests/unparsing/subp_body/long_subp_spec_with_short_aspect/input.ada create mode 100644 testsuite/tests/unparsing/subp_body/long_subp_spec_with_short_aspect/test.out create mode 100644 testsuite/tests/unparsing/subp_body/long_subp_spec_with_short_aspect/test.yaml create mode 100644 testsuite/tests/unparsing/subp_body/with_long_aspect/input.ada create mode 100644 testsuite/tests/unparsing/subp_body/with_long_aspect/test.out create mode 100644 testsuite/tests/unparsing/subp_body/with_long_aspect/test.yaml create mode 100644 testsuite/tests/unparsing/subp_body/with_short_aspect/input.ada create mode 100644 testsuite/tests/unparsing/subp_body/with_short_aspect/test.out create mode 100644 testsuite/tests/unparsing/subp_body/with_short_aspect/test.yaml diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index d066a78e8..5f25140fa 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -5077,17 +5077,22 @@ "field": "f_overriding" }, { - "kind": "recurse_field", - "field": "f_subp_spec" - }, - { - "kind": "recurse_field", - "field": "f_aspects" - }, - "hardlineWithoutBreakParent", - { - "kind": "text", - "text": "is" + "kind": "group", + "document": [ + { + "kind": "recurse_field", + "field": "f_subp_spec" + }, + { + "kind": "recurse_field", + "field": "f_aspects" + }, + "line", + { + "kind": "text", + "text": "is" + } + ] }, { "kind": "recurse_field", @@ -5101,7 +5106,7 @@ "kind": "recurse_field", "field": "f_stmts" }, - "hardlineWithoutBreakParent", + "hardline", { "kind": "text", "text": "end" @@ -5118,7 +5123,7 @@ }, "fields": { "f_aspects": [ - "hardline", + "line", "recurse" ], "f_decls": [ diff --git a/testsuite/tests/unparsing/decl_block/test.out b/testsuite/tests/unparsing/decl_block/test.out index ff68820c7..c0d787146 100644 --- a/testsuite/tests/unparsing/decl_block/test.out +++ b/testsuite/tests/unparsing/decl_block/test.out @@ -1,5 +1,4 @@ -procedure Foo -is +procedure Foo is begin declare Bar : Baz; diff --git a/testsuite/tests/unparsing/exception_handler/test.out b/testsuite/tests/unparsing/exception_handler/test.out index af4eb08d6..da7f0f7a7 100644 --- a/testsuite/tests/unparsing/exception_handler/test.out +++ b/testsuite/tests/unparsing/exception_handler/test.out @@ -1,5 +1,4 @@ -procedure Foo -is +procedure Foo is begin declare Bar : Baz; diff --git a/testsuite/tests/unparsing/object_decl/table/test.out b/testsuite/tests/unparsing/object_decl/table/test.out index 2e23be57f..f0227baf2 100644 --- a/testsuite/tests/unparsing/object_decl/table/test.out +++ b/testsuite/tests/unparsing/object_decl/table/test.out @@ -1,5 +1,4 @@ -procedure Main -is +procedure Main is AAAAAAAAAAAAAAAA : Baaaaaar := Bar; BBBBBBBBBBBBBBBBBBBB : Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz := diff --git a/testsuite/tests/unparsing/protected_body/simple_body/test.out b/testsuite/tests/unparsing/protected_body/simple_body/test.out index 51de1ea20..0e8c13b86 100644 --- a/testsuite/tests/unparsing/protected_body/simple_body/test.out +++ b/testsuite/tests/unparsing/protected_body/simple_body/test.out @@ -1,12 +1,10 @@ protected body Shared_Array is - function Component (N : in Index) return Item - is + function Component (N : in Index) return Item is begin return Table (N); end Component; - procedure Set_Component (N : in Index; E : in Item) - is + procedure Set_Component (N : in Index; E : in Item) is begin Table (N) := E; end Set_Component; diff --git a/testsuite/tests/unparsing/protected_body/with_entry/test.out b/testsuite/tests/unparsing/protected_body/with_entry/test.out index 7931d71d6..396311444 100644 --- a/testsuite/tests/unparsing/protected_body/with_entry/test.out +++ b/testsuite/tests/unparsing/protected_body/with_entry/test.out @@ -5,8 +5,7 @@ protected body Resource is Busy := True; end Seize; - procedure Release - is + procedure Release is begin Busy := False; end Release; diff --git a/testsuite/tests/unparsing/subp_body/long_subp_spec/input.ada b/testsuite/tests/unparsing/subp_body/long_subp_spec/input.ada new file mode 100644 index 000000000..ed7b31277 --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/long_subp_spec/input.ada @@ -0,0 +1,3 @@ +function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Freeeeeeeeeeeeeeed is begin + null; +end; diff --git a/testsuite/tests/unparsing/subp_body/long_subp_spec/test.out b/testsuite/tests/unparsing/subp_body/long_subp_spec/test.out new file mode 100644 index 000000000..1dd8c7e89 --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/long_subp_spec/test.out @@ -0,0 +1,5 @@ +function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Freeeeeeeeeeeeeeed +is +begin + null; +end; diff --git a/testsuite/tests/unparsing/subp_body/long_subp_spec/test.yaml b/testsuite/tests/unparsing/subp_body/long_subp_spec/test.yaml new file mode 100644 index 000000000..e91d50a4e --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/long_subp_spec/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: subp_body +description: | + Test a `SubpBody` whose `f_subp_spec` and `is` token do not fit on one + line. diff --git a/testsuite/tests/unparsing/subp_body/long_subp_spec_with_short_aspect/input.ada b/testsuite/tests/unparsing/subp_body/long_subp_spec_with_short_aspect/input.ada new file mode 100644 index 000000000..109fa4eca --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/long_subp_spec_with_short_aspect/input.ada @@ -0,0 +1,5 @@ +function Fooooooooooooo + (A : Bar; B : Baz; C : Qux) return Freeeeeeeeeeeeeeeeeed with Precondition is +begin + null; +end; diff --git a/testsuite/tests/unparsing/subp_body/long_subp_spec_with_short_aspect/test.out b/testsuite/tests/unparsing/subp_body/long_subp_spec_with_short_aspect/test.out new file mode 100644 index 000000000..fe0aafe3d --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/long_subp_spec_with_short_aspect/test.out @@ -0,0 +1,7 @@ +function Fooooooooooooo + (A : Bar; B : Baz; C : Qux) return Freeeeeeeeeeeeeeeeeed +with Precondition +is +begin + null; +end; diff --git a/testsuite/tests/unparsing/subp_body/long_subp_spec_with_short_aspect/test.yaml b/testsuite/tests/unparsing/subp_body/long_subp_spec_with_short_aspect/test.yaml new file mode 100644 index 000000000..5825f5caa --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/long_subp_spec_with_short_aspect/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: subp_body +description: | + Test that, if the `f_subp_spec` of a `SubpBody` breaks, then a line break is + added before `f_aspects` and the `is` token. diff --git a/testsuite/tests/unparsing/subp_body/no_end_name/test.out b/testsuite/tests/unparsing/subp_body/no_end_name/test.out index 6ad8998f8..a3b40e835 100644 --- a/testsuite/tests/unparsing/subp_body/no_end_name/test.out +++ b/testsuite/tests/unparsing/subp_body/no_end_name/test.out @@ -1,5 +1,4 @@ -function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred -is +function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred is type Garply; begin null; diff --git a/testsuite/tests/unparsing/subp_body/with_decls/test.out b/testsuite/tests/unparsing/subp_body/with_decls/test.out index a44997e62..9cafdf58e 100644 --- a/testsuite/tests/unparsing/subp_body/with_decls/test.out +++ b/testsuite/tests/unparsing/subp_body/with_decls/test.out @@ -1,5 +1,4 @@ -function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred -is +function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred is type Garply; begin null; diff --git a/testsuite/tests/unparsing/subp_body/with_long_aspect/input.ada b/testsuite/tests/unparsing/subp_body/with_long_aspect/input.ada new file mode 100644 index 000000000..0b8d05b1e --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/with_long_aspect/input.ada @@ -0,0 +1,8 @@ +function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred +with Pre => Some_Long_Precondition (With_An_Aggregate => And_Looooooooooooong_R_Expr) +is + type My_Type; +begin + null; +end; + diff --git a/testsuite/tests/unparsing/subp_body/with_long_aspect/test.out b/testsuite/tests/unparsing/subp_body/with_long_aspect/test.out new file mode 100644 index 000000000..164b65c5c --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/with_long_aspect/test.out @@ -0,0 +1,9 @@ +function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred +with + Pre => + Some_Long_Precondition (With_An_Aggregate => And_Looooooooooooong_R_Expr) +is + type My_Type; +begin + null; +end; diff --git a/testsuite/tests/unparsing/subp_body/with_long_aspect/test.yaml b/testsuite/tests/unparsing/subp_body/with_long_aspect/test.yaml new file mode 100644 index 000000000..ecadc62d7 --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/with_long_aspect/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: subp_body +description: | + Test that when a `SubpBody` has an non null `f_aspects`, a line break is + added before the `is` token. diff --git a/testsuite/tests/unparsing/subp_body/with_short_aspect/input.ada b/testsuite/tests/unparsing/subp_body/with_short_aspect/input.ada new file mode 100644 index 000000000..784911a7d --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/with_short_aspect/input.ada @@ -0,0 +1,5 @@ +function Foo (A : Bar) return Fred with Pre => Precondition is + type My_Type; +begin + null; +end; diff --git a/testsuite/tests/unparsing/subp_body/with_short_aspect/test.out b/testsuite/tests/unparsing/subp_body/with_short_aspect/test.out new file mode 100644 index 000000000..784911a7d --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/with_short_aspect/test.out @@ -0,0 +1,5 @@ +function Foo (A : Bar) return Fred with Pre => Precondition is + type My_Type; +begin + null; +end; diff --git a/testsuite/tests/unparsing/subp_body/with_short_aspect/test.yaml b/testsuite/tests/unparsing/subp_body/with_short_aspect/test.yaml new file mode 100644 index 000000000..147ea2146 --- /dev/null +++ b/testsuite/tests/unparsing/subp_body/with_short_aspect/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: subp_body +description: | + Test a `SubpBody` whose `f_subp_spec` and `is` token do not fine on one + line. diff --git a/testsuite/tests/unparsing/subp_body/without_decls/test.out b/testsuite/tests/unparsing/subp_body/without_decls/test.out index b01a86866..e25314bab 100644 --- a/testsuite/tests/unparsing/subp_body/without_decls/test.out +++ b/testsuite/tests/unparsing/subp_body/without_decls/test.out @@ -1,5 +1,4 @@ -function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred -is +function Foo (A : Bar; B : Baz; C : Qux; D : Corge) return Fred is begin null; end Foo; diff --git a/testsuite/tests/unparsing/subunit/test.out b/testsuite/tests/unparsing/subunit/test.out index ec979ba29..a7d4b73df 100644 --- a/testsuite/tests/unparsing/subunit/test.out +++ b/testsuite/tests/unparsing/subunit/test.out @@ -1,6 +1,5 @@ separate(Parent) -procedure Inner -is +procedure Inner is begin Foo; end Inner;