Skip to content

Commit

Permalink
Merge branch 'topic/1392' into 'master'
Browse files Browse the repository at this point in the history
Implement the `p_get_annotations` property

Closes #1391 and #1392

See merge request eng/libadalang/libadalang!1676
  • Loading branch information
Roldak committed Jun 26, 2024
2 parents d43165a + 7955872 commit 68bb683
Show file tree
Hide file tree
Showing 13 changed files with 620 additions and 38 deletions.
269 changes: 231 additions & 38 deletions ada/ast.py

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions testsuite/tests/name_resolution/annotate_aspect/test.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
procedure Test is
function Foo (X : Integer) return Integer is (X);
pragma Annotate
(My_Tool,
My_Command,
"foo", -- string literals
"foo" & "bar", -- string concatenations
"foo" & Wide_Character'Val (16#2665#), -- or wide strings
"foo" & Wide_Wide_Character'Val (16#2665#), -- or wide wide strings
2 + 2, -- arbitrary expression
Entity => Foo); -- the associated entity
pragma Test_Statement;

function Bar (X : Integer) return Integer is (X)
with Annotate =>
(My_Tool,
My_Command,
"foo",
"foo" & "bar",
"foo" & Wide_Character'Val (16#2665#),
"foo" & Wide_Wide_Character'Val (16#2665#),
2 + 2);
pragma Test_Block;
begin
null;
end Test;
274 changes: 274 additions & 0 deletions testsuite/tests/name_resolution/annotate_aspect/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
Analyzing test.adb
##################

Resolving xrefs for node <PragmaNode test.adb:3:4-11:22>
********************************************************

Expr: <Id "Annotate" test.adb:3:11-3:19>
references: None
type: None
expected type: None
Expr: <Id "My_Tool" test.adb:4:7-4:14>
references: None
type: None
expected type: None
Expr: <Id "My_Command" test.adb:5:7-5:17>
references: None
type: None
expected type: None
Expr: <Str ""foo"" test.adb:6:7-6:12>
references: None
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
Expr: <ConcatOp test.adb:7:7-7:20>
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
Expr: <Str ""foo"" test.adb:7:7-7:12>
references: None
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
Expr: <ConcatOperand test.adb:7:13-7:20>
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
Expr: <OpConcat "&" test.adb:7:13-7:14>
references: None
type: None
expected type: None
Expr: <Str ""bar"" test.adb:7:15-7:20>
references: None
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
Expr: <ConcatOp test.adb:8:7-8:44>
type: <ConcreteTypeDecl ["Wide_String"] __standard:107:3-108:39>
expected type: <ConcreteTypeDecl ["Wide_String"] __standard:107:3-108:39>
Expr: <Str ""foo"" test.adb:8:7-8:12>
references: None
type: <ConcreteTypeDecl ["Wide_String"] __standard:107:3-108:39>
expected type: <ConcreteTypeDecl ["Wide_String"] __standard:107:3-108:39>
Expr: <ConcatOperand test.adb:8:13-8:44>
type: <ConcreteTypeDecl ["Wide_String"] __standard:107:3-108:39>
expected type: <ConcreteTypeDecl ["Wide_String"] __standard:107:3-108:39>
Expr: <OpConcat "&" test.adb:8:13-8:14>
references: None
type: None
expected type: None
Expr: <CallExpr test.adb:8:15-8:44>
references: <SyntheticDefiningName "val" __standard:22:3-22:32>
type: <ConcreteTypeDecl ["Wide_Character"] __standard:22:3-22:32>
expected type: <ConcreteTypeDecl ["Wide_Character"] __standard:22:3-22:32>
Expr: <AttributeRef test.adb:8:15-8:33>
references: <SyntheticDefiningName "val" __standard:22:3-22:32>
type: None
expected type: None
Expr: <Id "Wide_Character" test.adb:8:15-8:29>
references: <DefiningName "Wide_Character" __standard:22:8-22:22>
type: None
expected type: None
Expr: <Id "Val" test.adb:8:30-8:33>
references: None
type: None
expected type: None
Expr: <Int test.adb:8:35-8:43>
references: None
type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
expected type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
Expr: <ConcatOp test.adb:9:7-9:49>
type: <ConcreteTypeDecl ["Wide_Wide_String"] __standard:109:3-110:44>
expected type: <ConcreteTypeDecl ["Wide_Wide_String"] __standard:109:3-110:44>
Expr: <Str ""foo"" test.adb:9:7-9:12>
references: None
type: <ConcreteTypeDecl ["Wide_Wide_String"] __standard:109:3-110:44>
expected type: <ConcreteTypeDecl ["Wide_Wide_String"] __standard:109:3-110:44>
Expr: <ConcatOperand test.adb:9:13-9:49>
type: <ConcreteTypeDecl ["Wide_Wide_String"] __standard:109:3-110:44>
expected type: <ConcreteTypeDecl ["Wide_Wide_String"] __standard:109:3-110:44>
Expr: <OpConcat "&" test.adb:9:13-9:14>
references: None
type: None
expected type: None
Expr: <CallExpr test.adb:9:15-9:49>
references: <SyntheticDefiningName "val" __standard:23:3-23:37>
type: <ConcreteTypeDecl ["Wide_Wide_Character"] __standard:23:3-23:37>
expected type: <ConcreteTypeDecl ["Wide_Wide_Character"] __standard:23:3-23:37>
Expr: <AttributeRef test.adb:9:15-9:38>
references: <SyntheticDefiningName "val" __standard:23:3-23:37>
type: None
expected type: None
Expr: <Id "Wide_Wide_Character" test.adb:9:15-9:34>
references: <DefiningName "Wide_Wide_Character" __standard:23:8-23:27>
type: None
expected type: None
Expr: <Id "Val" test.adb:9:35-9:38>
references: None
type: None
expected type: None
Expr: <Int test.adb:9:40-9:48>
references: None
type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
expected type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
Expr: <BinOp test.adb:10:7-10:12>
type: <ConcreteTypeDecl ["root_integer"] __standard:120:3-120:38>
expected type: None
Expr: <Int test.adb:10:7-10:8>
references: None
type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
expected type: <ConcreteTypeDecl ["root_integer"] __standard:120:3-120:38>
Expr: <OpPlus "+" test.adb:10:9-10:10>
references: <SyntheticDefiningName ""+"" __standard:120:24-120:37>
type: None
expected type: None
Expr: <Int test.adb:10:11-10:12>
references: None
type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
expected type: <ConcreteTypeDecl ["root_integer"] __standard:120:3-120:38>
Expr: <Id "Entity" test.adb:11:7-11:13>
references: None
type: None
expected type: None
Expr: <Id "Foo" test.adb:11:17-11:20>
references: <DefiningName "Foo" test.adb:2:13-2:16>
type: None
expected type: None

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

