From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: [Q] task discriminants and invariant expressions in SPARK
Date: Mon, 31 Oct 2011 13:38:21 +0100
Date: 2011-10-31T13:38:22+01:00 [thread overview]
Message-ID: <4eae96be$0$6564$9b4e6d93@newsspool4.arcor-online.net> (raw)
In a subprogram (named Test) local to a task, the body is a case
distinction that depends only on the value of the task's discriminant.
SPARK reports a flow error because referring to the discriminant
yields an invariant expression. I am trying to understand why
this is a flow error. Or maybe, why this flow is an error. I see
that for invariant expression of a case statement, only one of
the branches of the case statement will be computed per task
subtype, and that the discriminant will have a statically know value.
(I couldn't think of an easy workaround but that may be just me.)
Additionally, will the same flow error be reported for case expressions
or---by extension of the argument---for expression functions?
package Tsk
--# own task Busy : Business;
--# protected Data : Binary;
is
type Binary is mod 2**8;
pragma Atomic (Binary);
type Name is (Fred, Barney);
task type Business (Id : Name)
--# global in out Data;
--# derives Data from Data; -- , Id (constant, not entire_variable)
is
pragma Priority (5);
end Business;
end tsk;
package body Tsk is
Data : Binary := 2#0#;
subtype Freds_Business is Business (Id => Fred);
Busy : Freds_Business;
task body Business is
Current_Data : Binary;
procedure Test
--# global out Data;
--# derives Data from ;
is
begin
case Id is
when Fred =>
Data := 2#1#;
when Barney =>
Data := 2#101#;
end case;
end Test;
begin
loop
Current_Data := Data;
if Current_Data = 2#0# then
Test;
end if;
end loop;
end Business;
end Tsk;
Examining the body of package Tsk ...
18 case Id is
^
!!! Flow Error : 22: Value of expression is invariant.
next reply other threads:[~2011-10-31 12:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-31 12:38 Georg Bauhaus [this message]
2011-10-31 13:04 ` [Q] task discriminants and invariant expressions in SPARK Georg Bauhaus
2011-11-03 9:34 ` Phil Thornley
2011-11-03 12:11 ` Georg Bauhaus
2011-11-03 14:15 ` Georg Bauhaus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox