Skip to content

Commit 6ec3ce7

Browse files
committed
Remove support for specifying ASVAT models via a pragma Import.
In the CI tests there are many eaxmples of pragma Import with convention Ada which are not ASVAT models. It might be possible to resolve such instances but since Annotate ASVAT is now the preferred way to specify ASVAT models, it seemed better remove support for specifying via Import. Also this branch included code to check whether an Intrinsic program had a body known to gnat2goto. If this check was to comprehensive it should also check if an Imported subprogram with convention Ada has body known to gnat2goto. After some consideration, it was decided that this should not be checked by gnat2goto but at the link phase. So the Intrinsic check has been removed. Gnat2goto still checks and reports an unsupported node if a called subprogram is not in the symbol table.
1 parent e68253e commit 6ec3ce7

File tree

3 files changed

+60
-275
lines changed

3 files changed

+60
-275
lines changed

gnat2goto/driver/asvat-modelling.adb

Lines changed: 10 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
with Ada.Characters.Handling; use Ada.Characters.Handling;
22
with Namet; use Namet;
3-
with Stringt; use Stringt;
43
with Nlists; use Nlists;
54
with Einfo; use Einfo;
65
with Aspects; use Aspects;
6+
with Sem_Util; use Sem_Util;
77
with Ireps; use Ireps;
88
with Follow; use Follow;
99
with Range_Check; use Range_Check;
@@ -42,128 +42,14 @@ package body ASVAT.Modelling is
4242
return Result;
4343
end Find_Model;
4444

45-
-------------------------
46-
-- Get_Annotation_Name --
47-
-------------------------
48-
49-
function Get_Annotation_Name (N : Node_Id) return String is
50-
(Get_Name_String
51-
(Chars (Expression
52-
(First (Pragma_Argument_Associations (N))))));
53-
54-
---------------------------
55-
-- Get_Import_Convention --
56-
---------------------------
57-
58-
function Get_Import_Convention (N : Node_Id) return String is
59-
-- The gnat front end insists thet the parameters for
60-
-- pragma Import are given in the specified order even
61-
-- if named association is used:
62-
-- 1. Convention,
63-
-- 2. Enity,
64-
-- 3. Optional External_Name,
65-
-- 4. Optional Link_Name.
66-
-- The first 2 parameters are mandatory and
67-
-- for ASVAT models the External_Name is required.
68-
--
69-
-- The Convention parameter will always be present as
70-
-- the first parameter.
71-
Conv_Assoc : constant Node_Id :=
72-
First (Pragma_Argument_Associations (N));
73-
Conv_Name : constant Name_Id := Chars (Conv_Assoc);
74-
Convention : constant String := Get_Name_String
75-
(Chars (Expression (Conv_Assoc)));
76-
begin
77-
-- Double check the named parameter if named association is used.
78-
pragma Assert (Conv_Name = No_Name or else
79-
Get_Name_String (Conv_Name) = "convention");
80-
return Convention;
81-
end Get_Import_Convention;
82-
83-
------------------------------
84-
-- Get_Import_External_Name --
85-
------------------------------
86-
87-
function Get_Import_External_Name (N : Node_Id) return String is
88-
-- The gnat front end insists thet the parameters for
89-
-- pragma Import are given in the specified order even
90-
-- if named association is used:
91-
-- 1. Convention,
92-
-- 2. Enity,
93-
-- 3. Optional External_Name,
94-
-- 4. Optional Link_Name.
95-
-- The first 2 parameters are mandatory and
96-
-- for ASVAT models the External_Name is required.
97-
--
98-
-- The External_Name parameter, if present, will be
99-
-- the third parameter.
100-
External_Assoc : constant Node_Id := Next
101-
(Next
102-
(First (Pragma_Argument_Associations (N))));
103-
begin
104-
if Present (External_Assoc) then
105-
declare
106-
External_Name : constant Name_Id := Chars (External_Assoc);
107-
External_Name_Id : constant String_Id :=
108-
Strval (Expression (External_Assoc));
109-
External_Name_Id_Length : constant Natural :=
110-
Natural (String_Length (External_Name_Id));
111-
begin
112-
-- Double check the named parameter if named association is used.
113-
pragma Assert (External_Name = No_Name or else
114-
Get_Name_String
115-
(External_Name) = "external_name");
116-
String_To_Name_Buffer (External_Name_Id);
117-
return To_Lower (Name_Buffer (1 .. External_Name_Id_Length));
118-
end;
119-
else
120-
return "";
121-
end if;
122-
end Get_Import_External_Name;
123-
124-
--------------------------
125-
-- Get_Import_Link_Name --
126-
--------------------------
127-
128-
function Get_Import_Link_Name (N : Node_Id) return String is
129-
-- The gnat front end insists thet the parameters for
130-
-- pragma Import are given in the specified order even
131-
-- if named association is used:
132-
-- 1. Convention,
133-
-- 2. Enity,
134-
-- 3. Optional External_Name,
135-
-- 4. Optional Link_Name.
136-
-- The first 2 parameters are mandatory and
137-
-- for ASVAT models the External_Name is required
138-
-- and for imported non-visible objects, Link_Name is required.
139-
-- The Link_Name parameter, if present, will be
140-
-- the Fourth parameter.
141-
External_Assoc : constant Node_Id := Next
142-
(Next
143-
(First (Pragma_Argument_Associations (N))));
144-
Link_Assoc : constant Node_Id :=
145-
(if Present (External_Assoc) then Next (External_Assoc)
146-
else External_Assoc);
147-
begin
148-
if Present (Link_Assoc) then
149-
declare
150-
Link_Name : constant Name_Id := Chars (Link_Assoc);
151-
Link_Name_Id : constant String_Id :=
152-
Strval (Expression (Link_Assoc));
153-
Link_Name_Id_Length : constant Natural :=
154-
Natural (String_Length (Link_Name_Id));
155-
begin
156-
-- Double check the named parameter if named association is used.
157-
pragma Assert (Link_Name = No_Name or else
158-
Get_Name_String
159-
(Link_Name) = "link_name");
160-
String_To_Name_Buffer (Link_Name_Id);
161-
return To_Lower (Name_Buffer (1 .. Link_Name_Id_Length));
162-
end;
163-
else
164-
return "";
165-
end if;
166-
end Get_Import_Link_Name;
45+
-- -------------------------
46+
-- -- Get_Annotation_Name --
47+
-- -------------------------
48+
--
49+
-- function Get_Annotation_Name (N : Node_Id) return String is
50+
-- (Get_Name_String
51+
-- (Chars (Expression
52+
-- (First (Pragma_Argument_Associations (N))))));
16753

16854
-------------------------
16955
-- Get_Model_From_Anno --
@@ -224,51 +110,11 @@ package body ASVAT.Modelling is
224110
end if;
225111
end Get_Model_From_Anno;
226112

227-
---------------------------
228-
-- Get_Model_From_Import --
229-
---------------------------
230-
231-
function Get_Model_From_Import (N : Node_Id) return Model_Sorts is
232-
Convention : constant String :=
233-
Get_Import_Convention (N);
234-
235-
Is_Ada : constant Boolean := Convention = "ada";
236-
237-
Model_String : constant String :=
238-
(if Is_Ada then
239-
Get_Import_External_Name (N)
240-
else
241-
"");
242-
Model : constant Model_Sorts := Find_Model (Model_String);
243-
begin
244-
if Is_Ada then
245-
if Model_String = "" then
246-
Report_Unhandled_Node_Empty
247-
(N, "Get_Model_From_Import",
248-
"Import convention Ada must have a model sort");
249-
elsif Model = Not_A_Model then
250-
Report_Unhandled_Node_Empty
251-
(N, "Get_Model_From_Import",
252-
"Import convention Ada but '" &
253-
Model_String &
254-
"' is not an ASVAT model sort");
255-
end if;
256-
end if;
257-
return Model;
258-
end Get_Model_From_Import;
259-
260113
--------------------
261114
-- Get_Model_Sort --
262115
--------------------
263116