Expr: <Id "Integer" test.adb:14:38-14:45>
references: <DefiningName "Integer" __standard:4:8-4:15>
type: None
expected type: None

Resolving xrefs for node <ParamSpec ["X"] test.adb:14:18-14:29>
***************************************************************

Expr: <Id "Integer" test.adb:14:22-14:29>
references: <DefiningName "Integer" __standard:4:8-4:15>
type: None
expected type: None

Resolving xrefs for node <AspectAssoc test.adb:15:12-22:16>
***********************************************************

Expr: <Id "Annotate" test.adb:15:12-15:20>
references: None
type: None
expected type: None
Expr: <Aggregate test.adb:16:9-22:16>
type: None
expected type: None
Expr: <Id "My_Tool" test.adb:16:10-16:17>
references: None
type: None
expected type: None
Expr: <Id "My_Command" test.adb:17:10-17:20>
references: None
type: None
expected type: None
Expr: <Str ""foo"" test.adb:18:10-18:15>
references: None
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
Expr: <ConcatOp test.adb:19:10-19:23>
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
Expr: <Str ""foo"" test.adb:19:10-19:15>
references: None
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
Expr: <ConcatOperand test.adb:19:16-19:23>
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
Expr: <OpConcat "&" test.adb:19:16-19:17>
references: None
type: None
expected type: None
Expr: <Str ""bar"" test.adb:19:18-19:23>
references: None
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
Expr: <ConcatOp test.adb:20:10-20:47>
type: <ConcreteTypeDecl ["Wide_String"] __standard:107:3-108:39>
expected type: <ConcreteTypeDecl ["Wide_String"] __standard:107:3-108:39>
Expr: <Str ""foo"" test.adb:20:10-20:15>
references: None
type: <ConcreteTypeDecl ["Wide_String"] __standard:107:3-108:39>
expected type: <ConcreteTypeDecl ["Wide_String"] __standard:107:3-108:39>
Expr: <ConcatOperand test.adb:20:16-20:47>
type: <ConcreteTypeDecl ["Wide_String"] __standard:107:3-108:39>
expected type: <ConcreteTypeDecl ["Wide_String"] __standard:107:3-108:39>
Expr: <OpConcat "&" test.adb:20:16-20:17>
references: None
type: None
expected type: None
Expr: <CallExpr test.adb:20:18-20:47>
references: <SyntheticDefiningName "val" __standard:22:3-22:32>
type: <ConcreteTypeDecl ["Wide_Character"] __standard:22:3-22:32>
expected type: <ConcreteTypeDecl ["Wide_Character"] __standard:22:3-22:32>
Expr: <AttributeRef test.adb:20:18-20:36>
references: <SyntheticDefiningName "val" __standard:22:3-22:32>
type: None
expected type: None
Expr: <Id "Wide_Character" test.adb:20:18-20:32>
references: <DefiningName "Wide_Character" __standard:22:8-22:22>
type: None
expected type: None
Expr: <Id "Val" test.adb:20:33-20:36>
references: None
type: None
expected type: None
Expr: <Int test.adb:20:38-20:46>
references: None
type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
expected type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
Expr: <ConcatOp test.adb:21:10-21:52>
type: <ConcreteTypeDecl ["Wide_Wide_String"] __standard:109:3-110:44>
expected type: <ConcreteTypeDecl ["Wide_Wide_String"] __standard:109:3-110:44>
Expr: <Str ""foo"" test.adb:21:10-21:15>
references: None
type: <ConcreteTypeDecl ["Wide_Wide_String"] __standard:109:3-110:44>
expected type: <ConcreteTypeDecl ["Wide_Wide_String"] __standard:109:3-110:44>
Expr: <ConcatOperand test.adb:21:16-21:52>
type: <ConcreteTypeDecl ["Wide_Wide_String"] __standard:109:3-110:44>
expected type: <ConcreteTypeDecl ["Wide_Wide_String"] __standard:109:3-110:44>
Expr: <OpConcat "&" test.adb:21:16-21:17>
references: None
type: None
expected type: None
Expr: <CallExpr test.adb:21:18-21:52>
references: <SyntheticDefiningName "val" __standard:23:3-23:37>
type: <ConcreteTypeDecl ["Wide_Wide_Character"] __standard:23:3-23:37>
expected type: <ConcreteTypeDecl ["Wide_Wide_Character"] __standard:23:3-23:37>
Expr: <AttributeRef test.adb:21:18-21:41>
references: <SyntheticDefiningName "val" __standard:23:3-23:37>
type: None
expected type: None
Expr: <Id "Wide_Wide_Character" test.adb:21:18-21:37>
references: <DefiningName "Wide_Wide_Character" __standard:23:8-23:27>
type: None
expected type: None
Expr: <Id "Val" test.adb:21:38-21:41>
references: None
type: None
expected type: None
Expr: <Int test.adb:21:43-21:51>
references: None
type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
expected type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
Expr: <BinOp test.adb:22:10-22:15>
type: <ConcreteTypeDecl ["root_integer"] __standard:120:3-120:38>
expected type: None
Expr: <Int test.adb:22:10-22:11>
references: None
type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
expected type: <ConcreteTypeDecl ["root_integer"] __standard:120:3-120:38>
Expr: <OpPlus "+" test.adb:22:12-22:13>
references: <SyntheticDefiningName ""+"" __standard:120:24-120:37>
type: None
expected type: None
Expr: <Int test.adb:22:14-22:15>
references: None
type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
expected type: <ConcreteTypeDecl ["root_integer"] __standard:120:3-120:38>


