From 3d53978f73dceb44f7062cb7d767a8c0bd09bd3b Mon Sep 17 00:00:00 2001 From: Joao Azevedo Date: Tue, 6 Aug 2024 14:17:32 +0000 Subject: [PATCH 1/8] Add config and tests for ReduceAttributeRef --- extensions/default_unparsing_config.json | 83 +++++++++++++++++++ .../break_after_reduce/input.ada | 3 + .../break_after_reduce/test.out | 3 + .../break_after_reduce/test.yaml | 5 ++ .../break_before_reduce/input.ada | 2 + .../break_before_reduce/test.out | 2 + .../break_before_reduce/test.yaml | 5 ++ .../reduce_attribute_ref/long/input.ada | 5 ++ .../reduce_attribute_ref/long/test.out | 5 ++ .../reduce_attribute_ref/long/test.yaml | 5 ++ .../reduce_attribute_ref/short/input.ada | 1 + .../reduce_attribute_ref/short/test.out | 1 + .../reduce_attribute_ref/short/test.yaml | 5 ++ 13 files changed, 125 insertions(+) create mode 100644 testsuite/tests/unparsing/reduce_attribute_ref/break_after_reduce/input.ada create mode 100644 testsuite/tests/unparsing/reduce_attribute_ref/break_after_reduce/test.out create mode 100644 testsuite/tests/unparsing/reduce_attribute_ref/break_after_reduce/test.yaml create mode 100644 testsuite/tests/unparsing/reduce_attribute_ref/break_before_reduce/input.ada create mode 100644 testsuite/tests/unparsing/reduce_attribute_ref/break_before_reduce/test.out create mode 100644 testsuite/tests/unparsing/reduce_attribute_ref/break_before_reduce/test.yaml create mode 100644 testsuite/tests/unparsing/reduce_attribute_ref/long/input.ada create mode 100644 testsuite/tests/unparsing/reduce_attribute_ref/long/test.out create mode 100644 testsuite/tests/unparsing/reduce_attribute_ref/long/test.yaml create mode 100644 testsuite/tests/unparsing/reduce_attribute_ref/short/input.ada create mode 100644 testsuite/tests/unparsing/reduce_attribute_ref/short/test.out create mode 100644 testsuite/tests/unparsing/reduce_attribute_ref/short/test.yaml diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index 3e00abeed..02c546ffd 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -5250,6 +5250,66 @@ } } }, + "ReduceAttributeRef": { + "node": { + "kind": "group", + "document": [ + { + "kind": "recurse_field", + "field": "f_prefix" + }, + { + "kind": "text", + "text": "'" + }, + { + "kind": "continuationLineIndent", + "contents": { + "kind": "group", + "document": [ + "softline", + { + "kind": "group", + "document": [ + { + "kind": "recurse_field", + "field": "f_attribute" + }, + { + "kind": "continuationLineIndent", + "contents": [ + "line", + { + "kind": "group", + "document": [ + { + "kind": "text", + "text": "(" + }, + { + "kind": "align", + "width": " ", + "contents": { + "kind": "recurse_field", + "field": "f_args" + } + }, + { + "kind": "text", + "text": ")" + } + ] + } + ] + } + ] + } + ] + } + } + ] + } + }, "RenamingClause": { "node": { "kind": "group", @@ -6370,6 +6430,29 @@ ] } }, + "ValueSequence": { + "node": { + "kind": "group", + "document": [ + { + "kind": "text", + "text": "[" + }, + { + "kind": "align", + "width": " ", + "contents": { + "kind": "recurse_field", + "field": "f_iter_assoc" + } + }, + { + "kind": "text", + "text": "]" + } + ] + } + }, "Variant": { "node": [ { diff --git a/testsuite/tests/unparsing/reduce_attribute_ref/break_after_reduce/input.ada b/testsuite/tests/unparsing/reduce_attribute_ref/break_after_reduce/input.ada new file mode 100644 index 000000000..d576d708b --- /dev/null +++ b/testsuite/tests/unparsing/reduce_attribute_ref/break_after_reduce/input.ada @@ -0,0 +1,3 @@ +[for Value of Foo_Bar => Value]' + Reduce + (Foo_Bar_Bar_Bar_Bar_Bar_Bar_Bar, Bar_Foo_Foo_Foo_Foo_Foo_Foo_Foo_Foo_Foo) diff --git a/testsuite/tests/unparsing/reduce_attribute_ref/break_after_reduce/test.out b/testsuite/tests/unparsing/reduce_attribute_ref/break_after_reduce/test.out new file mode 100644 index 000000000..d576d708b --- /dev/null +++ b/testsuite/tests/unparsing/reduce_attribute_ref/break_after_reduce/test.out @@ -0,0 +1,3 @@ +[for Value of Foo_Bar => Value]' + Reduce + (Foo_Bar_Bar_Bar_Bar_Bar_Bar_Bar, Bar_Foo_Foo_Foo_Foo_Foo_Foo_Foo_Foo_Foo) diff --git a/testsuite/tests/unparsing/reduce_attribute_ref/break_after_reduce/test.yaml b/testsuite/tests/unparsing/reduce_attribute_ref/break_after_reduce/test.yaml new file mode 100644 index 000000000..e51f51048 --- /dev/null +++ b/testsuite/tests/unparsing/reduce_attribute_ref/break_after_reduce/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: expr +description: | + This tests checks that a `ReduceAttributeRef` first tries to break after the + `Reduce` attribute and not the `f_args` field. diff --git a/testsuite/tests/unparsing/reduce_attribute_ref/break_before_reduce/input.ada b/testsuite/tests/unparsing/reduce_attribute_ref/break_before_reduce/input.ada new file mode 100644 index 000000000..ea1dcba68 --- /dev/null +++ b/testsuite/tests/unparsing/reduce_attribute_ref/break_before_reduce/input.ada @@ -0,0 +1,2 @@ +[for Value of Foo_Bar => Value]' + Reduce (Foo_Bar_Bar_Bar_Bar, Bar_Foo_Foo_Foo_Foo) diff --git a/testsuite/tests/unparsing/reduce_attribute_ref/break_before_reduce/test.out b/testsuite/tests/unparsing/reduce_attribute_ref/break_before_reduce/test.out new file mode 100644 index 000000000..ea1dcba68 --- /dev/null +++ b/testsuite/tests/unparsing/reduce_attribute_ref/break_before_reduce/test.out @@ -0,0 +1,2 @@ +[for Value of Foo_Bar => Value]' + Reduce (Foo_Bar_Bar_Bar_Bar, Bar_Foo_Foo_Foo_Foo) diff --git a/testsuite/tests/unparsing/reduce_attribute_ref/break_before_reduce/test.yaml b/testsuite/tests/unparsing/reduce_attribute_ref/break_before_reduce/test.yaml new file mode 100644 index 000000000..46defda16 --- /dev/null +++ b/testsuite/tests/unparsing/reduce_attribute_ref/break_before_reduce/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: expr +description: | + This tests checks that a `ReduceAttributeRef` is first broken before the + `Reduce` attribute. diff --git a/testsuite/tests/unparsing/reduce_attribute_ref/long/input.ada b/testsuite/tests/unparsing/reduce_attribute_ref/long/input.ada new file mode 100644 index 000000000..ceb35faf3 --- /dev/null +++ b/testsuite/tests/unparsing/reduce_attribute_ref/long/input.ada @@ -0,0 +1,5 @@ +[for Value_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA of AAAAAAAAAAAAAAAAAAAAAA + => Value]' + Reduce + (Fooooooooooooooooooooooooooooooooo, + Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar) diff --git a/testsuite/tests/unparsing/reduce_attribute_ref/long/test.out b/testsuite/tests/unparsing/reduce_attribute_ref/long/test.out new file mode 100644 index 000000000..ceb35faf3 --- /dev/null +++ b/testsuite/tests/unparsing/reduce_attribute_ref/long/test.out @@ -0,0 +1,5 @@ +[for Value_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA of AAAAAAAAAAAAAAAAAAAAAA + => Value]' + Reduce + (Fooooooooooooooooooooooooooooooooo, + Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar) diff --git a/testsuite/tests/unparsing/reduce_attribute_ref/long/test.yaml b/testsuite/tests/unparsing/reduce_attribute_ref/long/test.yaml new file mode 100644 index 000000000..ad6af4ae2 --- /dev/null +++ b/testsuite/tests/unparsing/reduce_attribute_ref/long/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: expr +description: | + This tests checks the indentation when all possible line breaks of a + `ReduceAttributeRef` are active. diff --git a/testsuite/tests/unparsing/reduce_attribute_ref/short/input.ada b/testsuite/tests/unparsing/reduce_attribute_ref/short/input.ada new file mode 100644 index 000000000..3ad530a60 --- /dev/null +++ b/testsuite/tests/unparsing/reduce_attribute_ref/short/input.ada @@ -0,0 +1 @@ +[for Value of A => Value]'Reduce ("+", 0) diff --git a/testsuite/tests/unparsing/reduce_attribute_ref/short/test.out b/testsuite/tests/unparsing/reduce_attribute_ref/short/test.out new file mode 100644 index 000000000..3ad530a60 --- /dev/null +++ b/testsuite/tests/unparsing/reduce_attribute_ref/short/test.out @@ -0,0 +1 @@ +[for Value of A => Value]'Reduce ("+", 0) diff --git a/testsuite/tests/unparsing/reduce_attribute_ref/short/test.yaml b/testsuite/tests/unparsing/reduce_attribute_ref/short/test.yaml new file mode 100644 index 000000000..30ef62eb0 --- /dev/null +++ b/testsuite/tests/unparsing/reduce_attribute_ref/short/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: expr +description: | + Test that when a `ReduceAttributeRef` fits in a single line, it does not + break. From d8f0ea31f5180317e902560c5233f7c56214e2c5 Mon Sep 17 00:00:00 2001 From: Joao Azevedo Date: Tue, 6 Aug 2024 14:19:12 +0000 Subject: [PATCH 2/8] Add whitespace before the colon symbol in a NamedStmt --- extensions/default_unparsing_config.json | 3 ++- testsuite/tests/unparsing/named_stmt/test.out | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index 02c546ffd..c1da0b06d 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -3786,11 +3786,12 @@ "kind": "recurse_field", "field": "f_decl" }, + "whitespace", { "kind": "text", "text": ":" }, - "hardlineWithoutBreakParent", + "hardline", { "kind": "recurse_field", "field": "f_stmt" diff --git a/testsuite/tests/unparsing/named_stmt/test.out b/testsuite/tests/unparsing/named_stmt/test.out index 74baccdfc..18cc9c0fa 100644 --- a/testsuite/tests/unparsing/named_stmt/test.out +++ b/testsuite/tests/unparsing/named_stmt/test.out @@ -1,4 +1,4 @@ -Foo: +Foo : loop null; null; From ec5d2154fdc1200e5f37755bf8e9846adc969659 Mon Sep 17 00:00:00 2001 From: Joao Azevedo Date: Tue, 6 Aug 2024 14:28:36 +0000 Subject: [PATCH 3/8] Add config and tests for ModIntTypeDef --- extensions/default_unparsing_config.json | 19 +++++++++++++++++++ .../type_def/mod_int_type_def/long/input.ada | 1 + .../type_def/mod_int_type_def/long/test.out | 2 ++ .../type_def/mod_int_type_def/long/test.yaml | 4 ++++ .../type_def/mod_int_type_def/short/input.ada | 1 + .../type_def/mod_int_type_def/short/test.out | 1 + .../type_def/mod_int_type_def/short/test.yaml | 4 ++++ 7 files changed, 32 insertions(+) create mode 100644 testsuite/tests/unparsing/type_def/mod_int_type_def/long/input.ada create mode 100644 testsuite/tests/unparsing/type_def/mod_int_type_def/long/test.out create mode 100644 testsuite/tests/unparsing/type_def/mod_int_type_def/long/test.yaml create mode 100644 testsuite/tests/unparsing/type_def/mod_int_type_def/short/input.ada create mode 100644 testsuite/tests/unparsing/type_def/mod_int_type_def/short/test.out create mode 100644 testsuite/tests/unparsing/type_def/mod_int_type_def/short/test.yaml diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index c1da0b06d..c2ecbd105 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -3958,6 +3958,25 @@ "whitespace" ] }, + "ModIntTypeDef": { + "node": { + "kind": "group", + "document": [ + { + "kind": "text", + "text": "mod" + }, + "whitespace", + { + "kind": "innerRoot", + "contents": { + "kind": "recurse_field", + "field": "f_expr" + } + } + ] + } + }, "NoTypeObjectRenamingDecl": { "node": { "kind": "continuationLineIndent", diff --git a/testsuite/tests/unparsing/type_def/mod_int_type_def/long/input.ada b/testsuite/tests/unparsing/type_def/mod_int_type_def/long/input.ada new file mode 100644 index 000000000..55a4f0e6c --- /dev/null +++ b/testsuite/tests/unparsing/type_def/mod_int_type_def/long/input.ada @@ -0,0 +1 @@ +type Coloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooor is mod <>; diff --git a/testsuite/tests/unparsing/type_def/mod_int_type_def/long/test.out b/testsuite/tests/unparsing/type_def/mod_int_type_def/long/test.out new file mode 100644 index 000000000..d447a86ed --- /dev/null +++ b/testsuite/tests/unparsing/type_def/mod_int_type_def/long/test.out @@ -0,0 +1,2 @@ +type Coloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooor is + mod <>; diff --git a/testsuite/tests/unparsing/type_def/mod_int_type_def/long/test.yaml b/testsuite/tests/unparsing/type_def/mod_int_type_def/long/test.yaml new file mode 100644 index 000000000..ef0dbc440 --- /dev/null +++ b/testsuite/tests/unparsing/type_def/mod_int_type_def/long/test.yaml @@ -0,0 +1,4 @@ +driver: unparser +rule: type_decl +description: | + Test the line break before the `ModIntTypeDef`. diff --git a/testsuite/tests/unparsing/type_def/mod_int_type_def/short/input.ada b/testsuite/tests/unparsing/type_def/mod_int_type_def/short/input.ada new file mode 100644 index 000000000..2023bb79b --- /dev/null +++ b/testsuite/tests/unparsing/type_def/mod_int_type_def/short/input.ada @@ -0,0 +1 @@ +type Day is mod <>; diff --git a/testsuite/tests/unparsing/type_def/mod_int_type_def/short/test.out b/testsuite/tests/unparsing/type_def/mod_int_type_def/short/test.out new file mode 100644 index 000000000..2023bb79b --- /dev/null +++ b/testsuite/tests/unparsing/type_def/mod_int_type_def/short/test.out @@ -0,0 +1 @@ +type Day is mod <>; diff --git a/testsuite/tests/unparsing/type_def/mod_int_type_def/short/test.yaml b/testsuite/tests/unparsing/type_def/mod_int_type_def/short/test.yaml new file mode 100644 index 000000000..c526c2b3f --- /dev/null +++ b/testsuite/tests/unparsing/type_def/mod_int_type_def/short/test.yaml @@ -0,0 +1,4 @@ +driver: unparser +rule: type_decl +description: | + Test the a short `ModIntTypeDef` does not break. From ffb30e32c728cac281579d62c2cb94c3b29e95a7 Mon Sep 17 00:00:00 2001 From: Joao Azevedo Date: Tue, 6 Aug 2024 14:36:24 +0000 Subject: [PATCH 4/8] Add config as tests for SubtypeDecl --- extensions/default_unparsing_config.json | 50 +++++++++++++++++++ .../unparsing/subtype_decl/long/input.ada | 1 + .../unparsing/subtype_decl/long/test.out | 2 + .../unparsing/subtype_decl/long/test.yaml | 4 ++ .../unparsing/subtype_decl/short/input.ada | 1 + .../unparsing/subtype_decl/short/test.out | 1 + .../unparsing/subtype_decl/short/test.yaml | 4 ++ 7 files changed, 63 insertions(+) create mode 100644 testsuite/tests/unparsing/subtype_decl/long/input.ada create mode 100644 testsuite/tests/unparsing/subtype_decl/long/test.out create mode 100644 testsuite/tests/unparsing/subtype_decl/long/test.yaml create mode 100644 testsuite/tests/unparsing/subtype_decl/short/input.ada create mode 100644 testsuite/tests/unparsing/subtype_decl/short/test.out create mode 100644 testsuite/tests/unparsing/subtype_decl/short/test.yaml diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index c2ecbd105..f04a2fc28 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -6008,6 +6008,56 @@ } } }, + "SubtypeDecl": { + "node": { + "kind": "group", + "document": [ + { + "kind": "group", + "document": [ + { + "kind": "text", + "text": "subtype" + }, + "whitespace", + { + "kind": "recurse_field", + "field": "f_name" + }, + "whitespace", + { + "kind": "text", + "text": "is" + }, + { + "kind": "continuationLineIndent", + "contents": [ + "line", + { + "kind": "recurse_field", + "field": "f_subtype" + } + ] + } + ] + }, + { + "kind": "recurse_field", + "field": "f_aspects" + }, + { + "kind": "text", + "text": ";" + } + ] + }, + "fields": { + "f_aspects": [ + "line", + "recurse" + ] + } + }, "SubtypeIndication": { "node": { "kind": "group", diff --git a/testsuite/tests/unparsing/subtype_decl/long/input.ada b/testsuite/tests/unparsing/subtype_decl/long/input.ada new file mode 100644 index 000000000..40dac4f31 --- /dev/null +++ b/testsuite/tests/unparsing/subtype_decl/long/input.ada @@ -0,0 +1 @@ +subtype Foo_Bar_Bar_Foo is Foo_Bar_Bar_Bar_Bar_Bar.Bar_Foo_Foo_Foo_Foo_Foo_Foo_Foo; diff --git a/testsuite/tests/unparsing/subtype_decl/long/test.out b/testsuite/tests/unparsing/subtype_decl/long/test.out new file mode 100644 index 000000000..09baf28e1 --- /dev/null +++ b/testsuite/tests/unparsing/subtype_decl/long/test.out @@ -0,0 +1,2 @@ +subtype Foo_Bar_Bar_Foo is + Foo_Bar_Bar_Bar_Bar_Bar.Bar_Foo_Foo_Foo_Foo_Foo_Foo_Foo; diff --git a/testsuite/tests/unparsing/subtype_decl/long/test.yaml b/testsuite/tests/unparsing/subtype_decl/long/test.yaml new file mode 100644 index 000000000..2526b31b1 --- /dev/null +++ b/testsuite/tests/unparsing/subtype_decl/long/test.yaml @@ -0,0 +1,4 @@ +driver: unparser +rule: subtype_decl +description: | + Test that a `SubtypeDecl` first breaks before the `f_subtype` diff --git a/testsuite/tests/unparsing/subtype_decl/short/input.ada b/testsuite/tests/unparsing/subtype_decl/short/input.ada new file mode 100644 index 000000000..1ed969285 --- /dev/null +++ b/testsuite/tests/unparsing/subtype_decl/short/input.ada @@ -0,0 +1 @@ +subtype Foo is Bar; diff --git a/testsuite/tests/unparsing/subtype_decl/short/test.out b/testsuite/tests/unparsing/subtype_decl/short/test.out new file mode 100644 index 000000000..1ed969285 --- /dev/null +++ b/testsuite/tests/unparsing/subtype_decl/short/test.out @@ -0,0 +1 @@ +subtype Foo is Bar; diff --git a/testsuite/tests/unparsing/subtype_decl/short/test.yaml b/testsuite/tests/unparsing/subtype_decl/short/test.yaml new file mode 100644 index 000000000..0fc4fbe16 --- /dev/null +++ b/testsuite/tests/unparsing/subtype_decl/short/test.yaml @@ -0,0 +1,4 @@ +driver: unparser +rule: subtype_decl +description: | + Test that no line breaks are added when the `SubtypeDecl` fits on one line. From 5f1c4408326d1a81440b06c7c2450325cd15fc34 Mon Sep 17 00:00:00 2001 From: Joao Azevedo Date: Tue, 6 Aug 2024 14:38:53 +0000 Subject: [PATCH 5/8] Break after the with keyword on RaiseStmts --- extensions/default_unparsing_config.json | 10 +++++++++- .../long_error_message_concatenation/input.ada | 1 + .../long_error_message_concatenation/test.out | 6 ++++++ .../long_error_message_concatenation/test.yaml | 7 +++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/unparsing/raise_stmt/long_error_message_concatenation/input.ada create mode 100644 testsuite/tests/unparsing/raise_stmt/long_error_message_concatenation/test.out create mode 100644 testsuite/tests/unparsing/raise_stmt/long_error_message_concatenation/test.yaml diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index f04a2fc28..21b62aecf 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -5241,8 +5241,16 @@ "kind": "text", "text": "with" }, - "whitespace", + { + "kind": "continuationLineIndent", + "contents": { + "kind": "group", + "document": [ + "line", "recurse" + ] + } + } ] } } diff --git a/testsuite/tests/unparsing/raise_stmt/long_error_message_concatenation/input.ada b/testsuite/tests/unparsing/raise_stmt/long_error_message_concatenation/input.ada new file mode 100644 index 000000000..0a8049292 --- /dev/null +++ b/testsuite/tests/unparsing/raise_stmt/long_error_message_concatenation/input.ada @@ -0,0 +1 @@ +raise Some_Exception with "AAAAAAAAAAAAAAAAAAAAAAAA" & "AAAAAAAAAAAAAAAAAAAAAAAA" & "AAAAAAAAAAAAAAAAAAAAAAAA" & "AAAAAAAAAAAAAAAAAAAAAAAA"; diff --git a/testsuite/tests/unparsing/raise_stmt/long_error_message_concatenation/test.out b/testsuite/tests/unparsing/raise_stmt/long_error_message_concatenation/test.out new file mode 100644 index 000000000..9bdf9f09f --- /dev/null +++ b/testsuite/tests/unparsing/raise_stmt/long_error_message_concatenation/test.out @@ -0,0 +1,6 @@ +raise Some_Exception + with + "AAAAAAAAAAAAAAAAAAAAAAAA" + & "AAAAAAAAAAAAAAAAAAAAAAAA" + & "AAAAAAAAAAAAAAAAAAAAAAAA" + & "AAAAAAAAAAAAAAAAAAAAAAAA"; diff --git a/testsuite/tests/unparsing/raise_stmt/long_error_message_concatenation/test.yaml b/testsuite/tests/unparsing/raise_stmt/long_error_message_concatenation/test.yaml new file mode 100644 index 000000000..54470ff0c --- /dev/null +++ b/testsuite/tests/unparsing/raise_stmt/long_error_message_concatenation/test.yaml @@ -0,0 +1,7 @@ +driver: unparser +rule: raise_stmt +description: | + This test checks the formatting of a `RaiseExpr` that has a long + `f_error_message` which consists of concatenations. + It is expected `f_error_message` to be continuation line indented relative to + `with`. From f164f6b3ba620b1acab1f6bd6a8fe81a992dc2ed Mon Sep 17 00:00:00 2001 From: Joao Azevedo Date: Tue, 6 Aug 2024 14:45:46 +0000 Subject: [PATCH 6/8] Fix line length limit of ReturnStmts Make sure the semi-colon symbol is included in the return statment group. --- extensions/default_unparsing_config.json | 2 +- .../return_stmt/long_breaking_return_expr/input.ada | 1 + .../unparsing/return_stmt/long_breaking_return_expr/test.out | 2 ++ .../return_stmt/long_breaking_return_expr/test.yaml | 5 +++++ 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/unparsing/return_stmt/long_breaking_return_expr/input.ada create mode 100644 testsuite/tests/unparsing/return_stmt/long_breaking_return_expr/test.out create mode 100644 testsuite/tests/unparsing/return_stmt/long_breaking_return_expr/test.yaml diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index 21b62aecf..b02cfdeab 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -5508,7 +5508,7 @@ "node": { "kind": "continuationLineIndent", "contents": { - "kind": "fill", + "kind": "group", "document": "recurse" } }, diff --git a/testsuite/tests/unparsing/return_stmt/long_breaking_return_expr/input.ada b/testsuite/tests/unparsing/return_stmt/long_breaking_return_expr/input.ada new file mode 100644 index 000000000..007668d33 --- /dev/null +++ b/testsuite/tests/unparsing/return_stmt/long_breaking_return_expr/input.ada @@ -0,0 +1 @@ +return Fooooooooooooooooooooo / Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar; diff --git a/testsuite/tests/unparsing/return_stmt/long_breaking_return_expr/test.out b/testsuite/tests/unparsing/return_stmt/long_breaking_return_expr/test.out new file mode 100644 index 000000000..90088c417 --- /dev/null +++ b/testsuite/tests/unparsing/return_stmt/long_breaking_return_expr/test.out @@ -0,0 +1,2 @@ +return + Fooooooooooooooooooooo / Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar; diff --git a/testsuite/tests/unparsing/return_stmt/long_breaking_return_expr/test.yaml b/testsuite/tests/unparsing/return_stmt/long_breaking_return_expr/test.yaml new file mode 100644 index 000000000..5426a30de --- /dev/null +++ b/testsuite/tests/unparsing/return_stmt/long_breaking_return_expr/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: return_stmt +description: | + Test the `ReturnStmt` on the line length limit. + It is expected that tit breaks after the `return` keyword. From 72ae80a94a2289069f893d6ce75bfe5c95e097e5 Mon Sep 17 00:00:00 2001 From: Joao Azevedo Date: Tue, 6 Aug 2024 14:56:07 +0000 Subject: [PATCH 7/8] Fix ParenExpr and ElsifStmtPart Make sure the expression inside ParenExpr is always indented based on the starting parenthesis. Group ElsifStmtParts so that the last one breaks on its condition if it's too long. --- extensions/default_unparsing_config.json | 213 +++++++++++++++++- .../long_last_elsif_cond_expr/input.ada | 49 ++++ .../long_last_elsif_cond_expr/test.out | 50 ++++ .../long_last_elsif_cond_expr/test.yaml | 5 + .../unparsing/paren_expr/inside_if/input.ada | 10 + .../unparsing/paren_expr/inside_if/test.out | 10 + .../unparsing/paren_expr/inside_if/test.yaml | 5 + .../unparsing/paren_expr/{ => long}/input.ada | 0 .../unparsing/paren_expr/{ => long}/test.out | 0 .../unparsing/paren_expr/{ => long}/test.yaml | 0 10 files changed, 336 insertions(+), 6 deletions(-) create mode 100644 testsuite/tests/unparsing/if_stmt/long_last_elsif_cond_expr/input.ada create mode 100644 testsuite/tests/unparsing/if_stmt/long_last_elsif_cond_expr/test.out create mode 100644 testsuite/tests/unparsing/if_stmt/long_last_elsif_cond_expr/test.yaml create mode 100644 testsuite/tests/unparsing/paren_expr/inside_if/input.ada create mode 100644 testsuite/tests/unparsing/paren_expr/inside_if/test.out create mode 100644 testsuite/tests/unparsing/paren_expr/inside_if/test.yaml rename testsuite/tests/unparsing/paren_expr/{ => long}/input.ada (100%) rename testsuite/tests/unparsing/paren_expr/{ => long}/test.out (100%) rename testsuite/tests/unparsing/paren_expr/{ => long}/test.yaml (100%) diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index b02cfdeab..f90577380 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -601,11 +601,26 @@ }, "BinOp": { "node": { + "kind": "ifKind", + "field": "f_op", + "default": { + "kind": "group", + "document": [ + { + "kind": "group", + "document": [] + }, + { + "kind": "group", + "document": [ + { "kind": "group", "document": [ { "kind": "recurse_field", "field": "f_left" + } + ] }, "line", { @@ -621,6 +636,144 @@ } } ] + } + ] + }, + "matchers": [ + { + "kind": "OpAnd", + "document": { + "kind": "group", + "document": [ + { + "kind": "recurse_field", + "field": "f_left" + }, + "line", + { + "kind": "recurse_field", + "field": "f_op" + }, + "whitespace", + { + "kind": "innerRoot", + "contents": { + "kind": "recurse_field", + "field": "f_right" + } + } + ] + } + }, + { + "kind": "OpAndThen", + "document": { + "kind": "group", + "document": [ + { + "kind": "recurse_field", + "field": "f_left" + }, + "line", + { + "kind": "recurse_field", + "field": "f_op" + }, + "whitespace", + { + "kind": "innerRoot", + "contents": { + "kind": "recurse_field", + "field": "f_right" + } + } + ] + } + }, + { + "kind": "OpOr", + "document": { + "kind": "group", + "document": [ + { + "kind": "recurse_field", + "field": "f_left" + }, + "line", + { + "kind": "recurse_field", + "field": "f_op" + }, + "whitespace", + { + "kind": "innerRoot", + "contents": { + "kind": "recurse_field", + "field": "f_right" + } + } + ] + } + }, + { + "kind": "OpOrElse", + "document": { + "kind": "group", + "document": [ + { + "kind": "recurse_field", + "field": "f_left" + }, + "line", + { + "kind": "recurse_field", + "field": "f_op" + }, + "whitespace", + { + "kind": "innerRoot", + "contents": { + "kind": "recurse_field", + "field": "f_right" + } + } + ] + } + }, + { + "kind": "OpXor", + "document": { + "kind": "group", + "document": [ + { + "kind": "recurse_field", + "field": "f_left" + }, + "line", + { + "kind": "recurse_field", + "field": "f_op" + }, + "whitespace", + { + "kind": "innerRoot", + "contents": { + "kind": "recurse_field", + "field": "f_right" + } + } + ] + } + } + ] + }, + "fields": { + "f_left": { + "kind": "recurse_flatten", + "if": [ + "BinOp" + ] + } } }, "BracketAggregate": { @@ -2258,8 +2411,7 @@ "field": "f_stmts" } ] - }, - "hardlineWithoutBreakParent" + } ] } }, @@ -2269,6 +2421,12 @@ "line" ] }, + "ElsifStmtPartList": { + "sep": [ + "recurse", + "hardlineWithoutBreakParent" + ] + }, "ExceptionDecl": { "node": { "kind": "group", @@ -3423,8 +3581,11 @@ { "kind": "continuationLineIndent", "contents": { + "kind": "group", + "document": { "kind": "recurse_field", "field": "f_cond_expr" + } } }, "line", @@ -3470,10 +3631,24 @@ }, "fields": { "f_alternatives": { - "kind": "group", - "document": "recurse" + "kind": "ifEmpty", + "then": "recurse", + "else": [ + "recurse", + "hardlineWithoutBreakParent" + ] }, "f_else_stmts": [ + { + "kind": "text", + "text": "else" + }, + { + "kind": "ifEmpty", + "then": [ + "recurse" + ], + "else": [ { "kind": "indent", "contents": [ @@ -3482,6 +3657,8 @@ ] }, "hardlineWithoutBreakParent" + ] + } ] } }, @@ -4772,8 +4949,23 @@ "width": " ", "contents": { "kind": "group", - "document": "recurse" - } + "document": [ + { + "kind": "text", + "text": "(" + }, + { + "kind": "innerRoot", + "contents": { + "kind": "recurse_field", + "field": "f_expr" + } + }, + { + "kind": "text", + "text": ")" + } + ] } }, "ParentList": { @@ -5483,6 +5675,13 @@ "RelationOp": { "node": { "kind": "group", + "document": [ + { + "kind": "group", + "document": [] + }, + { + "kind": "group", "document": [ { "kind": "recurse_field", @@ -5500,6 +5699,8 @@ "kind": "recurse_field", "field": "f_right" } + } + ] } ] } diff --git a/testsuite/tests/unparsing/if_stmt/long_last_elsif_cond_expr/input.ada b/testsuite/tests/unparsing/if_stmt/long_last_elsif_cond_expr/input.ada new file mode 100644 index 000000000..eabd75eb0 --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_last_elsif_cond_expr/input.ada @@ -0,0 +1,49 @@ +if Subp.P_Is_Ghost_Code or else Is_Function_With_Ghost_Return (Subp) then + return + Non_Fuzzable_Subprogram' + (Declaration => Subp.As_Basic_Decl, + Reason => + +Subp.Full_Sloc_Image & "Can't fuzz ghost code subprograms."); +elsif Subp.Kind in Ada_Abstract_Subp_Decl then + return + Non_Fuzzable_Subprogram' + (Declaration => Subp.As_Basic_Decl, + Reason => + +Subp.Full_Sloc_Image & "Can't fuzz abstract subprograms."); +elsif Get_Subp_Params (Subp).Is_Null then + return + Non_Fuzzable_Subprogram' + (Declaration => Subp.As_Basic_Decl, + Reason => + +Subp.Full_Sloc_Image + & "Can't subprograms with no parameters."); +elsif not Has_Input_Parameters (Subp) then + return + Non_Fuzzable_Subprogram' + (Declaration => Subp.As_Basic_Decl, + Reason => + +Subp.Full_Sloc_Image + & "Can't fuzz subprograms with no 'in' or " + & "'in out' parameters"); +elsif Is_Subp_Decl_An_Import_With_Expression (Subp) and not Is_Intrinsic_Subprogram (Subp) then + return + Non_Fuzzable_Subprogram' + (Declaration => Subp.As_Basic_Decl, + Reason => + +Subp.Full_Sloc_Image + & "Can't fuzz subprograms where Imports aspect " + & "values are derived from expressions."); +elsif Is_Subp_Decl_Null (Subp) + and not Is_Expr_Function (Subp) + and not Is_Subp_Decl_An_Import (Subp) +then + return + Non_Fuzzable_Subprogram' + (Declaration => Subp.As_Basic_Decl, + Reason => + +Subp.Full_Sloc_Image + & "Can't fuzz subprograms with null " + & "specifications."); +else + null; +end if; diff --git a/testsuite/tests/unparsing/if_stmt/long_last_elsif_cond_expr/test.out b/testsuite/tests/unparsing/if_stmt/long_last_elsif_cond_expr/test.out new file mode 100644 index 000000000..b9976be79 --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_last_elsif_cond_expr/test.out @@ -0,0 +1,50 @@ +if Subp.P_Is_Ghost_Code or else Is_Function_With_Ghost_Return (Subp) then + return + Non_Fuzzable_Subprogram' + (Declaration => Subp.As_Basic_Decl, + Reason => + +Subp.Full_Sloc_Image & "Can't fuzz ghost code subprograms."); +elsif Subp.Kind in Ada_Abstract_Subp_Decl then + return + Non_Fuzzable_Subprogram' + (Declaration => Subp.As_Basic_Decl, + Reason => + +Subp.Full_Sloc_Image & "Can't fuzz abstract subprograms."); +elsif Get_Subp_Params (Subp).Is_Null then + return + Non_Fuzzable_Subprogram' + (Declaration => Subp.As_Basic_Decl, + Reason => + +Subp.Full_Sloc_Image & "Can't subprograms with no parameters."); +elsif not Has_Input_Parameters (Subp) then + return + Non_Fuzzable_Subprogram' + (Declaration => Subp.As_Basic_Decl, + Reason => + +Subp.Full_Sloc_Image + & "Can't fuzz subprograms with no 'in' or " + & "'in out' parameters"); +elsif Is_Subp_Decl_An_Import_With_Expression (Subp) + and not Is_Intrinsic_Subprogram (Subp) +then + return + Non_Fuzzable_Subprogram' + (Declaration => Subp.As_Basic_Decl, + Reason => + +Subp.Full_Sloc_Image + & "Can't fuzz subprograms where Imports aspect " + & "values are derived from expressions."); +elsif Is_Subp_Decl_Null (Subp) + and not Is_Expr_Function (Subp) + and not Is_Subp_Decl_An_Import (Subp) +then + return + Non_Fuzzable_Subprogram' + (Declaration => Subp.As_Basic_Decl, + Reason => + +Subp.Full_Sloc_Image + & "Can't fuzz subprograms with null " + & "specifications."); +else + null; +end if; diff --git a/testsuite/tests/unparsing/if_stmt/long_last_elsif_cond_expr/test.yaml b/testsuite/tests/unparsing/if_stmt/long_last_elsif_cond_expr/test.yaml new file mode 100644 index 000000000..ff13beb17 --- /dev/null +++ b/testsuite/tests/unparsing/if_stmt/long_last_elsif_cond_expr/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: stmt +description: | + Test that if the last `ElsifStmtPart` is long, it first breaks before the + `then` keyword and then the underlying `f_cond_expr` field. diff --git a/testsuite/tests/unparsing/paren_expr/inside_if/input.ada b/testsuite/tests/unparsing/paren_expr/inside_if/input.ada new file mode 100644 index 000000000..59ec50acd --- /dev/null +++ b/testsuite/tests/unparsing/paren_expr/inside_if/input.ada @@ -0,0 +1,10 @@ +if (Key = Last_Hang + or Key = Last_Crash + or Key = Last_Find + or Key = Slowest_Execution_MS + or Key = Execs_Done) + and Val = "0" +then + Data_Valid := False; + return Val; +end if; diff --git a/testsuite/tests/unparsing/paren_expr/inside_if/test.out b/testsuite/tests/unparsing/paren_expr/inside_if/test.out new file mode 100644 index 000000000..59ec50acd --- /dev/null +++ b/testsuite/tests/unparsing/paren_expr/inside_if/test.out @@ -0,0 +1,10 @@ +if (Key = Last_Hang + or Key = Last_Crash + or Key = Last_Find + or Key = Slowest_Execution_MS + or Key = Execs_Done) + and Val = "0" +then + Data_Valid := False; + return Val; +end if; diff --git a/testsuite/tests/unparsing/paren_expr/inside_if/test.yaml b/testsuite/tests/unparsing/paren_expr/inside_if/test.yaml new file mode 100644 index 000000000..bbb69ef12 --- /dev/null +++ b/testsuite/tests/unparsing/paren_expr/inside_if/test.yaml @@ -0,0 +1,5 @@ +driver: unparser +rule: if_stmt +descrition: | + Test that the expression inside a `ParenExpr` has a continuation line + indentation of 1. diff --git a/testsuite/tests/unparsing/paren_expr/input.ada b/testsuite/tests/unparsing/paren_expr/long/input.ada similarity index 100% rename from testsuite/tests/unparsing/paren_expr/input.ada rename to testsuite/tests/unparsing/paren_expr/long/input.ada diff --git a/testsuite/tests/unparsing/paren_expr/test.out b/testsuite/tests/unparsing/paren_expr/long/test.out similarity index 100% rename from testsuite/tests/unparsing/paren_expr/test.out rename to testsuite/tests/unparsing/paren_expr/long/test.out diff --git a/testsuite/tests/unparsing/paren_expr/test.yaml b/testsuite/tests/unparsing/paren_expr/long/test.yaml similarity index 100% rename from testsuite/tests/unparsing/paren_expr/test.yaml rename to testsuite/tests/unparsing/paren_expr/long/test.yaml From 3a472c1241f72b90050b85d0a865ffd32b3e084b Mon Sep 17 00:00:00 2001 From: Joao Azevedo Date: Tue, 6 Aug 2024 14:56:54 +0000 Subject: [PATCH 8/8] Add config and test for DeclExpr --- extensions/default_unparsing_config.json | 169 +++++++++++------- testsuite/tests/unparsing/decl_expr/input.ada | 8 + testsuite/tests/unparsing/decl_expr/test.out | 8 + testsuite/tests/unparsing/decl_expr/test.yaml | 4 + 4 files changed, 121 insertions(+), 68 deletions(-) create mode 100644 testsuite/tests/unparsing/decl_expr/input.ada create mode 100644 testsuite/tests/unparsing/decl_expr/test.out create mode 100644 testsuite/tests/unparsing/decl_expr/test.yaml diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index f90577380..13be671e3 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -614,29 +614,29 @@ "kind": "group", "document": [ { - "kind": "group", - "document": [ - { - "kind": "recurse_field", - "field": "f_left" + "kind": "group", + "document": [ + { + "kind": "recurse_field", + "field": "f_left" } ] - }, - "line", - { - "kind": "recurse_field", - "field": "f_op" - }, - "whitespace", - { - "kind": "innerRoot", - "contents": { - "kind": "recurse_field", - "field": "f_right" + }, + "line", + { + "kind": "recurse_field", + "field": "f_op" + }, + "whitespace", + { + "kind": "innerRoot", + "contents": { + "kind": "recurse_field", + "field": "f_right" + } + } + ] } - } - ] - } ] }, "matchers": [ @@ -1762,6 +1762,42 @@ ] } }, + "DeclExpr": { + "node": { + "kind": "group", + "document": [ + { + "kind": "text", + "text": "declare" + }, + { + "kind": "continuationLineIndent", + "contents": [ + "hardline", + { + "kind": "recurse_field", + "field": "f_decls" + } + ] + }, + "hardline", + { + "kind": "text", + "text": "begin" + }, + { + "kind": "continuationLineIndent", + "contents": [ + "hardline", + { + "kind": "recurse_field", + "field": "f_expr" + } + ] + } + ] + } + }, "DeclList": { "sep": [ "recurse", @@ -3583,8 +3619,8 @@ "contents": { "kind": "group", "document": { - "kind": "recurse_field", - "field": "f_cond_expr" + "kind": "recurse_field", + "field": "f_cond_expr" } } }, @@ -3649,14 +3685,14 @@ "recurse" ], "else": [ - { - "kind": "indent", - "contents": [ - "hardlineWithoutBreakParent", - "recurse" - ] - }, - "hardlineWithoutBreakParent" + { + "kind": "indent", + "contents": [ + "hardlineWithoutBreakParent", + "recurse" + ] + }, + "hardlineWithoutBreakParent" ] } ] @@ -4945,10 +4981,7 @@ }, "ParenExpr": { "node": { - "kind": "align", - "width": " ", - "contents": { - "kind": "group", + "kind": "group", "document": [ { "kind": "text", @@ -5439,7 +5472,7 @@ "kind": "group", "document": [ "line", - "recurse" + "recurse" ] } } @@ -5502,21 +5535,21 @@ { "kind": "group", "document": [ - { - "kind": "text", - "text": "(" - }, - { - "kind": "align", - "width": " ", - "contents": { - "kind": "recurse_field", - "field": "f_args" - } - }, - { - "kind": "text", - "text": ")" + { + "kind": "text", + "text": "(" + }, + { + "kind": "align", + "width": " ", + "contents": { + "kind": "recurse_field", + "field": "f_args" + } + }, + { + "kind": "text", + "text": ")" } ] } @@ -5681,24 +5714,24 @@ "document": [] }, { - "kind": "group", - "document": [ - { - "kind": "recurse_field", - "field": "f_left" - }, - "line", - { - "kind": "recurse_field", - "field": "f_op" - }, - "whitespace", - { - "kind": "innerRoot", - "contents": { - "kind": "recurse_field", - "field": "f_right" - } + "kind": "group", + "document": [ + { + "kind": "recurse_field", + "field": "f_left" + }, + "line", + { + "kind": "recurse_field", + "field": "f_op" + }, + "whitespace", + { + "kind": "innerRoot", + "contents": { + "kind": "recurse_field", + "field": "f_right" + } } ] } diff --git a/testsuite/tests/unparsing/decl_expr/input.ada b/testsuite/tests/unparsing/decl_expr/input.ada new file mode 100644 index 000000000..dd42f7b04 --- /dev/null +++ b/testsuite/tests/unparsing/decl_expr/input.ada @@ -0,0 +1,8 @@ +function Is_Subp_Decl_An_Import_With_Expression + (Subp : Basic_Decl'Class) return Boolean +is (declare + Import_Aspect : constant Aspect := + Subp.P_Get_Aspect (Langkit_Support.Text.To_Unbounded_Text ("Import")); + begin + Exists (Import_Aspect) + and then (To_Lower (+Value (Import_Aspect).Text) /= "false")); diff --git a/testsuite/tests/unparsing/decl_expr/test.out b/testsuite/tests/unparsing/decl_expr/test.out new file mode 100644 index 000000000..dd42f7b04 --- /dev/null +++ b/testsuite/tests/unparsing/decl_expr/test.out @@ -0,0 +1,8 @@ +function Is_Subp_Decl_An_Import_With_Expression + (Subp : Basic_Decl'Class) return Boolean +is (declare + Import_Aspect : constant Aspect := + Subp.P_Get_Aspect (Langkit_Support.Text.To_Unbounded_Text ("Import")); + begin + Exists (Import_Aspect) + and then (To_Lower (+Value (Import_Aspect).Text) /= "false")); diff --git a/testsuite/tests/unparsing/decl_expr/test.yaml b/testsuite/tests/unparsing/decl_expr/test.yaml new file mode 100644 index 000000000..e07cbedd2 --- /dev/null +++ b/testsuite/tests/unparsing/decl_expr/test.yaml @@ -0,0 +1,4 @@ +driver: unparser +rule: subp_decl +description: | + Test indentation of `f_decls` and `f_expr` on a `DeclExpr`.