1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
|
-------------------------------------------------------------------------------
-- (C) Altran Praxis Limited
-------------------------------------------------------------------------------
--
-- The SPARK toolset is free software; you can redistribute it and/or modify it
-- under terms of the GNU General Public License as published by the Free
-- Software Foundation; either version 3, or (at your option) any later
-- version. The SPARK toolset is distributed in the hope that it will be
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-- Public License for more details. You should have received a copy of the GNU
-- General Public License distributed with the SPARK toolset; see file
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy of
-- the license.
--
--=============================================================================
--------------------------------------------------------------------------------
--Synopsis: --
-- --
--Procedure to analyse a .PLG file --
-- --
--------------------------------------------------------------------------------
separate (VCS)
procedure AnalyseProofLogFile
(Report_File : in SPARK_IO.File_Type;
Filename : in E_Strings.T;
SIV_File_Date_Time : in E_Strings.T;
Error_In_File : out Boolean)
is
Dummy_Close_Status : SPARK_IO.File_Status;
File_Line : E_Strings.T;
Finished_With_File : Boolean;
Open_Status : SPARK_IO.File_Status;
Read_Line_Success : Boolean;
Proof_Log_File : SPARK_IO.File_Type := SPARK_IO.Null_File;
VC_Proof_Date_Time_From_PLG_File : E_Strings.T;
Proof_Log_Obsolete : Boolean;
Trimmed_Line : E_Strings.T;
Current_VC_Name : E_Strings.T;
procedure Extract_Dates_And_Times_From_Proof_Log_File
(Proof_Log_File : in SPARK_IO.File_Type;
Proof_Log_Date_Time : out E_Strings.T)
--# global in out SPARK_IO.File_Sys;
--# derives Proof_Log_Date_Time,
--# SPARK_IO.File_Sys from Proof_Log_File,
--# SPARK_IO.File_Sys;
is
File_Line : E_Strings.T;
Trimmed_Line : E_Strings.T;
Proof_Date_Time : E_Strings.T;
Start_Found : Boolean := False;
begin
Proof_Log_Date_Time := E_Strings.Empty_String;
while not Start_Found loop
E_Strings.Get_Line (File => Proof_Log_File,
E_Str => File_Line);
Trimmed_Line := E_Strings.Trim (File_Line);
-- find date
if E_Strings.Eq1_String (E_Str => E_Strings.Section (Trimmed_Line, 1, 4),
Str => "DATE") then
-- extract the proof session date and time from the string
Proof_Date_Time :=
E_Strings.Section (Trimmed_Line, PLG_File_VC_Proof_Date_Start_Column, PLG_File_VC_Proof_Date_Length);
E_Strings.Append_String (E_Str => Proof_Date_Time,
Str => " ");
E_Strings.Append_Examiner_String
(E_Str1 => Proof_Date_Time,
E_Str2 => E_Strings.Section (Trimmed_Line, PLG_File_VC_Proof_Time_Start_Column, PLG_File_VC_Proof_Time_Length));
Proof_Log_Date_Time := Proof_Date_Time;
end if;
-- find start of instructions, then go on to analyse the rest of the file
if E_Strings.Eq1_String (E_Str => E_Strings.Section (Trimmed_Line, 1, 7),
Str => "COMMAND") then
Start_Found := True;
end if;
end loop;
-- if date has not been found must be in plain output mode
if E_Strings.Is_Empty (E_Str => Proof_Log_Date_Time) then
Proof_Log_Date_Time := E_Strings.Copy_String (Str => "Unknown date");
end if;
end Extract_Dates_And_Times_From_Proof_Log_File;
-------------------------------------------------------------------------
procedure Check_Proof_Log_Obsolescence
(Proof_Log_Date_Time : in E_Strings.T;
SIV_File_Date_Time : in E_Strings.T;
PLG_Obsolete : out Boolean)
--# global in CommandLine.Data;
--# in out SPARK_IO.File_Sys;
--# derives PLG_Obsolete from CommandLine.Data,
--# Proof_Log_Date_Time,
--# SIV_File_Date_Time &
--# SPARK_IO.File_Sys from *,
--# Proof_Log_Date_Time,
--# SIV_File_Date_Time;
is
Result : Boolean;
PLG_Time_Stamp : Integer;
SIV_Time_Stamp : Integer;
PLG_Date_Stamp : SPARK_Calendar.Time;
SIV_Date_Stamp : SPARK_Calendar.Time;
PLG_Error : Boolean;
SIV_Error : Boolean;
procedure Get_Date_And_Time
(Date_String : in E_Strings.T;
Date_Stamp : out SPARK_Calendar.Time;
Time_Stamp : out Integer;
Error : out Boolean)
--# derives Date_Stamp,
--# Error,
--# Time_Stamp from Date_String;
is
subtype Month_Index is Integer range 0 .. SPARK_Calendar.Month_Number'Last;
Year_Num : SPARK_Calendar.Year_Number;
Raw_Month_Num : Month_Index;
Month_Num : SPARK_Calendar.Month_Number;
Day_Num : SPARK_Calendar.Day_Number;
Hours_Num : Integer;
Minutes_Num : Integer;
Seconds_Num : Integer;
Time_In_Seconds : Integer;
Stamp : SPARK_Calendar.Time;
Stop : Natural;
Time_Error : SPARK_Calendar.Error_Code;
function Month_Name_To_Month_Num (Month_Name : E_Strings.T) return Month_Index is
Num : Month_Index := 0;
begin
if E_Strings.Eq1_String (E_Str => Month_Name,
Str => "JAN") then
Num := 1;
elsif E_Strings.Eq1_String (E_Str => Month_Name,
Str => "FEB") then
Num := 2;
elsif E_Strings.Eq1_String (E_Str => Month_Name,
Str => "MAR") then
Num := 3;
elsif E_Strings.Eq1_String (E_Str => Month_Name,
Str => "APR") then
Num := 4;
elsif E_Strings.Eq1_String (E_Str => Month_Name,
Str => "MAY") then
Num := 5;
elsif E_Strings.Eq1_String (E_Str => Month_Name,
Str => "JUN") then
Num := 6;
elsif E_Strings.Eq1_String (E_Str => Month_Name,
Str => "JUL") then
Num := 7;
elsif E_Strings.Eq1_String (E_Str => Month_Name,
Str => "AUG") then
Num := 8;
elsif E_Strings.Eq1_String (E_Str => Month_Name,
Str => "SEP") then
Num := 9;
elsif E_Strings.Eq1_String (E_Str => Month_Name,
Str => "OCT") then
Num := 10;
elsif E_Strings.Eq1_String (E_Str => Month_Name,
Str => "NOV") then
Num := 11;
elsif E_Strings.Eq1_String (E_Str => Month_Name,
Str => "DEC") then
Num := 12;
end if;
return Num;
end Month_Name_To_Month_Num;
begin --Get_Date_And_Time
-- If the provided date string is empty, do not attempt to parse it, and
-- return an error. Otherwise constraint errors are raised in trying to
-- convert an empty string into an integer value.
-- Note this check does not exclude all situations that may raise a
-- constraint error. To do this, would need to check that the string
-- contains numeric characters in the correct locations.
if E_Strings.Is_Empty (E_Str => Date_String) then
Error := True;
Time_Stamp := 0;
else
--# accept F, 10, Stop, "Stop unused here";
E_Strings.Get_Int_From_String
(Source => E_Strings.Section (E_Str => Date_String,
Start_Pos => 8,
Length => 4),
Item => Year_Num,
Start_Pt => 1,
Stop => Stop);
--# end accept;
Raw_Month_Num := Month_Name_To_Month_Num (Month_Name => E_Strings.Section (Date_String, 4, 3));
if Raw_Month_Num = 0 then
Error := True;
Time_Stamp := 0;
else
Month_Num := Raw_Month_Num;
--# accept F, 10, Stop, "Stop unused here";
E_Strings.Get_Int_From_String
(Source => E_Strings.Section (E_Str => Date_String,
Start_Pos => 1,
Length => 2),
Item => Day_Num,
Start_Pt => 1,
Stop => Stop);
--# end accept;
SPARK_Calendar.Time_Of (Year_Num, Month_Num, Day_Num, Stamp, Time_Error);
if not (Time_Error = SPARK_Calendar.Valid) then
Error := True;
Time_Stamp := 0;
else
--# accept F, 10, Stop, "Stop unused here";
E_Strings.Get_Int_From_String
(Source => E_Strings.Section (E_Str => Date_String,
Start_Pos => 13,
Length => 2),
Item => Hours_Num,
Start_Pt => 1,
Stop => Stop);
E_Strings.Get_Int_From_String
(Source => E_Strings.Section (E_Str => Date_String,
Start_Pos => 16,
Length => 2),
Item => Minutes_Num,
Start_Pt => 1,
Stop => Stop);
E_Strings.Get_Int_From_String
(Source => E_Strings.Section (E_Str => Date_String,
Start_Pos => 19,
Length => 2),
Item => Seconds_Num,
Start_Pt => 1,
Stop => Stop);
--# end accept;
Time_In_Seconds := (Seconds_Num + (Minutes_Num * 60)) + (Hours_Num * 3600);
Date_Stamp := Stamp;
Time_Stamp := Time_In_Seconds;
Error := False;
end if;
end if;
end if;
--# accept F, 33, Stop, "Stop unused here" &
--# F, 602, Date_Stamp, Date_Stamp, "Always well-defined when no error";
end Get_Date_And_Time;
begin
if E_Strings.Eq1_String (E_Str => Proof_Log_Date_Time,
Str => "Unknown date") then
-- If the /i option is specified then the absence of date is not a problem and we
-- can assume that the file is valid.
-- If the /i option is not specified then dates are assumed to be important and a
-- file that lacks a date is therefore obsolete.
Result := CommandLine.Data.IgnoreDates;
else
Get_Date_And_Time
(Date_String => Proof_Log_Date_Time,
Date_Stamp => PLG_Date_Stamp,
Time_Stamp => PLG_Time_Stamp,
Error => PLG_Error);
Get_Date_And_Time
(Date_String => SIV_File_Date_Time,
Date_Stamp => SIV_Date_Stamp,
Time_Stamp => SIV_Time_Stamp,
Error => SIV_Error);
if PLG_Error then
SPARK_IO.Put_Line (SPARK_IO.Standard_Output, "Date format error in PLG file", 0);
Result := True;
elsif SIV_Error then
SPARK_IO.Put_Line (SPARK_IO.Standard_Output, "Date format error in SIV file", 0);
Result := True;
elsif SPARK_Calendar.LT (SIV_Date_Stamp, PLG_Date_Stamp) then
Result := False;
elsif SPARK_Calendar.GT (SIV_Date_Stamp, PLG_Date_Stamp) then
Result := True;
elsif PLG_Time_Stamp < SIV_Time_Stamp then
Result := True;
else
Result := False;
end if;
end if;
PLG_Obsolete := Result;
end Check_Proof_Log_Obsolescence;
--------------------------------------------------------------------------
begin -- AnalyseProofLogFile
-- open proof log file
E_Strings.Open
(File => Proof_Log_File,
Mode_Of_File => SPARK_IO.In_File,
Name_Of_File => Filename,
Form_Of_File => "",
Status => Open_Status);
if Open_Status /= SPARK_IO.Ok then
FatalErrors.Process (FatalErrors.Could_Not_Open_Input_File, E_Strings.Empty_String);
end if;
Extract_Dates_And_Times_From_Proof_Log_File
(Proof_Log_File => Proof_Log_File,
Proof_Log_Date_Time => VC_Proof_Date_Time_From_PLG_File);
-- If the SIV file has a Unknown date/time arising from /plain,
-- then assume the proof log is obsolete, UNLESS we're running
-- POGS with /i, so...
if E_Strings.Eq1_String (E_Str => SIV_File_Date_Time,
Str => Unknown_SIV_Date) then
Proof_Log_Obsolete := True;
else
Check_Proof_Log_Obsolescence
(Proof_Log_Date_Time => VC_Proof_Date_Time_From_PLG_File,
SIV_File_Date_Time => SIV_File_Date_Time,
PLG_Obsolete => Proof_Log_Obsolete);
end if;
if Proof_Log_Obsolete and not CommandLine.Data.IgnoreDates then
SPARK_IO.New_Line (Report_File, 1);
SPARK_IO.Put_Line (Report_File, "*** Warning: Proof Log file out of date ***", 0);
SPARK_IO.Put_String (Report_File, "SIV file time stamp: ", 0);
E_Strings.Put_Line (File => Report_File,
E_Str => SIV_File_Date_Time);
SPARK_IO.Put_String (Report_File, "PLG file time stamp: ", 0);
E_Strings.Put_Line (File => Report_File,
E_Str => VC_Proof_Date_Time_From_PLG_File);
Error_In_File := True;
else
SPARK_IO.New_Line (Report_File, 1);
-- Only output dates if we are not ignoring them.
if CommandLine.Data.IgnoreDates = False then
SPARK_IO.Put_String (Report_File, "VCs proved ", 0);
E_Strings.Put_Line (File => Report_File,
E_Str => VC_Proof_Date_Time_From_PLG_File);
end if;
-- find first non blank line
-- if we get to the end of the file first, flag a fatal error
Read_Next_Non_Blank_Line (File => Proof_Log_File,
Success => Read_Line_Success,
File_Line => File_Line);
if not Read_Line_Success then
SPARK_IO.Put_Line (SPARK_IO.Standard_Output, "************* Proof Log file empty ************", 0);
SPARK_IO.New_Line (SPARK_IO.Standard_Output, 1);
Error_In_File := True;
else
Error_In_File := False;
Finished_With_File := False;
-- process file line-by-line
-- on entry to the loop there is already a valid line in the
-- File_Line buffer
while not Finished_With_File loop
-- examine line and act accordingly
if Is_VC_Proof_Success_Line (Line => File_Line) then
Trimmed_Line := E_Strings.Trim (File_Line);
Current_VC_Name :=
E_Strings.Section
(E_Str => Trimmed_Line,
Start_Pos => 15,
Length => E_Strings.Get_Length (E_Str => Trimmed_Line) - 14);
-- In a proof log file, it's possible that the "Proof
-- Success Line" for a single VC can appear multiple times
-- (if the user types "done" repeatedly after proving a VC for
-- example), so we only mark the VC as proved here ONCE,
-- to stop it being accounted for multiple times in the Totals.
if VCHeap.Get_VC_State (Current_VC_Name) /= VCDetails.VC_Proved_By_Checker then
VCHeap.Set_VC_State (Current_VC_Name, VCDetails.VC_Proved_By_Checker);
end if;
end if;
if not Finished_With_File then
-- read next line
Read_Next_Non_Blank_Line (File => Proof_Log_File,
Success => Read_Line_Success,
File_Line => File_Line);
-- if unsuccessful then check EOF
-- and set Finished_With_File accordingly
if not Read_Line_Success then
if SPARK_IO.End_Of_File (Proof_Log_File) then
Finished_With_File := True;
else
FatalErrors.Process (FatalErrors.Problem_Reading_File, E_Strings.Empty_String);
end if;
end if;
end if;
end loop;
end if;
end if;
--# accept F, 10, Dummy_Close_Status, "Dummy_Close_Status unused here" &
--# F, 10, Proof_Log_File, "Proof_Log_File unused here";
SPARK_IO.Close (Proof_Log_File, Dummy_Close_Status);
--# end accept;
--# accept F, 33, Dummy_Close_Status, "Dummy_Close_Status unused here";
end AnalyseProofLogFile;
|