Skip to content

Commit

Permalink
Merge branch 'unparsing_config_fixes' into 'master'
Browse files Browse the repository at this point in the history
Fix multiple unparsing config issues

Closes eng/ide/gnatformat#62, eng/ide/gnatformat#63, eng/ide/gnatformat#64, eng/ide/gnatformat#65, eng/ide/gnatformat#66, eng/ide/gnatformat#67, eng/ide/gnatformat#68, eng/ide/gnatformat#69, and eng/ide/gnatformat#70

See merge request eng/libadalang/libadalang!1730
  • Loading branch information
joaopsazevedo committed Aug 7, 2024
2 parents 17679a2 + 3a472c1 commit 241f89a
Show file tree
Hide file tree
Showing 44 changed files with 681 additions and 47 deletions.
487 changes: 441 additions & 46 deletions extensions/default_unparsing_config.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions testsuite/tests/unparsing/decl_expr/input.ada
Original file line number Diff line number Diff line change
@@ -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"));
8 changes: 8 additions & 0 deletions testsuite/tests/unparsing/decl_expr/test.out
Original file line number Diff line number Diff line change
@@ -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"));
4 changes: 4 additions & 0 deletions testsuite/tests/unparsing/decl_expr/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: unparser
rule: subp_decl
description: |
Test indentation of `f_decls` and `f_expr` on a `DeclExpr`.
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion testsuite/tests/unparsing/named_stmt/test.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Foo:
Foo :
loop
null;
null;
Expand Down
10 changes: 10 additions & 0 deletions testsuite/tests/unparsing/paren_expr/inside_if/input.ada
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 10 additions & 0 deletions testsuite/tests/unparsing/paren_expr/inside_if/test.out
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions testsuite/tests/unparsing/paren_expr/inside_if/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: unparser
rule: if_stmt
descrition: |
Test that the expression inside a `ParenExpr` has a continuation line
indentation of 1.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
raise Some_Exception with "AAAAAAAAAAAAAAAAAAAAAAAA" & "AAAAAAAAAAAAAAAAAAAAAAAA" & "AAAAAAAAAAAAAAAAAAAAAAAA" & "AAAAAAAAAAAAAAAAAAAAAAAA";
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
raise Some_Exception
with
"AAAAAAAAAAAAAAAAAAAAAAAA"
& "AAAAAAAAAAAAAAAAAAAAAAAA"
& "AAAAAAAAAAAAAAAAAAAAAAAA"
& "AAAAAAAAAAAAAAAAAAAAAAAA";
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[for Value of Foo_Bar => Value]'
Reduce (Foo_Bar_Bar_Bar_Bar, Bar_Foo_Foo_Foo_Foo)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[for Value of Foo_Bar => Value]'
Reduce (Foo_Bar_Bar_Bar_Bar, Bar_Foo_Foo_Foo_Foo)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: unparser
rule: expr
description: |
This tests checks that a `ReduceAttributeRef` is first broken before the
`Reduce` attribute.
5 changes: 5 additions & 0 deletions testsuite/tests/unparsing/reduce_attribute_ref/long/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[for Value_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA of AAAAAAAAAAAAAAAAAAAAAA
=> Value]'
Reduce
(Fooooooooooooooooooooooooooooooooo,
Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar)
5 changes: 5 additions & 0 deletions testsuite/tests/unparsing/reduce_attribute_ref/long/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[for Value_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA of AAAAAAAAAAAAAAAAAAAAAA
=> Value]'
Reduce
(Fooooooooooooooooooooooooooooooooo,
Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar)
5 changes: 5 additions & 0 deletions testsuite/tests/unparsing/reduce_attribute_ref/long/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: unparser
rule: expr
description: |
This tests checks the indentation when all possible line breaks of a
`ReduceAttributeRef` are active.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[for Value of A => Value]'Reduce ("+", 0)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[for Value of A => Value]'Reduce ("+", 0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: unparser
rule: expr
description: |
Test that when a `ReduceAttributeRef` fits in a single line, it does not
break.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return Fooooooooooooooooooooo / Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
return
Fooooooooooooooooooooo / Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar;
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions testsuite/tests/unparsing/subtype_decl/long/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subtype Foo_Bar_Bar_Foo is Foo_Bar_Bar_Bar_Bar_Bar.Bar_Foo_Foo_Foo_Foo_Foo_Foo_Foo;
2 changes: 2 additions & 0 deletions testsuite/tests/unparsing/subtype_decl/long/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
subtype Foo_Bar_Bar_Foo is
Foo_Bar_Bar_Bar_Bar_Bar.Bar_Foo_Foo_Foo_Foo_Foo_Foo_Foo;
4 changes: 4 additions & 0 deletions testsuite/tests/unparsing/subtype_decl/long/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: unparser
rule: subtype_decl
description: |
Test that a `SubtypeDecl` first breaks before the `f_subtype`
1 change: 1 addition & 0 deletions testsuite/tests/unparsing/subtype_decl/short/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subtype Foo is Bar;
1 change: 1 addition & 0 deletions testsuite/tests/unparsing/subtype_decl/short/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subtype Foo is Bar;
4 changes: 4 additions & 0 deletions testsuite/tests/unparsing/subtype_decl/short/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: unparser
rule: subtype_decl
description: |
Test that no line breaks are added when the `SubtypeDecl` fits on one line.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Coloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooor is mod <>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type Coloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooor is
mod <>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: unparser
rule: type_decl
description: |
Test the line break before the `ModIntTypeDef`.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Day is mod <>;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Day is mod <>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: unparser
rule: type_decl
description: |
Test the a short `ModIntTypeDef` does not break.

0 comments on commit 241f89a

Please sign in to comment.