From 314188ed50b0c6e04e2a7505fdc02538bc56a586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Th=C3=A9venoux?= Date: Wed, 12 Apr 2023 16:35:49 +0200 Subject: [PATCH] Support ForLoopVarDecl in BasicDecl.identity_type ForLoopVarDecl can be used in `for ... of` loops as valid task reference. Therefore, the identity_type property should support this node to properly handle the `Identity` attribute. --- ada/ast.py | 2 + .../name_resolution/identity_attr/test.adb | 9 +++ .../name_resolution/identity_attr/test.out | 79 ++++++++++++++----- 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/ada/ast.py b/ada/ast.py index 241c88db7..d0be091b5 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -2923,6 +2923,8 @@ def identity_type(): # An object decl on which you can call 'Identity implies that its # type is a task type. lambda _=T.ObjectDecl: Self.task_id_type, + # As well as for for loop variable declarations + lambda _=T.ForLoopVarDecl: Self.task_id_type, lambda _: No(T.BaseTypeDecl.entity) ) diff --git a/testsuite/tests/name_resolution/identity_attr/test.adb b/testsuite/tests/name_resolution/identity_attr/test.adb index 8abb6d38f..793e86b4d 100644 --- a/testsuite/tests/name_resolution/identity_attr/test.adb +++ b/testsuite/tests/name_resolution/identity_attr/test.adb @@ -15,6 +15,7 @@ procedure Test is end TT; X : TT; + X_Array : array (1 .. 10) of T; begin if T'Identity = X'Identity then null; @@ -25,4 +26,12 @@ begin null; end if; pragma Test_Statement_UID; + + -- Should also work on ForLoopVarDecl + for I of X_Array loop + if I'Identity = Ada.Task_Identification.Current_Task then + null; + end if; + pragma Test_Statement_UID; + end loop; end Test; diff --git a/testsuite/tests/name_resolution/identity_attr/test.out b/testsuite/tests/name_resolution/identity_attr/test.out index 890ba106d..d3a2a999c 100644 --- a/testsuite/tests/name_resolution/identity_attr/test.out +++ b/testsuite/tests/name_resolution/identity_attr/test.out @@ -1,75 +1,118 @@ Analyzing test.adb ################## -Resolving xrefs for node +Resolving xrefs for node ***************************************************** -Expr: +Expr: type: standard.boolean expected type: standard.boolean -Expr: +Expr: references: None type: ada.task_identification.task_id expected type: ada.task_identification.task_id -Expr: +Expr: references: test().t.t type: test().t.t expected type: None -Expr: +Expr: references: None type: None expected type: None -Expr: references: ada.task_identification."="((ada.task_identification.task_id, ada.task_identification.task_id) -> standard.boolean) type: None expected type: None -Expr: +Expr: references: None type: ada.task_identification.task_id expected type: ada.task_identification.task_id -Expr: +Expr: references: test().x type: test().tt expected type: None -Expr: +Expr: references: None type: None expected type: None -Resolving xrefs for node +Resolving xrefs for node ***************************************************** -Expr: +Expr: type: standard.boolean expected type: standard.boolean -Expr: +Expr: references: None type: ada.exceptions.exception_id expected type: ada.exceptions.exception_id -Expr: +Expr: references: standard.constraint_error type: None expected type: None -Expr: +Expr: references: None type: None expected type: None -Expr: references: None type: None expected type: None -Expr: +Expr: references: None type: ada.exceptions.exception_id expected type: ada.exceptions.exception_id -Expr: +Expr: references: standard.constraint_error type: None expected type: None -Expr: +Expr: references: None type: None expected type: None +Resolving xrefs for node +***************************************************** + +Expr: + type: standard.boolean + expected type: standard.boolean +Expr: + references: None + type: ada.task_identification.task_id + expected type: ada.task_identification.task_id +Expr: + references: test().i + type: None + expected type: None +Expr: + references: None + type: None + expected type: None +Expr: standard.boolean) + type: None + expected type: None +Expr: + references: ada.task_identification.current_task(() -> ada.task_identification.task_id) + type: ada.task_identification.task_id + expected type: ada.task_identification.task_id +Expr: + references: ada.task_identification + type: None + expected type: None +Expr: + references: ada + type: None + expected type: None +Expr: + references: ada.task_identification + type: None + expected type: None +Expr: + references: ada.task_identification.current_task(() -> ada.task_identification.task_id) + type: ada.task_identification.task_id + expected type: ada.task_identification.task_id + Done.