diff --git a/ada/ast.py b/ada/ast.py index c31c3ce07..c62fdb7cc 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -12547,7 +12547,7 @@ class GenericFormal(BaseFormalParamDecl): Enclosing declaration for a generic formal. The real declaration is accessible via the ``decl`` field. """ - decl = Field(T.BasicDecl) + decl = Field(type=T.BasicDecl) aspects = NullField() defining_names = Property(Entity.decl.defining_names) @@ -22113,6 +22113,17 @@ class NamedStmt(CompositeStmt): xref_equation = Property(LogicTrue()) +class SimpleDeclStmt(SimpleStmt): + """ + Statement wrapping a simple object declaration. + """ + decl = Field(type=T.ObjectDecl) + + @langkit_property() + def xref_equation(): + return LogicTrue() + + @abstract class BaseLoopStmt(CompositeStmt): """ diff --git a/ada/grammar.py b/ada/grammar.py index c84871835..2423f84e4 100644 --- a/ada/grammar.py +++ b/ada/grammar.py @@ -517,6 +517,9 @@ def end_named_block(): A.protected_type_decl, A.subtype_decl, A.object_decl, + A.single_task_decl, + A.protected_decl, + A.number_decl, A.package_decl, A.aspect_clause, A.use_clause, @@ -530,9 +533,6 @@ def end_named_block(): object_decl=Or( A.sub_object_decl, A.no_type_object_renaming_decl, - A.single_task_decl, - A.protected_decl, - A.number_decl ), sub_object_decl=ObjectDecl( @@ -1098,10 +1098,12 @@ def end_named_block(): simple_stmt=Or(A.null_stmt, A.assignment_stmt, A.goto_stmt, A.exit_stmt, - A.return_stmt, A.requeue_stmt, + A.return_stmt, A.requeue_stmt, A.simple_decl_stmt, A.call_stmt, A.abort_stmt, A.delay_stmt, A.raise_stmt, A.terminate_alternative, A.pragma), + simple_decl_stmt=SimpleDeclStmt(A.object_decl), + null_stmt=NullStmt(L.Null, sc()), assignment_stmt=AssignStmt(A.name, ":=", Cut(), A.expr, sc()), diff --git a/testsuite/tests/name_resolution/stmt_object_decl/test.adb b/testsuite/tests/name_resolution/stmt_object_decl/test.adb new file mode 100644 index 000000000..c6b26b39c --- /dev/null +++ b/testsuite/tests/name_resolution/stmt_object_decl/test.adb @@ -0,0 +1,37 @@ +with Ada.Text_IO; use Ada.Text_IO; + +procedure Test is + Outer : Integer := 12; +begin + A : Integer := 12; + B : Integer := A; + + -- Basic test: A & B should be visible + Put_Line (Integer'Image (A + B)); + pragma Test_Statement; + + -- Sequential visibility test: This should fail because C is not declared + -- yet. + Put_Line (Integer'Image (A + B + C)); + pragma Test_Statement; + + -- Renamings test: this should work + C : Integer renames B; + Put_Line (Integer'Image (A + B + C)); + pragma Test_Statement; + + -- FQN test + Test.Outer := A; + pragma Test_Statement; + + Outer : Integer := Test.Outer; + + -- Hiding test: should point to redefinition above + Outer := A; + pragma Test_Statement; + + -- FQN + hiding test: should point to redefinition above too + Test.Outer := A; + pragma Test_Statement; + +end Test; diff --git a/testsuite/tests/name_resolution/stmt_object_decl/test.out b/testsuite/tests/name_resolution/stmt_object_decl/test.out new file mode 100644 index 000000000..3180b06c2 --- /dev/null +++ b/testsuite/tests/name_resolution/stmt_object_decl/test.out @@ -0,0 +1,159 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +******************************************************* + +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: + type: + expected type: +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: None + type: None + expected type: None +Expr: + type: + expected type: +Expr: + references: + type: + expected type: +Expr: + references: None + type: None + expected type: None +Expr: + references: + type: + expected type: + +Resolving xrefs for node +******************************************************* + +Resolution failed for node + +Resolving xrefs for node +******************************************************* + +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: + type: + expected type: +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: None + type: None + expected type: None +Expr: + type: + expected type: +Expr: + type: + expected type: +Expr: + references: + type: + expected type: +Expr: + references: None + type: None + expected type: None +Expr: + references: + type: + expected type: +Expr: + references: None + type: None + expected type: None +Expr: + references: + type: + expected type: + +Resolving xrefs for node +********************************************************* + +Expr: + references: + type: + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: + type: + expected type: None +Expr: + references: + type: + expected type: + +Resolving xrefs for node +********************************************************* + +Expr: + references: + type: + expected type: None +Expr: + references: + type: + expected type: + +Resolving xrefs for node +********************************************************* + +Expr: + references: + type: + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: + type: + expected type: None +Expr: + references: + type: + expected type: + + +Done. diff --git a/testsuite/tests/name_resolution/stmt_object_decl/test.yaml b/testsuite/tests/name_resolution/stmt_object_decl/test.yaml new file mode 100644 index 000000000..173e325ff --- /dev/null +++ b/testsuite/tests/name_resolution/stmt_object_decl/test.yaml @@ -0,0 +1,2 @@ +driver: name-resolution +input_sources: [test.adb]