264117
function Get_Model_Sort (E : Entity_Id) return Model_Sorts is
265-
Obj_Import : constant Node_Id := Get_Pragma (E, Pragma_Import);
266-
Subprog_Import : constant Node_Id :=
267-
(if Ekind (E) in E_Procedure | E_Function then
268-
Import_Pragma (E)
269-
else
270-
Obj_Import);
271-
272118
Anno : constant Node_Id := Find_Aspect (E, Aspect_Annotate);
273119

274120
Anno_Model : constant Model_Sorts :=
@@ -277,27 +123,8 @@ package body ASVAT.Modelling is
277123
else
278124
Not_A_Model);
279125

280-
-- The ASVAT anotation is used even if there is a pragma Import
281-
-- specifying a, possibly different, model.
282-
Import_Model : constant Model_Sorts :=
283-
(if Present (Obj_Import) then
284-
(if Anno_Model = Not_A_Model then
285-
Get_Model_From_Import (Obj_Import)
286-
else
287-
Anno_Model)
288-
elsif Present (Subprog_Import) then
289-
(if Anno_Model = Not_A_Model then
290-
Get_Model_From_Import (Subprog_Import)
291-
else
292-
Anno_Model)
293-
else
294-
Not_A_Model);
295-
296126
begin
297-
return (if Anno_Model /= Not_A_Model then
298-
Anno_Model
299-
else
300-
Import_Model);
127+
return Anno_Model;
301128
end Get_Model_Sort;
302129

303130
--------------------------

gnat2goto/driver/asvat-modelling.ads