Done.
2 changes: 2 additions & 0 deletions testsuite/tests/name_resolution/annotate_aspect/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
driver: name-resolution
input_sources: [test.adb]
33 changes: 33 additions & 0 deletions testsuite/tests/properties/get_annotations/base/test.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
procedure Test is
function Foo (X : Integer) return Integer
with Annotate => (My_Tool, My_Command_1),
Annotate => (My_Tool, My_Command_2);
--% node.p_get_annotations()

function Foo (X : Integer) return Integer is
begin
return X;
end Foo;

pragma Annotate (My_Tool, My_Command_3, Entity => Foo);
pragma Annotate (My_Tool, My_Command_4, Entity => Foo);

package Pkg is
type Base is tagged null record
with Annotate => (My_Tool, My_Commmand_1);
--% node.p_get_annotations()

type Der is new Base with private
with Annotate => (My_Tool, My_Command_3);
--% node.p_get_annotations()

pragma Annotate (My_Tool, My_Command_2, Entity => Base);
private
type Der is new Base with null record;

pragma Annotate (My_Tool, My_Command_4, Entity => Der);
end Pkg;
begin
null;
end Test;

24 changes: 24 additions & 0 deletions testsuite/tests/properties/get_annotations/base/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Working on node <SubpDecl ["Foo"] test.adb:2:4-4:48>
====================================================

