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
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . G N A T _ I N T --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2016, Free Software Foundation, Inc. --
--
-- ASIS-for-GNAT 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. ASIS-for-GNAT 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. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception distributed with GNAT; see --
-- the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the --
-- Software Engineering Laboratory of the Swiss Federal Institute of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the --
-- Scientific Research Computer Center of Moscow State University (SRCC --
-- MSU), Russia, with funding partially provided by grants from the Swiss --
-- National Science Foundation and the Swiss Academy of Engineering --
-- Sciences. ASIS-for-GNAT is now maintained by AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
pragma Ada_2012;
with Ada.Exceptions;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with Asis.Errors;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Extensions; use Asis.Extensions;
with A4G.A_Debug; use A4G.A_Debug;
with A4G.A_Opt; use A4G.A_Opt;
with A4G.A_Output; use A4G.A_Output;
with A4G.Contt; use A4G.Contt;
with A4G.Vcheck; use A4G.Vcheck;
with Aspects;
with Atree;
with Csets;
with Elists;
with Fname;
with Gnatvsn;
with Lib;
with Namet;
with Nlists;
with Opt; use Opt;
with Repinfo;
with Sem_Aux;
with Sinput;
with Stand;
with Stringt;
with Uintp;
with Urealp;
with Tree_IO;
package body A4G.GNAT_Int is
LT : String renames ASIS_Line_Terminator;
Standard_GCC : constant String_Access :=
GNAT.OS_Lib.Locate_Exec_On_Path ("gcc-" & Gnatvsn.Library_Version);
-----------------
-- Create_Tree --
-----------------
procedure Create_Tree (Source_File : String_Access;
Context : Context_Id;
Is_Predefined : Boolean;
Success : out Boolean)
is
begin
if Is_Predefined then
Compile (Source_File => Source_File,
Args => GNAT_Flag & Get_Extra_Options (Context),
Success => Success,
GCC => Gcc_To_Call (Context),
Display_Call => Debug_Mode or else Debug_Flag_C);
else
Compile (Source_File => Source_File,
Args => I_Options (Context)
& Get_Extra_Options (Context),
Success => Success,
GCC => Gcc_To_Call (Context),
Display_Call => Debug_Mode or else Debug_Flag_C);
end if;
exception
when others =>
Raise_ASIS_Failed ("A4G.GNAT_Int.Create_Tree:" & LT &
" check the path and environment settings for gcc!");
end Create_Tree;
-------------
-- Execute --
-------------
function Execute
(Program : String_Access;
Args : Argument_List;
Compiler_Out : String := "";
Display_Call : Boolean :=
A4G.A_Debug.Debug_Mode or else A4G.A_Debug.Debug_Flag_C)
return Boolean
is
Success : Boolean;
Return_Code : Integer;
Execute : String_Access := Program;
begin
if Execute = null then
Execute := Standard_GCC;
end if;
if Execute = null then
Ada.Exceptions.Raise_Exception
(Program_Error'Identity,
"A4G.GNAT_Int.Execute: Can not locate program to execute");
end if;
if Display_Call then
Put (Standard_Error, Execute.all);
for J in Args'Range loop
Put (Standard_Error, " ");
Put (Standard_Error, Args (J).all);
end loop;
New_Line (Standard_Error);
if False then -- disable for now
Print_Env;
end if;
end if;
if Compiler_Out /= "" then
GNAT.OS_Lib.Spawn
(Execute.all,
Args,
Compiler_Out,
Success,
Return_Code);
Success := Return_Code = 0;
else
GNAT.OS_Lib.Spawn (Execute.all, Args, Success);
end if;
return Success;
end Execute;
----------------------------------------------
-- General Interfaces between GNAT and ASIS --
----------------------------------------------
function A_Time (T : Time_Stamp_Type) return Time is
Year : Year_Number;
Month : Month_Number;
Day : Day_Number;
Hours : Integer range 0 .. 23;
Minutes : Integer range 0 .. 59;
Seconds : Integer range 0 .. 59;
Day_Time : Day_Duration;
begin
Split_Time_Stamp
(TS => T,
Year => Nat (Year),
Month => Nat (Month),
Day => Nat (Day),
Hour => Nat (Hours),
Minutes => Nat (Minutes),
Seconds => Nat (Seconds));
Day_Time := Duration (Seconds + 60 * Minutes + 3600 * Hours);
return Time_Of (Year, Month, Day, Day_Time);
end A_Time;
--------------------------------
-- Tree_In_With_Version_Check --
--------------------------------
procedure Tree_In_With_Version_Check
(Desc : File_Descriptor;
Cont : Context_Id;
Success : out Boolean)
is
use type Lib.Fatal_Type;
Cont_Mode : constant Context_Mode := Context_Processing_Mode (Cont);
File_Closed : Boolean := False;
ASIS_GNAT_V : constant String := Gnatvsn.Gnat_Version_String;
First_A_Idx : Natural;
Last_A_Idx : Natural;
First_T_Idx : Natural;
Last_T_Idx : Natural;
procedure Note_Version_Mismatch;
-- Close Desc and raise Version_Mismatch
procedure Note_Version_Mismatch is
begin
Close (Desc, File_Closed);
raise Version_Mismatch with
"GNAT " & Tree_Version_String.all &
" vs. ASIS " & ASIS_GNAT_V & ": " &
A_Name_Buffer (1 .. A_Name_Len);
end Note_Version_Mismatch;
-- Start of processing for Tree_In_With_Version_Check
begin
Success := False;
Tree_IO.Tree_Read_Initialize (Desc);
Opt.Tree_Read;
if Strong_Version_Check then
-- We check only the dates here!
First_A_Idx :=
Index (Source => ASIS_GNAT_V,
Pattern => "(") + 1;
First_T_Idx :=
Index (Source => Tree_Version_String.all,
Pattern => "(") + 1;
Last_A_Idx := Index (Source => ASIS_GNAT_V,
Pattern => ")") - 1;
if Index
(Source => ASIS_GNAT_V (First_A_Idx .. Last_A_Idx),
Pattern => "-") /= 0
then
Last_A_Idx :=
Index (Source => ASIS_GNAT_V (First_A_Idx .. Last_A_Idx),
Pattern => "-") - 1;
end if;
Last_T_Idx := Index (Source => Tree_Version_String.all,
Pattern => ")") - 1;
if Index
(Source => Tree_Version_String.all (First_T_Idx .. Last_T_Idx),
Pattern => "-") /= 0
then
Last_T_Idx :=
Index (Source =>
Tree_Version_String.all (First_T_Idx .. Last_T_Idx),
Pattern => "-") - 1;
end if;
if ASIS_GNAT_V (First_A_Idx .. Last_A_Idx) /=
Tree_Version_String (First_T_Idx .. Last_T_Idx)
then
Note_Version_Mismatch;
end if;
end if;
-- GNAT/ASIS version check
if Tree_ASIS_Version_Number /= Tree_IO.ASIS_Version_Number then
Note_Version_Mismatch;
end if;
-- Check that ASIS Pro uses the tree created by GNAT Pro
if ASIS_GNAT_V (ASIS_GNAT_V'First .. ASIS_GNAT_V'First + 2) = "Pro"
and then
Tree_Version_String
(Tree_Version_String'First .. Tree_Version_String'First + 2) /=
"Pro"
then
Note_Version_Mismatch;
end if;
if Operating_Mode /= Check_Semantics then
if Cont_Mode = One_Tree then
-- If in one-tree mode we can not read the only tree we have,
-- there is no reason to continue, so raising an exception
-- is the only choice:
Close (Desc, File_Closed);
-- We did not check File_Closed here, because the fact that the
-- tree is not compile-only seems to be more important for ASIS
Set_Error_Status
(Status => Asis.Errors.Use_Error,
Diagnosis => "Asis.Ada_Environments.Open:"
& ASIS_Line_Terminator
& "tree file "
& Base_Name (A_Name_Buffer (1 .. A_Name_Len))
& " is not compile-only with full semantics");
raise ASIS_Failed;
elsif Cont_Mode = N_Trees
or else
Cont_Mode = All_Trees
then
-- no need to read the rest of this tree file, but
-- we can continue even if we can not read some trees...
ASIS_Warning
(Message => "Asis.Ada_Environments.Open: "
& ASIS_Line_Terminator
& "tree file "
& Base_Name (A_Name_Buffer (1 .. A_Name_Len))
& " is not compile-only with full semantics, ignored",
Error => Asis.Errors.Use_Error);
end if;
-- debug stuff...
if (Debug_Flag_O or else
Debug_Lib_Model or else
Debug_Mode)
and then
Cont_Mode /= One_Tree and then
Cont_Mode /= N_Trees
then
Put (Standard_Error, "tree file ");
Put (Standard_Error, Base_Name (A_Name_Buffer (1 .. A_Name_Len)));
Put (Standard_Error, " is not compile-only with full semantics");
New_Line (Standard_Error);
end if;
else
Atree.Tree_Read;
Elists.Tree_Read;
Fname.Tree_Read;
Lib.Tree_Read;
Namet.Tree_Read;
Nlists.Tree_Read;
Sem_Aux.Tree_Read;
Sinput.Tree_Read;
Stand.Tree_Read;
Stringt.Tree_Read;
Uintp.Tree_Read;
Urealp.Tree_Read;
Repinfo.Tree_Read;
Aspects.Tree_Read;
Csets.Initialize;
-- Check that the tree corresponds to a legal unit
if Lib.Fatal_Error (Types.Main_Unit) /= Lib.None then
Put (Standard_Error, "tree file ");
Put (Standard_Error, Base_Name (A_Name_Buffer (1 .. A_Name_Len)));
Put (Standard_Error, " corresponds to illegal unit");
New_Line (Standard_Error);
Success := False;
else
-- debug stuff...
if Debug_Flag_O or else
Debug_Lib_Model or else
Debug_Mode
then
Put (Standard_Error, "The tree file ");
Put (Standard_Error,
Base_Name (A_Name_Buffer (1 .. A_Name_Len)));
Put (Standard_Error, " is OK");
New_Line (Standard_Error);
end if;
Success := True;
end if;
end if;
Close (Desc, File_Closed);
if not File_Closed then
Raise_ASIS_Failed
(Diagnosis => "Asis.Ada_Environments.Open: " &
"Can not close tree file: " &
Base_Name (A_Name_Buffer (1 .. A_Name_Len)) &
ASIS_Line_Terminator &
"disk is full or file may be used by other program",
Stat => Asis.Errors.Data_Error);
end if;
exception
when Tree_IO.Tree_Format_Error =>
Close (Desc, File_Closed);
Ada.Exceptions.Raise_Exception
(Program_Error'Identity, "Inconsistent versions of GNAT and ASIS");
end Tree_In_With_Version_Check;
end A4G.GNAT_Int;
|