Skip to content

Commit

Permalink
Merge branch 'topic/1069' into 'master'
Browse files Browse the repository at this point in the history
Support all forms of the Warnings pragma

Closes #1069

See merge request eng/libadalang/libadalang!1402
  • Loading branch information
thvnx committed Oct 3, 2023
2 parents ec91f34 + 70308a3 commit 5a83f76
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 10 deletions.
27 changes: 17 additions & 10 deletions ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -10085,17 +10085,24 @@ def xref_equation():
),

Entity.id.name_is('Warnings'),
Entity.args.at(1)._.assoc_expr.then(
lambda expr: If(
expr.is_a(T.Identifier),

expr.sub_equation,
Entity.args.logic_all(
lambda arg: arg.assoc_expr.then(
lambda expr: If(
expr.is_a(T.Identifier),
If(
expr.cast(T.Identifier)._.name_symbol.any_of(
'On', 'Off', 'GNAT', 'GNATprove'
),
LogicTrue(),
expr.sub_equation
),

Bind(expr.expected_type_var, Self.std_entity("String"))
& expr.sub_equation
& expr.matches_expected_type
),
default_val=LogicTrue()
Bind(expr.expected_type_var, Self.std_entity("String"))
& expr.sub_equation
& expr.matches_expected_type
),
default_val=LogicTrue()
)
),

# Pragmas we want to deliberately not resolve, either because there
Expand Down
12 changes: 12 additions & 0 deletions testsuite/tests/name_resolution/pragma_warnings/test.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
procedure Test is
pragma Warnings (GNATprove, On, "a warning");
pragma Test_Statement;
pragma Warnings (GNAT, Off, "a warning");
pragma Test_Statement;
pragma Warnings (Off, "a warning");
pragma Test_Statement;
pragma Warnings (Off);
pragma Test_Statement;
begin
null;
end Test;
73 changes: 73 additions & 0 deletions testsuite/tests/name_resolution/pragma_warnings/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
Analyzing test.adb
##################

Resolving xrefs for node <PragmaNode test.adb:2:4-2:49>
*******************************************************

Expr: <Id "Warnings" test.adb:2:11-2:19>
references: None
type: None
expected type: None
Expr: <Id "GNATprove" test.adb:2:21-2:30>
references: None
type: None
expected type: None
Expr: <Id "On" test.adb:2:32-2:34>
references: None
type: None
expected type: None
Expr: <Str ""a warning"" test.adb:2:36-2:47>
references: None
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>

Resolving xrefs for node <PragmaNode test.adb:4:4-4:45>
*******************************************************

Expr: <Id "Warnings" test.adb:4:11-4:19>
references: None
type: None
expected type: None
Expr: <Id "GNAT" test.adb:4:21-4:25>
references: None
type: None
expected type: None
Expr: <Id "Off" test.adb:4:27-4:30>
references: None
type: None
expected type: None
Expr: <Str ""a warning"" test.adb:4:32-4:43>
references: None
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>

Resolving xrefs for node <PragmaNode test.adb:6:4-6:39>
*******************************************************

Expr: <Id "Warnings" test.adb:6:11-6:19>
references: None
type: None
expected type: None
Expr: <Id "Off" test.adb:6:21-6:24>
references: None
type: None
expected type: None
Expr: <Str ""a warning"" test.adb:6:26-6:37>
references: None
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>

Resolving xrefs for node <PragmaNode test.adb:8:4-8:26>
*******************************************************

Expr: <Id "Warnings" test.adb:8:11-8:19>
references: None
type: None
expected type: None
Expr: <Id "Off" test.adb:8:21-8:24>
references: None
type: None
expected type: None


Done.
2 changes: 2 additions & 0 deletions testsuite/tests/name_resolution/pragma_warnings/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
driver: name-resolution
input_sources: [test.adb]
6 changes: 6 additions & 0 deletions user_manual/changes/libadalang/1069.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: bugfix
title: Fix ``pragma Warnings`` name resolution
description: |
This change fixes a name resolution bug for the pragma `Warnings` by not
trying to resolve reserved words such as `On`, `Off`, `GNAT` or `GNATprove`.
date: 2023-09-08

0 comments on commit 5a83f76

Please sign in to comment.