Eval 'node.p_get_annotations()'
Result: [<Aspect exists=True node=<PragmaNode test.adb:12:4-12:59> value=<Id "My_Tool" test.adb:12:21-12:28> inherited=False>,
<Aspect exists=True node=<PragmaNode test.adb:13:4-13:59> value=<Id "My_Tool" test.adb:13:21-13:28> inherited=False>,
<Aspect exists=True node=<AspectAssoc test.adb:3:12-3:47> value=<Id "My_Tool" test.adb:3:25-3:32> inherited=False>,
<Aspect exists=True node=<AspectAssoc test.adb:4:12-4:47> value=<Id "My_Tool" test.adb:4:25-4:32> inherited=False>]

Working on node <ConcreteTypeDecl ["Base"] test.adb:16:7-17:52>
===============================================================

Eval 'node.p_get_annotations()'
Result: [<Aspect exists=True node=<PragmaNode test.adb:24:7-24:63> value=<Id "My_Tool" test.adb:24:24-24:31> inherited=False>,
<Aspect exists=True node=<AspectAssoc test.adb:17:15-17:51> value=<Id "My_Tool" test.adb:17:28-17:35> inherited=False>]

Working on node <ConcreteTypeDecl ["Der"] test.adb:20:7-21:51>
==============================================================

Eval 'node.p_get_annotations()'
Result: [<Aspect exists=True node=<PragmaNode test.adb:28:7-28:62> value=<Id "My_Tool" test.adb:28:24-28:31> inherited=False>,
<Aspect exists=True node=<AspectAssoc test.adb:21:15-21:50> value=<Id "My_Tool" test.adb:21:28-21:35> inherited=False>,
<Aspect exists=True node=<PragmaNode test.adb:24:7-24:63> value=<Id "My_Tool" test.adb:24:24-24:31> inherited=True>,
<Aspect exists=True node=<AspectAssoc test.adb:17:15-17:51> value=<Id "My_Tool" test.adb:17:28-17:35> inherited=True>]
2 changes: 2 additions & 0 deletions testsuite/tests/properties/get_annotations/base/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
driver: inline-playground
input_sources: [test.adb]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma Annotate (My_Tool, My_Command_2);

package Pkg is
type T is null record;
end Pkg;

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
project Prj is
package Compiler is
for Local_Configuration_Pragmas use "test.adc";
end Compiler;
end Prj;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pragma Annotate (My_Tool, My_Command_1);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[<Aspect exists=True node=<PragmaNode pkg.ads:1:1-1:41> value=<Id "My_Tool" pkg.ads:1:18-1:25> inherited=False>, <Aspect exists=True node=<PragmaNode test.adc:1:1-1:41> value=<Id "My_Tool" test.adc:1:18-1:25> inherited=False>]
14 changes: 14 additions & 0 deletions testsuite/tests/properties/get_annotations/config_pragma/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Check that 'Annotate' configuration pragma are correctly taken into account
in the `get_annotations` property.
"""
import libadalang as lal


project = lal.GPRProject('prj.gpr')
context = project.create_context()

unit = context.get_from_file("pkg.ads")
td = unit.root.find(lal.TypeDecl)

print(td.p_get_annotations())
Loading

0 comments on commit 68bb683

Please sign in to comment.