From c63dabe9e11763aa06804f9e08ebdd3bfccc3867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Th=C3=A9venoux?= Date: Thu, 7 Dec 2023 15:04:30 +0100 Subject: [PATCH] Fix p_is_static_expr regarding AttributeRefs This change fixes the p_is_static_expr property when the expression is an attribute reference operating on an enumeration type. --- ada/ast.py | 2 +- .../properties/is_static_expr_2/enum.adb | 23 ++++++++++ .../properties/is_static_expr_2/test.out | 42 +++++++++++++++++++ .../properties/is_static_expr_2/test.yaml | 2 +- 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 testsuite/tests/properties/is_static_expr_2/enum.adb diff --git a/ada/ast.py b/ada/ast.py index d324fd610..bacb9759c 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -13138,7 +13138,7 @@ def is_static_expr(): ar.prefix.name_designated_type ._.is_static_decl & ar.attribute.name_symbol.any_of( - 'First', 'Last', 'Range', 'Val' + 'First', 'Last', 'Range', 'Val', 'Pos' ), ar.prefix.referenced_decl._.is_array diff --git a/testsuite/tests/properties/is_static_expr_2/enum.adb b/testsuite/tests/properties/is_static_expr_2/enum.adb new file mode 100644 index 000000000..5fab93e00 --- /dev/null +++ b/testsuite/tests/properties/is_static_expr_2/enum.adb @@ -0,0 +1,23 @@ +procedure Enum is + type My_Enum is (A, B, C, D, E); + + Min : constant := My_Enum'Pos (My_Enum'First); + --% node.f_expr.p_is_static_expr() + + Max : constant := My_Enum'Pos (My_Enum'Last); + --% node.f_expr.p_is_static_expr() + + type R1 is range Min .. Max; + --% range = node.f_type_def.f_range.f_range + --% range.f_left.p_is_static_expr() + --% range.f_right.p_is_static_expr() + --% node.p_is_static_decl() + + type R2 is range My_Enum'Pos (My_Enum'First) .. My_Enum'Pos (My_Enum'Last); + --% range = node.f_type_def.f_range.f_range + --% range.f_left.p_is_static_expr() + --% range.f_right.p_is_static_expr() + --% node.p_is_static_decl() +begin + null; +end Enum; diff --git a/testsuite/tests/properties/is_static_expr_2/test.out b/testsuite/tests/properties/is_static_expr_2/test.out index f47f2d417..92d7cbd1a 100644 --- a/testsuite/tests/properties/is_static_expr_2/test.out +++ b/testsuite/tests/properties/is_static_expr_2/test.out @@ -1,3 +1,45 @@ +Working on node +====================================================== + +Eval 'node.f_expr.p_is_static_expr()' +Result: True + +Working on node +====================================================== + +Eval 'node.f_expr.p_is_static_expr()' +Result: True + +Working on node +============================================================= + +Set 'range' to 'node.f_type_def.f_range.f_range' +Result: + +Eval 'range.f_left.p_is_static_expr()' +Result: True + +Eval 'range.f_right.p_is_static_expr()' +Result: True + +Eval 'node.p_is_static_decl()' +Result: True + +Working on node +============================================================= + +Set 'range' to 'node.f_type_def.f_range.f_range' +Result: + +Eval 'range.f_left.p_is_static_expr()' +Result: True + +Eval 'range.f_right.p_is_static_expr()' +Result: True + +Eval 'node.p_is_static_decl()' +Result: True + Working on node ============================================== diff --git a/testsuite/tests/properties/is_static_expr_2/test.yaml b/testsuite/tests/properties/is_static_expr_2/test.yaml index 830142b33..d5ed64f90 100644 --- a/testsuite/tests/properties/is_static_expr_2/test.yaml +++ b/testsuite/tests/properties/is_static_expr_2/test.yaml @@ -1,2 +1,2 @@ driver: inline-playground -input_sources: [foo.adb] +input_sources: [foo.adb, enum.adb]