Lines changed: 18 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,33 @@
3333
-- is also not visible).
3434
--
3535
-- The ASVAT models are associated with Ada subprograms (or objects, in
36-
-- the case of Represents) by an Annotate aspect specifications or by a
37-
-- pragma Import.
36+
-- the case of Represents) by an Annotate aspect specifications.
3837
--
3938
-- Generally modelling subprograms will not have a body as they represent
4039
-- features of the system that are not being directly analysed by ASVAT,
4140
-- this is the very reason that a model of their behaviour is requred.
42-
-- If the model is associated via an Import pragma the subprogram cannot
43-
-- have a body (An Ada rule). If the model is associated by an Annotation
41+
-- When an ASVAT model is associated with an entity by an Annotation
4442
-- aspect specification then usually an Import => True will be included in
4543
-- the aspect specification. If Import => True is not in the
4644
-- aspect specification the subprogram, Ada rules require the subprogram
4745
-- to have a body but it will be ignored by ASVAT.
4846
--
49-
-- Associating Represents to a declaration of a local variable indicates that
50-
-- the variable represents a more global variable that is not visible in the
51-
-- context of the local declaration. Furthermore, if the type of the
52-
-- non-visible variable a local type declaration can be used to represent
53-
-- this too.
47+
-- Associating Represents model with a declaration of a local variable
48+
-- indicates that the variable represents a more global variable that is
49+
-- not visible in the context of the local declaration.
50+
-- Furthermore, if the type of the non-visible variable a
51+
-- local type declaration can be used to representthis too.
52+
--
5453
-- The local declaration of the variable (and its type, if the type of
5554
-- the non-visible variable is also not visible) must exactly match the
5655
-- declaration of the non-visible variable (and its type if necessary).
5756
-- The purpose of these declarations is to represent global variables of
5857
-- the subprogram which are indirectly updated by the subprogram but not
5958
-- directly visible to it.
6059
--
61-
-- The models can be associated in one of two ways, by an ASVAT annotation or,
62-
-- by using an Import pragma. The ASVAT annotation is the preferred method.
60+
-- The ASVAT models are associated with an entity by an ASVAT annotation.
6361
--
64-
-- Using the ASVAT annotation:
62+
-- Examples:
6563
-- type My_Int is range 1 .. 100;
6664
--
6765
-- X : Integer; -- A normal, visible variable.
@@ -76,8 +74,8 @@
7674
-- "Hidden_Type.My_Int" -- Its non-visible type
7775
-- );
7876
--
79-
-- The name of a modelling subprogram can be any legal Ada subprogram name
80-
-- except operator names.
77+
-- The name of a subprogram associated with an ASVAT model can be any legal
78+
-- Ada subprogram name except operator names.
8179
--
8280
-- function In_Type (N : My_Int) return Boolean
8381
-- with Annotate => (ASVAT, In_Type_Function),
@@ -97,45 +95,13 @@
9795
-- Annotate => (ASVAT, Nondet_In_Type_Vars),
9896
-- Import => True;
9997
--
100-
-- Using pragma Import - the convention Ada indicates it is an ASVAT model:
101-
-- type My_Int is range 1 .. 100;
102-
--
103-
-- X : Integer; -- A normal, visible variable
104-
--
105-
-- I : Integer; -- Represents a variable that is not visible.
106-
-- pragma Import (Ada, I, "Represents", "Hidden_Vars.I");
107-
--
108-
-- J : My_Int; -- Represents a non-visible variable whose type is also
109-
-- -- not visible.
110-
-- pragma Import (Convention => Ada,
111-
-- Entity => J,
112-
-- External_Name => "Represents",
113-
-- Link_Name => "Hidden_Vars.J:Hidden_Type.My_Int");
114-
-- -- Notice the hidden type follows the colon. No spaces allowed.
115-
--
116-
-- The name of a modelling subprogram can be any legal Ada subprogram name
117-
-- except operator names.
118-
--
119-
-- function In_Type (N : My_Int) return Boolean;
120-
-- pragma Import (Ada, In_Type, "In_Type_Function");
121-
--
122-
-- function Nondet_Integer return Integer
123-
-- pragma Global (null);
124-
-- pragma Import (Ada, Non_Det_Integer, "Nondet_Function");
125-
--
126-
-- procedure Update
127-
-- pragma Global ((In_Out => (I, J, X));
128-
-- pragma Import (Ada, Update, "Nondet");
129-
--
130-
-- procedure Read (I : out Integer)
131-
-- pragma Global null,
132-
-- pragma Import (Ada, Read, "Nondet");
98+
-- Current limitations:
99+
-- Only Annotate aspect specifications are supported.
100+
-- Pragma Annotate is not currently supported.
133101

134102
with Types; use Types;
135103
with Atree; use Atree;
136104
with Sinfo; use Sinfo;
137-
with Sem_Util; use Sem_Util;
138-
with Snames; use Snames;
139105

140106
package ASVAT.Modelling is
141107
type Model_Sorts is
@@ -144,30 +110,13 @@ package ASVAT.Modelling is
144110
subtype Valid_Model is Model_Sorts range
145111
Nondet_Function .. Model_Sorts'Last;
146112

147-
function Get_Annotation_Name (N : Node_Id) return String
148-
with Pre => Nkind (N) = N_Pragma and then
149-
Get_Pragma_Id (N) = Pragma_Annotate;
150-
151-
function Get_Import_Convention (N : Node_Id) return String
152-
with Pre => Nkind (N) = N_Pragma and then
153-
Get_Pragma_Id (N) = Pragma_Import;
154-
155-
function Get_Import_External_Name (N : Node_Id) return String
156-
with Pre => Nkind (N) = N_Pragma and then
157-
Get_Pragma_Id (N) = Pragma_Import;
158-
-- Returns null string if the External_Name parameter is not present.
159-
160-
function Get_Import_Link_Name (N : Node_Id) return String
161-
with Pre => Nkind (N) = N_Pragma and then
162-
Get_Pragma_Id (N) = Pragma_Import;
163-
-- Returns null string if the Link_Name parameter is not present.
113+
-- function Get_Annotation_Name (N : Node_Id) return String
114+
-- with Pre => Nkind (N) = N_Pragma and then
115+
-- Get_Pragma_Id (N) = Pragma_Annotate;
164116

165117
function Get_Model_From_Anno (N : Node_Id) return Model_Sorts
166118
with Pre => Nkind (N) = N_Aspect_Specification;
167119

168-
function Get_Model_From_Import (N : Node_Id) return Model_Sorts
169-
with Pre => Nkind (N) = N_Pragma and then Get_Pragma_Id (N) = Pragma_Import;
170-
171120
function Get_Model_Sort (E : Entity_Id) return Model_Sorts;
172121

173122
function Is_Model (Model : Model_Sorts) return Boolean is

0 commit comments

Comments
 (0)