content
stringlengths
23
1.05M
-- HalfSipHash24 -- An instantiation of HalfSipHash with recommended parameters. -- The key must be set with SetKey before use, or there will be no protection -- from hash flooding attacks. -- Copyright (c) 2016, James Humphry - see LICENSE file for details pragma Spark_Mode; with HalfSipHash; pragma Elaborate_All(HalfSipHash); package HalfSipHash24 is new HalfSipHash(c_rounds => 2, d_rounds => 4, k0 => 16#03020100#, k1 => 16#07060504#);
-- TITLE main body -- AUTHOR: John Self (UCI) -- DESCRIPTION driver routines for aflex. Calls drivers for all -- high level routines from other packages. -- $Header: /co/ua/self/arcadia/aflex/ada/src/RCS/mainB.a,v 1.23 90/10/15 20:00:28 self Exp Locker: self $ --*************************************************************************** -- This file is subject to the Arcadia License Agreement. -- -- (see notice in aflex.a) -- --*************************************************************************** with MISC_DEFS, MISC, COMMAND_LINE_INTERFACE, DFA, ECS, GEN, TEXT_IO, PARSER; with MAIN_BODY, TSTRING, PARSE_TOKENS, SKELETON_MANAGER, EXTERNAL_FILE_MANAGER; with EXTERNAL_FILE_MANAGER, INT_IO; use MISC_DEFS, COMMAND_LINE_INTERFACE, TSTRING, EXTERNAL_FILE_MANAGER; package body MAIN_BODY is OUTFILE_CREATED : BOOLEAN := FALSE; AFLEX_VERSION : STRING(1 .. 4) := "1.4a"; STARTTIME, ENDTIME : VSTRING; -- aflexend - terminate aflex -- -- note -- This routine does not return. procedure AFLEXEND(STATUS : in INTEGER) is use TEXT_IO; TBLSIZ : INTEGER; begin TERMINATION_STATUS := STATUS; -- we'll return this value of the OS. if (IS_OPEN(SKELFILE)) then CLOSE(SKELFILE); end if; if (IS_OPEN(TEMP_ACTION_FILE)) then DELETE(TEMP_ACTION_FILE); end if; if (IS_OPEN(DEF_FILE)) then DELETE(DEF_FILE); end if; if (BACKTRACK_REPORT) then if (NUM_BACKTRACKING = 0) then TEXT_IO.PUT_LINE(BACKTRACK_FILE, "No backtracking."); else if (FULLTBL) then INT_IO.PUT(BACKTRACK_FILE, NUM_BACKTRACKING, 0); TEXT_IO.PUT_LINE(BACKTRACK_FILE, " backtracking (non-accepting) states."); else TEXT_IO.PUT_LINE(BACKTRACK_FILE, "Compressed tables always backtrack." ); end if; end if; CLOSE(BACKTRACK_FILE); end if; if (PRINTSTATS) then ENDTIME := MISC.AFLEX_GETTIME; TEXT_IO.PUT_LINE(STANDARD_ERROR, "aflex version " & AFLEX_VERSION & " usage statistics:"); TSTRING.PUT_LINE(STANDARD_ERROR, " started at " & STARTTIME & ", finished at " & ENDTIME); TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, LASTNFA, 0); TEXT_IO.PUT(STANDARD_ERROR, '/'); INT_IO.PUT(STANDARD_ERROR, CURRENT_MNS, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " NFA states"); TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, LASTDFA, 0); TEXT_IO.PUT(STANDARD_ERROR, '/'); INT_IO.PUT(STANDARD_ERROR, CURRENT_MAX_DFAS, 0); TEXT_IO.PUT(STANDARD_ERROR, " DFA states ("); INT_IO.PUT(STANDARD_ERROR, TOTNST, 0); TEXT_IO.PUT(STANDARD_ERROR, " words)"); TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, NUM_RULES - 1, 0); -- - 1 for def. rule TEXT_IO.PUT_LINE(STANDARD_ERROR, " rules"); if (NUM_BACKTRACKING = 0) then TEXT_IO.PUT_LINE(STANDARD_ERROR, " No backtracking"); else if (FULLTBL) then TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, NUM_BACKTRACKING, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " backtracking (non-accepting) states"); else TEXT_IO.PUT_LINE(STANDARD_ERROR, " compressed tables always backtrack" ); end if; end if; if (BOL_NEEDED) then TEXT_IO.PUT_LINE(STANDARD_ERROR, " Beginning-of-line patterns used"); end if; TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, LASTSC, 0); TEXT_IO.PUT(STANDARD_ERROR, '/'); INT_IO.PUT(STANDARD_ERROR, CURRENT_MAX_SCS, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " start conditions"); TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, NUMEPS, 0); TEXT_IO.PUT(STANDARD_ERROR, " epsilon states, "); INT_IO.PUT(STANDARD_ERROR, EPS2, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " double epsilon states"); if (LASTCCL = 0) then TEXT_IO.PUT_LINE(STANDARD_ERROR, " no character classes"); else TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, LASTCCL, 0); TEXT_IO.PUT(STANDARD_ERROR, '/'); INT_IO.PUT(STANDARD_ERROR, CURRENT_MAXCCLS, 0); TEXT_IO.PUT(STANDARD_ERROR, " character classes needed "); INT_IO.PUT(STANDARD_ERROR, CCLMAP(LASTCCL) + CCLLEN(LASTCCL), 0); TEXT_IO.PUT(STANDARD_ERROR, '/'); INT_IO.PUT(STANDARD_ERROR, CURRENT_MAX_CCL_TBL_SIZE, 0); TEXT_IO.PUT(STANDARD_ERROR, " words of storage, "); INT_IO.PUT(STANDARD_ERROR, CCLREUSE, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, "reused"); end if; TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, NUMSNPAIRS, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " state/nextstate pairs created"); TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, NUMUNIQ, 0); TEXT_IO.PUT(STANDARD_ERROR, '/'); INT_IO.PUT(STANDARD_ERROR, NUMDUP, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " unique/duplicate transitions"); if (FULLTBL) then TBLSIZ := LASTDFA*NUMECS; TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, TBLSIZ, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " table entries"); else TBLSIZ := 2*(LASTDFA + NUMTEMPS) + 2*TBLEND; TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, LASTDFA + NUMTEMPS, 0); TEXT_IO.PUT(STANDARD_ERROR, '/'); INT_IO.PUT(STANDARD_ERROR, CURRENT_MAX_DFAS, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " base-def entries created"); TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, TBLEND, 0); TEXT_IO.PUT(STANDARD_ERROR, '/'); INT_IO.PUT(STANDARD_ERROR, CURRENT_MAX_XPAIRS, 0); TEXT_IO.PUT(STANDARD_ERROR, " (peak "); INT_IO.PUT(STANDARD_ERROR, PEAKPAIRS, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, ") nxt-chk entries created"); TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, NUMTEMPS*NUMMECS, 0); TEXT_IO.PUT(STANDARD_ERROR, '/'); INT_IO.PUT(STANDARD_ERROR, CURRENT_MAX_TEMPLATE_XPAIRS, 0); TEXT_IO.PUT(STANDARD_ERROR, " (peak "); INT_IO.PUT(STANDARD_ERROR, NUMTEMPS*NUMECS, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, ") template nxt-chk entries created"); TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, NUMMT, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " empty table entries"); TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, NUMPROTS, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " protos created"); TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, NUMTEMPS, 0); TEXT_IO.PUT(STANDARD_ERROR, " templates created, "); INT_IO.PUT(STANDARD_ERROR, TMPUSES, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, "uses"); end if; if (USEECS) then TBLSIZ := TBLSIZ + CSIZE; TEXT_IO.PUT_LINE(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, NUMECS, 0); TEXT_IO.PUT(STANDARD_ERROR, '/'); INT_IO.PUT(STANDARD_ERROR, CSIZE, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " equivalence classes created"); end if; if (USEMECS) then TBLSIZ := TBLSIZ + NUMECS; TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, NUMMECS, 0); TEXT_IO.PUT(STANDARD_ERROR, '/'); INT_IO.PUT(STANDARD_ERROR, CSIZE, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " meta-equivalence classes created"); end if; TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, HSHCOL, 0); TEXT_IO.PUT(STANDARD_ERROR, " ("); INT_IO.PUT(STANDARD_ERROR, HSHSAVE, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " saved) hash collisions, "); INT_IO.PUT(STANDARD_ERROR, DFAEQL, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " DFAs equal"); TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, NUM_REALLOCS, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " sets of reallocations needed"); TEXT_IO.PUT(STANDARD_ERROR, " "); INT_IO.PUT(STANDARD_ERROR, TBLSIZ, 0); TEXT_IO.PUT_LINE(STANDARD_ERROR, " total table entries needed"); end if; if (STATUS /= 0) then raise AFLEX_TERMINATE; end if; end AFLEXEND; -- aflexinit - initialize aflex procedure AFLEXINIT is use TEXT_IO, TSTRING; SAWCMPFLAG, USE_STDOUT : BOOLEAN; OUTPUT_FILE : FILE_TYPE; INPUT_FILE : FILE_TYPE; I : INTEGER; ARG_CNT : INTEGER; FLAG_POS : INTEGER; ARG : VSTRING; SKELNAME : VSTRING; SKELNAME_USED : BOOLEAN := FALSE; begin PRINTSTATS := FALSE; SYNTAXERROR := FALSE; TRACE := FALSE; SPPRDFLT := FALSE; INTERACTIVE := FALSE; CASEINS := FALSE; BACKTRACK_REPORT := FALSE; PERFORMANCE_REPORT := FALSE; DDEBUG := FALSE; FULLTBL := FALSE; CONTINUED_ACTION := FALSE; GEN_LINE_DIRS := TRUE; USEMECS := TRUE; USEECS := TRUE; SAWCMPFLAG := FALSE; USE_STDOUT := FALSE; -- read flags COMMAND_LINE_INTERFACE.INITIALIZE_COMMAND_LINE; -- load up argv EXTERNAL_FILE_MANAGER.INITIALIZE_FILES; -- do external files setup -- loop through the list of arguments ARG_CNT := 1; while (ARG_CNT <= ARGC - 1) loop if ((CHAR(ARGV(ARG_CNT), 1) /= '-') or (LEN(ARGV(ARG_CNT)) < 2)) then exit; end if; -- loop through the flags in this argument. ARG := ARGV(ARG_CNT); FLAG_POS := 2; while (FLAG_POS <= LEN(ARG)) loop case CHAR(ARG, FLAG_POS) is when 'b' => BACKTRACK_REPORT := TRUE; when 'd' => DDEBUG := TRUE; when 'f' => USEECS := FALSE; USEMECS := FALSE; FULLTBL := TRUE; when 'I' => INTERACTIVE := TRUE; when 'i' => CASEINS := TRUE; when 'L' => GEN_LINE_DIRS := FALSE; when 'p' => PERFORMANCE_REPORT := TRUE; when 'S' => if (FLAG_POS /= 2) then MISC.AFLEXERROR("-S flag must be given separately"); end if; SKELNAME := SLICE(ARG, FLAG_POS + 1, LEN(ARG)); SKELNAME_USED := TRUE; goto GET_NEXT_ARG; when 's' => SPPRDFLT := TRUE; when 't' => USE_STDOUT := TRUE; when 'T' => TRACE := TRUE; when 'v' => PRINTSTATS := TRUE; -- UMASS CODES : -- Added an flag to indicate whether or not the aflex generated -- codes will be used by Ayacc extension. when 'E' => Ayacc_Extension_Flag := TRUE; -- END OF UMASS CODES. when others => MISC.AFLEXERROR("unknown flag " & CHAR(ARG, FLAG_POS)); end case; FLAG_POS := FLAG_POS + 1; end loop; <<GET_NEXT_ARG>> ARG_CNT := ARG_CNT + 1; -- go on to next argument from list. end loop; if (FULLTBL and USEMECS) then MISC.AFLEXERROR("full table and -cm don't make sense together"); end if; if (FULLTBL and INTERACTIVE) then MISC.AFLEXERROR("full table and -I are (currently) incompatible"); end if; if (ARG_CNT < ARGC) then begin if (ARG_CNT - ARGC > 1) then MISC.AFLEXERROR("extraneous argument(s) given"); end if; -- Tell aflex where to read input from. INFILENAME := ARGV(ARG_CNT); OPEN(INPUT_FILE, IN_FILE, STR(ARGV(ARG_CNT))); SET_INPUT(INPUT_FILE); exception when NAME_ERROR => MISC.AFLEXFATAL("can't open " & INFILENAME); end; end if; if (not USE_STDOUT) then EXTERNAL_FILE_MANAGER.GET_SCANNER_FILE(OUTPUT_FILE); OUTFILE_CREATED := TRUE; end if; if (BACKTRACK_REPORT) then EXTERNAL_FILE_MANAGER.GET_BACKTRACK_FILE(BACKTRACK_FILE); end if; LASTCCL := 0; LASTSC := 0; --initialize the statistics STARTTIME := MISC.AFLEX_GETTIME; begin -- open the skeleton file if (SKELNAME_USED) then OPEN(SKELFILE, IN_FILE, STR(SKELNAME)); SKELETON_MANAGER.SET_EXTERNAL_SKELETON; end if; exception when USE_ERROR | NAME_ERROR => MISC.AFLEXFATAL("couldn't open skeleton file " & SKELNAME); end; -- without a third argument create make an anonymous temp file. begin CREATE(TEMP_ACTION_FILE, OUT_FILE); CREATE(DEF_FILE, OUT_FILE); exception when USE_ERROR | NAME_ERROR => MISC.AFLEXFATAL("can't create temporary file"); end; LASTDFA := 0; LASTNFA := 0; NUM_RULES := 0; NUMAS := 0; NUMSNPAIRS := 0; TMPUSES := 0; NUMECS := 0; NUMEPS := 0; EPS2 := 0; NUM_REALLOCS := 0; HSHCOL := 0; DFAEQL := 0; TOTNST := 0; NUMUNIQ := 0; NUMDUP := 0; HSHSAVE := 0; EOFSEEN := FALSE; DATAPOS := 0; DATALINE := 0; NUM_BACKTRACKING := 0; ONESP := 0; NUMPROTS := 0; VARIABLE_TRAILING_CONTEXT_RULES := FALSE; BOL_NEEDED := FALSE; LINENUM := 1; SECTNUM := 1; FIRSTPROT := NIL; -- used in mkprot() so that the first proto goes in slot 1 -- of the proto queue LASTPROT := 1; if (USEECS) then -- set up doubly-linked equivalence classes ECGROUP(1) := NIL; for CNT in 2 .. CSIZE loop ECGROUP(CNT) := CNT - 1; NEXTECM(CNT - 1) := CNT; end loop; NEXTECM(CSIZE) := NIL; else -- put everything in its own equivalence class for CNT in 1 .. CSIZE loop ECGROUP(CNT) := CNT; NEXTECM(CNT) := BAD_SUBSCRIPT; -- to catch errors end loop; end if; SET_UP_INITIAL_ALLOCATIONS; end AFLEXINIT; -- readin - read in the rules section of the input file(s) procedure READIN is begin SKELETON_MANAGER.SKELOUT; TEXT_IO.PUT("with " & TSTRING.STR(MISC.BASENAME) & "_dfa" & "; "); TEXT_IO.PUT_LINE("use " & TSTRING.STR(MISC.BASENAME) & "_dfa" & "; "); TEXT_IO.PUT("with " & TSTRING.STR(MISC.BASENAME) & "_io" & "; "); TEXT_IO.PUT_LINE("use " & TSTRING.STR(MISC.BASENAME) & "_io" & "; "); MISC.LINE_DIRECTIVE_OUT; PARSER.YYPARSE; if (USEECS) then ECS.CRE8ECS(NEXTECM, ECGROUP, CSIZE, NUMECS); ECS.CCL2ECL; else NUMECS := CSIZE; end if; exception when PARSE_TOKENS.SYNTAX_ERROR => MISC.AFLEXERROR("fatal parse error at line " & INTEGER'IMAGE(LINENUM)); MAIN_BODY.AFLEXEND(1); end READIN; -- set_up_initial_allocations - allocate memory for internal tables procedure SET_UP_INITIAL_ALLOCATIONS is begin CURRENT_MNS := INITIAL_MNS; FIRSTST := ALLOCATE_INTEGER_ARRAY(CURRENT_MNS); LASTST := ALLOCATE_INTEGER_ARRAY(CURRENT_MNS); FINALST := ALLOCATE_INTEGER_ARRAY(CURRENT_MNS); TRANSCHAR := ALLOCATE_INTEGER_ARRAY(CURRENT_MNS); TRANS1 := ALLOCATE_INTEGER_ARRAY(CURRENT_MNS); TRANS2 := ALLOCATE_INTEGER_ARRAY(CURRENT_MNS); ACCPTNUM := ALLOCATE_INTEGER_ARRAY(CURRENT_MNS); ASSOC_RULE := ALLOCATE_INTEGER_ARRAY(CURRENT_MNS); STATE_TYPE := ALLOCATE_STATE_ENUM_ARRAY(CURRENT_MNS); CURRENT_MAX_RULES := INITIAL_MAX_RULES; RULE_TYPE := ALLOCATE_RULE_ENUM_ARRAY(CURRENT_MAX_RULES); RULE_LINENUM := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_RULES); CURRENT_MAX_SCS := INITIAL_MAX_SCS; SCSET := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_SCS); SCBOL := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_SCS); SCXCLU := ALLOCATE_BOOLEAN_ARRAY(CURRENT_MAX_SCS); SCEOF := ALLOCATE_BOOLEAN_ARRAY(CURRENT_MAX_SCS); SCNAME := ALLOCATE_VSTRING_ARRAY(CURRENT_MAX_SCS); ACTVSC := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_SCS); CURRENT_MAXCCLS := INITIAL_MAX_CCLS; CCLMAP := ALLOCATE_INTEGER_ARRAY(CURRENT_MAXCCLS); CCLLEN := ALLOCATE_INTEGER_ARRAY(CURRENT_MAXCCLS); CCLNG := ALLOCATE_INTEGER_ARRAY(CURRENT_MAXCCLS); CURRENT_MAX_CCL_TBL_SIZE := INITIAL_MAX_CCL_TBL_SIZE; CCLTBL := ALLOCATE_CHARACTER_ARRAY(CURRENT_MAX_CCL_TBL_SIZE); CURRENT_MAX_DFA_SIZE := INITIAL_MAX_DFA_SIZE; CURRENT_MAX_XPAIRS := INITIAL_MAX_XPAIRS; NXT := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_XPAIRS); CHK := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_XPAIRS); CURRENT_MAX_TEMPLATE_XPAIRS := INITIAL_MAX_TEMPLATE_XPAIRS; TNXT := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_TEMPLATE_XPAIRS); CURRENT_MAX_DFAS := INITIAL_MAX_DFAS; BASE := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_DFAS); DEF := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_DFAS); DFASIZ := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_DFAS); ACCSIZ := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_DFAS); DHASH := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_DFAS); DSS := ALLOCATE_INT_PTR_ARRAY(CURRENT_MAX_DFAS); DFAACC := ALLOCATE_DFAACC_UNION(CURRENT_MAX_DFAS); end SET_UP_INITIAL_ALLOCATIONS; end MAIN_BODY;
-- { dg-do run } with System; procedure Array21 is type Index_T is mod System.Memory_Size; type Arr is array (Index_T range Index_T'Last/2-3 .. Index_T'Last/2+3) of Integer; C : constant Arr := (1, others => 2); begin if C /= (1, 2, 2, 2, 2, 2, 2) then raise Program_Error; end if; end;
with Ada.Real_Time; use Ada.Real_Time; package body Helper with SPARK_Mode is function addWrap(x : Numeric_Type; inc : Numeric_Type) return Numeric_Type is begin if x + inc > Numeric_Type'Last then return x + inc - Numeric_Type'Last; else return x + inc; end if; end addWrap; procedure delay_ms( ms : Natural) is current_time : constant Ada.Real_Time.Time := Ada.Real_Time.Clock; begin delay until current_time + Ada.Real_Time.Milliseconds( ms ); end delay_ms; subtype Balance_Type is Float range -1.0 .. 1.0; pragma Unreferenced (Balance_Type); --function mix( channel_a : Float; channel_b : Float; balance : Balance_Type); end Helper;
with Ada.Unchecked_Conversion; with System; with C.string; package body zlib is use type C.signed_int; use type C.size_t; type unsigned_char_array is array (C.size_t range <>) of aliased C.unsigned_char with Convention => C; pragma Suppress_Initialization (unsigned_char_array); -- C.unsigned_char_array is not generated in some cases Flush_Table : constant array (Boolean) of C.signed_int := (C.zlib.Z_NO_FLUSH, C.zlib.Z_FINISH); function To_String (S : not null access constant C.char) return String is Result : String (1 .. Natural (C.string.strlen (S))); for Result'Address use S.all'Address; begin return Result; end To_String; procedure Raise_Error (Result : C.signed_int); pragma No_Return (Raise_Error); procedure Raise_Error (Result : C.signed_int) is begin case Result is when C.zlib.Z_DATA_ERROR => raise Data_Error with To_String (C.zlib.zError (Result)); when C.zlib.Z_MEM_ERROR => raise Storage_Error with To_String (C.zlib.zError (Result)); when C.zlib.Z_BUF_ERROR => raise Constraint_Error with To_String (C.zlib.zError (Result)); when others => raise Use_Error with To_String (C.zlib.zError (Result)); end case; end Raise_Error; function Make_Window_Bits ( Window_Bits : zlib.Window_Bits; Header : Inflation_Header) return C.signed_int is begin case Header is when None => return -C.signed_int (Window_Bits); when Default => return C.signed_int (Window_Bits); when GZip => return C.signed_int (Window_Bits + 16); when Auto => return C.signed_int (Window_Bits + 32); end case; end Make_Window_Bits; procedure Internal_Deflate_Init ( Stream : in out zlib.Stream; Level : in Compression_Level; Method : in Compression_Method; Window_Bits : in zlib.Window_Bits; Header : in Deflation_Header; Memory_Level : in zlib.Memory_Level; Strategy : in zlib.Strategy) is function To_signed_int is new Ada.Unchecked_Conversion (Compression_Method, C.signed_int); function To_signed_int is new Ada.Unchecked_Conversion (zlib.Strategy, C.signed_int); NC_Stream : Non_Controlled_Stream renames Controlled.Reference (Stream).all; Result : C.signed_int; begin NC_Stream.Z_Stream.zalloc := null; NC_Stream.Z_Stream.zfree := null; NC_Stream.Z_Stream.opaque := C.void_ptr (System.Null_Address); Result := C.zlib.deflateInit2q ( NC_Stream.Z_Stream'Access, level => C.signed_int (Level), method => To_signed_int (Method), windowBits => Make_Window_Bits (Window_Bits, Header), memLevel => C.signed_int (Memory_Level), strategy => To_signed_int (Strategy), version => C.zlib.ZLIB_VERSION (C.zlib.ZLIB_VERSION'First)'Access, stream_size => C.zlib.z_stream'Size / System.Storage_Unit); if Result /= C.zlib.Z_OK then Raise_Error (Result); end if; NC_Stream.Finalize := C.zlib.deflateEnd'Access; NC_Stream.Is_Open := True; NC_Stream.Mode := Deflating; NC_Stream.Stream_End := False; end Internal_Deflate_Init; procedure Internal_Inflate_Init ( Stream : in out zlib.Stream; Window_Bits : in zlib.Window_Bits; Header : in Inflation_Header) is NC_Stream : Non_Controlled_Stream renames Controlled.Reference (Stream).all; Result : C.signed_int; begin NC_Stream.Z_Stream.zalloc := null; NC_Stream.Z_Stream.zfree := null; NC_Stream.Z_Stream.opaque := C.void_ptr (System.Null_Address); Result := C.zlib.inflateInit2q ( NC_Stream.Z_Stream'Access, windowBits => Make_Window_Bits (Window_Bits, Header), version => C.zlib.ZLIB_VERSION (C.zlib.ZLIB_VERSION'First)'Access, stream_size => C.zlib.z_stream'Size / System.Storage_Unit); if Result /= C.zlib.Z_OK then Raise_Error (Result); end if; NC_Stream.Finalize := C.zlib.inflateEnd'Access; NC_Stream.Is_Open := True; NC_Stream.Mode := Inflating; NC_Stream.Stream_End := False; end Internal_Inflate_Init; procedure Close ( NC_Stream : in out Non_Controlled_Stream; Raise_On_Error : Boolean) is Result : C.signed_int; begin Result := NC_Stream.Finalize (NC_Stream.Z_Stream'Access); if Result /= C.zlib.Z_OK and then Raise_On_Error then Raise_Error (Result); end if; NC_Stream.Is_Open := False; end Close; -- implementation procedure Deflate ( Stream : in out zlib.Stream; In_Item : in Ada.Streams.Stream_Element_Array; In_Last : out Ada.Streams.Stream_Element_Offset; Out_Item : out Ada.Streams.Stream_Element_Array; Out_Last : out Ada.Streams.Stream_Element_Offset; Finish : in Boolean; Finished : out Boolean) is pragma Check (Dynamic_Predicate, Check => Is_Open (Stream) or else raise Status_Error); pragma Check (Dynamic_Predicate, Check => Mode (Stream) = Deflating or else raise Mode_Error); NC_Stream : Non_Controlled_Stream renames Controlled.Reference (Stream).all; Z_Stream : constant not null access C.zlib.z_stream := NC_Stream.Z_Stream'Access; C_In_Size : constant C.size_t := In_Item'Length; C_In_Item : unsigned_char_array (0 .. C.size_t'Max (C_In_Size, 1) - 1); for C_In_Item'Address use In_Item'Address; C_Out_Size : constant C.size_t := Out_Item'Length; C_Out_Item : unsigned_char_array (0 .. C.size_t'Max (C_Out_Size, 1) - 1); for C_Out_Item'Address use Out_Item'Address; Result : C.signed_int; begin Z_Stream.next_in := C_In_Item (0)'Unchecked_Access; Z_Stream.avail_in := C.zconf.uInt (C_In_Size); Z_Stream.next_out := C_Out_Item (0)'Unchecked_Access; Z_Stream.avail_out := C.zconf.uInt (C_Out_Size); Result := C.zlib.deflate (Z_Stream, Flush_Table (Finish)); case Result is when C.zlib.Z_OK | C.zlib.Z_STREAM_END => In_Last := In_Item'First + Ada.Streams.Stream_Element_Offset (C_In_Size) - Ada.Streams.Stream_Element_Offset (Z_Stream.avail_in) - 1; Out_Last := Out_Item'First + Ada.Streams.Stream_Element_Offset (C_Out_Size) - Ada.Streams.Stream_Element_Offset (Z_Stream.avail_out) - 1; Finished := Result = C.zlib.Z_STREAM_END; if Finished then NC_Stream.Stream_End := True; end if; when others => Raise_Error (Result); end case; end Deflate; procedure Deflate ( Stream : in out zlib.Stream; In_Item : in Ada.Streams.Stream_Element_Array; In_Last : out Ada.Streams.Stream_Element_Offset; Out_Item : out Ada.Streams.Stream_Element_Array; Out_Last : out Ada.Streams.Stream_Element_Offset) is Dummy_Finished : Boolean; begin Deflate ( Stream, -- Status_Error would be raised if Stream is not open In_Item, In_Last, Out_Item, Out_Last, False, Dummy_Finished); end Deflate; procedure Deflate ( Stream : in out zlib.Stream; Out_Item : out Ada.Streams.Stream_Element_Array; Out_Last : out Ada.Streams.Stream_Element_Offset; Finish : in Boolean; Finished : out Boolean) is Dummy_In_Item : Ada.Streams.Stream_Element_Array (1 .. 0); Dummy_In_Last : Ada.Streams.Stream_Element_Offset; begin Deflate ( Stream, -- Status_Error would be raised if Stream is not open Dummy_In_Item, Dummy_In_Last, Out_Item, Out_Last, Finish, Finished); end Deflate; function Deflate_Init ( Level : Compression_Level := Default_Compression; Method : Compression_Method := Deflated; Window_Bits : zlib.Window_Bits := Default_Window_Bits; Header : Deflation_Header := Default; Memory_Level : zlib.Memory_Level := Default_Memory_Level; Strategy : zlib.Strategy := Default_Strategy) return Stream is begin return Result : Stream do Internal_Deflate_Init ( Result, Level, Method, Window_Bits, Header, Memory_Level, Strategy); end return; end Deflate_Init; procedure Deflate_Or_Inflate ( Stream : in out zlib.Stream; In_Item : in Ada.Streams.Stream_Element_Array; In_Last : out Ada.Streams.Stream_Element_Offset; Out_Item : out Ada.Streams.Stream_Element_Array; Out_Last : out Ada.Streams.Stream_Element_Offset; Finish : in Boolean; Finished : out Boolean) is pragma Check (Dynamic_Predicate, Check => Is_Open (Stream) or else raise Status_Error); NC_Stream : Non_Controlled_Stream renames Controlled.Reference (Stream).all; begin case NC_Stream.Mode is when Deflating => Deflate ( Stream, In_Item, In_Last, Out_Item, Out_Last, Finish, Finished); when Inflating => Inflate ( Stream, In_Item, In_Last, Out_Item, Out_Last, Finish, Finished); end case; end Deflate_Or_Inflate; procedure Inflate ( Stream : in out zlib.Stream; In_Item : in Ada.Streams.Stream_Element_Array; In_Last : out Ada.Streams.Stream_Element_Offset; Out_Item : out Ada.Streams.Stream_Element_Array; Out_Last : out Ada.Streams.Stream_Element_Offset; Finish : in Boolean; Finished : out Boolean) is pragma Check (Dynamic_Predicate, Check => Is_Open (Stream) or else raise Status_Error); pragma Check (Dynamic_Predicate, Check => Mode (Stream) = Inflating or else raise Mode_Error); NC_Stream : Non_Controlled_Stream renames Controlled.Reference (Stream).all; Z_Stream : constant not null access C.zlib.z_stream := NC_Stream.Z_Stream'Access; C_In_Size : constant C.size_t := In_Item'Length; C_In_Item : unsigned_char_array (0 .. C.size_t'Max (C_In_Size, 1) - 1); for C_In_Item'Address use In_Item'Address; C_Out_Size : constant C.size_t := Out_Item'Length; C_Out_Item : unsigned_char_array (0 .. C.size_t'Max (C_Out_Size, 1) - 1); for C_Out_Item'Address use Out_Item'Address; Result : C.signed_int; begin Z_Stream.next_in := C_In_Item (0)'Unchecked_Access; Z_Stream.avail_in := C.zconf.uInt (C_In_Size); Z_Stream.next_out := C_Out_Item (0)'Unchecked_Access; Z_Stream.avail_out := C.zconf.uInt (C_Out_Size); Result := C.zlib.inflate (Z_Stream, Flush_Table (Finish)); case Result is when C.zlib.Z_OK | C.zlib.Z_STREAM_END => In_Last := In_Item'First + Ada.Streams.Stream_Element_Offset (C_In_Size) - Ada.Streams.Stream_Element_Offset (Z_Stream.avail_in) - 1; Out_Last := Out_Item'First + Ada.Streams.Stream_Element_Offset (C_Out_Size) - Ada.Streams.Stream_Element_Offset (Z_Stream.avail_out) - 1; Finished := Result = C.zlib.Z_STREAM_END; if Finished then NC_Stream.Stream_End := True; end if; when others => Raise_Error (Result); end case; end Inflate; procedure Inflate ( Stream : in out zlib.Stream; In_Item : in Ada.Streams.Stream_Element_Array; In_Last : out Ada.Streams.Stream_Element_Offset; Out_Item : out Ada.Streams.Stream_Element_Array; Out_Last : out Ada.Streams.Stream_Element_Offset) is Dummy_Finished : Boolean; begin Inflate ( Stream, -- Status_Error would be raised if Stream is not open In_Item, In_Last, Out_Item, Out_Last, False, Dummy_Finished); end Inflate; procedure Inflate ( Stream : in out zlib.Stream; Out_Item : out Ada.Streams.Stream_Element_Array; Out_Last : out Ada.Streams.Stream_Element_Offset; Finish : in Boolean; Finished : out Boolean) is Dummy_In_Item : Ada.Streams.Stream_Element_Array (1 .. 0); Dummy_In_Last : Ada.Streams.Stream_Element_Offset; begin Inflate ( Stream, -- Status_Error would be raised if Stream is not open Dummy_In_Item, Dummy_In_Last, Out_Item, Out_Last, Finish, Finished); end Inflate; function Inflate_Init ( Window_Bits : zlib.Window_Bits := Default_Window_Bits; Header : Inflation_Header := Auto) return Stream is begin return Result : Stream do Internal_Inflate_Init (Result, Window_Bits, Header); end return; end Inflate_Init; procedure Close (Stream : in out zlib.Stream) is pragma Check (Dynamic_Predicate, Check => Is_Open (Stream) or else raise Status_Error); NC_Stream : Non_Controlled_Stream renames Controlled.Reference (Stream).all; begin Close (NC_Stream, Raise_On_Error => True); end Close; function Is_Open (Stream : zlib.Stream) return Boolean is NC_Stream : Non_Controlled_Stream renames Controlled.Constant_Reference (Stream).all; begin return NC_Stream.Is_Open; end Is_Open; function Mode ( Stream : zlib.Stream) return Stream_Mode is pragma Check (Dynamic_Predicate, Check => Is_Open (Stream) or else raise Status_Error); NC_Stream : Non_Controlled_Stream renames Controlled.Constant_Reference (Stream).all; begin return NC_Stream.Mode; end Mode; function Total_In ( Stream : zlib.Stream) return Ada.Streams.Stream_Element_Count is pragma Check (Dynamic_Predicate, Check => Is_Open (Stream) or else raise Status_Error); NC_Stream : Non_Controlled_Stream renames Controlled.Constant_Reference (Stream).all; begin return Ada.Streams.Stream_Element_Count (NC_Stream.Z_Stream.total_in); end Total_In; function Total_Out ( Stream : zlib.Stream) return Ada.Streams.Stream_Element_Count is pragma Check (Dynamic_Predicate, Check => Is_Open (Stream) or else raise Status_Error); NC_Stream : Non_Controlled_Stream renames Controlled.Constant_Reference (Stream).all; begin return Ada.Streams.Stream_Element_Count (NC_Stream.Z_Stream.total_out); end Total_Out; function Version return String is begin return To_String (C.zlib.zlibVersion); end Version; package body Controlled is function Constant_Reference (Object : zlib.Stream) return not null access constant Non_Controlled_Stream is begin return Stream (Object).Data'Unchecked_Access; end Constant_Reference; function Reference (Object : in out zlib.Stream) return not null access Non_Controlled_Stream is begin return Stream (Object).Variable_View.Data'Access; end Reference; overriding procedure Finalize (Object : in out Stream) is begin if Object.Data.Is_Open then Close (Object.Data, Raise_On_Error => False); end if; end Finalize; end Controlled; -- compatibility procedure Deflate_Init ( Filter : in out Filter_Type; Level : in Compression_Level := Default_Compression; Method : in Compression_Method := Deflated; Window_Bits : in zlib.Window_Bits := Default_Window_Bits; Header : in Deflation_Header := Default; Memory_Level : in zlib.Memory_Level := Default_Memory_Level; Strategy : in Strategy_Type := Default_Strategy) is pragma Check (Dynamic_Predicate, Check => not Is_Open (Filter) or else raise Status_Error); begin Internal_Deflate_Init ( Filter, Level, Method, Window_Bits, Header, Memory_Level, Strategy); end Deflate_Init; procedure Generic_Translate (Filter : in out Filter_Type) is NC_Filter : Non_Controlled_Stream renames Controlled.Reference (Filter).all; In_Item : Ada.Streams.Stream_Element_Array (1 .. 2 ** 15); In_First : Ada.Streams.Stream_Element_Offset := In_Item'Last + 1; In_Last : Ada.Streams.Stream_Element_Offset; In_Used : Ada.Streams.Stream_Element_Offset; Out_Item : Ada.Streams.Stream_Element_Array (1 .. 2 ** 15); Out_Last : Ada.Streams.Stream_Element_Offset; begin loop if In_First > In_Item'Last then Data_In (In_Item, In_Last); In_First := In_Item'First; end if; Translate ( Filter, -- Status_Error would be raised if Filter is not open In_Item (In_First .. In_Last), In_Used, Out_Item, Out_Last, In_Last < In_Item'Last); Data_Out (Out_Item (Out_Item'First .. Out_Last)); exit when NC_Filter.Stream_End; In_First := In_Used + 1; end loop; end Generic_Translate; procedure Inflate_Init ( Filter : in out Filter_Type; Window_Bits : in zlib.Window_Bits := Default_Window_Bits; Header : in Header_Type := Auto) is pragma Check (Dynamic_Predicate, Check => not Is_Open (Filter) or else raise Status_Error); begin Internal_Inflate_Init (Filter, Window_Bits, Header); end Inflate_Init; procedure Read ( Filter : in out Filter_Type; Item : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset; Flush : in Flush_Mode := No_Flush) is pragma Check (Dynamic_Predicate, Check => Is_Open (Filter) or else raise Status_Error); NC_Filter : Non_Controlled_Stream renames Controlled.Reference (Filter).all; begin if NC_Filter.Stream_End then Last := Item'First - 1; else declare In_Used : Ada.Streams.Stream_Element_Offset; Out_First : Ada.Streams.Stream_Element_Offset := Item'First; Finish : Boolean := Flush; begin loop if Rest_First > Rest_Last then Read (Buffer, Rest_Last); Rest_First := Buffer'First; if NC_Filter.Mode = Deflating then Finish := Finish or else Rest_Last < Buffer'Last; end if; end if; Translate ( Filter, Buffer (Rest_First .. Rest_Last), In_Used, Item (Out_First .. Item'Last), Last, Finish); Rest_First := In_Used + 1; exit when NC_Filter.Stream_End or else Last >= Item'Last; Out_First := Last + 1; end loop; end; end if; end Read; procedure Translate ( Filter : in out Filter_Type; In_Data : in Ada.Streams.Stream_Element_Array; In_Last : out Ada.Streams.Stream_Element_Offset; Out_Data : out Ada.Streams.Stream_Element_Array; Out_Last : out Ada.Streams.Stream_Element_Offset; Flush : in Flush_Mode) is Dummy_Finished : Boolean; begin Deflate_Or_Inflate ( Filter, -- Status_Error would be raised if Filter is not open In_Data, In_Last, Out_Data, Out_Last, Flush, Dummy_Finished); end Translate; procedure Write ( Filter : in out Filter_Type; Item : in Ada.Streams.Stream_Element_Array; Flush : in Flush_Mode := No_Flush) is begin if Flush or else Item'First <= Item'Last then declare In_First : Ada.Streams.Stream_Element_Offset := Item'First; begin loop declare In_Used : Ada.Streams.Stream_Element_Offset; Out_Item : Ada.Streams.Stream_Element_Array (1 .. 2 ** 15); Out_Last : Ada.Streams.Stream_Element_Offset; Finished : Boolean; begin Deflate_Or_Inflate ( Filter, -- Status_Error would be raised if it is not open Item (In_First .. Item'Last), In_Used, Out_Item, Out_Last, Flush, Finished); Write (Out_Item (Out_Item'First .. Out_Last)); exit when Finished or else In_Used >= Item'Last; In_First := In_Used + 1; end; end loop; end; end if; end Write; end zlib;
with GESTE; with GESTE_Config; package Render is procedure Push_Pixels (Buffer : GESTE.Output_Buffer); procedure Set_Drawing_Area (Area : GESTE.Pix_Rect); procedure Set_Screen_Offset (Pt : GESTE.Pix_Point); procedure Render_All (Background : GESTE_Config.Output_Color); procedure Render_Dirty (Background : GESTE_Config.Output_Color); procedure Kill; function Dark_Cyan return GESTE_Config.Output_Color; function Black return GESTE_Config.Output_Color; end Render;
------------------------------------------------------------------------------ -- Copyright (c) 2015, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Natools.Web.Backends.Filesystem provides a very simple filesystem-based -- -- implementation of Natools.Web.Backends.Backend. -- ------------------------------------------------------------------------------ with Natools.S_Expressions.Lockable; private with Natools.S_Expressions.Atom_Refs; package Natools.Web.Backends.Filesystem is type File_Backend is new Backend with private; overriding function Create (Self : in out File_Backend; Directory, Name : in S_Expressions.Atom) return Ada.Streams.Root_Stream_Type'Class; -- Create a new file, which must not exist previously overriding procedure Delete (Self : in out File_Backend; Directory, Name : in S_Expressions.Atom); -- Destroy a file, which must exist previously overriding function Read (Self : in File_Backend; Directory, Name : in S_Expressions.Atom) return Ada.Streams.Root_Stream_Type'Class; -- Read the contents of an existing file overriding function Append (Self : in out File_Backend; Directory, Name : in S_Expressions.Atom) return Ada.Streams.Root_Stream_Type'Class; -- Return a stream to append data to the given file overriding function Overwrite (Self : in out File_Backend; Directory, Name : in S_Expressions.Atom) return Ada.Streams.Root_Stream_Type'Class; -- Reset the given file to empty and return a stream to write on it overriding procedure Iterate (Self : in File_Backend; Directory : in S_Expressions.Atom; Process : not null access procedure (Name : in S_Expressions.Atom)); -- Iterate over all the existing file names in Directory not overriding function Create (Root : in String) return File_Backend; function Create (Arguments : in out S_Expressions.Lockable.Descriptor'Class) return Backend'Class; private type File_Backend is new Backend with record Root : S_Expressions.Atom_Refs.Immutable_Reference; end record; end Natools.Web.Backends.Filesystem;
-- AoC 2020, Day 5 with Ada.Text_IO; package body Day is package TIO renames Ada.Text_IO; function parse_line(line : in String) return Boarding_Pass is curr : Boarding_Pass; begin declare low : Row_Type := Row_Type'first; high : Row_Type := Row_Type'last; tmp : Float; begin for idx in 0..6 loop tmp := (Float(high)-Float(low))/2.0; if line(line'first + idx) = 'B' then low := low + Row_Type(Float'Floor(tmp)) + 1; curr.Row := low; elsif line(line'first + idx) = 'F' then high := high - Row_Type(Float'Floor(tmp)) - 1; curr.Row := high; else TIO.put_line("Don't know that value: " & line(line'first + idx)); return curr; end if; end loop; end; declare low : Seat_Type := Seat_Type'first; high : Seat_Type := Seat_Type'last; tmp : Float; begin for idx in 7..9 loop tmp := (Float(high)-Float(low))/2.0; if line(line'first + idx) = 'R' then low := low + Seat_Type(Float'Floor(tmp)) + 1; curr.Seat := low; elsif line(line'first + idx) = 'L' then high := high - Seat_Type(Float'Floor(tmp)) - 1; curr.Seat := high; else TIO.put_line("Don't know that value: " & line(line'first + idx)); return curr; end if; end loop; end; return curr; end parse_line; function load_batch(filename : in String) return Boarding_Pass_Vectors.Vector is file : TIO.File_Type; output : Boarding_Pass_Vectors.Vector; begin TIO.open(File => file, Mode => TIO.In_File, Name => filename); while not TIO.end_of_file(file) loop declare curr : constant Boarding_Pass := parse_line(TIO.get_line(file)); begin output.append(curr); end; end loop; TIO.close(file); return output; end load_batch; function seat_id(pass : in Boarding_Pass) return Natural is begin return (Natural(pass.row) * 8) + Natural(pass.seat); end seat_id; function highest_id(passes : in Boarding_Pass_Vectors.Vector) return Natural is max : Natural := 0; curr : Natural := 0; begin for p of passes loop curr := seat_id(p); if curr > max then max := curr; end if; end loop; return max; end highest_id; package ID_Vectors is new Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Natural); package ID_Sorter is new ID_Vectors.Generic_Sorting; function missing_id(passes : in Boarding_Pass_Vectors.Vector) return Natural is ids : ID_Vectors.Vector; last : Natural; begin for p of passes loop ids.append(seat_id(p)); end loop; ID_Sorter.sort(ids); last := ids(ids.first_index) - 1; for id of ids loop if id /= (last + 1) then return id-1; end if; last := id; end loop; return 0; end missing_id; end Day;
package body impact.d3.Shape.concave is --- Forge -- procedure define (Self : in out Item) is begin Self.m_collisionMargin := 0.0; end define; overriding procedure destruct (Self : in out Item) is begin null; end destruct; --- Attributes -- overriding procedure setMargin (Self : in out Item; margin : in Real) is begin Self.m_collisionMargin := margin; end setMargin; overriding function getMargin (Self : in Item) return Real is begin return Self.m_collisionMargin; end getMargin; end impact.d3.Shape.concave;
-- This package has been generated automatically by GNATtest. -- Do not edit any part of it, see GNATtest documentation for more details. -- begin read only with GNATtest_Generated; package Bases.Recruit_Data_Test_Data.Recruit_Data_Tests is type Test_Recruit_Data is new GNATtest_Generated.GNATtest_Standard.Bases .Recruit_Data_Test_Data .Test_Recruit_Data with null record; end Bases.Recruit_Data_Test_Data.Recruit_Data_Tests; -- end read only
-- This file is covered by the Internet Software Consortium (ISC) License -- Reference: ../License.txt with System; with Interfaces.C.Strings; package Sodium.Thin_Binding is package IC renames Interfaces.C; package ICS renames Interfaces.C.Strings; ------------------ -- Data Types -- ------------------ type NaCl_uint64 is mod 2 ** 64; type NaCl_uint32 is mod 2 ** 32; type NaCl_uint8 is mod 2 ** 8; type NaCl_block64 is array (Natural range <>) of NaCl_uint64; type NaCl_block8 is array (Natural range <>) of NaCl_uint8; pragma Pack (NaCl_block64); pragma Pack (NaCl_block8); type crypto_generichash_blake2b_state is record h : NaCl_block64 (0 .. 7); t : NaCl_block64 (0 .. 1); f : NaCl_block64 (0 .. 1); buf : NaCl_block8 (0 .. 255); buflen : IC.size_t; last_node : NaCl_uint8; end record; for crypto_generichash_blake2b_state'Alignment use 64; pragma Pack (crypto_generichash_blake2b_state); subtype crypto_generichash_state is crypto_generichash_blake2b_state; type crypto_generichash_state_Access is access all crypto_generichash_state; pragma Convention (C, crypto_generichash_state_Access); type crypto_aead_aes256gcm_state is record state : NaCl_block8 (0 .. 511); end record; for crypto_aead_aes256gcm_state'Alignment use 16; type crypto_aead_aes256gcm_state_Access is access all crypto_aead_aes256gcm_state; pragma Convention (C, crypto_aead_aes256gcm_state_Access); type NaCl_uint64_Access is access all NaCl_uint64; pragma Convention (C, NaCl_uint64_Access); ----------------- -- Constants -- ----------------- crypto_generichash_blake2b_BYTES_MIN : constant NaCl_uint8 := 16; crypto_generichash_blake2b_BYTES : constant NaCl_uint8 := 32; crypto_generichash_blake2b_BYTES_MAX : constant NaCl_uint8 := 64; crypto_generichash_blake2b_KEYBYTES_MIN : constant NaCl_uint8 := 16; crypto_generichash_blake2b_KEYBYTES : constant NaCl_uint8 := 32; crypto_generichash_blake2b_KEYBYTES_MAX : constant NaCl_uint8 := 64; crypto_generichash_blake2b_SALTBYTES : constant NaCl_uint8 := 16; crypto_generichash_blake2b_PERSONALBYTES : constant NaCl_uint8 := 16; crypto_generichash_BYTES_MIN : NaCl_uint8 renames crypto_generichash_blake2b_BYTES_MIN; crypto_generichash_BYTES : NaCl_uint8 renames crypto_generichash_blake2b_BYTES; crypto_generichash_BYTES_MAX : NaCl_uint8 renames crypto_generichash_blake2b_BYTES_MAX; crypto_generichash_KEYBYTES_MIN : NaCl_uint8 renames crypto_generichash_blake2b_KEYBYTES_MIN; crypto_generichash_KEYBYTES : NaCl_uint8 renames crypto_generichash_blake2b_KEYBYTES; crypto_generichash_KEYBYTES_MAX : NaCl_uint8 renames crypto_generichash_blake2b_KEYBYTES_MAX; crypto_shorthash_siphash24_BYTES : constant NaCl_uint8 := 8; crypto_shorthash_siphash24_KEYBYTES : constant NaCl_uint8 := 16; crypto_shorthash_BYTES : NaCl_uint8 renames crypto_shorthash_siphash24_BYTES; crypto_shorthash_KEYBYTES : NaCl_uint8 renames crypto_shorthash_siphash24_KEYBYTES; crypto_pwhash_argon2i_ALG_ARGON2I13 : constant IC.int := 1; crypto_pwhash_argon2i_SALTBYTES : constant NaCl_uint8 := 16; crypto_pwhash_argon2i_STRBYTES : constant NaCl_uint8 := 128; crypto_pwhash_argon2i_STRPREFIX : constant String := "$argon2i$"; crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVE : constant NaCl_uint64 := 4; crypto_pwhash_argon2i_MEMLIMIT_INTERACTIVE : constant IC.size_t := 33554432; crypto_pwhash_argon2i_OPSLIMIT_MODERATE : constant NaCl_uint64 := 6; crypto_pwhash_argon2i_MEMLIMIT_MODERATE : constant IC.size_t := 134217728; crypto_pwhash_argon2i_OPSLIMIT_SENSITIVE : constant NaCl_uint64 := 8; crypto_pwhash_argon2i_MEMLIMIT_SENSITIVE : constant IC.size_t := 536870912; crypto_pwhash_ALG_DEFAULT : IC.int renames crypto_pwhash_argon2i_ALG_ARGON2I13; crypto_pwhash_SALTBYTES : NaCl_uint8 renames crypto_pwhash_argon2i_SALTBYTES; crypto_pwhash_STRBYTES : NaCl_uint8 renames crypto_pwhash_argon2i_STRBYTES; crypto_pwhash_STRPREFIX : String renames crypto_pwhash_argon2i_STRPREFIX; crypto_pwhash_OPSLIMIT_MODERATE : NaCl_uint64 renames crypto_pwhash_argon2i_OPSLIMIT_MODERATE; crypto_pwhash_MEMLIMIT_MODERATE : IC.size_t renames crypto_pwhash_argon2i_MEMLIMIT_MODERATE; crypto_pwhash_OPSLIMIT_SENSITIVE : NaCl_uint64 renames crypto_pwhash_argon2i_OPSLIMIT_SENSITIVE; crypto_pwhash_MEMLIMIT_SENSITIVE : IC.size_t renames crypto_pwhash_argon2i_MEMLIMIT_SENSITIVE; crypto_pwhash_OPSLIMIT_INTERACTIVE : NaCl_uint64 renames crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVE; crypto_pwhash_MEMLIMIT_INTERACTIVE : IC.size_t renames crypto_pwhash_argon2i_MEMLIMIT_INTERACTIVE; crypto_box_curve25519xsalsa20poly1305_SEEDBYTES : constant NaCl_uint8 := 32; crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES : constant NaCl_uint8 := 32; crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES : constant NaCl_uint8 := 32; crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES : constant NaCl_uint8 := 32; crypto_box_curve25519xsalsa20poly1305_NONCEBYTES : constant NaCl_uint8 := 24; crypto_box_curve25519xsalsa20poly1305_MACBYTES : constant NaCl_uint8 := 16; crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES : constant NaCl_uint8 := 16; crypto_box_curve25519xsalsa20poly1305_ZEROBYTES : constant NaCl_uint8 := crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES + crypto_box_curve25519xsalsa20poly1305_MACBYTES; crypto_box_SEEDBYTES : NaCl_uint8 renames crypto_box_curve25519xsalsa20poly1305_SEEDBYTES; crypto_box_NONCEBYTES : NaCl_uint8 renames crypto_box_curve25519xsalsa20poly1305_NONCEBYTES; crypto_box_MACBYTES : NaCl_uint8 renames crypto_box_curve25519xsalsa20poly1305_MACBYTES; crypto_box_ZEROBYTES : NaCl_uint8 renames crypto_box_curve25519xsalsa20poly1305_ZEROBYTES; crypto_box_BOXZEROBYTES : NaCl_uint8 renames crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; crypto_box_BEFORENMBYTES : NaCl_uint8 renames crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES; crypto_box_PUBLICKEYBYTES : NaCl_uint8 renames crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES; crypto_box_SECRETKEYBYTES : NaCl_uint8 renames crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES; crypto_box_SEALBYTES : constant NaCl_uint8 := crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES; crypto_sign_ed25519_BYTES : constant NaCl_uint8 := 64; crypto_sign_ed25519_SEEDBYTES : constant NaCl_uint8 := 32; crypto_sign_ed25519_PUBLICKEYBYTES : constant NaCl_uint8 := 32; crypto_sign_ed25519_SECRETKEYBYTES : constant NaCl_uint8 := 32 + 32; crypto_sign_BYTES : NaCl_uint8 renames crypto_sign_ed25519_BYTES; crypto_sign_SEEDBYTES : NaCl_uint8 renames crypto_sign_ed25519_SEEDBYTES; crypto_sign_PUBLICKEYBYTES : NaCl_uint8 renames crypto_sign_ed25519_PUBLICKEYBYTES; crypto_sign_SECRETKEYBYTES : NaCl_uint8 renames crypto_sign_ed25519_SECRETKEYBYTES; crypto_secretbox_xsalsa20poly1305_KEYBYTES : constant NaCl_uint8 := 32; crypto_secretbox_xsalsa20poly1305_NONCEBYTES : constant NaCl_uint8 := 24; crypto_secretbox_xsalsa20poly1305_MACBYTES : constant NaCl_uint8 := 16; crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES : constant NaCl_uint8 := 16; crypto_secretbox_xsalsa20poly1305_ZEROBYTES : constant NaCl_uint8 := crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES + crypto_secretbox_xsalsa20poly1305_MACBYTES; crypto_secretbox_KEYBYTES : NaCl_uint8 renames crypto_secretbox_xsalsa20poly1305_KEYBYTES; crypto_secretbox_MACBYTES : NaCl_uint8 renames crypto_secretbox_xsalsa20poly1305_MACBYTES; crypto_secretbox_NONCEBYTES : NaCl_uint8 renames crypto_secretbox_xsalsa20poly1305_NONCEBYTES; crypto_secretbox_ZEROBYTES : NaCl_uint8 renames crypto_secretbox_xsalsa20poly1305_ZEROBYTES; crypto_secretbox_BOXZEROBYTES : NaCl_uint8 renames crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES; crypto_auth_hmacsha512256_BYTES : constant NaCl_uint8 := 32; crypto_auth_hmacsha512256_KEYBYTES : constant NaCl_uint8 := 32; crypto_auth_BYTES : NaCl_uint8 renames crypto_auth_hmacsha512256_BYTES; crypto_auth_KEYBYTES : NaCl_uint8 renames crypto_auth_hmacsha512256_KEYBYTES; crypto_aead_chacha20poly1305_ietf_KEYBYTES : constant NaCl_uint8 := 32; crypto_aead_chacha20poly1305_ietf_NPUBBYTES : constant NaCl_uint8 := 12; crypto_aead_chacha20poly1305_ietf_ABYTES : constant NaCl_uint8 := 16; crypto_aead_chacha20poly1305_KEYBYTES : constant NaCl_uint8 := 32; crypto_aead_chacha20poly1305_NPUBBYTES : constant NaCl_uint8 := 8; crypto_aead_chacha20poly1305_ABYTES : constant NaCl_uint8 := 16; crypto_aead_aes256gcm_KEYBYTES : constant NaCl_uint8 := 32; crypto_aead_aes256gcm_NPUBBYTES : constant NaCl_uint8 := 12; crypto_aead_aes256gcm_ABYTES : constant NaCl_uint8 := 16; ------------------------ -- New C Data Types -- ------------------------ type Password_Hash_Container is array (1 .. Positive (crypto_pwhash_STRBYTES)) of IC.char; pragma Convention (C, Password_Hash_Container); ----------------- -- Important -- ----------------- function sodium_init return IC.int; pragma Import (C, sodium_init); --------------- -- Hashing -- --------------- function crypto_generichash (text_out : ICS.chars_ptr; outlen : IC.size_t; text_in : ICS.chars_ptr; inlen : NaCl_uint64; key : ICS.chars_ptr; keylen : IC.size_t) return IC.int; pragma Import (C, crypto_generichash); function crypto_generichash_init (state : crypto_generichash_state_Access; key : ICS.chars_ptr; keylen : IC.size_t; outlen : IC.size_t) return IC.int; pragma Import (C, crypto_generichash_init); function crypto_generichash_update (state : crypto_generichash_state_Access; text_in : ICS.chars_ptr; inlen : NaCl_uint64) return IC.int; pragma Import (C, crypto_generichash_update); function crypto_generichash_final (state : crypto_generichash_state_Access; text_out : ICS.chars_ptr; outlen : IC.size_t) return IC.int; pragma Import (C, crypto_generichash_final); function crypto_shorthash (text_out : ICS.chars_ptr; text_in : ICS.chars_ptr; inlen : NaCl_uint64; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_shorthash); function crypto_pwhash (text_out : ICS.chars_ptr; outlen : NaCl_uint64; passwd : ICS.chars_ptr; passwdlen : NaCl_uint64; salt : ICS.chars_ptr; opslimit : NaCl_uint64; memlimit : IC.size_t; alg : IC.int) return IC.int; pragma Import (C, crypto_pwhash); function crypto_pwhash_str (text_out : out Password_Hash_Container; passwd : ICS.chars_ptr; passwdlen : NaCl_uint64; opslimit : NaCl_uint64; memlimit : IC.size_t) return IC.int; pragma Import (C, crypto_pwhash_str); function crypto_pwhash_str_verify (text_str : Password_Hash_Container; passwd : ICS.chars_ptr; passwdlen : NaCl_uint64) return IC.int; pragma Import (C, crypto_pwhash_str_verify); --------------------- -- Random Things -- --------------------- procedure randombytes_buf (buf : System.Address; size : IC.size_t); pragma Import (C, randombytes_buf); function randombytes_random return NaCl_uint32; pragma Import (C, randombytes_random); function randombytes_uniform (upper_bound : NaCl_uint32) return NaCl_uint32; pragma Import (C, randombytes_uniform); ----------------------------- -- Public Key Signatures -- ----------------------------- function crypto_sign_keypair (pk : ICS.chars_ptr; sk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_sign_keypair); function crypto_sign_seed_keypair (pk : ICS.chars_ptr; sk : ICS.chars_ptr; seed : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_sign_seed_keypair); function crypto_sign (sm : ICS.chars_ptr; smlen : NaCl_uint64; m : ICS.chars_ptr; mlen : NaCl_uint64; sk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_sign); function crypto_sign_open (m : ICS.chars_ptr; mlen : NaCl_uint64; sm : ICS.chars_ptr; smlen : NaCl_uint64; pk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_sign_open); function crypto_sign_detached (sig : ICS.chars_ptr; siglen : ICS.chars_ptr; m : ICS.chars_ptr; mlen : NaCl_uint64; sk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_sign_detached); function crypto_sign_verify_detached (sig : ICS.chars_ptr; m : ICS.chars_ptr; mlen : NaCl_uint64; pk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_sign_verify_detached); ----------------------------- -- Public Key Encryption -- ----------------------------- function crypto_box_keypair (pk : ICS.chars_ptr; sk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_keypair); function crypto_box_seed_keypair (pk : ICS.chars_ptr; sk : ICS.chars_ptr; seed : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_seed_keypair); function crypto_scalarmult_base (q : ICS.chars_ptr; n : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_scalarmult_base); function crypto_box_easy (c : ICS.chars_ptr; m : ICS.chars_ptr; mlen : NaCl_uint64; n : ICS.chars_ptr; pk : ICS.chars_ptr; sk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_easy); function crypto_box_open_easy (m : ICS.chars_ptr; c : ICS.chars_ptr; clen : NaCl_uint64; n : ICS.chars_ptr; pk : ICS.chars_ptr; sk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_open_easy); function crypto_box_detached (c : ICS.chars_ptr; mac : ICS.chars_ptr; m : ICS.chars_ptr; mlen : NaCl_uint64; n : ICS.chars_ptr; pk : ICS.chars_ptr; sk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_detached); function crypto_box_open_detached (m : ICS.chars_ptr; c : ICS.chars_ptr; mac : ICS.chars_ptr; clen : NaCl_uint64; n : ICS.chars_ptr; pk : ICS.chars_ptr; sk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_open_detached); function crypto_box_beforenm (k : ICS.chars_ptr; pk : ICS.chars_ptr; sk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_beforenm); function crypto_box_easy_afternm (c : ICS.chars_ptr; m : ICS.chars_ptr; mlen : NaCl_uint64; n : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_easy_afternm); function crypto_box_open_easy_afternm (m : ICS.chars_ptr; c : ICS.chars_ptr; clen : NaCl_uint64; n : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_open_easy_afternm); function crypto_box_detached_afternm (c : ICS.chars_ptr; mac : ICS.chars_ptr; m : ICS.chars_ptr; mlen : NaCl_uint64; n : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_detached_afternm); function crypto_box_open_detached_afternm (m : ICS.chars_ptr; c : ICS.chars_ptr; mac : ICS.chars_ptr; clen : NaCl_uint64; n : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_open_detached_afternm); ---------------------------------- -- Anonymous Private Messages -- ---------------------------------- function crypto_box_seal (c : ICS.chars_ptr; m : ICS.chars_ptr; mlen : NaCl_uint64; pk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_seal); function crypto_box_seal_open (m : ICS.chars_ptr; c : ICS.chars_ptr; clen : NaCl_uint64; pk : ICS.chars_ptr; sk : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_box_seal_open); ---------------------------- -- Symmetric Encryption -- ---------------------------- function crypto_secretbox_easy (c : ICS.chars_ptr; m : ICS.chars_ptr; mlen : NaCl_uint64; n : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_secretbox_easy); function crypto_secretbox_open_easy (m : ICS.chars_ptr; c : ICS.chars_ptr; clen : NaCl_uint64; n : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_secretbox_open_easy); function crypto_secretbox_detached (c : ICS.chars_ptr; mac : ICS.chars_ptr; m : ICS.chars_ptr; mlen : NaCl_uint64; n : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_secretbox_detached); function crypto_secretbox_open_detached (m : ICS.chars_ptr; c : ICS.chars_ptr; mac : ICS.chars_ptr; clen : NaCl_uint64; n : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_secretbox_open_detached); ------------------------------ -- Message Authentication -- ------------------------------ function crypto_auth (tag : ICS.chars_ptr; text_in : ICS.chars_ptr; inlen : NaCl_uint64; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_auth); function crypto_auth_verify (tag : ICS.chars_ptr; text_in : ICS.chars_ptr; inlen : NaCl_uint64; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_auth_verify); ---------------------------------- -- original ChaCha20-Poly1305 -- ---------------------------------- function crypto_aead_chacha20poly1305_encrypt (c : ICS.chars_ptr; clen_p : NaCl_uint64_Access; m : ICS.chars_ptr; mlen : NaCl_uint64; ad : ICS.chars_ptr; adlen : NaCl_uint64; nsec : ICS.chars_ptr; npub : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_chacha20poly1305_encrypt); function crypto_aead_chacha20poly1305_decrypt (m : ICS.chars_ptr; mlen_p : NaCl_uint64_Access; nsec : ICS.chars_ptr; c : ICS.chars_ptr; clen : NaCl_uint64; ad : ICS.chars_ptr; adlen : NaCl_uint64; npub : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_chacha20poly1305_decrypt); function crypto_aead_chacha20poly1305_encrypt_detached (c : ICS.chars_ptr; mac : ICS.chars_ptr; maclen_p : NaCl_uint64_Access; m : ICS.chars_ptr; mlen : NaCl_uint64; ad : ICS.chars_ptr; adlen : NaCl_uint64; nsec : ICS.chars_ptr; npub : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_chacha20poly1305_encrypt_detached); function crypto_aead_chacha20poly1305_decrypt_detached (m : ICS.chars_ptr; nsec : ICS.chars_ptr; c : ICS.chars_ptr; clen : NaCl_uint64; mac : ICS.chars_ptr; ad : ICS.chars_ptr; adlen : NaCl_uint64; npub : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_chacha20poly1305_decrypt_detached); ------------------------------ -- IETF ChaCha20-Poly1305 -- ------------------------------ function crypto_aead_chacha20poly1305_ietf_encrypt (c : ICS.chars_ptr; clen_p : NaCl_uint64_Access; m : ICS.chars_ptr; mlen : NaCl_uint64; ad : ICS.chars_ptr; adlen : NaCl_uint64; nsec : ICS.chars_ptr; npub : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_chacha20poly1305_ietf_encrypt); function crypto_aead_chacha20poly1305_ietf_decrypt (m : ICS.chars_ptr; mlen_p : NaCl_uint64_Access; nsec : ICS.chars_ptr; c : ICS.chars_ptr; clen : NaCl_uint64; ad : ICS.chars_ptr; adlen : NaCl_uint64; npub : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_chacha20poly1305_ietf_decrypt); function crypto_aead_chacha20poly1305_ietf_encrypt_detached (c : ICS.chars_ptr; mac : ICS.chars_ptr; maclen_p : NaCl_uint64_Access; m : ICS.chars_ptr; mlen : NaCl_uint64; ad : ICS.chars_ptr; adlen : NaCl_uint64; nsec : ICS.chars_ptr; npub : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_chacha20poly1305_ietf_encrypt_detached); function crypto_aead_chacha20poly1305_ietf_decrypt_detached (m : ICS.chars_ptr; nsec : ICS.chars_ptr; c : ICS.chars_ptr; clen : NaCl_uint64; mac : ICS.chars_ptr; ad : ICS.chars_ptr; adlen : NaCl_uint64; npub : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_chacha20poly1305_ietf_decrypt_detached); --------------- -- AES-GCM -- --------------- function crypto_aead_aes256gcm_encrypt (c : ICS.chars_ptr; clen_p : NaCl_uint64_Access; m : ICS.chars_ptr; mlen : NaCl_uint64; ad : ICS.chars_ptr; adlen : NaCl_uint64; nsec : ICS.chars_ptr; npub : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_aes256gcm_encrypt); function crypto_aead_aes256gcm_decrypt (m : ICS.chars_ptr; mlen_p : NaCl_uint64_Access; nsec : ICS.chars_ptr; c : ICS.chars_ptr; clen : NaCl_uint64; ad : ICS.chars_ptr; adlen : NaCl_uint64; npub : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_aes256gcm_decrypt); function crypto_aead_aes256gcm_encrypt_detached (c : ICS.chars_ptr; mac : ICS.chars_ptr; maclen_p : NaCl_uint64_Access; m : ICS.chars_ptr; mlen : NaCl_uint64; ad : ICS.chars_ptr; adlen : NaCl_uint64; nsec : ICS.chars_ptr; npub : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_aes256gcm_encrypt_detached); function crypto_aead_aes256gcm_decrypt_detached (m : ICS.chars_ptr; nsec : ICS.chars_ptr; c : ICS.chars_ptr; clen : NaCl_uint64; mac : ICS.chars_ptr; ad : ICS.chars_ptr; adlen : NaCl_uint64; npub : ICS.chars_ptr; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_aes256gcm_decrypt_detached); ----------------------------------- -- AES-GCM with Precalculation -- ----------------------------------- function crypto_aead_aes256gcm_beforenm (ctx : crypto_aead_aes256gcm_state_Access; k : ICS.chars_ptr) return IC.int; pragma Import (C, crypto_aead_aes256gcm_beforenm); function crypto_aead_aes256gcm_encrypt_afternm (c : ICS.chars_ptr; clen_p : NaCl_uint64_Access; m : ICS.chars_ptr; mlen : NaCl_uint64; ad : ICS.chars_ptr; adlen : NaCl_uint64; nsec : ICS.chars_ptr; npub : ICS.chars_ptr; ctx : crypto_aead_aes256gcm_state_Access) return IC.int; pragma Import (C, crypto_aead_aes256gcm_encrypt_afternm); function crypto_aead_aes256gcm_decrypt_afternm (m : ICS.chars_ptr; mlen_p : NaCl_uint64_Access; nsec : ICS.chars_ptr; c : ICS.chars_ptr; clen : NaCl_uint64; ad : ICS.chars_ptr; adlen : NaCl_uint64; npub : ICS.chars_ptr; ctx : crypto_aead_aes256gcm_state_Access) return IC.int; pragma Import (C, crypto_aead_aes256gcm_decrypt_afternm); function crypto_aead_aes256gcm_encrypt_detached_afternm (c : ICS.chars_ptr; mac : ICS.chars_ptr; maclen_p : NaCl_uint64_Access; m : ICS.chars_ptr; mlen : NaCl_uint64; ad : ICS.chars_ptr; adlen : NaCl_uint64; nsec : ICS.chars_ptr; npub : ICS.chars_ptr; ctx : crypto_aead_aes256gcm_state_Access) return IC.int; pragma Import (C, crypto_aead_aes256gcm_encrypt_detached_afternm); function crypto_aead_aes256gcm_decrypt_detached_afternm (m : ICS.chars_ptr; nsec : ICS.chars_ptr; c : ICS.chars_ptr; clen : NaCl_uint64; mac : ICS.chars_ptr; ad : ICS.chars_ptr; adlen : NaCl_uint64; npub : ICS.chars_ptr; ctx : crypto_aead_aes256gcm_state_Access) return IC.int; pragma Import (C, crypto_aead_aes256gcm_decrypt_detached_afternm); ------------------------ -- AES Availability -- ------------------------ function crypto_aead_aes256gcm_is_available return IC.int; pragma Import (C, crypto_aead_aes256gcm_is_available); end Sodium.Thin_Binding;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- G N A T . C O M M A N D _ L I N E -- -- -- -- S p e c -- -- -- -- Copyright (C) 1999-2016, AdaCore -- -- -- -- 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 Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- High level package for command line parsing and manipulation ---------------------------------------- -- Simple Parsing of the Command Line -- ---------------------------------------- -- This package provides an interface for parsing command line arguments, -- when they are either read from Ada.Command_Line or read from a string list. -- As shown in the example below, one should first retrieve the switches -- (special command line arguments starting with '-' by default) and their -- parameters, and then the rest of the command line arguments. -- -- While it may appear easy to parse the command line arguments with -- Ada.Command_Line, there are in fact lots of special cases to handle in some -- applications. Those are fully managed by GNAT.Command_Line. Among these are -- switches with optional parameters, grouping switches (for instance "-ab" -- might mean the same as "-a -b"), various characters to separate a switch -- and its parameter (or none: "-a 1" and "-a1" are generally the same, which -- can introduce confusion with grouped switches),... -- -- begin -- loop -- case Getopt ("a b: ad") is -- Accepts '-a', '-ad', or '-b argument' -- when ASCII.NUL => exit; -- when 'a' => -- if Full_Switch = "a" then -- Put_Line ("Got a"); -- else -- Put_Line ("Got ad"); -- end if; -- when 'b' => Put_Line ("Got b + " & Parameter); -- when others => -- raise Program_Error; -- cannot occur -- end case; -- end loop; -- loop -- declare -- S : constant String := Get_Argument (Do_Expansion => True); -- begin -- exit when S'Length = 0; -- Put_Line ("Got " & S); -- end; -- end loop; -- exception -- when Invalid_Switch => Put_Line ("Invalid Switch " & Full_Switch); -- when Invalid_Parameter => Put_Line ("No parameter for " & Full_Switch); -- end; -------------- -- Sections -- -------------- -- A more complicated example would involve the use of sections for the -- switches, as for instance in gnatmake. The same command line is used to -- provide switches for several tools. Each tool recognizes its switches by -- separating them with special switches that act as section separators. -- Each section acts as a command line of its own. -- begin -- Initialize_Option_Scan ('-', False, "largs bargs cargs"); -- loop -- -- Same loop as above to get switches and arguments -- end loop; -- Goto_Section ("bargs"); -- loop -- -- Same loop as above to get switches and arguments -- -- The supported switches in Getopt might be different -- end loop; -- Goto_Section ("cargs"); -- loop -- -- Same loop as above to get switches and arguments -- -- The supported switches in Getopt might be different -- end loop; -- end; ------------------------------- -- Parsing a List of Strings -- ------------------------------- -- The examples above show how to parse the command line when the arguments -- are read directly from Ada.Command_Line. However, these arguments can also -- be read from a list of strings. This can be useful in several contexts, -- either because your system does not support Ada.Command_Line, or because -- you are manipulating other tools and creating their command lines by hand, -- or for any other reason. -- To create the list of strings, it is recommended to use -- GNAT.OS_Lib.Argument_String_To_List. -- The example below shows how to get the parameters from such a list. Note -- also the use of '*' to get all the switches, and not report errors when an -- unexpected switch was used by the user -- declare -- Parser : Opt_Parser; -- Args : constant Argument_List_Access := -- GNAT.OS_Lib.Argument_String_To_List ("-g -O1 -Ipath"); -- begin -- Initialize_Option_Scan (Parser, Args); -- while Getopt ("* g O! I=", Parser) /= ASCII.NUL loop -- Put_Line ("Switch " & Full_Switch (Parser) -- & " param=" & Parameter (Parser)); -- end loop; -- Free (Parser); -- end; ------------------------------------------- -- High-Level Command Line Configuration -- ------------------------------------------- -- As shown above, the code is still relatively low-level. For instance, there -- is no way to indicate which switches are related (thus if "-l" and "--long" -- should have the same effect, your code will need to test for both cases). -- Likewise, it is difficult to handle more advanced constructs, like: -- * Specifying -gnatwa is the same as specifying -gnatwu -gnatwv, but -- shorter and more readable -- * All switches starting with -gnatw can be grouped, for instance one -- can write -gnatwcd instead of -gnatwc -gnatwd. -- Of course, this can be combined with the above and -gnatwacd is the -- same as -gnatwc -gnatwd -gnatwu -gnatwv -- * The switch -T is the same as -gnatwAB (same as -gnatwA -gnatwB) -- With the above form of Getopt, you would receive "-gnatwa", "-T" or -- "-gnatwcd" in the examples above, and thus you require additional manual -- parsing of the switch. -- Instead, this package provides the type Command_Line_Configuration, which -- stores all the knowledge above. For instance: -- Config : Command_Line_Configuration; -- Define_Alias (Config, "-gnatwa", "-gnatwu -gnatwv"); -- Define_Prefix (Config, "-gnatw"); -- Define_Alias (Config, "-T", "-gnatwAB"); -- You then need to specify all possible switches in your application by -- calling Define_Switch, for instance: -- Define_Switch (Config, "-gnatwu", Help => "warn on unused entities"); -- Define_Switch (Config, "-gnatwv", Help => "warn on unassigned var"); -- ... -- Specifying the help message is optional, but makes it easy to then call -- the function: -- Display_Help (Config); -- that will display a properly formatted help message for your application, -- listing all possible switches. That way you have a single place in which -- to maintain the list of switches and their meaning, rather than maintaining -- both the string to pass to Getopt and a subprogram to display the help. -- Both will properly stay synchronized. -- Once you have this Config, you just have to call: -- Getopt (Config, Callback'Access); -- to parse the command line. The Callback will be called for each switch -- found on the command line (in the case of our example, that is "-gnatwu" -- and then "-gnatwv", not "-gnatwa" itself). This simplifies command line -- parsing a lot. -- In fact, this can be further automated for the most command case where the -- parameter passed to a switch is stored in a variable in the application. -- When a switch is defined, you only have to indicate where to store the -- value, and let Getopt do the rest. For instance: -- Optimization : aliased Integer; -- Verbose : aliased Boolean; -- Define_Switch (Config, Verbose'Access, -- "-v", Long_Switch => "--verbose", -- Help => "Output extra verbose information"); -- Define_Switch (Config, Optimization'Access, -- "-O?", Help => "Optimization level"); -- Getopt (Config); -- No callback -- Since all switches are handled automatically, we don't even need to pass -- a callback to Getopt. Once getopt has been called, the two variables -- Optimization and Verbose have been properly initialized, either to the -- default value or to the value found on the command line. ------------------------------------------------ -- Creating and Manipulating the Command Line -- ------------------------------------------------ -- This package provides mechanisms to create and modify command lines by -- adding or removing arguments from them. The resulting command line is kept -- as short as possible by coalescing arguments whenever possible. -- Complex command lines can thus be constructed, for example from a GUI -- (although this package does not by itself depend upon any specific GUI -- toolkit). -- Using the configuration defined earlier, one can then construct a command -- line for the tool with: -- Cmd : Command_Line; -- Set_Configuration (Cmd, Config); -- Config created earlier -- Add_Switch (Cmd, "-bar"); -- Add_Switch (Cmd, "-gnatwu"); -- Add_Switch (Cmd, "-gnatwv"); -- will be grouped with the above -- Add_Switch (Cmd, "-T"); -- The resulting command line can be iterated over to get all its switches, -- There are two modes for this iteration: either you want to get the -- shortest possible command line, which would be: -- -bar -gnatwaAB -- or on the other hand you want each individual switch (so that your own -- tool does not have to do further complex processing), which would be: -- -bar -gnatwu -gnatwv -gnatwA -gnatwB -- Of course, we can assume that the tool you want to spawn would understand -- both of these, since they are both compatible with the description we gave -- above. However, the first result is useful if you want to show the user -- what you are spawning (since that keeps the output shorter), and the second -- output is more useful for a tool that would check whether -gnatwu was -- passed (which isn't obvious in the first output). Likewise, the second -- output is more useful if you have a graphical interface since each switch -- can be associated with a widget, and you immediately know whether -gnatwu -- was selected. -- -- Some command line arguments can have parameters, which on a command line -- appear as a separate argument that must immediately follow the switch. -- Since the subprograms in this package will reorganize the switches to group -- them, you need to indicate what is a command line parameter, and what is a -- switch argument. -- This is done by passing an extra argument to Add_Switch, as in: -- Add_Switch (Cmd, "-foo", Parameter => "arg1"); -- This ensures that "arg1" will always be treated as the argument to -foo, -- and will not be grouped with other parts of the command line. with Ada.Command_Line; with GNAT.Directory_Operations; with GNAT.OS_Lib; with GNAT.Regexp; with GNAT.Strings; package GNAT.Command_Line is ------------- -- Parsing -- ------------- type Opt_Parser is private; Command_Line_Parser : constant Opt_Parser; -- This object is responsible for parsing a list of arguments, which by -- default are the standard command line arguments from Ada.Command_Line. -- This is really a pointer to actual data, which must therefore be -- initialized through a call to Initialize_Option_Scan, and must be freed -- with a call to Free. -- -- As a special case, Command_Line_Parser does not need to be either -- initialized or free-ed. procedure Initialize_Option_Scan (Switch_Char : Character := '-'; Stop_At_First_Non_Switch : Boolean := False; Section_Delimiters : String := ""); procedure Initialize_Option_Scan (Parser : out Opt_Parser; Command_Line : GNAT.OS_Lib.Argument_List_Access; Switch_Char : Character := '-'; Stop_At_First_Non_Switch : Boolean := False; Section_Delimiters : String := ""); -- The first procedure resets the internal state of the package to prepare -- to rescan the parameters. It does not need to be called before the -- first use of Getopt (but it could be), but it must be called if you -- want to start rescanning the command line parameters from the start. -- The optional parameter Switch_Char can be used to reset the switch -- character, e.g. to '/' for use in DOS-like systems. -- -- The second subprogram initializes a parser that takes its arguments -- from an array of strings rather than directly from the command line. In -- this case, the parser is responsible for freeing the strings stored in -- Command_Line. If you pass null to Command_Line, this will in fact create -- a second parser for Ada.Command_Line, which doesn't share any data with -- the default parser. This parser must be free'ed. -- -- The optional parameter Stop_At_First_Non_Switch indicates if Getopt is -- to look for switches on the whole command line, or if it has to stop as -- soon as a non-switch argument is found. -- -- Example: -- -- Arguments: my_application file1 -c -- -- If Stop_At_First_Non_Switch is False, then -c will be considered -- as a switch (returned by getopt), otherwise it will be considered -- as a normal argument (returned by Get_Argument). -- -- If Section_Delimiters is set, then every following subprogram -- (Getopt and Get_Argument) will only operate within a section, which -- is delimited by any of these delimiters or the end of the command line. -- -- Example: -- Initialize_Option_Scan (Section_Delimiters => "largs bargs cargs"); -- -- Arguments on command line : my_application -c -bargs -d -e -largs -f -- This line contains three sections, the first one is the default one -- and includes only the '-c' switch, the second one is between -bargs -- and -largs and includes '-d -e' and the last one includes '-f'. procedure Free (Parser : in out Opt_Parser); -- Free the memory used by the parser. Calling this is not mandatory for -- the Command_Line_Parser procedure Goto_Section (Name : String := ""; Parser : Opt_Parser := Command_Line_Parser); -- Change the current section. The next Getopt or Get_Argument will start -- looking at the beginning of the section. An empty name ("") refers to -- the first section between the program name and the first section -- delimiter. If the section does not exist in Section_Delimiters, then -- Invalid_Section is raised. If the section does not appear on the command -- line, then it is treated as an empty section. function Full_Switch (Parser : Opt_Parser := Command_Line_Parser) return String; -- Returns the full name of the last switch found (Getopt only returns the -- first character). Does not include the Switch_Char ('-' by default), -- unless the "*" option of Getopt is used (see below). function Current_Section (Parser : Opt_Parser := Command_Line_Parser) return String; -- Return the name of the current section. -- The list of valid sections is defined through Initialize_Option_Scan function Getopt (Switches : String; Concatenate : Boolean := True; Parser : Opt_Parser := Command_Line_Parser) return Character; -- This function moves to the next switch on the command line (defined as -- switch character followed by a character within Switches, casing being -- significant). The result returned is the first character of the switch -- that is located. If there are no more switches in the current section, -- returns ASCII.NUL. If Concatenate is True (the default), the switches do -- not need to be separated by spaces (they can be concatenated if they do -- not require an argument, e.g. -ab is the same as two separate arguments -- -a -b). -- -- Switches is a string of all the possible switches, separated by -- spaces. A switch can be followed by one of the following characters: -- -- ':' The switch requires a parameter. There can optionally be a space -- on the command line between the switch and its parameter. -- -- '=' The switch requires a parameter. There can either be a '=' or a -- space on the command line between the switch and its parameter. -- -- '!' The switch requires a parameter, but there can be no space on the -- command line between the switch and its parameter. -- -- '?' The switch may have an optional parameter. There can be no space -- between the switch and its argument. -- -- e.g. if Switches has the following value : "a? b", -- The command line can be: -- -- -afoo : -a switch with 'foo' parameter -- -a foo : -a switch and another element on the -- command line 'foo', returned by Get_Argument -- -- Example: if Switches is "-a: -aO:", you can have the following -- command lines: -- -- -aarg : 'a' switch with 'arg' parameter -- -a arg : 'a' switch with 'arg' parameter -- -aOarg : 'aO' switch with 'arg' parameter -- -aO arg : 'aO' switch with 'arg' parameter -- -- Example: -- -- Getopt ("a b: ac ad?") -- -- accept either 'a' or 'ac' with no argument, -- accept 'b' with a required argument -- accept 'ad' with an optional argument -- -- If the first item in switches is '*', then Getopt will catch -- every element on the command line that was not caught by any other -- switch. The character returned by GetOpt is '*', but Full_Switch -- contains the full command line argument, including leading '-' if there -- is one. If this character was not returned, there would be no way of -- knowing whether it is there or not. -- -- Example -- Getopt ("* a b") -- If the command line is '-a -c toto.o -b', Getopt will return -- successively 'a', '*', '*' and 'b', with Full_Switch returning -- "a", "-c", "toto.o", and "b". -- -- When Getopt encounters an invalid switch, it raises the exception -- Invalid_Switch and sets Full_Switch to return the invalid switch. -- When Getopt cannot find the parameter associated with a switch, it -- raises Invalid_Parameter, and sets Full_Switch to return the invalid -- switch. -- -- Note: in case of ambiguity, e.g. switches a ab abc, then the longest -- matching switch is returned. -- -- Arbitrary characters are allowed for switches, although it is -- strongly recommended to use only letters and digits for portability -- reasons. -- -- When Concatenate is False, individual switches need to be separated by -- spaces. -- -- Example -- Getopt ("a b", Concatenate => False) -- If the command line is '-ab', exception Invalid_Switch will be -- raised and Full_Switch will return "ab". function Get_Argument (Do_Expansion : Boolean := False; Parser : Opt_Parser := Command_Line_Parser) return String; -- Returns the next element on the command line that is not a switch. This -- function should not be called before Getopt has returned ASCII.NUL. -- -- If Do_Expansion is True, then the parameter on the command line will -- be considered as a filename with wild cards, and will be expanded. The -- matching file names will be returned one at a time. This is useful in -- non-Unix systems for obtaining normal expansion of wild card references. -- When there are no more arguments on the command line, this function -- returns an empty string. function Parameter (Parser : Opt_Parser := Command_Line_Parser) return String; -- Returns parameter associated with the last switch returned by Getopt. -- If no parameter was associated with the last switch, or no previous call -- has been made to Get_Argument, raises Invalid_Parameter. If the last -- switch was associated with an optional argument and this argument was -- not found on the command line, Parameter returns an empty string. function Separator (Parser : Opt_Parser := Command_Line_Parser) return Character; -- The separator that was between the switch and its parameter. This is -- useful if you want to know exactly what was on the command line. This -- is in general a single character, set to ASCII.NUL if the switch and -- the parameter were concatenated. A space is returned if the switch and -- its argument were in two separate arguments. Invalid_Section : exception; -- Raised when an invalid section is selected by Goto_Section Invalid_Switch : exception; -- Raised when an invalid switch is detected in the command line Invalid_Parameter : exception; -- Raised when a parameter is missing, or an attempt is made to obtain a -- parameter for a switch that does not allow a parameter. ----------------------------------------- -- Expansion of command line arguments -- ----------------------------------------- -- These subprograms take care of expanding globbing patterns on the -- command line. On Unix, such expansion is done by the shell before your -- application is called. But on Windows you must do this expansion -- yourself. type Expansion_Iterator is limited private; -- Type used during expansion of file names procedure Start_Expansion (Iterator : out Expansion_Iterator; Pattern : String; Directory : String := ""; Basic_Regexp : Boolean := True); -- Initialize a wild card expansion. The next calls to Expansion will -- return the next file name in Directory which match Pattern (Pattern -- is a regular expression, using only the Unix shell and DOS syntax if -- Basic_Regexp is True). When Directory is an empty string, the current -- directory is searched. -- -- Pattern may contain directory separators (as in "src/*/*.ada"). -- Subdirectories of Directory will also be searched, up to one -- hundred levels deep. -- -- When Start_Expansion has been called, function Expansion should -- be called repeatedly until it returns an empty string, before -- Start_Expansion can be called again with the same Expansion_Iterator -- variable. function Expansion (Iterator : Expansion_Iterator) return String; -- Returns the next file in the directory matching the parameters given -- to Start_Expansion and updates Iterator to point to the next entry. -- Returns an empty string when there are no more files. -- -- If Expansion is called again after an empty string has been returned, -- then the exception GNAT.Directory_Operations.Directory_Error is raised. ----------------- -- Configuring -- ----------------- -- The following subprograms are used to manipulate a command line -- represented as a string (for instance "-g -O2"), as well as parsing -- the switches from such a string. They provide high-level configurations -- to define aliases (a switch is equivalent to one or more other switches) -- or grouping of switches ("-gnatyac" is equivalent to "-gnatya" and -- "-gnatyc"). -- See the top of this file for examples on how to use these subprograms type Command_Line_Configuration is private; procedure Define_Section (Config : in out Command_Line_Configuration; Section : String); -- Indicates a new switch section. All switches belonging to the same -- section are ordered together, preceded by the section. They are placed -- at the end of the command line (as in "gnatmake somefile.adb -cargs -g") -- -- The section name should not include the leading '-'. So for instance in -- the case of gnatmake we would use: -- -- Define_Section (Config, "cargs"); -- Define_Section (Config, "bargs"); procedure Define_Alias (Config : in out Command_Line_Configuration; Switch : String; Expanded : String; Section : String := ""); -- Indicates that whenever Switch appears on the command line, it should -- be expanded as Expanded. For instance, for the GNAT compiler switches, -- we would define "-gnatwa" as an alias for "-gnatwcfijkmopruvz", ie some -- default warnings to be activated. -- -- This expansion is only done within the specified section, which must -- have been defined first through a call to [Define_Section]. procedure Define_Prefix (Config : in out Command_Line_Configuration; Prefix : String); -- Indicates that all switches starting with the given prefix should be -- grouped. For instance, for the GNAT compiler we would define "-gnatw" as -- a prefix, so that "-gnatwu -gnatwv" can be grouped into "-gnatwuv" It is -- assumed that the remainder of the switch ("uv") is a set of characters -- whose order is irrelevant. In fact, this package will sort them -- alphabetically. -- -- When grouping switches that accept arguments (for instance "-gnatyL!" -- as the definition, and "-gnatyaL12b" as the command line), only -- numerical arguments are accepted. The above is equivalent to -- "-gnatya -gnatyL12 -gnatyb". procedure Define_Switch (Config : in out Command_Line_Configuration; Switch : String := ""; Long_Switch : String := ""; Help : String := ""; Section : String := ""; Argument : String := "ARG"); -- Indicates a new switch. The format of this switch follows the getopt -- format (trailing ':', '?', etc for defining a switch with parameters). -- -- Switch should also start with the leading '-' (or any other characters). -- If this character is not '-', you need to call Initialize_Option_Scan to -- set the proper character for the parser. -- -- The switches defined in the command_line_configuration object are used -- when ungrouping switches with more that one character after the prefix. -- -- Switch and Long_Switch (when specified) are aliases and can be used -- interchangeably. There is no check that they both take an argument or -- both take no argument. Switch can be set to "*" to indicate that any -- switch is supported (in which case Getopt will return '*', see its -- documentation). -- -- Help is used by the Display_Help procedure to describe the supported -- switches. -- -- In_Section indicates in which section the switch is valid (you need to -- first define the section through a call to Define_Section). -- -- Argument is the name of the argument, as displayed in the automatic -- help message. It is always capitalized for consistency. procedure Define_Switch (Config : in out Command_Line_Configuration; Output : access Boolean; Switch : String := ""; Long_Switch : String := ""; Help : String := ""; Section : String := ""; Value : Boolean := True); -- See Define_Switch for a description of the parameters. -- When the switch is found on the command line, Getopt will set -- Output.all to Value. -- -- Output is always initially set to "not Value", so that if the switch is -- not found on the command line, Output still has a valid value. -- The switch must not take any parameter. -- -- Output must exist at least as long as Config, otherwise an erroneous -- memory access may occur. procedure Define_Switch (Config : in out Command_Line_Configuration; Output : access Integer; Switch : String := ""; Long_Switch : String := ""; Help : String := ""; Section : String := ""; Initial : Integer := 0; Default : Integer := 1; Argument : String := "ARG"); -- See Define_Switch for a description of the parameters. When the -- switch is found on the command line, Getopt will set Output.all to the -- value of the switch's parameter. If the parameter is not an integer, -- Invalid_Parameter is raised. -- Output is always initialized to Initial. If the switch has an optional -- argument which isn't specified by the user, then Output will be set to -- Default. The switch must accept an argument. procedure Define_Switch (Config : in out Command_Line_Configuration; Output : access GNAT.Strings.String_Access; Switch : String := ""; Long_Switch : String := ""; Help : String := ""; Section : String := ""; Argument : String := "ARG"); -- Set Output to the value of the switch's parameter when the switch is -- found on the command line. Output is always initialized to the empty -- string if it does not have a value already (otherwise it is left as is -- so that you can specify the default value directly in the declaration -- of the variable). The switch must accept an argument. procedure Set_Usage (Config : in out Command_Line_Configuration; Usage : String := "[switches] [arguments]"; Help : String := ""; Help_Msg : String := ""); -- Defines the general format of the call to the application, and a short -- help text. These are both displayed by Display_Help. When a non-empty -- Help_Msg is given, it is used by Display_Help instead of the -- automatically generated list of supported switches. procedure Display_Help (Config : Command_Line_Configuration); -- Display the help for the tool (ie its usage, and its supported switches) function Get_Switches (Config : Command_Line_Configuration; Switch_Char : Character := '-'; Section : String := "") return String; -- Get the switches list as expected by Getopt, for a specific section of -- the command line. This list is built using all switches defined -- previously via Define_Switch above. function Section_Delimiters (Config : Command_Line_Configuration) return String; -- Return a string suitable for use in Initialize_Option_Scan procedure Free (Config : in out Command_Line_Configuration); -- Free the memory used by Config type Switch_Handler is access procedure (Switch : String; Parameter : String; Section : String); -- Called when a switch is found on the command line. Switch includes -- any leading '-' that was specified in Define_Switch. This is slightly -- different from the functional version of Getopt above, for which -- Full_Switch omits the first leading '-'. Exit_From_Command_Line : exception; -- Emitted when the program should exit. This is called when Getopt below -- has seen -h, --help or an invalid switch. procedure Getopt (Config : Command_Line_Configuration; Callback : Switch_Handler := null; Parser : Opt_Parser := Command_Line_Parser; Concatenate : Boolean := True); -- Similar to the standard Getopt function. For each switch found on the -- command line, this calls Callback, if the switch is not handled -- automatically. -- -- The list of valid switches are the ones from the configuration. The -- switches that were declared through Define_Switch with an Output -- parameter are never returned (and result in a modification of the Output -- variable). This function will in fact never call [Callback] if all -- switches were handled automatically and there is nothing left to do. -- -- The option Concatenate is identical to the one of the standard Getopt -- function. -- -- This procedure automatically adds -h and --help to the valid switches, -- to display the help message and raises Exit_From_Command_Line. -- If an invalid switch is specified on the command line, this procedure -- will display an error message and raises Invalid_Switch again. -- -- This function automatically expands switches: -- -- If Define_Prefix was called (for instance "-gnaty") and the user -- specifies "-gnatycb" on the command line, then Getopt returns -- "-gnatyc" and "-gnatyb" separately. -- -- If Define_Alias was called (for instance "-gnatya = -gnatycb") then -- the latter is returned (in this case it also expands -gnaty as per -- the above. -- -- The goal is to make handling as easy as possible by leaving as much -- work as possible to this package. -- -- As opposed to the standard Getopt, this one will analyze all sections -- as defined by Define_Section, and automatically jump from one section to -- the next. ------------------------------ -- Generating command lines -- ------------------------------ -- Once the command line configuration has been created, you can build your -- own command line. This will be done in general because you need to spawn -- external tools from your application. -- Although it could be done by concatenating strings, the following -- subprograms will properly take care of grouping switches when possible, -- so as to keep the command line as short as possible. They also provide a -- way to remove a switch from an existing command line. -- For instance: -- declare -- Config : Command_Line_Configuration; -- Line : Command_Line; -- Args : Argument_List_Access; -- begin -- Define_Switch (Config, "-gnatyc"); -- Define_Switch (Config, ...); -- for all valid switches -- Define_Prefix (Config, "-gnaty"); -- Set_Configuration (Line, Config); -- Add_Switch (Line, "-O2"); -- Add_Switch (Line, "-gnatyc"); -- Add_Switch (Line, "-gnatyd"); -- -- Build (Line, Args); -- -- Args is now ["-O2", "-gnatycd"] -- end; type Command_Line is private; procedure Set_Configuration (Cmd : in out Command_Line; Config : Command_Line_Configuration); function Get_Configuration (Cmd : Command_Line) return Command_Line_Configuration; -- Set or retrieve the configuration used for that command line. The Config -- must have been initialized first, by calling one of the Define_Switches -- subprograms. procedure Set_Command_Line (Cmd : in out Command_Line; Switches : String; Getopt_Description : String := ""; Switch_Char : Character := '-'); -- Set the new content of the command line, by replacing the current -- version with Switches. -- -- The parsing of Switches is done through calls to Getopt, by passing -- Getopt_Description as an argument. (A "*" is automatically prepended so -- that all switches and command line arguments are accepted). If a config -- was defined via Set_Configuration, the Getopt_Description parameter will -- be ignored. -- -- To properly handle switches that take parameters, you should document -- them in Getopt_Description. Otherwise, the switch and its parameter will -- be recorded as two separate command line arguments as returned by a -- Command_Line_Iterator (which might be fine depending on your -- application). -- -- If the command line has sections (such as -bargs -cargs), then they -- should be listed in the Sections parameter (as "-bargs -cargs"). -- -- This function can be used to reset Cmd by passing an empty string -- -- If an invalid switch is found on the command line (ie wasn't defined in -- the configuration via Define_Switch), and the configuration wasn't set -- to accept all switches (by defining "*" as a valid switch), then an -- exception Invalid_Switch is raised. The exception message indicates the -- invalid switch. procedure Add_Switch (Cmd : in out Command_Line; Switch : String; Parameter : String := ""; Separator : Character := ASCII.NUL; Section : String := ""; Add_Before : Boolean := False); -- Add a new switch to the command line, and combine/group it with existing -- switches if possible. Nothing is done if the switch already exists with -- the same parameter. -- -- If the Switch takes a parameter, the latter should be specified -- separately, so that the association between the two is always correctly -- recognized even if the order of switches on the command line changes. -- For instance, you should pass "--check=full" as ("--check", "full") so -- that Remove_Switch below can simply take "--check" in parameter. That -- will automatically remove "full" as well. The value of the parameter is -- never modified by this package. -- -- On the other hand, you could decide to simply pass "--check=full" as -- the Switch above, and then pass no parameter. This means that you need -- to pass "--check=full" to Remove_Switch as well. -- -- A Switch with a parameter will never be grouped with another switch to -- avoid ambiguities as to what the parameter applies to. -- -- If the switch is part of a section, then it should be specified so that -- the switch is correctly placed in the command line, and the section -- added if not already present. For example, to add the -g switch into the -- -cargs section, you need to call (Cmd, "-g", Section => "-cargs"). -- -- [Separator], if specified, overrides the separator that was defined -- through Define_Switch. For instance, if the switch was defined as -- "-from:", the separator defaults to a space. But if your application -- uses unusual separators not supported by GNAT.Command_Line (for instance -- it requires ":"), you can specify this separator here. -- -- For instance, -- Add_Switch(Cmd, "-from", "bar", ':') -- -- results in -- -from:bar -- -- rather than the default -- -from bar -- -- Note however that Getopt doesn't know how to handle ":" as a separator. -- So the recommendation is to declare the switch as "-from!" (ie no -- space between the switch and its parameter). Then Getopt will return -- ":bar" as the parameter, and you can trim the ":" in your application. -- -- Invalid_Section is raised if Section was not defined in the -- configuration of the command line. -- -- Add_Before allows insertion of the switch at the beginning of the -- command line. procedure Add_Switch (Cmd : in out Command_Line; Switch : String; Parameter : String := ""; Separator : Character := ASCII.NUL; Section : String := ""; Add_Before : Boolean := False; Success : out Boolean); -- Same as above, returning the status of the operation procedure Remove_Switch (Cmd : in out Command_Line; Switch : String; Remove_All : Boolean := False; Has_Parameter : Boolean := False; Section : String := ""); -- Remove Switch from the command line, and ungroup existing switches if -- necessary. -- -- The actual parameter to the switches are ignored. If for instance -- you are removing "-foo", then "-foo param1" and "-foo param2" can -- be removed. -- -- If Remove_All is True, then all matching switches are removed, otherwise -- only the first matching one is removed. -- -- If Has_Parameter is set to True, then only switches having a parameter -- are removed. -- -- If the switch belongs to a section, then this section should be -- specified: Remove_Switch (Cmd_Line, "-g", Section => "-cargs") called -- on the command line "-g -cargs -g" will result in "-g", while if -- called with (Cmd_Line, "-g") this will result in "-cargs -g". -- If Remove_All is set, then both "-g" will be removed. procedure Remove_Switch (Cmd : in out Command_Line; Switch : String; Remove_All : Boolean := False; Has_Parameter : Boolean := False; Section : String := ""; Success : out Boolean); -- Same as above, reporting the success of the operation (Success is False -- if no switch was removed). procedure Remove_Switch (Cmd : in out Command_Line; Switch : String; Parameter : String; Section : String := ""); -- Remove a switch with a specific parameter. If Parameter is the empty -- string, then only a switch with no parameter will be removed. procedure Free (Cmd : in out Command_Line); -- Free the memory used by Cmd --------------- -- Iteration -- --------------- -- When a command line was created with the above, you can then iterate -- over its contents using the following iterator. type Command_Line_Iterator is private; procedure Start (Cmd : in out Command_Line; Iter : in out Command_Line_Iterator; Expanded : Boolean := False); -- Start iterating over the command line arguments. If Expanded is true, -- then the arguments are not grouped and no alias is used. For instance, -- "-gnatwv" and "-gnatwu" would be returned instead of "-gnatwuv". -- -- The iterator becomes invalid if the command line is changed through a -- call to Add_Switch, Remove_Switch or Set_Command_Line. function Current_Switch (Iter : Command_Line_Iterator) return String; function Is_New_Section (Iter : Command_Line_Iterator) return Boolean; function Current_Section (Iter : Command_Line_Iterator) return String; function Current_Separator (Iter : Command_Line_Iterator) return String; function Current_Parameter (Iter : Command_Line_Iterator) return String; -- Return the current switch and its parameter (or the empty string if -- there is no parameter or the switch was added through Add_Switch -- without specifying the parameter. -- -- Separator is the string that goes between the switch and its separator. -- It could be the empty string if they should be concatenated, or a space -- for instance. When printing, you should not add any other character. function Has_More (Iter : Command_Line_Iterator) return Boolean; -- Return True if there are more switches to be returned procedure Next (Iter : in out Command_Line_Iterator); -- Move to the next switch procedure Build (Line : in out Command_Line; Args : out GNAT.OS_Lib.Argument_List_Access; Expanded : Boolean := False; Switch_Char : Character := '-'); -- This is a wrapper using the Command_Line_Iterator. It provides a simple -- way to get all switches (grouped as much as possible), and possibly -- create an Opt_Parser. -- -- Args must be freed by the caller. -- -- Expanded has the same meaning as in Start. procedure Try_Help; -- Output a message on standard error to indicate how to get the usage for -- the executable. This procedure should only be called when the executable -- accepts switch --help. When this procedure is called by executable xxx, -- the following message is displayed on standard error: -- try "xxx --help" for more information. private Max_Depth : constant := 100; -- Maximum depth of subdirectories Max_Path_Length : constant := 1024; -- Maximum length of relative path type Depth is range 1 .. Max_Depth; type Level is record Name_Last : Natural := 0; Dir : GNAT.Directory_Operations.Dir_Type; end record; type Level_Array is array (Depth) of Level; type Section_Number is new Natural range 0 .. 65534; for Section_Number'Size use 16; type Parameter_Type is record Arg_Num : Positive; First : Positive; Last : Natural; Extra : Character; end record; type Is_Switch_Type is array (Natural range <>) of Boolean; pragma Pack (Is_Switch_Type); type Section_Type is array (Natural range <>) of Section_Number; pragma Pack (Section_Type); type Expansion_Iterator is limited record Start : Positive := 1; -- Position of the first character of the relative path to check against -- the pattern. Dir_Name : String (1 .. Max_Path_Length); Current_Depth : Depth := 1; Levels : Level_Array; Regexp : GNAT.Regexp.Regexp; -- Regular expression built with the pattern Maximum_Depth : Depth := 1; -- The maximum depth of directories, reflecting the number of directory -- separators in the pattern. end record; type Opt_Parser_Data (Arg_Count : Natural) is record Arguments : GNAT.OS_Lib.Argument_List_Access; -- null if reading from the command line The_Parameter : Parameter_Type; The_Separator : Character; The_Switch : Parameter_Type; -- This type and this variable are provided to store the current switch -- and parameter. Is_Switch : Is_Switch_Type (1 .. Arg_Count) := (others => False); -- Indicates wich arguments on the command line are considered not be -- switches or parameters to switches (leaving e.g. filenames,...) Section : Section_Type (1 .. Arg_Count) := (others => 1); -- Contains the number of the section associated with the current -- switch. If this number is 0, then it is a section delimiter, which is -- never returned by GetOpt. Current_Argument : Natural := 1; -- Number of the current argument parsed on the command line Current_Index : Natural := 1; -- Index in the current argument of the character to be processed Current_Section : Section_Number := 1; Expansion_It : aliased Expansion_Iterator; -- When Get_Argument is expanding a file name, this is the iterator used In_Expansion : Boolean := False; -- True if we are expanding a file Switch_Character : Character := '-'; -- The character at the beginning of the command line arguments, -- indicating the beginning of a switch. Stop_At_First : Boolean := False; -- If it is True then Getopt stops at the first non-switch argument end record; Command_Line_Parser_Data : aliased Opt_Parser_Data (Ada.Command_Line.Argument_Count); -- The internal data used when parsing the command line type Opt_Parser is access all Opt_Parser_Data; Command_Line_Parser : constant Opt_Parser := Command_Line_Parser_Data'Access; type Switch_Type is (Switch_Untyped, Switch_Boolean, Switch_Integer, Switch_String); type Switch_Definition (Typ : Switch_Type := Switch_Untyped) is record Switch : GNAT.OS_Lib.String_Access; Long_Switch : GNAT.OS_Lib.String_Access; Section : GNAT.OS_Lib.String_Access; Help : GNAT.OS_Lib.String_Access; Argument : GNAT.OS_Lib.String_Access; -- null if "ARG". -- Name of the argument for this switch. case Typ is when Switch_Untyped => null; when Switch_Boolean => Boolean_Output : access Boolean; Boolean_Value : Boolean; -- will set Output to that value when Switch_Integer => Integer_Output : access Integer; Integer_Initial : Integer; Integer_Default : Integer; when Switch_String => String_Output : access GNAT.Strings.String_Access; end case; end record; type Switch_Definitions is array (Natural range <>) of Switch_Definition; type Switch_Definitions_List is access all Switch_Definitions; -- [Switch] includes the leading '-' type Alias_Definition is record Alias : GNAT.OS_Lib.String_Access; Expansion : GNAT.OS_Lib.String_Access; Section : GNAT.OS_Lib.String_Access; end record; type Alias_Definitions is array (Natural range <>) of Alias_Definition; type Alias_Definitions_List is access all Alias_Definitions; type Command_Line_Configuration_Record is record Prefixes : GNAT.OS_Lib.Argument_List_Access; -- The list of prefixes Sections : GNAT.OS_Lib.Argument_List_Access; -- The list of sections Star_Switch : Boolean := False; -- Whether switches not described in this configuration should be -- returned to the user (True). If False, an exception Invalid_Switch -- is raised. Aliases : Alias_Definitions_List; Usage : GNAT.OS_Lib.String_Access; Help : GNAT.OS_Lib.String_Access; Help_Msg : GNAT.OS_Lib.String_Access; Switches : Switch_Definitions_List; -- List of expected switches (Used when expanding switch groups) end record; type Command_Line_Configuration is access Command_Line_Configuration_Record; type Command_Line is record Config : Command_Line_Configuration; Expanded : GNAT.OS_Lib.Argument_List_Access; Params : GNAT.OS_Lib.Argument_List_Access; -- Parameter for the corresponding switch in Expanded. The first -- character is the separator (or ASCII.NUL if there is no separator). Sections : GNAT.OS_Lib.Argument_List_Access; -- The list of sections Coalesce : GNAT.OS_Lib.Argument_List_Access; Coalesce_Params : GNAT.OS_Lib.Argument_List_Access; Coalesce_Sections : GNAT.OS_Lib.Argument_List_Access; -- Cached version of the command line. This is recomputed every time -- the command line changes. Switches are grouped as much as possible, -- and aliases are used to reduce the length of the command line. The -- parameters are not allocated, they point into Params, so they must -- not be freed. end record; type Command_Line_Iterator is record List : GNAT.OS_Lib.Argument_List_Access; Sections : GNAT.OS_Lib.Argument_List_Access; Params : GNAT.OS_Lib.Argument_List_Access; Current : Natural; end record; end GNAT.Command_Line;
with Trendy_Test.Generics; generic type T is (<>); package Trendy_Test.Assertions.Discrete is -- Defaults all operations to what is visible. procedure Assert_EQ is new Trendy_Test.Generics.Assert_Discrete (T, "=", "="); procedure Assert_NE is new Trendy_Test.Generics.Assert_Discrete (T, "/=", "/="); procedure Assert_LT is new Trendy_Test.Generics.Assert_Discrete (T, "<", "<"); procedure Assert_GT is new Trendy_Test.Generics.Assert_Discrete (T, ">", ">"); procedure Assert_LE is new Trendy_Test.Generics.Assert_Discrete (T, "<=", "<="); procedure Assert_GE is new Trendy_Test.Generics.Assert_Discrete (T, ">=", ">="); end Trendy_Test.Assertions.Discrete;
-- Mojang API -- No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) -- -- OpenAPI spec version: 2020_06_05 -- -- -- NOTE: This package is auto generated by the swagger code generator 3.3.4. -- https://openapi-generator.tech -- Do not edit the class manually. with Swagger.Streams; package body com.github.asyncmc.mojang.status.ada.model.Clients is -- Checks the Mojang service statuses procedure Check_Statuses (Client : in out Client_Type; Result : out Swagger.com.github.asyncmc.mojang.status.ada.model.Models.ApiStatus_Type_Map_Vectors.Vector) is URI : Swagger.Clients.URI_Type; Reply : Swagger.Value_Type; begin Client.Set_Accept ((1 => Swagger.Clients.APPLICATION_JSON)); URI.Set_Path ("/check"); Client.Call (Swagger.Clients.GET, URI, Reply); com.github.asyncmc.mojang.status.ada.model.Models.Deserialize (Reply, "", Result); end Check_Statuses; end com.github.asyncmc.mojang.status.ada.model.Clients;
with Ada.Text_IO; use Ada.Text_IO; package body Generic_List.Output is procedure Print (List : List_T) is begin null; end Print; end Generic_List.Output;
----------------------------------------------------------------------- -- auth_cb -- Authentication callback examples -- Copyright (C) 2013 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with AWS.Response; with AWS.Status; with Util.Properties; with Security.Auth; package Auth_CB is -- Implement the first step of authentication: discover the OpenID (if any) provider, -- create the authorization request and redirect the user to the authorization server. -- Some authorization data is saved in the session for the verify process. -- The authorization provider is defined according to the base URI which is configured -- by the <tt>Auth_Config</tt> properties. The following names are recognized: -- -- google yahoo orange facebook -- -- Each authorization provider has its own set of configuration parameter which defines -- what implementation to use (OpenID or OAuth) and how to configure and connect -- to the server. The google, yahoo and orange map to the <tt>openid</tt> implementation. -- The facebook maps to the <tt>facebook</tt> implementation (based on OAuth). function Get_Authorization (Request : in AWS.Status.Data) return AWS.Response.Data; -- Second step of authentication: verify the authorization response. The authorization -- data saved in the session is extracted and checked against the response. If it matches -- the response is verified to check if the authentication succeeded or not. -- The user is then redirected to the success page. function Verify_Authorization (Request : in AWS.Status.Data) return AWS.Response.Data; -- Display information about the current user. function User_Info (Request : in AWS.Status.Data) return AWS.Response.Data; type Auth_Config is new Util.Properties.Manager and Security.Auth.Parameters with null record; overriding function Get_Parameter (Params : in Auth_Config; Name : in String) return String; Config : Auth_Config; end Auth_CB;
with Text_Io; with sort; -- ------------------ procedure progmain is -- Package usage declarations use Text_Io; use sort; package Int_Io is new Integer_Io(Integer); use Int_Io; -- Variable declarations A : m_array; input_var : Integer; array_sum : Integer; -- Task declarations task Reader is entry start; end Reader; task Sum is entry start; end Sum; task Printer is entry start; end Printer; -- Task definitions -- ----------------- task body Reader is begin accept start do for i in 1..SIZE loop Int_Io.Get(input_var); A(i) := input_var; end loop; end start; end Reader; -- ----------------- -- ----------------- task body Sum is begin accept start do null; end start; array_sum := 0; for i in 1..SIZE loop array_sum := array_sum + A(i); end loop; Put("Array sum: "); Int_Io.Put(array_sum); end Sum; -- ----------------- -- ----------------- task body Printer is begin accept start do null; end start; Put("Sorted array: "); New_Line; for i in 1..SIZE loop Int_Io.Put(A(i)); end loop; end Printer; -- ----------------- begin Reader.start; MergeSort(A); Sum.start; Printer.start; end progmain; -- ------------------
with Ada.Text_IO; use Ada.Text_IO; package Auto_Differentiation.Integrator is type Variable (N2 : Nat) is record X : Real_Vector (1 .. N2); T : Real; end record; type Control_Type is record N : Nat; Dt : Real := 1.0; Eps : Real := 1.0e-10; Err : Real := 1.0; K : Nat := 9; end record; procedure FJ (Lagrangian : not null access function (X : Real_Vector; N : Nat) return AD_Type; Var : in Variable; Control : in Control_Type; Q : in Real_Vector; F : out Sparse_Vector; J : out Sparse_Matrix); function Collocation (Lagrangian : not null access function (X : Real_Vector; N : Nat) return AD_Type; Var : in Variable; Control : in out Control_Type) return Real_Vector with Pre => Is_Setup = True; function Bogacki_Shampine (Hamiltonian : not null access function (X : Real_Vector; N : Nat) return AD_Type; Var : in Variable; Control : in out Control_Type) return Real_Vector; procedure Update (Hamiltonian : not null access function (X : Real_Vector; N : Nat) return AD_Type; Var : in out Variable; Control : in out Control_Type); procedure Print_Data (Var : in Variable; Hamiltonian : not null access function (X : Real_Vector; N : Nat) return AD_Type); procedure Print_XYZ (File : in File_Type; Var : in Variable); procedure Print_Data_L (File : in File_Type; Var : in Variable); procedure Setup (N : in Nat; K : in Nat); function Is_Setup return Boolean; private MatA, MatB, MatC, MatD : Sparse_Matrix; end Auto_Differentiation.Integrator;
------------------------------------------------------------------------------- -- Copyright (c) 2017 Daniel King -- -- Permission is hereby granted, free of charge, to any person obtaining a -- copy of this software and associated documentation files (the "Software"), -- to deal in the Software without restriction, including without limitation -- the rights to use, copy, modify, merge, publish, distribute, sublicense, -- and/or sell copies of the Software, and to permit persons to whom the -- Software is furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in -- all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -- DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------- with DW1000.Driver; use DW1000.Driver; package body Configurations with SPARK_Mode => On is type Preamble_Codes_Array is array (Positive range 1 .. 7, DW1000.Driver.PRF_Type) of DW1000.Driver.Preamble_Code_Number; type PRF_Config_Array is array (EVB1000.S1.Bit) of DW1000.Driver.PRF_Type; type Data_Rate_Config_Array is array (EVB1000.S1.Bit, EVB1000.S1.Bit) of DW1000.Driver.Data_Rates; type Channels_Config_Array is array (EVB1000.S1.Bit, EVB1000.S1.Bit, EVB1000.S1.Bit) of DW1000.Driver.Channel_Number; Preamble_Codes : constant Preamble_Codes_Array := (1 => (PRF_16MHz => 1, PRF_64MHz => 9), 2 => (PRF_16MHz => 3, PRF_64MHz => 10), 3 => (PRF_16MHz => 5, PRF_64MHz => 11), 4 => (PRF_16MHz => 7, PRF_64MHz => 17), 5 => (PRF_16MHz => 4, PRF_64MHz => 12), 6 => (PRF_16MHz => 1, -- Channel 6 not used PRF_64MHz => 9), 7 => (PRF_16MHz => 8, PRF_64MHz => 18)); PRF_Config : constant PRF_Config_Array := (0 => PRF_16MHz, 1 => PRF_64MHz); Data_Rate_Config : constant Data_Rate_Config_Array := (0 => (0 => Data_Rate_110k, 1 => Data_Rate_850k), 1 => (0 => Data_Rate_6M8, 1 => Data_Rate_6M8)); Channel_Config : constant Channels_Config_Array := (0 => (0 => (0 => 1, 1 => 2), 1 => (0 => 3, 1 => 4)), 1 => (0 => (0 => 5, 1 => 7), 1 => (0 => 7, 1 => 7))); procedure Get_Switches_Config (Config : out DecaDriver.Core.Configuration_Type) is Switches : EVB1000.S1.Switch_Bit_Array; Channel : DW1000.Driver.Channel_Number; PRF : DW1000.Driver.PRF_Type; Data_Rate : DW1000.Driver.Data_Rates; begin EVB1000.S1.Read_All (Switches); Data_Rate := Data_Rate_Config (Switches (3), Switches (4)); PRF := PRF_Config (Switches (5)); Channel := Channel_Config (Switches (6), Switches (7), Switches (8)); Config := DecaDriver.Core.Configuration_Type' (Channel => Channel, PRF => PRF, Tx_Preamble_Length => PLEN_1024, Rx_PAC => PAC_32, Tx_Preamble_Code => Preamble_Codes (Positive (Channel), PRF), Rx_Preamble_Code => Preamble_Codes (Positive (Channel), PRF), Use_Nonstandard_SFD => False, Data_Rate => Data_Rate, PHR_Mode => Standard_Frames, SFD_Timeout => 1024 + 64 + 1); end Get_Switches_Config; end Configurations;
------------------------------------------------------------------------------ -- -- -- GNAT RUNTIME COMPONENTS -- -- -- -- S Y S T E M . I M G _ R E A L -- -- -- -- S p e c -- -- -- -- $Revision: 2 $ -- -- -- -- Copyright (c) 1992,1993,1994 NYU, All Rights Reserved -- -- -- -- The GNAT library is free software; you can redistribute it and/or modify -- -- it under terms of the GNU Library General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) any -- -- later version. The GNAT library 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 -- -- Library General Public License for more details. You should have -- -- received a copy of the GNU Library General Public License along with -- -- the GNAT library; see the file COPYING.LIB. If not, write to the Free -- -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. -- -- -- ------------------------------------------------------------------------------ -- Image for fixed and float types (also used for Float_IO/Fixed_IO output) package System.Img_Real is pragma Preelaborate (Img_Real); function Image_Ordinary_Fixed_Point (V : Long_Long_Float; S : access String; Aft : Natural) return Natural; -- Computes the image of V and stores the resulting string in S (1 .. N) -- according to the rules for image for fixed-point types (RM 3.5(34)), -- where Aft is the value of the Aft attribute for the fixed-point type. -- This function is used only for ordinary fixed point (see package -- System.Img_Decimal for handling of decimal fixed-point). The caller -- guarantees that the string is long enough. function Image_Floating_Point (V : Long_Long_Float; S : access String; Digs : Natural) return Natural; -- Computes the image of V and stores the resulting string in S (1 .. N) -- according to the rules for image for foating-point types (RM 3.5(33)), -- where Digs is the value of the Digits attribute for the floating-point -- type. The caller guarantees that the string is long enough. procedure Set_Image_Real (V : Long_Long_Float; S : out String; P : in out Natural; Fore : Natural; Aft : Natural; Exp : Natural); -- Sets the image of V starting at S (P + 1), updating P to point to the -- last character stored, the caller promises that the buffer is large -- enough and no check is made for this. Constraint_Error will not -- necessarily beraised if this is violated, since it is perfectly valid -- to compile this unit with checks off). The Fore, Aft and Exp values -- can be set to any valid values for the case of use from Text_IO. end System.Img_Real;
with ARM_Output; with ARM_Index; package ARM_Subindex is -- -- Ada reference manual formatter (ARM_Form). -- -- This package contains the database to store subindex items for -- non-normative appendixes. -- -- --------------------------------------- -- Copyright 2005, 2011 -- AXE Consultants. All rights reserved. -- P.O. Box 1512, Madison WI 53701 -- E-Mail: randy@rrsoftware.com -- -- ARM_Form is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License version 3 -- as published by the Free Software Foundation. -- -- AXE CONSULTANTS MAKES THIS TOOL AND SOURCE CODE AVAILABLE ON AN "AS IS" -- BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY, -- CAPABILITY, EFFICIENCY, MERCHANTABILITY, OR FUNCTIONING OF THIS TOOL. -- IN NO EVENT WILL AXE CONSULTANTS BE LIABLE FOR ANY GENERAL, -- CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES, -- EVEN IF AXE CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -- DAMAGES. -- -- A copy of the GNU General Public License is available in the file -- gpl-3-0.txt in the standard distribution of the ARM_Form tool. -- Otherwise, see <http://www.gnu.org/licenses/>. -- -- If the GPLv3 license is not satisfactory for your needs, a commercial -- use license is available for this tool. Contact Randy at AXE Consultants -- for more information. -- -- --------------------------------------- -- -- Edit History: -- -- 10/28/05 - RLB - Created package. -- 10/18/11 - RLB - Changed to GPLv3 license. type Subindex_Type is tagged limited private; Not_Valid_Error : exception; procedure Create (Subindex_Object : in out Subindex_Type); -- Initialize a Subindex object. procedure Destroy (Subindex_Object : in out Subindex_Type); -- Destroy a Subindex object, freeing any resources used. type Subindex_Item_Kind_Type is (Top_Level, In_Unit, Child_of_Parent, Subtype_In_Unit, Description_In_Unit, Raised_Belonging_to_Unit); procedure Insert (Subindex_Object : in out Subindex_Type; Entity : in String; From_Unit : in String := ""; Kind : in Subindex_Item_Kind_Type := Top_Level; Clause : in String := ""; Paragraph : in String := ""; Key : in ARM_Index.Index_Key); -- Insert an item into the Subindex object. -- The Key must be one returned by ARM_Index.Add or ARM_Index.Get_Key. -- Raises Not_Valid_Error if In_Unit, Clause, or Paragraph is not -- empty when the kind does not use it. procedure Write_Subindex ( Subindex_Object : in out Subindex_Type; Output_Object : in out ARM_Output.Output_Type'Class; Use_Paragraphs : in Boolean := True; Minimize_Lines : in Boolean := False); -- Generate the given subindex to Output_Object. -- References include paragraph numbers if Use_Paragraphs is true. -- Try to minimize lines if Minimize_Lines is True. private type Item; type Item_List is access all Item; type Subindex_Type is tagged limited record Is_Valid : Boolean := False; List : Item_List; Item_Count : Natural; end record; end ARM_Subindex;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S Y S T E M . G E N E R I C _ B I G N U M S -- -- -- -- B o d y -- -- -- -- Copyright (C) 2012-2020, Free Software Foundation, Inc. -- -- -- -- 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 Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package provides arbitrary precision signed integer arithmetic. package body System.Generic_Bignums is use Interfaces; -- So that operations on Unsigned_32/Unsigned_64 are available use Shared_Bignums; type DD is mod Base ** 2; -- Double length digit used for intermediate computations function MSD (X : DD) return SD is (SD (X / Base)); function LSD (X : DD) return SD is (SD (X mod Base)); -- Most significant and least significant digit of double digit value function "&" (X, Y : SD) return DD is (DD (X) * Base + DD (Y)); -- Compose double digit value from two single digit values subtype LLI is Long_Long_Integer; One_Data : constant Digit_Vector (1 .. 1) := (1 => 1); -- Constant one Zero_Data : constant Digit_Vector (1 .. 0) := (1 .. 0 => 0); -- Constant zero ----------------------- -- Local Subprograms -- ----------------------- function Add (X, Y : Digit_Vector; X_Neg : Boolean; Y_Neg : Boolean) return Big_Integer with Pre => X'First = 1 and then Y'First = 1; -- This procedure adds two signed numbers returning the Sum, it is used -- for both addition and subtraction. The value computed is X + Y, with -- X_Neg and Y_Neg giving the signs of the operands. type Compare_Result is (LT, EQ, GT); -- Indicates result of comparison in following call function Compare (X, Y : Digit_Vector; X_Neg, Y_Neg : Boolean) return Compare_Result with Pre => X'First = 1 and then Y'First = 1; -- Compare (X with sign X_Neg) with (Y with sign Y_Neg), and return the -- result of the signed comparison. procedure Div_Rem (X, Y : Bignum; Quotient : out Big_Integer; Remainder : out Big_Integer; Discard_Quotient : Boolean := False; Discard_Remainder : Boolean := False); -- Returns the Quotient and Remainder from dividing abs (X) by abs (Y). The -- values of X and Y are not modified. If Discard_Quotient is True, then -- Quotient is undefined on return, and if Discard_Remainder is True, then -- Remainder is undefined on return. Service routine for Big_Div/Rem/Mod. function Normalize (X : Digit_Vector; Neg : Boolean := False) return Big_Integer; -- Given a digit vector and sign, allocate and construct a big integer -- value. Note that X may have leading zeroes which must be removed, and if -- the result is zero, the sign is forced positive. -- If X is too big, Storage_Error is raised. function "**" (X : Bignum; Y : SD) return Big_Integer; -- Exponentiation routine where we know right operand is one word --------- -- Add -- --------- function Add (X, Y : Digit_Vector; X_Neg : Boolean; Y_Neg : Boolean) return Big_Integer is begin -- If signs are the same, we are doing an addition, it is convenient to -- ensure that the first operand is the longer of the two. if X_Neg = Y_Neg then if X'Last < Y'Last then return Add (X => Y, Y => X, X_Neg => Y_Neg, Y_Neg => X_Neg); -- Here signs are the same, and the first operand is the longer else pragma Assert (X_Neg = Y_Neg and then X'Last >= Y'Last); -- Do addition, putting result in Sum (allowing for carry) declare Sum : Digit_Vector (0 .. X'Last); RD : DD; begin RD := 0; for J in reverse 1 .. X'Last loop RD := RD + DD (X (J)); if J >= 1 + (X'Last - Y'Last) then RD := RD + DD (Y (J - (X'Last - Y'Last))); end if; Sum (J) := LSD (RD); RD := RD / Base; end loop; Sum (0) := SD (RD); return Normalize (Sum, X_Neg); end; end if; -- Signs are different so really this is a subtraction, we want to make -- sure that the largest magnitude operand is the first one, and then -- the result will have the sign of the first operand. else declare CR : constant Compare_Result := Compare (X, Y, False, False); begin if CR = EQ then return Normalize (Zero_Data); elsif CR = LT then return Add (X => Y, Y => X, X_Neg => Y_Neg, Y_Neg => X_Neg); else pragma Assert (X_Neg /= Y_Neg and then CR = GT); -- Do subtraction, putting result in Diff declare Diff : Digit_Vector (1 .. X'Length); RD : DD; begin RD := 0; for J in reverse 1 .. X'Last loop RD := RD + DD (X (J)); if J >= 1 + (X'Last - Y'Last) then RD := RD - DD (Y (J - (X'Last - Y'Last))); end if; Diff (J) := LSD (RD); RD := (if RD < Base then 0 else -1); end loop; return Normalize (Diff, X_Neg); end; end if; end; end if; end Add; ------------- -- Big_Abs -- ------------- function Big_Abs (X : Bignum) return Big_Integer is begin return Normalize (X.D); end Big_Abs; ------------- -- Big_Add -- ------------- function Big_Add (X, Y : Bignum) return Big_Integer is begin return Add (X.D, Y.D, X.Neg, Y.Neg); end Big_Add; ------------- -- Big_Div -- ------------- -- This table is excerpted from RM 4.5.5(28-30) and shows how the result -- varies with the signs of the operands. -- A B A/B A B A/B -- -- 10 5 2 -10 5 -2 -- 11 5 2 -11 5 -2 -- 12 5 2 -12 5 -2 -- 13 5 2 -13 5 -2 -- 14 5 2 -14 5 -2 -- -- A B A/B A B A/B -- -- 10 -5 -2 -10 -5 2 -- 11 -5 -2 -11 -5 2 -- 12 -5 -2 -12 -5 2 -- 13 -5 -2 -13 -5 2 -- 14 -5 -2 -14 -5 2 function Big_Div (X, Y : Bignum) return Big_Integer is Q, R : aliased Big_Integer; begin Div_Rem (X, Y, Q, R, Discard_Remainder => True); To_Bignum (Q).Neg := To_Bignum (Q).Len > 0 and then (X.Neg xor Y.Neg); return Q; end Big_Div; ---------- -- "**" -- ---------- function "**" (X : Bignum; Y : SD) return Big_Integer is begin case Y is -- X ** 0 is 1 when 0 => return Normalize (One_Data); -- X ** 1 is X when 1 => return Normalize (X.D); -- X ** 2 is X * X when 2 => return Big_Mul (X, X); -- For X greater than 2, use the recursion -- X even, X ** Y = (X ** (Y/2)) ** 2; -- X odd, X ** Y = (X ** (Y/2)) ** 2 * X; when others => declare XY2 : aliased Big_Integer := X ** (Y / 2); XY2S : aliased Big_Integer := Big_Mul (To_Bignum (XY2), To_Bignum (XY2)); begin Free_Big_Integer (XY2); if (Y and 1) = 0 then return XY2S; else return Res : constant Big_Integer := Big_Mul (To_Bignum (XY2S), X) do Free_Big_Integer (XY2S); end return; end if; end; end case; end "**"; ------------- -- Big_Exp -- ------------- function Big_Exp (X, Y : Bignum) return Big_Integer is begin -- Error if right operand negative if Y.Neg then raise Constraint_Error with "exponentiation to negative power"; -- X ** 0 is always 1 (including 0 ** 0, so do this test first) elsif Y.Len = 0 then return Normalize (One_Data); -- 0 ** X is always 0 (for X non-zero) elsif X.Len = 0 then return Normalize (Zero_Data); -- (+1) ** Y = 1 -- (-1) ** Y = +/-1 depending on whether Y is even or odd elsif X.Len = 1 and then X.D (1) = 1 then return Normalize (X.D, Neg => X.Neg and then ((Y.D (Y.Len) and 1) = 1)); -- If the absolute value of the base is greater than 1, then the -- exponent must not be bigger than one word, otherwise the result -- is ludicrously large, and we just signal Storage_Error right away. elsif Y.Len > 1 then raise Storage_Error with "exponentiation result is too large"; -- Special case (+/-)2 ** K, where K is 1 .. 31 using a shift elsif X.Len = 1 and then X.D (1) = 2 and then Y.D (1) < 32 then declare D : constant Digit_Vector (1 .. 1) := (1 => Shift_Left (SD'(1), Natural (Y.D (1)))); begin return Normalize (D, X.Neg); end; -- Remaining cases have right operand of one word else return X ** Y.D (1); end if; end Big_Exp; ------------- -- Big_And -- ------------- function Big_And (X, Y : Bignum) return Big_Integer is begin if X.Len > Y.Len then return Big_And (X => Y, Y => X); end if; -- X is the smallest integer declare Result : Digit_Vector (1 .. X.Len); Diff : constant Length := Y.Len - X.Len; begin for J in 1 .. X.Len loop Result (J) := X.D (J) and Y.D (J + Diff); end loop; return Normalize (Result, X.Neg and Y.Neg); end; end Big_And; ------------ -- Big_Or -- ------------ function Big_Or (X, Y : Bignum) return Big_Integer is begin if X.Len < Y.Len then return Big_Or (X => Y, Y => X); end if; -- X is the largest integer declare Result : Digit_Vector (1 .. X.Len); Index : Length; Diff : constant Length := X.Len - Y.Len; begin Index := 1; while Index <= Diff loop Result (Index) := X.D (Index); Index := Index + 1; end loop; for J in 1 .. Y.Len loop Result (Index) := X.D (Index) or Y.D (J); Index := Index + 1; end loop; return Normalize (Result, X.Neg or Y.Neg); end; end Big_Or; -------------------- -- Big_Shift_Left -- -------------------- function Big_Shift_Left (X : Bignum; Amount : Natural) return Big_Integer is begin if X.Neg then raise Constraint_Error; elsif Amount = 0 then return Allocate_Big_Integer (X.D, False); end if; declare Shift : constant Natural := Amount rem SD'Size; Result : Digit_Vector (0 .. X.Len + Amount / SD'Size); Carry : SD := 0; begin for J in X.Len + 1 .. Result'Last loop Result (J) := 0; end loop; for J in reverse 1 .. X.Len loop Result (J) := Shift_Left (X.D (J), Shift) or Carry; Carry := Shift_Right (X.D (J), SD'Size - Shift); end loop; Result (0) := Carry; return Normalize (Result, False); end; end Big_Shift_Left; --------------------- -- Big_Shift_Right -- --------------------- function Big_Shift_Right (X : Bignum; Amount : Natural) return Big_Integer is begin if X.Neg then raise Constraint_Error; elsif Amount = 0 then return Allocate_Big_Integer (X.D, False); end if; declare Shift : constant Natural := Amount rem SD'Size; Result : Digit_Vector (1 .. X.Len - Amount / SD'Size); Carry : SD := 0; begin for J in 1 .. Result'Last - 1 loop Result (J) := Shift_Right (X.D (J), Shift) or Carry; Carry := Shift_Left (X.D (J), SD'Size - Shift); end loop; Result (Result'Last) := Shift_Right (X.D (Result'Last), Shift) or Carry; return Normalize (Result, False); end; end Big_Shift_Right; ------------ -- Big_EQ -- ------------ function Big_EQ (X, Y : Bignum) return Boolean is begin return Compare (X.D, Y.D, X.Neg, Y.Neg) = EQ; end Big_EQ; ------------ -- Big_GE -- ------------ function Big_GE (X, Y : Bignum) return Boolean is begin return Compare (X.D, Y.D, X.Neg, Y.Neg) /= LT; end Big_GE; ------------ -- Big_GT -- ------------ function Big_GT (X, Y : Bignum) return Boolean is begin return Compare (X.D, Y.D, X.Neg, Y.Neg) = GT; end Big_GT; ------------ -- Big_LE -- ------------ function Big_LE (X, Y : Bignum) return Boolean is begin return Compare (X.D, Y.D, X.Neg, Y.Neg) /= GT; end Big_LE; ------------ -- Big_LT -- ------------ function Big_LT (X, Y : Bignum) return Boolean is begin return Compare (X.D, Y.D, X.Neg, Y.Neg) = LT; end Big_LT; ------------- -- Big_Mod -- ------------- -- This table is excerpted from RM 4.5.5(28-30) and shows how the result -- of Rem and Mod vary with the signs of the operands. -- A B A mod B A rem B A B A mod B A rem B -- 10 5 0 0 -10 5 0 0 -- 11 5 1 1 -11 5 4 -1 -- 12 5 2 2 -12 5 3 -2 -- 13 5 3 3 -13 5 2 -3 -- 14 5 4 4 -14 5 1 -4 -- A B A mod B A rem B A B A mod B A rem B -- 10 -5 0 0 -10 -5 0 0 -- 11 -5 -4 1 -11 -5 -1 -1 -- 12 -5 -3 2 -12 -5 -2 -2 -- 13 -5 -2 3 -13 -5 -3 -3 -- 14 -5 -1 4 -14 -5 -4 -4 function Big_Mod (X, Y : Bignum) return Big_Integer is Q, R : aliased Big_Integer; begin -- If signs are same, result is same as Rem if X.Neg = Y.Neg then return Big_Rem (X, Y); -- Case where Mod is different else -- Do division Div_Rem (X, Y, Q, R, Discard_Quotient => True); -- Zero result is unchanged if To_Bignum (R).Len = 0 then return R; -- Otherwise adjust result else declare T1 : aliased Big_Integer := Big_Sub (Y, To_Bignum (R)); begin To_Bignum (T1).Neg := Y.Neg; Free_Big_Integer (R); return T1; end; end if; end if; end Big_Mod; ------------- -- Big_Mul -- ------------- function Big_Mul (X, Y : Bignum) return Big_Integer is Result : Digit_Vector (1 .. X.Len + Y.Len) := (others => 0); -- Accumulate result (max length of result is sum of operand lengths) L : Length; -- Current result digit D : DD; -- Result digit begin for J in 1 .. X.Len loop for K in 1 .. Y.Len loop L := Result'Last - (X.Len - J) - (Y.Len - K); D := DD (X.D (J)) * DD (Y.D (K)) + DD (Result (L)); Result (L) := LSD (D); D := D / Base; -- D is carry which must be propagated while D /= 0 and then L >= 1 loop L := L - 1; D := D + DD (Result (L)); Result (L) := LSD (D); D := D / Base; end loop; -- Must not have a carry trying to extend max length pragma Assert (D = 0); end loop; end loop; -- Return result return Normalize (Result, X.Neg xor Y.Neg); end Big_Mul; ------------ -- Big_NE -- ------------ function Big_NE (X, Y : Bignum) return Boolean is begin return Compare (X.D, Y.D, X.Neg, Y.Neg) /= EQ; end Big_NE; ------------- -- Big_Neg -- ------------- function Big_Neg (X : Bignum) return Big_Integer is begin return Normalize (X.D, not X.Neg); end Big_Neg; ------------- -- Big_Rem -- ------------- -- This table is excerpted from RM 4.5.5(28-30) and shows how the result -- varies with the signs of the operands. -- A B A rem B A B A rem B -- 10 5 0 -10 5 0 -- 11 5 1 -11 5 -1 -- 12 5 2 -12 5 -2 -- 13 5 3 -13 5 -3 -- 14 5 4 -14 5 -4 -- A B A rem B A B A rem B -- 10 -5 0 -10 -5 0 -- 11 -5 1 -11 -5 -1 -- 12 -5 2 -12 -5 -2 -- 13 -5 3 -13 -5 -3 -- 14 -5 4 -14 -5 -4 function Big_Rem (X, Y : Bignum) return Big_Integer is Q, R : aliased Big_Integer; begin Div_Rem (X, Y, Q, R, Discard_Quotient => True); To_Bignum (R).Neg := To_Bignum (R).Len > 0 and then X.Neg; return R; end Big_Rem; ------------- -- Big_Sub -- ------------- function Big_Sub (X, Y : Bignum) return Big_Integer is begin -- If right operand zero, return left operand (avoiding sharing) if Y.Len = 0 then return Normalize (X.D, X.Neg); -- Otherwise add negative of right operand else return Add (X.D, Y.D, X.Neg, not Y.Neg); end if; end Big_Sub; ------------- -- Compare -- ------------- function Compare (X, Y : Digit_Vector; X_Neg, Y_Neg : Boolean) return Compare_Result is begin -- Signs are different, that's decisive, since 0 is always plus if X_Neg /= Y_Neg then return (if X_Neg then LT else GT); -- Lengths are different, that's decisive since no leading zeroes elsif X'Last /= Y'Last then return (if (X'Last > Y'Last) xor X_Neg then GT else LT); -- Need to compare data else for J in X'Range loop if X (J) /= Y (J) then return (if (X (J) > Y (J)) xor X_Neg then GT else LT); end if; end loop; return EQ; end if; end Compare; ------------- -- Div_Rem -- ------------- procedure Div_Rem (X, Y : Bignum; Quotient : out Big_Integer; Remainder : out Big_Integer; Discard_Quotient : Boolean := False; Discard_Remainder : Boolean := False) is begin -- Error if division by zero if Y.Len = 0 then raise Constraint_Error with "division by zero"; end if; -- Handle simple cases with special tests -- If X < Y then quotient is zero and remainder is X if Compare (X.D, Y.D, False, False) = LT then if not Discard_Quotient then Quotient := Normalize (Zero_Data); end if; if not Discard_Remainder then Remainder := Normalize (X.D); end if; return; -- If both X and Y are less than 2**63-1, we can use Long_Long_Integer -- arithmetic. Note it is good not to do an accurate range check against -- Long_Long_Integer since -2**63 / -1 overflows. elsif (X.Len <= 1 or else (X.Len = 2 and then X.D (1) < 2**31)) and then (Y.Len <= 1 or else (Y.Len = 2 and then Y.D (1) < 2**31)) then declare A : constant LLI := abs (From_Bignum (X)); B : constant LLI := abs (From_Bignum (Y)); begin if not Discard_Quotient then Quotient := To_Bignum (A / B); end if; if not Discard_Remainder then Remainder := To_Bignum (A rem B); end if; return; end; -- Easy case if divisor is one digit elsif Y.Len = 1 then declare ND : DD; Div : constant DD := DD (Y.D (1)); Result : Digit_Vector (1 .. X.Len); Remdr : Digit_Vector (1 .. 1); begin ND := 0; for J in 1 .. X.Len loop ND := Base * ND + DD (X.D (J)); pragma Assert (Div /= 0); Result (J) := SD (ND / Div); ND := ND rem Div; end loop; if not Discard_Quotient then Quotient := Normalize (Result); end if; if not Discard_Remainder then Remdr (1) := SD (ND); Remainder := Normalize (Remdr); end if; return; end; end if; -- The complex full multi-precision case. We will employ algorithm -- D defined in the section "The Classical Algorithms" (sec. 4.3.1) -- of Donald Knuth's "The Art of Computer Programming", Vol. 2, 2nd -- edition. The terminology is adjusted for this section to match that -- reference. -- We are dividing X.Len digits of X (called u here) by Y.Len digits -- of Y (called v here), developing the quotient and remainder. The -- numbers are represented using Base, which was chosen so that we have -- the operations of multiplying to single digits (SD) to form a double -- digit (DD), and dividing a double digit (DD) by a single digit (SD) -- to give a single digit quotient and a single digit remainder. -- Algorithm D from Knuth -- Comments here with square brackets are directly from Knuth Algorithm_D : declare -- The following lower case variables correspond exactly to the -- terminology used in algorithm D. m : constant Length := X.Len - Y.Len; n : constant Length := Y.Len; b : constant DD := Base; u : Digit_Vector (0 .. m + n); v : Digit_Vector (1 .. n); q : Digit_Vector (0 .. m); r : Digit_Vector (1 .. n); u0 : SD renames u (0); v1 : SD renames v (1); v2 : SD renames v (2); d : DD; j : Length; qhat : DD; rhat : DD; temp : DD; begin -- Initialize data of left and right operands for J in 1 .. m + n loop u (J) := X.D (J); end loop; for J in 1 .. n loop v (J) := Y.D (J); end loop; -- [Division of nonnegative integers.] Given nonnegative integers u -- = (ul,u2..um+n) and v = (v1,v2..vn), where v1 /= 0 and n > 1, we -- form the quotient u / v = (q0,ql..qm) and the remainder u mod v = -- (r1,r2..rn). pragma Assert (v1 /= 0); pragma Assert (n > 1); -- Dl. [Normalize.] Set d = b/(vl + 1). Then set (u0,u1,u2..um+n) -- equal to (u1,u2..um+n) times d, and set (v1,v2..vn) equal to -- (v1,v2..vn) times d. Note the introduction of a new digit position -- u0 at the left of u1; if d = 1 all we need to do in this step is -- to set u0 = 0. d := b / (DD (v1) + 1); if d = 1 then u0 := 0; else declare Carry : DD; Tmp : DD; begin -- Multiply Dividend (u) by d Carry := 0; for J in reverse 1 .. m + n loop Tmp := DD (u (J)) * d + Carry; u (J) := LSD (Tmp); Carry := Tmp / Base; end loop; u0 := SD (Carry); -- Multiply Divisor (v) by d Carry := 0; for J in reverse 1 .. n loop Tmp := DD (v (J)) * d + Carry; v (J) := LSD (Tmp); Carry := Tmp / Base; end loop; pragma Assert (Carry = 0); end; end if; -- D2. [Initialize j.] Set j = 0. The loop on j, steps D2 through D7, -- will be essentially a division of (uj, uj+1..uj+n) by (v1,v2..vn) -- to get a single quotient digit qj. j := 0; -- Loop through digits loop -- Note: In the original printing, step D3 was as follows: -- D3. [Calculate qhat.] If uj = v1, set qhat to b-l; otherwise -- set qhat to (uj,uj+1)/v1. Now test if v2 * qhat is greater than -- (uj*b + uj+1 - qhat*v1)*b + uj+2. If so, decrease qhat by 1 and -- repeat this test -- This had a bug not discovered till 1995, see Vol 2 errata: -- http://www-cs-faculty.stanford.edu/~uno/err2-2e.ps.gz. Under -- rare circumstances the expression in the test could overflow. -- This version was further corrected in 2005, see Vol 2 errata: -- http://www-cs-faculty.stanford.edu/~uno/all2-pre.ps.gz. -- The code below is the fixed version of this step. -- D3. [Calculate qhat.] Set qhat to (uj,uj+1)/v1 and rhat to -- to (uj,uj+1) mod v1. temp := u (j) & u (j + 1); qhat := temp / DD (v1); rhat := temp mod DD (v1); -- D3 (continued). Now test if qhat >= b or v2*qhat > (rhat,uj+2): -- if so, decrease qhat by 1, increase rhat by v1, and repeat this -- test if rhat < b. [The test on v2 determines at high speed -- most of the cases in which the trial value qhat is one too -- large, and eliminates all cases where qhat is two too large.] while qhat >= b or else DD (v2) * qhat > LSD (rhat) & u (j + 2) loop qhat := qhat - 1; rhat := rhat + DD (v1); exit when rhat >= b; end loop; -- D4. [Multiply and subtract.] Replace (uj,uj+1..uj+n) by -- (uj,uj+1..uj+n) minus qhat times (v1,v2..vn). This step -- consists of a simple multiplication by a one-place number, -- combined with a subtraction. -- The digits (uj,uj+1..uj+n) are always kept positive; if the -- result of this step is actually negative then (uj,uj+1..uj+n) -- is left as the true value plus b**(n+1), i.e. as the b's -- complement of the true value, and a "borrow" to the left is -- remembered. declare Borrow : SD; Carry : DD; Temp : DD; Negative : Boolean; -- Records if subtraction causes a negative result, requiring -- an add back (case where qhat turned out to be 1 too large). begin Borrow := 0; for K in reverse 1 .. n loop Temp := qhat * DD (v (K)) + DD (Borrow); Borrow := MSD (Temp); if LSD (Temp) > u (j + K) then Borrow := Borrow + 1; end if; u (j + K) := u (j + K) - LSD (Temp); end loop; Negative := u (j) < Borrow; u (j) := u (j) - Borrow; -- D5. [Test remainder.] Set qj = qhat. If the result of step -- D4 was negative, we will do the add back step (step D6). q (j) := LSD (qhat); if Negative then -- D6. [Add back.] Decrease qj by 1, and add (0,v1,v2..vn) -- to (uj,uj+1,uj+2..uj+n). (A carry will occur to the left -- of uj, and it is be ignored since it cancels with the -- borrow that occurred in D4.) q (j) := q (j) - 1; Carry := 0; for K in reverse 1 .. n loop Temp := DD (v (K)) + DD (u (j + K)) + Carry; u (j + K) := LSD (Temp); Carry := Temp / Base; end loop; u (j) := u (j) + SD (Carry); end if; end; -- D7. [Loop on j.] Increase j by one. Now if j <= m, go back to -- D3 (the start of the loop on j). j := j + 1; exit when not (j <= m); end loop; -- D8. [Unnormalize.] Now (qo,ql..qm) is the desired quotient, and -- the desired remainder may be obtained by dividing (um+1..um+n) -- by d. if not Discard_Quotient then Quotient := Normalize (q); end if; if not Discard_Remainder then declare Remdr : DD; begin Remdr := 0; for K in 1 .. n loop Remdr := Base * Remdr + DD (u (m + K)); r (K) := SD (Remdr / d); Remdr := Remdr rem d; end loop; pragma Assert (Remdr = 0); end; Remainder := Normalize (r); end if; end Algorithm_D; end Div_Rem; ----------------- -- From_Bignum -- ----------------- function From_Bignum (X : Bignum) return Long_Long_Integer is begin if X.Len = 0 then return 0; elsif X.Len = 1 then return (if X.Neg then -LLI (X.D (1)) else LLI (X.D (1))); elsif X.Len = 2 then declare Mag : constant DD := X.D (1) & X.D (2); begin if X.Neg and then Mag <= 2 ** 63 then return -LLI (Mag); elsif Mag < 2 ** 63 then return LLI (Mag); end if; end; end if; raise Constraint_Error with "expression value out of range"; end From_Bignum; ------------------------- -- Bignum_In_LLI_Range -- ------------------------- function Bignum_In_LLI_Range (X : Bignum) return Boolean is begin -- If length is 0 or 1, definitely fits if X.Len <= 1 then return True; -- If length is greater than 2, definitely does not fit elsif X.Len > 2 then return False; -- Length is 2, more tests needed else declare Mag : constant DD := X.D (1) & X.D (2); begin return Mag < 2 ** 63 or else (X.Neg and then Mag = 2 ** 63); end; end if; end Bignum_In_LLI_Range; --------------- -- Normalize -- --------------- Bignum_Limit : constant := 200; function Normalize (X : Digit_Vector; Neg : Boolean := False) return Big_Integer is J : Length; begin J := X'First; while J <= X'Last and then X (J) = 0 loop J := J + 1; end loop; if X'Last - J > Bignum_Limit then raise Storage_Error with "big integer limit exceeded"; end if; return Allocate_Big_Integer (X (J .. X'Last), J <= X'Last and then Neg); end Normalize; --------------- -- To_Bignum -- --------------- function To_Bignum (X : Long_Long_Integer) return Big_Integer is begin if X = 0 then return Allocate_Big_Integer ((1 .. 0 => <>), False); -- One word result elsif X in -(2 ** 32 - 1) .. +(2 ** 32 - 1) then return Allocate_Big_Integer ((1 => SD (abs X)), X < 0); -- Largest negative number annoyance elsif X = Long_Long_Integer'First then return Allocate_Big_Integer ((2 ** 31, 0), True); -- Other negative numbers elsif X < 0 then return Allocate_Big_Integer ((SD ((-X) / Base), SD ((-X) mod Base)), True); -- Positive numbers else return Allocate_Big_Integer ((SD (X / Base), SD (X mod Base)), False); end if; end To_Bignum; function To_Bignum (X : Unsigned_64) return Big_Integer is begin if X = 0 then return Allocate_Big_Integer ((1 .. 0 => <>), False); -- One word result elsif X < 2 ** 32 then return Allocate_Big_Integer ((1 => SD (X)), False); -- Two word result else return Allocate_Big_Integer ((SD (X / Base), SD (X mod Base)), False); end if; end To_Bignum; --------------- -- To_String -- --------------- Hex_Chars : constant array (0 .. 15) of Character := "0123456789ABCDEF"; function To_String (X : Bignum; Width : Natural := 0; Base : Positive := 10) return String is Big_Base : aliased Bignum_Data := (1, False, (1 => SD (Base))); function Add_Base (S : String) return String; -- Add base information if Base /= 10 function Leading_Padding (Str : String; Min_Length : Natural; Char : Character := ' ') return String; -- Return padding of Char concatenated with Str so that the resulting -- string is at least Min_Length long. function Image (Arg : Bignum) return String; -- Return image of Arg, assuming Arg is positive. function Image (N : Natural) return String; -- Return image of N, with no leading space. -------------- -- Add_Base -- -------------- function Add_Base (S : String) return String is begin if Base = 10 then return S; else return Image (Base) & "#" & S & "#"; end if; end Add_Base; ----------- -- Image -- ----------- function Image (N : Natural) return String is S : constant String := Natural'Image (N); begin return S (2 .. S'Last); end Image; function Image (Arg : Bignum) return String is begin if Big_LT (Arg, Big_Base'Unchecked_Access) then return (1 => Hex_Chars (Natural (From_Bignum (Arg)))); else declare Div : aliased Big_Integer; Remain : aliased Big_Integer; R : Natural; begin Div_Rem (Arg, Big_Base'Unchecked_Access, Div, Remain); R := Natural (From_Bignum (To_Bignum (Remain))); Free_Big_Integer (Remain); return S : constant String := Image (To_Bignum (Div)) & Hex_Chars (R) do Free_Big_Integer (Div); end return; end; end if; end Image; --------------------- -- Leading_Padding -- --------------------- function Leading_Padding (Str : String; Min_Length : Natural; Char : Character := ' ') return String is begin return (1 .. Integer'Max (Integer (Min_Length) - Str'Length, 0) => Char) & Str; end Leading_Padding; Zero : aliased Bignum_Data := (0, False, D => Zero_Data); begin if Big_LT (X, Zero'Unchecked_Access) then declare X_Pos : aliased Bignum_Data := (X.Len, not X.Neg, X.D); begin return Leading_Padding ("-" & Add_Base (Image (X_Pos'Unchecked_Access)), Width); end; else return Leading_Padding (" " & Add_Base (Image (X)), Width); end if; end To_String; ------------- -- Is_Zero -- ------------- function Is_Zero (X : Bignum) return Boolean is (X /= null and then X.D = Zero_Data); end System.Generic_Bignums;
pragma Ada_2012; with Ada.Strings.Fixed; with Adventofcode.File_Line_Readers; with GNAT.String_Split; package body Adventofcode.Day_4 is use Ada.Strings.Fixed; ------------ -- Adjust -- ------------ overriding procedure Adjust (P : in out Passport) is begin P.Hair_Color := (if P.Hair_Color /= null then new String'(P.Hair_Color.all) else null); P.Eye_Color := (if P.Eye_Color /= null then new String'(P.Eye_Color.all) else null); P.Passport_ID := (if P.Passport_ID /= null then new String'(P.Passport_ID.all) else null); P.Height := (if P.Height /= null then new String'(P.Height.all) else null); end Adjust; -------------- -- Finalize -- -------------- overriding procedure Finalize (P : in out Passport) is begin Free (P.Hair_Color); Free (P.Eye_Color); Free (P.Passport_ID); Free (P.Height); end Finalize; procedure Check_Validty (P : in out Passport) is begin null; end Check_Validty; ---------- -- Read -- ---------- procedure Read (Passports : in out Passport_Vector; From_Path : String) is Temp : Passport; begin Temp := Null_Passport; for Line of Adventofcode.File_Line_Readers.Read_Lines (From_Path) loop if Line'Length > 0 then Temp.Append (Line); else Temp.Check_Validty; Passports.Append (Temp); Temp := Null_Passport; end if; end loop; if Temp /= Null_Passport then Temp.Check_Validty; Passports.Append (Temp); end if; end Read; procedure Append (Self : in out Passport; Fields : String) is begin -- for F of GNAT.String_Split.Create (Fields, " " & ASCII.LF & ASCII.CR) loop -- declare -- Separator_Index : constant Natural := Index (F, ":"); -- Key : constant String := F (F'First .. Separator_Index - 1); -- Value : constant String := F (Separator_Index + 1 .. F'Last); -- begin -- if Key = "byr" then -- Self.Birth_Year := Year_Type'Value (Value); -- -- elsif Key = "iyr" then -- Self.Issue_Year := Year_Type'Value (Value); -- -- elsif Key = "eyr" then -- Self.Expiration_Year := Year_Type'Value (Value); -- -- elsif Key = "hgt" then -- Self.Height := new String'(Value); -- -- elsif Key = "hcl" then -- Self.Hair_Color := new String'(Value); -- -- elsif Key = "ecl" then -- Self.Eye_Color := new String'(Value); -- -- elsif Key = "pid" then -- Self.Passport_ID := new String'(Value); -- -- elsif Key = "cid" then -- Self.Country_ID := Country_ID_Type'Value (Value); -- -- else -- raise Constraint_Error with "invalid Key:" & Key; -- end if; -- end; -- end loop; null; end; function Count_Valid (Passports : Passport_Vector) return Natural is begin return Valid_Passports : Natural := 0 do for Passport of Passports loop if Passport.Is_Valid then Valid_Passports := Valid_Passports + 1; end if; end loop; end return; end; end Adventofcode.Day_4;
with Ahven.Framework; with Node.Api; package Test_Node.Read is package Skill renames Node.Api; use Node; use Node.Api; type Test is new Ahven.Framework.Test_Case with record State : access Skill_State := new Skill_State; end record; procedure Initialize (T : in out Test); procedure Node_1; procedure Node_2; procedure Node_3; procedure Node_4; end Test_Node.Read;
-- { dg-do run } with System; procedure align_check is N_Allocated_Buffers : Natural := 0; -- function New_Buffer (N_Bytes : Natural) return System.Address is begin N_Allocated_Buffers := N_Allocated_Buffers + 1; return System.Null_Address; end; -- Buffer_Address : constant System.Address := New_Buffer (N_Bytes => 8); N : Natural; for N'Address use Buffer_Address; -- begin if N_Allocated_Buffers /= 1 then raise Program_Error; end if; end;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- G E T _ T A R G -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2020, Free Software Foundation, Inc. -- -- -- -- 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 Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT 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 GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Version for use with GCC package body Get_Targ is -- Functions returning individual run-time values. For the standard (GCC) -- back end, these come from C interface functions (one for each value). ----------------------- -- Get_Bits_Per_Unit -- ----------------------- function Get_Bits_Per_Unit return Pos is function C_Get_Bits_Per_Unit return Pos; pragma Import (C, C_Get_Bits_Per_Unit, "get_target_bits_per_unit"); begin return C_Get_Bits_Per_Unit; end Get_Bits_Per_Unit; ----------------------- -- Get_Bits_Per_Word -- ----------------------- function Get_Bits_Per_Word return Pos is function C_Get_Bits_Per_Word return Pos; pragma Import (C, C_Get_Bits_Per_Word, "get_target_bits_per_word"); begin return C_Get_Bits_Per_Word; end Get_Bits_Per_Word; ------------------- -- Get_Char_Size -- ------------------- function Get_Char_Size return Pos is function C_Get_Char_Size return Pos; pragma Import (C, C_Get_Char_Size, "get_target_char_size"); begin return C_Get_Char_Size; end Get_Char_Size; ---------------------- -- Get_Wchar_T_Size -- ---------------------- function Get_Wchar_T_Size return Pos is function C_Get_Wchar_T_Size return Pos; pragma Import (C, C_Get_Wchar_T_Size, "get_target_wchar_t_size"); begin return C_Get_Wchar_T_Size; end Get_Wchar_T_Size; -------------------- -- Get_Short_Size -- -------------------- function Get_Short_Size return Pos is function C_Get_Short_Size return Pos; pragma Import (C, C_Get_Short_Size, "get_target_short_size"); begin return C_Get_Short_Size; end Get_Short_Size; ------------------ -- Get_Int_Size -- ------------------ function Get_Int_Size return Pos is function C_Get_Int_Size return Pos; pragma Import (C, C_Get_Int_Size, "get_target_int_size"); begin return C_Get_Int_Size; end Get_Int_Size; ------------------- -- Get_Long_Size -- ------------------- function Get_Long_Size return Pos is function C_Get_Long_Size return Pos; pragma Import (C, C_Get_Long_Size, "get_target_long_size"); begin return C_Get_Long_Size; end Get_Long_Size; ------------------------ -- Get_Long_Long_Size -- ------------------------ function Get_Long_Long_Size return Pos is function C_Get_Long_Long_Size return Pos; pragma Import (C, C_Get_Long_Long_Size, "get_target_long_long_size"); begin return C_Get_Long_Long_Size; end Get_Long_Long_Size; ---------------------- -- Get_Pointer_Size -- ---------------------- function Get_Pointer_Size return Pos is function C_Get_Pointer_Size return Pos; pragma Import (C, C_Get_Pointer_Size, "get_target_pointer_size"); begin return C_Get_Pointer_Size; end Get_Pointer_Size; --------------------------- -- Get_Maximum_Alignment -- --------------------------- function Get_Maximum_Alignment return Pos is function C_Get_Maximum_Alignment return Pos; pragma Import (C, C_Get_Maximum_Alignment, "get_target_maximum_alignment"); begin return C_Get_Maximum_Alignment; end Get_Maximum_Alignment; ------------------------ -- Get_Float_Words_BE -- ------------------------ function Get_Float_Words_BE return Nat is function C_Get_Float_Words_BE return Nat; pragma Import (C, C_Get_Float_Words_BE, "get_target_float_words_be"); begin return C_Get_Float_Words_BE; end Get_Float_Words_BE; ------------------ -- Get_Words_BE -- ------------------ function Get_Words_BE return Nat is function C_Get_Words_BE return Nat; pragma Import (C, C_Get_Words_BE, "get_target_words_be"); begin return C_Get_Words_BE; end Get_Words_BE; ------------------ -- Get_Bytes_BE -- ------------------ function Get_Bytes_BE return Nat is function C_Get_Bytes_BE return Nat; pragma Import (C, C_Get_Bytes_BE, "get_target_bytes_be"); begin return C_Get_Bytes_BE; end Get_Bytes_BE; ----------------- -- Get_Bits_BE -- ----------------- function Get_Bits_BE return Nat is function C_Get_Bits_BE return Nat; pragma Import (C, C_Get_Bits_BE, "get_target_bits_be"); begin return C_Get_Bits_BE; end Get_Bits_BE; --------------------- -- Get_Short_Enums -- --------------------- function Get_Short_Enums return Int is flag_short_enums : Int; pragma Import (C, flag_short_enums); begin return flag_short_enums; end Get_Short_Enums; -------------------------- -- Get_Strict_Alignment -- -------------------------- function Get_Strict_Alignment return Nat is function C_Get_Strict_Alignment return Nat; pragma Import (C, C_Get_Strict_Alignment, "get_target_strict_alignment"); begin return C_Get_Strict_Alignment; end Get_Strict_Alignment; ------------------------------------ -- Get_System_Allocator_Alignment -- ------------------------------------ function Get_System_Allocator_Alignment return Nat is function C_Get_System_Allocator_Alignment return Nat; pragma Import (C, C_Get_System_Allocator_Alignment, "get_target_system_allocator_alignment"); begin return C_Get_System_Allocator_Alignment; end Get_System_Allocator_Alignment; -------------------------------- -- Get_Double_Float_Alignment -- -------------------------------- function Get_Double_Float_Alignment return Nat is function C_Get_Double_Float_Alignment return Nat; pragma Import (C, C_Get_Double_Float_Alignment, "get_target_double_float_alignment"); begin return C_Get_Double_Float_Alignment; end Get_Double_Float_Alignment; --------------------------------- -- Get_Double_Scalar_Alignment -- --------------------------------- function Get_Double_Scalar_Alignment return Nat is function C_Get_Double_Scalar_Alignment return Nat; pragma Import (C, C_Get_Double_Scalar_Alignment, "get_target_double_scalar_alignment"); begin return C_Get_Double_Scalar_Alignment; end Get_Double_Scalar_Alignment; ------------------------------ -- Get_Back_End_Config_File -- ------------------------------ function Get_Back_End_Config_File return String_Ptr is begin return null; end Get_Back_End_Config_File; ---------------------- -- Digits_From_Size -- ---------------------- function Digits_From_Size (Size : Pos) return Pos is begin case Size is when 32 => return 6; when 48 => return 9; when 64 => return 15; when 96 => return 18; when 128 => return 18; when others => raise Program_Error; end case; end Digits_From_Size; ----------------------------- -- Get_Max_Unaligned_Field -- ----------------------------- function Get_Max_Unaligned_Field return Pos is begin return 64; -- Can be different on some targets (e.g., AAMP) end Get_Max_Unaligned_Field; ----------------------------- -- Register_Back_End_Types -- ----------------------------- procedure Register_Back_End_Types (Call_Back : Register_Type_Proc) is procedure Enumerate_Modes (Call_Back : Register_Type_Proc); pragma Import (C, Enumerate_Modes, "enumerate_modes"); begin Enumerate_Modes (Call_Back); end Register_Back_End_Types; --------------------- -- Width_From_Size -- --------------------- function Width_From_Size (Size : Pos) return Pos is begin case Size is when 8 => return 4; when 16 => return 6; when 32 => return 11; when 64 => return 21; when others => raise Program_Error; end case; end Width_From_Size; end Get_Targ;
with Ada.Text_IO, Ada.Numerics.Discrete_Random, Ada.Command_Line; procedure Dutch_National_Flag is type Colour_Type is (Red, White, Blue); Number: Positive range 2 .. Positive'Last := Positive'Value(Ada.Command_Line.Argument(1)); -- no sorting if the Number of balls is less than 2 type Balls is array(1 .. Number) of Colour_Type; function Is_Sorted(B: Balls) return Boolean is -- checks if balls are in order begin for I in Balls'First .. Balls'Last-1 loop if B(I) > B(I+1) then return False; end if; end loop; return True; end Is_Sorted; function Random_Balls return Balls is -- generates an array of random balls, ensuring they are not in order package Random_Colour is new Ada.Numerics.Discrete_Random(Colour_Type); Gen: Random_Colour.Generator; B: Balls; begin Random_Colour.Reset(Gen); loop for I in Balls'Range loop B(I) := Random_Colour.Random(Gen); end loop; exit when (not Is_Sorted(B)); -- ... ensuring they are not in order end loop; return B; end Random_Balls; procedure Print(Message: String; B: Balls) is begin Ada.Text_IO.Put(Message); for I in B'Range loop Ada.Text_IO.Put(Colour_Type'Image(B(I))); if I < B'Last then Ada.Text_IO.Put(", "); else Ada.Text_IO.New_Line; end if; end loop; end Print; procedure Sort(Bls: in out Balls) is -- sort Bls in O(1) time Cnt: array(Colour_Type) of Natural := (Red => 0, White => 0, Blue => 0); Col: Colour_Type; procedure Move_Colour_To_Top(Bls: in out Balls; Colour: Colour_Type; Start: Positive; Count: Natural) is This: Positive := Start; Tmp: Colour_Type; begin for N in Start .. Start+Count-1 loop while Bls(This) /= Colour loop This := This + 1; end loop; -- This is the first index >= N with B(This) = Colour Tmp := Bls(N); Bls(N) := Bls(This); Bls(This) := Tmp; -- swap This := This + 1; end loop; end Move_Colour_To_Top; begin for Ball in Balls'Range loop -- count how often each colour is found Col := Bls(Ball); Cnt(Col) := Cnt(Col) + 1; end loop; Move_Colour_To_Top(Bls, Red, Start => 1, Count => Cnt(Red)); Move_Colour_To_Top(Bls, White, Start => 1+Cnt(Red), Count => Cnt(White)); -- all the remaining balls are blue end Sort; A: Balls := Random_Balls; begin Print("Original Order: ", A); pragma Assert(not Is_Sorted(A)); -- Check if A is unsorted Sort(A); -- A = ((Red**Cnt(Red)= & (White**Cnt(White)) & (Blue**Cnt(Blue))) pragma Assert(Is_Sorted(A)); -- Check if A is actually sorted Print("After Sorting: ", A); end Dutch_National_Flag;
------------------------------------------------------------------------------ -- Copyright (C) 2018, AdaCore -- -- -- -- This is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. This software is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- -- TABILITY 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 this software; see file -- -- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy -- -- of the license. -- ------------------------------------------------------------------------------ with Ada.Real_Time; use Ada.Real_Time; with HAL; use HAL; with NRF51_SVD.GPIO; use NRF51_SVD.GPIO; with Font5x5; use Font5x5; with Generic_Timers; package body Display is procedure Display_Update; -- Callback for the LED matrix scan package Display_Update_Timer is new Generic_Timers (One_Shot => False, Timer_Name => "Display update", Period => Ada.Real_Time.Microseconds (900), Action => Display_Update); -- This timing event will call the procedure Display_Update every -- 900 microseconds. subtype Width is Natural range LED_Column_Coord'First .. LED_Column_Coord'First + LED_Column_Coord'Range_Length * 2; -- The bitmap width is 2 time the display size so we can instert hidden -- characters to the right of the screen and scroll them in with the -- Shift_Left procedure. Bitmap : array (Width, LED_Row_Coord) of Boolean := (others => (others => False)); Current_X : LED_Column_Coord := 0; Current_Y : LED_Row_Coord := 0; -- Coordinate of the current LED begin lit procedure Clear (Pin : GPIO_Pin_Index); -- Set the GPIO to a low state procedure Set (Pin : GPIO_Pin_Index); -- Set the GPIO to a High state procedure Initialize; -- Initialize GPIOs and timers for the LED matrix procedure Shift_Left; -- Shift all pixels of the bitmap buffer to the left procedure Put_Char (X_Org : Width; C : Character); -- Print a charater to the bitmap buffer procedure Scroll_Character (Char : Character); -- Print a character to the hidden part of the bitmap buffer and scroll it -- to the visible part. -------------------- -- Display_Update -- -------------------- procedure Display_Update is begin -- Turn Off the current LED Clear (Row_Points (Map (Current_X, Current_Y).Row_Id)); Set (Column_Points (Map (Current_X, Current_Y).Column_Id)); -- Compute the coordinate of the next LED to be lit if Current_X = LED_Column_Coord'Last then Current_X := LED_Column_Coord'First; if Current_Y = LED_Row_Coord'Last then Current_Y := LED_Row_Coord'First; else Current_Y := Current_Y + 1; end if; else Current_X := Current_X + 1; end if; -- Turn on the new LED? if Bitmap (Current_X, Current_Y) then -- Row source current Set (Row_Points (Map (Current_X, Current_Y).Row_Id)); -- Column sink current Clear (Column_Points (Map (Current_X, Current_Y).Column_Id)); end if; end Display_Update; ----------- -- Clear -- ----------- procedure Clear (Pin : GPIO_Pin_Index) is begin GPIO_Periph.OUT_k.Arr (Pin) := Low; end Clear; --------- -- Set -- --------- procedure Set (Pin : GPIO_Pin_Index) is begin GPIO_Periph.OUT_k.Arr (Pin) := High; end Set; ---------------- -- Initialize -- ---------------- procedure Initialize is procedure Configure_GPIO (Pin : GPIO_Pin_Index); -------------------- -- Configure_GPIO -- -------------------- procedure Configure_GPIO (Pin : GPIO_Pin_Index) is CNF : PIN_CNF_Register renames GPIO_Periph.PIN_CNF (Pin); begin CNF.DIR := Output; CNF.INPUT := Disconnect; CNF.PULL := Pullup; CNF.DRIVE := S0S1; CNF.SENSE := Disabled; end Configure_GPIO; begin -- Initialize LED maxtrix GPIO for Pin of Row_Points loop Configure_GPIO (Pin); Clear (Pin); end loop; for Pin of Column_Points loop Configure_GPIO (Pin); Set (Pin); end loop; -- Start the LED scan timer Display_Update_Timer.Start; end Initialize; ---------------- -- Shift_Left -- ---------------- procedure Shift_Left is begin -- Shift pixel columns to the left, erasing the left most one for X in Bitmap'First (1) .. Bitmap'Last (1) - 1 loop for Y in Bitmap'Range (2) loop Bitmap (X, Y) := Bitmap (X + 1, Y); end loop; end loop; -- Insert black pixels to the right most column for Y in Bitmap'Range (2) loop Bitmap (Bitmap'Last (1), Y) := False; end loop; end Shift_Left; -------------- -- Put_Char -- -------------- procedure Put_Char (X_Org : Width; C : Character) is C_Index : constant Integer := Character'Pos (C) - Character'Pos ('!'); begin if C_Index not in Font'Range then -- C is not a printable character return; end if; -- Copy the glyph into the bitmap buffer for X in LED_Column_Coord loop for Y in LED_Row_Coord loop if X_Org + X in Width then if (Font (C_Index) (Y) and 2**X) /= 0 then Bitmap (X_Org + X, Y) := True; end if; end if; end loop; end loop; end Put_Char; ---------------------- -- Scroll_Character -- ---------------------- procedure Scroll_Character (Char : Character) is begin -- Insert glyph in the hidden part of the buffer Put_Char (5, Char); -- Shift the buffer 6 times with a 150 milliseconds delay between each -- shifts. for Shifts in 1 .. 6 loop Shift_Left; delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (150); end loop; end Scroll_Character; ----------------- -- Scroll_Text -- ----------------- procedure Scroll_Text (Str : String) is begin -- Scroll each character of the string for Char of Str loop Scroll_Character (Char); end loop; end Scroll_Text; begin Initialize; end Display;
with Ada.Interrupts.Names; with STM32GD.GPIO; with STM32GD.GPIO.Pin; with STM32GD.SPI; with STM32GD.SPI.Peripheral; with STM32GD.Timer; with STM32GD.Timer.Peripheral; with Drivers; with Drivers.RFM69; package Peripherals is package GPIO renames STM32GD.GPIO; package Timer is new STM32GD.Timer.Peripheral (Timer => STM32GD.Timer.Timer_14, IRQ => Ada.Interrupts.Names.TIM14); package SCLK is new GPIO.Pin (Pin => GPIO.Pin_5, Port => GPIO.Port_A, Mode => GPIO.Mode_AF); package MISO is new GPIO.Pin (Pin => GPIO.Pin_6, Port => GPIO.Port_A, Mode => GPIO.Mode_AF); package MOSI is new GPIO.Pin (Pin => GPIO.Pin_7, Port => GPIO.Port_A, Mode => GPIO.Mode_AF); package CSN is new GPIO.Pin (Pin => GPIO.Pin_4, Port => GPIO.Port_A, Mode => GPIO.Mode_Out); package IRQ is new GPIO.Pin (Pin => GPIO.Pin_3, Port => GPIO.Port_A, Mode => GPIO.Mode_In); package SPI is new STM32GD.SPI.Peripheral (SPI => STM32GD.SPI.SPI_1); package Radio is new Drivers.RFM69 (Frequency => 868_000_000, SPI => SPI, Chip_Select => CSN, IRQ => IRQ); procedure Init; end Peripherals;
with C_String; with Interfaces.C; package body Agar.Core.Init is package UB_Strings renames Ada.Strings.Unbounded; package C renames Interfaces.C; use type C.int; use type C.unsigned; procedure Get_Version (Major : out Natural; Minor : out Natural; Patch : out Natural; Release : out UB_Strings.Unbounded_String) is Version : aliased Thin.Core.Version_t; begin Thin.Core.Get_Version (Version'Unchecked_Access); Major := Natural (Version.Major); Minor := Natural (Version.Minor); Patch := Natural (Version.Patch); Release := UB_Strings.To_Unbounded_String (C_String.To_String (Version.Release)); end Get_Version; function Init_Flags_To_C_Flags (Flags : in Init_Flags_t) return C.unsigned is C_Flags : C.unsigned := 0; begin for Index in Init_Flags_t'Range loop if Flags (Index) then case Index is when Verbose => C_Flags := C_Flags or Thin.Core.AG_VERBOSE; when Create_Data_Directory => C_Flags := C_Flags or Thin.Core.AG_CREATE_DATADIR; when No_Config_Autoload => C_Flags := C_Flags or Thin.Core.AG_NO_CFG_AUTOLOAD; end case; end if; end loop; return C_Flags; end Init_Flags_To_C_Flags; function Init_Core (Program_Name : in String; Flags : in Init_Flags_t) return Boolean is Ch_Name : aliased C.char_array := C.To_C (Program_Name); C_Flags : constant C.unsigned := Init_Flags_To_C_Flags (Flags); begin return 0 = Thin.Core.Init_Core (Progname => C_String.To_C_String (Ch_Name'Unchecked_Access), Flags => C_Flags); end Init_Core; -- function Video_Flags_To_C_Flags -- (Flags : in Video_Flags_t) return C.unsigned -- is -- C_Flags : C.unsigned := 0; -- begin -- for Index in Video_Flags_t'Range loop -- if Video_Flags (Index) then -- case Index in -- when Video_Hardware_Surface => -- when Video_Asynchronous_Blit => -- when Video_Any_Format => -- when Video_Hardware_Palette => -- when Video_Double_Buffer => -- when Video_Fullscreen => -- when Video_Resizable => -- when Video_No_Frame => -- when Video_Background_Popup_Menu => -- when Video_OpenGL => -- when Video_OpenGL_Or_SDL => -- when Video_Overlay => -- end case; -- end if; -- end loop; -- return C_Flags; -- end Video_Flags_To_C_Flags; -- -- Proxy procedure to call 'Exit_Callback' from C. -- procedure At_Exit_Caller; pragma Convention (C, At_Exit_Caller); Exit_Callback : Exit_Procedure_t := null; procedure At_Exit_Caller is begin if Exit_Callback /= null then Exit_Callback.all; end if; end At_Exit_Caller; procedure At_Exit (Callback : Exit_Procedure_Not_Null_t) is begin Exit_Callback := Callback; Thin.Core.At_Exit_Func (At_Exit_Caller'Access); end At_Exit; end Agar.Core.Init;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- W I D E C H A R -- -- -- -- B o d y -- -- -- -- $Revision$ -- -- -- Copyright (C) 1992-2001 Free Software Foundation, Inc. -- -- -- -- 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 Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT 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 GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Note: this package uses the generic subprograms in System.Wch_Cnv, which -- completely encapsulate the set of wide character encoding methods, so no -- modifications are required when adding new encoding methods. with Opt; use Opt; with System.WCh_Cnv; use System.WCh_Cnv; with System.WCh_Con; use System.WCh_Con; package body Widechar is --------------------------- -- Is_Start_Of_Wide_Char -- --------------------------- function Is_Start_Of_Wide_Char (S : Source_Buffer_Ptr; P : Source_Ptr) return Boolean is begin case Wide_Character_Encoding_Method is when WCEM_Hex => return S (P) = ASCII.ESC; when WCEM_Upper | WCEM_Shift_JIS | WCEM_EUC | WCEM_UTF8 => return S (P) >= Character'Val (16#80#); when WCEM_Brackets => return P <= S'Last - 2 and then S (P) = '[' and then S (P + 1) = '"' and then S (P + 2) /= '"'; end case; end Is_Start_Of_Wide_Char; ----------------- -- Length_Wide -- ----------------- function Length_Wide return Nat is begin return WC_Longest_Sequence; end Length_Wide; --------------- -- Scan_Wide -- --------------- procedure Scan_Wide (S : Source_Buffer_Ptr; P : in out Source_Ptr; C : out Char_Code; Err : out Boolean) is function In_Char return Character; -- Function to obtain characters of wide character escape sequence function In_Char return Character is begin P := P + 1; return S (P - 1); end In_Char; function WC_In is new Char_Sequence_To_Wide_Char (In_Char); begin C := Char_Code (Wide_Character'Pos (WC_In (In_Char, Wide_Character_Encoding_Method))); Err := False; exception when Constraint_Error => C := Char_Code (0); P := P - 1; Err := True; end Scan_Wide; -------------- -- Set_Wide -- -------------- procedure Set_Wide (C : Char_Code; S : in out String; P : in out Natural) is procedure Out_Char (C : Character); -- Procedure to store one character of wide character sequence procedure Out_Char (C : Character) is begin P := P + 1; S (P) := C; end Out_Char; procedure WC_Out is new Wide_Char_To_Char_Sequence (Out_Char); begin WC_Out (Wide_Character'Val (C), Wide_Character_Encoding_Method); end Set_Wide; --------------- -- Skip_Wide -- --------------- procedure Skip_Wide (S : String; P : in out Natural) is function Skip_Char return Character; -- Function to skip one character of wide character escape sequence function Skip_Char return Character is begin P := P + 1; return S (P - 1); end Skip_Char; function WC_Skip is new Char_Sequence_To_Wide_Char (Skip_Char); Discard : Wide_Character; begin Discard := WC_Skip (Skip_Char, Wide_Character_Encoding_Method); end Skip_Wide; end Widechar;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2015-2016, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of STMicroelectronics nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- -- -- -- This file is based on: -- -- -- -- @file stm32f429i_discovery_lcd.c -- -- @author MCD Application Team -- -- @version V1.1.0 -- -- @date 19-June-2014 -- -- @brief This file includes the LTDC driver to control LCD display. -- -- -- -- COPYRIGHT(c) 2014 STMicroelectronics -- ------------------------------------------------------------------------------ with Ada.Interrupts.Names; with Ada.Unchecked_Conversion; with System; use System; with STM32_SVD.LTDC; use STM32_SVD.LTDC; with STM32_SVD.RCC; use STM32_SVD.RCC; package body STM32.LTDC is pragma Warnings (Off, "* is not referenced"); type LCD_Polarity is (Polarity_Active_Low, Polarity_Active_High) with Size => 1; type LCD_PC_Polarity is (Input_Pixel_Clock, Inverted_Input_Pixel_Clock) with Size => 1; pragma Warnings (On, "* is not referenced"); function To_Bool is new Ada.Unchecked_Conversion (LCD_Polarity, Boolean); function To_Bool is new Ada.Unchecked_Conversion (LCD_PC_Polarity, Boolean); -- Extracted from STM32F429x.LTDC type Layer_Type is record LCR : L1CR_Register; -- Layerx Control Register LWHPCR : L1WHPCR_Register; -- Layerx Window Horizontal Position Configuration Register LWVPCR : L1WVPCR_Register; -- Layerx Window Vertical Position Configuration Register LCKCR : L1CKCR_Register; -- Layerx Color Keying Configuration Register LPFCR : L1PFCR_Register; -- Layerx Pixel Format Configuration Register LCACR : L1CACR_Register; -- Layerx Constant Alpha Configuration Register LDCCR : L1DCCR_Register; -- Layerx Default Color Configuration Register LBFCR : L1BFCR_Register; -- Layerx Blending Factors Configuration Register Reserved_0 : Word; Reserved_1 : Word; LCFBAR : Word; -- Layerx Color Frame Buffer Address Register LCFBLR : L1CFBLR_Register; -- Layerx Color Frame Buffer Length Register LCFBLNR : L1CFBLNR_Register; -- Layerx ColorFrame Buffer Line Number Register Reserved_2 : Word; Reserved_3 : Word; Reserved_4 : Word; LCLUTWR : L1CLUTWR_Register; -- Layerx CLUT Write Register end record with Volatile; for Layer_Type use record LCR at 0 range 0 .. 31; LWHPCR at 4 range 0 .. 31; LWVPCR at 8 range 0 .. 31; LCKCR at 12 range 0 .. 31; LPFCR at 16 range 0 .. 31; LCACR at 20 range 0 .. 31; LDCCR at 24 range 0 .. 31; LBFCR at 28 range 0 .. 31; Reserved_0 at 32 range 0 .. 31; Reserved_1 at 36 range 0 .. 31; LCFBAR at 40 range 0 .. 31; LCFBLR at 44 range 0 .. 31; LCFBLNR at 48 range 0 .. 31; Reserved_2 at 52 range 0 .. 31; Reserved_3 at 56 range 0 .. 31; Reserved_4 at 60 range 0 .. 31; LCLUTWR at 64 range 0 .. 31; end record; type Layer_Access is access all Layer_Type; BF1_Constant_Alpha : constant := 2#100#; BF2_Constant_Alpha : constant := 2#101#; BF1_Pixel_Alpha : constant := 2#110#; BF2_Pixel_Alpha : constant := 2#111#; G_Layer1_Reg : aliased Layer_Type with Import, Address => LTDC_Periph.L1CR'Address; G_Layer2_Reg : aliased Layer_Type with Import, Address => LTDC_Periph.L2CR'Address; function Get_Layer (Layer : LCD_Layer) return Layer_Access; -- Retrieve the layer's registers protected Sync is -- Apply pending buffers on Vertical Sync. Caller must call Wait -- afterwards. procedure Apply_On_VSync; -- Wait for an interrupt. entry Wait; procedure Interrupt; pragma Attach_Handler (Interrupt, Ada.Interrupts.Names.LCD_TFT_Interrupt); private Not_Pending : Boolean := True; end Sync; ---------- -- Sync -- ---------- protected body Sync is ---------- -- Wait -- ---------- entry Wait when Not_Pending is begin null; end Wait; -------------------- -- Apply_On_VSync -- -------------------- procedure Apply_On_VSync is begin Not_Pending := False; -- Enable the Register Refresh interrupt LTDC_Periph.IER.RRIE := True; -- And tell the LTDC to apply the layer registers on refresh LTDC_Periph.SRCR.VBR := True; end Apply_On_VSync; --------------- -- Interrupt -- --------------- procedure Interrupt is begin if LTDC_Periph.ISR.RRIF then LTDC_Periph.IER.RRIE := False; LTDC_Periph.ICR.CRRIF := True; Not_Pending := True; end if; end Interrupt; end Sync; --------------- -- Get_Layer -- --------------- function Get_Layer (Layer : LCD_Layer) return Layer_Access is begin if Layer = Layer1 then return G_Layer1_Reg'Access; else return G_Layer2_Reg'Access; end if; end Get_Layer; ------------------- -- Reload_Config -- ------------------- procedure Reload_Config (Immediate : Boolean := False) is begin if Immediate then LTDC_Periph.SRCR.IMR := True; loop exit when not LTDC_Periph.SRCR.IMR; end loop; else Sync.Apply_On_VSync; Sync.Wait; end if; end Reload_Config; --------------------- -- Set_Layer_State -- --------------------- procedure Set_Layer_State (Layer : LCD_Layer; Enabled : Boolean) is L : constant Layer_Access := Get_Layer (Layer); begin if L.LCR.LEN /= Enabled then L.LCR.LEN := Enabled; Reload_Config (Immediate => True); end if; end Set_Layer_State; ---------------- -- Initialize -- ---------------- procedure Initialize (Width : Positive; Height : Positive; H_Sync : Natural; H_Back_Porch : Natural; H_Front_Porch : Natural; V_Sync : Natural; V_Back_Porch : Natural; V_Front_Porch : Natural; PLLSAI_N : UInt9; PLLSAI_R : UInt3; DivR : Natural) is DivR_Val : PLLSAI_DivR; begin if Initialized then return; end if; if DivR = 2 then DivR_Val := PLLSAI_DIV2; elsif DivR = 4 then DivR_Val := PLLSAI_DIV4; elsif DivR = 8 then DivR_Val := PLLSAI_DIV8; elsif DivR = 16 then DivR_Val := PLLSAI_DIV16; else raise Constraint_Error with "Invalid DivR value: 2, 4, 8, 16 allowed"; end if; Disable_PLLSAI; RCC_Periph.APB2ENR.LTDCEN := True; LTDC_Periph.GCR.VSPOL := To_Bool (Polarity_Active_Low); LTDC_Periph.GCR.HSPOL := To_Bool (Polarity_Active_Low); LTDC_Periph.GCR.DEPOL := To_Bool (Polarity_Active_Low); LTDC_Periph.GCR.PCPOL := To_Bool (Inverted_Input_Pixel_Clock); Set_PLLSAI_Factors (LCD => PLLSAI_R, VCO => PLLSAI_N, DivR => DivR_Val); Enable_PLLSAI; -- Synchronization size LTDC_Periph.SSCR := (HSW => SSCR_HSW_Field (H_Sync - 1), VSH => SSCR_VSH_Field (V_Sync - 1), others => <>); -- Accumulated Back Porch LTDC_Periph.BPCR := (AHBP => BPCR_AHBP_Field (H_Sync + H_Back_Porch - 1), AVBP => BPCR_AVBP_Field (V_Sync + V_Back_Porch - 1), others => <>); -- Accumulated Active Width/Height LTDC_Periph.AWCR := (AAW => AWCR_AAW_Field (H_Sync + H_Back_Porch + Width - 1), AAH => AWCR_AAH_Field (V_Sync + V_Back_Porch + Height - 1), others => <>); -- VTotal Width/Height LTDC_Periph.TWCR := (TOTALW => TWCR_TOTALW_Field (H_Sync + H_Back_Porch + Width + H_Front_Porch - 1), TOTALH => TWCR_TOTALH_Field (V_Sync + V_Back_Porch + Height + V_Front_Porch - 1), others => <>); -- Background color to black LTDC_Periph.BCCR.BC := 0; LTDC_Periph.GCR.LTDCEN := True; end Initialize; ----------- -- Start -- ----------- procedure Start is begin LTDC_Periph.GCR.LTDCEN := True; end Start; ---------- -- Stop -- ---------- procedure Stop is begin LTDC_Periph.GCR.LTDCEN := False; end Stop; ----------------- -- Initialized -- ----------------- function Initialized return Boolean is begin return LTDC_Periph.GCR.LTDCEN; end Initialized; ---------------- -- Layer_Init -- ---------------- procedure Layer_Init (Layer : LCD_Layer; Config : Pixel_Format; Buffer : System.Address; X, Y : Natural; W, H : Positive; Constant_Alpha : Byte := 255; BF : Blending_Factor := BF_Pixel_Alpha_X_Constant_Alpha) is L : constant Layer_Access := Get_Layer (Layer); CFBL : L1CFBLR_Register := L.LCFBLR; begin -- Horizontal start and stop = sync + Back Porch L.LWHPCR := (WHSTPOS => L1WHPCR_WHSTPOS_Field (LTDC_Periph.BPCR.AHBP) + 1 + L1WHPCR_WHSTPOS_Field (X), WHSPPOS => L1WHPCR_WHSPPOS_Field (LTDC_Periph.BPCR.AHBP) + L1WHPCR_WHSPPOS_Field (X + W), others => <>); -- Vertical start and stop L.LWVPCR := (WVSTPOS => LTDC_Periph.BPCR.AVBP + 1 + UInt11 (Y), WVSPPOS => LTDC_Periph.BPCR.AVBP + UInt11 (Y + H), others => <>); L.LPFCR.PF := Pixel_Format'Enum_Rep (Config); L.LCACR.CONSTA := Constant_Alpha; L.LDCCR := (others => 0); case BF is when BF_Constant_Alpha => L.LBFCR.BF1 := BF1_Constant_Alpha; L.LBFCR.BF2 := BF2_Constant_Alpha; when BF_Pixel_Alpha_X_Constant_Alpha => L.LBFCR.BF1 := BF1_Pixel_Alpha; L.LBFCR.BF2 := BF2_Pixel_Alpha; end case; CFBL.CFBLL := UInt13 (W * Bytes_Per_Pixel (Config)) + 3; CFBL.CFBP := UInt13 (W * Bytes_Per_Pixel (Config)); L.LCFBLR := CFBL; L.LCFBLNR.CFBLNBR := UInt11 (H); Set_Frame_Buffer (Layer, Buffer); L.LCR.LEN := True; Reload_Config (True); end Layer_Init; ---------------------- -- Set_Frame_Buffer -- ---------------------- procedure Set_Frame_Buffer (Layer : LCD_Layer; Addr : Frame_Buffer_Access) is function To_Word is new Ada.Unchecked_Conversion (Frame_Buffer_Access, Word); begin if Layer = Layer1 then LTDC_Periph.L1CFBAR := To_Word (Addr); else LTDC_Periph.L2CFBAR := To_Word (Addr); end if; end Set_Frame_Buffer; ---------------------- -- Get_Frame_Buffer -- ---------------------- function Get_Frame_Buffer (Layer : LCD_Layer) return Frame_Buffer_Access is L : constant Layer_Access := Get_Layer (Layer); function To_FBA is new Ada.Unchecked_Conversion (Word, Frame_Buffer_Access); begin return To_FBA (L.LCFBAR); end Get_Frame_Buffer; -------------------- -- Set_Background -- -------------------- procedure Set_Background (R, G, B : Byte) is RShift : constant Word := Shift_Left (Word (R), 16); GShift : constant Word := Shift_Left (Word (G), 8); begin LTDC_Periph.BCCR.BC := UInt24 (RShift) or UInt24 (GShift) or UInt24 (B); end Set_Background; end STM32.LTDC;
pragma License (Unrestricted); -- implementation unit required by compiler with System.Packed_Arrays; package System.Compare_Array_Signed_8 is pragma Preelaborate; -- It can not be Pure, subprograms would become __attribute__((const)). type Integer_8 is range -(2 ** 7) .. 2 ** 7 - 1; for Integer_8'Size use 8; package Ordering is new Packed_Arrays.Ordering (Integer_8); -- required to compare arrays by compiler (s-carsi8.ads) function Compare_Array_S8_Unaligned ( Left : Address; Right : Address; Left_Len : Natural; Right_Len : Natural) return Integer renames Ordering.Compare; -- required to compare arrays by compiler (s-carsi8.ads) function Compare_Array_S8 ( Left : Address; Right : Address; Left_Len : Natural; Right_Len : Natural) return Integer renames Ordering.Compare; end System.Compare_Array_Signed_8;
----------------------------------------------------------------------- -- ADO Objects -- Database objects -- Copyright (C) 2009 - 2020 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Strings.Unbounded.Hash; with Ada.Unchecked_Deallocation; with ADO.Sessions.Factory; package body ADO.Objects is use type ADO.Schemas.Class_Mapping_Access; -- ------------------------------ -- Compute the hash of the object key. -- ------------------------------ function Hash (Key : Object_Key) return Ada.Containers.Hash_Type is use Ada.Containers; Result : Ada.Containers.Hash_Type; begin case Key.Of_Type is when KEY_INTEGER => if Key.Id < 0 then Result := Hash_Type (-Key.Id); else Result := Hash_Type (Key.Id); end if; when KEY_STRING => Result := Ada.Strings.Unbounded.Hash (Key.Str); end case; -- Merge with the class mapping hash so that two key values of different -- tables will result in a different hash. Result := Result xor ADO.Schemas.Hash (Key.Of_Class); return Result; end Hash; -- ------------------------------ -- Compare whether the two objects pointed to by Left and Right have the same -- object key. The object key is identical if the object key type, the class -- mapping and the key value are identical. -- ------------------------------ function Equivalent_Elements (Left, Right : Object_Key) return Boolean is use Ada.Strings.Unbounded; begin if Left.Of_Type /= Right.Of_Type then return False; end if; if Left.Of_Class /= Right.Of_Class then return False; end if; case Left.Of_Type is when KEY_INTEGER => return Left.Id = Right.Id; when KEY_STRING => return Left.Str = Right.Str; end case; end Equivalent_Elements; -- ------------------------------ -- Get the key value -- ------------------------------ function Get_Value (Key : Object_Key) return Identifier is begin return Key.Id; end Get_Value; -- ------------------------------ -- Get the key value -- ------------------------------ function Get_Value (Key : Object_Key) return Ada.Strings.Unbounded.Unbounded_String is begin return Key.Str; end Get_Value; -- ------------------------------ -- Set the key value -- ------------------------------ procedure Set_Value (Key : in out Object_Key; Value : in Identifier) is begin case Key.Of_Type is when KEY_INTEGER => Key.Id := Value; when KEY_STRING => Key.Str := Ada.Strings.Unbounded.To_Unbounded_String (Identifier'Image (Value)); end case; end Set_Value; -- ------------------------------ -- Set the key value -- ------------------------------ procedure Set_Value (Key : in out Object_Key; Value : in String) is begin case Key.Of_Type is when KEY_INTEGER => Key.Id := Identifier'Value (Value); when KEY_STRING => Key.Str := Ada.Strings.Unbounded.To_Unbounded_String (Value); end case; end Set_Value; -- ------------------------------ -- Get the key as a string -- ------------------------------ function To_String (Key : Object_Key) return String is begin case Key.Of_Type is when KEY_INTEGER => return Identifier'Image (Key.Id); when KEY_STRING => return Ada.Strings.Unbounded.To_String (Key.Str); end case; end To_String; -- ------------------------------ -- Return the key value in a bean object. -- ------------------------------ function To_Object (Key : Object_Key) return Util.Beans.Objects.Object is begin case Key.Of_Type is when KEY_INTEGER => return Util.Beans.Objects.To_Object (Long_Long_Integer (Key.Id)); when KEY_STRING => return Util.Beans.Objects.To_Object (Key.Str); end case; end To_Object; -- ------------------------------ -- Increment the reference counter when an object is copied -- ------------------------------ overriding procedure Adjust (Object : in out Object_Ref) is begin if Object.Object /= null then Util.Concurrent.Counters.Increment (Object.Object.Counter); end if; end Adjust; -- ------------------------------ -- Decrement the reference counter and release the object record. -- ------------------------------ overriding procedure Finalize (Object : in out Object_Ref) is procedure Free is new Ada.Unchecked_Deallocation (Object => Object_Record'Class, Name => Object_Record_Access); Is_Zero : Boolean; begin if Object.Object /= null then Util.Concurrent.Counters.Decrement (Object.Object.Counter, Is_Zero); if Is_Zero then Free (Object.Object); end if; end if; end Finalize; -- ------------------------------ -- Mark the field identified by <b>Field</b> as modified. -- ------------------------------ procedure Set_Field (Object : in out Object_Ref'Class; Field : in Column_Index) is begin if Object.Object = null then Object.Allocate; Object.Object.Is_Loaded := True; elsif not Object.Object.Is_Loaded then Object.Lazy_Load; end if; Object.Object.Modified (Field) := True; end Set_Field; -- ------------------------------ -- Prepare the object to be modified. If the reference is empty, an object record -- instance is allocated by calling <b>Allocate</b>. -- ------------------------------ procedure Prepare_Modify (Object : in out Object_Ref'Class; Result : out Object_Record_Access) is begin if Object.Object = null then Object.Allocate; Object.Object.Is_Loaded := True; elsif not Object.Object.Is_Loaded then Object.Lazy_Load; end if; Result := Object.Object; end Prepare_Modify; -- ------------------------------ -- Check whether this object is initialized or not. -- ------------------------------ function Is_Null (Object : in Object_Ref'Class) return Boolean is begin return Object.Object = null; end Is_Null; -- ------------------------------ -- Check whether this object is saved in the database. -- Returns True if the object was saved in the database. -- ------------------------------ function Is_Inserted (Object : in Object_Ref'Class) return Boolean is begin if Object.Object = null then return False; else return Object.Object.Is_Created; end if; end Is_Inserted; -- ------------------------------ -- Check whether this object is loaded from the database. -- ------------------------------ function Is_Loaded (Object : in Object_Ref'Class) return Boolean is begin if Object.Object = null then return False; else return Object.Object.Is_Loaded; end if; end Is_Loaded; -- ------------------------------ -- Check if at least one field is modified and the object must be saved. -- ------------------------------ function Is_Modified (Object : in Object_Ref'Class) return Boolean is begin if Object.Object = null then return False; else return Object.Object.Is_Modified; end if; end Is_Modified; -- ------------------------------ -- Load the object from the database if it was not already loaded. -- For a lazy association, the <b>Object_Record</b> is allocated and holds the primary key. -- The <b>Is_Loaded</b> boolean is cleared thus indicating the other values are not loaded. -- This procedure makes sure these values are loaded by invoking <b>Load</b> if necessary. -- Raises Session_Error if the session associated with the object is closed. -- ------------------------------ procedure Lazy_Load (Ref : in Object_Ref'Class) is begin if Ref.Object = null then raise NULL_ERROR; elsif not Ref.Object.Is_Loaded then if Ref.Object.Session = null then raise ADO.Sessions.Session_Error; end if; if Ref.Object.Session.Session = null then raise ADO.Sessions.Session_Error; end if; declare S : ADO.Sessions.Session := ADO.Sessions.Factory.Get_Session (Ref.Object.Session.Session.all'Access); begin Ref.Object.Load (S); end; end if; end Lazy_Load; -- ------------------------------ -- Internal method to get the object record instance and make sure it is fully loaded. -- If the object was not yet loaded, calls <b>Lazy_Load</b> to get the values from the -- database. Raises Session_Error if the session associated with the object is closed. -- ------------------------------ function Get_Load_Object (Ref : in Object_Ref'Class) return Object_Record_Access is begin Ref.Lazy_Load; return Ref.Object; end Get_Load_Object; -- ------------------------------ -- Internal method to get the object record instance. -- ------------------------------ function Get_Object (Ref : in Object_Ref'Class) return Object_Record_Access is begin return Ref.Object; end Get_Object; -- ------------------------------ -- Get the object key -- ------------------------------ function Get_Key (Ref : in Object_Ref'Class) return Object_Key is begin return Ref.Object.Key; end Get_Key; -- ------------------------------ -- Set the object key. -- ------------------------------ procedure Set_Key_Value (Ref : in out Object_Ref'Class; Value : in Identifier; Session : in ADO.Sessions.Session'Class) is begin if Ref.Object = null then Ref.Allocate; end if; Ref.Object.Is_Created := True; Ref.Object.Set_Key_Value (Value); Ref.Object.Session := Session.Get_Session_Proxy; Util.Concurrent.Counters.Increment (Ref.Object.Session.Counter); end Set_Key_Value; -- ------------------------------ -- Set the object key. -- ------------------------------ procedure Set_Key_Value (Ref : in out Object_Ref'Class; Value : in Ada.Strings.Unbounded.Unbounded_String; Session : in ADO.Sessions.Session'Class) is begin if Ref.Object = null then Ref.Allocate; end if; Ref.Object.Is_Created := True; Ref.Object.Set_Key_Value (Value); Ref.Object.Session := Session.Get_Session_Proxy; Util.Concurrent.Counters.Increment (Ref.Object.Session.Counter); end Set_Key_Value; -- ------------------------------ -- Check if the two objects are the same database objects. -- The comparison is only made on the primary key. -- Returns true if the two objects have the same primary key. -- ------------------------------ function "=" (Left : Object_Ref; Right : Object_Ref) return Boolean is begin -- Same target object if Left.Object = Right.Object then return True; end if; -- One of the target object is null if Left.Object = null or Right.Object = null then return False; end if; return Left.Object.Key = Right.Object.Key; end "="; procedure Set_Object (Ref : in out Object_Ref'Class; Object : in Object_Record_Access) is Is_Zero : Boolean; begin if Ref.Object /= null and Ref.Object /= Object then Util.Concurrent.Counters.Decrement (Ref.Object.Counter, Is_Zero); if Is_Zero then Destroy (Ref.Object); end if; end if; Ref.Object := Object; end Set_Object; procedure Set_Object (Ref : in out Object_Ref'Class; Object : in Object_Record_Access; Session : in ADO.Sessions.Session'Class) is begin if Object /= null and then Object.Session = null then Object.Session := Session.Get_Session_Proxy; Util.Concurrent.Counters.Increment (Object.Session.Counter); end if; Ref.Set_Object (Object); end Set_Object; -- ------------------------------ -- Get the object primary key in a bean object. -- ------------------------------ function To_Object (Object : in Object_Ref'Class) return Util.Beans.Objects.Object is begin if Object.Object = null then return Util.Beans.Objects.Null_Object; else return To_Object (Object.Object.Get_Key); end if; end To_Object; -- ------------------------------ -- Get the object key -- ------------------------------ function Get_Key (Ref : in Object_Record'Class) return Object_Key is begin return Ref.Key; end Get_Key; -- ------------------------------ -- Set the object key -- ------------------------------ procedure Set_Key (Ref : in out Object_Record'Class; Key : in Object_Key) is begin Ref.Key := Key; end Set_Key; -- ------------------------------ -- Get the object key value as an identifier -- ------------------------------ function Get_Key_Value (Ref : in Object_Record'Class) return Identifier is begin return Ref.Key.Id; end Get_Key_Value; function Get_Key_Value (Ref : in Object_Record'Class) return Ada.Strings.Unbounded.Unbounded_String is begin return Ref.Key.Str; end Get_Key_Value; procedure Set_Key_Value (Ref : in out Object_Record'Class; Value : in Identifier) is begin Set_Value (Ref.Key, Value); end Set_Key_Value; procedure Set_Key_Value (Ref : in out Object_Record'Class; Value : in Ada.Strings.Unbounded.Unbounded_String) is begin Ref.Key.Str := Value; end Set_Key_Value; procedure Set_Key_Value (Ref : in out Object_Record'Class; Value : in String) is begin Ref.Key.Str := Ada.Strings.Unbounded.To_Unbounded_String (Value); end Set_Key_Value; -- ------------------------------ -- Get the table name associated with the object record. -- ------------------------------ function Get_Table_Name (Ref : in Object_Record'Class) return Util.Strings.Name_Access is begin if Ref.Key.Of_Class = null then return null; else return Ref.Key.Of_Class.Table; end if; end Get_Table_Name; -- ------------------------------ -- Check if this is a new object. -- Returns True if an insert is necessary to persist this object. -- ------------------------------ function Is_Created (Ref : in Object_Record'Class) return Boolean is begin return Ref.Is_Created; end Is_Created; -- ------------------------------ -- Mark the object as created in the database. -- ------------------------------ procedure Set_Created (Ref : in out Object_Record'Class) is begin Ref.Is_Created := True; Ref.Is_Loaded := True; Ref.Modified := (others => False); end Set_Created; -- ------------------------------ -- Check if at least one field is modified and the object must be saved. -- ------------------------------ function Is_Modified (Ref : in Object_Record'Class) return Boolean is begin return (for some Modified_Field of Ref.Modified => Modified_Field); end Is_Modified; -- ------------------------------ -- Check if the field at position <b>Field</b> was modified. -- ------------------------------ function Is_Modified (Ref : in Object_Record'Class; Field : in Column_Index) return Boolean is begin return Ref.Modified (Field); end Is_Modified; -- ------------------------------ -- Clear the modification flag associated with the field at -- position <b>Field</b>. -- ------------------------------ procedure Clear_Modified (Ref : in out Object_Record'Class; Field : in Column_Index) is begin Ref.Modified (Field) := False; end Clear_Modified; -- ------------------------------ -- Release the session proxy, deleting the instance if it is no longer used. -- The <tt>Detach</tt> parameter controls whether the session proxy must be detached -- from the database session. When set, the session proxy is no longer linked to the -- database session and trying to load the lazy object will raise the Session_Error -- exception. -- ------------------------------ procedure Release_Proxy (Proxy : in out Session_Proxy_Access; Detach : in Boolean := False) is procedure Free is new Ada.Unchecked_Deallocation (Object => Session_Proxy, Name => Session_Proxy_Access); Is_Zero : Boolean; begin if Proxy /= null then Util.Concurrent.Counters.Decrement (Proxy.Counter, Is_Zero); if Detach then Proxy.Session := null; end if; if Is_Zero then Free (Proxy); end if; Proxy := null; end if; end Release_Proxy; -- ------------------------------ -- Release the object. -- ------------------------------ overriding procedure Finalize (Object : in out Object_Record) is begin Release_Proxy (Object.Session); end Finalize; -- ------------------------------ -- Copy the source object record into the target. -- ------------------------------ procedure Copy (To : in out Object_Record; From : in Object_Record'Class) is begin To.Session := From.Session; To.Is_Created := From.Is_Created; To.Is_Loaded := From.Is_Loaded; To.Modified := From.Modified; To.Key := From.Key; end Copy; function Create_Session_Proxy (S : access ADO.Sessions.Session_Record) return Session_Proxy_Access is Result : constant Session_Proxy_Access := new Session_Proxy; begin Result.Session := S; return Result; end Create_Session_Proxy; -- ------------------------------ -- Set the object field to the new value in <b>Into</b>. If the new value is identical, -- the operation does nothing. Otherwise, the new value <b>Value</b> is copied -- to <b>Into</b> and the field identified by <b>Field</b> is marked as modified on -- the object. -- ------------------------------ procedure Set_Field_Unbounded_String (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out Ada.Strings.Unbounded.Unbounded_String; Value : in Ada.Strings.Unbounded.Unbounded_String) is use Ada.Strings.Unbounded; begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Unbounded_String; procedure Set_Field_String (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out Ada.Strings.Unbounded.Unbounded_String; Value : in String) is use Ada.Strings.Unbounded; begin if Into /= Value then Ada.Strings.Unbounded.Set_Unbounded_String (Into, Value); Object.Modified (Field) := True; end if; end Set_Field_String; procedure Set_Field_String (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out ADO.Nullable_String; Value : in String) is use Ada.Strings.Unbounded; begin if Into.Is_Null or else Into.Value /= Value then Into.Is_Null := False; Ada.Strings.Unbounded.Set_Unbounded_String (Into.Value, Value); Object.Modified (Field) := True; end if; end Set_Field_String; procedure Set_Field_String (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out ADO.Nullable_String; Value : in ADO.Nullable_String) is use Ada.Strings.Unbounded; begin if Into.Is_Null then if not Value.Is_Null then Into := Value; Object.Modified (Field) := True; end if; elsif Value.Is_Null then Into.Is_Null := True; Object.Modified (Field) := True; elsif Into.Value /= Value.Value then Into.Value := Value.Value; Object.Modified (Field) := True; end if; end Set_Field_String; procedure Set_Field_Time (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out Ada.Calendar.Time; Value : in Ada.Calendar.Time) is use Ada.Calendar; begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Time; procedure Set_Field_Time (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out ADO.Nullable_Time; Value : in ADO.Nullable_Time) is use Ada.Calendar; begin if Into.Is_Null then if not Value.Is_Null then Into := Value; Object.Modified (Field) := True; end if; elsif Value.Is_Null then Into.Is_Null := True; Object.Modified (Field) := True; elsif Into.Value /= Value.Value then Into.Value := Value.Value; Object.Modified (Field) := True; end if; end Set_Field_Time; procedure Set_Field_Integer (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out Integer; Value : in Integer) is begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Integer; procedure Set_Field_Integer (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out ADO.Nullable_Integer; Value : in ADO.Nullable_Integer) is begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Integer; procedure Set_Field_Natural (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out Natural; Value : in Natural) is begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Natural; procedure Set_Field_Positive (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out Positive; Value : in Positive) is begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Positive; procedure Set_Field_Boolean (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out Boolean; Value : in Boolean) is begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Boolean; procedure Set_Field_Boolean (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out Nullable_Boolean; Value : in Nullable_Boolean) is begin if Into.Is_Null then if not Value.Is_Null then Into := Value; Object.Modified (Field) := True; end if; elsif Value.Is_Null then Into.Is_Null := True; Object.Modified (Field) := True; elsif Into.Value /= Value.Value then Into.Value := Value.Value; Object.Modified (Field) := True; end if; end Set_Field_Boolean; procedure Set_Field_Float (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out Float; Value : in Float) is begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Float; procedure Set_Field_Long_Float (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out Long_Float; Value : in Long_Float) is begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Long_Float; procedure Set_Field_Object (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out Object_Ref'Class; Value : in Object_Ref'Class) is begin if Into.Object /= Value.Object then Set_Object (Into, Value.Object); if Into.Object /= null then Util.Concurrent.Counters.Increment (Into.Object.Counter); end if; Object.Modified (Field) := True; end if; end Set_Field_Object; procedure Set_Field_Identifier (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out ADO.Identifier; Value : in ADO.Identifier) is begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Identifier; procedure Set_Field_Entity_Type (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out ADO.Entity_Type; Value : in ADO.Entity_Type) is begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Entity_Type; procedure Set_Field_Entity_Type (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out ADO.Nullable_Entity_Type; Value : in ADO.Nullable_Entity_Type) is begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Entity_Type; procedure Set_Field_Blob (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out ADO.Blob_Ref; Value : in ADO.Blob_Ref) is use type ADO.Blob_Ref; begin if Value /= Into then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Blob; procedure Set_Field_Key_Value (Object : in out Object_Record'Class; Field : in Column_Index; Value : in ADO.Identifier) is begin if Object.Get_Key_Value /= Value then Set_Key_Value (Object, Value); Object.Modified (Field) := True; end if; end Set_Field_Key_Value; procedure Set_Field_Key_Value (Object : in out Object_Record'Class; Field : in Column_Index; Value : in String) is use Ada.Strings.Unbounded; begin if Object.Key.Str /= Value then Set_Key_Value (Object, Value); Object.Modified (Field) := True; end if; end Set_Field_Key_Value; procedure Set_Field_Key_Value (Object : in out Object_Record'Class; Field : in Column_Index; Value : in Ada.Strings.Unbounded.Unbounded_String) is use Ada.Strings.Unbounded; begin if Object.Key.Str /= Value then Set_Key_Value (Object, Value); Object.Modified (Field) := True; end if; end Set_Field_Key_Value; procedure Set_Field_Operation (Object : in out Object_Record'Class; Field : in Column_Index; Into : in out T; Value : in T) is begin if Into /= Value then Into := Value; Object.Modified (Field) := True; end if; end Set_Field_Operation; -- ------------------------------ -- Mark the field identified by <b>Field</b> as modified. -- ------------------------------ procedure Set_Field (Object : in out Object_Record'Class; Field : in Column_Index) is begin Object.Modified (Field) := True; end Set_Field; end ADO.Objects;
-- -- The author disclaims copyright to this source code. In place of -- a legal notice, here is a blessing: -- -- May you do good and not evil. -- May you find forgiveness for yourself and forgive others. -- May you share freely, not taking more than you give. -- with Ada.Text_IO; with AWS.Config; with AWS.Server.Log; with AWS.Services.Page_Server; package body Web_Server is Server : AWS.Server.HTTP; procedure Startup is Config : constant AWS.Config.Object := AWS.Config.Get_Current; begin if AWS.Config.Directory_Browser_Page (Config) /= "" then AWS.Services.Page_Server.Directory_Browsing (True); end if; if AWS.Config.Log_Filename_Prefix (Config) /= "" then AWS.Server.Log.Start (Server); end if; if AWS.Config.Error_Log_Filename_Prefix (Config) /= "" then AWS.Server.Log.Start_Error (Server); end if; AWS.Server.Start (Web_Server => Server, Dispatcher => Virtual_Hosts.Dispatcher, Config => Config); end Startup; procedure Work_Until_Stopped is use AWS.Server; begin Wait (Forever); end Work_Until_Stopped; procedure Shutdown is begin Ada.Text_IO.Put_Line ("AWS server shutdown in progress."); AWS.Server.Shutdown (Server); end Shutdown; end Web_Server;
-- -- The author disclaims copyright to this source code. In place of -- a legal notice, here is a blessing: -- -- May you do good and not evil. -- May you find forgiveness for yourself and forgive others. -- May you share freely, not taking more than you give. -- with GNAT.Strings; with Setup; package Options is Show_Version : aliased Boolean; Show_Help : aliased Boolean; Be_Quiet : aliased Boolean; Default_Host_List_File : constant String := Setup.Get_Program_Name & ".hosts"; Default_TCP_IP_Port : constant String := "8080"; use GNAT.Strings; Web_Dir_Base : aliased String_Access := new String'(""); Host_List_File : aliased String_Access := new String'(Default_Host_List_File); TCP_IP_Port : aliased String_Access := new String'(Default_TCP_IP_Port); end Options;
-- This file is covered by the Internet Software Consortium (ISC) License -- Reference: ../License.txt with Ada.Exceptions; with Ada.Directories; with Ada.Containers.Vectors; with Ada.Characters.Latin_1; with File_Operations; with Parameters; with Signals; with Unix; package body Replicant is package EX renames Ada.Exceptions; package PM renames Parameters; package CON renames Ada.Containers; package DIR renames Ada.Directories; package LAT renames Ada.Characters.Latin_1; package FOP renames File_Operations; -------------------------------------------------------------------------------------------- -- initialize -------------------------------------------------------------------------------------------- procedure initialize (testmode : Boolean) is raven_sysroot : constant String := HT.USS (PM.configuration.dir_sysroot); mm : constant String := get_master_mount; sretc : constant String := raven_sysroot & "/usr/share"; maspas : constant String := "/master.passwd"; passwd : constant String := "/passwd"; spwd : constant String := "/spwd.db"; pwd : constant String := "/pwd.db"; rcconf : constant String := "/rc.conf"; hints : constant String := "/ld-elf.so.hints"; nhints : constant String := "/ld.so.hints"; group : constant String := "/group"; ldcnf1 : constant String := "/x86_64-linux-gnu.conf"; ldcnf2 : constant String := "/ld.so.conf"; begin developer_mode := testmode; ravenbase := PM.configuration.dir_localbase; start_abnormal_logging; DIR.Create_Path (mm); case platform_type is when dragonfly | freebsd | macos | netbsd | openbsd => DIR.Copy_File (sretc & passwd, mm & passwd); DIR.Copy_File (sretc & maspas, mm & maspas); DIR.Copy_File (sretc & group, mm & group); when linux | sunos => DIR.Copy_File (sretc & passwd, mm & passwd); DIR.Copy_File (sretc & group, mm & group); end case; case platform_type is when dragonfly | freebsd | netbsd | openbsd => DIR.Copy_File (sretc & spwd, mm & spwd); DIR.Copy_File (sretc & pwd, mm & pwd); when linux | macos | sunos => null; -- pwd.db not used end case; case platform_type is when dragonfly | freebsd | netbsd | openbsd => DIR.Copy_File (sretc & rcconf, mm & rcconf); when linux | macos | sunos => null; -- rc.conf not used end case; case platform_type is when dragonfly => DIR.Copy_File (sretc & hints, mm & hints); when freebsd => DIR.Copy_File (sretc & hints, mm & hints); when netbsd | openbsd => DIR.Copy_File (sretc & nhints, mm & nhints); when linux => DIR.Copy_File (sretc & ldcnf1, mm & ldcnf1); DIR.Copy_File (sretc & ldcnf2, mm & ldcnf2); when macos | sunos => null; end case; create_mtree_exc_preinst (mm); create_mtree_exc_preconfig (mm); end initialize; -------------------------------------------------------------------------------------------- -- finalize -------------------------------------------------------------------------------------------- procedure finalize is mm : constant String := get_master_mount; begin if DIR.Exists (mm) then annihilate_directory_tree (mm); end if; stop_abnormal_logging; end finalize; -------------------------------------------------------------------------------------------- -- get_master_mount -------------------------------------------------------------------------------------------- function get_master_mount return String is begin return HT.USS (PM.configuration.dir_buildbase) & "/" & reference_base; end get_master_mount; -------------------------------------------------------------------------------------------- -- get_slave_mount -------------------------------------------------------------------------------------------- function get_slave_mount (id : builders) return String is begin return HT.USS (PM.configuration.dir_buildbase) & "/" & slave_name (id); end get_slave_mount; -------------------------------------------------------------------------------------------- -- start_abnormal_logging -------------------------------------------------------------------------------------------- procedure start_abnormal_logging is logpath : constant String := HT.USS (PM.configuration.dir_logs) & "/logs/" & abnormal_cmd_logname; begin if DIR.Exists (logpath) then DIR.Delete_File (logpath); end if; TIO.Create (File => abnormal_log, Mode => TIO.Out_File, Name => logpath); abn_log_ready := True; exception when others => abn_log_ready := False; end start_abnormal_logging; -------------------------------------------------------------------------------------------- -- stop_abnormal_logging -------------------------------------------------------------------------------------------- procedure stop_abnormal_logging is begin if abn_log_ready then TIO.Close (abnormal_log); end if; end stop_abnormal_logging; -------------------------------------------------------------------------------------------- -- annihilate_directory_tree -------------------------------------------------------------------------------------------- procedure annihilate_directory_tree (tree : String) is command : constant String := "/bin/rm -rf " & tree; retry : Boolean := False; begin silent_exec (command); exception when others => -- Only can occur when tmpfs is avoided if DIR.Exists (tree & "/home") then folder_access (tree & "/home", unlock); retry := True; end if; if DIR.Exists (tree & "/root") then folder_access (tree & "/root", unlock); retry := True; end if; if retry then silent_exec (command); else raise scenario_unexpected with "annihilate_directory_tree " & tree & " failed"; end if; end annihilate_directory_tree; -------------------------------------------------------------------------------------------- -- annihilate_directory_tree_contents -------------------------------------------------------------------------------------------- procedure annihilate_directory_tree_contents (tree : String) is command : constant String := "/usr/bin/find -s " & tree & " -depth 1 -maxdepth 1 -exec /bin/rm -rf {} \;"; begin silent_exec (command); end annihilate_directory_tree_contents; -------------------------------------------------------------------------------------------- -- execute -------------------------------------------------------------------------------------------- procedure execute (command : String) is Exit_Status : Integer; output : HT.Text := Unix.piped_command (command, Exit_Status); begin if abn_log_ready and then not HT.IsBlank (output) then TIO.Put_Line (abnormal_log, HT.USS (output)); end if; if Exit_Status /= 0 then raise scenario_unexpected with command & " => failed with code" & Exit_Status'Img; end if; end execute; -------------------------------------------------------------------------------------------- -- silent_exec -------------------------------------------------------------------------------------------- procedure silent_exec (command : String) is cmd_output : HT.Text; success : Boolean := Unix.piped_mute_command (command, cmd_output); begin if not success then if abn_log_ready and then not HT.IsBlank (cmd_output) then TIO.Put_Line (abnormal_log, "piped_mute_command failure:"); TIO.Put_Line (abnormal_log, HT.USS (cmd_output)); end if; raise scenario_unexpected with command & " => failed (exit code not 0)"; end if; end silent_exec; -------------------------------------------------------------------------------------------- -- append_abnormal_log -------------------------------------------------------------------------------------------- procedure append_abnormal_log (line : String) is begin TIO.Put_Line (abnormal_log, line); end append_abnormal_log; -------------------------------------------------------------------------------------------- -- internal_system_command -------------------------------------------------------------------------------------------- function internal_system_command (command : String) return HT.Text is content : HT.Text; status : Integer; begin content := Unix.piped_command (command, status); if status /= 0 then raise scenario_unexpected with "cmd: " & command & " (return code =" & status'Img & ")"; end if; return content; end internal_system_command; -------------------------------------------------------------------------------------------- -- specific_mount_exists -------------------------------------------------------------------------------------------- function specific_mount_exists (mount_point : String) return Boolean is comres : constant String := HT.USS (internal_system_command (df_command)); markers : HT.Line_Markers; begin HT.initialize_markers (comres, markers); loop exit when not HT.next_line_present (comres, markers); declare line : constant String := HT.extract_line (comres, markers); begin if HT.contains (line, mount_point) then return True; end if; end; end loop; return False; exception when others => return True; end specific_mount_exists; -------------------------------------------------------------------------------------------- -- ravenadm_mounts_exist -------------------------------------------------------------------------------------------- function ravenadm_mounts_exist return Boolean is buildbase : constant String := HT.USS (PM.configuration.dir_buildbase); comres : constant String := HT.USS (internal_system_command (df_command)); markers : HT.Line_Markers; begin HT.initialize_markers (comres, markers); loop exit when not HT.next_line_present (comres, markers); declare line : constant String := HT.extract_line (comres, markers); begin if HT.contains (line, buildbase) then return True; end if; end; end loop; return False; exception when others => return True; end ravenadm_mounts_exist; -------------------------------------------------------------------------------------------- -- clear_existing_mounts -------------------------------------------------------------------------------------------- function clear_existing_mounts return Boolean is package crate is new CON.Vectors (Index_Type => Positive, Element_Type => HT.Text, "=" => HT.SU."="); procedure annihilate (cursor : crate.Cursor); buildbase : constant String := HT.USS (PM.configuration.dir_buildbase); comres : constant String := HT.USS (internal_system_command (df_command)); markers : HT.Line_Markers; mpoints : crate.Vector; procedure annihilate (cursor : crate.Cursor) is mountpoint : constant String := HT.USS (crate.Element (cursor)); begin unmount (mountpoint); if DIR.Exists (mountpoint) then DIR.Delete_Directory (mountpoint); end if; exception when others => null; end annihilate; begin HT.initialize_markers (comres, markers); loop exit when not HT.next_line_present (comres, markers); declare line : constant String := HT.extract_line (comres, markers); mindex : Natural; begin mindex := HT.start_index (line, buildbase); if mindex > 0 then mpoints.Append (HT.SUS (line (mindex .. line'Last))); end if; end; end loop; mpoints.Reverse_Iterate (Process => annihilate'Access); if ravenadm_mounts_exist then return False; end if; -- No need to remove empty dirs, the upcoming run will do that. return True; end clear_existing_mounts; -------------------------------------------------------------------------------------------- -- disk_workareas_exist -------------------------------------------------------------------------------------------- function disk_workareas_exist return Boolean is Search : DIR.Search_Type; buildbase : constant String := HT.USS (PM.configuration.dir_buildbase); result : Boolean := False; begin if not DIR.Exists (buildbase) then return False; end if; if DIR.Exists (buildbase & "/Base") then return True; end if; -- SLXX may be present if tmpfs is avoided DIR.Start_Search (Search => Search, Directory => buildbase, Filter => (DIR.Directory => True, others => False), Pattern => "SL*"); result := DIR.More_Entries (Search => Search); DIR.End_Search (Search); return result; end disk_workareas_exist; -------------------------------------------------------------------------------------------- -- clear_existing_workareas -------------------------------------------------------------------------------------------- function clear_existing_workareas return Boolean is Search : DIR.Search_Type; Dir_Ent : DIR.Directory_Entry_Type; buildbase : constant String := HT.USS (PM.configuration.dir_buildbase); base : constant String := buildbase & "/Base"; begin if DIR.Exists (base) then annihilate_directory_tree (base); end if; -- SLXX may be present if tmpfs is avoided DIR.Start_Search (Search => Search, Directory => buildbase, Filter => (DIR.Directory => True, others => False), Pattern => "SL*"); while DIR.More_Entries (Search => Search) loop DIR.Get_Next_Entry (Search => Search, Directory_Entry => Dir_Ent); declare target : constant String := buildbase & "/" & DIR.Simple_Name (Dir_Ent); begin annihilate_directory_tree (target); end; end loop; DIR.End_Search (Search); return True; exception when others => return False; end clear_existing_workareas; -------------------------------------------------------------------------------------------- -- create_mtree_exc_preinst -------------------------------------------------------------------------------------------- procedure create_mtree_exc_preinst (path_to_mm : String) is mtreefile : TIO.File_Type; filename : constant String := path_to_mm & "/mtree.prestage.exclude"; begin TIO.Create (File => mtreefile, Mode => TIO.Out_File, Name => filename); write_common_mtree_exclude_base (mtreefile); write_preinstall_section (mtreefile); TIO.Close (mtreefile); end create_mtree_exc_preinst; -------------------------------------------------------------------------------------------- -- create_mtree_exc_preconfig -------------------------------------------------------------------------------------------- procedure create_mtree_exc_preconfig (path_to_mm : String) is mtreefile : TIO.File_Type; filename : constant String := path_to_mm & "/mtree.preconfig.exclude"; begin TIO.Create (File => mtreefile, Mode => TIO.Out_File, Name => filename); write_common_mtree_exclude_base (mtreefile); TIO.Close (mtreefile); end create_mtree_exc_preconfig; -------------------------------------------------------------------------------------------- -- write_common_mtree_exclude_base -------------------------------------------------------------------------------------------- procedure write_common_mtree_exclude_base (mtreefile : TIO.File_Type) is function write_usr return String; function opsys_specific return String; RB : String := LAT.Full_Stop & HT.USS (ravenbase); function write_usr return String is begin if HT.equivalent (ravenbase, bsd_localbase) then return "./usr/bin" & LAT.LF & "./usr/include" & LAT.LF & "./usr/lib" & LAT.LF & "./usr/lib32" & LAT.LF & "./usr/share" & LAT.LF; else return "./usr" & LAT.LF; end if; end write_usr; function opsys_specific return String is begin case platform_type is when freebsd | dragonfly | netbsd | openbsd => return "./libexec" & LAT.LF; when linux => return "./lib" & LAT.LF & "./lib64" & LAT.LF; when sunos => return "./lib" & LAT.LF & "./devices" & LAT.LF; when macos => return "./System" & LAT.LF; end case; end opsys_specific; begin TIO.Put_Line (mtreefile, "./bin" & LAT.LF & "./ccache" & LAT.LF & "./construction" & LAT.LF & "./dev" & LAT.LF & "./distfiles" & LAT.LF & "./home" & LAT.LF & "./packages" & LAT.LF & "./port" & LAT.LF & "./proc" & LAT.LF & "./root" & LAT.LF & "./tmp" & LAT.LF & write_usr & opsys_specific & "./var/db/rvnfontconfig" & LAT.LF & "./var/run" & LAT.LF & "./var/tmp" & LAT.LF & "./xports" & LAT.LF & RB & "/toolchain" ); end write_common_mtree_exclude_base; -------------------------------------------------------------------------------------------- -- write_preinstall_section -------------------------------------------------------------------------------------------- procedure write_preinstall_section (mtreefile : TIO.File_Type) is RB : String := LAT.Full_Stop & HT.USS (ravenbase); begin TIO.Put_Line (mtreefile, "./etc/group" & LAT.LF & "./etc/make.conf" & LAT.LF & "./etc/make.conf.bak" & LAT.LF & "./etc/make.nxb.conf" & LAT.LF & "./etc/master.passwd" & LAT.LF & "./etc/passwd" & LAT.LF & "./etc/pwd.db" & LAT.LF & "./etc/shells" & LAT.LF & "./etc/spwd.db" & LAT.LF & "./etc/ld.so.conf.d/x86_64-linux-gnu.conf" & LAT.LF & "./var/db" & LAT.LF & "./var/log" & LAT.LF & "./var/mail" & LAT.LF & "./var/spool" & LAT.LF & "./var/tmp" & LAT.LF & RB & "/etc/gconf/gconf.xml.defaults/%gconf-tree*.xml" & LAT.LF & RB & "/lib/gio/modules/giomodule.cache" & LAT.LF & RB & "/share/info/dir" & LAT.LF & RB & "/share/info" & LAT.LF & RB & "/share/*/info/dir" & LAT.LF & RB & "/share/*/info" & LAT.LF & RB & "/*/ls-R" & LAT.LF & RB & "/share/octave/octave_packages" & LAT.LF & RB & "/share/xml/catalog.ports" ); end write_preinstall_section; -------------------------------------------------------------------------------------------- -- df_command -------------------------------------------------------------------------------------------- function df_command return String is begin case platform_type is when freebsd | macos => return "/bin/df -h"; when dragonfly | netbsd | openbsd => return "/bin/df -h -t null,tmpfs,devfs,procfs"; when sunos => return "/usr/sbin/df -h"; when linux => return "/bin/df -h -a"; end case; end df_command; -------------------------------------------------------------------------------------------- -- unmount -------------------------------------------------------------------------------------------- procedure unmount (device_or_node : String; retry_times : Natural := 0) is bsd_command : constant String := "/sbin/umount " & device_or_node; sol_command : constant String := "/usr/sbin/umount " & device_or_node; lin_command : constant String := "/bin/umount " & device_or_node; counter : Natural := 0; success : Boolean := False; begin -- failure to unmount causes stderr squawks which messes up curses display -- Just log it and ignore for now (Add robustness later) loop begin exit when counter > retry_times; case platform_type is when dragonfly | freebsd | macos | netbsd | openbsd => execute (bsd_command); when linux => execute (lin_command); when sunos => execute (sol_command); end case; success := True; exit; exception when others => counter := counter + 1; delay 10.0; end; end loop; if not success then raise failed_unmount with device_or_node; end if; end unmount; -------------------------------------------------------------------------------------------- -- mount_nullfs -------------------------------------------------------------------------------------------- procedure mount_nullfs (target, mount_point : String; mode : mount_mode := readonly) is cmd_freebsd : constant String := "/sbin/mount_nullfs"; cmd_dragonfly : constant String := "/sbin/mount_null"; cmd_solaris : constant String := "/sbin/mount -F lofs"; cmd_linux : constant String := "/bin/mount --bind"; cmd_macos : constant String := "/sbin/mount -t nfs"; cmd_openbsd : constant String := "/sbin/mount_nfs"; command : HT.Text; begin if not DIR.Exists (mount_point) then raise scenario_unexpected with "mount point " & mount_point & " does not exist"; end if; if not DIR.Exists (target) then raise scenario_unexpected with "mount target " & target & " does not exist"; end if; case platform_type is when freebsd => command := HT.SUS (cmd_freebsd); when dragonfly | netbsd => command := HT.SUS (cmd_dragonfly); when sunos => command := HT.SUS (cmd_solaris); when linux => command := HT.SUS (cmd_linux); when macos => command := HT.SUS (cmd_macos); when openbsd => command := HT.SUS (cmd_openbsd); end case; case mode is when readonly => HT.SU.Append (command, " -o ro"); when readwrite => null; end case; case platform_type is when macos | openbsd => execute (HT.USS (command) & " 127.0.0.1:" & target & " " & mount_point); when others => execute (HT.USS (command) & " " & target & " " & mount_point); end case; end mount_nullfs; -------------------------------------------------------------------------------------------- -- mount_tmpfs -------------------------------------------------------------------------------------------- procedure mount_tmpfs (mount_point : String; max_size_M : Natural := 0) is cmd_freebsd : constant String := "/sbin/mount -t tmpfs"; cmd_dragonfly : constant String := "/sbin/mount_tmpfs"; cmd_solaris : constant String := "/sbin/mount -F tmpfs"; cmd_linux : constant String := "/bin/mount -t tmpfs"; command : HT.Text; begin case platform_type is when freebsd | netbsd => command := HT.SUS (cmd_freebsd); when dragonfly => command := HT.SUS (cmd_dragonfly); when sunos => command := HT.SUS (cmd_solaris); when linux => command := HT.SUS (cmd_linux); when macos | -- Not available at all openbsd => -- Was available, disabled on OpenBSD 6.0 (no maintenance) raise scenario_unexpected with "tmpfs not supported on " & platform_type'Img; end case; if max_size_M > 0 then HT.SU.Append (command, " -o size=" & HT.trim (max_size_M'Img) & "M"); end if; case platform_type is when sunos => HT.SU.Append (command, " swap " & mount_point); when freebsd | dragonfly | netbsd | linux => HT.SU.Append (command, " tmpfs " & mount_point); when macos => null; when openbsd => null; end case; execute (HT.USS (command)); end mount_tmpfs; -------------------------------------------------------------------------------------------- -- mount_devices -------------------------------------------------------------------------------------------- procedure mount_devices (path_to_dev : String) is bsd_command : constant String := "/sbin/mount -t devfs devfs " & path_to_dev; lin_command : constant String := "/bin/mount --bind /dev " & path_to_dev; begin case platform_type is when dragonfly | freebsd | macos => execute (bsd_command); when linux => execute (lin_command); when netbsd | openbsd | sunos => mount_nullfs (target => "/dev", mount_point => path_to_dev); end case; end mount_devices; -------------------------------------------------------------------------------------------- -- unmount_devices -------------------------------------------------------------------------------------------- procedure unmount_devices (path_to_dev : String) is begin unmount (path_to_dev); end unmount_devices; -------------------------------------------------------------------------------------------- -- mount_procfs -------------------------------------------------------------------------------------------- procedure mount_procfs (path_to_proc : String) is bsd_command : constant String := "/sbin/mount -t procfs proc " & path_to_proc; net_command : constant String := "/sbin/mount_procfs /proc " & path_to_proc; lin_command : constant String := "/bin/mount --bind /proc " & path_to_proc; begin case platform_type is when dragonfly | freebsd => execute (bsd_command); when netbsd | openbsd => execute (net_command); when linux => execute (lin_command); when sunos => mount_nullfs (target => "/proc", mount_point => path_to_proc); when macos => raise scenario_unexpected with "procfs not supported on " & platform_type'Img; end case; end mount_procfs; -------------------------------------------------------------------------------------------- -- unmount_procfs -------------------------------------------------------------------------------------------- procedure unmount_procfs (path_to_proc : String) is begin unmount (path_to_proc); end unmount_procfs; -------------------------------------------------------------------------------------------- -- mount_hardlink -------------------------------------------------------------------------------------------- procedure mount_hardlink (target, mount_point, sysroot : String) is find_program : constant String := sysroot & "/usr/bin/find "; copy_program : constant String := sysroot & "/bin/cp -RpPl "; chmod_program : constant String := sysroot & "/bin/chmod "; begin if DIR.Exists (mount_point) then DIR.Delete_Directory (mount_point); end if; execute (copy_program & target & " " & mount_point); execute (find_program & mount_point & " -type d -exec " & chmod_program & "555 {} +"); end mount_hardlink; -------------------------------------------------------------------------------------------- -- mount_fullcopy -------------------------------------------------------------------------------------------- procedure mount_fullcopy (target, mount_point, sysroot : String) is find_program : constant String := sysroot & "/usr/bin/find "; copy_program : constant String := sysroot & "/bin/cp -RpP "; chmod_program : constant String := sysroot & "/bin/chmod "; begin if DIR.Exists (mount_point) then DIR.Delete_Directory (mount_point); end if; execute (copy_program & target & " " & mount_point); execute (find_program & mount_point & " -type d -exec " & chmod_program & "555 {} +"); end mount_fullcopy; -------------------------------------------------------------------------------------------- -- location -------------------------------------------------------------------------------------------- function location (mount_base : String; point : folder) return String is begin case point is when bin => return mount_base & root_bin; when usr => return mount_base & root_usr; when dev => return mount_base & root_dev; when etc => return mount_base & root_etc; when etc_default => return mount_base & root_etc_default; when etc_rcd => return mount_base & root_etc_rcd; when etc_ldsocnf => return mount_base & root_etc_ldsocnf; when tmp => return mount_base & root_tmp; when var => return mount_base & root_var; when home => return mount_base & root_home; when proc => return mount_base & root_proc; when root => return mount_base & root_root; when xports => return mount_base & root_xports; when port => return mount_base & root_port; when lib => return mount_base & root_lib; when lib64 => return mount_base & root_lib64; when libexec => return mount_base & root_libexec; when packages => return mount_base & root_packages; when distfiles => return mount_base & root_distfiles; when wrkdirs => return mount_base & root_wrkdirs; when ccache => return mount_base & root_ccache; when devices => return mount_base & root_devices; when frameworks => return mount_base & root_frameworks; when localbase => return mount_base & HT.USS (PM.configuration.dir_localbase); when toolchain => return mount_base & HT.USS (PM.configuration.dir_localbase) & toolchain_dir; end case; end location; -------------------------------------------------------------------------------------------- -- mount_target -------------------------------------------------------------------------------------------- function mount_target (point : folder) return String is begin case point is when xports => return HT.USS (PM.configuration.dir_conspiracy); when packages => return HT.USS (PM.configuration.dir_packages); when toolchain => return HT.USS (PM.configuration.dir_toolchain); when distfiles => return HT.USS (PM.configuration.dir_distfiles); when ccache => return HT.USS (PM.configuration.dir_ccache); when others => return "ERROR"; end case; end mount_target; -------------------------------------------------------------------------------------------- -- forge_directory -------------------------------------------------------------------------------------------- procedure forge_directory (target : String) is begin DIR.Create_Path (New_Directory => target); exception when failed : others => TIO.Put_Line (EX.Exception_Information (failed)); raise scenario_unexpected with "failed to create " & target & " directory"; end forge_directory; -------------------------------------------------------------------------------------------- -- folder_access -------------------------------------------------------------------------------------------- procedure folder_access (path : String; operation : folder_operation) is -- chattr does not work on tmpfs partitions -- It appears immutable locking can't be supported on Linux -- Don't use chflags schg on *BSD as securitylevel > 0 (BSD) will block it cmd_fallback : constant String := "/bin/chmod"; fback_lock : constant String := " 555 "; fback_unlock : constant String := " 755 "; command : HT.Text := HT.SUS (cmd_fallback); begin if not DIR.Exists (path) then return; end if; case operation is when lock => HT.SU.Append (command, fback_lock & path); when unlock => HT.SU.Append (command, fback_unlock & path); end case; execute (HT.USS (command)); end folder_access; -------------------------------------------------------------------------------------------- -- folder_access -------------------------------------------------------------------------------------------- procedure set_folder_mode (path : String; operation : folder_operation) is cmd : constant String := "/bin/chmod"; oplock : constant String := " 555 "; opunlock : constant String := " 755 "; command : HT.Text; begin case operation is when lock => command := HT.SUS (cmd & oplock & path); when unlock => command := HT.SUS (cmd & opunlock & path); end case; execute (HT.USS (command)); end set_folder_mode; -------------------------------------------------------------------------------------------- -- get_workzone_path -------------------------------------------------------------------------------------------- function get_workzone_path return String is begin return get_slave_mount (workzone_id); end get_workzone_path; -------------------------------------------------------------------------------------------- -- launch_workzone -------------------------------------------------------------------------------------------- procedure launch_workzone is zone_base : constant String := get_workzone_path; begin forge_directory (zone_base); if not PM.configuration.avoid_tmpfs then -- Limit slave to 32Mb mount_tmpfs (zone_base, 32); end if; end launch_workzone; -------------------------------------------------------------------------------------------- -- destroy_workzone -------------------------------------------------------------------------------------------- procedure destroy_workzone is zone_base : constant String := get_workzone_path; begin if not PM.configuration.avoid_tmpfs then unmount (zone_base, 50); end if; annihilate_directory_tree (zone_base); end destroy_workzone; -------------------------------------------------------------------------------------------- -- clear_workzone_directory -------------------------------------------------------------------------------------------- procedure clear_workzone_directory (subpath : String) is zone_base : constant String := get_workzone_path; begin annihilate_directory_tree (zone_base & "/" & subpath); end clear_workzone_directory; -------------------------------------------------------------------------------------------- -- launch_slave -------------------------------------------------------------------------------------------- procedure launch_slave (id : builders; need_procfs : Boolean := False) is slave_base : constant String := get_slave_mount (id); slave_local : constant String := slave_base & "_localbase"; dir_system : constant String := HT.USS (PM.configuration.dir_sysroot); lbase : constant String := HT.USS (PM.configuration.dir_localbase); etc_path : constant String := location (slave_base, etc); begin forge_directory (slave_base); if PM.configuration.avoid_tmpfs then if lbase = bsd_localbase then -- /usr is write only, so to build on /usr/local, we need a dedicated mount -- restriction isn't necessary on mac or openbsd which copies via hardlink case platform_type is when macos | openbsd => set_folder_mode (slave_base & lbase, unlock); forge_directory (location (slave_base, toolchain)); when others => forge_directory (location (slave_local, toolchain)); mount_nullfs (slave_local, slave_base & lbase, readwrite); end case; else forge_directory (location (slave_base, toolchain)); end if; else -- Limit slave to 24Gb, covers localbase + construction mainly mount_tmpfs (slave_base, 24 * 1024); if lbase = bsd_localbase then mount_tmpfs (slave_base & bsd_localbase, 12 * 1024); end if; forge_directory (location (slave_base, toolchain)); end if; for mnt in safefolders'Range loop forge_directory (location (slave_base, mnt)); end loop; -- Save a null mount on all platforms (all keeps /xports to the bare minimum) declare mk_directory : constant String := mount_target (xports) & "/Mk"; slave_mk : constant String := location (slave_base, xports) & "/Mk"; begin if PM.configuration.avoid_tmpfs then mount_hardlink (mk_directory, slave_mk, dir_system); else mount_fullcopy (mk_directory, slave_mk, dir_system); end if; process_keyword_files (slave_mk, lbase); end; case platform_type is when macos | openbsd => mount_hardlink (location (dir_system, bin), location (slave_base, bin), dir_system); mount_hardlink (location (dir_system, usr), location (slave_base, usr), dir_system); mount_hardlink (mount_target (toolchain), location (slave_base, toolchain) & "-off", dir_system); preplace_libgcc_s (location (slave_base, toolchain) & "-fallback"); when others => mount_nullfs (location (dir_system, bin), location (slave_base, bin)); mount_nullfs (location (dir_system, usr), location (slave_base, usr)); end case; case platform_type is when freebsd | dragonfly | netbsd | openbsd => -- should be limited to rtld executable if PM.configuration.avoid_tmpfs then mount_hardlink (target => location (dir_system, libexec), mount_point => location (slave_base, libexec), sysroot => dir_system); else -- saves a null mount (at the cost of memory) mount_fullcopy (target => location (dir_system, libexec), mount_point => location (slave_base, libexec), sysroot => dir_system); end if; when linux => mount_nullfs (location (dir_system, lib), location (slave_base, lib)); mount_nullfs (location (dir_system, lib64), location (slave_base, lib64)); when sunos => forge_directory (location (slave_base, devices)); mount_nullfs (location (dir_system, lib), location (slave_base, lib)); mount_nullfs (root_devices, location (slave_base, devices)); when macos => forge_directory (location (slave_base, frameworks)); mount_nullfs (location (dir_system, frameworks), location (slave_base, frameworks)); end case; folder_access (location (slave_base, home), lock); folder_access (location (slave_base, root), lock); mount_nullfs (mount_target (packages), location (slave_base, packages), mode => readwrite); mount_nullfs (mount_target (distfiles), location (slave_base, distfiles), mode => readwrite); if need_procfs or else platform_type = linux or else platform_type = sunos then mount_procfs (path_to_proc => location (slave_base, proc)); end if; if DIR.Exists (mount_target (ccache)) then mount_nullfs (mount_target (ccache), location (slave_base, ccache), readwrite); end if; mount_devices (location (slave_base, dev)); populate_var_folder (location (slave_base, var)); copy_rc_default (etc_path); copy_resolv_conf (etc_path); copy_ldconfig_hints (slave_base & "/var/run"); copy_unkindness_IDs (slave_base & "/construction"); fix_macos_resolv (slave_base & "/var/run"); create_make_conf (etc_path); install_passwd_and_group (etc_path); create_etc_services (etc_path); create_etc_shells (etc_path); create_sun_files (etc_path); install_linux_ldsoconf (location (slave_base, etc_ldsocnf)); exception when hiccup : others => TIO.Put_Line (abnormal_log, "LAUNCH SLAVE" & id'Img & " FAILED: " & EX.Exception_Information (hiccup)); Signals.initiate_shutdown; end launch_slave; -------------------------------------------------------------------------------------------- -- destroy_slave -------------------------------------------------------------------------------------------- procedure destroy_slave (id : builders; need_procfs : Boolean := False) is slave_base : constant String := get_slave_mount (id); slave_local : constant String := slave_base & "_localbase"; dir_system : constant String := HT.USS (PM.configuration.dir_sysroot); lbase : constant String := HT.USS (PM.configuration.dir_localbase); retry1min : constant Natural := 6; counter : Natural := 0; begin unmount_devices (location (slave_base, dev)); if DIR.Exists (mount_target (ccache)) then unmount (location (slave_base, ccache), retry1min); end if; if need_procfs or else platform_type = linux or else platform_type = sunos then unmount_procfs (location (slave_base, proc)); end if; unmount (location (slave_base, distfiles), retry1min); unmount (location (slave_base, packages), retry1min); if DIR.Exists (slave_base & toolchain_tag) then unhook_toolchain (id); end if; case platform_type is when macos | openbsd => null; when others => unmount (location (slave_base, bin)); unmount (location (slave_base, usr)); end case; case platform_type is when freebsd | dragonfly | netbsd | openbsd => null; -- libexec is copied now when linux => unmount (location (slave_base, lib)); unmount (location (slave_base, lib64)); when sunos => unmount (location (slave_base, lib)); unmount (location (slave_base, devices)); when macos => unmount (location (slave_base, frameworks)); end case; if PM.configuration.avoid_tmpfs then if lbase = bsd_localbase then case platform_type is when macos | openbsd => null; when others => unmount (slave_base & lbase, retry1min); end case; end if; annihilate_directory_tree (slave_local); else if lbase = bsd_localbase then unmount (slave_base & lbase, retry1min); end if; unmount (slave_base, retry1min * 5); end if; annihilate_directory_tree (slave_base); exception when hiccup : others => TIO.Put_Line (abnormal_log, "DESTROY SLAVE" & id'Img & " FAILED: " & EX.Exception_Information (hiccup)); Signals.initiate_shutdown; end destroy_slave; -------------------------------------------------------------------------------------------- -- hook_toolchain -------------------------------------------------------------------------------------------- procedure hook_toolchain (id : builders) is use type DIR.File_Kind; slave_base : constant String := get_slave_mount (id); tc_path : constant String := location (slave_base, toolchain); forged : TIO.File_Type; begin -- When hook_toolchain is called, there very well may be installed packages that -- brought in gcc libs and installed them at /raven/toolchain. -- For null-mount systems, the toolchain is mounted over /raven/toolchain, but it's -- unmounted before package deinstallation. -- For NFS-mount systems, the toolchain is hardlink-copied at toolchain-off. The -- toolchain and toolchain-off are renamed toolchain-packages and toolchain respectively. -- This is reversed during unhooking. case platform_type is when macos | openbsd => DIR.Rename (Old_Name => tc_path, New_Name => tc_path & "-packaged"); DIR.Rename (Old_Name => tc_path & "-off", New_Name => tc_path); when others => mount_nullfs (mount_target (toolchain), tc_path); end case; TIO.Create (File => forged, Mode => TIO.Out_File, Name => slave_base & toolchain_tag); TIO.Close (forged); end hook_toolchain; -------------------------------------------------------------------------------------------- -- unhook_toolchain -------------------------------------------------------------------------------------------- procedure unhook_toolchain (id : builders) is use type DIR.File_Kind; slave_base : constant String := get_slave_mount (id); tc_path : constant String := location (slave_base, toolchain); begin case platform_type is when macos | openbsd => DIR.Rename (Old_Name => tc_path, New_Name => tc_path & "-off"); DIR.Rename (Old_Name => tc_path & "-packaged", New_Name => tc_path); when others => unmount (tc_path); end case; DIR.Delete_File (slave_base & toolchain_tag); end unhook_toolchain; -------------------------------------------------------------------------------------------- -- slave_name -------------------------------------------------------------------------------------------- function slave_name (id : builders) return String is id_image : constant String := HT.int2str (Integer (id)); suffix : String := "SL00"; begin if id < 10 then suffix (4) := id_image (id_image'First); else suffix (3 .. 4) := id_image (id_image'First .. id_image'First + 1); end if; return suffix; end slave_name; -------------------------------------------------------------------------------------------- -- populate_var_folder -------------------------------------------------------------------------------------------- procedure populate_var_folder (path : String) is begin forge_directory (path & "/cache"); forge_directory (path & "/cron"); forge_directory (path & "/db"); forge_directory (path & "/empty"); forge_directory (path & "/games"); forge_directory (path & "/log"); forge_directory (path & "/mail"); forge_directory (path & "/msgs"); forge_directory (path & "/preserve"); forge_directory (path & "/run/sem"); forge_directory (path & "/spool"); forge_directory (path & "/tmp"); end populate_var_folder; -------------------------------------------------------------------------------------------- -- copy_ldconfig_hints -------------------------------------------------------------------------------------------- procedure copy_ldconfig_hints (path_to_varrun : String) is mm : constant String := get_master_mount; hints : constant String := "/ld-elf.so.hints"; nhints : constant String := "/ld.so.hints"; begin case platform_type is when dragonfly | freebsd => DIR.Copy_File (mm & hints, path_to_varrun & hints); when netbsd | openbsd => DIR.Copy_File (mm & nhints, path_to_varrun & nhints); when macos | linux | sunos => null; end case; end copy_ldconfig_hints; -------------------------------------------------------------------------------------------- -- fix_macos_resolv -------------------------------------------------------------------------------------------- procedure fix_macos_resolv (path_to_varrun : String) is DNSR : constant String := "/mDNSResponder"; path_orig : constant String := "/var/run" & DNSR; path_dest : constant String := path_to_varrun & DNSR; errprefix : constant String := "Hardlink failure: "; begin case platform_type is when macos => if DIR.Exists (path_orig) then if not Unix.create_hardlink (path_orig, path_dest) then TIO.Put_Line (errprefix & "link " & path_dest & " to " & path_orig); end if; else raise scenario_unexpected with errprefix & path_orig & " is not present on system"; end if; when others => null; end case; end fix_macos_resolv; -------------------------------------------------------------------------------------------- -- preplace_libgcc_s -------------------------------------------------------------------------------------------- procedure preplace_libgcc_s (path_to_toolchain : String) is mpath : constant String := "/" & default_compiler & "/lib"; dylib : constant String := mpath & "/libgcc_s.1.dylib"; TC : constant String := mount_target (toolchain); begin if DIR.Exists (TC & dylib) then forge_directory (path_to_toolchain & mpath); DIR.Copy_File (Source_Name => TC & dylib, Target_Name => path_to_toolchain & dylib); else raise scenario_unexpected with TC & dylib & " is not present on system"; end if; end preplace_libgcc_s; -------------------------------------------------------------------------------------------- -- populate_var_folder -------------------------------------------------------------------------------------------- procedure copy_rc_default (path_to_etc : String) is mm : constant String := get_master_mount; rcconf : constant String := "/rc.conf"; begin if DIR.Exists (mm & rcconf) then DIR.Copy_File (Source_Name => mm & rcconf, Target_Name => path_to_etc & "/defaults" & rcconf); end if; end copy_rc_default; -------------------------------------------------------------------------------------------- -- copy_resolv_conf -------------------------------------------------------------------------------------------- procedure copy_resolv_conf (path_to_etc : String) is procedure install (filename : String); resolv : constant String := "/resolv.conf"; netconfig : constant String := "/netconfig"; nssconf : constant String := "/nsswitch.conf"; nssfiles : constant String := "/nsswitch.files"; nssdns : constant String := "/nsswitch.dns"; procedure install (filename : String) is begin if DIR.Exists ("/etc" & filename) then DIR.Copy_File (Source_Name => "/etc" & filename, Target_Name => path_to_etc & filename); end if; end install; begin install (resolv); install (netconfig); install (nssconf); install (nssfiles); install (nssdns); end copy_resolv_conf; -------------------------------------------------------------------------------------------- -- copy_unkindness_IDs -------------------------------------------------------------------------------------------- procedure copy_unkindness_IDs (path_to_construction : String) is procedure install (filename, new_name : String); dir_unkindness : constant String := HT.USS (PM.configuration.dir_unkindness); procedure install (filename, new_name : String) is begin if DIR.Exists (filename) then DIR.Copy_File (Source_Name => filename, Target_Name => path_to_construction & new_name); end if; end install; begin if dir_unkindness /= PM.no_unkindness then install (dir_unkindness & "/custom_UID", "/.UID.custom"); install (dir_unkindness & "/custom_GID", "/.GID.custom"); end if; end copy_unkindness_IDs; -------------------------------------------------------------------------------------------- -- install_passwd -------------------------------------------------------------------------------------------- procedure install_passwd_and_group (path_to_etc : String) is procedure install (filename : String); mm : constant String := get_master_mount; maspwd : constant String := "/master.passwd"; passwd : constant String := "/passwd"; spwd : constant String := "/spwd.db"; pwd : constant String := "/pwd.db"; group : constant String := "/group"; mtree1 : constant String := "/mtree.preconfig.exclude"; mtree2 : constant String := "/mtree.prestage.exclude"; ldcnf2 : constant String := "/ld.so.conf"; procedure install (filename : String) is begin if DIR.Exists (mm & filename) then DIR.Copy_File (Source_Name => mm & filename, Target_Name => path_to_etc & filename); end if; end install; begin install (passwd); install (maspwd); install (spwd); install (pwd); install (group); install (mtree1); install (mtree2); install (ldcnf2); end install_passwd_and_group; -------------------------------------------------------------------------------------------- -- install_linux_ldsoconf -------------------------------------------------------------------------------------------- procedure install_linux_ldsoconf (path_to_etc_ldsocnf : String) is procedure install (filename : String); mm : constant String := get_master_mount; ldconf : constant String := "/x86_64-linux-gnu.conf"; procedure install (filename : String) is begin if DIR.Exists (mm & filename) then DIR.Copy_File (Source_Name => mm & filename, Target_Name => path_to_etc_ldsocnf & filename); end if; end install; begin install (ldconf); end install_linux_ldsoconf; -------------------------------------------------------------------------------------------- -- create_etc_services -------------------------------------------------------------------------------------------- procedure create_etc_services (path_to_etc : String) is svcfile : TIO.File_Type; begin TIO.Create (File => svcfile, Mode => TIO.Out_File, Name => path_to_etc & "/services"); TIO.Put_Line (svcfile, "ftp 21/tcp" & LAT.LF & "ftp 21/udp" & LAT.LF & "ssh 22/tcp" & LAT.LF & "ssh 22/udp" & LAT.LF & "http 80/tcp" & LAT.LF & "http 80/udp" & LAT.LF & "https 443/tcp" & LAT.LF & "https 443/udp" & LAT.LF); TIO.Close (svcfile); end create_etc_services; -------------------------------------------------------------------------------------------- -- create_etc_shells -------------------------------------------------------------------------------------------- procedure create_etc_shells (path_to_etc : String) is shells : TIO.File_Type; begin TIO.Create (File => shells, Mode => TIO.Out_File, Name => path_to_etc & "/shells"); TIO.Put_Line (shells, "/bin/sh"); TIO.Put_Line (shells, "/bin/csh"); if platform_type = linux then TIO.Put_Line (shells, "/bin/bash"); end if; TIO.Close (shells); end create_etc_shells; -------------------------------------------------------------------------------------------- -- create_make_conf -------------------------------------------------------------------------------------------- procedure create_make_conf (path_to_etc : String) is procedure override_defaults (label : String; value : HT.Text); makeconf : TIO.File_Type; profilemc : constant String := PM.raven_confdir & "/" & HT.USS (PM.configuration.profile) & "-make.conf"; profile : constant String := HT.USS (PM.configuration.profile); mjnum : constant Integer := Integer (PM.configuration.jobs_limit); procedure override_defaults (label : String; value : HT.Text) is begin if not (HT.equivalent (value, ports_default)) then TIO.Put_Line (makeconf, "DEFAULT_VERSIONS+=" & label & "=" & HT.USS (value)); end if; end override_defaults; begin TIO.Create (File => makeconf, Mode => TIO.Out_File, Name => path_to_etc & "/make.conf"); TIO.Put_Line (makeconf, "RAVENPROFILE=" & profile & LAT.LF & "RAVENBASE=" & HT.USS (PM.configuration.dir_localbase) & LAT.LF & "WRKDIRPREFIX=/construction" & LAT.LF & "DISTDIR=/distfiles" & LAT.LF & "NUMBER_CPUS=" & HT.int2str (Integer (PM.configuration.number_cores)) & LAT.LF & "MAKE_JOBS_NUMBER_LIMIT=" & HT.int2str (mjnum)); if developer_mode then TIO.Put_Line (makeconf, "DEVELOPER=1"); TIO.Put_Line (makeconf, "PATCH_DEBUG=yes"); end if; if DIR.Exists (HT.USS (PM.configuration.dir_ccache)) then TIO.Put_Line (makeconf, "BUILD_WITH_CCACHE=yes"); TIO.Put_Line (makeconf, "CCACHE_DIR=/ccache"); end if; override_defaults ("firebird", PM.configuration.def_firebird); override_defaults ("lua", PM.configuration.def_lua); override_defaults ("mysql", PM.configuration.def_mysql_group); override_defaults ("perl5", PM.configuration.def_perl); override_defaults ("php", PM.configuration.def_php); override_defaults ("pgsql", PM.configuration.def_postgresql); override_defaults ("python3", PM.configuration.def_python3); override_defaults ("ruby", PM.configuration.def_ruby); override_defaults ("ssl", PM.configuration.def_ssl); override_defaults ("tcl", PM.configuration.def_tcl_tk); concatenate_makeconf (makeconf, profilemc); TIO.Close (makeconf); end create_make_conf; -------------------------------------------------------------------------------------------- -- create_make_conf -------------------------------------------------------------------------------------------- procedure concatenate_makeconf (makeconf_handle : TIO.File_Type; target_name : String) is fragment : TIO.File_Type; begin if DIR.Exists (target_name) then TIO.Open (File => fragment, Mode => TIO.In_File, Name => target_name); while not TIO.End_Of_File (fragment) loop declare Line : String := TIO.Get_Line (fragment); begin TIO.Put_Line (makeconf_handle, Line); end; end loop; TIO.Close (fragment); end if; exception when others => null; end concatenate_makeconf; -------------------------------------------------------------------------------------------- -- create_sun_files -------------------------------------------------------------------------------------------- procedure create_sun_files (path_to_etc : String) is sun_file : TIO.File_Type; security : constant String := path_to_etc & "/security"; skel : constant String := path_to_etc & "/skel"; begin if platform_type /= sunos then return; end if; -- version found in Solaris 10u8 -- # -- # Copyright 2008 Sun Microsystems, Inc. All rights reserved. -- # Use is subject to license terms. -- # -- #ident "@(#)crypt.conf 1.2 08/05/14 SMI" -- # -- # The algorithm name __unix__ is reserved. -- -- 1 crypt_bsdmd5.so.1 -- 2a crypt_bsdbf.so.1 -- md5 crypt_sunmd5.so.1 -- 5 crypt_sha256.so.1 -- 6 crypt_sha512.so.1 DIR.Create_Path (security); TIO.Create (sun_file, TIO.Out_File, security & "/crypt.conf"); TIO.Put_Line (sun_file, "1 crypt_bsdmd5.so.1"); TIO.Put_Line (sun_file, "2a crypt_bsdbf.so.1"); TIO.Put_Line (sun_file, "md5 crypt_sunmd5.so.1"); TIO.Put_Line (sun_file, "5 crypt_sha256.so.1"); TIO.Put_Line (sun_file, "6 crypt_sha512.so.1"); TIO.Close (sun_file); -- Dummy /etc/user_attr to allow useradd to succeed TIO.Create (sun_file, TIO.Out_File, path_to_etc & "/user_attr"); TIO.Put_Line (sun_file, "adm::::profiles=Log Management"); TIO.Put_Line (sun_file, "lp::::profiles=Printer Management"); TIO.Close (sun_file); -- Create skel files DIR.Create_Path (skel); TIO.Create (sun_file, TIO.Out_File, skel & "/local.cshrc"); TIO.Put_Line (sun_file, "umask 022"); TIO.Put_Line (sun_file, "set path=(/bin /usr/bin /usr/ucb /etc .)"); TIO.Put_Line (sun_file, "if ( $?prompt ) then"); TIO.Put_Line (sun_file, " set history=32"); TIO.Put_Line (sun_file, "endif"); TIO.Close (sun_file); -- skel/local.login TIO.Create (sun_file, TIO.Out_File, skel & "/local.login"); TIO.Put_Line (sun_file, "stty -istrip"); TIO.Close (sun_file); -- skel/local.profile TIO.Create (sun_file, TIO.Out_File, skel & "/local.profile"); TIO.Put_Line (sun_file, "stty istrip"); TIO.Put_Line (sun_file, "PATH=/usr/bin:/usr/ucb:/etc:."); TIO.Put_Line (sun_file, "export PATH"); TIO.Close (sun_file); -- etc/datemsk (extremely pared done) TIO.Create (sun_file, TIO.Out_File, path_to_etc & "/datemsk"); TIO.Put_Line (sun_file, "%m/%d/%y %H:%M"); TIO.Put_Line (sun_file, "%m%d%H%M%y"); TIO.Close (sun_file); -- etc/shadow (couple of entries) TIO.Create (sun_file, TIO.Out_File, path_to_etc & "/shadow"); TIO.Put_Line (sun_file, "root:kF/MO3YejnKKE:6445::::::"); TIO.Put_Line (sun_file, "adm:NP:6445::::::"); TIO.Put_Line (sun_file, "lp:NP:6445::::::"); TIO.Put_Line (sun_file, "nobody:*LK*:6445::::::"); TIO.Put_Line (sun_file, "nobody4:*LK*:6445::::::"); TIO.Close (sun_file); -- etc/project TIO.Create (sun_file, TIO.Out_File, path_to_etc & "/project"); TIO.Put_Line (sun_file, "system:0::::"); TIO.Put_Line (sun_file, "user.root:1::::"); TIO.Put_Line (sun_file, "noproject:2::::"); TIO.Put_Line (sun_file, "default:3::::"); TIO.Put_Line (sun_file, "group.staff:10::::"); TIO.Close (sun_file); end create_sun_files; -------------------------------------------------------------------------------------------- -- process keyword files -------------------------------------------------------------------------------------------- procedure process_keyword_files (slave_mk : String; localbase : String) is procedure process_file (keyfile : String); Search : DIR.Search_Type; Dir_Ent : DIR.Directory_Entry_Type; keydir : constant String := slave_mk & "/Keywords"; procedure process_file (keyfile : String) is contents : constant String := FOP.get_file_contents (keyfile); lpattern : constant String := "%LOCALBASE%"; modified : Boolean := False; finaltxt : HT.Text := HT.SUS (contents); begin loop exit when not HT.contains (finaltxt, lpattern); modified := True; finaltxt := HT.replace_substring (finaltxt, lpattern, localbase); end loop; if modified then DIR.Delete_File (keyfile); FOP.dump_contents_to_file (HT.USS (finaltxt), keyfile); end if; end process_file; begin DIR.Start_Search (Search => Search, Directory => keydir, Filter => (DIR.Ordinary_File => True, others => False), Pattern => "*.ucl"); while DIR.More_Entries (Search => Search) loop DIR.Get_Next_Entry (Search => Search, Directory_Entry => Dir_Ent); declare kfile : constant String := keydir & "/" & DIR.Simple_Name (Dir_Ent); begin process_file (kfile); end; end loop; DIR.End_Search (Search); end process_keyword_files; end Replicant;
-- { dg-do run } with System; use System; procedure Boolean_Conv is subtype B1 is Boolean; subtype B2 is Boolean; A0, A1, A2 : Address; B : aliased B1; procedure P2 (X2 : access B2) is begin A2 := X2.all'Address; end P2; procedure P1 (X1 : access B1) is begin A1 := X1.all'Address; P2 (B2 (X1.all)'Unrestricted_Access); end P1; begin A0 := B'Address; P1 (B'Access); if A1 /= A0 then raise Program_Error; end if; if A2 /= A0 then raise Program_Error; end if; end;
-- Generated by a script from an "avr tools device file" (atdf) with SAM.Port; use SAM.Port; package SAM.Functions is PA04_AC_AIN0 : constant Peripheral_Function := B; PA05_AC_AIN1 : constant Peripheral_Function := B; PA06_AC_AIN2 : constant Peripheral_Function := B; PA07_AC_AIN3 : constant Peripheral_Function := B; PA12_AC_CMP0 : constant Peripheral_Function := M; PA18_AC_CMP0 : constant Peripheral_Function := M; PA13_AC_CMP1 : constant Peripheral_Function := M; PA19_AC_CMP1 : constant Peripheral_Function := M; PA02_ADC0_AIN0 : constant Peripheral_Function := B; PA03_ADC0_AIN1 : constant Peripheral_Function := B; PB08_ADC0_AIN2 : constant Peripheral_Function := B; PB09_ADC0_AIN3 : constant Peripheral_Function := B; PA04_ADC0_AIN4 : constant Peripheral_Function := B; PA05_ADC0_AIN5 : constant Peripheral_Function := B; PA06_ADC0_AIN6 : constant Peripheral_Function := B; PA07_ADC0_AIN7 : constant Peripheral_Function := B; PA08_ADC0_AIN8 : constant Peripheral_Function := B; PA09_ADC0_AIN9 : constant Peripheral_Function := B; PA10_ADC0_AIN10 : constant Peripheral_Function := B; PA11_ADC0_AIN11 : constant Peripheral_Function := B; PB00_ADC0_AIN12 : constant Peripheral_Function := B; PB01_ADC0_AIN13 : constant Peripheral_Function := B; PB02_ADC0_AIN14 : constant Peripheral_Function := B; PB03_ADC0_AIN15 : constant Peripheral_Function := B; PA03_ADC0_X0 : constant Peripheral_Function := B; PA03_ADC0_Y0 : constant Peripheral_Function := B; PB08_ADC0_X1 : constant Peripheral_Function := B; PB08_ADC0_Y1 : constant Peripheral_Function := B; PB09_ADC0_X2 : constant Peripheral_Function := B; PB09_ADC0_Y2 : constant Peripheral_Function := B; PA04_ADC0_X3 : constant Peripheral_Function := B; PA04_ADC0_Y3 : constant Peripheral_Function := B; PA06_ADC0_X4 : constant Peripheral_Function := B; PA06_ADC0_Y4 : constant Peripheral_Function := B; PA07_ADC0_X5 : constant Peripheral_Function := B; PA07_ADC0_Y5 : constant Peripheral_Function := B; PA08_ADC0_X6 : constant Peripheral_Function := B; PA08_ADC0_Y6 : constant Peripheral_Function := B; PA09_ADC0_X7 : constant Peripheral_Function := B; PA09_ADC0_Y7 : constant Peripheral_Function := B; PA10_ADC0_X8 : constant Peripheral_Function := B; PA10_ADC0_Y8 : constant Peripheral_Function := B; PA11_ADC0_X9 : constant Peripheral_Function := B; PA11_ADC0_Y9 : constant Peripheral_Function := B; PA16_ADC0_X10 : constant Peripheral_Function := B; PA16_ADC0_Y10 : constant Peripheral_Function := B; PA17_ADC0_X11 : constant Peripheral_Function := B; PA17_ADC0_Y11 : constant Peripheral_Function := B; PA18_ADC0_X12 : constant Peripheral_Function := B; PA18_ADC0_Y12 : constant Peripheral_Function := B; PA19_ADC0_X13 : constant Peripheral_Function := B; PA19_ADC0_Y13 : constant Peripheral_Function := B; PA20_ADC0_X14 : constant Peripheral_Function := B; PA20_ADC0_Y14 : constant Peripheral_Function := B; PA21_ADC0_X15 : constant Peripheral_Function := B; PA21_ADC0_Y15 : constant Peripheral_Function := B; PA22_ADC0_X16 : constant Peripheral_Function := B; PA22_ADC0_Y16 : constant Peripheral_Function := B; PA23_ADC0_X17 : constant Peripheral_Function := B; PA23_ADC0_Y17 : constant Peripheral_Function := B; PA27_ADC0_X18 : constant Peripheral_Function := B; PA27_ADC0_Y18 : constant Peripheral_Function := B; PA30_ADC0_X19 : constant Peripheral_Function := B; PA30_ADC0_Y19 : constant Peripheral_Function := B; PB02_ADC0_X20 : constant Peripheral_Function := B; PB02_ADC0_Y20 : constant Peripheral_Function := B; PB03_ADC0_X21 : constant Peripheral_Function := B; PB03_ADC0_Y21 : constant Peripheral_Function := B; PB04_ADC0_X22 : constant Peripheral_Function := B; PB04_ADC0_Y22 : constant Peripheral_Function := B; PB05_ADC0_X23 : constant Peripheral_Function := B; PB05_ADC0_Y23 : constant Peripheral_Function := B; PB06_ADC0_X24 : constant Peripheral_Function := B; PB06_ADC0_Y24 : constant Peripheral_Function := B; PB07_ADC0_X25 : constant Peripheral_Function := B; PB07_ADC0_Y25 : constant Peripheral_Function := B; PB12_ADC0_X26 : constant Peripheral_Function := B; PB12_ADC0_Y26 : constant Peripheral_Function := B; PB13_ADC0_X27 : constant Peripheral_Function := B; PB13_ADC0_Y27 : constant Peripheral_Function := B; PB14_ADC0_X28 : constant Peripheral_Function := B; PB14_ADC0_Y28 : constant Peripheral_Function := B; PB15_ADC0_X29 : constant Peripheral_Function := B; PB15_ADC0_Y29 : constant Peripheral_Function := B; PB00_ADC0_X30 : constant Peripheral_Function := B; PB00_ADC0_Y30 : constant Peripheral_Function := B; PB01_ADC0_X31 : constant Peripheral_Function := B; PB01_ADC0_Y31 : constant Peripheral_Function := B; PB08_ADC1_AIN0 : constant Peripheral_Function := B; PB09_ADC1_AIN1 : constant Peripheral_Function := B; PA08_ADC1_AIN2 : constant Peripheral_Function := B; PA09_ADC1_AIN3 : constant Peripheral_Function := B; PB04_ADC1_AIN6 : constant Peripheral_Function := B; PB05_ADC1_AIN7 : constant Peripheral_Function := B; PB06_ADC1_AIN8 : constant Peripheral_Function := B; PB07_ADC1_AIN9 : constant Peripheral_Function := B; PA04_CCL_IN0 : constant Peripheral_Function := N; PA16_CCL_IN0 : constant Peripheral_Function := N; PB22_CCL_IN0 : constant Peripheral_Function := N; PA05_CCL_IN1 : constant Peripheral_Function := N; PA17_CCL_IN1 : constant Peripheral_Function := N; PB00_CCL_IN1 : constant Peripheral_Function := N; PA06_CCL_IN2 : constant Peripheral_Function := N; PA18_CCL_IN2 : constant Peripheral_Function := N; PB01_CCL_IN2 : constant Peripheral_Function := N; PA08_CCL_IN3 : constant Peripheral_Function := N; PA30_CCL_IN3 : constant Peripheral_Function := N; PA09_CCL_IN4 : constant Peripheral_Function := N; PA10_CCL_IN5 : constant Peripheral_Function := N; PA22_CCL_IN6 : constant Peripheral_Function := N; PB06_CCL_IN6 : constant Peripheral_Function := N; PA23_CCL_IN7 : constant Peripheral_Function := N; PB07_CCL_IN7 : constant Peripheral_Function := N; PA24_CCL_IN8 : constant Peripheral_Function := N; PB08_CCL_IN8 : constant Peripheral_Function := N; PB14_CCL_IN9 : constant Peripheral_Function := N; PB15_CCL_IN10 : constant Peripheral_Function := N; PB10_CCL_IN11 : constant Peripheral_Function := N; PB16_CCL_IN11 : constant Peripheral_Function := N; PA07_CCL_OUT0 : constant Peripheral_Function := N; PA19_CCL_OUT0 : constant Peripheral_Function := N; PB02_CCL_OUT0 : constant Peripheral_Function := N; PB23_CCL_OUT0 : constant Peripheral_Function := N; PA11_CCL_OUT1 : constant Peripheral_Function := N; PA31_CCL_OUT1 : constant Peripheral_Function := N; PB11_CCL_OUT1 : constant Peripheral_Function := N; PA25_CCL_OUT2 : constant Peripheral_Function := N; PB09_CCL_OUT2 : constant Peripheral_Function := N; PB17_CCL_OUT3 : constant Peripheral_Function := N; PA02_DAC_VOUT0 : constant Peripheral_Function := B; PA05_DAC_VOUT1 : constant Peripheral_Function := B; PA00_EIC_EXTINT0 : constant Peripheral_Function := A; PA16_EIC_EXTINT0 : constant Peripheral_Function := A; PB00_EIC_EXTINT0 : constant Peripheral_Function := A; PB16_EIC_EXTINT0 : constant Peripheral_Function := A; PA01_EIC_EXTINT1 : constant Peripheral_Function := A; PA17_EIC_EXTINT1 : constant Peripheral_Function := A; PB01_EIC_EXTINT1 : constant Peripheral_Function := A; PB17_EIC_EXTINT1 : constant Peripheral_Function := A; PA02_EIC_EXTINT2 : constant Peripheral_Function := A; PA18_EIC_EXTINT2 : constant Peripheral_Function := A; PB02_EIC_EXTINT2 : constant Peripheral_Function := A; PA03_EIC_EXTINT3 : constant Peripheral_Function := A; PA19_EIC_EXTINT3 : constant Peripheral_Function := A; PB03_EIC_EXTINT3 : constant Peripheral_Function := A; PA04_EIC_EXTINT4 : constant Peripheral_Function := A; PA20_EIC_EXTINT4 : constant Peripheral_Function := A; PB04_EIC_EXTINT4 : constant Peripheral_Function := A; PA05_EIC_EXTINT5 : constant Peripheral_Function := A; PA21_EIC_EXTINT5 : constant Peripheral_Function := A; PB05_EIC_EXTINT5 : constant Peripheral_Function := A; PA06_EIC_EXTINT6 : constant Peripheral_Function := A; PA22_EIC_EXTINT6 : constant Peripheral_Function := A; PB06_EIC_EXTINT6 : constant Peripheral_Function := A; PB22_EIC_EXTINT6 : constant Peripheral_Function := A; PA07_EIC_EXTINT7 : constant Peripheral_Function := A; PA23_EIC_EXTINT7 : constant Peripheral_Function := A; PB07_EIC_EXTINT7 : constant Peripheral_Function := A; PB23_EIC_EXTINT7 : constant Peripheral_Function := A; PA24_EIC_EXTINT8 : constant Peripheral_Function := A; PB08_EIC_EXTINT8 : constant Peripheral_Function := A; PA09_EIC_EXTINT9 : constant Peripheral_Function := A; PA25_EIC_EXTINT9 : constant Peripheral_Function := A; PB09_EIC_EXTINT9 : constant Peripheral_Function := A; PA10_EIC_EXTINT10 : constant Peripheral_Function := A; PB10_EIC_EXTINT10 : constant Peripheral_Function := A; PA11_EIC_EXTINT11 : constant Peripheral_Function := A; PA27_EIC_EXTINT11 : constant Peripheral_Function := A; PB11_EIC_EXTINT11 : constant Peripheral_Function := A; PA12_EIC_EXTINT12 : constant Peripheral_Function := A; PB12_EIC_EXTINT12 : constant Peripheral_Function := A; PA13_EIC_EXTINT13 : constant Peripheral_Function := A; PB13_EIC_EXTINT13 : constant Peripheral_Function := A; PA30_EIC_EXTINT14 : constant Peripheral_Function := A; PB14_EIC_EXTINT14 : constant Peripheral_Function := A; PB30_EIC_EXTINT14 : constant Peripheral_Function := A; PA14_EIC_EXTINT14 : constant Peripheral_Function := A; PA15_EIC_EXTINT15 : constant Peripheral_Function := A; PA31_EIC_EXTINT15 : constant Peripheral_Function := A; PB15_EIC_EXTINT15 : constant Peripheral_Function := A; PB31_EIC_EXTINT15 : constant Peripheral_Function := A; PA08_EIC_NMI : constant Peripheral_Function := A; PA30_GCLK_IO0 : constant Peripheral_Function := M; PB14_GCLK_IO0 : constant Peripheral_Function := M; PA14_GCLK_IO0 : constant Peripheral_Function := M; PB22_GCLK_IO0 : constant Peripheral_Function := M; PB15_GCLK_IO1 : constant Peripheral_Function := M; PA15_GCLK_IO1 : constant Peripheral_Function := M; PB23_GCLK_IO1 : constant Peripheral_Function := M; PA27_GCLK_IO1 : constant Peripheral_Function := M; PA16_GCLK_IO2 : constant Peripheral_Function := M; PB16_GCLK_IO2 : constant Peripheral_Function := M; PA17_GCLK_IO3 : constant Peripheral_Function := M; PB17_GCLK_IO3 : constant Peripheral_Function := M; PA10_GCLK_IO4 : constant Peripheral_Function := M; PB10_GCLK_IO4 : constant Peripheral_Function := M; PA11_GCLK_IO5 : constant Peripheral_Function := M; PB11_GCLK_IO5 : constant Peripheral_Function := M; PB12_GCLK_IO6 : constant Peripheral_Function := M; PB13_GCLK_IO7 : constant Peripheral_Function := M; PA09_I2S_FS0 : constant Peripheral_Function := J; PA20_I2S_FS0 : constant Peripheral_Function := J; PA23_I2S_FS1 : constant Peripheral_Function := J; PB11_I2S_FS1 : constant Peripheral_Function := J; PA08_I2S_MCK0 : constant Peripheral_Function := J; PB17_I2S_MCK0 : constant Peripheral_Function := J; PB13_I2S_MCK1 : constant Peripheral_Function := J; PA10_I2S_SCK0 : constant Peripheral_Function := J; PB16_I2S_SCK0 : constant Peripheral_Function := J; PB12_I2S_SCK1 : constant Peripheral_Function := J; PA22_I2S_SDI : constant Peripheral_Function := J; PB10_I2S_SDI : constant Peripheral_Function := J; PA11_I2S_SDO : constant Peripheral_Function := J; PA21_I2S_SDO : constant Peripheral_Function := J; PA14_PCC_CLK : constant Peripheral_Function := K; PA16_PCC_DATA0 : constant Peripheral_Function := K; PA17_PCC_DATA1 : constant Peripheral_Function := K; PA18_PCC_DATA2 : constant Peripheral_Function := K; PA19_PCC_DATA3 : constant Peripheral_Function := K; PA20_PCC_DATA4 : constant Peripheral_Function := K; PA21_PCC_DATA5 : constant Peripheral_Function := K; PA22_PCC_DATA6 : constant Peripheral_Function := K; PA23_PCC_DATA7 : constant Peripheral_Function := K; PB14_PCC_DATA8 : constant Peripheral_Function := K; PB15_PCC_DATA9 : constant Peripheral_Function := K; PA12_PCC_DEN1 : constant Peripheral_Function := K; PA13_PCC_DEN2 : constant Peripheral_Function := K; PB23_PDEC_QDI0 : constant Peripheral_Function := G; PA24_PDEC_QDI0 : constant Peripheral_Function := G; PA25_PDEC_QDI1 : constant Peripheral_Function := G; PB22_PDEC_QDI2 : constant Peripheral_Function := G; PB11_QSPI_CS : constant Peripheral_Function := H; PA08_QSPI_DATA0 : constant Peripheral_Function := H; PA09_QSPI_DATA1 : constant Peripheral_Function := H; PA10_QSPI_DATA2 : constant Peripheral_Function := H; PA11_QSPI_DATA3 : constant Peripheral_Function := H; PB10_QSPI_SCK : constant Peripheral_Function := H; PA06_SDHC0_SDCD : constant Peripheral_Function := I; PA12_SDHC0_SDCD : constant Peripheral_Function := I; PB12_SDHC0_SDCD : constant Peripheral_Function := I; PB11_SDHC0_SDCK : constant Peripheral_Function := I; PA08_SDHC0_SDCMD : constant Peripheral_Function := I; PA09_SDHC0_SDDAT0 : constant Peripheral_Function := I; PA10_SDHC0_SDDAT1 : constant Peripheral_Function := I; PA11_SDHC0_SDDAT2 : constant Peripheral_Function := I; PB10_SDHC0_SDDAT3 : constant Peripheral_Function := I; PA07_SDHC0_SDWP : constant Peripheral_Function := I; PA13_SDHC0_SDWP : constant Peripheral_Function := I; PB13_SDHC0_SDWP : constant Peripheral_Function := I; PA04_SERCOM0_PAD0 : constant Peripheral_Function := D; PA08_SERCOM0_PAD0 : constant Peripheral_Function := C; PA05_SERCOM0_PAD1 : constant Peripheral_Function := D; PA09_SERCOM0_PAD1 : constant Peripheral_Function := C; PA06_SERCOM0_PAD2 : constant Peripheral_Function := D; PA10_SERCOM0_PAD2 : constant Peripheral_Function := C; PA07_SERCOM0_PAD3 : constant Peripheral_Function := D; PA11_SERCOM0_PAD3 : constant Peripheral_Function := C; PA00_SERCOM1_PAD0 : constant Peripheral_Function := D; PA16_SERCOM1_PAD0 : constant Peripheral_Function := C; PA01_SERCOM1_PAD1 : constant Peripheral_Function := D; PA17_SERCOM1_PAD1 : constant Peripheral_Function := C; PA30_SERCOM1_PAD2 : constant Peripheral_Function := D; PA18_SERCOM1_PAD2 : constant Peripheral_Function := C; PB22_SERCOM1_PAD2 : constant Peripheral_Function := C; PA31_SERCOM1_PAD3 : constant Peripheral_Function := D; PA19_SERCOM1_PAD3 : constant Peripheral_Function := C; PB23_SERCOM1_PAD3 : constant Peripheral_Function := C; PA09_SERCOM2_PAD0 : constant Peripheral_Function := D; PA12_SERCOM2_PAD0 : constant Peripheral_Function := C; PA08_SERCOM2_PAD1 : constant Peripheral_Function := D; PA13_SERCOM2_PAD1 : constant Peripheral_Function := C; PA10_SERCOM2_PAD2 : constant Peripheral_Function := D; PA14_SERCOM2_PAD2 : constant Peripheral_Function := C; PA11_SERCOM2_PAD3 : constant Peripheral_Function := D; PA15_SERCOM2_PAD3 : constant Peripheral_Function := C; PA17_SERCOM3_PAD0 : constant Peripheral_Function := D; PA22_SERCOM3_PAD0 : constant Peripheral_Function := C; PA16_SERCOM3_PAD1 : constant Peripheral_Function := D; PA23_SERCOM3_PAD1 : constant Peripheral_Function := C; PA18_SERCOM3_PAD2 : constant Peripheral_Function := D; PA20_SERCOM3_PAD2 : constant Peripheral_Function := D; PA24_SERCOM3_PAD2 : constant Peripheral_Function := C; PA19_SERCOM3_PAD3 : constant Peripheral_Function := D; PA21_SERCOM3_PAD3 : constant Peripheral_Function := D; PA25_SERCOM3_PAD3 : constant Peripheral_Function := C; PA13_SERCOM4_PAD0 : constant Peripheral_Function := D; PB08_SERCOM4_PAD0 : constant Peripheral_Function := D; PB12_SERCOM4_PAD0 : constant Peripheral_Function := C; PA12_SERCOM4_PAD1 : constant Peripheral_Function := D; PB09_SERCOM4_PAD1 : constant Peripheral_Function := D; PB13_SERCOM4_PAD1 : constant Peripheral_Function := C; PA14_SERCOM4_PAD2 : constant Peripheral_Function := D; PB10_SERCOM4_PAD2 : constant Peripheral_Function := D; PB14_SERCOM4_PAD2 : constant Peripheral_Function := C; PB11_SERCOM4_PAD3 : constant Peripheral_Function := D; PA15_SERCOM4_PAD3 : constant Peripheral_Function := D; PB15_SERCOM4_PAD3 : constant Peripheral_Function := C; PA23_SERCOM5_PAD0 : constant Peripheral_Function := D; PB02_SERCOM5_PAD0 : constant Peripheral_Function := D; PB31_SERCOM5_PAD0 : constant Peripheral_Function := D; PB16_SERCOM5_PAD0 : constant Peripheral_Function := C; PA22_SERCOM5_PAD1 : constant Peripheral_Function := D; PB03_SERCOM5_PAD1 : constant Peripheral_Function := D; PB30_SERCOM5_PAD1 : constant Peripheral_Function := D; PB17_SERCOM5_PAD1 : constant Peripheral_Function := C; PA24_SERCOM5_PAD2 : constant Peripheral_Function := D; PB00_SERCOM5_PAD2 : constant Peripheral_Function := D; PB22_SERCOM5_PAD2 : constant Peripheral_Function := D; PA20_SERCOM5_PAD2 : constant Peripheral_Function := C; PA25_SERCOM5_PAD3 : constant Peripheral_Function := D; PB01_SERCOM5_PAD3 : constant Peripheral_Function := D; PB23_SERCOM5_PAD3 : constant Peripheral_Function := D; PA21_SERCOM5_PAD3 : constant Peripheral_Function := C; PA04_TC0_WO0 : constant Peripheral_Function := E; PA08_TC0_WO0 : constant Peripheral_Function := E; PB30_TC0_WO0 : constant Peripheral_Function := E; PA05_TC0_WO1 : constant Peripheral_Function := E; PA09_TC0_WO1 : constant Peripheral_Function := E; PB31_TC0_WO1 : constant Peripheral_Function := E; PA06_TC1_WO0 : constant Peripheral_Function := E; PA10_TC1_WO0 : constant Peripheral_Function := E; PA07_TC1_WO1 : constant Peripheral_Function := E; PA11_TC1_WO1 : constant Peripheral_Function := E; PA12_TC2_WO0 : constant Peripheral_Function := E; PA16_TC2_WO0 : constant Peripheral_Function := E; PA00_TC2_WO0 : constant Peripheral_Function := E; PA01_TC2_WO1 : constant Peripheral_Function := E; PA13_TC2_WO1 : constant Peripheral_Function := E; PA17_TC2_WO1 : constant Peripheral_Function := E; PA18_TC3_WO0 : constant Peripheral_Function := E; PA14_TC3_WO0 : constant Peripheral_Function := E; PA15_TC3_WO1 : constant Peripheral_Function := E; PA19_TC3_WO1 : constant Peripheral_Function := E; PA22_TC4_WO0 : constant Peripheral_Function := E; PB08_TC4_WO0 : constant Peripheral_Function := E; PB12_TC4_WO0 : constant Peripheral_Function := E; PA23_TC4_WO1 : constant Peripheral_Function := E; PB09_TC4_WO1 : constant Peripheral_Function := E; PB13_TC4_WO1 : constant Peripheral_Function := E; PA24_TC5_WO0 : constant Peripheral_Function := E; PB10_TC5_WO0 : constant Peripheral_Function := E; PB14_TC5_WO0 : constant Peripheral_Function := E; PA25_TC5_WO1 : constant Peripheral_Function := E; PB11_TC5_WO1 : constant Peripheral_Function := E; PB15_TC5_WO1 : constant Peripheral_Function := E; PA20_TCC0_WO0 : constant Peripheral_Function := G; PB12_TCC0_WO0 : constant Peripheral_Function := G; PA08_TCC0_WO0 : constant Peripheral_Function := F; PA21_TCC0_WO1 : constant Peripheral_Function := G; PB13_TCC0_WO1 : constant Peripheral_Function := G; PA09_TCC0_WO1 : constant Peripheral_Function := F; PA22_TCC0_WO2 : constant Peripheral_Function := G; PB14_TCC0_WO2 : constant Peripheral_Function := G; PA10_TCC0_WO2 : constant Peripheral_Function := F; PA23_TCC0_WO3 : constant Peripheral_Function := G; PB15_TCC0_WO3 : constant Peripheral_Function := G; PA11_TCC0_WO3 : constant Peripheral_Function := F; PA16_TCC0_WO4 : constant Peripheral_Function := G; PB16_TCC0_WO4 : constant Peripheral_Function := G; PB10_TCC0_WO4 : constant Peripheral_Function := F; PA17_TCC0_WO5 : constant Peripheral_Function := G; PB17_TCC0_WO5 : constant Peripheral_Function := G; PB11_TCC0_WO5 : constant Peripheral_Function := F; PA18_TCC0_WO6 : constant Peripheral_Function := G; PB30_TCC0_WO6 : constant Peripheral_Function := G; PA12_TCC0_WO6 : constant Peripheral_Function := F; PA19_TCC0_WO7 : constant Peripheral_Function := G; PB31_TCC0_WO7 : constant Peripheral_Function := G; PA13_TCC0_WO7 : constant Peripheral_Function := F; PB10_TCC1_WO0 : constant Peripheral_Function := G; PA16_TCC1_WO0 : constant Peripheral_Function := F; PB11_TCC1_WO1 : constant Peripheral_Function := G; PA17_TCC1_WO1 : constant Peripheral_Function := F; PA12_TCC1_WO2 : constant Peripheral_Function := G; PA14_TCC1_WO2 : constant Peripheral_Function := G; PA18_TCC1_WO2 : constant Peripheral_Function := F; PA13_TCC1_WO3 : constant Peripheral_Function := G; PA15_TCC1_WO3 : constant Peripheral_Function := G; PA19_TCC1_WO3 : constant Peripheral_Function := F; PA08_TCC1_WO4 : constant Peripheral_Function := G; PA20_TCC1_WO4 : constant Peripheral_Function := F; PA09_TCC1_WO5 : constant Peripheral_Function := G; PA21_TCC1_WO5 : constant Peripheral_Function := F; PA10_TCC1_WO6 : constant Peripheral_Function := G; PA22_TCC1_WO6 : constant Peripheral_Function := F; PA11_TCC1_WO7 : constant Peripheral_Function := G; PA23_TCC1_WO7 : constant Peripheral_Function := F; PA14_TCC2_WO0 : constant Peripheral_Function := F; PA30_TCC2_WO0 : constant Peripheral_Function := F; PA15_TCC2_WO1 : constant Peripheral_Function := F; PA31_TCC2_WO1 : constant Peripheral_Function := F; PA24_TCC2_WO2 : constant Peripheral_Function := F; PB02_TCC2_WO2 : constant Peripheral_Function := F; PB12_TCC3_WO0 : constant Peripheral_Function := F; PB16_TCC3_WO0 : constant Peripheral_Function := F; PB13_TCC3_WO1 : constant Peripheral_Function := F; PB17_TCC3_WO1 : constant Peripheral_Function := F; PB14_TCC4_WO0 : constant Peripheral_Function := F; PB30_TCC4_WO0 : constant Peripheral_Function := F; PB15_TCC4_WO1 : constant Peripheral_Function := F; PB31_TCC4_WO1 : constant Peripheral_Function := F; PA24_USB_DM : constant Peripheral_Function := H; PA25_USB_DP : constant Peripheral_Function := H; PA23_USB_SOF_1KHZ : constant Peripheral_Function := H; PB22_USB_SOF_1KHZ : constant Peripheral_Function := H; end SAM.Functions;
pragma Ada_2005; pragma Style_Checks (Off); with Interfaces.C; use Interfaces.C; package avx2intrin_h is -- Copyright (C) 2011-2017 Free Software Foundation, Inc. -- This file is part of GCC. -- GCC is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 3, or (at your option) -- any later version. -- GCC 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. -- Under Section 7 of GPL version 3, you are granted additional -- permissions described in the GCC Runtime Library Exception, version -- 3.1, as published by the Free Software Foundation. -- You should have received a copy of the GNU General Public License and -- a copy of the GCC Runtime Library Exception along with this program; -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- <http://www.gnu.org/licenses/>. -- Sum absolute 8-bit integer difference of adjacent groups of 4 -- byte integers in the first 2 operands. Starting offsets within -- operands are determined by the 3rd mask operand. -- skipped func _mm256_abs_epi8 -- skipped func _mm256_abs_epi16 -- skipped func _mm256_abs_epi32 -- skipped func _mm256_packs_epi32 -- skipped func _mm256_packs_epi16 -- skipped func _mm256_packus_epi32 -- skipped func _mm256_packus_epi16 -- skipped func _mm256_add_epi8 -- skipped func _mm256_add_epi16 -- skipped func _mm256_add_epi32 -- skipped func _mm256_add_epi64 -- skipped func _mm256_adds_epi8 -- skipped func _mm256_adds_epi16 -- skipped func _mm256_adds_epu8 -- skipped func _mm256_adds_epu16 -- In that case (__N*8) will be in vreg, and insn will not be matched. -- Use define instead -- skipped func _mm256_and_si256 -- skipped func _mm256_andnot_si256 -- skipped func _mm256_avg_epu8 -- skipped func _mm256_avg_epu16 -- skipped func _mm256_blendv_epi8 -- skipped func _mm256_cmpeq_epi8 -- skipped func _mm256_cmpeq_epi16 -- skipped func _mm256_cmpeq_epi32 -- skipped func _mm256_cmpeq_epi64 -- skipped func _mm256_cmpgt_epi8 -- skipped func _mm256_cmpgt_epi16 -- skipped func _mm256_cmpgt_epi32 -- skipped func _mm256_cmpgt_epi64 -- skipped func _mm256_hadd_epi16 -- skipped func _mm256_hadd_epi32 -- skipped func _mm256_hadds_epi16 -- skipped func _mm256_hsub_epi16 -- skipped func _mm256_hsub_epi32 -- skipped func _mm256_hsubs_epi16 -- skipped func _mm256_maddubs_epi16 -- skipped func _mm256_madd_epi16 -- skipped func _mm256_max_epi8 -- skipped func _mm256_max_epi16 -- skipped func _mm256_max_epi32 -- skipped func _mm256_max_epu8 -- skipped func _mm256_max_epu16 -- skipped func _mm256_max_epu32 -- skipped func _mm256_min_epi8 -- skipped func _mm256_min_epi16 -- skipped func _mm256_min_epi32 -- skipped func _mm256_min_epu8 -- skipped func _mm256_min_epu16 -- skipped func _mm256_min_epu32 -- skipped func _mm256_movemask_epi8 -- skipped func _mm256_cvtepi8_epi16 -- skipped func _mm256_cvtepi8_epi32 -- skipped func _mm256_cvtepi8_epi64 -- skipped func _mm256_cvtepi16_epi32 -- skipped func _mm256_cvtepi16_epi64 -- skipped func _mm256_cvtepi32_epi64 -- skipped func _mm256_cvtepu8_epi16 -- skipped func _mm256_cvtepu8_epi32 -- skipped func _mm256_cvtepu8_epi64 -- skipped func _mm256_cvtepu16_epi32 -- skipped func _mm256_cvtepu16_epi64 -- skipped func _mm256_cvtepu32_epi64 -- skipped func _mm256_mul_epi32 -- skipped func _mm256_mulhrs_epi16 -- skipped func _mm256_mulhi_epu16 -- skipped func _mm256_mulhi_epi16 -- skipped func _mm256_mullo_epi16 -- skipped func _mm256_mullo_epi32 -- skipped func _mm256_mul_epu32 -- skipped func _mm256_or_si256 -- skipped func _mm256_sad_epu8 -- skipped func _mm256_shuffle_epi8 -- skipped func _mm256_sign_epi8 -- skipped func _mm256_sign_epi16 -- skipped func _mm256_sign_epi32 -- skipped func _mm256_slli_epi16 -- skipped func _mm256_sll_epi16 -- skipped func _mm256_slli_epi32 -- skipped func _mm256_sll_epi32 -- skipped func _mm256_slli_epi64 -- skipped func _mm256_sll_epi64 -- skipped func _mm256_srai_epi16 -- skipped func _mm256_sra_epi16 -- skipped func _mm256_srai_epi32 -- skipped func _mm256_sra_epi32 -- skipped func _mm256_srli_epi16 -- skipped func _mm256_srl_epi16 -- skipped func _mm256_srli_epi32 -- skipped func _mm256_srl_epi32 -- skipped func _mm256_srli_epi64 -- skipped func _mm256_srl_epi64 -- skipped func _mm256_sub_epi8 -- skipped func _mm256_sub_epi16 -- skipped func _mm256_sub_epi32 -- skipped func _mm256_sub_epi64 -- skipped func _mm256_subs_epi8 -- skipped func _mm256_subs_epi16 -- skipped func _mm256_subs_epu8 -- skipped func _mm256_subs_epu16 -- skipped func _mm256_unpackhi_epi8 -- skipped func _mm256_unpackhi_epi16 -- skipped func _mm256_unpackhi_epi32 -- skipped func _mm256_unpackhi_epi64 -- skipped func _mm256_unpacklo_epi8 -- skipped func _mm256_unpacklo_epi16 -- skipped func _mm256_unpacklo_epi32 -- skipped func _mm256_unpacklo_epi64 -- skipped func _mm256_xor_si256 -- skipped func _mm256_stream_load_si256 -- skipped func _mm_broadcastss_ps -- skipped func _mm256_broadcastss_ps -- skipped func _mm256_broadcastsd_pd -- skipped func _mm256_broadcastsi128_si256 -- skipped func _mm256_broadcastb_epi8 -- skipped func _mm256_broadcastw_epi16 -- skipped func _mm256_broadcastd_epi32 -- skipped func _mm256_broadcastq_epi64 -- skipped func _mm_broadcastb_epi8 -- skipped func _mm_broadcastw_epi16 -- skipped func _mm_broadcastd_epi32 -- skipped func _mm_broadcastq_epi64 -- skipped func _mm256_permutevar8x32_epi32 -- skipped func _mm256_permutevar8x32_ps -- skipped func _mm256_maskload_epi32 -- skipped func _mm256_maskload_epi64 -- skipped func _mm_maskload_epi32 -- skipped func _mm_maskload_epi64 -- skipped func _mm256_maskstore_epi32 -- skipped func _mm256_maskstore_epi64 -- skipped func _mm_maskstore_epi32 -- skipped func _mm_maskstore_epi64 -- skipped func _mm256_sllv_epi32 -- skipped func _mm_sllv_epi32 -- skipped func _mm256_sllv_epi64 -- skipped func _mm_sllv_epi64 -- skipped func _mm256_srav_epi32 -- skipped func _mm_srav_epi32 -- skipped func _mm256_srlv_epi32 -- skipped func _mm_srlv_epi32 -- skipped func _mm256_srlv_epi64 -- skipped func _mm_srlv_epi64 end avx2intrin_h;
with AdaM.Factory; package body AdaM.Statement is -- Storage Pool -- record_Version : constant := 1; max_Statements : constant := 5_000; package Pool is new AdaM.Factory.Pools (".adam-store", "statements", max_Statements, record_Version, Statement.item, Statement.view); -- Forge -- procedure define (Self : in out Item; Line : in String) is begin if Line /= "" then Self.Lines.append (+Line); end if; end define; procedure destruct (Self : in out Item) is begin null; end destruct; function new_Statement (Line : in String := "") return View is new_View : constant Statement.view := Pool.new_Item; begin define (Statement.item (new_View.all), Line); return new_View; end new_Statement; procedure free (Self : in out Statement.view) is begin destruct (Statement.item (Self.all)); Pool.free (Self); end free; -- Attributes -- overriding function Id (Self : access Item) return AdaM.Id is begin return Pool.to_Id (Self); end Id; overriding function Name (Self : in Item) return Identifier is pragma Unreferenced (Self); begin return "a_Statement"; end Name; overriding function to_Source (Self : in Item) return text_Vectors.Vector is begin return Self.Lines; end to_Source; -- Operations -- procedure add (Self : in out Item; the_Line : in String) is begin Self.Lines.Append (+the_Line); end add; -- Streams -- procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class; Self : in View) renames Pool.View_write; procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class; Self : out View) renames Pool.View_read; end AdaM.Statement;
pragma Ada_2012; package body System_Random is -- Underlying libc function function getentropy (buffer : out Element_Array; length : size_t) return int with Import => True, Convention => C, External_Name => "getentropy"; procedure Random (Output : aliased out Element_Array) is Return_Code : int := 0; begin Return_Code := getentropy (Output, size_t (Output'Length)); -- We're okay with this as Ada should automagically pass an address -- of the first array element. Array is defined as aliased array of -- aliased Elements, so that no funny business occurs -- We already checked in contract that Output'Length is less or -- equal to size_t'Last, therefore Constraint_Error is not -- going to ever occur here if Return_Code /= 0 then raise System_Random_Error with "getentropy failed with status code " & Return_Code'Image; end if; end Random; end System_Random;
-------------------------------------------------------------------------------- -- Copyright (c) 2013, Felix Krause <contact@flyx.org> -- -- Permission to use, copy, modify, and/or distribute this software for any -- purpose with or without fee is hereby granted, provided that the above -- copyright notice and this permission notice appear in all copies. -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -------------------------------------------------------------------------------- with CL.API; with CL.Enumerations; with CL.Helpers; package body CL.Events is procedure Adjust (Object : in out Event) is use type System.Address; begin if Object.Location /= System.Null_Address then Helpers.Error_Handler (API.Retain_Event (Object.Location)); end if; end Adjust; procedure Finalize (Object : in out Event) is use type System.Address; begin if Object.Location /= System.Null_Address then Helpers.Error_Handler (API.Release_Event (Object.Location)); end if; end Finalize; procedure Wait_For (Subject : Event) is List : constant Event_List (1..1) := (1 => Subject'Unchecked_Access); begin Wait_For (List); end Wait_For; procedure Wait_For (Subjects : Event_List) is Raw_List : Address_List (Subjects'Range); begin for Index in Subjects'Range loop Raw_List (Index) := Subjects (Index).Location; end loop; Helpers.Error_Handler (API.Wait_For_Events (Subjects'Length, Raw_List (1)'Address)); end Wait_For; function Command_Queue (Source : Event) return Command_Queues.Queue is function Getter is new Helpers.Get_Parameter (Return_T => System.Address, Parameter_T => Enumerations.Event_Info, C_Getter => API.Get_Event_Info); function New_CQ_Reference is new Helpers.New_Reference (Object_T => Command_Queues.Queue); begin return New_CQ_Reference (Getter (Source, Enumerations.Command_Queue)); end Command_Queue; function Kind (Source : Event) return Command_Type is function Getter is new Helpers.Get_Parameter (Return_T => Command_Type, Parameter_T => Enumerations.Event_Info, C_Getter => API.Get_Event_Info); begin return Getter (Source, Enumerations.Command_T); end Kind; function Reference_Count (Source : Event) return UInt is function Getter is new Helpers.Get_Parameter (Return_T => UInt, Parameter_T => Enumerations.Event_Info, C_Getter => API.Get_Event_Info); begin return Getter (Source, Enumerations.Reference_Count); end Reference_Count; function Status (Source : Event) return Execution_Status is function Getter is new Helpers.Get_Parameter (Return_T => Execution_Status, Parameter_T => Enumerations.Event_Info, C_Getter => API.Get_Event_Info); begin return Getter (Source, Enumerations.Command_Execution_Status); end Status; function Profiling_Info_ULong is new Helpers.Get_Parameter (Return_T => ULong, Parameter_T => Enumerations.Profiling_Info, C_Getter => API.Get_Event_Profiling_Info); function Queued_At (Source : Event) return ULong is begin return Profiling_Info_ULong (Source, Enumerations.Command_Queued); end Queued_At; function Submitted_At (Source : Event) return ULong is begin return Profiling_Info_ULong (Source, Enumerations.Submit); end Submitted_At; function Started_At (Source : Event) return ULong is begin return Profiling_Info_ULong (Source, Enumerations.Start); end Started_At; function Ended_At (Source : Event) return ULong is begin return Profiling_Info_ULong (Source, Enumerations.P_End); end Ended_At; end CL.Events;
with Interfaces.C.Strings, System; use type Interfaces.C.int, Interfaces.C.Strings.chars_ptr; package body FLTK.Dialogs is procedure dialog_fl_alert (M : in Interfaces.C.char_array); pragma Import (C, dialog_fl_alert, "dialog_fl_alert"); pragma Inline (dialog_fl_alert); -- function dialog_fl_ask -- (M : in Interfaces.C.char_array) -- return Interfaces.C.int; -- pragma Import (C, dialog_fl_ask, "dialog_fl_ask"); -- pragma Inline (dialog_fl_ask); procedure dialog_fl_beep (B : in Interfaces.C.int); pragma Import (C, dialog_fl_beep, "dialog_fl_beep"); pragma Inline (dialog_fl_beep); function dialog_fl_choice (M, A, B, C : in Interfaces.C.char_array) return Interfaces.C.int; pragma Import (C, dialog_fl_choice, "dialog_fl_choice"); pragma Inline (dialog_fl_choice); function dialog_fl_input (M, D : in Interfaces.C.char_array) return Interfaces.C.Strings.chars_ptr; pragma Import (C, dialog_fl_input, "dialog_fl_input"); pragma Inline (dialog_fl_input); procedure dialog_fl_message (M : in Interfaces.C.char_array); pragma Import (C, dialog_fl_message, "dialog_fl_message"); pragma Inline (dialog_fl_message); function dialog_fl_password (M, D : in Interfaces.C.char_array) return Interfaces.C.Strings.chars_ptr; pragma Import (C, dialog_fl_password, "dialog_fl_password"); pragma Inline (dialog_fl_password); function dialog_fl_color_chooser (N : in Interfaces.C.char_array; R, G, B : in out Interfaces.C.double; M : in Interfaces.C.int) return Interfaces.C.int; pragma Import (C, dialog_fl_color_chooser, "dialog_fl_color_chooser"); pragma Inline (dialog_fl_color_chooser); function dialog_fl_color_chooser2 (N : in Interfaces.C.char_array; R, G, B : in out Interfaces.C.unsigned_char; M : in Interfaces.C.int) return Interfaces.C.int; pragma Import (C, dialog_fl_color_chooser2, "dialog_fl_color_chooser2"); pragma Inline (dialog_fl_color_chooser2); function dialog_fl_dir_chooser (M, D : in Interfaces.C.char_array; R : in Interfaces.C.int) return Interfaces.C.Strings.chars_ptr; pragma Import (C, dialog_fl_dir_chooser, "dialog_fl_dir_chooser"); pragma Inline (dialog_fl_dir_chooser); function dialog_fl_file_chooser (M, P, D : in Interfaces.C.char_array; R : in Interfaces.C.int) return Interfaces.C.Strings.chars_ptr; pragma Import (C, dialog_fl_file_chooser, "dialog_fl_file_chooser"); pragma Inline (dialog_fl_file_chooser); function dialog_fl_get_message_hotspot return Interfaces.C.int; pragma Import (C, dialog_fl_get_message_hotspot, "dialog_fl_get_message_hotspot"); pragma Inline (dialog_fl_get_message_hotspot); procedure dialog_fl_set_message_hotspot (V : in Interfaces.C.int); pragma Import (C, dialog_fl_set_message_hotspot, "dialog_fl_set_message_hotspot"); pragma Inline (dialog_fl_set_message_hotspot); procedure dialog_fl_message_font (F, S : in Interfaces.C.int); pragma Import (C, dialog_fl_message_font, "dialog_fl_message_font"); pragma Inline (dialog_fl_message_font); function dialog_fl_message_icon return System.Address; pragma Import (C, dialog_fl_message_icon, "dialog_fl_message_icon"); pragma Inline (dialog_fl_message_icon); procedure dialog_fl_message_title (T : in Interfaces.C.char_array); pragma Import (C, dialog_fl_message_title, "dialog_fl_message_title"); pragma Inline (dialog_fl_message_title); procedure dialog_fl_message_title_default (T : in Interfaces.C.char_array); pragma Import (C, dialog_fl_message_title_default, "dialog_fl_message_title_default"); pragma Inline (dialog_fl_message_title_default); procedure Alert (Message : String) is begin dialog_fl_alert (Interfaces.C.To_C (Message)); end Alert; -- function Ask -- (Message : in String) -- return Boolean is -- begin -- return dialog_fl_ask (Interfaces.C.To_C (Message)) /= 0; -- end Ask; procedure Beep (Kind : in Beep_Kind) is begin dialog_fl_beep (Beep_Kind'Pos (Kind)); end Beep; function Three_Way_Choice (Message, Button1, Button2, Button3 : in String) return Choice is Result : Interfaces.C.int := dialog_fl_choice (Interfaces.C.To_C (Message), Interfaces.C.To_C (Button1), Interfaces.C.To_C (Button2), Interfaces.C.To_C (Button3)); begin return Choice'Val (Result); end Three_Way_Choice; function Text_Input (Message : in String; Default : in String := "") return String is Result : Interfaces.C.Strings.chars_ptr := dialog_fl_input (Interfaces.C.To_C (Message), Interfaces.C.To_C (Default)); begin -- string does not need dealloc if Result = Interfaces.C.Strings.Null_Ptr then return ""; else return Interfaces.C.Strings.Value (Result); end if; end Text_Input; procedure Message_Box (Message : in String) is begin dialog_fl_message (Interfaces.C.To_C (Message)); end Message_Box; function Password (Message : in String; Default : in String := "") return String is Result : Interfaces.C.Strings.chars_ptr := dialog_fl_password (Interfaces.C.To_C (Message), Interfaces.C.To_C (Default)); begin -- string does not need dealloc if Result = Interfaces.C.Strings.Null_Ptr then return ""; else return Interfaces.C.Strings.Value (Result); end if; end Password; function Color_Chooser (Title : in String; R, G, B : in out RGB_Float; Mode : in FLTK.Widgets.Groups.Color_Choosers.Color_Mode := FLTK.Widgets.Groups.Color_Choosers.RGB) return Boolean is C_R : Interfaces.C.double := Interfaces.C.double (R); C_G : Interfaces.C.double := Interfaces.C.double (G); C_B : Interfaces.C.double := Interfaces.C.double (B); M : Interfaces.C.int := FLTK.Widgets.Groups.Color_Choosers.Color_Mode'Pos (Mode); Result : Boolean := dialog_fl_color_chooser (Interfaces.C.To_C (Title), C_R, C_G, C_B, M) /= 0; begin R := RGB_Float (C_R); G := RGB_Float (C_G); B := RGB_Float (C_B); return Result; end Color_Chooser; function Color_Chooser (Title : in String; R, G, B : in out RGB_Int; Mode : in FLTK.Widgets.Groups.Color_Choosers.Color_Mode := FLTK.Widgets.Groups.Color_Choosers.RGB) return Boolean is C_R : Interfaces.C.unsigned_char := Interfaces.C.unsigned_char (R); C_G : Interfaces.C.unsigned_char := Interfaces.C.unsigned_char (G); C_B : Interfaces.C.unsigned_char := Interfaces.C.unsigned_char (B); M : Interfaces.C.int := FLTK.Widgets.Groups.Color_Choosers.Color_Mode'Pos (Mode); Result : Boolean := dialog_fl_color_chooser2 (Interfaces.C.To_C (Title), C_R, C_G, C_B, M) /= 0; begin R := RGB_Int (C_R); G := RGB_Int (C_G); B := RGB_Int (C_B); return Result; end Color_Chooser; function Dir_Chooser (Message, Default : in String; Relative : in Boolean := False) return String is Result : Interfaces.C.Strings.chars_ptr := dialog_fl_dir_chooser (Interfaces.C.To_C (Message), Interfaces.C.To_C (Default), Boolean'Pos (Relative)); begin -- I'm... fairly sure the string does not need dealloc? if Result = Interfaces.C.Strings.Null_Ptr then return ""; else return Interfaces.C.Strings.Value (Result); end if; end Dir_Chooser; function File_Chooser (Message, Filter_Pattern, Default : in String; Relative : in Boolean := False) return String is Result : Interfaces.C.Strings.chars_ptr := dialog_fl_file_chooser (Interfaces.C.To_C (Message), Interfaces.C.To_C (Filter_Pattern), Interfaces.C.To_C (Default), Boolean'Pos (Relative)); begin -- I'm... fairly sure the string does not need dealloc? if Result = Interfaces.C.Strings.Null_Ptr then return ""; else return Interfaces.C.Strings.Value (Result); end if; end File_Chooser; function Get_Hotspot return Boolean is begin return dialog_fl_get_message_hotspot /= 0; end Get_Hotspot; procedure Set_Hotspot (To : in Boolean) is begin dialog_fl_set_message_hotspot (Boolean'Pos (To)); end Set_Hotspot; procedure Set_Message_Font (Font : in Font_Kind; Size : in Font_Size) is begin dialog_fl_message_font (Font_Kind'Pos (Font), Interfaces.C.int (Size)); end Set_Message_Font; function Get_Message_Icon return FLTK.Widgets.Boxes.Box_Reference is begin return (Data => Icon_Box'Access); end Get_Message_Icon; procedure Set_Message_Title (To : in String) is begin dialog_fl_message_title (Interfaces.C.To_C (To)); end Set_Message_Title; procedure Set_Message_Title_Default (To : in String) is begin dialog_fl_message_title_default (Interfaces.C.To_C (To)); end Set_Message_Title_Default; begin Wrapper (Icon_Box).Void_Ptr := dialog_fl_message_icon; Wrapper (Icon_Box).Needs_Dealloc := False; end FLTK.Dialogs;
with Giza.GUI; with Giza.Widget; with Giza.Widget.Button; use Giza.Widget.Button; use Giza; with Test_Tiles_Window; use Test_Tiles_Window; with Test_Scroll_Window; use Test_Scroll_Window; with Test_Button_Window; use Test_Button_Window; with Test_Gnumber_Window; use Test_Gnumber_Window; with Test_Graphic_Bounds; use Test_Graphic_Bounds; with Test_Fonts; with Test_Keyboard_Window; with Test_Images; package body Test_Main_Window is ------------- -- On_Init -- ------------- overriding procedure On_Init (This : in out Main_Window) is begin This.Sub_Windows (1).Btn := new Button.Instance; This.Sub_Windows (1).Btn.Set_Text ("Gtile"); This.Sub_Windows (1).Win := new Tiles_Window; This.Sub_Windows (2).Btn := new Button.Instance; This.Sub_Windows (2).Btn.Set_Text ("Gscroll"); This.Sub_Windows (2).Win := new Scroll_Window; This.Sub_Windows (3).Btn := new Button.Instance; This.Sub_Windows (3).Btn.Set_Text ("Button"); This.Sub_Windows (3).Win := new Button_Window; This.Sub_Windows (4).Btn := new Button.Instance; This.Sub_Windows (4).Btn.Set_Text ("Number_Select"); This.Sub_Windows (4).Win := new Gnumber_Window; This.Sub_Windows (5).Btn := new Button.Instance; This.Sub_Windows (5).Btn.Set_Text ("Graphics"); This.Sub_Windows (5).Win := new Graphic_Bounds_Window; This.Sub_Windows (6).Btn := new Button.Instance; This.Sub_Windows (6).Btn.Set_Text ("Keyboard"); This.Sub_Windows (6).Win := new Test_Keyboard_Window.Keyboard_Window; This.Sub_Windows (7).Btn := new Button.Instance; This.Sub_Windows (7).Btn.Set_Text ("Fonts"); This.Sub_Windows (7).Win := new Test_Fonts.Test_Fonts_Window; This.Sub_Windows (8).Btn := new Button.Instance; This.Sub_Windows (8).Btn.Set_Text ("Images"); This.Sub_Windows (8).Win := new Test_Images.Images_Window; This.Btn_Tile := new Tiles.Instance (This.Sub_Windows'Length, Top_Down); This.Btn_Tile.Set_Size (This.Get_Size); This.Add_Child (Widget.Reference (This.Btn_Tile), (0, 0)); for Index in This.Sub_Windows'Range loop This.Sub_Windows (Index).Btn.Set_Rounded (20); This.Btn_Tile.Set_Child (Index, Widget.Reference (This.Sub_Windows (Index).Btn)); end loop; -- Uncomment to directly open a specific test window -- Giza.GUI.Push (This.Sub_Windows (8).Win); end On_Init; ------------------ -- On_Displayed -- ------------------ overriding procedure On_Displayed (This : in out Main_Window) is begin null; end On_Displayed; --------------- -- On_Hidden -- --------------- overriding procedure On_Hidden (This : in out Main_Window) is pragma Unreferenced (This); begin null; end On_Hidden; -------------- -- On_Click -- -------------- overriding function On_Position_Event (This : in out Main_Window; Evt : Position_Event_Ref; Pos : Point_T) return Boolean is begin if not On_Position_Event (Parent (This), Evt, Pos) then return False; end if; for Sub of This.Sub_Windows loop if Sub.Win /= null and then Sub.Btn /= null and then Sub.Btn.Active then Sub.Btn.Set_Active (False); Giza.GUI.Push (Sub.Win); return True; end if; end loop; return True; end On_Position_Event; end Test_Main_Window;
---------------------------------------- -- Copyright (C) 2019 Dmitriy Shadrin -- -- All rights reserved. -- ---------------------------------------- with Ada.Unchecked_Deallocation; with Ada.Text_IO; use Ada.Text_IO; with ConfigTree; use ConfigTree; with TimeStamp; -------------------------------------------------------------------------------- package body Proxy is procedure Free is new Ada.Unchecked_Deallocation (Configurator, ConfiguratorPtr); procedure Free is new Ada.Unchecked_Deallocation (Manager, ManagerPtr); --------------------------------- -- Configurator implementation -- --------------------------------- procedure Initialize (Object : in out Configurator) is begin Put_Line ("Init Configurator"); end Initialize; ----------------------------------------------------------------------------- procedure Finalize (Object : in out Configurator) is begin Put_Line ("Delete Configurator"); end Finalize; ----------------------------------------------------------------------------- function GetChild (ptr : in out Configurator; path : in String) return NodePtr is begin return ptr.data.GetChild (path); end GetChild; ----------------------------------------------------------------------------- function GetValue (ptr : in out Configurator; path : in String; default : in String := "") return String is begin return ptr.data.GetValue (path, default); end GetValue; --------------------------------- -- Manager implementation -- --------------------------------- procedure Initialize (Object : in out Manager) is loggerConfig : NodePtr; begin Put_Line ("Init Manager"); Object.config := new Configurator; loggerConfig := Object.config.GetChild ("proxy.logger"); TimeStamp.SetTimeCorrectValue (Long_Integer'Value (Object.config.GetValue ("proxy.system.tz"))); Object.logger := Logging.StartLogger (loggerConfig); end Initialize; ----------------------------------------------------------------------------- procedure Finalize (Object : in out Manager) is begin Logging.StopLogger; Free (Object.config); Put_Line ("Delete Manager"); end Finalize; ----------------------------------------------------------------------------- procedure Start (Object : in out Manager) is actors : NodePtr := GetConfig.data.GetChild ("proxy.actors"); begin if not IsNull (actors) then actors := null; end if; end Start; --------------------------------- -- Package free functions -- --------------------------------- function GetManager return ManagerPtr is begin if mgrPtr = null then mgrPtr := new Manager; end if; return mgrPtr; end GetManager; ----------------------------------------------------------------------------- function GetConfig return ConfiguratorPtr is begin return mgrPtr.config; end GetConfig; ----------------------------------------------------------------------------- procedure DeleteManager is begin Free (mgrPtr); end DeleteManager; ----------------------------------------------------------------------------- function GetLogger return Logging.LoggerPtr is begin return mgrPtr.logger; end GetLogger; end Proxy;
-- Copyright 2005 Free Software Foundation, Inc. -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program 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 -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -- MA 02110-1301, USA procedure P is type Index is (One, Two, Three); type Table is array (Integer range 1 .. 3) of Integer; type ETable is array (Index) of Integer; type RTable is array (Index range Two .. Three) of Integer; type UTable is array (Positive range <>) of Integer; type PTable is array (Index) of Boolean; pragma Pack (PTable); function Get_UTable (I : Integer) return UTable is begin return Utable'(1 => I, 2 => 2, 3 => 3); end Get_UTable; One_Two_Three : Table := (1, 2, 3); E_One_Two_Three : ETable := (1, 2, 3); R_Two_Three : RTable := (2, 3); U_One_Two_Three : UTable := Get_UTable (1); P_One_Two_Three : PTable := (False, True, True); Few_Reps : UTable := (1, 2, 3, 3, 3, 3, 3, 4, 5); Many_Reps : UTable := (1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5); Empty : array (1 .. 0) of Integer := (others => 0); begin One_Two_Three (1) := 4; -- START E_One_Two_Three (One) := 4; R_Two_Three (Two) := 4; U_One_Two_Three (U_One_Two_Three'First) := 4; P_One_Two_Three (One) := True; Few_Reps (Few_Reps'First) := 2; Many_Reps (Many_Reps'First) := 2; Empty := (others => 1); end P;
package Riemann is -- An approximation of the function erf(x)*pi/2, which is equal -- to the integral \int_0^x(e^(-t^2))dt. This integral does not -- have a closed algebraic solution. This function uses a simple -- Riemann sum to approximate the integral. -- -- The parameter n determines the number of segments to be used in the -- partition of equal size. There are 2^n segments. function erf_Riemann(x : Float; n : Integer) return Float; end Riemann;
package FLTK.Widgets.Buttons is type Button is new Widget with private; type Button_Reference (Data : not null access Button'Class) is limited null record with Implicit_Dereference => Data; type State is (Off, On); package Forge is function Create (X, Y, W, H : in Integer; Text : in String) return Button; end Forge; function Get_State (This : in Button) return State; procedure Set_State (This : in out Button; St : in State); procedure Set_Only (This : in out Button); function Get_Down_Box (This : in Button) return Box_Kind; procedure Set_Down_Box (This : in out Button; To : in Box_Kind); function Get_Shortcut (This : in Button) return Key_Combo; procedure Set_Shortcut (This : in out Button; Key : in Key_Combo); procedure Draw (This : in out Button); function Handle (This : in out Button; Event : in Event_Kind) return Event_Outcome; private type Button is new Widget with null record; overriding procedure Finalize (This : in out Button); pragma Inline (Get_State); pragma Inline (Set_State); pragma Inline (Set_Only); pragma Inline (Get_Down_Box); pragma Inline (Set_Down_Box); pragma Inline (Get_Shortcut); pragma Inline (Set_Shortcut); pragma Inline (Draw); pragma Inline (Handle); end FLTK.Widgets.Buttons;
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- A D A . N U M E R I C S . A U X _ F L O A T -- -- -- -- S p e c -- -- (C Math Library Version, Float) -- -- -- -- Copyright (C) 1992-2020, Free Software Foundation, Inc. -- -- -- -- 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 Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package provides the basic computational interface for the generic -- elementary functions. The C library version interfaces with the routines -- in the C mathematical library, and is thus quite portable. with Ada.Numerics.Aux_Linker_Options; pragma Warnings (Off, Ada.Numerics.Aux_Linker_Options); package Ada.Numerics.Aux_Float is pragma Pure; subtype T is Float; -- We import these functions directly from C. Note that we label them -- all as pure functions, because indeed all of them are in fact pure. function Sin (X : T) return T with Import, Convention => Intrinsic, External_Name => "sinf"; function Cos (X : T) return T with Import, Convention => Intrinsic, External_Name => "cosf"; function Tan (X : T) return T with Import, Convention => Intrinsic, External_Name => "tanf"; function Exp (X : T) return T with Import, Convention => Intrinsic, External_Name => "expf"; function Sqrt (X : T) return T with Import, Convention => Intrinsic, External_Name => "sqrtf"; function Log (X : T) return T with Import, Convention => Intrinsic, External_Name => "logf"; function Acos (X : T) return T with Import, Convention => Intrinsic, External_Name => "acosf"; function Asin (X : T) return T with Import, Convention => Intrinsic, External_Name => "asinf"; function Atan (X : T) return T with Import, Convention => Intrinsic, External_Name => "atanf"; function Sinh (X : T) return T with Import, Convention => Intrinsic, External_Name => "sinhf"; function Cosh (X : T) return T with Import, Convention => Intrinsic, External_Name => "coshf"; function Tanh (X : T) return T with Import, Convention => Intrinsic, External_Name => "tanhf"; function Pow (X, Y : T) return T with Import, Convention => Intrinsic, External_Name => "powf"; end Ada.Numerics.Aux_Float;
package body System_Function_Package is function System_A(X : Integer) return Integer is begin delay To_Duration(Milliseconds(100)); return X + 1; end System_A; function System_B(Y : Integer) return Integer is begin delay To_Duration(Milliseconds(200)); return Y * 2; end System_B; function System_C(X, Y : Integer) return Integer is begin delay To_Duration(Milliseconds(200)); return X * Y; end System_C; end System_Function_Package;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- P R J . C O N F -- -- -- -- B o d y -- -- -- -- Copyright (C) 2006-2015, Free Software Foundation, Inc. -- -- -- -- 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 Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT 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 GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Makeutl; use Makeutl; with MLib.Tgt; with Opt; use Opt; with Output; use Output; with Prj.Env; with Prj.Err; with Prj.Part; with Prj.PP; with Prj.Proc; use Prj.Proc; with Prj.Tree; use Prj.Tree; with Prj.Util; use Prj.Util; with Prj; use Prj; with Snames; use Snames; with Ada.Directories; use Ada.Directories; with Ada.Exceptions; use Ada.Exceptions; with GNAT.Case_Util; use GNAT.Case_Util; with GNAT.HTable; use GNAT.HTable; package body Prj.Conf is Auto_Cgpr : constant String := "auto.cgpr"; Config_Project_Env_Var : constant String := "GPR_CONFIG"; -- Name of the environment variable that provides the name of the -- configuration file to use. Gprconfig_Name : constant String := "gprconfig"; Warn_For_RTS : Boolean := True; -- Set to False when gprbuild parse again the project files, to avoid -- an incorrect warning. type Runtime_Root_Data; type Runtime_Root_Ptr is access Runtime_Root_Data; type Runtime_Root_Data is record Root : String_Access; Next : Runtime_Root_Ptr; end record; -- Data for a runtime root to be used when adding directories to the -- project path. type Compiler_Root_Data; type Compiler_Root_Ptr is access Compiler_Root_Data; type Compiler_Root_Data is record Root : String_Access; Runtimes : Runtime_Root_Ptr; Next : Compiler_Root_Ptr; end record; -- Data for a compiler root to be used when adding directories to the -- project path. First_Compiler_Root : Compiler_Root_Ptr := null; -- Head of the list of compiler roots package RTS_Languages is new GNAT.HTable.Simple_HTable (Header_Num => Prj.Header_Num, Element => Name_Id, No_Element => No_Name, Key => Name_Id, Hash => Prj.Hash, Equal => "="); -- Stores the runtime names for the various languages. This is in general -- set from a --RTS command line option. ----------------------- -- Local_Subprograms -- ----------------------- function Check_Target (Config_File : Prj.Project_Id; Autoconf_Specified : Boolean; Project_Tree : Prj.Project_Tree_Ref; Target : String := "") return Boolean; -- Check that the config file's target matches Target. -- Target should be set to the empty string when the user did not specify -- a target. If the target in the configuration file is invalid, this -- function will raise Invalid_Config with an appropriate message. -- Autoconf_Specified should be set to True if the user has used -- autoconf. function Locate_Config_File (Name : String) return String_Access; -- Search for Name in the config files directory. Return full path if -- found, or null otherwise. procedure Raise_Invalid_Config (Msg : String); pragma No_Return (Raise_Invalid_Config); -- Raises exception Invalid_Config with given message procedure Apply_Config_File (Config_File : Prj.Project_Id; Project_Tree : Prj.Project_Tree_Ref); -- Apply the configuration file settings to all the projects in the -- project tree. The Project_Tree must have been parsed first, and -- processed through the first phase so that all its projects are known. -- -- Currently, this will add new attributes and packages in the various -- projects, so that when the second phase of the processing is performed -- these attributes are automatically taken into account. type State is (No_State); procedure Look_For_Project_Paths (Project : Project_Id; Tree : Project_Tree_Ref; With_State : in out State); -- Check the compilers in the Project and add record them in the list -- rooted at First_Compiler_Root, with their runtimes, if they are not -- already in the list. procedure Update_Project_Path is new For_Every_Project_Imported (State => State, Action => Look_For_Project_Paths); ------------------------------------ -- Add_Default_GNAT_Naming_Scheme -- ------------------------------------ procedure Add_Default_GNAT_Naming_Scheme (Config_File : in out Project_Node_Id; Project_Tree : Project_Node_Tree_Ref) is procedure Create_Attribute (Name : Name_Id; Value : String; Index : String := ""; Pkg : Project_Node_Id := Empty_Node); ---------------------- -- Create_Attribute -- ---------------------- procedure Create_Attribute (Name : Name_Id; Value : String; Index : String := ""; Pkg : Project_Node_Id := Empty_Node) is Attr : Project_Node_Id; pragma Unreferenced (Attr); Expr : Name_Id := No_Name; Val : Name_Id := No_Name; Parent : Project_Node_Id := Config_File; begin if Index /= "" then Name_Len := Index'Length; Name_Buffer (1 .. Name_Len) := Index; Val := Name_Find; end if; if Pkg /= Empty_Node then Parent := Pkg; end if; Name_Len := Value'Length; Name_Buffer (1 .. Name_Len) := Value; Expr := Name_Find; Attr := Create_Attribute (Tree => Project_Tree, Prj_Or_Pkg => Parent, Name => Name, Index_Name => Val, Kind => Prj.Single, Value => Create_Literal_String (Expr, Project_Tree)); end Create_Attribute; -- Local variables Name : Name_Id; Naming : Project_Node_Id; Compiler : Project_Node_Id; -- Start of processing for Add_Default_GNAT_Naming_Scheme begin if Config_File = Empty_Node then -- Create a dummy config file if none was found Name_Len := Auto_Cgpr'Length; Name_Buffer (1 .. Name_Len) := Auto_Cgpr; Name := Name_Find; -- An invalid project name to avoid conflicts with user-created ones Name_Len := 5; Name_Buffer (1 .. Name_Len) := "_auto"; Config_File := Create_Project (In_Tree => Project_Tree, Name => Name_Find, Full_Path => Path_Name_Type (Name), Is_Config_File => True); -- Setup library support case MLib.Tgt.Support_For_Libraries is when None => null; when Static_Only => Create_Attribute (Name_Library_Support, "static_only"); when Full => Create_Attribute (Name_Library_Support, "full"); end case; if MLib.Tgt.Standalone_Library_Auto_Init_Is_Supported then Create_Attribute (Name_Library_Auto_Init_Supported, "true"); else Create_Attribute (Name_Library_Auto_Init_Supported, "false"); end if; -- Declare an empty target Create_Attribute (Name_Target, ""); -- Setup Ada support (Ada is the default language here, since this -- is only called when no config file existed initially, ie for -- gnatmake). Create_Attribute (Name_Default_Language, "ada"); Compiler := Create_Package (Project_Tree, Config_File, "compiler"); Create_Attribute (Name_Driver, "gcc", "ada", Pkg => Compiler); Create_Attribute (Name_Language_Kind, "unit_based", "ada", Pkg => Compiler); Create_Attribute (Name_Dependency_Kind, "ALI_File", "ada", Pkg => Compiler); Naming := Create_Package (Project_Tree, Config_File, "naming"); Create_Attribute (Name_Spec_Suffix, ".ads", "ada", Pkg => Naming); Create_Attribute (Name_Separate_Suffix, ".adb", "ada", Pkg => Naming); Create_Attribute (Name_Body_Suffix, ".adb", "ada", Pkg => Naming); Create_Attribute (Name_Dot_Replacement, "-", Pkg => Naming); Create_Attribute (Name_Casing, "lowercase", Pkg => Naming); if Current_Verbosity = High then Write_Line ("Automatically generated (in-memory) config file"); Prj.PP.Pretty_Print (Project => Config_File, In_Tree => Project_Tree, Backward_Compatibility => False); end if; end if; end Add_Default_GNAT_Naming_Scheme; ----------------------- -- Apply_Config_File -- ----------------------- procedure Apply_Config_File (Config_File : Prj.Project_Id; Project_Tree : Prj.Project_Tree_Ref) is procedure Add_Attributes (Project_Tree : Project_Tree_Ref; Conf_Decl : Declarations; User_Decl : in out Declarations); -- Process the attributes in the config declarations. For -- single string values, if the attribute is not declared in -- the user declarations, declare it with the value in the -- config declarations. For string list values, prepend the -- value in the user declarations with the value in the config -- declarations. -------------------- -- Add_Attributes -- -------------------- procedure Add_Attributes (Project_Tree : Project_Tree_Ref; Conf_Decl : Declarations; User_Decl : in out Declarations) is Shared : constant Shared_Project_Tree_Data_Access := Project_Tree.Shared; Conf_Attr_Id : Variable_Id; Conf_Attr : Variable; Conf_Array_Id : Array_Id; Conf_Array : Array_Data; Conf_Array_Elem_Id : Array_Element_Id; Conf_Array_Elem : Array_Element; Conf_List : String_List_Id; Conf_List_Elem : String_Element; User_Attr_Id : Variable_Id; User_Attr : Variable; User_Array_Id : Array_Id; User_Array : Array_Data; User_Array_Elem_Id : Array_Element_Id; User_Array_Elem : Array_Element; begin Conf_Attr_Id := Conf_Decl.Attributes; User_Attr_Id := User_Decl.Attributes; while Conf_Attr_Id /= No_Variable loop Conf_Attr := Shared.Variable_Elements.Table (Conf_Attr_Id); User_Attr := Shared.Variable_Elements.Table (User_Attr_Id); if not Conf_Attr.Value.Default then if User_Attr.Value.Default then -- No attribute declared in user project file: just copy -- the value of the configuration attribute. User_Attr.Value := Conf_Attr.Value; Shared.Variable_Elements.Table (User_Attr_Id) := User_Attr; elsif User_Attr.Value.Kind = List and then Conf_Attr.Value.Values /= Nil_String then -- List attribute declared in both the user project and the -- configuration project: prepend the user list with the -- configuration list. declare User_List : constant String_List_Id := User_Attr.Value.Values; Conf_List : String_List_Id := Conf_Attr.Value.Values; Conf_Elem : String_Element; New_List : String_List_Id; New_Elem : String_Element; begin -- Create new list String_Element_Table.Increment_Last (Shared.String_Elements); New_List := String_Element_Table.Last (Shared.String_Elements); -- Value of attribute is new list User_Attr.Value.Values := New_List; Shared.Variable_Elements.Table (User_Attr_Id) := User_Attr; loop -- Get each element of configuration list Conf_Elem := Shared.String_Elements.Table (Conf_List); New_Elem := Conf_Elem; Conf_List := Conf_Elem.Next; if Conf_List = Nil_String then -- If it is the last element in the list, connect -- to first element of user list, and we are done. New_Elem.Next := User_List; Shared.String_Elements.Table (New_List) := New_Elem; exit; else -- If it is not the last element in the list, add -- to new list. String_Element_Table.Increment_Last (Shared.String_Elements); New_Elem.Next := String_Element_Table.Last (Shared.String_Elements); Shared.String_Elements.Table (New_List) := New_Elem; New_List := New_Elem.Next; end if; end loop; end; end if; end if; Conf_Attr_Id := Conf_Attr.Next; User_Attr_Id := User_Attr.Next; end loop; Conf_Array_Id := Conf_Decl.Arrays; while Conf_Array_Id /= No_Array loop Conf_Array := Shared.Arrays.Table (Conf_Array_Id); User_Array_Id := User_Decl.Arrays; while User_Array_Id /= No_Array loop User_Array := Shared.Arrays.Table (User_Array_Id); exit when User_Array.Name = Conf_Array.Name; User_Array_Id := User_Array.Next; end loop; -- If this associative array does not exist in the user project -- file, do a shallow copy of the full associative array. if User_Array_Id = No_Array then Array_Table.Increment_Last (Shared.Arrays); User_Array := Conf_Array; User_Array.Next := User_Decl.Arrays; User_Decl.Arrays := Array_Table.Last (Shared.Arrays); Shared.Arrays.Table (User_Decl.Arrays) := User_Array; -- Otherwise, check each array element else Conf_Array_Elem_Id := Conf_Array.Value; while Conf_Array_Elem_Id /= No_Array_Element loop Conf_Array_Elem := Shared.Array_Elements.Table (Conf_Array_Elem_Id); User_Array_Elem_Id := User_Array.Value; while User_Array_Elem_Id /= No_Array_Element loop User_Array_Elem := Shared.Array_Elements.Table (User_Array_Elem_Id); exit when User_Array_Elem.Index = Conf_Array_Elem.Index; User_Array_Elem_Id := User_Array_Elem.Next; end loop; -- If the array element doesn't exist in the user array, -- insert a shallow copy of the conf array element in the -- user array. if User_Array_Elem_Id = No_Array_Element then Array_Element_Table.Increment_Last (Shared.Array_Elements); User_Array_Elem := Conf_Array_Elem; User_Array_Elem.Next := User_Array.Value; User_Array.Value := Array_Element_Table.Last (Shared.Array_Elements); Shared.Array_Elements.Table (User_Array.Value) := User_Array_Elem; Shared.Arrays.Table (User_Array_Id) := User_Array; -- Otherwise, if the value is a string list, prepend the -- conf array element value to the array element. elsif Conf_Array_Elem.Value.Kind = List then Conf_List := Conf_Array_Elem.Value.Values; if Conf_List /= Nil_String then declare Link : constant String_List_Id := User_Array_Elem.Value.Values; Previous : String_List_Id := Nil_String; Next : String_List_Id; begin loop Conf_List_Elem := Shared.String_Elements.Table (Conf_List); String_Element_Table.Increment_Last (Shared.String_Elements); Next := String_Element_Table.Last (Shared.String_Elements); Shared.String_Elements.Table (Next) := Conf_List_Elem; if Previous = Nil_String then User_Array_Elem.Value.Values := Next; Shared.Array_Elements.Table (User_Array_Elem_Id) := User_Array_Elem; else Shared.String_Elements.Table (Previous).Next := Next; end if; Previous := Next; Conf_List := Conf_List_Elem.Next; if Conf_List = Nil_String then Shared.String_Elements.Table (Previous).Next := Link; exit; end if; end loop; end; end if; end if; Conf_Array_Elem_Id := Conf_Array_Elem.Next; end loop; end if; Conf_Array_Id := Conf_Array.Next; end loop; end Add_Attributes; Shared : constant Shared_Project_Tree_Data_Access := Project_Tree.Shared; Conf_Decl : constant Declarations := Config_File.Decl; Conf_Pack_Id : Package_Id; Conf_Pack : Package_Element; User_Decl : Declarations; User_Pack_Id : Package_Id; User_Pack : Package_Element; Proj : Project_List; begin Debug_Output ("Applying config file to a project tree"); Proj := Project_Tree.Projects; while Proj /= null loop if Proj.Project /= Config_File then User_Decl := Proj.Project.Decl; Add_Attributes (Project_Tree => Project_Tree, Conf_Decl => Conf_Decl, User_Decl => User_Decl); Conf_Pack_Id := Conf_Decl.Packages; while Conf_Pack_Id /= No_Package loop Conf_Pack := Shared.Packages.Table (Conf_Pack_Id); User_Pack_Id := User_Decl.Packages; while User_Pack_Id /= No_Package loop User_Pack := Shared.Packages.Table (User_Pack_Id); exit when User_Pack.Name = Conf_Pack.Name; User_Pack_Id := User_Pack.Next; end loop; if User_Pack_Id = No_Package then Package_Table.Increment_Last (Shared.Packages); User_Pack := Conf_Pack; User_Pack.Next := User_Decl.Packages; User_Decl.Packages := Package_Table.Last (Shared.Packages); Shared.Packages.Table (User_Decl.Packages) := User_Pack; else Add_Attributes (Project_Tree => Project_Tree, Conf_Decl => Conf_Pack.Decl, User_Decl => Shared.Packages.Table (User_Pack_Id).Decl); end if; Conf_Pack_Id := Conf_Pack.Next; end loop; Proj.Project.Decl := User_Decl; -- For aggregate projects, we need to apply the config to all -- their aggregated trees as well. if Proj.Project.Qualifier in Aggregate_Project then declare List : Aggregated_Project_List; begin List := Proj.Project.Aggregated_Projects; while List /= null loop Debug_Output ("Recursively apply config to aggregated tree", List.Project.Name); Apply_Config_File (Config_File, Project_Tree => List.Tree); List := List.Next; end loop; end; end if; end if; Proj := Proj.Next; end loop; end Apply_Config_File; ------------------ -- Check_Target -- ------------------ function Check_Target (Config_File : Project_Id; Autoconf_Specified : Boolean; Project_Tree : Prj.Project_Tree_Ref; Target : String := "") return Boolean is Shared : constant Shared_Project_Tree_Data_Access := Project_Tree.Shared; Variable : constant Variable_Value := Value_Of (Name_Target, Config_File.Decl.Attributes, Shared); Tgt_Name : Name_Id := No_Name; OK : Boolean; begin if Variable /= Nil_Variable_Value and then not Variable.Default then Tgt_Name := Variable.Value; end if; OK := Target = "" or else (Tgt_Name /= No_Name and then (Length_Of_Name (Tgt_Name) = 0 or else Target = Get_Name_String (Tgt_Name))); if not OK then if Autoconf_Specified then if Verbose_Mode then Write_Line ("inconsistent targets, performing autoconf"); end if; return False; else if Tgt_Name /= No_Name then Raise_Invalid_Config ("mismatched targets: """ & Get_Name_String (Tgt_Name) & """ in configuration, """ & Target & """ specified"); else Raise_Invalid_Config ("no target specified in configuration file"); end if; end if; end if; return True; end Check_Target; -------------------------------------- -- Get_Or_Create_Configuration_File -- -------------------------------------- procedure Get_Or_Create_Configuration_File (Project : Project_Id; Conf_Project : Project_Id; Project_Tree : Project_Tree_Ref; Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref; Env : in out Prj.Tree.Environment; Allow_Automatic_Generation : Boolean; Config_File_Name : String := ""; Autoconf_Specified : Boolean; Target_Name : String := ""; Normalized_Hostname : String; Packages_To_Check : String_List_Access := null; Config : out Prj.Project_Id; Config_File_Path : out String_Access; Automatically_Generated : out Boolean; On_Load_Config : Config_File_Hook := null) is Shared : constant Shared_Project_Tree_Data_Access := Project_Tree.Shared; At_Least_One_Compiler_Command : Boolean := False; -- Set to True if at least one attribute Ide'Compiler_Command is -- specified for one language of the system. Conf_File_Name : String_Access := new String'(Config_File_Name); -- The configuration project file name. May be modified if there are -- switches --config= in the Builder package of the main project. Selected_Target : String_Access := new String'(Target_Name); function Default_File_Name return String; -- Return the name of the default config file that should be tested procedure Do_Autoconf; -- Generate a new config file through gprconfig. In case of error, this -- raises the Invalid_Config exception with an appropriate message procedure Check_Builder_Switches; -- Check for switches --config and --RTS in package Builder procedure Get_Project_Target; -- If Target_Name is empty, get the specified target in the project -- file, if any. procedure Get_Project_Runtimes; -- Get the various Runtime (<lang>) in the project file or any project -- it extends, if any are specified. function Get_Config_Switches return Argument_List_Access; -- Return the --config switches to use for gprconfig function Get_Db_Switches return Argument_List_Access; -- Return the --db switches to use for gprconfig function Might_Have_Sources (Project : Project_Id) return Boolean; -- True if the specified project might have sources (ie the user has not -- explicitly specified it. We haven't checked the file system, nor do -- we need to at this stage. ---------------------------- -- Check_Builder_Switches -- ---------------------------- procedure Check_Builder_Switches is Get_RTS_Switches : constant Boolean := RTS_Languages.Get_First = No_Name; -- If no switch --RTS have been specified on the command line, look -- for --RTS switches in the Builder switches. Builder : constant Package_Id := Value_Of (Name_Builder, Project.Decl.Packages, Shared); Switch_Array_Id : Array_Element_Id; -- The Switches to be checked procedure Check_Switches; -- Check the switches in Switch_Array_Id -------------------- -- Check_Switches -- -------------------- procedure Check_Switches is Switch_Array : Array_Element; Switch_List : String_List_Id := Nil_String; Switch : String_Element; Lang : Name_Id; Lang_Last : Positive; begin while Switch_Array_Id /= No_Array_Element loop Switch_Array := Shared.Array_Elements.Table (Switch_Array_Id); Switch_List := Switch_Array.Value.Values; List_Loop : while Switch_List /= Nil_String loop Switch := Shared.String_Elements.Table (Switch_List); if Switch.Value /= No_Name then Get_Name_String (Switch.Value); if Conf_File_Name'Length = 0 and then Name_Len > 9 and then Name_Buffer (1 .. 9) = "--config=" then Conf_File_Name := new String'(Name_Buffer (10 .. Name_Len)); elsif Get_RTS_Switches and then Name_Len >= 7 and then Name_Buffer (1 .. 5) = "--RTS" then if Name_Buffer (6) = '=' then if not Runtime_Name_Set_For (Name_Ada) then Set_Runtime_For (Name_Ada, Name_Buffer (7 .. Name_Len)); end if; elsif Name_Len > 7 and then Name_Buffer (6) = ':' and then Name_Buffer (7) /= '=' then Lang_Last := 7; while Lang_Last < Name_Len and then Name_Buffer (Lang_Last + 1) /= '=' loop Lang_Last := Lang_Last + 1; end loop; if Name_Buffer (Lang_Last + 1) = '=' then declare RTS : constant String := Name_Buffer (Lang_Last + 2 .. Name_Len); begin Name_Buffer (1 .. Lang_Last - 6) := Name_Buffer (7 .. Lang_Last); Name_Len := Lang_Last - 6; To_Lower (Name_Buffer (1 .. Name_Len)); Lang := Name_Find; if not Runtime_Name_Set_For (Lang) then Set_Runtime_For (Lang, RTS); end if; end; end if; end if; end if; end if; Switch_List := Switch.Next; end loop List_Loop; Switch_Array_Id := Switch_Array.Next; end loop; end Check_Switches; -- Start of processing for Check_Builder_Switches begin if Builder /= No_Package then Switch_Array_Id := Value_Of (Name => Name_Switches, In_Arrays => Shared.Packages.Table (Builder).Decl.Arrays, Shared => Shared); Check_Switches; Switch_Array_Id := Value_Of (Name => Name_Default_Switches, In_Arrays => Shared.Packages.Table (Builder).Decl.Arrays, Shared => Shared); Check_Switches; end if; end Check_Builder_Switches; ------------------------ -- Get_Project_Target -- ------------------------ procedure Get_Project_Target is begin if Selected_Target'Length = 0 then -- Check if attribute Target is specified in the main -- project, or in a project it extends. If it is, use this -- target to invoke gprconfig. declare Variable : Variable_Value; Proj : Project_Id; Tgt_Name : Name_Id := No_Name; begin Proj := Project; Project_Loop : while Proj /= No_Project loop Variable := Value_Of (Name_Target, Proj.Decl.Attributes, Shared); if Variable /= Nil_Variable_Value and then not Variable.Default and then Variable.Value /= No_Name then Tgt_Name := Variable.Value; exit Project_Loop; end if; Proj := Proj.Extends; end loop Project_Loop; if Tgt_Name /= No_Name then Selected_Target := new String'(Get_Name_String (Tgt_Name)); end if; end; end if; end Get_Project_Target; -------------------------- -- Get_Project_Runtimes -- -------------------------- procedure Get_Project_Runtimes is Element : Array_Element; Id : Array_Element_Id; Lang : Name_Id; Proj : Project_Id; begin Proj := Project; while Proj /= No_Project loop Id := Value_Of (Name_Runtime, Proj.Decl.Arrays, Shared); while Id /= No_Array_Element loop Element := Shared.Array_Elements.Table (Id); Lang := Element.Index; if not Runtime_Name_Set_For (Lang) then Set_Runtime_For (Lang, RTS_Name => Get_Name_String (Element.Value.Value)); end if; Id := Element.Next; end loop; Proj := Proj.Extends; end loop; end Get_Project_Runtimes; ----------------------- -- Default_File_Name -- ----------------------- function Default_File_Name return String is Ada_RTS : constant String := Runtime_Name_For (Name_Ada); Tmp : String_Access; begin if Selected_Target'Length /= 0 then if Ada_RTS /= "" then return Selected_Target.all & '-' & Ada_RTS & Config_Project_File_Extension; else return Selected_Target.all & Config_Project_File_Extension; end if; elsif Ada_RTS /= "" then return Ada_RTS & Config_Project_File_Extension; else Tmp := Getenv (Config_Project_Env_Var); declare T : constant String := Tmp.all; begin Free (Tmp); if T'Length = 0 then return Default_Config_Name; else return T; end if; end; end if; end Default_File_Name; ----------------- -- Do_Autoconf -- ----------------- procedure Do_Autoconf is Obj_Dir : constant Variable_Value := Value_Of (Name_Object_Dir, Conf_Project.Decl.Attributes, Shared); Gprconfig_Path : String_Access; Success : Boolean; begin Gprconfig_Path := Locate_Exec_On_Path (Gprconfig_Name); if Gprconfig_Path = null then Raise_Invalid_Config ("could not locate gprconfig for auto-configuration"); end if; -- First, find the object directory of the Conf_Project -- If the object directory is a relative one and Build_Tree_Dir is -- set, first add it. Name_Len := 0; if Obj_Dir = Nil_Variable_Value or else Obj_Dir.Default then if Build_Tree_Dir /= null then Add_Str_To_Name_Buffer (Build_Tree_Dir.all); if Get_Name_String (Conf_Project.Directory.Display_Name)'Length < Root_Dir'Length then Raise_Invalid_Config ("cannot relocate deeper than object directory"); end if; Add_Str_To_Name_Buffer (Relative_Path (Get_Name_String (Conf_Project.Directory.Display_Name), Root_Dir.all)); else Get_Name_String (Conf_Project.Directory.Display_Name); end if; else if Is_Absolute_Path (Get_Name_String (Obj_Dir.Value)) then Get_Name_String (Obj_Dir.Value); else if Build_Tree_Dir /= null then if Get_Name_String (Conf_Project.Directory.Display_Name)'Length < Root_Dir'Length then Raise_Invalid_Config ("cannot relocate deeper than object directory"); end if; Add_Str_To_Name_Buffer (Build_Tree_Dir.all); Add_Str_To_Name_Buffer (Relative_Path (Get_Name_String (Conf_Project.Directory.Display_Name), Root_Dir.all)); else Add_Str_To_Name_Buffer (Get_Name_String (Conf_Project.Directory.Display_Name)); end if; Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value)); end if; end if; if Subdirs /= null then Add_Char_To_Name_Buffer (Directory_Separator); Add_Str_To_Name_Buffer (Subdirs.all); end if; for J in 1 .. Name_Len loop if Name_Buffer (J) = '/' then Name_Buffer (J) := Directory_Separator; end if; end loop; -- Make sure that Obj_Dir ends with a directory separator if Name_Buffer (Name_Len) /= Directory_Separator then Name_Len := Name_Len + 1; Name_Buffer (Name_Len) := Directory_Separator; end if; declare Obj_Dir : constant String := Name_Buffer (1 .. Name_Len); Config_Switches : Argument_List_Access; Db_Switches : Argument_List_Access; Args : Argument_List (1 .. 5); Arg_Last : Positive; Obj_Dir_Exists : Boolean := True; begin -- Check if the object directory exists. If Setup_Projects is True -- (-p) and directory does not exist, attempt to create it. -- Otherwise, if directory does not exist, fail without calling -- gprconfig. if not Is_Directory (Obj_Dir) and then (Setup_Projects or else Subdirs /= null) then begin Create_Path (Obj_Dir); if not Quiet_Output then Write_Str ("object directory """); Write_Str (Obj_Dir); Write_Line (""" created"); end if; exception when others => Raise_Invalid_Config ("could not create object directory " & Obj_Dir); end; end if; if not Is_Directory (Obj_Dir) then case Env.Flags.Require_Obj_Dirs is when Error => Raise_Invalid_Config ("object directory " & Obj_Dir & " does not exist"); when Warning => Prj.Err.Error_Msg (Env.Flags, "?object directory " & Obj_Dir & " does not exist"); Obj_Dir_Exists := False; when Silent => null; end case; end if; -- Get the config switches. This should be done only now, as some -- runtimes may have been found in the Builder switches. Config_Switches := Get_Config_Switches; -- Get eventual --db switches Db_Switches := Get_Db_Switches; -- Invoke gprconfig Args (1) := new String'("--batch"); Args (2) := new String'("-o"); -- If no config file was specified, set the auto.cgpr one if Conf_File_Name'Length = 0 then if Obj_Dir_Exists then Args (3) := new String'(Obj_Dir & Auto_Cgpr); else declare Path_FD : File_Descriptor; Path_Name : Path_Name_Type; begin Prj.Env.Create_Temp_File (Shared => Project_Tree.Shared, Path_FD => Path_FD, Path_Name => Path_Name, File_Use => "configuration file"); if Path_FD /= Invalid_FD then declare Temp_Dir : constant String := Containing_Directory (Get_Name_String (Path_Name)); begin GNAT.OS_Lib.Close (Path_FD); Args (3) := new String'(Temp_Dir & Directory_Separator & Auto_Cgpr); Delete_File (Get_Name_String (Path_Name)); end; else -- We'll have an error message later on Args (3) := new String'(Obj_Dir & Auto_Cgpr); end if; end; end if; else Args (3) := Conf_File_Name; end if; Arg_Last := 3; if Selected_Target /= null and then Selected_Target.all /= "" then Args (4) := new String'("--target=" & Selected_Target.all); Arg_Last := 4; elsif Normalized_Hostname /= "" then if At_Least_One_Compiler_Command then Args (4) := new String'("--target=all"); else Args (4) := new String'("--target=" & Normalized_Hostname); end if; Arg_Last := 4; end if; if not Verbose_Mode then Arg_Last := Arg_Last + 1; Args (Arg_Last) := new String'("-q"); end if; if Verbose_Mode then Write_Str (Gprconfig_Name); for J in 1 .. Arg_Last loop Write_Char (' '); Write_Str (Args (J).all); end loop; for J in Config_Switches'Range loop Write_Char (' '); Write_Str (Config_Switches (J).all); end loop; for J in Db_Switches'Range loop Write_Char (' '); Write_Str (Db_Switches (J).all); end loop; Write_Eol; elsif not Quiet_Output then -- Display no message if we are creating auto.cgpr, unless in -- verbose mode. if Config_File_Name'Length > 0 or else Verbose_Mode then Write_Str ("creating "); Write_Str (Simple_Name (Args (3).all)); Write_Eol; end if; end if; Spawn (Gprconfig_Path.all, Args (1 .. Arg_Last) & Config_Switches.all & Db_Switches.all, Success); Free (Config_Switches); Config_File_Path := Locate_Config_File (Args (3).all); if Config_File_Path = null then Raise_Invalid_Config ("could not create " & Args (3).all); end if; for F in Args'Range loop Free (Args (F)); end loop; end; end Do_Autoconf; --------------------- -- Get_Db_Switches -- --------------------- function Get_Db_Switches return Argument_List_Access is Result : Argument_List_Access; Nmb_Arg : Natural; begin Nmb_Arg := (2 * Db_Switch_Args.Last) + Boolean'Pos (not Load_Standard_Base); Result := new Argument_List (1 .. Nmb_Arg); if Nmb_Arg /= 0 then for J in 1 .. Db_Switch_Args.Last loop Result (2 * J - 1) := new String'("--db"); Result (2 * J) := new String'(Get_Name_String (Db_Switch_Args.Table (J))); end loop; if not Load_Standard_Base then Result (Result'Last) := new String'("--db-"); end if; end if; return Result; end Get_Db_Switches; ------------------------- -- Get_Config_Switches -- ------------------------- function Get_Config_Switches return Argument_List_Access is package Language_Htable is new GNAT.HTable.Simple_HTable (Header_Num => Prj.Header_Num, Element => Name_Id, No_Element => No_Name, Key => Name_Id, Hash => Prj.Hash, Equal => "="); -- Hash table to keep the languages used in the project tree IDE : constant Package_Id := Value_Of (Name_Ide, Project.Decl.Packages, Shared); procedure Add_Config_Switches_For_Project (Project : Project_Id; Tree : Project_Tree_Ref; With_State : in out Integer); -- Add all --config switches for this project. This is also called -- for aggregate projects. ------------------------------------- -- Add_Config_Switches_For_Project -- ------------------------------------- procedure Add_Config_Switches_For_Project (Project : Project_Id; Tree : Project_Tree_Ref; With_State : in out Integer) is pragma Unreferenced (With_State); Shared : constant Shared_Project_Tree_Data_Access := Tree.Shared; Variable : Variable_Value; Check_Default : Boolean; Lang : Name_Id; List : String_List_Id; Elem : String_Element; begin if Might_Have_Sources (Project) then Variable := Value_Of (Name_Languages, Project.Decl.Attributes, Shared); if Variable = Nil_Variable_Value or else Variable.Default then -- Languages is not declared. If it is not an extending -- project, or if it extends a project with no Languages, -- check for Default_Language. Check_Default := Project.Extends = No_Project; if not Check_Default then Variable := Value_Of (Name_Languages, Project.Extends.Decl.Attributes, Shared); Check_Default := Variable /= Nil_Variable_Value and then Variable.Values = Nil_String; end if; if Check_Default then Variable := Value_Of (Name_Default_Language, Project.Decl.Attributes, Shared); if Variable /= Nil_Variable_Value and then not Variable.Default then Get_Name_String (Variable.Value); To_Lower (Name_Buffer (1 .. Name_Len)); Lang := Name_Find; Language_Htable.Set (Lang, Lang); -- If no default language is declared, default to Ada else Language_Htable.Set (Name_Ada, Name_Ada); end if; end if; elsif Variable.Values /= Nil_String then -- Attribute Languages is declared with a non empty list: -- put all the languages in Language_HTable. List := Variable.Values; while List /= Nil_String loop Elem := Shared.String_Elements.Table (List); Get_Name_String (Elem.Value); To_Lower (Name_Buffer (1 .. Name_Len)); Lang := Name_Find; Language_Htable.Set (Lang, Lang); List := Elem.Next; end loop; end if; end if; end Add_Config_Switches_For_Project; procedure For_Every_Imported_Project is new For_Every_Project_Imported (State => Integer, Action => Add_Config_Switches_For_Project); -- Document this procedure ??? -- Local variables Name : Name_Id; Count : Natural; Result : Argument_List_Access; Variable : Variable_Value; Dummy : Integer := 0; -- Start of processing for Get_Config_Switches begin For_Every_Imported_Project (By => Project, Tree => Project_Tree, With_State => Dummy, Include_Aggregated => True); Name := Language_Htable.Get_First; Count := 0; while Name /= No_Name loop Count := Count + 1; Name := Language_Htable.Get_Next; end loop; Result := new String_List (1 .. Count); Count := 1; Name := Language_Htable.Get_First; while Name /= No_Name loop -- Check if IDE'Compiler_Command is declared for the language. -- If it is, use its value to invoke gprconfig. Variable := Value_Of (Name, Attribute_Or_Array_Name => Name_Compiler_Command, In_Package => IDE, Shared => Shared, Force_Lower_Case_Index => True); declare Config_Command : constant String := "--config=" & Get_Name_String (Name); Runtime_Name : constant String := Runtime_Name_For (Name); begin -- In CodePeer mode, we do not take into account any compiler -- command from the package IDE. if CodePeer_Mode or else Variable = Nil_Variable_Value or else Length_Of_Name (Variable.Value) = 0 then Result (Count) := new String'(Config_Command & ",," & Runtime_Name); else At_Least_One_Compiler_Command := True; declare Compiler_Command : constant String := Get_Name_String (Variable.Value); begin if Is_Absolute_Path (Compiler_Command) then Result (Count) := new String' (Config_Command & ",," & Runtime_Name & "," & Containing_Directory (Compiler_Command) & "," & Simple_Name (Compiler_Command)); else Result (Count) := new String' (Config_Command & ",," & Runtime_Name & ",," & Compiler_Command); end if; end; end if; end; Count := Count + 1; Name := Language_Htable.Get_Next; end loop; return Result; end Get_Config_Switches; ------------------------ -- Might_Have_Sources -- ------------------------ function Might_Have_Sources (Project : Project_Id) return Boolean is Variable : Variable_Value; begin Variable := Value_Of (Name_Source_Dirs, Project.Decl.Attributes, Shared); if Variable = Nil_Variable_Value or else Variable.Default or else Variable.Values /= Nil_String then Variable := Value_Of (Name_Source_Files, Project.Decl.Attributes, Shared); return Variable = Nil_Variable_Value or else Variable.Default or else Variable.Values /= Nil_String; else return False; end if; end Might_Have_Sources; -- Local Variables Success : Boolean; Config_Project_Node : Project_Node_Id := Empty_Node; -- Start of processing for Get_Or_Create_Configuration_File begin pragma Assert (Prj.Env.Is_Initialized (Env.Project_Path)); Free (Config_File_Path); Config := No_Project; Get_Project_Target; Get_Project_Runtimes; Check_Builder_Switches; -- Do not attempt to find a configuration project file when -- Config_File_Name is No_Configuration_File. if Config_File_Name = No_Configuration_File then Config_File_Path := null; else if Conf_File_Name'Length > 0 then Config_File_Path := Locate_Config_File (Conf_File_Name.all); else Config_File_Path := Locate_Config_File (Default_File_Name); end if; if Config_File_Path = null then if not Allow_Automatic_Generation and then Conf_File_Name'Length > 0 then Raise_Invalid_Config ("could not locate main configuration project " & Conf_File_Name.all); end if; end if; end if; Automatically_Generated := Allow_Automatic_Generation and then Config_File_Path = null; <<Process_Config_File>> if Automatically_Generated then -- This might raise an Invalid_Config exception Do_Autoconf; -- If the config file is not auto-generated, warn if there is any --RTS -- switch, but not when the config file is generated in memory. elsif Warn_For_RTS and then RTS_Languages.Get_First /= No_Name and then Opt.Warning_Mode /= Opt.Suppress and then On_Load_Config = null then Write_Line ("warning: " & "runtimes are taken into account only in auto-configuration"); end if; -- Parse the configuration file if Verbose_Mode and then Config_File_Path /= null then Write_Str ("Checking configuration "); Write_Line (Config_File_Path.all); end if; if Config_File_Path /= null then Prj.Part.Parse (In_Tree => Project_Node_Tree, Project => Config_Project_Node, Project_File_Name => Config_File_Path.all, Errout_Handling => Prj.Part.Finalize_If_Error, Packages_To_Check => Packages_To_Check, Current_Directory => Current_Directory, Is_Config_File => True, Env => Env); else Config_Project_Node := Empty_Node; end if; if On_Load_Config /= null then On_Load_Config (Config_File => Config_Project_Node, Project_Node_Tree => Project_Node_Tree); end if; if Config_Project_Node /= Empty_Node then Prj.Proc.Process_Project_Tree_Phase_1 (In_Tree => Project_Tree, Project => Config, Packages_To_Check => Packages_To_Check, Success => Success, From_Project_Node => Config_Project_Node, From_Project_Node_Tree => Project_Node_Tree, Env => Env, Reset_Tree => False, On_New_Tree_Loaded => null); end if; if Config_Project_Node = Empty_Node or else Config = No_Project then Raise_Invalid_Config ("processing of configuration project """ & Config_File_Path.all & """ failed"); end if; -- Check that the target of the configuration file is the one the user -- specified on the command line. We do not need to check that when in -- auto-conf mode, since the appropriate target was passed to gprconfig. if not Automatically_Generated and then not Check_Target (Config, Autoconf_Specified, Project_Tree, Selected_Target.all) then Automatically_Generated := True; goto Process_Config_File; end if; end Get_Or_Create_Configuration_File; ------------------------ -- Locate_Config_File -- ------------------------ function Locate_Config_File (Name : String) return String_Access is Prefix_Path : constant String := Executable_Prefix_Path; begin if Prefix_Path'Length /= 0 then return Locate_Regular_File (Name, "." & Path_Separator & Prefix_Path & "share" & Directory_Separator & "gpr"); else return Locate_Regular_File (Name, "."); end if; end Locate_Config_File; ------------------------------------ -- Parse_Project_And_Apply_Config -- ------------------------------------ procedure Parse_Project_And_Apply_Config (Main_Project : out Prj.Project_Id; User_Project_Node : out Prj.Tree.Project_Node_Id; Config_File_Name : String := ""; Autoconf_Specified : Boolean; Project_File_Name : String; Project_Tree : Prj.Project_Tree_Ref; Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref; Env : in out Prj.Tree.Environment; Packages_To_Check : String_List_Access; Allow_Automatic_Generation : Boolean := True; Automatically_Generated : out Boolean; Config_File_Path : out String_Access; Target_Name : String := ""; Normalized_Hostname : String; On_Load_Config : Config_File_Hook := null; Implicit_Project : Boolean := False; On_New_Tree_Loaded : Prj.Proc.Tree_Loaded_Callback := null) is Success : Boolean := False; Target_Try_Again : Boolean := True; Config_Try_Again : Boolean; Finalization : Prj.Part.Errout_Mode := Prj.Part.Always_Finalize; S : State := No_State; Conf_File_Name : String_Access := new String'(Config_File_Name); procedure Add_Directory (Dir : String); -- Add a directory at the end of the Project Path Auto_Generated : Boolean; ------------------- -- Add_Directory -- ------------------- procedure Add_Directory (Dir : String) is begin if Opt.Verbose_Mode then Write_Line (" Adding directory """ & Dir & """"); end if; Prj.Env.Add_Directories (Env.Project_Path, Dir); end Add_Directory; begin pragma Assert (Prj.Env.Is_Initialized (Env.Project_Path)); -- Start with ignoring missing withed projects Set_Ignore_Missing_With (Env.Flags, True); -- Note: If in fact the config file is automatically generated, then -- Automatically_Generated will be set to True after invocation of -- Process_Project_And_Apply_Config. Automatically_Generated := False; -- Record Target_Value and Target_Origin if Target_Name = "" then Opt.Target_Value := new String'(Normalized_Hostname); Opt.Target_Origin := Default; else Opt.Target_Value := new String'(Target_Name); Opt.Target_Origin := Specified; end if; <<Parse_Again>> -- Parse the user project tree Project_Node_Tree.Incomplete_With := False; Env.Flags.Incomplete_Withs := False; Prj.Initialize (Project_Tree); Main_Project := No_Project; Prj.Part.Parse (In_Tree => Project_Node_Tree, Project => User_Project_Node, Project_File_Name => Project_File_Name, Errout_Handling => Finalization, Packages_To_Check => Packages_To_Check, Current_Directory => Current_Directory, Is_Config_File => False, Env => Env, Implicit_Project => Implicit_Project); Finalization := Prj.Part.Finalize_If_Error; if User_Project_Node = Empty_Node then return; end if; -- If --target was not specified on the command line, then do Phase 1 to -- check if attribute Target is declared in the main project. if Opt.Target_Origin /= Specified then Main_Project := No_Project; Process_Project_Tree_Phase_1 (In_Tree => Project_Tree, Project => Main_Project, Packages_To_Check => Packages_To_Check, Success => Success, From_Project_Node => User_Project_Node, From_Project_Node_Tree => Project_Node_Tree, Env => Env, Reset_Tree => True, On_New_Tree_Loaded => On_New_Tree_Loaded); if not Success then Main_Project := No_Project; return; end if; declare Variable : constant Variable_Value := Value_Of (Name_Target, Main_Project.Decl.Attributes, Project_Tree.Shared); begin if Variable /= Nil_Variable_Value and then not Variable.Default and then Get_Name_String (Variable.Value) /= Opt.Target_Value.all then if Target_Try_Again then Opt.Target_Value := new String'(Get_Name_String (Variable.Value)); Target_Try_Again := False; goto Parse_Again; else Fail_Program (Project_Tree, "inconsistent value of attribute Target"); end if; end if; end; end if; -- If there are missing withed projects, the projects will be parsed -- again after the project path is extended with directories rooted -- at the compiler roots. Config_Try_Again := Project_Node_Tree.Incomplete_With; Process_Project_And_Apply_Config (Main_Project => Main_Project, User_Project_Node => User_Project_Node, Config_File_Name => Conf_File_Name.all, Autoconf_Specified => Autoconf_Specified, Project_Tree => Project_Tree, Project_Node_Tree => Project_Node_Tree, Env => Env, Packages_To_Check => Packages_To_Check, Allow_Automatic_Generation => Allow_Automatic_Generation, Automatically_Generated => Auto_Generated, Config_File_Path => Config_File_Path, Target_Name => Target_Name, Normalized_Hostname => Normalized_Hostname, On_Load_Config => On_Load_Config, On_New_Tree_Loaded => On_New_Tree_Loaded, Do_Phase_1 => Opt.Target_Origin = Specified); if Auto_Generated then Automatically_Generated := True; end if; -- Exit if there was an error. Otherwise, if Config_Try_Again is True, -- update the project path and try again. if Main_Project /= No_Project and then Config_Try_Again then Set_Ignore_Missing_With (Env.Flags, False); if Config_File_Path /= null then Conf_File_Name := new String'(Config_File_Path.all); end if; -- For the second time the project files are parsed, the warning for -- --RTS= being only taken into account in auto-configuration are -- suppressed, as we are no longer in auto-configuration. Warn_For_RTS := False; -- Add the default directories corresponding to the compilers Update_Project_Path (By => Main_Project, Tree => Project_Tree, With_State => S, Include_Aggregated => True, Imported_First => False); declare Compiler_Root : Compiler_Root_Ptr; Prefix : String_Access; Runtime_Root : Runtime_Root_Ptr; Path_Value : constant String_Access := Getenv ("PATH"); begin if Opt.Verbose_Mode then Write_Line ("Setting the default project search directories"); if Prj.Current_Verbosity = High then if Path_Value = null or else Path_Value'Length = 0 then Write_Line ("No environment variable PATH"); else Write_Line ("PATH ="); Write_Line (" " & Path_Value.all); end if; end if; end if; -- Reorder the compiler roots in the PATH order if First_Compiler_Root /= null and then First_Compiler_Root.Next /= null then declare Pred : Compiler_Root_Ptr; First_New_Comp : Compiler_Root_Ptr := null; New_Comp : Compiler_Root_Ptr := null; First : Positive := Path_Value'First; Last : Positive; Path_Last : Positive; begin while First <= Path_Value'Last loop Last := First; if Path_Value (First) /= Path_Separator then while Last < Path_Value'Last and then Path_Value (Last + 1) /= Path_Separator loop Last := Last + 1; end loop; Path_Last := Last; while Path_Last > First and then Path_Value (Path_Last) = Directory_Separator loop Path_Last := Path_Last - 1; end loop; if Path_Last > First + 4 and then Path_Value (Path_Last - 2 .. Path_Last) = "bin" and then Path_Value (Path_Last - 3) = Directory_Separator then Path_Last := Path_Last - 4; Pred := null; Compiler_Root := First_Compiler_Root; while Compiler_Root /= null and then Compiler_Root.Root.all /= Path_Value (First .. Path_Last) loop Pred := Compiler_Root; Compiler_Root := Compiler_Root.Next; end loop; if Compiler_Root /= null then if Pred = null then First_Compiler_Root := First_Compiler_Root.Next; else Pred.Next := Compiler_Root.Next; end if; if First_New_Comp = null then First_New_Comp := Compiler_Root; else New_Comp.Next := Compiler_Root; end if; New_Comp := Compiler_Root; New_Comp.Next := null; end if; end if; end if; First := Last + 1; end loop; if First_New_Comp /= null then New_Comp.Next := First_Compiler_Root; First_Compiler_Root := First_New_Comp; end if; end; end if; -- Now that the compiler roots are in a correct order, add the -- directories corresponding to these compiler roots in the -- project path. Compiler_Root := First_Compiler_Root; while Compiler_Root /= null loop Prefix := Compiler_Root.Root; Runtime_Root := Compiler_Root.Runtimes; while Runtime_Root /= null loop Add_Directory (Runtime_Root.Root.all & Directory_Separator & "lib" & Directory_Separator & "gnat"); Add_Directory (Runtime_Root.Root.all & Directory_Separator & "share" & Directory_Separator & "gpr"); Runtime_Root := Runtime_Root.Next; end loop; Add_Directory (Prefix.all & Directory_Separator & Opt.Target_Value.all & Directory_Separator & "lib" & Directory_Separator & "gnat"); Add_Directory (Prefix.all & Directory_Separator & Opt.Target_Value.all & Directory_Separator & "share" & Directory_Separator & "gpr"); Add_Directory (Prefix.all & Directory_Separator & "share" & Directory_Separator & "gpr"); Add_Directory (Prefix.all & Directory_Separator & "lib" & Directory_Separator & "gnat"); Compiler_Root := Compiler_Root.Next; end loop; end; -- And parse again the project files. There will be no missing -- withed projects, as Ignore_Missing_With is set to False in -- the environment flags, so there is no risk of endless loop here. goto Parse_Again; end if; end Parse_Project_And_Apply_Config; -------------------------------------- -- Process_Project_And_Apply_Config -- -------------------------------------- procedure Process_Project_And_Apply_Config (Main_Project : out Prj.Project_Id; User_Project_Node : Prj.Tree.Project_Node_Id; Config_File_Name : String := ""; Autoconf_Specified : Boolean; Project_Tree : Prj.Project_Tree_Ref; Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref; Env : in out Prj.Tree.Environment; Packages_To_Check : String_List_Access; Allow_Automatic_Generation : Boolean := True; Automatically_Generated : out Boolean; Config_File_Path : out String_Access; Target_Name : String := ""; Normalized_Hostname : String; On_Load_Config : Config_File_Hook := null; Reset_Tree : Boolean := True; On_New_Tree_Loaded : Prj.Proc.Tree_Loaded_Callback := null; Do_Phase_1 : Boolean := True) is Shared : constant Shared_Project_Tree_Data_Access := Project_Tree.Shared; Main_Config_Project : Project_Id; Success : Boolean; Conf_Project : Project_Id := No_Project; -- The object directory of this project is used to store the config -- project file in auto-configuration. Set by Check_Project below. procedure Check_Project (Project : Project_Id); -- Look for a non aggregate project. If one is found, put its project Id -- in Conf_Project. ------------------- -- Check_Project -- ------------------- procedure Check_Project (Project : Project_Id) is begin if Project.Qualifier = Aggregate or else Project.Qualifier = Aggregate_Library then declare List : Aggregated_Project_List := Project.Aggregated_Projects; begin -- Look for a non aggregate project until one is found while Conf_Project = No_Project and then List /= null loop Check_Project (List.Project); List := List.Next; end loop; end; else Conf_Project := Project; end if; end Check_Project; -- Start of processing for Process_Project_And_Apply_Config begin Automatically_Generated := False; if Do_Phase_1 then Main_Project := No_Project; Process_Project_Tree_Phase_1 (In_Tree => Project_Tree, Project => Main_Project, Packages_To_Check => Packages_To_Check, Success => Success, From_Project_Node => User_Project_Node, From_Project_Node_Tree => Project_Node_Tree, Env => Env, Reset_Tree => Reset_Tree, On_New_Tree_Loaded => On_New_Tree_Loaded); if not Success then Main_Project := No_Project; return; end if; end if; if Project_Tree.Source_Info_File_Name /= null then if not Is_Absolute_Path (Project_Tree.Source_Info_File_Name.all) then declare Obj_Dir : constant Variable_Value := Value_Of (Name_Object_Dir, Main_Project.Decl.Attributes, Shared); begin if Obj_Dir = Nil_Variable_Value or else Obj_Dir.Default then Get_Name_String (Main_Project.Directory.Display_Name); else if Is_Absolute_Path (Get_Name_String (Obj_Dir.Value)) then Get_Name_String (Obj_Dir.Value); else Name_Len := 0; Add_Str_To_Name_Buffer (Get_Name_String (Main_Project.Directory.Display_Name)); Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value)); end if; end if; Add_Char_To_Name_Buffer (Directory_Separator); Add_Str_To_Name_Buffer (Project_Tree.Source_Info_File_Name.all); Free (Project_Tree.Source_Info_File_Name); Project_Tree.Source_Info_File_Name := new String'(Name_Buffer (1 .. Name_Len)); end; end if; Read_Source_Info_File (Project_Tree); end if; -- Get the first project that is not an aggregate project or an -- aggregate library project. The object directory of this project will -- be used to store the config project file in auto-configuration. Check_Project (Main_Project); -- Fail if there is only aggregate projects and aggregate library -- projects in the project tree. if Conf_Project = No_Project then Raise_Invalid_Config ("there are no non-aggregate projects"); end if; -- Find configuration file Get_Or_Create_Configuration_File (Config => Main_Config_Project, Project => Main_Project, Conf_Project => Conf_Project, Project_Tree => Project_Tree, Project_Node_Tree => Project_Node_Tree, Env => Env, Allow_Automatic_Generation => Allow_Automatic_Generation, Config_File_Name => Config_File_Name, Autoconf_Specified => Autoconf_Specified, Target_Name => Target_Name, Normalized_Hostname => Normalized_Hostname, Packages_To_Check => Packages_To_Check, Config_File_Path => Config_File_Path, Automatically_Generated => Automatically_Generated, On_Load_Config => On_Load_Config); Apply_Config_File (Main_Config_Project, Project_Tree); -- Finish processing the user's project Prj.Proc.Process_Project_Tree_Phase_2 (In_Tree => Project_Tree, Project => Main_Project, Success => Success, From_Project_Node => User_Project_Node, From_Project_Node_Tree => Project_Node_Tree, Env => Env); if Success then if Project_Tree.Source_Info_File_Name /= null and then not Project_Tree.Source_Info_File_Exists then Write_Source_Info_File (Project_Tree); end if; else Main_Project := No_Project; end if; end Process_Project_And_Apply_Config; -------------------------- -- Raise_Invalid_Config -- -------------------------- procedure Raise_Invalid_Config (Msg : String) is begin Raise_Exception (Invalid_Config'Identity, Msg); end Raise_Invalid_Config; ---------------------- -- Runtime_Name_For -- ---------------------- function Runtime_Name_For (Language : Name_Id) return String is begin if RTS_Languages.Get (Language) /= No_Name then return Get_Name_String (RTS_Languages.Get (Language)); else return ""; end if; end Runtime_Name_For; -------------------------- -- Runtime_Name_Set_For -- -------------------------- function Runtime_Name_Set_For (Language : Name_Id) return Boolean is begin return RTS_Languages.Get (Language) /= No_Name; end Runtime_Name_Set_For; --------------------- -- Set_Runtime_For -- --------------------- procedure Set_Runtime_For (Language : Name_Id; RTS_Name : String) is begin Name_Len := RTS_Name'Length; Name_Buffer (1 .. Name_Len) := RTS_Name; RTS_Languages.Set (Language, Name_Find); end Set_Runtime_For; ---------------------------- -- Look_For_Project_Paths -- ---------------------------- procedure Look_For_Project_Paths (Project : Project_Id; Tree : Project_Tree_Ref; With_State : in out State) is Lang_Id : Language_Ptr; Compiler_Root : Compiler_Root_Ptr; Runtime_Root : Runtime_Root_Ptr; Comp_Driver : String_Access; Comp_Dir : String_Access; Prefix : String_Access; pragma Unreferenced (Tree); begin With_State := No_State; Lang_Id := Project.Languages; while Lang_Id /= No_Language_Index loop if Lang_Id.Config.Compiler_Driver /= No_File then Comp_Driver := new String' (Get_Name_String (Lang_Id.Config.Compiler_Driver)); -- Get the absolute path of the compiler driver if not Is_Absolute_Path (Comp_Driver.all) then Comp_Driver := Locate_Exec_On_Path (Comp_Driver.all); end if; if Comp_Driver /= null and then Comp_Driver'Length > 0 then Comp_Dir := new String' (Containing_Directory (Comp_Driver.all)); -- Consider only the compiler drivers that are in "bin" -- subdirectories. if Simple_Name (Comp_Dir.all) = "bin" then Prefix := new String'(Containing_Directory (Comp_Dir.all)); -- Check if the compiler root is already in the list. If it -- is not, add it to the list. Compiler_Root := First_Compiler_Root; while Compiler_Root /= null loop exit when Prefix.all = Compiler_Root.Root.all; Compiler_Root := Compiler_Root.Next; end loop; if Compiler_Root = null then First_Compiler_Root := new Compiler_Root_Data' (Root => Prefix, Runtimes => null, Next => First_Compiler_Root); Compiler_Root := First_Compiler_Root; end if; -- If there is a runtime for this compiler, check if it is -- recorded with the compiler root. If it is not, record -- the runtime. declare Runtime : constant String := Runtime_Name_For (Lang_Id.Name); Root : String_Access; begin if Runtime'Length > 0 then if Is_Absolute_Path (Runtime) then Root := new String'(Runtime); else Root := new String' (Prefix.all & Directory_Separator & Opt.Target_Value.all & Directory_Separator & Runtime); end if; Runtime_Root := Compiler_Root.Runtimes; while Runtime_Root /= null loop exit when Root.all = Runtime_Root.Root.all; Runtime_Root := Runtime_Root.Next; end loop; if Runtime_Root = null then Compiler_Root.Runtimes := new Runtime_Root_Data' (Root => Root, Next => Compiler_Root.Runtimes); end if; end if; end; end if; end if; end if; Lang_Id := Lang_Id.Next; end loop; end Look_For_Project_Paths; end Prj.Conf;
-- Institution: Technische Universität München -- Department: Realtime Computer Systems (RCS) -- Project: StratoX -- -- Authors: Martin Becker (becker@rcs.ei.tum.de) with HIL.Devices.NVRAM; -- @summary -- Target-independent specification for HIL of NVRAM package HIL.NVRAM with Spark_Mode => On is subtype Address is HIL.Devices.NVRAM.NVRAM_Address; -- expose type -- the target-specific packages must specify the address type procedure Init; -- initialize the communication to the FRAM procedure Self_Check (Status : out Boolean); -- run a self-check. -- @return true on success procedure Read_Byte (addr : Address; byte : out HIL.Byte); -- read a single byte procedure Write_Byte (addr : Address; byte : HIL.Byte); -- with Pre => Is_Init; -- write a single byte end HIL.NVRAM;
package Test1 is Question: constant string := "How Many Characters?"; Ask_Twice: constant string := Question & Question; end Test1;
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- package body Program.Nodes is ----------------------- -- Enclosing_Element -- ----------------------- overriding function Enclosing_Element (Self : Node) return Program.Elements.Element_Access is begin return Self.Enclosing_Element; end Enclosing_Element; ------------------------ -- Is_Abort_Statement -- ------------------------ overriding function Is_Abort_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Abort_Statement; ------------------------- -- Is_Accept_Statement -- ------------------------- overriding function Is_Accept_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Accept_Statement; -------------------- -- Is_Access_Type -- -------------------- overriding function Is_Access_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Access_Type; ------------------ -- Is_Allocator -- ------------------ overriding function Is_Allocator (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Allocator; ------------------------------------ -- Is_Anonymous_Access_Definition -- ------------------------------------ overriding function Is_Anonymous_Access_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Anonymous_Access_Definition; ----------------------------------- -- Is_Anonymous_Access_To_Object -- ----------------------------------- overriding function Is_Anonymous_Access_To_Object (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Anonymous_Access_To_Object; -------------------------------------- -- Is_Anonymous_Access_To_Procedure -- -------------------------------------- overriding function Is_Anonymous_Access_To_Procedure (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Anonymous_Access_To_Procedure; ------------------------------------- -- Is_Anonymous_Access_To_Function -- ------------------------------------- overriding function Is_Anonymous_Access_To_Function (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Anonymous_Access_To_Function; ------------------------ -- Is_Array_Aggregate -- ------------------------ overriding function Is_Array_Aggregate (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Array_Aggregate; ------------------------------------ -- Is_Array_Component_Association -- ------------------------------------ overriding function Is_Array_Component_Association (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Array_Component_Association; ----------------------------- -- Is_Aspect_Specification -- ----------------------------- overriding function Is_Aspect_Specification (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Aspect_Specification; ----------------------------- -- Is_Assignment_Statement -- ----------------------------- overriding function Is_Assignment_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Assignment_Statement; -------------------- -- Is_Association -- -------------------- overriding function Is_Association (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Association; ------------------ -- Is_At_Clause -- ------------------ overriding function Is_At_Clause (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_At_Clause; ------------------------------------ -- Is_Attribute_Definition_Clause -- ------------------------------------ overriding function Is_Attribute_Definition_Clause (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Attribute_Definition_Clause; ---------------------------- -- Is_Attribute_Reference -- ---------------------------- overriding function Is_Attribute_Reference (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Attribute_Reference; ------------------------ -- Is_Block_Statement -- ------------------------ overriding function Is_Block_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Block_Statement; ----------------------- -- Is_Call_Statement -- ----------------------- overriding function Is_Call_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Call_Statement; ------------------------ -- Is_Case_Expression -- ------------------------ overriding function Is_Case_Expression (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Case_Expression; ----------------------------- -- Is_Case_Expression_Path -- ----------------------------- overriding function Is_Case_Expression_Path (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Case_Expression_Path; ------------------ -- Is_Case_Path -- ------------------ overriding function Is_Case_Path (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Case_Path; ----------------------- -- Is_Case_Statement -- ----------------------- overriding function Is_Case_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Case_Statement; -------------------------- -- Is_Character_Literal -- -------------------------- overriding function Is_Character_Literal (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Character_Literal; --------------------------------------- -- Is_Choice_Parameter_Specification -- --------------------------------------- overriding function Is_Choice_Parameter_Specification (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Choice_Parameter_Specification; --------------- -- Is_Clause -- --------------- overriding function Is_Clause (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Clause; ----------------------- -- Is_Code_Statement -- ----------------------- overriding function Is_Code_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Code_Statement; ------------------------- -- Is_Component_Clause -- ------------------------- overriding function Is_Component_Clause (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Component_Clause; ------------------------------ -- Is_Component_Declaration -- ------------------------------ overriding function Is_Component_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Component_Declaration; ----------------------------- -- Is_Component_Definition -- ----------------------------- overriding function Is_Component_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Component_Definition; ------------------------------- -- Is_Constrained_Array_Type -- ------------------------------- overriding function Is_Constrained_Array_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Constrained_Array_Type; ------------------- -- Is_Constraint -- ------------------- overriding function Is_Constraint (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Constraint; --------------------------------- -- Is_Decimal_Fixed_Point_Type -- --------------------------------- overriding function Is_Decimal_Fixed_Point_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Decimal_Fixed_Point_Type; -------------------- -- Is_Declaration -- -------------------- overriding function Is_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Declaration; ----------------------------------- -- Is_Defining_Character_Literal -- ----------------------------------- overriding function Is_Defining_Character_Literal (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Defining_Character_Literal; ------------------------------- -- Is_Defining_Expanded_Name -- ------------------------------- overriding function Is_Defining_Expanded_Name (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Defining_Expanded_Name; ---------------------------- -- Is_Defining_Identifier -- ---------------------------- overriding function Is_Defining_Identifier (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Defining_Identifier; ---------------------- -- Is_Defining_Name -- ---------------------- overriding function Is_Defining_Name (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Defining_Name; --------------------------------- -- Is_Defining_Operator_Symbol -- --------------------------------- overriding function Is_Defining_Operator_Symbol (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Defining_Operator_Symbol; ------------------- -- Is_Definition -- ------------------- overriding function Is_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Definition; ------------------------ -- Is_Delay_Statement -- ------------------------ overriding function Is_Delay_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Delay_Statement; ------------------------- -- Is_Delta_Constraint -- ------------------------- overriding function Is_Delta_Constraint (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Delta_Constraint; --------------------------------- -- Is_Derived_Record_Extension -- --------------------------------- overriding function Is_Derived_Record_Extension (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Derived_Record_Extension; --------------------- -- Is_Derived_Type -- --------------------- overriding function Is_Derived_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Derived_Type; -------------------------- -- Is_Digits_Constraint -- -------------------------- overriding function Is_Digits_Constraint (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Digits_Constraint; ----------------------- -- Is_Discrete_Range -- ----------------------- overriding function Is_Discrete_Range (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Discrete_Range; ------------------------------------------- -- Is_Discrete_Range_Attribute_Reference -- ------------------------------------------- overriding function Is_Discrete_Range_Attribute_Reference (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Discrete_Range_Attribute_Reference; ----------------------------------------- -- Is_Discrete_Simple_Expression_Range -- ----------------------------------------- overriding function Is_Discrete_Simple_Expression_Range (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Discrete_Simple_Expression_Range; ------------------------------------ -- Is_Discrete_Subtype_Indication -- ------------------------------------ overriding function Is_Discrete_Subtype_Indication (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Discrete_Subtype_Indication; --------------------------------- -- Is_Discriminant_Association -- --------------------------------- overriding function Is_Discriminant_Association (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Discriminant_Association; -------------------------------- -- Is_Discriminant_Constraint -- -------------------------------- overriding function Is_Discriminant_Constraint (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Discriminant_Constraint; ----------------------------------- -- Is_Discriminant_Specification -- ----------------------------------- overriding function Is_Discriminant_Specification (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Discriminant_Specification; --------------------------------------- -- Is_Element_Iterator_Specification -- --------------------------------------- overriding function Is_Element_Iterator_Specification (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Element_Iterator_Specification; ------------------------------ -- Is_Elsif_Expression_Path -- ------------------------------ overriding function Is_Elsif_Expression_Path (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Elsif_Expression_Path; ------------------- -- Is_Elsif_Path -- ------------------- overriding function Is_Elsif_Path (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Elsif_Path; ------------------------------- -- Is_Entry_Body_Declaration -- ------------------------------- overriding function Is_Entry_Body_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Entry_Body_Declaration; -------------------------- -- Is_Entry_Declaration -- -------------------------- overriding function Is_Entry_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Entry_Declaration; ---------------------------------- -- Is_Entry_Index_Specification -- ---------------------------------- overriding function Is_Entry_Index_Specification (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Entry_Index_Specification; ------------------------------------------ -- Is_Enumeration_Literal_Specification -- ------------------------------------------ overriding function Is_Enumeration_Literal_Specification (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Enumeration_Literal_Specification; ------------------------------------------ -- Is_Enumeration_Representation_Clause -- ------------------------------------------ overriding function Is_Enumeration_Representation_Clause (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Enumeration_Representation_Clause; ------------------------- -- Is_Enumeration_Type -- ------------------------- overriding function Is_Enumeration_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Enumeration_Type; ------------------------------ -- Is_Exception_Declaration -- ------------------------------ overriding function Is_Exception_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Exception_Declaration; -------------------------- -- Is_Exception_Handler -- -------------------------- overriding function Is_Exception_Handler (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Exception_Handler; --------------------------------------- -- Is_Exception_Renaming_Declaration -- --------------------------------------- overriding function Is_Exception_Renaming_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Exception_Renaming_Declaration; ----------------------- -- Is_Exit_Statement -- ----------------------- overriding function Is_Exit_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Exit_Statement; ----------------------------- -- Is_Explicit_Dereference -- ----------------------------- overriding function Is_Explicit_Dereference (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Explicit_Dereference; ------------------- -- Is_Expression -- ------------------- overriding function Is_Expression (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Expression; ---------------------------------- -- Is_Extended_Return_Statement -- ---------------------------------- overriding function Is_Extended_Return_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Extended_Return_Statement; ---------------------------- -- Is_Extension_Aggregate -- ---------------------------- overriding function Is_Extension_Aggregate (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Extension_Aggregate; ---------------------------- -- Is_Floating_Point_Type -- ---------------------------- overriding function Is_Floating_Point_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Floating_Point_Type; --------------------------- -- Is_For_Loop_Statement -- --------------------------- overriding function Is_For_Loop_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_For_Loop_Statement; --------------------------- -- Is_Formal_Access_Type -- --------------------------- overriding function Is_Formal_Access_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Access_Type; -------------------------------------- -- Is_Formal_Constrained_Array_Type -- -------------------------------------- overriding function Is_Formal_Constrained_Array_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Constrained_Array_Type; ---------------------------------------------- -- Is_Formal_Decimal_Fixed_Point_Definition -- ---------------------------------------------- overriding function Is_Formal_Decimal_Fixed_Point_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Decimal_Fixed_Point_Definition; --------------------------------------- -- Is_Formal_Derived_Type_Definition -- --------------------------------------- overriding function Is_Formal_Derived_Type_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Derived_Type_Definition; ---------------------------------------- -- Is_Formal_Discrete_Type_Definition -- ---------------------------------------- overriding function Is_Formal_Discrete_Type_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Discrete_Type_Definition; ----------------------------------------- -- Is_Formal_Floating_Point_Definition -- ----------------------------------------- overriding function Is_Formal_Floating_Point_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Floating_Point_Definition; ------------------------------------ -- Is_Formal_Function_Declaration -- ------------------------------------ overriding function Is_Formal_Function_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Function_Declaration; --------------------------------------- -- Is_Formal_Modular_Type_Definition -- --------------------------------------- overriding function Is_Formal_Modular_Type_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Modular_Type_Definition; ---------------------------------- -- Is_Formal_Object_Access_Type -- ---------------------------------- overriding function Is_Formal_Object_Access_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Object_Access_Type; ------------------------------------- -- Is_Formal_Procedure_Access_Type -- ------------------------------------- overriding function Is_Formal_Procedure_Access_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Procedure_Access_Type; ------------------------------------ -- Is_Formal_Function_Access_Type -- ------------------------------------ overriding function Is_Formal_Function_Access_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Function_Access_Type; ------------------------------ -- Is_Formal_Interface_Type -- ------------------------------ overriding function Is_Formal_Interface_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Interface_Type; ---------------------------------- -- Is_Formal_Object_Declaration -- ---------------------------------- overriding function Is_Formal_Object_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Object_Declaration; ----------------------------------------------- -- Is_Formal_Ordinary_Fixed_Point_Definition -- ----------------------------------------------- overriding function Is_Formal_Ordinary_Fixed_Point_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Ordinary_Fixed_Point_Definition; ----------------------------------- -- Is_Formal_Package_Association -- ----------------------------------- overriding function Is_Formal_Package_Association (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Package_Association; ----------------------------------- -- Is_Formal_Package_Declaration -- ----------------------------------- overriding function Is_Formal_Package_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Package_Declaration; --------------------------------------- -- Is_Formal_Private_Type_Definition -- --------------------------------------- overriding function Is_Formal_Private_Type_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Private_Type_Definition; ------------------------------------- -- Is_Formal_Procedure_Declaration -- ------------------------------------- overriding function Is_Formal_Procedure_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Procedure_Declaration; ---------------------------------------------- -- Is_Formal_Signed_Integer_Type_Definition -- ---------------------------------------------- overriding function Is_Formal_Signed_Integer_Type_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Signed_Integer_Type_Definition; -------------------------------- -- Is_Formal_Type_Declaration -- -------------------------------- overriding function Is_Formal_Type_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Type_Declaration; ------------------------------- -- Is_Formal_Type_Definition -- ------------------------------- overriding function Is_Formal_Type_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Type_Definition; ---------------------------------------- -- Is_Formal_Unconstrained_Array_Type -- ---------------------------------------- overriding function Is_Formal_Unconstrained_Array_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Formal_Unconstrained_Array_Type; ----------------------------- -- Is_Function_Access_Type -- ----------------------------- overriding function Is_Function_Access_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Function_Access_Type; ---------------------------------- -- Is_Function_Body_Declaration -- ---------------------------------- overriding function Is_Function_Body_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Function_Body_Declaration; --------------------------- -- Is_Function_Body_Stub -- --------------------------- overriding function Is_Function_Body_Stub (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Function_Body_Stub; ---------------------- -- Is_Function_Call -- ---------------------- overriding function Is_Function_Call (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Function_Call; ----------------------------- -- Is_Function_Declaration -- ----------------------------- overriding function Is_Function_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Function_Declaration; ------------------------------- -- Is_Function_Instantiation -- ------------------------------- overriding function Is_Function_Instantiation (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Function_Instantiation; -------------------------------------- -- Is_Function_Renaming_Declaration -- -------------------------------------- overriding function Is_Function_Renaming_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Function_Renaming_Declaration; ------------------------------------------- -- Is_Generalized_Iterator_Specification -- ------------------------------------------- overriding function Is_Generalized_Iterator_Specification (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Generalized_Iterator_Specification; ------------------------------------- -- Is_Generic_Function_Declaration -- ------------------------------------- overriding function Is_Generic_Function_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Generic_Function_Declaration; ---------------------------------------------- -- Is_Generic_Function_Renaming_Declaration -- ---------------------------------------------- overriding function Is_Generic_Function_Renaming_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Generic_Function_Renaming_Declaration; ------------------------------------ -- Is_Generic_Package_Declaration -- ------------------------------------ overriding function Is_Generic_Package_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Generic_Package_Declaration; --------------------------------------------- -- Is_Generic_Package_Renaming_Declaration -- --------------------------------------------- overriding function Is_Generic_Package_Renaming_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Generic_Package_Renaming_Declaration; -------------------------------------- -- Is_Generic_Procedure_Declaration -- -------------------------------------- overriding function Is_Generic_Procedure_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Generic_Procedure_Declaration; ----------------------------------------------- -- Is_Generic_Procedure_Renaming_Declaration -- ----------------------------------------------- overriding function Is_Generic_Procedure_Renaming_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Generic_Procedure_Renaming_Declaration; ----------------------- -- Is_Goto_Statement -- ----------------------- overriding function Is_Goto_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Goto_Statement; ------------------- -- Is_Identifier -- ------------------- overriding function Is_Identifier (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Identifier; ---------------------- -- Is_If_Expression -- ---------------------- overriding function Is_If_Expression (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_If_Expression; --------------------- -- Is_If_Statement -- --------------------- overriding function Is_If_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_If_Statement; ----------------------------------- -- Is_Incomplete_Type_Definition -- ----------------------------------- overriding function Is_Incomplete_Type_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Incomplete_Type_Definition; ------------------------- -- Is_Index_Constraint -- ------------------------- overriding function Is_Index_Constraint (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Index_Constraint; -------------------------- -- Is_Indexed_Component -- -------------------------- overriding function Is_Indexed_Component (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Indexed_Component; ----------------------- -- Is_Infix_Operator -- ----------------------- overriding function Is_Infix_Operator (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Infix_Operator; ----------------------- -- Is_Interface_Type -- ----------------------- overriding function Is_Interface_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Interface_Type; -------------------------------- -- Is_Known_Discriminant_Part -- -------------------------------- overriding function Is_Known_Discriminant_Part (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Known_Discriminant_Part; ------------------------------------- -- Is_Loop_Parameter_Specification -- ------------------------------------- overriding function Is_Loop_Parameter_Specification (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Loop_Parameter_Specification; ----------------------- -- Is_Loop_Statement -- ----------------------- overriding function Is_Loop_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Loop_Statement; ------------------------ -- Is_Membership_Test -- ------------------------ overriding function Is_Membership_Test (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Membership_Test; --------------------- -- Is_Modular_Type -- --------------------- overriding function Is_Modular_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Modular_Type; ----------------------- -- Is_Null_Component -- ----------------------- overriding function Is_Null_Component (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Null_Component; --------------------- -- Is_Null_Literal -- --------------------- overriding function Is_Null_Literal (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Null_Literal; ----------------------- -- Is_Null_Statement -- ----------------------- overriding function Is_Null_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Null_Statement; --------------------------- -- Is_Number_Declaration -- --------------------------- overriding function Is_Number_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Number_Declaration; ------------------------ -- Is_Numeric_Literal -- ------------------------ overriding function Is_Numeric_Literal (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Numeric_Literal; --------------------------- -- Is_Object_Access_Type -- --------------------------- overriding function Is_Object_Access_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Object_Access_Type; --------------------------- -- Is_Object_Declaration -- --------------------------- overriding function Is_Object_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Object_Declaration; ------------------------------------ -- Is_Object_Renaming_Declaration -- ------------------------------------ overriding function Is_Object_Renaming_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Object_Renaming_Declaration; ------------------------ -- Is_Operator_Symbol -- ------------------------ overriding function Is_Operator_Symbol (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Operator_Symbol; ---------------------------------- -- Is_Ordinary_Fixed_Point_Type -- ---------------------------------- overriding function Is_Ordinary_Fixed_Point_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Ordinary_Fixed_Point_Type; ---------------------- -- Is_Others_Choice -- ---------------------- overriding function Is_Others_Choice (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Others_Choice; --------------------------------- -- Is_Package_Body_Declaration -- --------------------------------- overriding function Is_Package_Body_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Package_Body_Declaration; -------------------------- -- Is_Package_Body_Stub -- -------------------------- overriding function Is_Package_Body_Stub (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Package_Body_Stub; ---------------------------- -- Is_Package_Declaration -- ---------------------------- overriding function Is_Package_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Package_Declaration; ------------------------------ -- Is_Package_Instantiation -- ------------------------------ overriding function Is_Package_Instantiation (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Package_Instantiation; ------------------------------------- -- Is_Package_Renaming_Declaration -- ------------------------------------- overriding function Is_Package_Renaming_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Package_Renaming_Declaration; ------------------------------ -- Is_Parameter_Association -- ------------------------------ overriding function Is_Parameter_Association (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Parameter_Association; -------------------------------- -- Is_Parameter_Specification -- -------------------------------- overriding function Is_Parameter_Specification (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Parameter_Specification; --------------------------------- -- Is_Parenthesized_Expression -- --------------------------------- overriding function Is_Parenthesized_Expression (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Parenthesized_Expression; ------------------------- -- Is_Part_Of_Implicit -- ------------------------- overriding function Is_Part_Of_Implicit (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Part_Of_Implicit; -------------------------- -- Is_Part_Of_Inherited -- -------------------------- overriding function Is_Part_Of_Inherited (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Part_Of_Inherited; ------------------------- -- Is_Part_Of_Instance -- ------------------------- overriding function Is_Part_Of_Instance (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Part_Of_Instance; ------------- -- Is_Path -- ------------- overriding function Is_Path (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Path; --------------- -- Is_Pragma -- --------------- overriding function Is_Pragma (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Pragma; ------------------------------------- -- Is_Private_Extension_Definition -- ------------------------------------- overriding function Is_Private_Extension_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Private_Extension_Definition; -------------------------------- -- Is_Private_Type_Definition -- -------------------------------- overriding function Is_Private_Type_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Private_Type_Definition; ------------------------------ -- Is_Procedure_Access_Type -- ------------------------------ overriding function Is_Procedure_Access_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Procedure_Access_Type; ----------------------------------- -- Is_Procedure_Body_Declaration -- ----------------------------------- overriding function Is_Procedure_Body_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Procedure_Body_Declaration; ---------------------------- -- Is_Procedure_Body_Stub -- ---------------------------- overriding function Is_Procedure_Body_Stub (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Procedure_Body_Stub; ------------------------------ -- Is_Procedure_Declaration -- ------------------------------ overriding function Is_Procedure_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Procedure_Declaration; -------------------------------- -- Is_Procedure_Instantiation -- -------------------------------- overriding function Is_Procedure_Instantiation (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Procedure_Instantiation; --------------------------------------- -- Is_Procedure_Renaming_Declaration -- --------------------------------------- overriding function Is_Procedure_Renaming_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Procedure_Renaming_Declaration; ----------------------------------- -- Is_Protected_Body_Declaration -- ----------------------------------- overriding function Is_Protected_Body_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Protected_Body_Declaration; ---------------------------- -- Is_Protected_Body_Stub -- ---------------------------- overriding function Is_Protected_Body_Stub (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Protected_Body_Stub; ----------------------------- -- Is_Protected_Definition -- ----------------------------- overriding function Is_Protected_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Protected_Definition; ----------------------------------- -- Is_Protected_Type_Declaration -- ----------------------------------- overriding function Is_Protected_Type_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Protected_Type_Declaration; ----------------------------- -- Is_Qualified_Expression -- ----------------------------- overriding function Is_Qualified_Expression (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Qualified_Expression; ------------------------------ -- Is_Quantified_Expression -- ------------------------------ overriding function Is_Quantified_Expression (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Quantified_Expression; ------------------------- -- Is_Raise_Expression -- ------------------------- overriding function Is_Raise_Expression (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Raise_Expression; ------------------------ -- Is_Raise_Statement -- ------------------------ overriding function Is_Raise_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Raise_Statement; ---------------------------------- -- Is_Range_Attribute_Reference -- ---------------------------------- overriding function Is_Range_Attribute_Reference (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Range_Attribute_Reference; --------------------------------- -- Is_Real_Range_Specification -- --------------------------------- overriding function Is_Real_Range_Specification (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Real_Range_Specification; ------------------------- -- Is_Record_Aggregate -- ------------------------- overriding function Is_Record_Aggregate (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Record_Aggregate; ------------------------------------- -- Is_Record_Component_Association -- ------------------------------------- overriding function Is_Record_Component_Association (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Record_Component_Association; -------------------------- -- Is_Record_Definition -- -------------------------- overriding function Is_Record_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Record_Definition; ------------------------------------- -- Is_Record_Representation_Clause -- ------------------------------------- overriding function Is_Record_Representation_Clause (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Record_Representation_Clause; -------------------- -- Is_Record_Type -- -------------------- overriding function Is_Record_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Record_Type; ------------------------------ -- Is_Representation_Clause -- ------------------------------ overriding function Is_Representation_Clause (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Representation_Clause; -------------------------- -- Is_Requeue_Statement -- -------------------------- overriding function Is_Requeue_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Requeue_Statement; ------------------------------------ -- Is_Return_Object_Specification -- ------------------------------------ overriding function Is_Return_Object_Specification (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Return_Object_Specification; ------------------ -- Is_Root_Type -- ------------------ overriding function Is_Root_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Root_Type; -------------------- -- Is_Select_Path -- -------------------- overriding function Is_Select_Path (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Select_Path; ------------------------- -- Is_Select_Statement -- ------------------------- overriding function Is_Select_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Select_Statement; --------------------------- -- Is_Selected_Component -- --------------------------- overriding function Is_Selected_Component (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Selected_Component; -------------------------------- -- Is_Short_Circuit_Operation -- -------------------------------- overriding function Is_Short_Circuit_Operation (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Short_Circuit_Operation; ---------------------------- -- Is_Signed_Integer_Type -- ---------------------------- overriding function Is_Signed_Integer_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Signed_Integer_Type; -------------------------------- -- Is_Simple_Expression_Range -- -------------------------------- overriding function Is_Simple_Expression_Range (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Simple_Expression_Range; -------------------------------- -- Is_Simple_Return_Statement -- -------------------------------- overriding function Is_Simple_Return_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Simple_Return_Statement; ------------------------------------- -- Is_Single_Protected_Declaration -- ------------------------------------- overriding function Is_Single_Protected_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Single_Protected_Declaration; -------------------------------- -- Is_Single_Task_Declaration -- -------------------------------- overriding function Is_Single_Task_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Single_Task_Declaration; -------------- -- Is_Slice -- -------------- overriding function Is_Slice (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Slice; ------------------ -- Is_Statement -- ------------------ overriding function Is_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Statement; ----------------------- -- Is_String_Literal -- ----------------------- overriding function Is_String_Literal (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_String_Literal; ---------------------------- -- Is_Subtype_Declaration -- ---------------------------- overriding function Is_Subtype_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Subtype_Declaration; --------------------------- -- Is_Subtype_Indication -- --------------------------- overriding function Is_Subtype_Indication (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Subtype_Indication; ------------------------------ -- Is_Task_Body_Declaration -- ------------------------------ overriding function Is_Task_Body_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Task_Body_Declaration; ----------------------- -- Is_Task_Body_Stub -- ----------------------- overriding function Is_Task_Body_Stub (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Task_Body_Stub; ------------------------ -- Is_Task_Definition -- ------------------------ overriding function Is_Task_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Task_Definition; ------------------------------ -- Is_Task_Type_Declaration -- ------------------------------ overriding function Is_Task_Type_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Task_Type_Declaration; ---------------------------------------- -- Is_Terminate_Alternative_Statement -- ---------------------------------------- overriding function Is_Terminate_Alternative_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Terminate_Alternative_Statement; ------------------------ -- Is_Type_Conversion -- ------------------------ overriding function Is_Type_Conversion (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Type_Conversion; ------------------------- -- Is_Type_Declaration -- ------------------------- overriding function Is_Type_Declaration (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Type_Declaration; ------------------------ -- Is_Type_Definition -- ------------------------ overriding function Is_Type_Definition (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Type_Definition; --------------------------------- -- Is_Unconstrained_Array_Type -- --------------------------------- overriding function Is_Unconstrained_Array_Type (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Unconstrained_Array_Type; ---------------------------------- -- Is_Unknown_Discriminant_Part -- ---------------------------------- overriding function Is_Unknown_Discriminant_Part (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Unknown_Discriminant_Part; ------------------- -- Is_Use_Clause -- ------------------- overriding function Is_Use_Clause (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Use_Clause; ---------------- -- Is_Variant -- ---------------- overriding function Is_Variant (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Variant; --------------------- -- Is_Variant_Part -- --------------------- overriding function Is_Variant_Part (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Variant_Part; ----------------------------- -- Is_While_Loop_Statement -- ----------------------------- overriding function Is_While_Loop_Statement (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_While_Loop_Statement; -------------------- -- Is_With_Clause -- -------------------- overriding function Is_With_Clause (Self : Node) return Boolean is pragma Unreferenced (Self); begin return False; end Is_With_Clause; --------------------------- -- Set_Enclosing_Element -- --------------------------- procedure Set_Enclosing_Element (Self : access Program.Elements.Element'Class; Value : access Program.Elements.Element'Class) is begin if Self.all in Node'Class then Node'Class (Self.all).Enclosing_Element := Value; end if; end Set_Enclosing_Element; end Program.Nodes;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; with Ada.Directories; with Helper; use Helper; with Courbes; use Courbes; with Courbes.Droites; use Courbes.Droites; with Courbes.Singletons; use Courbes.Singletons; with Courbes.Bezier_Cubiques; use Courbes.Bezier_Cubiques; with Courbes.Bezier_Quadratiques; use Courbes.Bezier_Quadratiques; with Interpolations_Lineaires; use Interpolations_Lineaires; with Vecteurs; use Vecteurs; -- Certains bonnes pratiques ont été sacrifiées -- pour rendre les TU plus courts/simples procedure test_unitaires is -- Activation des assert pragma Assertion_Policy(Check); LF : constant Character := Ada.Characters.Latin_1.LF; procedure Fichier_Ecrire_Chaine(F : String; S : String) is Handle : File_Type; begin begin Open(File => Handle, Mode => Out_File, Name => F); exception when Name_Error => Create(File => Handle, Mode => Out_File, Name => F); end; Put_Line(Handle, S); Close(Handle); end; procedure Test_Trouver_Ligne_Fichier is begin Fichier_Ecrire_Chaine("tu.tmp", "aze" & LF & "rty" & LF & "salut" & LF & "ca va""" & LF & "coucou"); declare Str : constant String := Fichier_Ligne_Commence_Par("tu.tmp", "ca"); begin pragma Assert (Str = " va"); end; Ada.Directories.Delete_File ("tu.tmp"); Debug("OK recherche ligne fichier"); end; procedure Test_Singleton is P : constant Point2D := (1 => 1.0, 2 => 2.0); S : Courbe_Ptr := new Singleton'(Ctor_Singleton(P)); begin pragma Assert (S.Obtenir_Debut = P, "S mauvais debut"); pragma Assert (S.Obtenir_Fin = P, "S mauvais fin"); pragma Assert (S.Obtenir_Point(0.0) = P, "S point 0.0 /= P"); pragma Assert (S.Obtenir_Point(1.0) = P, "S point 1.0 /= P"); pragma Assert (S.Obtenir_Point(0.5) = P, "S point 0.5 /= P"); Liberer_Courbe(S); pragma Assert (S = null, "S deallocated ptr /= null"); Debug("OK singleton"); end; procedure Test_Droite is Deb : constant Point2D := (1 => 1.0, 2 => 2.0); Fin : constant Point2D := (1 => 3.0, 2 => 4.0); Mid : constant Point2D := (Deb + Fin) / 2.0; D : Courbe_Ptr := new Droite'(Ctor_Droite(Deb, Fin)); begin pragma Assert (D.Obtenir_Debut = Deb, "BC mauvais debut"); pragma Assert (D.Obtenir_Fin = Fin, "BC mauvais fin"); pragma Assert (D.Obtenir_Point(0.0) = Deb, "BC point 0.0 /= debut"); pragma Assert (D.Obtenir_Point(1.0) = Fin, "BC point 1.0 /= fin"); pragma Assert (D.Obtenir_Point(0.5) = Mid, "BC point 0.5 /= mid"); Liberer_Courbe(D); pragma Assert (D = null, "D deallocated ptr /= null"); Debug("OK droite"); end; procedure Test_Cubique is Deb : constant Point2D := (1 => 0.0, 2 => 0.0); Fin : constant Point2D := (1 => 2.0, 2 => 2.0); C1 : constant Point2D := (1 => 1.5, 2 => 0.5); C2 : constant Point2D := (1 => 0.5, 2 => 1.5); Mid : constant Point2D := (others => 1.0); BC : Courbe_Ptr := new Bezier_Cubique'(Ctor_Bezier_Cubique(Deb, Fin, C1, C2)); begin pragma Assert (BC.Obtenir_Debut = Deb, "BC mauvais debut"); pragma Assert (BC.Obtenir_Fin = Fin, "BC fin"); pragma Assert (BC.Obtenir_Point(0.0) = Deb, "BC point 0.0 /= debut"); pragma Assert (BC.Obtenir_Point(1.0) = Fin, "BC point 1.0 /= fin"); pragma Assert (BC.Obtenir_Point(0.5) = Mid, "BC point 0.5 /= mid"); Liberer_Courbe(BC); pragma Assert (BC = null, "BC deallocated ptr /= null"); Debug("OK Bezier Cubique"); end; procedure Test_Quadratique is Deb : constant Point2D := (1 => 0.0, 2 => 0.0); Fin : constant Point2D := (1 => 10.0, 2 => 0.0); C : constant Point2D := (1 => 5.0, 2 => 10.0); Mid : constant Point2D := (others => 5.0); BQ : Courbe_Ptr := new Bezier_Quadratique'(Ctor_Bezier_Quadratique(Deb, Fin, C)); begin pragma Assert (BQ.Obtenir_Debut = Deb, "BQ mauvais debut"); pragma Assert (BQ.Obtenir_Fin = Fin, "BQ fin"); pragma Assert (BQ.Obtenir_Point(0.0) = Deb, "BQ point 0.0 /= debut"); pragma Assert (BQ.Obtenir_Point(1.0) = Fin, "BQ point 1.0 /= fin"); pragma Assert (BQ.Obtenir_Point(0.5) = Mid, "BQ point 0.5 /= mid"); Liberer_Courbe(BQ); pragma Assert (BQ = null, "BQ deallocated ptr /= null"); Debug("OK Bezier Quadratique"); end; procedure Test_Interpolation_Lineaire is L : Liste_Courbes.Liste; S : Liste_Points.Liste; Deb : constant Point2D := (1 => 0.0, 2 => 0.0); Fin : constant Point2D := (1 => 2.0, 2 => 2.0); D : Courbe_Ptr := new Droite'(Ctor_Droite(Deb, Fin)); I : Integer := 0; procedure Verif_Helper (P : in out Point2D) is Diff : constant Point2D := P - float(I) / 10.0 * Fin; begin pragma Assert(Diff(1) < 0.001, "Point invalide"); pragma Assert(Diff(2) < 0.001, "Point invalide"); I := I + 1; end; procedure Verif is new Liste_Points.Parcourir(Verif_Helper); begin Liste_Courbes.Insertion_Queue(L, D); Interpolation_Lineaire(L, S, 10, True); pragma Assert (Liste_Points.Taille(S) = 10, "Nb segments invalide"); Verif(S); Liberer_Courbe(D); Liste_Courbes.Vider(L); Liste_Points.Vider(S); Debug("OK Interpolation"); end; begin Afficher_Debug(True); Test_Trouver_Ligne_Fichier; Test_Singleton; Test_Droite; Test_Cubique; Test_Quadratique; Test_Interpolation_Lineaire; end;
with Asis.Declarations; with Asis.Elements; with Asis.Expressions; with Asis.Set_Get; package body Asis_Adapter.Element.Declarations is procedure Do_Pre_Child_Processing (Element : in Asis.Element; State : in out Class) is Parent_Name : constant String := Module_Name; Module_Name : constant String := Parent_Name & ".Do_Pre_Child_Processing"; Result : a_nodes_h.Declaration_Struct := a_nodes_h.Support.Default_Declaration_Struct; Declaration_Kind : Asis.Declaration_Kinds := Asis.Elements.Declaration_Kind (Element); -- Supporting procedures are in alphabetical order: procedure Add_Aspect_Specifications is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Aspect_Specifications (Element), Dot_Label_Name => "Aspect_Specifications", List_Out => Result.Aspect_Specifications, Add_Edges => True); end; -- This is obsolete a/o Ada95, and should be removed: procedure Add_Body_Block_Statement is begin Result.Body_Block_Statement := anhS.Empty_ID; end; procedure Add_Body_Declarative_Items is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Body_Declarative_Items (Element), Dot_Label_Name => "Body_Declarative_Items", List_Out => Result.Body_Declarative_Items, Add_Edges => True); end; procedure Add_Body_Exception_Handlers is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Body_Exception_Handlers (Element), Dot_Label_Name => "Body_Exception_Handlers", List_Out => Result.Body_Exception_Handlers, Add_Edges => True); end; procedure Add_Body_Statements is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Body_Statements (Element), Dot_Label_Name => "Body_Statements", List_Out => Result.Body_Statements, Add_Edges => True); end; procedure Add_Corresponding_Base_Entity is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Corresponding_Base_Entity (Element)); begin State.Add_To_Dot_Label ("Corresponding_Base_Entity", ID); Result.Corresponding_Base_Entity := ID; end; procedure Add_Corresponding_Body is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Corresponding_Body (Element)); begin State.Add_To_Dot_Label ("Corresponding_Body", ID); Result.Corresponding_Body := ID; end; --You can only call Add_Corresponding_Body on An_Entry_Declaration if it's --a protected definition. Weird, but I don't know how else to do this-Jim procedure Add_Corresponding_Body_If_A_Protected_Definition is use A4G.Int_Knds; ID : a_nodes_h.Element_ID := a_nodes_h.Support.Empty_ID; begin if Asis.Set_Get.Int_Kind (Asis.Elements.Enclosing_Element (Element)) = A_Protected_Definition then ID := Get_Element_ID (Asis.Declarations.Corresponding_Body (Element)); State.Add_To_Dot_Label ("Corresponding_Body", ID); end if; Result.Corresponding_Body := ID; end; procedure Add_Corresponding_Body_Stub is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Corresponding_Body_Stub (Element)); begin State.Add_To_Dot_Label ("Corresponding_Body_Stub", ID); Result.Corresponding_Body_Stub := ID; end; procedure Add_Corresponding_Declaration is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Corresponding_Declaration (Element)); begin State.Add_To_Dot_Label ("Corresponding_Declaration", ID); Result.Corresponding_Declaration := ID; end; procedure Add_Corresponding_End_Name is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Elements.Corresponding_End_Name (Element)); begin State.Add_To_Dot_Label ("Corresponding_End_Name", ID); Result.Corresponding_End_Name := ID; end; procedure Add_Corresponding_Equality_Operator is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Corresponding_Equality_Operator (Element)); begin State.Add_To_Dot_Label ("Corresponding_Equality_Operator", ID); Result.Corresponding_Equality_Operator := ID; end; procedure Add_Corresponding_First_Subtype is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Corresponding_First_Subtype (Element)); begin State.Add_To_Dot_Label ("Corresponding_First_Subtype", ID); Result.Corresponding_First_Subtype := ID; end; procedure Add_Corresponding_Last_Constraint is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Corresponding_Last_Constraint (Element)); begin State.Add_To_Dot_Label ("Corresponding_Last_Constraint", ID); Result.Corresponding_Last_Constraint := ID; end; procedure Add_Corresponding_Last_Subtype is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Corresponding_Last_Subtype (Element)); begin State.Add_To_Dot_Label ("Corresponding_Last_Subtype", ID); Result.Corresponding_Last_Subtype := ID; end; procedure Add_Corresponding_Pragmas is begin Add_Element_List (This => State, Elements_In => Asis.Elements.Corresponding_Pragmas (Element), Dot_Label_Name => "Corresponding_Pragmas", List_Out => Result.Corresponding_Pragmas, Add_Edges => True); end; procedure Add_Corresponding_Representation_Clauses is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Corresponding_Representation_Clauses (Element), Dot_Label_Name => "Corresponding_Representation_Clauses", List_Out => Result.Corresponding_Representation_Clauses); end; procedure Add_Corresponding_Subunit is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Corresponding_Subunit (Element)); begin State.Add_To_Dot_Label ("Corresponding_Subunit", ID); Result.Corresponding_Subprogram_Derivation := ID; end; --Asis will only accept this call on subprograms that have been derived. --So we need to check that before we call into ASIS procedure Add_Corresponding_Subprogram_Derivation is use Asis.Set_Get; ID : a_nodes_h.Element_ID := a_nodes_h.Support.Empty_ID; begin if(Is_From_Inherited (Element)) then ID := Get_Element_ID (Asis.Declarations.Corresponding_Subprogram_Derivation (Element)); State.Add_To_Dot_Label ("Corresponding_Subprogram_Derivation", ID); end if; Result.Corresponding_Subprogram_Derivation := ID; end; --Asis will only accept this call on subprograms that are implicit? --So we need to check that before we call into ASIS procedure Add_Corresponding_Type is use Asis.Set_Get; ID : a_nodes_h.Element_ID := a_nodes_h.Support.Empty_ID; begin if(Is_From_Implicit (Element)) then ID := Get_Element_ID (Asis.Declarations.Corresponding_Type (Element)); State.Add_To_Dot_Label ("Corresponding_Type", ID); end if; Result.Corresponding_Type := ID; end; procedure Add_Corresponding_Type_Completion is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Corresponding_Type_Completion (Element)); begin State.Add_To_Dot_Label ("Corresponding_Type_Completion", ID); Result.Corresponding_Type_Completion := ID; end; procedure Add_Corresponding_Type_Declaration is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Corresponding_Type_Declaration (Element)); begin State.Add_To_Dot_Label ("Corresponding_Type_Declaration", ID); Result.Corresponding_Type_Declaration := ID; end; procedure Add_Corresponding_Type_Partial_View is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Corresponding_Type_Partial_View (Element)); begin State.Add_To_Dot_Label ("Corresponding_Type_Partial_View", ID); Result.Corresponding_Type_Partial_View := ID; end; procedure Add_Declaration_Interface_List is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Declaration_Interface_List (Element), Dot_Label_Name => "Declaration_Interface_List", List_Out => Result.Declaration_Interface_List, Add_Edges => True); end; procedure Add_Declaration_Kind is -- Hides same thing in outer scope: Value : Asis.Declaration_Kinds := Asis.Elements.Declaration_Kind (Element); begin State.Add_To_Dot_Label ("Declaration_Kind", Value'Image); Result.Declaration_Kind := a_nodes_h.Support.To_Declaration_Kinds (Value); end; procedure Add_Default_Kind is -- Hides same thing in outer scope: Value : Asis.Subprogram_Default_Kinds := Asis.Elements.Default_Kind (Element); begin State.Add_To_Dot_Label ("Default_Kind", Value'Image); Result.Default_Kind := a_nodes_h.Support.To_Subprogram_Default_Kinds (Value); end; procedure Add_Declaration_Origin is Value : Asis.Declaration_Origins := Asis.Elements.Declaration_Origin (Element); begin State.Add_To_Dot_Label ("Declaration_Origin", Value'Image); Result.Declaration_Origin := a_nodes_h.Support.To_Declaration_Origins (Value); end; procedure Add_Discriminant_Part is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Discriminant_Part (Element)); begin State.Add_To_Dot_Label_And_Edge ("Discriminant_Part", ID); Result.Discriminant_Part := ID; end; -- Redirecting Add_Declaration_Subtype_Mark to Add_Object_Declaration_View. -- See Declaration_Subtype_Mark A2005 comment in asis.declarations.ads in function -- Object_Declaration_View. procedure Add_Object_Declaration_View; procedure Add_Declaration_Subtype_Mark renames Add_Object_Declaration_View; procedure Add_Entry_Barrier is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Entry_Barrier (Element)); begin State.Add_To_Dot_Label_And_Edge ("Entry_Barrier", ID); Result.Entry_Family_Definition := ID; end; procedure Add_Entry_Family_Definition is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Entry_Family_Definition (Element)); begin State.Add_To_Dot_Label_And_Edge ("Entry_Family_Definition", ID); Result.Entry_Family_Definition := ID; end; procedure Add_Entry_Index_Specification is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Entry_Index_Specification (Element)); begin State.Add_To_Dot_Label_And_Edge ("Entry_Index_Specification", ID); Result.Entry_Index_Specification := ID; end; procedure Add_Formal_Subprogram_Default is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Formal_Subprogram_Default (Element)); begin State.Add_To_Dot_Label_And_Edge ("Formal_Subprogram_Default", ID); Result.Formal_Subprogram_Default := ID; end; procedure Add_Generic_Actual_Part is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Generic_Actual_Part (Element), Dot_Label_Name => "Generic_Actual_Part", List_Out => Result.Generic_Actual_Part, Add_Edges => True); end; procedure Add_Generic_Formal_Part is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Generic_Formal_Part (Element), Dot_Label_Name => "Generic_Formal_Part", List_Out => Result.Generic_Formal_Part, Add_Edges => True); end; procedure Add_Generic_Unit_Name is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Generic_Unit_Name (Element)); begin State.Add_To_Dot_Label_And_Edge ("Generic_Unit_Name", ID); Result.Generic_Unit_Name := ID; end; procedure Add_Has_Abstract is Value : constant Boolean := Asis.Elements.Has_Abstract (Element); begin State.Add_To_Dot_Label ("Has_Abstract", Value); Result.Has_Abstract := a_nodes_h.Support.To_bool (Value); end; procedure Add_Has_Aliased is Value : constant Boolean := Asis.Elements.Has_Aliased (Element); begin State.Add_To_Dot_Label ("Has_Aliased", Value); Result.Has_Aliased := a_nodes_h.Support.To_bool (Value); end; procedure Add_Has_Limited is Value : constant Boolean := Asis.Elements.Has_Limited (Element); begin State.Add_To_Dot_Label ("Has_Limited", Value); Result.Has_Limited := a_nodes_h.Support.To_bool (Value); end; procedure Add_Has_Null_Exclusion is Value : constant Boolean := Asis.Elements.Has_Null_Exclusion (Element); begin State.Add_To_Dot_Label ("Has_Null_Exclusion", Value); Result.Has_Null_Exclusion := a_nodes_h.Support.To_bool (Value); end; procedure Add_Has_Private is Value : constant Boolean := Asis.Elements.Has_Private (Element); begin State.Add_To_Dot_Label ("Has_Private", Value); Result.Has_Private := a_nodes_h.Support.To_bool (Value); end; procedure Add_Has_Protected is Value : constant Boolean := Asis.Elements.Has_Protected (Element); begin State.Add_To_Dot_Label ("Has_Protected", Value); Result.Has_Protected := a_nodes_h.Support.To_bool (Value); end; procedure Add_Has_Reverse is Value : constant Boolean := Asis.Elements.Has_Reverse (Element); begin State.Add_To_Dot_Label ("Has_Reverse", Value); Result.Has_Reverse := a_nodes_h.Support.To_bool (Value); end; procedure Add_Has_Task is Value : constant Boolean := Asis.Elements.Has_Task (Element); begin State.Add_To_Dot_Label ("Has_Task", Value); Result.Has_Task := a_nodes_h.Support.To_bool (Value); end; procedure Add_Has_Tagged is Value : constant Boolean := Asis.Elements.Has_Tagged (Element); begin State.Add_To_Dot_Label ("Has_Tagged", Value); Result.Has_Task := a_nodes_h.Support.To_bool (Value); end; procedure Add_Initialization_Expression is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Initialization_Expression (Element)); begin State.Add_To_Dot_Label_And_Edge ("Initialization_Expression", ID); Result.Initialization_Expression := ID; end; procedure Add_Is_Dispatching_Operation is Value : constant Boolean := Asis.Declarations.Is_Dispatching_Operation (Element); begin State.Add_To_Dot_Label ("Is_Dispatching_Operation", Value); Result.Is_Dispatching_Operation := a_nodes_h.Support.To_bool (Value); end; procedure Add_Is_Name_Repeated is Value : constant Boolean := Asis.Declarations.Is_Name_Repeated (Element); begin State.Add_To_Dot_Label ("Is_Name_Repeated", Value); Result.Is_Name_Repeated := a_nodes_h.Support.To_bool (Value); end; procedure Add_Is_Not_Null_Return is Value : constant Boolean := Asis.Elements.Is_Not_Null_Return (Element); begin State.Add_To_Dot_Label ("Is_Not_Null_Return", Value); Result.Is_Not_Null_Return := a_nodes_h.Support.To_bool (Value); end; procedure Add_Is_Not_Overriding_Declaration is Value : constant Boolean := Asis.Declarations.Is_Not_Overriding_Declaration (Element); begin State.Add_To_Dot_Label ("Is_Not_Overriding_Declaration", Value); Result.Is_Not_Overriding_Declaration := a_nodes_h.Support.To_bool (Value); end; procedure Add_Is_Overriding_Declaration is Value : constant Boolean := Asis.Declarations.Is_Overriding_Declaration (Element); begin State.Add_To_Dot_Label ("Is_Overriding_Declaration", Value); Result.Is_Overriding_Declaration := a_nodes_h.Support.To_bool (Value); end; procedure Add_Is_Private_Present is Value : constant Boolean := Asis.Declarations.Is_Private_Present (Element); begin State.Add_To_Dot_Label ("Is_Private_Present", Value); Result.Is_Private_Present := a_nodes_h.Support.To_bool (Value); end; procedure Add_Is_Subunit is Value : constant Boolean := Asis.Declarations.Is_Subunit (Element); begin State.Add_To_Dot_Label ("Is_Subunit", Value); Result.Is_Subunit := a_nodes_h.Support.To_bool (Value); If Value then Add_Corresponding_Body_Stub; end if; end; -- Add_Iteration_Scheme_Name procedure Add_Iteration_Scheme_Name is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Iteration_Scheme_Name (Element)); begin State.Add_To_Dot_Label_And_Edge ("Iteration_Scheme_Name", ID); Result.Iteration_Scheme_Name := ID; end; procedure Add_Iterator_Specification is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Expressions.Iterator_Specification (Element)); begin State.Add_To_Dot_Label_And_Edge ("Iterator_Specification", ID); -- No Iterator_Specification in a_nodes yet: -- TODO: Add: -- Result.Iterator_Specification := ID; State.Add_Not_Implemented (Ada_2012); end; procedure Add_Mode_Kind is Value : constant Asis.Mode_Kinds := Asis.Elements.Mode_Kind (Element); begin State.Add_To_Dot_Label ("Mode_Kind", Value'Image); Result.Mode_Kind := a_nodes_h.Support.To_Mode_Kinds (Value); end; procedure Add_Names is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Names (Element), Dot_Label_Name => "Names", List_Out => Result.Names, Add_Edges => True); end; procedure Add_Object_Declaration_View is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Object_Declaration_View (Element)); begin State.Add_To_Dot_Label_And_Edge ("Object_Declaration_View", ID); Result.Object_Declaration_View := ID; end; procedure Add_Parameter_Profile is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Parameter_Profile (Element), Dot_Label_Name => "Parameter_Profile", List_Out => Result.Parameter_Profile, Add_Edges => True); end; procedure Add_Pragmas is begin Add_Element_List (This => State, Elements_In => Asis.Elements.Pragmas (Element), Dot_Label_Name => "Pragmas", List_Out => Result.Pragmas, Add_Edges => True); end; procedure Add_Protected_Operation_Items is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Protected_Operation_Items (Element), Dot_Label_Name => "Protected_Operation_Items", List_Out => Result.Protected_Operation_Items, Add_Edges => True); end; procedure Add_Private_Part_Declarative_Items is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Private_Part_Declarative_Items (Element), Dot_Label_Name => "Private_Part_Declarative_Items", List_Out => Result.Private_Part_Declarative_Items, Add_Edges => True); end; procedure Add_Renamed_Entity is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Renamed_Entity (Element)); begin State.Add_To_Dot_Label_And_Edge ("Renamed_Entity", ID); Result.Renamed_Entity := ID; end; procedure Add_Result_Profile is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Result_Profile (Element)); begin State.Add_To_Dot_Label_And_Edge ("Result_Profile", ID); Result.Result_Profile := ID; end; procedure Add_Specification_Subtype_Definition is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Specification_Subtype_Definition (Element)); begin State.Add_To_Dot_Label_And_Edge ("Specification_Subtype_Definition", ID); Result.Specification_Subtype_Definition := ID; end; procedure Add_Type_Declaration_View is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Declarations.Type_Declaration_View (Element)); begin State.Add_To_Dot_Label_And_Edge ("Type_Declaration_View", ID); Result.Type_Declaration_View := ID; end; procedure Add_Visible_Part_Declarative_Items is begin Add_Element_List (This => State, Elements_In => Asis.Declarations.Visible_Part_Declarative_Items (Element), Dot_Label_Name => "Visible_Part_Declarative_Items", List_Out => Result.Visible_Part_Declarative_Items, Add_Edges => True); end; procedure Add_Common_Items is begin Add_Declaration_Kind; Add_Declaration_Origin; Add_Corresponding_Pragmas; Add_Names; Add_Aspect_Specifications; Add_Corresponding_Representation_Clauses; end Add_Common_Items; use all type Asis.Declaration_Kinds; begin -- Process_Declaration If Declaration_Kind /= Not_A_Declaration then Add_Common_Items; end if; case Declaration_Kind is when Not_A_Declaration => raise Program_Error with Module_Name & " called with: " & Declaration_Kind'Image; when An_Ordinary_Type_Declaration => Add_Has_Abstract; Add_Has_Limited; Add_Discriminant_Part; Add_Type_Declaration_View; Add_Corresponding_Type_Declaration; Add_Corresponding_Type_Partial_View; Add_Corresponding_First_Subtype; Add_Corresponding_Last_Constraint; Add_Corresponding_Last_Subtype; when A_Task_Type_Declaration => Add_Has_Task; Add_Corresponding_End_Name; Add_Discriminant_Part; Add_Type_Declaration_View; Add_Corresponding_Type_Declaration; Add_Corresponding_Type_Partial_View; Add_Corresponding_First_Subtype; Add_Corresponding_Last_Constraint; Add_Corresponding_Last_Subtype; Add_Is_Name_Repeated; Add_Corresponding_Declaration; Add_Corresponding_Body; Add_Declaration_Interface_List; when A_Protected_Type_Declaration => Add_Has_Protected; Add_Corresponding_End_Name; Add_Discriminant_Part; Add_Type_Declaration_View; Add_Corresponding_Type_Declaration; Add_Corresponding_Type_Partial_View; Add_Corresponding_First_Subtype; Add_Corresponding_Last_Constraint; Add_Corresponding_Last_Subtype; Add_Is_Name_Repeated; Add_Corresponding_Declaration; Add_Corresponding_Body; Add_Declaration_Interface_List; when An_Incomplete_Type_Declaration => Add_Discriminant_Part; Add_Corresponding_Type_Declaration; Add_Corresponding_Type_Completion; -- TODO: (2005) -- asis.limited_withs.ads (2005) -- Is_From_Limited_View when A_Tagged_Incomplete_Type_Declaration => Add_Discriminant_Part; -- A2005 Add_Corresponding_Type_Declaration; -- A2005 Add_Corresponding_Type_Completion; Add_Has_Tagged; when A_Private_Type_Declaration => Add_Has_Abstract; Add_Has_Limited; Add_Has_Private; Add_Discriminant_Part; Add_Type_Declaration_View; Add_Corresponding_Type_Declaration; Add_Corresponding_Type_Completion; Add_Corresponding_Type_Partial_View; Add_Corresponding_First_Subtype; Add_Corresponding_Last_Constraint; Add_Corresponding_Last_Subtype; when A_Private_Extension_Declaration => Add_Has_Abstract; Add_Has_Limited; Add_Has_Private; Add_Discriminant_Part; Add_Type_Declaration_View; Add_Corresponding_Type_Declaration; Add_Corresponding_Type_Completion; Add_Corresponding_Type_Partial_View; Add_Corresponding_First_Subtype; Add_Corresponding_Last_Constraint; Add_Corresponding_Last_Subtype; when A_Subtype_Declaration => Add_Type_Declaration_View; Add_Corresponding_First_Subtype; Add_Corresponding_Last_Constraint; Add_Corresponding_Last_Subtype; when A_Variable_Declaration => Add_Has_Aliased; Add_Object_Declaration_View; Add_Initialization_Expression; when A_Constant_Declaration => Add_Has_Aliased; Add_Object_Declaration_View; Add_Initialization_Expression; when A_Deferred_Constant_Declaration => Add_Has_Aliased; Add_Object_Declaration_View; when A_Single_Task_Declaration => Add_Object_Declaration_View; Add_Is_Name_Repeated; Add_Corresponding_Declaration; Add_Corresponding_Body; Add_Declaration_Interface_List; Add_Has_Task; Add_Corresponding_End_Name; when A_Single_Protected_Declaration => Add_Object_Declaration_View; Add_Is_Name_Repeated; Add_Corresponding_Declaration; Add_Corresponding_Body; Add_Declaration_Interface_List; Add_Has_Protected; Add_Corresponding_End_Name; when An_Integer_Number_Declaration => Add_Initialization_Expression; when A_Real_Number_Declaration => Add_Initialization_Expression; when An_Enumeration_Literal_Specification => null; -- No more info when A_Discriminant_Specification => Add_Object_Declaration_View; -- A2005 Add_Initialization_Expression; Add_Declaration_Subtype_Mark; Add_Has_Null_Exclusion; when A_Component_Declaration => Add_Has_Aliased; Add_Object_Declaration_View; Add_Initialization_Expression; when A_Loop_Parameter_Specification => Add_Specification_Subtype_Definition; Add_Has_Reverse; when A_Generalized_Iterator_Specification => -- A2012 Add_Iterator_Specification; -- Has Add_Not_Implemented Add_Has_Reverse; when An_Element_Iterator_Specification => -- A2012 Add_Iteration_Scheme_Name; Add_Iterator_Specification; -- Has Add_Not_Implemented Add_Has_Reverse; when A_Procedure_Declaration => Add_Has_Abstract; Add_Is_Not_Null_Return; Add_Parameter_Profile; Add_Is_Overriding_Declaration; Add_Is_Not_Overriding_Declaration; Add_Corresponding_Declaration; Add_Corresponding_Body; Add_Corresponding_Subprogram_Derivation; Add_Corresponding_Type; Add_Is_Dispatching_Operation; when A_Function_Declaration => Add_Has_Abstract; Add_Parameter_Profile; Add_Result_Profile; Add_Is_Overriding_Declaration; Add_Is_Not_Overriding_Declaration; Add_Corresponding_Declaration; Add_Corresponding_Body; Add_Corresponding_Subprogram_Derivation; Add_Corresponding_Type; Add_Corresponding_Equality_Operator; Add_Is_Dispatching_Operation; when A_Parameter_Specification => Add_Has_Aliased; Add_Has_Null_Exclusion; Add_Mode_Kind; Add_Object_Declaration_View; Add_Initialization_Expression; when A_Procedure_Body_Declaration => Add_Pragmas; Add_Corresponding_End_Name; Add_Parameter_Profile; Add_Is_Overriding_Declaration; Add_Is_Not_Overriding_Declaration; Add_Body_Declarative_Items; Add_Body_Statements; Add_Body_Exception_Handlers; Add_Body_Block_Statement; Add_Is_Name_Repeated; Add_Corresponding_Declaration; Add_Is_Subunit; Add_Is_Dispatching_Operation; when A_Function_Body_Declaration => Add_Is_Not_Null_Return; Add_Pragmas; Add_Corresponding_End_Name; Add_Parameter_Profile; Add_Result_Profile; Add_Is_Overriding_Declaration; Add_Is_Not_Overriding_Declaration; Add_Body_Declarative_Items; Add_Body_Statements; Add_Body_Exception_Handlers; Add_Body_Block_Statement; Add_Is_Name_Repeated; Add_Corresponding_Declaration; Add_Is_Subunit; Add_Is_Dispatching_Operation; when A_Return_Variable_Specification => -- A2005 State.Add_Not_Implemented (Ada_2005); when A_Return_Constant_Specification => -- A2005 State.Add_Not_Implemented (Ada_2005); when A_Null_Procedure_Declaration => -- A2005 State.Add_Not_Implemented (Ada_2005); when An_Expression_Function_Declaration => -- A2012 State.Add_Not_Implemented (Ada_2012); when A_Package_Declaration => Add_Pragmas; Add_Corresponding_End_Name; Add_Is_Name_Repeated; Add_Corresponding_Declaration; Add_Corresponding_Body; Add_Visible_Part_Declarative_Items; Add_Is_Private_Present; Add_Private_Part_Declarative_Items; when A_Package_Body_Declaration => Add_Pragmas; Add_Corresponding_End_Name; Add_Body_Declarative_Items; Add_Body_Statements; Add_Body_Exception_Handlers; Add_Body_Block_Statement; Add_Is_Name_Repeated; Add_Corresponding_Declaration; Add_Is_Subunit; when An_Object_Renaming_Declaration => Add_Object_Declaration_View; -- A2005 Add_Declaration_Subtype_Mark; Add_Renamed_Entity; Add_Corresponding_Base_Entity; Add_Has_Null_Exclusion; -- A2005 when An_Exception_Renaming_Declaration => Add_Corresponding_Base_Entity; Add_Renamed_Entity; when A_Package_Renaming_Declaration => Add_Corresponding_Base_Entity; Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Renamed_Entity; when A_Procedure_Renaming_Declaration => Add_Corresponding_Base_Entity; Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Corresponding_Subprogram_Derivation; Add_Is_Dispatching_Operation; Add_Is_Not_Overriding_Declaration; Add_Is_Overriding_Declaration; Add_Parameter_Profile; Add_Renamed_Entity; when A_Function_Renaming_Declaration => Add_Corresponding_Base_Entity; Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Corresponding_Equality_Operator; Add_Corresponding_Subprogram_Derivation; Add_Is_Dispatching_Operation; Add_Is_Not_Overriding_Declaration; Add_Is_Overriding_Declaration; Add_Parameter_Profile; Add_Renamed_Entity; Add_Result_Profile; -- Add_Is_Not_Null_Return -- A2005 when A_Generic_Package_Renaming_Declaration => Add_Corresponding_Base_Entity; Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Renamed_Entity; when A_Generic_Procedure_Renaming_Declaration => Add_Corresponding_Base_Entity; Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Renamed_Entity; when A_Generic_Function_Renaming_Declaration => Add_Corresponding_Base_Entity; Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Renamed_Entity; when A_Task_Body_Declaration => Add_Has_Task; Add_Pragmas; Add_Corresponding_End_Name; Add_Body_Declarative_Items; Add_Body_Statements; Add_Body_Exception_Handlers; Add_Body_Block_Statement; Add_Is_Name_Repeated; Add_Corresponding_Declaration; Add_Is_Subunit; when A_Protected_Body_Declaration => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Corresponding_End_Name; Add_Has_Protected; Add_Is_Name_Repeated; Add_Is_Subunit; Add_Pragmas; Add_Protected_Operation_Items; when An_Entry_Declaration => Add_Parameter_Profile; Add_Is_Overriding_Declaration; Add_Is_Not_Overriding_Declaration; Add_Corresponding_Declaration; Add_Corresponding_Body_If_A_Protected_Definition; Add_Entry_Family_Definition; when An_Entry_Body_Declaration => Add_Body_Block_Statement; Add_Body_Declarative_Items; Add_Body_Exception_Handlers; Add_Body_Statements; Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Corresponding_End_Name; Add_Entry_Barrier; Add_Entry_Index_Specification; Add_Is_Name_Repeated; Add_Parameter_Profile; Add_Pragmas; when An_Entry_Index_Specification => Add_Specification_Subtype_Definition; when A_Procedure_Body_Stub => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Corresponding_Subunit; Add_Is_Dispatching_Operation; Add_Is_Not_Overriding_Declaration; Add_Is_Overriding_Declaration; Add_Parameter_Profile; when A_Function_Body_Stub => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Corresponding_Subunit; Add_Is_Dispatching_Operation; Add_Is_Not_Null_Return; Add_Is_Not_Overriding_Declaration; Add_Is_Overriding_Declaration; Add_Parameter_Profile; Add_Result_Profile; when A_Package_Body_Stub => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Corresponding_Subunit; when A_Task_Body_Stub => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Corresponding_Subunit; Add_Has_Task; when A_Protected_Body_Stub => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Corresponding_Subunit; Add_Has_Protected; when An_Exception_Declaration => null; -- No more info when A_Choice_Parameter_Specification => null; -- No more info when A_Generic_Procedure_Declaration => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Generic_Formal_Part; Add_Parameter_Profile; Add_Pragmas; when A_Generic_Function_Declaration => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Generic_Formal_Part; Add_Is_Not_Null_Return; Add_Parameter_Profile; Add_Pragmas; Add_Result_Profile; when A_Generic_Package_Declaration => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Corresponding_End_Name; Add_Generic_Formal_Part; Add_Is_Name_Repeated; Add_Is_Private_Present; Add_Pragmas; Add_Private_Part_Declarative_Items; Add_Visible_Part_Declarative_Items; when A_Package_Instantiation => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Generic_Actual_Part; Add_Generic_Unit_Name; when A_Procedure_Instantiation => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Generic_Actual_Part; Add_Generic_Unit_Name; Add_Is_Not_Overriding_Declaration; Add_Is_Overriding_Declaration; when A_Function_Instantiation => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Generic_Actual_Part; Add_Generic_Unit_Name; Add_Is_Not_Overriding_Declaration; Add_Is_Overriding_Declaration; when A_Formal_Object_Declaration => Add_Declaration_Subtype_Mark; -- Add_Has_Null_Exclusion; -- A2005 Add_Initialization_Expression; -- Add_Object_Declaration_View; -- A2005 Add_Mode_Kind; when A_Formal_Type_Declaration => Add_Discriminant_Part; Add_Type_Declaration_View; Add_Corresponding_First_Subtype; Add_Corresponding_Last_Constraint; Add_Corresponding_Last_Subtype; when A_Formal_Incomplete_Type_Declaration => -- A2012 State.Add_Not_Implemented (Ada_2012); when A_Formal_Procedure_Declaration => Add_Default_Kind; Add_Formal_Subprogram_Default; Add_Has_Abstract; Add_Parameter_Profile; when A_Formal_Function_Declaration => Add_Default_Kind; Add_Formal_Subprogram_Default; Add_Has_Abstract; Add_Parameter_Profile; Add_Result_Profile; -- Add_Is_Not_Null_Return -- A2005 when A_Formal_Package_Declaration => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Generic_Unit_Name; Add_Generic_Actual_Part; when A_Formal_Package_Declaration_With_Box => Add_Corresponding_Body; Add_Corresponding_Declaration; Add_Generic_Unit_Name; -- Add_Generic_Actual_Part; -- A2005 end case; State.A_Element.Element_Kind := a_nodes_h.A_Declaration; State.A_Element.The_Union.Declaration := Result; end Do_Pre_Child_Processing; end Asis_Adapter.Element.Declarations;
with Interfaces; use Interfaces; with Ada.Text_IO; use Ada.Text_IO; procedure main with SPARK_Mode is type Some_Record is record c1 : Unsigned_8 := 0; c2 : Unsigned_8 := 0; end record; for Some_Record use record c1 at 0 range 0 .. 7; c2 at 1 range 0 .. 7; end record; for Some_Record'Size use 16; foo : Some_Record; off_c1 : constant Integer := foo.c1'Position; off_c2 : constant Integer := foo.c2'Position; begin pragma Assert (off_c1 < 10000); pragma Assert (off_c2 = 1); Put_Line ("Pos c1=" & Integer'Image (off_c1)); -- stdout: 0 Put_Line ("Pos c2=" & Integer'Image (off_c2)); -- stdout: 1 end main;
with SDL_surface_h; use SDL_surface_h; with SDL_stdinc_h; use SDL_stdinc_h; with SDL_pixels_h; use SDL_pixels_h; with Interfaces.C; use Interfaces.C; with Ada.Text_IO; with Display.Basic.Fonts; use Display.Basic.Fonts; package body Display.Basic.GLFonts is function SDL_DEFINE_PIXELFORMAT(stype : Uint32; order : Uint32; layout : Uint32; bits: Uint32; bytes: Uint32) return Uint32 is (2 ** 28 or (stype * 2 ** 24) or (order * 2**20) or (layout * 2 ** 16) or (bits * 2 ** 8) or bytes ); SDL_PIXELFORMAT_ABGR8888 : Uint32 := SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_TYPE'Pos(SDL_PIXELTYPE_PACKED32), SDL_PACKEDORDER_TYPE'Pos(SDL_PACKEDORDER_ABGR), SDL_PACKEDLAYOUT_TYPE'Pos(SDL_PACKEDLAYOUT_8888), 32, 4); SDL_PIXELFORMAT_RGBA32 : Uint32 := SDL_PIXELFORMAT_ABGR8888; subtype Visible_Char_Idx is Character range ' ' .. '~'; type Char_Texture_Array_T is array (Visible_Char_Idx) of GLUint; Char_Texture_Ids : Char_Texture_Array_T; Is_Char_Texture_Initialized : boolean := False; procedure InitCharTextures is S : access SDL_Surface; Format : UInt32 := SDL_PIXELFORMAT_RGBA32; Texture_ID : aliased GLuint; begin for C in Visible_Char_Idx loop glGenTextures(1, Texture_ID'Access); Char_Texture_Ids(C) := Texture_ID; glBindTexture(GL_TEXTURE_2D, Texture_ID); --S := SDL_CreateRGBSurfaceWithFormat(0, 8, 8, 32, Format); S := SDL_CreateRGBSurface(0, 8, 8, 32, 16#FF#, 16#FF00#,16#FF0000#,16#FF000000#); if S = null then Ada.Text_IO.Put_Line ("Cant create surface"); else Draw_Char(S, Screen_Point'(0, 0), C, Font8x8, SDL_MapRGBA(S.format, 255, 255, 255, 255), SDL_MapRGBA(S.format, 0, 0, 0, 0)); glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, S.pixels); if glGetError /= GL_NO_ERROR then Ada.Text_IO.Put_Line ("Error in texture"); end if; SDL_FreeSurface (S); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); end if; end loop; Is_Char_Texture_Initialized := true; end InitCharTextures; function getCharTexture(Char : Character) return GLUint is begin if not Is_Char_Texture_Initialized then InitCharTextures; end if; return Char_Texture_Ids(Char); end getCharTexture; end Display.Basic.GLFonts;
with Ada.Text_IO; use Ada.Text_IO; procedure Test_LCS is function LCS (A, B : String) return String is begin if A'Length = 0 or else B'Length = 0 then return ""; elsif A (A'Last) = B (B'Last) then return LCS (A (A'First..A'Last - 1), B (B'First..B'Last - 1)) & A (A'Last); else declare X : String renames LCS (A, B (B'First..B'Last - 1)); Y : String renames LCS (A (A'First..A'Last - 1), B); begin if X'Length > Y'Length then return X; else return Y; end if; end; end if; end LCS; begin Put_Line (LCS ("thisisatest", "testing123testing")); end Test_LCS;
with C.unistd; package body System.Multiprocessors is use type C.signed_long; function Number_Of_CPUs return CPU is Result : C.signed_long; begin Result := C.unistd.sysconf (C.unistd.SC_NPROCESSORS_ONLN); if Result < 0 then raise Program_Error; end if; return CPU (Result); end Number_Of_CPUs; end System.Multiprocessors;
with ZMQ.Messages; with UxAS.Common.Configuration_Manager; package body UxAS.Comms.Transport.Receiver.ZeroMQ.Addr_Attr_Msg_Receivers is ---------------- -- Initialize -- ---------------- overriding procedure Initialize (This : in out ZeroMq_Addressed_Attributed_Message_Receiver; Entity_Id : UInt32; Service_Id : UInt32; Socket_Configuration : ZeroMq_Socket_Configuration) is begin Initialize (ZeroMq_Receiver_Base (This), -- call parent version Entity_Id => Entity_Id, Service_Id => Service_Id, Socket_Configuration => Socket_Configuration); This.Is_TCP_Stream := Socket_Configuration.Zmq_Socket_Type = STREAM; end Initialize; use Message_Lists; function String_From_Socket (S : ZMQ.Sockets.Socket) return String; -- NOTE: s_recv() etc are defined in OpenUxAS\src\Utilities\UxAS_ZeroMQ.h -- as simple wrappers that hide result type conversions etc. ---------------------- -- Get_Next_Message -- ---------------------- procedure Get_Next_Message (This : in out ZeroMq_Addressed_Attributed_Message_Receiver; Msg : out Addressed_Attributed_Message_Ref) is -- std::unique_ptr<uxas::communications::data::AddressedAttributedMessage> nextMsg; begin -- just send the next message if one is available if not Is_Empty (This.Received_Messages) then Msg := First_Element (This.Received_Messages); Delete_First (This.Received_Messages); return; end if; -- No messages in queue, attempt to read from socket. -- Polling is not supported in the current Ada binding to ZMQ (as of Feb -- 2019), although we could do it with the low-level binding. Therefore -- we will use a blocking call (in function String_From_Socket). We -- don't need all the code below for our demo, since the demo doesn't -- use TcpStreams and the messages are not multipart. -- zmq::pollitem_t pollItems [] = { -- { *m_zmqSocket, 0, ZMQ_POLLIN, 0}, -- }; -- -- zmq::poll(&pollItems[0], 1, uxas::common::ConfigurationManager::getZeroMqReceiveSocketPollWaitTime_ms()); // wait time units are milliseconds -- -- if (pollItems[0].revents & ZMQ_POLLIN) // polling detected received data -- { if This.Is_TCP_Stream then raise Program_Error with "Get_Next_Message is not implemented for STREAM"; else -- not a stream socket if UxAS.Common.Configuration_Manager.Is_ZeroMq_Multipart_Message then raise Program_Error with "Get_Next_Message is not implemented for multipart messages"; else -- not a multipart message declare Recvd_Msg : Addressed_Attributed_Message_Ref; Success : Boolean; begin -- std::unique_ptr<uxas::communications::data::AddressedAttributedMessage> recvdSinglepartAddAttMsg -- = uxas::stduxas::make_unique<uxas::communications::data::AddressedAttributedMessage>(); Recvd_Msg := new Addressed_Attributed_Message; -- if (recvdSinglepartAddAttMsg->setAddressAttributesAndPayloadFromDelimitedString(n_ZMQ::s_recv(*m_zmqSocket))) Recvd_Msg.Set_Address_Attributes_And_Payload_From_Delimited_String (Delimited_String => String_From_Socket (This.Zmq_Socket), Result => Success); if Success then -- if (m_entityIdString != recvdSinglepartAddAttMsg->getMessageAttributesReference()->getSourceEntityId() -- || m_serviceIdString != recvdSinglepartAddAttMsg->getMessageAttributesReference()->getSourceServiceId()) if This.Entity_Id_String /= Recvd_Msg.Message_Attributes_Reference.Source_Entity_Id or This.Service_Id_String /= Recvd_Msg.Message_Attributes_Reference.Source_Service_Id then -- m_recvdMsgs.push_back( std::move(recvdSinglepartAddAttMsg) ); Append (This.Received_Messages, Recvd_Msg); end if; end if; end; end if; -- is a multipart message end if; -- is a stream socket -- now see if there was anything just put into the deque if not Is_Empty (This.Received_Messages) then Msg := First_Element (This.Received_Messages); Delete_First (This.Received_Messages); end if; end Get_Next_Message; ------------------------ -- String_From_Socket -- ------------------------ function String_From_Socket (S : ZMQ.Sockets.Socket) return String is Message : ZMQ.Messages.Message; begin Message.Initialize (Size => 0); S.Recv (Message); -- blocking return Message.GetData; end String_From_Socket; end UxAS.Comms.Transport.Receiver.ZeroMQ.Addr_Attr_Msg_Receivers;
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- with Ada.Unchecked_Deallocation; package body Program.Dummy_Subpools is type Dummy_Subpool_Access is access all Dummy_Subpool; procedure Free is new Ada.Unchecked_Deallocation (Dummy_Subpool, Dummy_Subpool_Access); --------------------------- -- Allocate_From_Subpool -- --------------------------- overriding procedure Allocate_From_Subpool (Self : in out Dummy_Storage_Pool; Address : out System.Address; Size : System.Storage_Elements.Storage_Count; Alignment : System.Storage_Elements.Storage_Count; Subpool : not null System.Storage_Pools.Subpools.Subpool_Handle) is pragma Unreferenced (Self, Subpool); Default : System.Storage_Pools.Root_Storage_Pool'Class renames Dummy_Subpool_Access'Storage_Pool; begin Default.Allocate (Storage_Address => Address, Size_In_Storage_Elements => Size, Alignment => Alignment); end Allocate_From_Subpool; -------------------- -- Create_Subpool -- -------------------- overriding function Create_Subpool (Self : in out Dummy_Storage_Pool) return not null System.Storage_Pools.Subpools.Subpool_Handle is Dummy : constant Dummy_Subpool_Access := new Dummy_Subpool; begin return Result : constant not null System.Storage_Pools.Subpools.Subpool_Handle := System.Storage_Pools.Subpools.Subpool_Handle (Dummy) do System.Storage_Pools.Subpools.Set_Pool_Of_Subpool (Result, Self); Self.Last_Subpool := Result; end return; end Create_Subpool; ------------------------ -- Deallocate_Subpool -- ------------------------ overriding procedure Deallocate_Subpool (Self : in out Dummy_Storage_Pool; Subpool : in out System.Storage_Pools.Subpools.Subpool_Handle) is Dummy : Dummy_Subpool_Access := Dummy_Subpool_Access (Subpool); begin Free (Dummy); Self.Last_Subpool := null; end Deallocate_Subpool; ------------------------------ -- Default_Subpool_For_Pool -- ------------------------------ overriding function Default_Subpool_For_Pool (Self : in out Dummy_Storage_Pool) return not null System.Storage_Pools.Subpools.Subpool_Handle is begin return Self.Last_Subpool; end Default_Subpool_For_Pool; end Program.Dummy_Subpools;
with System; package gnatcoll.Dl is pragma Preelaborate; type Dynamic_Library is tagged private; type Flag is mod 2**32; pragma warnings(off, """Or"" is being renamed as a different operator"); function "+" (L , R :Flag) return Flag renames "or"; pragma warnings(on, """Or"" is being renamed as a different operator"); RTLD_LAZY : constant Flag; -- Perform lazy binding. -- Only resolve symbols as the code that references them is executed. -- If the symbol is never referenced, then it is never resolved. -- (Lazy binding is only performed for function references; -- references to variables are always immediately bound when the -- library is loaded.) RTLD_NOW : constant Flag; -- If this value is specified, or the environment variable LD_BIND_NOW -- is set to a non-empty string, all undefined symbols in the library are -- Resolved Before Dlopen () Returns. if This Cannot Be Done, An Error -- is Returned. -- Zero of more of the following values may also be ORed in flag: RTLD_GLOBAL : constant Flag; -- The symbols defined by this library will be made available for -- symbol resolution of subsequently loaded libraries. RTLD_LOCAL : constant Flag; -- This is the converse of RTLD_GLOBAL, and the default if neither flag -- is Specified. Symbols Defined in This Library Are not Made Available -- To Resolve References in Subsequently Loaded Libraries. RTLD_NODELETE : constant Flag; -- Do not unload the library during dlclose(). Consequently, -- the library's static variables are not reinitialised if the library is -- reloaded with dlopen() at a later time. RTLD_NOLOAD : constant Flag; -- Don't load the library. This can be used to test if the library -- is already resident (dlopen() returns NULL if it is not, -- or the library's handle if it is resident). -- This flag can also be used to promote the flags on a library that -- is already loaded. For example, a library that was previously loaded -- with RTLD_LOCAL can be re-opened with RTLD_NOLOAD | RTLD_GLOBAL. RTLD_DEEPBIND : constant Flag; -- Place the lookup scope of the symbols in this library ahead of the global -- scope. This means that a self-contained library will use its own symbols -- in preference to global symbols with the same name contained in libraries -- that have already been loaded. procedure Open (This : in out Dynamic_Library; File_Name : String; Flags : Flag := RTLD_LAZY); function Open (File_Name : String; Flags : Flag := RTLD_LAZY) return Dynamic_Library; procedure Close (This : Dynamic_Library); function Sym (This : Dynamic_Library; Symbol_Name : String) return System.Address; Dynamic_Library_Error : exception; private type Dynamic_Library is tagged record Handle : System.Address := System.Null_Address; end record; function Error return String; -- dlfcn.h:83:14 RTLD_LAZY : constant Flag := 2#0000_0000_0000_0001#; RTLD_NOW : constant Flag := 2#0000_0000_0000_0010#; RTLD_GLOBAL : constant Flag := 2#0000_0001_0000_0000#; RTLD_LOCAL : constant Flag := 2#0000_0000_0000_0000#; RTLD_NODELETE : constant Flag := 2#0001_0000_0000_0000#; RTLD_NOLOAD : constant Flag := 2#0000_0000_0000_0100#; RTLD_DEEPBIND : constant Flag := 2#0000_0000_0000_1000#; end gnatcoll.Dl;
with Units.Numerics; use Units.Numerics; pragma Elaborate_All(Units); package body Units.Vectors with SPARK_Mode is function Sat_Add is new Saturated_Addition (Base_Unit_Type); function Sat_Sub is new Saturated_Subtraction (Base_Unit_Type); function Unit_Square (val : Base_Unit_Type) return Base_Unit_Type is begin if Sqrt (Base_Unit_Type'Last) <= abs (val) then return Base_Unit_Type'Last; else return val*val; -- TODO: fails (Sqrt is not modeled precisely) end if; end Unit_Square; procedure rotate (vector : in out Cartesian_Vector_Type; axis : Cartesian_Coordinates_Type; angle : Angle_Type) is result : Cartesian_Vector_Type := vector; co : constant Base_Unit_Type := Cos (angle); si : constant Base_Unit_Type := Sin (angle); pragma Assert (co in -1.0 .. 1.0); pragma Assert (si in -1.0 .. 1.0); begin case (axis) is when X => result (Y) := Sat_Sub (co * vector(Y), si * vector(Z)); result (Z) := Sat_Add (si * vector(Y), co * vector(Z)); when Y => result (X) := Sat_Add (si * vector(Z), co * vector(X)); result (Z) := Sat_Sub (co * vector(Z), si * vector(X)); when Z => result (X) := Sat_Sub (co * vector(X), si * vector(Y)); result (Y) := Sat_Add (si * vector(X), co * vector(Y)); end case; vector := result; end rotate; function "abs" (vector : Cartesian_Vector_Type) return Base_Unit_Type is xx : constant Base_Unit_Type := Unit_Square (vector(X)); yy : constant Base_Unit_Type := Unit_Square (vector(Y)); zz : constant Base_Unit_Type := Unit_Square (vector(Z)); len : constant Base_Unit_Type := Sat_Add (Sat_Add (xx, yy), zz); pragma Assert (len >= 0.0); -- TODO: fails. need lemma? begin return Sqrt (len); end "abs"; function "abs" (vector : Angular_Vector) return Base_Unit_Type is xx : constant Base_Unit_Type := Unit_Square (vector(X)); yy : constant Base_Unit_Type := Unit_Square (vector(Y)); zz : constant Base_Unit_Type := Unit_Square (vector(Z)); len : constant Base_Unit_Type := Sat_Add (Sat_Add (xx, yy), zz); pragma Assert (len >= 0.0); -- TODO: fails. need lemma? begin return Sqrt (len); end "abs"; function "abs" (vector : Linear_Acceleration_Vector) return Linear_Acceleration_Type is xx : constant Base_Unit_Type := Unit_Square (Base_Unit_Type (vector(X))); yy : constant Base_Unit_Type := Unit_Square (Base_Unit_Type (vector(Y))); zz : constant Base_Unit_Type := Unit_Square (Base_Unit_Type (vector(Z))); len : constant Base_Unit_Type := Sat_Add (Sat_Add (xx, yy), zz); pragma Assert (len >= 0.0); -- TODO: fails. need lemma? begin return Linear_Acceleration_Type (Sqrt (len)); end "abs"; function Eye( n : Natural ) return Unit_Matrix is result : Unit_Matrix(1 .. n, 1 .. n) := (others => (others => 0.0)); begin for i in result'Range loop result(i,i) := 1.0; end loop; return result; end Eye; function Ones( n : Natural ) return Unit_Matrix is result : constant Unit_Matrix(1 .. n, 1 .. n) := (others => (others => 1.0)); begin return result; end Ones; function Zeros( n : Natural ) return Unit_Matrix is result : constant Unit_Matrix(1 .. n, 1 .. n) := (others => (others => 0.0)); begin return result; end Zeros; procedure setOnes( A : in out Unit_Matrix; first : Natural; last : Natural) is null; end Units.Vectors;
with Ada.Text_IO; with Ada.Integer_Text_IO; with Ada.Float_Text_IO; use Ada; with Geometry; procedure geometry_test is procedure put_float(number : Float) is begin Float_Text_IO.put(Item => number, Aft => 3, Exp => 0); end put_float; cup : Geometry.Cylinder; cup_volume : Float; begin -- calculate volume of coffee mug cup.radius := (3.25/2.0); -- 3.25 inches diameter cup.height := (5.0); -- 5 inches tall cup_volume := Geometry.volume (cup); put_float(cup_volume); end geometry_test;
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Ada.Strings.Wide_Wide_Hash; with Ada.Wide_Wide_Characters.Handling; package body Program.Symbols.Tables is ----------- -- Equal -- ----------- function Equal (Left, Right : Symbol_Reference) return S.Boolean is Left_Text : constant Program.Text := Left.Buffer.Text (Left.Span); Right_Text : constant Program.Text := Right.Buffer.Text (Right.Span); begin if Left_Text (Left_Text'First) = ''' then return Left_Text = Right_Text; else return Ada.Wide_Wide_Characters.Handling.To_Lower (Left_Text) = Ada.Wide_Wide_Characters.Handling.To_Lower (Right_Text); end if; end Equal; package Dummy_Source_Buffers is type Dummy_Source_Buffer (Value : access constant Program.Text) is new Program.Source_Buffers.Source_Buffer with null record; overriding function Text (Self : Dummy_Source_Buffer; Unused : Program.Source_Buffers.Span) return Program.Text is (Self.Value.all); overriding procedure Read (Self : in out Dummy_Source_Buffer; Data : out Program.Source_Buffers.Character_Info_Array; Last : out Natural) is null; overriding procedure Rewind (Self : in out Dummy_Source_Buffer) is null; end Dummy_Source_Buffers; ---------- -- Find -- ---------- function Find (Self : Symbol_Table'Class; Value : Program.Text) return Symbol is Text : aliased Program.Text := Value; Dummy : aliased Dummy_Source_Buffers.Dummy_Source_Buffer (Text'Access); Ref : constant Symbol_Reference := (Dummy'Unchecked_Access, (1, 0)); Cursor : constant Symbol_Maps.Cursor := Self.Map.Find (Ref); begin if Symbol_Maps.Has_Element (Cursor) then return Symbol_Maps.Element (Cursor); elsif Value (Value'First) = ''' and Value (Value'Last) = ''' and Value'Length = 3 then -- Character literal return S.Wide_Wide_Character'Pos (Value (Value'First + 1)); else return Program.Symbols.No_Symbol; end if; end Find; -------------------- -- Find_Or_Create -- -------------------- procedure Find_Or_Create (Self : in out Symbol_Table'Class; Buffer : not null Program.Source_Buffers.Source_Buffer_Access; Span : Program.Source_Buffers.Span; Result : out Symbol) is Ref : constant Symbol_Reference := (Buffer, Span); Cursor : constant Symbol_Maps.Cursor := Self.Map.Find (Ref); begin if Symbol_Maps.Has_Element (Cursor) then Result := Symbol_Maps.Element (Cursor); return; end if; declare Value : constant Program.Text := Buffer.Text (Span); begin if Value (Value'First) = ''' and Value (Value'Last) = ''' and Value'Length = 3 then -- Character literal Result := S.Wide_Wide_Character'Pos (Value (Value'First + 1)); return; elsif Value (Value'First) in '"' then Result := No_Symbol; return; end if; end; Self.Last_Symbol := Self.Last_Symbol + 1; Result := Self.Last_Symbol; Self.Map.Insert (Ref, Result); end Find_Or_Create; ---------- -- Hash -- ---------- function Hash (Value : Symbol_Reference) return Ada.Containers.Hash_Type is Value_Text : constant Program.Text := Value.Buffer.Text (Value.Span); begin if Value_Text (Value_Text'First) = ''' then return Ada.Strings.Wide_Wide_Hash (Value_Text); else return Ada.Strings.Wide_Wide_Hash (Ada.Wide_Wide_Characters.Handling.To_Lower (Value_Text)); end if; end Hash; ---------------- -- Initialize -- ---------------- procedure Initialize (Self : in out Symbol_Table) is B : constant Program.Source_Buffers.Source_Buffer_Access := Self.Buffer'Unchecked_Access; begin Self.Map.Insert ((B, (1, 0)), Less_Symbol); Self.Map.Insert ((B, (2, 0)), Equal_Symbol); Self.Map.Insert ((B, (3, 0)), Greater_Symbol); Self.Map.Insert ((B, (4, 0)), Hyphen_Symbol); Self.Map.Insert ((B, (5, 0)), Slash_Symbol); Self.Map.Insert ((B, (6, 0)), Star_Symbol); Self.Map.Insert ((B, (7, 0)), Ampersand_Symbol); Self.Map.Insert ((B, (8, 0)), Plus_Symbol); Self.Map.Insert ((B, (9, 0)), Less_Or_Equal_Symbol); Self.Map.Insert ((B, (10, 0)), Greater_Or_Equal_Symbol); Self.Map.Insert ((B, (11, 0)), Inequality_Symbol); Self.Map.Insert ((B, (12, 0)), Double_Star_Symbol); Self.Map.Insert ((B, (13, 0)), Or_Symbol); Self.Map.Insert ((B, (14, 0)), And_Symbol); Self.Map.Insert ((B, (15, 0)), Xor_Symbol); Self.Map.Insert ((B, (16, 0)), Mod_Symbol); Self.Map.Insert ((B, (17, 0)), Rem_Symbol); Self.Map.Insert ((B, (18, 0)), Abs_Symbol); Self.Map.Insert ((B, (19, 0)), Not_Symbol); Self.Map.Insert ((B, (20, 0)), All_Calls_Remote); Self.Map.Insert ((B, (21, 0)), Assert); Self.Map.Insert ((B, (22, 0)), Assertion_Policy); Self.Map.Insert ((B, (23, 0)), Asynchronous); Self.Map.Insert ((B, (24, 0)), Atomic); Self.Map.Insert ((B, (25, 0)), Atomic_Components); Self.Map.Insert ((B, (26, 0)), Attach_Handler); Self.Map.Insert ((B, (27, 0)), Controlled); Self.Map.Insert ((B, (28, 0)), Convention); Self.Map.Insert ((B, (29, 0)), Detect_Blocking); Self.Map.Insert ((B, (30, 0)), Discard_Names); Self.Map.Insert ((B, (31, 0)), Elaborate); Self.Map.Insert ((B, (32, 0)), Elaborate_All); Self.Map.Insert ((B, (33, 0)), Elaborate_Body); Self.Map.Insert ((B, (34, 0)), Export); Self.Map.Insert ((B, (35, 0)), Import); Self.Map.Insert ((B, (36, 0)), Inline); Self.Map.Insert ((B, (37, 0)), Inspection_Point); Self.Map.Insert ((B, (38, 0)), Interrupt_Handler); Self.Map.Insert ((B, (39, 0)), Interrupt_Priority); Self.Map.Insert ((B, (40, 0)), Linker_Options); Self.Map.Insert ((B, (41, 0)), List); Self.Map.Insert ((B, (42, 0)), Locking_Policy); Self.Map.Insert ((B, (43, 0)), No_Return); Self.Map.Insert ((B, (44, 0)), Normalize_Scalars); Self.Map.Insert ((B, (45, 0)), Optimize); Self.Map.Insert ((B, (46, 0)), Pack); Self.Map.Insert ((B, (47, 0)), Page); Self.Map.Insert ((B, (48, 0)), Partition_Elaboration_Policy); Self.Map.Insert ((B, (49, 0)), Preelaborable_Initialization); Self.Map.Insert ((B, (50, 0)), Preelaborate); Self.Map.Insert ((B, (51, 0)), Priority_Specific_Dispatching); Self.Map.Insert ((B, (52, 0)), Profile); Self.Map.Insert ((B, (53, 0)), Pure); Self.Map.Insert ((B, (54, 0)), Queuing_Policy); Self.Map.Insert ((B, (55, 0)), Relative_Deadline); Self.Map.Insert ((B, (56, 0)), Remote_Call_Interface); Self.Map.Insert ((B, (57, 0)), Remote_Types); Self.Map.Insert ((B, (58, 0)), Restrictions); Self.Map.Insert ((B, (59, 0)), Reviewable); Self.Map.Insert ((B, (60, 0)), Shared_Passive); Self.Map.Insert ((B, (61, 0)), Suppress); Self.Map.Insert ((B, (62, 0)), Task_Dispatching_Policy); Self.Map.Insert ((B, (63, 0)), Unchecked_Union); Self.Map.Insert ((B, (64, 0)), Unsuppress); Self.Map.Insert ((B, (65, 0)), Volatile); Self.Map.Insert ((B, (66, 0)), Volatile_Components); -- Attributes: Self.Map.Insert ((B, (67, 0)), Access_Symbol); Self.Map.Insert ((B, (68, 0)), Address); Self.Map.Insert ((B, (69, 0)), Adjacent); Self.Map.Insert ((B, (70, 0)), Aft); Self.Map.Insert ((B, (71, 0)), Alignment); Self.Map.Insert ((B, (72, 0)), Base); Self.Map.Insert ((B, (73, 0)), Bit_Order); Self.Map.Insert ((B, (74, 0)), Body_Version); Self.Map.Insert ((B, (75, 0)), Callable); Self.Map.Insert ((B, (76, 0)), Caller); Self.Map.Insert ((B, (77, 0)), Ceiling); Self.Map.Insert ((B, (78, 0)), Class); Self.Map.Insert ((B, (79, 0)), Component_Size); Self.Map.Insert ((B, (80, 0)), Compose); Self.Map.Insert ((B, (81, 0)), Constrained); Self.Map.Insert ((B, (82, 0)), Copy_Sign); Self.Map.Insert ((B, (83, 0)), Count); Self.Map.Insert ((B, (84, 0)), Definite); Self.Map.Insert ((B, (85, 0)), Delta_Symbol); Self.Map.Insert ((B, (86, 0)), Denorm); Self.Map.Insert ((B, (87, 0)), Digits_Symbol); Self.Map.Insert ((B, (88, 0)), Exponent); Self.Map.Insert ((B, (89, 0)), External_Tag); Self.Map.Insert ((B, (90, 0)), First); Self.Map.Insert ((B, (91, 0)), First_Bit); Self.Map.Insert ((B, (92, 0)), Floor); Self.Map.Insert ((B, (93, 0)), Fore); Self.Map.Insert ((B, (94, 0)), Fraction); Self.Map.Insert ((B, (95, 0)), Identity); Self.Map.Insert ((B, (96, 0)), Image); Self.Map.Insert ((B, (97, 0)), Input); Self.Map.Insert ((B, (98, 0)), Last); Self.Map.Insert ((B, (99, 0)), Last_Bit); Self.Map.Insert ((B, (100, 0)), Leading_Part); Self.Map.Insert ((B, (101, 0)), Length); Self.Map.Insert ((B, (102, 0)), Machine); Self.Map.Insert ((B, (103, 0)), Machine_Emax); Self.Map.Insert ((B, (104, 0)), Machine_Emin); Self.Map.Insert ((B, (105, 0)), Machine_Mantissa); Self.Map.Insert ((B, (106, 0)), Machine_Overflows); Self.Map.Insert ((B, (107, 0)), Machine_Radix); Self.Map.Insert ((B, (108, 0)), Machine_Rounding); Self.Map.Insert ((B, (109, 0)), Machine_Rounds); Self.Map.Insert ((B, (110, 0)), Max); Self.Map.Insert ((B, (111, 0)), Max_Size_In_Storage_Elements); Self.Map.Insert ((B, (112, 0)), Min); Self.Map.Insert ((B, (113, 0)), Mod_Keyword); Self.Map.Insert ((B, (114, 0)), Model); Self.Map.Insert ((B, (115, 0)), Model_Emin); Self.Map.Insert ((B, (116, 0)), Model_Epsilon); Self.Map.Insert ((B, (117, 0)), Model_Mantissa); Self.Map.Insert ((B, (118, 0)), Model_Small); Self.Map.Insert ((B, (119, 0)), Modulus); Self.Map.Insert ((B, (120, 0)), Output); Self.Map.Insert ((B, (121, 0)), Partition_ID); Self.Map.Insert ((B, (122, 0)), Pos); Self.Map.Insert ((B, (123, 0)), Position); Self.Map.Insert ((B, (124, 0)), Pred); Self.Map.Insert ((B, (125, 0)), Priority); Self.Map.Insert ((B, (126, 0)), Range_Keyword); Self.Map.Insert ((B, (127, 0)), Read); Self.Map.Insert ((B, (128, 0)), Remainder); Self.Map.Insert ((B, (129, 0)), Round); Self.Map.Insert ((B, (130, 0)), Rounding); Self.Map.Insert ((B, (131, 0)), Safe_First); Self.Map.Insert ((B, (132, 0)), Safe_Last); Self.Map.Insert ((B, (133, 0)), Scale); Self.Map.Insert ((B, (134, 0)), Scaling); Self.Map.Insert ((B, (135, 0)), Signed_Zeros); Self.Map.Insert ((B, (136, 0)), Size); Self.Map.Insert ((B, (137, 0)), Small); Self.Map.Insert ((B, (138, 0)), Storage_Pool); Self.Map.Insert ((B, (139, 0)), Storage_Size); Self.Map.Insert ((B, (140, 0)), Stream_Size); Self.Map.Insert ((B, (141, 0)), Succ); Self.Map.Insert ((B, (142, 0)), Tag); Self.Map.Insert ((B, (143, 0)), Terminated); Self.Map.Insert ((B, (144, 0)), Truncation); Self.Map.Insert ((B, (145, 0)), Unbiased_Rounding); Self.Map.Insert ((B, (146, 0)), Unchecked_Access); Self.Map.Insert ((B, (147, 0)), Val); Self.Map.Insert ((B, (148, 0)), Valid); Self.Map.Insert ((B, (149, 0)), Value); Self.Map.Insert ((B, (150, 0)), Version); Self.Map.Insert ((B, (151, 0)), Wide_Image); Self.Map.Insert ((B, (152, 0)), Wide_Value); Self.Map.Insert ((B, (153, 0)), Wide_Wide_Image); Self.Map.Insert ((B, (154, 0)), Wide_Wide_Value); Self.Map.Insert ((B, (155, 0)), Wide_Wide_Width); Self.Map.Insert ((B, (156, 0)), Wide_Width); Self.Map.Insert ((B, (157, 0)), Width); Self.Map.Insert ((B, (158, 0)), Write); -- Other names: Self.Map.Insert ((B, (159, 0)), Standard); Self.Map.Insert ((B, (160, 0)), Boolean); Self.Map.Insert ((B, (161, 0)), Integer); Self.Map.Insert ((B, (162, 0)), Float); Self.Map.Insert ((B, (163, 0)), Character); Self.Map.Insert ((B, (164, 0)), Wide_Character); Self.Map.Insert ((B, (165, 0)), Wide_Wide_Character); Self.Map.Insert ((B, (166, 0)), String); Self.Map.Insert ((B, (167, 0)), Wide_String); Self.Map.Insert ((B, (168, 0)), Wide_Wide_String); Self.Map.Insert ((B, (169, 0)), Duration); Self.Map.Insert ((B, (170, 0)), Root_Integer); Self.Map.Insert ((B, (171, 0)), Root_Real); end Initialize; ---------- -- Text -- ---------- overriding function Text (Self : Predefined_Source_Buffer; Span : Program.Source_Buffers.Span) return Program.Text is pragma Unreferenced (Self); begin case Symbol (Span.From) is when 1 => return """<"""; when 2 => return """="""; when 3 => return """>"""; when 4 => return """-"""; when 5 => return """/"""; when 6 => return """*"""; when 7 => return """&"""; when 8 => return """+"""; when 9 => return """<="""; when 10 => return """>="""; when 11 => return """/="""; when 12 => return """**"""; when 13 => return """or"""; when 14 => return """and"""; when 15 => return """xor"""; when 16 => return """mod"""; when 17 => return """rem"""; when 18 => return """abd"""; when 19 => return """not"""; when 20 => return "All_Calls_Remote"; when 21 => return "Assert"; when 22 => return "Assertion_Policy"; when 23 => return "Asynchronous"; when 24 => return "Atomic"; when 25 => return "Atomic_Components"; when 26 => return "Attach_Handler"; when 27 => return "Controlled"; when 28 => return "Convention"; when 29 => return "Detect_Blocking"; when 30 => return "Discard_Names"; when 31 => return "Elaborate"; when 32 => return "Elaborate_All"; when 33 => return "Elaborate_Body"; when 34 => return "Export"; when 35 => return "Import"; when 36 => return "Inline"; when 37 => return "Inspection_Point"; when 38 => return "Interrupt_Handler"; when 39 => return "Interrupt_Priority"; when 40 => return "Linker_Options"; when 41 => return "List"; when 42 => return "Locking_Policy"; when 43 => return "No_Return"; when 44 => return "Normalize_Scalars"; when 45 => return "Optimize"; when 46 => return "Pack"; when 47 => return "Page"; when 48 => return "Partition_Elaboration_Policy"; when 49 => return "Preelaborable_Initialization"; when 50 => return "Preelaborate"; when 51 => return "Priority_Specific_Dispatching"; when 52 => return "Profile"; when 53 => return "Pure"; when 54 => return "Queuing_Policy"; when 55 => return "Relative_Deadline"; when 56 => return "Remote_Call_Interface"; when 57 => return "Remote_Types"; when 58 => return "Restrictions"; when 59 => return "Reviewable"; when 60 => return "Shared_Passive"; when 61 => return "Suppress"; when 62 => return "Task_Dispatching_Policy"; when 63 => return "Unchecked_Union"; when 64 => return "Unsuppress"; when 65 => return "Volatile"; when 66 => return "Volatile_Components"; when 67 => return "Access_Symbol"; when 68 => return "Address"; when 69 => return "Adjacent"; when 70 => return "Aft"; when 71 => return "Alignment"; when 72 => return "Base"; when 73 => return "Bit_Order"; when 74 => return "Body_Version"; when 75 => return "Callable"; when 76 => return "Caller"; when 77 => return "Ceiling"; when 78 => return "Class"; when 79 => return "Component_Size"; when 80 => return "Compose"; when 81 => return "Constrained"; when 82 => return "Copy_Sign"; when 83 => return "Count"; when 84 => return "Definite"; when 85 => return "Delta_Symbol"; when 86 => return "Denorm"; when 87 => return "Digits_Symbol"; when 88 => return "Exponent"; when 89 => return "External_Tag"; when 90 => return "First"; when 91 => return "First_Bit"; when 92 => return "Floor"; when 93 => return "Fore"; when 94 => return "Fraction"; when 95 => return "Identity"; when 96 => return "Image"; when 97 => return "Input"; when 98 => return "Last"; when 99 => return "Last_Bit"; when 100 => return "Leading_Part"; when 101 => return "Length"; when 102 => return "Machine"; when 103 => return "Machine_Emax"; when 104 => return "Machine_Emin"; when 105 => return "Machine_Mantissa"; when 106 => return "Machine_Overflows"; when 107 => return "Machine_Radix"; when 108 => return "Machine_Rounding"; when 109 => return "Machine_Rounds"; when 110 => return "Max"; when 111 => return "Max_Size_In_Storage_Elements"; when 112 => return "Min"; when 113 => return "Mod"; when 114 => return "Model"; when 115 => return "Model_Emin"; when 116 => return "Model_Epsilon"; when 117 => return "Model_Mantissa"; when 118 => return "Model_Small"; when 119 => return "Modulus"; when 120 => return "Output"; when 121 => return "Partition_ID"; when 122 => return "Pos"; when 123 => return "Position"; when 124 => return "Pred"; when 125 => return "Priority"; when 126 => return "Range"; when 127 => return "Read"; when 128 => return "Remainder"; when 129 => return "Round"; when 130 => return "Rounding"; when 131 => return "Safe_First"; when 132 => return "Safe_Last"; when 133 => return "Scale"; when 134 => return "Scaling"; when 135 => return "Signed_Zeros"; when 136 => return "Size"; when 137 => return "Small"; when 138 => return "Storage_Pool"; when 139 => return "Storage_Size"; when 140 => return "Stream_Size"; when 141 => return "Succ"; when 142 => return "Tag"; when 143 => return "Terminated"; when 144 => return "Truncation"; when 145 => return "Unbiased_Rounding"; when 146 => return "Unchecked_Access"; when 147 => return "Val"; when 148 => return "Valid"; when 149 => return "Value"; when 150 => return "Version"; when 151 => return "Wide_Image"; when 152 => return "Wide_Value"; when 153 => return "Wide_Wide_Image"; when 154 => return "Wide_Wide_Value"; when 155 => return "Wide_Wide_Width"; when 156 => return "Wide_Width"; when 157 => return "Width"; when 158 => return "Write"; when 159 => return "Standard"; when 160 => return "Boolean"; when 161 => return "Integer"; when 162 => return "Float"; when 163 => return "Character"; when 164 => return "Wide_Character"; when 165 => return "Wide_Wide_Character"; when 166 => return "String"; when 167 => return "Wide_String"; when 168 => return "Wide_Wide_String"; when 169 => return "Duration"; when 170 => return "Root_Integer"; when 171 => return "Root_Real"; when others => raise Constraint_Error; end case; end Text; end Program.Symbols.Tables;
package body agar.gui.widget.numerical is use type c.int; package cbinds is function allocate (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr) return numerical_access_t; pragma import (c, allocate, "AG_NumericalNew"); function allocate_float (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : float_access_t) return numerical_access_t; pragma import (c, allocate_float, "AG_NumericalNewFlt"); function allocate_float_ranged (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : float_access_t; min : float_t; max : float_t) return numerical_access_t; pragma import (c, allocate_float_ranged, "AG_NumericalNewFltR"); function allocate_double (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : double_access_t) return numerical_access_t; pragma import (c, allocate_double, "AG_NumericalNewDbl"); function allocate_double_ranged (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : double_access_t; min : double_t; max : double_t) return numerical_access_t; pragma import (c, allocate_double_ranged, "AG_NumericalNewDblR"); function allocate_integer (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : integer_access_t) return numerical_access_t; pragma import (c, allocate_integer, "AG_NumericalNewInt"); function allocate_integer_ranged (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : integer_access_t; min : integer_t; max : integer_t) return numerical_access_t; pragma import (c, allocate_integer_ranged, "AG_NumericalNewIntR"); function allocate_unsigned (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : unsigned_access_t) return numerical_access_t; pragma import (c, allocate_unsigned, "AG_NumericalNewUint"); function allocate_unsigned_ranged (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : unsigned_access_t; min : unsigned_t; max : unsigned_t) return numerical_access_t; pragma import (c, allocate_unsigned_ranged, "AG_NumericalNewUintR"); function allocate_uint8 (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : agar.core.types.uint8_ptr_t) return numerical_access_t; pragma import (c, allocate_uint8, "AG_NumericalNewUint8"); function allocate_uint16 (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : agar.core.types.uint16_ptr_t) return numerical_access_t; pragma import (c, allocate_uint16, "AG_NumericalNewUint16"); function allocate_uint32 (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : agar.core.types.uint32_ptr_t) return numerical_access_t; pragma import (c, allocate_uint32, "AG_NumericalNewUint32"); function allocate_int8 (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : agar.core.types.int8_ptr_t) return numerical_access_t; pragma import (c, allocate_int8, "AG_NumericalNewSint8"); function allocate_int16 (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : agar.core.types.int16_ptr_t) return numerical_access_t; pragma import (c, allocate_int16, "AG_NumericalNewSint16"); function allocate_int32 (parent : widget_access_t; flags : flags_t; unit : cs.chars_ptr; label : cs.chars_ptr; value : agar.core.types.int32_ptr_t) return numerical_access_t; pragma import (c, allocate_int32, "AG_NumericalNewSint32"); function set_unit_system (numerical : numerical_access_t; unit : cs.chars_ptr) return c.int; pragma import (c, set_unit_system, "AG_NumericalSetUnitSystem"); procedure select_unit (numerical : numerical_access_t; unit : cs.chars_ptr); pragma import (c, select_unit, "AG_NumericalSelectUnit"); procedure set_precision (numerical : numerical_access_t; format : cs.chars_ptr; precision : c.int); pragma import (c, set_precision, "AG_NumericalSetPrecision"); procedure set_writeable (numerical : numerical_access_t; writeable : c.int); pragma import (c, set_writeable, "AG_NumericalSetWriteable"); end cbinds; function allocate (parent : widget_access_t; flags : flags_t; unit : string; label : string) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access)); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access)); end; end if; end allocate; function allocate_float (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : float_access_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_float (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_float (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value); end; end if; end allocate_float; function allocate_float_ranged (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : float_access_t; min : float_t; max : float_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_float_ranged (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value, min => min, max => max); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_float_ranged (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value, min => min, max => max); end; end if; end allocate_float_ranged; function allocate_double (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : double_access_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_double (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_double (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value); end; end if; end allocate_double; function allocate_double_ranged (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : double_access_t; min : double_t; max : double_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_double_ranged (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value, min => min, max => max); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_double_ranged (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value, min => min, max => max); end; end if; end allocate_double_ranged; function allocate_integer (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : integer_access_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_integer (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_integer (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value); end; end if; end allocate_integer; function allocate_integer_ranged (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : integer_access_t; min : integer_t; max : integer_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_integer_ranged (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value, min => min, max => max); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_integer_ranged (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value, min => min, max => max); end; end if; end allocate_integer_ranged; function allocate_unsigned (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : unsigned_access_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_unsigned (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_unsigned (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value); end; end if; end allocate_unsigned; function allocate_unsigned_ranged (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : unsigned_access_t; min : unsigned_t; max : unsigned_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_unsigned_ranged (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value, min => min, max => max); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_unsigned_ranged (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value, min => min, max => max); end; end if; end allocate_unsigned_ranged; function allocate_uint8 (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : agar.core.types.uint8_ptr_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_uint8 (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_uint8 (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value); end; end if; end allocate_uint8; function allocate_uint16 (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : agar.core.types.uint16_ptr_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_uint16 (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_uint16 (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value); end; end if; end allocate_uint16; function allocate_uint32 (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : agar.core.types.uint32_ptr_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_uint32 (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_uint32 (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value); end; end if; end allocate_uint32; function allocate_int8 (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : agar.core.types.int8_ptr_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_int8 (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_int8 (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value); end; end if; end allocate_int8; function allocate_int16 (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : agar.core.types.int16_ptr_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_int16 (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_int16 (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value); end; end if; end allocate_int16; function allocate_int32 (parent : widget_access_t; flags : flags_t; unit : string; label : string; value : agar.core.types.int32_ptr_t) return numerical_access_t is c_label : aliased c.char_array := c.to_c (label); begin if unit /= no_unit then return cbinds.allocate_int32 (parent => parent, flags => flags, unit => cs.null_ptr, label => cs.to_chars_ptr (c_label'unchecked_access), value => value); else declare c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.allocate_int32 (parent => parent, flags => flags, unit => cs.to_chars_ptr (c_unit'unchecked_access), label => cs.to_chars_ptr (c_label'unchecked_access), value => value); end; end if; end allocate_int32; function set_unit_system (numerical : numerical_access_t; unit : string) return boolean is c_unit : aliased c.char_array := c.to_c (unit); begin return cbinds.set_unit_system (numerical => numerical, unit => cs.to_chars_ptr (c_unit'unchecked_access)) = 0; end set_unit_system; procedure select_unit (numerical : numerical_access_t; unit : string) is c_unit : aliased c.char_array := c.to_c (unit); begin cbinds.select_unit (numerical => numerical, unit => cs.to_chars_ptr (c_unit'unchecked_access)); end select_unit; procedure set_precision (numerical : numerical_access_t; format : string; precision : positive) is c_format : aliased c.char_array := c.to_c (format); begin cbinds.set_precision (numerical => numerical, format => cs.to_chars_ptr (c_format'unchecked_access), precision => c.int (precision)); end set_precision; procedure set_writeable (numerical : numerical_access_t; writeable : boolean) is begin if writeable then cbinds.set_writeable (numerical, 1); else cbinds.set_writeable (numerical, 0); end if; end set_writeable; procedure sub_value (numerical : numerical_access_t; value : double_t) is begin add_value (numerical, 0.0 - value); end sub_value; function widget (numerical : numerical_access_t) return widget_access_t is begin return numerical.widget'access; end widget; end agar.gui.widget.numerical;
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- package body Program.Nodes.Infix_Operators is function Create (Left : Program.Elements.Expressions.Expression_Access; Operator : not null Program.Elements.Operator_Symbols .Operator_Symbol_Access; Right : not null Program.Elements.Expressions.Expression_Access) return Infix_Operator is begin return Result : Infix_Operator := (Left => Left, Operator => Operator, Right => Right, Enclosing_Element => null) do Initialize (Result); end return; end Create; function Create (Left : Program.Elements.Expressions.Expression_Access; Operator : not null Program.Elements.Operator_Symbols .Operator_Symbol_Access; Right : not null Program.Elements.Expressions .Expression_Access; Is_Part_Of_Implicit : Boolean := False; Is_Part_Of_Inherited : Boolean := False; Is_Part_Of_Instance : Boolean := False) return Implicit_Infix_Operator is begin return Result : Implicit_Infix_Operator := (Left => Left, Operator => Operator, Right => Right, Is_Part_Of_Implicit => Is_Part_Of_Implicit, Is_Part_Of_Inherited => Is_Part_Of_Inherited, Is_Part_Of_Instance => Is_Part_Of_Instance, Enclosing_Element => null) do Initialize (Result); end return; end Create; overriding function Left (Self : Base_Infix_Operator) return Program.Elements.Expressions.Expression_Access is begin return Self.Left; end Left; overriding function Operator (Self : Base_Infix_Operator) return not null Program.Elements.Operator_Symbols .Operator_Symbol_Access is begin return Self.Operator; end Operator; overriding function Right (Self : Base_Infix_Operator) return not null Program.Elements.Expressions.Expression_Access is begin return Self.Right; end Right; overriding function Is_Part_Of_Implicit (Self : Implicit_Infix_Operator) return Boolean is begin return Self.Is_Part_Of_Implicit; end Is_Part_Of_Implicit; overriding function Is_Part_Of_Inherited (Self : Implicit_Infix_Operator) return Boolean is begin return Self.Is_Part_Of_Inherited; end Is_Part_Of_Inherited; overriding function Is_Part_Of_Instance (Self : Implicit_Infix_Operator) return Boolean is begin return Self.Is_Part_Of_Instance; end Is_Part_Of_Instance; procedure Initialize (Self : in out Base_Infix_Operator'Class) is begin if Self.Left.Assigned then Set_Enclosing_Element (Self.Left, Self'Unchecked_Access); end if; Set_Enclosing_Element (Self.Operator, Self'Unchecked_Access); Set_Enclosing_Element (Self.Right, Self'Unchecked_Access); null; end Initialize; overriding function Is_Infix_Operator (Self : Base_Infix_Operator) return Boolean is pragma Unreferenced (Self); begin return True; end Is_Infix_Operator; overriding function Is_Expression (Self : Base_Infix_Operator) return Boolean is pragma Unreferenced (Self); begin return True; end Is_Expression; overriding procedure Visit (Self : not null access Base_Infix_Operator; Visitor : in out Program.Element_Visitors.Element_Visitor'Class) is begin Visitor.Infix_Operator (Self); end Visit; overriding function To_Infix_Operator_Text (Self : in out Infix_Operator) return Program.Elements.Infix_Operators.Infix_Operator_Text_Access is begin return Self'Unchecked_Access; end To_Infix_Operator_Text; overriding function To_Infix_Operator_Text (Self : in out Implicit_Infix_Operator) return Program.Elements.Infix_Operators.Infix_Operator_Text_Access is pragma Unreferenced (Self); begin return null; end To_Infix_Operator_Text; end Program.Nodes.Infix_Operators;
package display is type grid is array(1..50,1..100) of boolean ; screen : grid ; procedure render(screen : grid) ; end display ;
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr> -- MIT license. Please refer to the LICENSE file. with Ada.Unchecked_Deallocation, Apsepp.Scope_Bound_Locks, Apsepp_Scope_Bound_Locks_Test_Fixture, Apsepp.Generic_Fixture.Creator; package body Apsepp_Scope_Bound_Locks_Test_Case is use Apsepp.Scope_Bound_Locks, Apsepp_Scope_Bound_Locks_Test_Fixture; ---------------------------------------------------------------------------- function SBLF return Scope_Bound_Locks_Test_Fixture_Access renames Instance; ---------------------------------------------------------------------------- procedure SB_Lock_CB_procedure_Test is procedure P_Null is new SB_Lock_CB_procedure (null); procedure P_Increment_N is new SB_Lock_CB_procedure (Increment_N'Access); begin P_Null; Assert (SBLF.N = 0); P_Increment_N; Assert (SBLF.N = 1); end SB_Lock_CB_procedure_Test; ---------------------------------------------------------------------------- procedure Locked_Test is begin Assert (not Locked (SBLF.Lock)); declare Locker : SB_L_Locker (SBLF.Lock'Access); pragma Unreferenced (Locker); begin Assert (Locked (SBLF.Lock)); end; Assert (not Locked (SBLF.Lock)); declare Locker : SB_L_Locker (SBLF.Lock'Access); pragma Unreferenced (Locker); begin Assert (Locked (SBLF.Lock)); end; Assert (not Locked (SBLF.Lock)); end; ---------------------------------------------------------------------------- procedure Locked_With_CB_Test is begin Assert (not Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 0); declare Locker : SB_L_Locker (SBLF.Lock_W_CB'Access); pragma Unreferenced (Locker); begin Assert (Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 1); end; Assert (not Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 0); begin declare Locker : SB_L_Locker (SBLF.Lock_W_CB'Access); pragma Unreferenced (Locker); begin Assert (Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 1); raise Program_Error; end; exception when others => Assert (not Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 0); end; Assert (not Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 0); declare Locker : SB_L_Locker (SBLF.Lock_W_CB'Access); pragma Unreferenced (Locker); begin Assert (Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 1); end; Assert (not Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 0); end; ---------------------------------------------------------------------------- procedure Has_Actually_Locked_Test is begin declare Outer_Locker : SB_L_Locker (SBLF.Lock'Access); begin Assert (Outer_Locker.Has_Actually_Locked); declare Inner_Locker : SB_L_Locker (SBLF.Lock'Access); begin Assert (not Inner_Locker.Has_Actually_Locked); end; Assert (Outer_Locker.Has_Actually_Locked); end; end; ---------------------------------------------------------------------------- procedure Has_Actually_Locked_With_CB_Test is begin declare Outer_Locker : SB_L_Locker (SBLF.Lock_W_CB'Access); begin Assert (Outer_Locker.Has_Actually_Locked); Assert (SBLF.N = 1); declare Inner_Locker : SB_L_Locker (SBLF.Lock_W_CB'Access); begin Assert (not Inner_Locker.Has_Actually_Locked); Assert (SBLF.N = 1); end; Assert (Outer_Locker.Has_Actually_Locked); Assert (SBLF.N = 1); end; Assert (SBLF.N = 0); end; ---------------------------------------------------------------------------- procedure Allocator_Test is type SB_L_Locker_Access is access SB_L_Locker; procedure Free is new Ada.Unchecked_Deallocation (SB_L_Locker, SB_L_Locker_Access); Locker_Access_1, Locker_Access_2 : SB_L_Locker_Access; begin Assert (not Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 0); Locker_Access_1 := new SB_L_Locker (SBLF.Lock_W_CB'Access); Assert (Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 1); Assert (Locker_Access_1.Has_Actually_Locked); Locker_Access_2 := new SB_L_Locker (SBLF.Lock_W_CB'Access); Assert (Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 1); Assert (not Locker_Access_2.Has_Actually_Locked); Assert (Locker_Access_1.Has_Actually_Locked); Free (Locker_Access_1); Assert (Locker_Access_1 = null); Assert (not Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 0); Assert (not Locker_Access_2.Has_Actually_Locked); Free (Locker_Access_2); Assert (Locker_Access_2 = null); Assert (not Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 0); Locker_Access_1 := new SB_L_Locker (SBLF.Lock_W_CB'Access); Assert (Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 1); Assert (Locker_Access_1.Has_Actually_Locked); Locker_Access_2 := new SB_L_Locker (SBLF.Lock_W_CB'Access); Assert (Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 1); Assert (not Locker_Access_2.Has_Actually_Locked); Free (Locker_Access_2); Assert (Locker_Access_2 = null); Assert (Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 1); Assert (Locker_Access_1.Has_Actually_Locked); Free (Locker_Access_1); Assert (Locker_Access_1 = null); Assert (not Locked (SBLF.Lock_W_CB)); Assert (SBLF.N = 0); end; ---------------------------------------------------------------------------- overriding procedure Setup_Routine (Obj : Apsepp_Scope_Bound_Locks_T_C) is pragma Unreferenced (Obj); begin SBLF.Reset; end Setup_Routine; ---------------------------------------------------------------------------- overriding function Routine_Array (Obj : Apsepp_Scope_Bound_Locks_T_C) return Test_Routine_Array is (SB_Lock_CB_procedure_Test'Access, Locked_Test'Access, Locked_With_CB_Test'Access, Has_Actually_Locked_Test'Access, Has_Actually_Locked_With_CB_Test'Access, Allocator_Test'Access); ---------------------------------------------------------------------------- overriding procedure Run (Obj : in out Apsepp_Scope_Bound_Locks_T_C; Outcome : out Test_Outcome; Kind : Run_Kind := Assert_Cond_And_Run_Test) is ----------------------------------------------------- package Scope_Bound_Locks_T_F_Creator is new Scope_Bound_Locks_T_F.Creator (Just_Pretend => Check_Cond_Run (Kind)); ----------------------------------------------------- function Cond return Boolean is (Scope_Bound_Locks_T_F_Creator.Has_Actually_Created); ----------------------------------------------------- begin Run_Body (Obj, Outcome, Kind, Cond'Access); end Run; ---------------------------------------------------------------------------- end Apsepp_Scope_Bound_Locks_Test_Case;
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- SYSTEM.MULTIPROCESSORS.DISPATCHING_DOMAINS -- -- -- -- B o d y -- -- -- -- Copyright (C) 2011-2019, Free Software Foundation, Inc. -- -- -- -- GNARL is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNARL was developed by the GNARL team at Florida State University. -- -- Extensive contributions were provided by Ada Core Technologies, Inc. -- -- -- ------------------------------------------------------------------------------ -- Body used on targets where the operating system supports setting task -- affinities. with System.Tasking.Initialization; with System.Task_Primitives.Operations; use System.Task_Primitives.Operations; with Ada.Unchecked_Conversion; package body System.Multiprocessors.Dispatching_Domains is package ST renames System.Tasking; ----------------------- -- Local subprograms -- ----------------------- function Convert_Ids is new Ada.Unchecked_Conversion (Ada.Task_Identification.Task_Id, ST.Task_Id); procedure Unchecked_Set_Affinity (Domain : ST.Dispatching_Domain_Access; CPU : CPU_Range; T : ST.Task_Id); -- Internal procedure to move a task to a target domain and CPU. No checks -- are performed about the validity of the domain and the CPU because they -- are done by the callers of this procedure (either Assign_Task or -- Set_CPU). procedure Freeze_Dispatching_Domains; pragma Export (Ada, Freeze_Dispatching_Domains, "__gnat_freeze_dispatching_domains"); -- Signal the time when no new dispatching domains can be created. It -- should be called before the environment task calls the main procedure -- (and after the elaboration code), so the binder-generated file needs to -- import and call this procedure. ----------------- -- Assign_Task -- ----------------- procedure Assign_Task (Domain : in out Dispatching_Domain; CPU : CPU_Range := Not_A_Specific_CPU; T : Ada.Task_Identification.Task_Id := Ada.Task_Identification.Current_Task) is Target : constant ST.Task_Id := Convert_Ids (T); begin -- The exception Dispatching_Domain_Error is propagated if T is already -- assigned to a Dispatching_Domain other than -- System_Dispatching_Domain, or if CPU is not one of the processors of -- Domain (and is not Not_A_Specific_CPU). if Dispatching_Domain (Target.Common.Domain) /= System_Dispatching_Domain then raise Dispatching_Domain_Error with "task already in user-defined dispatching domain"; elsif CPU /= Not_A_Specific_CPU and then CPU not in Domain'Range then raise Dispatching_Domain_Error with "processor does not belong to dispatching domain"; end if; -- Assigning a task to System_Dispatching_Domain that is already -- assigned to that domain has no effect. if Domain = System_Dispatching_Domain then return; else -- Set the task affinity once we know it is possible Unchecked_Set_Affinity (ST.Dispatching_Domain_Access (Domain), CPU, Target); end if; end Assign_Task; ------------ -- Create -- ------------ function Create (First : CPU; Last : CPU_Range) return Dispatching_Domain is begin return Create ((First .. Last => True)); end Create; function Create (Set : CPU_Set) return Dispatching_Domain is ST_DD : aliased constant ST.Dispatching_Domain := ST.Dispatching_Domain (Set); First : constant CPU := Get_First_CPU (ST_DD'Unrestricted_Access); Last : constant CPU_Range := Get_Last_CPU (ST_DD'Unrestricted_Access); subtype Rng is CPU_Range range First .. Last; use type ST.Dispatching_Domain; use type ST.Dispatching_Domain_Access; use type ST.Task_Id; T : ST.Task_Id; New_System_Domain : ST.Dispatching_Domain := ST.System_Domain.all; ST_DD_Slice : constant ST.Dispatching_Domain := ST_DD (Rng); begin -- The set of processors for creating a dispatching domain must -- comply with the following restrictions: -- - Not exceeding the range of available processors. -- - CPUs from the System_Dispatching_Domain. -- - The calling task must be the environment task. -- - The call to Create must take place before the call to the main -- subprogram. -- - Set does not contain a processor with a task assigned to it. -- - The allocation cannot leave System_Dispatching_Domain empty. -- Note that a previous version of the language forbade empty domains. if Rng'Last > Number_Of_CPUs then raise Dispatching_Domain_Error with "CPU not supported by the target"; end if; declare System_Domain_Slice : constant ST.Dispatching_Domain := ST.System_Domain (Rng); Actual : constant ST.Dispatching_Domain := ST_DD_Slice and not System_Domain_Slice; Expected : constant ST.Dispatching_Domain := (Rng => False); begin if Actual /= Expected then raise Dispatching_Domain_Error with "CPU not currently in System_Dispatching_Domain"; end if; end; if Self /= Environment_Task then raise Dispatching_Domain_Error with "only the environment task can create dispatching domains"; end if; if ST.Dispatching_Domains_Frozen then raise Dispatching_Domain_Error with "cannot create dispatching domain after call to main procedure"; end if; for Proc in Rng loop if ST_DD (Proc) and then ST.Dispatching_Domain_Tasks (Proc) /= 0 then raise Dispatching_Domain_Error with "CPU has tasks assigned"; end if; end loop; New_System_Domain (Rng) := New_System_Domain (Rng) and not ST_DD_Slice; if New_System_Domain = (New_System_Domain'Range => False) then raise Dispatching_Domain_Error with "would leave System_Dispatching_Domain empty"; end if; return Result : constant Dispatching_Domain := new ST.Dispatching_Domain'(ST_DD_Slice) do -- At this point we need to fix the processors belonging to the -- system domain, and change the affinity of every task that has -- been created and assigned to the system domain. ST.Initialization.Defer_Abort (Self); Lock_RTS; ST.System_Domain (Rng) := New_System_Domain (Rng); pragma Assert (ST.System_Domain.all = New_System_Domain); -- Iterate the list of tasks belonging to the default system -- dispatching domain and set the appropriate affinity. T := ST.All_Tasks_List; while T /= null loop if T.Common.Domain = ST.System_Domain then Set_Task_Affinity (T); end if; T := T.Common.All_Tasks_Link; end loop; Unlock_RTS; ST.Initialization.Undefer_Abort (Self); end return; end Create; ----------------------------- -- Delay_Until_And_Set_CPU -- ----------------------------- procedure Delay_Until_And_Set_CPU (Delay_Until_Time : Ada.Real_Time.Time; CPU : CPU_Range) is begin -- Not supported atomically by the underlying operating systems. -- Operating systems use to migrate the task immediately after the call -- to set the affinity. delay until Delay_Until_Time; Set_CPU (CPU); end Delay_Until_And_Set_CPU; -------------------------------- -- Freeze_Dispatching_Domains -- -------------------------------- procedure Freeze_Dispatching_Domains is begin -- Signal the end of the elaboration code ST.Dispatching_Domains_Frozen := True; end Freeze_Dispatching_Domains; ------------- -- Get_CPU -- ------------- function Get_CPU (T : Ada.Task_Identification.Task_Id := Ada.Task_Identification.Current_Task) return CPU_Range is begin return Convert_Ids (T).Common.Base_CPU; end Get_CPU; ----------------- -- Get_CPU_Set -- ----------------- function Get_CPU_Set (Domain : Dispatching_Domain) return CPU_Set is begin return CPU_Set (Domain.all); end Get_CPU_Set; ---------------------------- -- Get_Dispatching_Domain -- ---------------------------- function Get_Dispatching_Domain (T : Ada.Task_Identification.Task_Id := Ada.Task_Identification.Current_Task) return Dispatching_Domain is begin return Result : constant Dispatching_Domain := Dispatching_Domain (Convert_Ids (T).Common.Domain) do pragma Assert (Result /= null); end return; end Get_Dispatching_Domain; ------------------- -- Get_First_CPU -- ------------------- function Get_First_CPU (Domain : Dispatching_Domain) return CPU is begin for Proc in Domain'Range loop if Domain (Proc) then return Proc; end if; end loop; return CPU'First; end Get_First_CPU; ------------------ -- Get_Last_CPU -- ------------------ function Get_Last_CPU (Domain : Dispatching_Domain) return CPU_Range is begin for Proc in reverse Domain'Range loop if Domain (Proc) then return Proc; end if; end loop; return CPU_Range'First; end Get_Last_CPU; ------------- -- Set_CPU -- ------------- procedure Set_CPU (CPU : CPU_Range; T : Ada.Task_Identification.Task_Id := Ada.Task_Identification.Current_Task) is Target : constant ST.Task_Id := Convert_Ids (T); begin -- The exception Dispatching_Domain_Error is propagated if CPU is not -- one of the processors of the Dispatching_Domain on which T is -- assigned (and is not Not_A_Specific_CPU). if CPU /= Not_A_Specific_CPU and then (CPU not in Target.Common.Domain'Range or else not Target.Common.Domain (CPU)) then raise Dispatching_Domain_Error with "processor does not belong to the task's dispatching domain"; end if; Unchecked_Set_Affinity (Target.Common.Domain, CPU, Target); end Set_CPU; ---------------------------- -- Unchecked_Set_Affinity -- ---------------------------- procedure Unchecked_Set_Affinity (Domain : ST.Dispatching_Domain_Access; CPU : CPU_Range; T : ST.Task_Id) is Source_CPU : constant CPU_Range := T.Common.Base_CPU; use type ST.Dispatching_Domain_Access; begin Write_Lock (T); -- Move to the new domain T.Common.Domain := Domain; -- Attach the CPU to the task T.Common.Base_CPU := CPU; -- Change the number of tasks attached to a given task in the system -- domain if needed. if not ST.Dispatching_Domains_Frozen and then (Domain = null or else Domain = ST.System_Domain) then -- Reduce the number of tasks attached to the CPU from which this -- task is being moved, if needed. if Source_CPU /= Not_A_Specific_CPU then ST.Dispatching_Domain_Tasks (Source_CPU) := ST.Dispatching_Domain_Tasks (Source_CPU) - 1; end if; -- Increase the number of tasks attached to the CPU to which this -- task is being moved, if needed. if CPU /= Not_A_Specific_CPU then ST.Dispatching_Domain_Tasks (CPU) := ST.Dispatching_Domain_Tasks (CPU) + 1; end if; end if; -- Change the actual affinity calling the operating system level Set_Task_Affinity (T); Unlock (T); end Unchecked_Set_Affinity; end System.Multiprocessors.Dispatching_Domains;
with Ada.Text_IO, Another_Package; use Ada.Text_IO; -- the with-clause tells the compiler to include the Text_IO package from the Ada standard -- and Another_Package. Subprograms from these packages may be called as follows: -- Ada.Text_IO.Put_Line("some text"); -- Another_Package.Do_Something("some text"); -- The use-clause allows the program author to write a subprogram call shortly as -- Put_Line("some text");
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- S Y S T E M . W I N 3 2 -- -- -- -- S p e c -- -- -- -- Copyright (C) 2008-2019, Free Software Foundation, Inc. -- -- -- -- 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 Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package plus its child provide the low level interface to the Win32 -- API. The core part of the Win32 API (common to RTX and Win32) is in this -- package, and an additional part of the Win32 API which is not supported by -- RTX is in package System.Win32.Ext. with Interfaces.C; package System.Win32 is pragma Pure; ------------------- -- General Types -- ------------------- -- The LARGE_INTEGER type is actually a fixed point type -- that only can represent integers. The reason for this is -- easier conversion to Duration or other fixed point types. -- (See System.OS_Primitives.Clock, mingw and rtx versions.) type LARGE_INTEGER is delta 1.0 range -2.0**63 .. 2.0**63 - 1.0; subtype PVOID is Address; type HANDLE is new Interfaces.C.ptrdiff_t; INVALID_HANDLE_VALUE : constant HANDLE := -1; INVALID_FILE_SIZE : constant := 16#FFFFFFFF#; type DWORD is new Interfaces.C.unsigned_long; type WORD is new Interfaces.C.unsigned_short; type BYTE is new Interfaces.C.unsigned_char; type LONG is new Interfaces.C.long; type CHAR is new Interfaces.C.char; type BOOL is new Interfaces.C.int; for BOOL'Size use Interfaces.C.int'Size; type Bits1 is range 0 .. 2 ** 1 - 1; type Bits2 is range 0 .. 2 ** 2 - 1; type Bits17 is range 0 .. 2 ** 17 - 1; for Bits1'Size use 1; for Bits2'Size use 2; for Bits17'Size use 17; -- Note that the following clashes with standard names are to stay -- compatible with the historical choice of following the C names. pragma Warnings (Off); FALSE : constant := 0; TRUE : constant := 1; pragma Warnings (On); function GetLastError return DWORD; pragma Import (Stdcall, GetLastError, "GetLastError"); ----------- -- Files -- ----------- CP_UTF8 : constant := 65001; CP_ACP : constant := 0; GENERIC_READ : constant := 16#80000000#; GENERIC_WRITE : constant := 16#40000000#; CREATE_NEW : constant := 1; CREATE_ALWAYS : constant := 2; OPEN_EXISTING : constant := 3; OPEN_ALWAYS : constant := 4; TRUNCATE_EXISTING : constant := 5; FILE_SHARE_DELETE : constant := 16#00000004#; FILE_SHARE_READ : constant := 16#00000001#; FILE_SHARE_WRITE : constant := 16#00000002#; FILE_BEGIN : constant := 0; FILE_CURRENT : constant := 1; FILE_END : constant := 2; PAGE_NOACCESS : constant := 16#0001#; PAGE_READONLY : constant := 16#0002#; PAGE_READWRITE : constant := 16#0004#; PAGE_WRITECOPY : constant := 16#0008#; PAGE_EXECUTE : constant := 16#0010#; FILE_MAP_ALL_ACCESS : constant := 16#F001f#; FILE_MAP_READ : constant := 4; FILE_MAP_WRITE : constant := 2; FILE_MAP_COPY : constant := 1; FILE_ADD_FILE : constant := 16#0002#; FILE_ADD_SUBDIRECTORY : constant := 16#0004#; FILE_APPEND_DATA : constant := 16#0004#; FILE_CREATE_PIPE_INSTANCE : constant := 16#0004#; FILE_DELETE_CHILD : constant := 16#0040#; FILE_EXECUTE : constant := 16#0020#; FILE_LIST_DIRECTORY : constant := 16#0001#; FILE_READ_ATTRIBUTES : constant := 16#0080#; FILE_READ_DATA : constant := 16#0001#; FILE_READ_EA : constant := 16#0008#; FILE_TRAVERSE : constant := 16#0020#; FILE_WRITE_ATTRIBUTES : constant := 16#0100#; FILE_WRITE_DATA : constant := 16#0002#; FILE_WRITE_EA : constant := 16#0010#; STANDARD_RIGHTS_READ : constant := 16#20000#; STANDARD_RIGHTS_WRITE : constant := 16#20000#; SYNCHRONIZE : constant := 16#100000#; FILE_ATTRIBUTE_READONLY : constant := 16#00000001#; FILE_ATTRIBUTE_HIDDEN : constant := 16#00000002#; FILE_ATTRIBUTE_SYSTEM : constant := 16#00000004#; FILE_ATTRIBUTE_DIRECTORY : constant := 16#00000010#; FILE_ATTRIBUTE_ARCHIVE : constant := 16#00000020#; FILE_ATTRIBUTE_DEVICE : constant := 16#00000040#; FILE_ATTRIBUTE_NORMAL : constant := 16#00000080#; FILE_ATTRIBUTE_TEMPORARY : constant := 16#00000100#; FILE_ATTRIBUTE_SPARSE_FILE : constant := 16#00000200#; FILE_ATTRIBUTE_REPARSE_POINT : constant := 16#00000400#; FILE_ATTRIBUTE_COMPRESSED : constant := 16#00000800#; FILE_ATTRIBUTE_OFFLINE : constant := 16#00001000#; FILE_ATTRIBUTE_NOT_CONTENT_INDEXED : constant := 16#00002000#; FILE_ATTRIBUTE_ENCRYPTED : constant := 16#00004000#; FILE_ATTRIBUTE_VALID_FLAGS : constant := 16#00007fb7#; FILE_ATTRIBUTE_VALID_SET_FLAGS : constant := 16#000031a7#; GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS : constant := 16#00000004#; type OVERLAPPED is record Internal : DWORD; InternalHigh : DWORD; Offset : DWORD; OffsetHigh : DWORD; hEvent : HANDLE; end record; type SECURITY_ATTRIBUTES is record nLength : DWORD; pSecurityDescriptor : PVOID; bInheritHandle : BOOL; end record; function CreateFileA (lpFileName : Address; dwDesiredAccess : DWORD; dwShareMode : DWORD; lpSecurityAttributes : access SECURITY_ATTRIBUTES; dwCreationDisposition : DWORD; dwFlagsAndAttributes : DWORD; hTemplateFile : HANDLE) return HANDLE; pragma Import (Stdcall, CreateFileA, "CreateFileA"); function CreateFile (lpFileName : Address; dwDesiredAccess : DWORD; dwShareMode : DWORD; lpSecurityAttributes : access SECURITY_ATTRIBUTES; dwCreationDisposition : DWORD; dwFlagsAndAttributes : DWORD; hTemplateFile : HANDLE) return HANDLE; pragma Import (Stdcall, CreateFile, "CreateFileW"); function GetFileSize (hFile : HANDLE; lpFileSizeHigh : access DWORD) return BOOL; pragma Import (Stdcall, GetFileSize, "GetFileSize"); function SetFilePointer (hFile : HANDLE; lDistanceToMove : LONG; lpDistanceToMoveHigh : access LONG; dwMoveMethod : DWORD) return DWORD; pragma Import (Stdcall, SetFilePointer, "SetFilePointer"); function WriteFile (hFile : HANDLE; lpBuffer : Address; nNumberOfBytesToWrite : DWORD; lpNumberOfBytesWritten : access DWORD; lpOverlapped : access OVERLAPPED) return BOOL; pragma Import (Stdcall, WriteFile, "WriteFile"); function ReadFile (hFile : HANDLE; lpBuffer : Address; nNumberOfBytesToRead : DWORD; lpNumberOfBytesRead : access DWORD; lpOverlapped : access OVERLAPPED) return BOOL; pragma Import (Stdcall, ReadFile, "ReadFile"); function CloseHandle (hObject : HANDLE) return BOOL; pragma Import (Stdcall, CloseHandle, "CloseHandle"); function CreateFileMapping (hFile : HANDLE; lpSecurityAttributes : access SECURITY_ATTRIBUTES; flProtect : DWORD; dwMaximumSizeHigh : DWORD; dwMaximumSizeLow : DWORD; lpName : Address) return HANDLE; pragma Import (Stdcall, CreateFileMapping, "CreateFileMappingA"); function MapViewOfFile (hFileMappingObject : HANDLE; dwDesiredAccess : DWORD; dwFileOffsetHigh : DWORD; dwFileOffsetLow : DWORD; dwNumberOfBytesToMap : DWORD) return System.Address; pragma Import (Stdcall, MapViewOfFile, "MapViewOfFile"); function UnmapViewOfFile (lpBaseAddress : System.Address) return BOOL; pragma Import (Stdcall, UnmapViewOfFile, "UnmapViewOfFile"); function MultiByteToWideChar (CodePage : WORD; dwFlags : DWORD; lpMultiByteStr : System.Address; cchMultiByte : WORD; lpWideCharStr : System.Address; cchWideChar : WORD) return WORD; pragma Import (Stdcall, MultiByteToWideChar, "MultiByteToWideChar"); ------------------------ -- System Information -- ------------------------ subtype ProcessorId is DWORD; type SYSTEM_INFO is record dwOemId : DWORD; dwPageSize : DWORD; lpMinimumApplicationAddress : PVOID; lpMaximumApplicationAddress : PVOID; dwActiveProcessorMask : DWORD; dwNumberOfProcessors : DWORD; dwProcessorType : DWORD; dwAllocationGranularity : DWORD; dwReserved : DWORD; end record; procedure GetSystemInfo (SI : access SYSTEM_INFO); pragma Import (Stdcall, GetSystemInfo, "GetSystemInfo"); --------------------- -- Time Management -- --------------------- type SYSTEMTIME is record wYear : WORD; wMonth : WORD; wDayOfWeek : WORD; wDay : WORD; wHour : WORD; wMinute : WORD; wSecond : WORD; wMilliseconds : WORD; end record; procedure GetSystemTime (pSystemTime : access SYSTEMTIME); pragma Import (Stdcall, GetSystemTime, "GetSystemTime"); procedure GetSystemTimeAsFileTime (lpFileTime : access Long_Long_Integer); pragma Import (Stdcall, GetSystemTimeAsFileTime, "GetSystemTimeAsFileTime"); function FileTimeToSystemTime (lpFileTime : access Long_Long_Integer; lpSystemTime : access SYSTEMTIME) return BOOL; pragma Import (Stdcall, FileTimeToSystemTime, "FileTimeToSystemTime"); function SystemTimeToFileTime (lpSystemTime : access SYSTEMTIME; lpFileTime : access Long_Long_Integer) return BOOL; pragma Import (Stdcall, SystemTimeToFileTime, "SystemTimeToFileTime"); function FileTimeToLocalFileTime (lpFileTime : access Long_Long_Integer; lpLocalFileTime : access Long_Long_Integer) return BOOL; pragma Import (Stdcall, FileTimeToLocalFileTime, "FileTimeToLocalFileTime"); function LocalFileTimeToFileTime (lpFileTime : access Long_Long_Integer; lpLocalFileTime : access Long_Long_Integer) return BOOL; pragma Import (Stdcall, LocalFileTimeToFileTime, "LocalFileTimeToFileTime"); procedure Sleep (dwMilliseconds : DWORD); pragma Import (Stdcall, Sleep, External_Name => "Sleep"); function QueryPerformanceCounter (lpPerformanceCount : access LARGE_INTEGER) return BOOL; pragma Import (Stdcall, QueryPerformanceCounter, "QueryPerformanceCounter"); ------------ -- Module -- ------------ function GetModuleHandleEx (dwFlags : DWORD; lpModuleName : Address; phModule : access HANDLE) return BOOL; pragma Import (Stdcall, GetModuleHandleEx, "GetModuleHandleExA"); function GetModuleFileName (hModule : HANDLE; lpFilename : Address; nSize : DWORD) return DWORD; pragma Import (Stdcall, GetModuleFileName, "GetModuleFileNameA"); function FreeLibrary (hModule : HANDLE) return BOOL; pragma Import (Stdcall, FreeLibrary, "FreeLibrary"); end System.Win32;
------------------------------------------------------------------------------ -- Copyright (c) 2016, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ package body Natools.String_Escapes is subtype Hex_Digit is Natural range 0 .. 15; function C_Escape_Hex (C : Character) return String; -- Return the string representing C in C-style escaped strings function Image (N : Hex_Digit) return Character; -- Return upper-case hexadecimal image of a digit ------------------------------ -- Local Helper Subprograms -- ------------------------------ function C_Escape_Hex (C : Character) return String is begin case C is when Character'Val (0) => return "\0"; when Character'Val (8) => return "\b"; when Character'Val (9) => return "\t"; when Character'Val (10) => return "\n"; when Character'Val (11) => return "\f"; when Character'Val (12) => return "\v"; when Character'Val (13) => return "\r"; when Character'Val (34) => return "\"""; when Character'Val (32) | Character'Val (33) | Character'Val (35) .. Character'Val (126) => return String'(1 => C); when others => declare Code : constant Natural := Character'Pos (C); begin return "\x" & Image (Code / 16) & Image (Code mod 16); end; end case; end C_Escape_Hex; function Image (N : Hex_Digit) return Character is begin case N is when 0 .. 9 => return Character'Val (Character'Pos ('0') + N); when 10 .. 15 => return Character'Val (Character'Pos ('A') + N - 10); end case; end Image; ---------------------- -- Public Interface -- ---------------------- function C_Escape_Hex (S : String; Add_Quotes : Boolean := False) return String is Length : Natural := 0; O : Positive := 1; Sublength : Natural := 0; begin for I in S'Range loop case S (I) is when Character'Val (0) | '"' | Character'Val (8) .. Character'Val (13) => Length := Length + 2; when Character'Val (32) | Character'Val (33) | Character'Val (35) .. Character'Val (126) => Length := Length + 1; when others => Length := Length + 4; end case; end loop; if Add_Quotes then Length := Length + 2; end if; return Result : String (1 .. Length) do if Add_Quotes then O := O + 1; Result (Result'First) := '"'; Result (Result'Last) := '"'; end if; for I in S'Range loop O := O + Sublength; declare Img : constant String := C_Escape_Hex (S (I)); begin Sublength := Img'Length; Result (O .. O + Sublength - 1) := Img; end; end loop; end return; end C_Escape_Hex; end Natools.String_Escapes;
with Libtcod.Color, Libtcod.Maps.FOV; package body Game_Maps is dark_wall : constant Color.RGB_Color := Color.make_RGB_color(0, 0, 100); dark_ground : constant Color.RGB_Color := Color.make_RGB_color(50, 50, 150); light_wall : constant Color.RGB_Color := Color.make_RGB_color(130, 110, 50); light_ground : constant Color.RGB_Color := Color.make_RGB_color(200, 180, 50); ------------- -- is_wall -- ------------- function is_wall(self : Game_Map; x : Maps.X_Pos; y : Maps.Y_Pos) return Boolean is (not self.map.is_walkable(x, y)); ----------------- -- is_explored -- ----------------- function is_explored(self : Game_Map; x : Maps.X_Pos; y : Maps.Y_Pos) return Boolean is (self.tiles(y, x).flags(Explored)); ------------ -- in_fov -- ------------ function in_fov(self : in out Game_Map; x : Maps.X_Pos; y : Maps.Y_Pos) return Boolean is begin if Maps.FOV.in_FOV(self.map, x, y) then self.tiles(y, x).flags(Explored) := True; return True; end if; return False; end in_fov; ----------------- -- compute_fov -- ----------------- procedure compute_fov(self : in out Game_Map; source_x : Maps.X_Pos; source_y : Maps.Y_Pos; radius : Maps.Radius) is begin Maps.FOV.compute_FOV(self.map, source_x, source_y, radius); end compute_fov; --------- -- dig -- --------- procedure dig(self : in out Game_Map; x1 : Maps.X_Pos; y1 : Maps.Y_Pos; x2 : Maps.X_Pos; y2 : Maps.Y_Pos) is begin for y in Maps.Y_Pos'Min(y1, y2) .. Maps.Y_Pos'Max(y1, y2) loop for x in Maps.X_Pos'Min(x1, x2) .. Maps.X_Pos'Max(x1, x2) loop self.map.set_properties(x, y, walkable => True, transparent => True); end loop; end loop; end dig; ------------------- -- make_game_map -- ------------------- function make_game_map(w : Width; h : Height) return Game_Map is begin return map : Game_Map := (width => Maps.X_Pos(w), height => Maps.Y_Pos(h), tiles => <>, map => Maps.make_map(w, h)); end make_game_map; ------------ -- render -- ------------ procedure render(self : in out Game_Map; screen : in out Console.Screen) is begin for y in self.tiles'Range loop for x in self.tiles'Range(2) loop if self.in_fov(x, y) then screen.set_char_bg(Console.X_Pos(x), Console.Y_Pos(y), (if self.is_wall(x, y) then light_wall else light_ground)); elsif self.is_explored(x, y) then screen.set_char_bg(Console.X_Pos(x), Console.Y_Pos(y), (if self.is_wall(x, y) then dark_wall else dark_ground)); end if; end loop; end loop; end render; end Game_Maps;
with Ada.Numerics.Real_Arrays; use Ada.Numerics.Real_Arrays; function Fit (X, Y : Real_Vector; N : Positive) return Real_Vector is A : Real_Matrix (0..N, X'Range); -- The plane begin for I in A'Range (2) loop for J in A'Range (1) loop A (J, I) := X (I)**J; end loop; end loop; return Solve (A * Transpose (A), A * Y); end Fit;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2020-2021, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ with System; with System.Machine_Code; use System.Machine_Code; with SAM_SVD.QSPI; use SAM_SVD.QSPI; package body SAM.QSPI is QSPI_Region : constant := 16#04000000#; Empty : UInt8_Array (1 .. 0); ------------ -- Enable -- ------------ procedure Enable is begin QSPI_Periph.CTRLA.ENABLE := True; end Enable; ----------- -- Reset -- ----------- procedure Reset is begin QSPI_Periph.CTRLA.SWRST := True; end Reset; --------------- -- Configure -- --------------- procedure Configure (Baud : UInt8) is begin QSPI_Periph.BAUD.BAUD := Baud; QSPI_Periph.CTRLB.MODE := MEMORY; QSPI_Periph.CTRLB.DATALEN := Val_8BITS; QSPI_Periph.CTRLB.CSMODE := LASTXFER; end Configure; --------- -- Run -- --------- procedure Run (Command : UInt8) is Iframe : QSPI_INSTRFRAME_Register := (others => <>); begin Iframe.WIDTH := SINGLE_BIT_SPI; Iframe.ADDRLEN := Val_24BITS; Iframe.TFRTYPE := READ; Iframe.INSTREN := True; Run_Instruction (Command, Iframe, 0, Empty); end Run; ---------- -- Read -- ---------- procedure Read (Command : UInt8; Data : out UInt8_Array) is Iframe : QSPI_INSTRFRAME_Register := (others => <>); begin Iframe.WIDTH := SINGLE_BIT_SPI; Iframe.ADDRLEN := Val_24BITS; Iframe.TFRTYPE := READ; Iframe.DATAEN := True; Iframe.INSTREN := True; Run_Instruction (Command, Iframe, 0, Data); end Read; ----------- -- Write -- ----------- procedure Write (Command : UInt8; Data : in out UInt8_Array) is Iframe : QSPI_INSTRFRAME_Register := (others => <>); begin Iframe.WIDTH := SINGLE_BIT_SPI; Iframe.ADDRLEN := Val_24BITS; Iframe.TFRTYPE := WRITE; Iframe.DATAEN := Data'Length /= 0; Iframe.INSTREN := True; Run_Instruction (Command, Iframe, 0, Data); end Write; ----------- -- Erase -- ----------- procedure Erase (Command : UInt8; Addr : UInt32) is Iframe : QSPI_INSTRFRAME_Register := (others => <>); begin Iframe.WIDTH := SINGLE_BIT_SPI; Iframe.ADDRLEN := Val_24BITS; Iframe.TFRTYPE := WRITE; Iframe.ADDREN := True; Iframe.INSTREN := True; Run_Instruction (Command, Iframe, Addr, Empty); end Erase; ----------------- -- Read_Memory -- ----------------- procedure Read_Memory (Addr : UInt32; Data : out UInt8_Array) is Iframe : QSPI_INSTRFRAME_Register := (others => <>); begin Iframe.WIDTH := QUAD_OUTPUT; Iframe.ADDRLEN := Val_24BITS; Iframe.TFRTYPE := READMEMORY; Iframe.ADDREN := True; Iframe.DATAEN := True; Iframe.INSTREN := True; Iframe.DUMMYLEN := 8; Run_Instruction (16#6B#, Iframe, Addr, Data); end Read_Memory; ------------------ -- Write_Memory -- ------------------ procedure Write_Memory (Addr : UInt32; Data : in out UInt8_Array) is Iframe : QSPI_INSTRFRAME_Register := (others => <>); begin Iframe.WIDTH := QUAD_OUTPUT; Iframe.ADDRLEN := Val_24BITS; Iframe.TFRTYPE := WRITEMEMORY; Iframe.ADDREN := True; Iframe.DATAEN := True; Iframe.INSTREN := True; Run_Instruction (16#32#, Iframe, Addr, Data); end Write_Memory; --------------------- -- Run_Instruction -- --------------------- procedure Run_Instruction (Command : UInt8; Iframe : SAM_SVD.QSPI.QSPI_INSTRFRAME_Register; Addr : UInt32; Buffer : in out UInt8_Array) is Unused : QSPI_INSTRFRAME_Register; begin -- WTF?!? -- if Command in 16#20# | 16#D8# then -- QSPI_Periph.INSTRADDR := Addr; -- end if; QSPI_Periph.INSTRCTRL.INSTR := Command; QSPI_Periph.INSTRADDR := Addr; QSPI_Periph.INSTRFRAME := Iframe; -- Dummy read of INSTRFRAME needed to synchronize. -- See Instruction Transmission Flow Diagram, figure 37.9, page 995 -- and Example 4, page 998, section 37.6.8.5. Unused := QSPI_Periph.INSTRFRAME; if Buffer'Length /= 0 then declare Mem : UInt8_Array (Buffer'First .. Buffer'Last) with Address => System'To_Address (QSPI_Region + Addr); begin case Iframe.TFRTYPE is when READ | READMEMORY => Buffer := Mem; when WRITE | WRITEMEMORY => Mem := Buffer; end case; end; end if; Asm ("dsb" & ASCII.LF & ASCII.HT & "isb", Volatile => True); QSPI_Periph.CTRLA := (SWRST => False, ENABLE => True, LASTXFER => True, others => <>); while not QSPI_Periph.INTFLAG.INSTREND loop null; end loop; QSPI_Periph.INTFLAG.INSTREND := True; end Run_Instruction; end SAM.QSPI;
with Ada.Numerics; with Ada.Unchecked_Deallocation; package body Circles is -- Initialization of a Circle procedure Initialize(This : in CircleAcc; Pos, Vel, Grav : in Vec2D; Rad : in Float; Mat : in Material) is begin Entities.Initialize(Entities.Entity(This.all), Entities.EntCircle, Pos, Vel, Grav, Mat); This.all.Radius := Rad; This.all.ComputeMass; end Initialize; -- Create a new Circle function Create(Pos, Vel, Grav : in Vec2D; Rad : in Float; Mat : in Material) return EntityClassAcc is TmpAcc : EntityClassAcc; begin TmpAcc := new Circle; Initialize(CircleAcc(TmpAcc), Pos, Vel, Grav, Rad, Mat); return TmpAcc; end Create; overriding procedure ComputeMass(This : in out Circle) is begin This.Mass := Ada.Numerics.Pi * This.Radius * This.Radius * This.Mat.Density; This.InvMass := (if This.Mass = 0.0 then 0.0 else 1.0 / This.Mass); end ComputeMass; procedure FreeEnt(This : access Circle) is procedure FreeCircle is new Ada.Unchecked_Deallocation(Circle, CircleAcc); P : CircleAcc := CircleAcc(This); begin FreeCircle(P); end FreeEnt; overriding function GetPosition(This : in Circle) return Vec2D is begin return This.Coords; end GetPosition; end Circles;
with TEXT_IO; with INFLECTIONS_PACKAGE; use INFLECTIONS_PACKAGE; with DICTIONARY_PACKAGE; use DICTIONARY_PACKAGE; package LIST_PACKAGE is -- SCROLL_LINE_NUMBER : INTEGER := 0; -- OUTPUT_SCROLL_COUNT : INTEGER := 0; -- procedure LIST_STEMS(OUTPUT : TEXT_IO.FILE_TYPE; RAW_WORD : STRING; INPUT_LINE : STRING; PA : in out PARSE_ARRAY; PA_LAST : in out INTEGER); procedure LIST_ENTRY(OUTPUT : TEXT_IO.FILE_TYPE; D_K : DICTIONARY_KIND; MN : DICT_IO.COUNT); procedure UNKNOWN_SEARCH(UNKNOWN : in STRING; UNKNOWN_COUNT : out DICT_IO.COUNT); procedure LIST_NEIGHBORHOOD(OUTPUT : TEXT_IO.FILE_TYPE; INPUT_WORD : STRING); end LIST_PACKAGE;
------------------------------------------------------------------------------ -- -- -- GNAT LIBRARY COMPONENTS -- -- -- -- G N A T . S E M A P H O R E S -- -- -- -- S p e c -- -- -- -- Copyright (C) 2003-2020, AdaCore -- -- -- -- 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 Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). -- -- -- ------------------------------------------------------------------------------ -- This package provides classic counting semaphores and binary semaphores. -- Both types are visibly defined as protected types so that users can make -- conditional and timed calls when appropriate. with System; package GNAT.Semaphores is Default_Ceiling : constant System.Priority := System.Default_Priority; -- A convenient value for the priority discriminants that follow ------------------------ -- Counting_Semaphore -- ------------------------ protected type Counting_Semaphore (Initial_Value : Natural; -- A counting semaphore contains an internal counter. The initial -- value of this counter is set by clients via the discriminant. Ceiling : System.Priority) -- Users must specify the ceiling priority for the object. If the -- Real-Time Systems Annex is not in use this value is not important. is pragma Priority (Ceiling); entry Seize; -- Blocks caller until/unless the semaphore's internal counter is -- greater than zero. Decrements the semaphore's internal counter when -- executed. procedure Release; -- Increments the semaphore's internal counter private Count : Natural := Initial_Value; end Counting_Semaphore; ---------------------- -- Binary_Semaphore -- ---------------------- protected type Binary_Semaphore (Initially_Available : Boolean; -- Binary semaphores are either available or not; there is no internal -- count involved. The discriminant value determines whether the -- individual object is initially available. Ceiling : System.Priority) -- Users must specify the ceiling priority for the object. If the -- Real-Time Systems Annex is not in use this value is not important. is pragma Priority (Ceiling); entry Seize; -- Blocks the caller unless/until semaphore is available. After -- execution the semaphore is no longer available. procedure Release; -- Makes the semaphore available private Available : Boolean := Initially_Available; end Binary_Semaphore; end GNAT.Semaphores;
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- package body Program.Units is ----------------- -- Compilation -- ----------------- overriding function Compilation (Self : access Unit) return Program.Compilations.Compilation_Access is begin return Self.Compilation; end Compilation; ----------------------------- -- Context_Clause_Elements -- ----------------------------- overriding function Context_Clause_Elements (Self : access Unit) return Program.Element_Vectors.Element_Vector_Access is begin return Self.Context_Clause; end Context_Clause_Elements; --------------- -- Full_Name -- --------------- overriding function Full_Name (Self : access Unit) return Text is begin return Ada.Strings.Wide_Wide_Unbounded.To_Wide_Wide_String (Self.Full_Name); end Full_Name; ---------------- -- Initialize -- ---------------- procedure Initialize (Self : in out Unit'Class; Compilation : Program.Compilations.Compilation_Access; Full_Name : Text; Context_Clause : Program.Element_Vectors.Element_Vector_Access; Unit_Declaration : not null Program.Elements.Element_Access) is begin Self.Compilation := Compilation; Self.Full_Name := Ada.Strings.Wide_Wide_Unbounded.To_Unbounded_Wide_Wide_String (Full_Name); Self.Context_Clause := Context_Clause; Self.Unit_Declaration := Unit_Declaration; end Initialize; ---------------------- -- Unit_Declaration -- ---------------------- overriding function Unit_Declaration (Self : access Unit) return not null Program.Elements.Element_Access is begin return Self.Unit_Declaration; end Unit_Declaration; ------------------------------- -- Is_Library_Unit_Body_Unit -- ------------------------------- overriding function Is_Library_Unit_Body_Unit (Self : Unit) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Library_Unit_Body_Unit; -------------------------- -- Is_Library_Item_Unit -- -------------------------- overriding function Is_Library_Item_Unit (Self : Unit) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Library_Item_Unit; -------------------------------------- -- Is_Library_Unit_Declaration_Unit -- -------------------------------------- overriding function Is_Library_Unit_Declaration_Unit (Self : Unit) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Library_Unit_Declaration_Unit; --------------------- -- Is_Subunit_Unit -- --------------------- overriding function Is_Subunit_Unit (Self : Unit) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Subunit_Unit; end Program.Units;
-------------------------------------------------------------------- --| Package : TileADT Version : -------------------------------------------------------------------- --| Abstract : Provides an ADT for a TILE in the Mahjongg game. -------------------------------------------------------------------- --| Compiler/System : IBM AIX/Ada 6000 --| Author : John Dalbey Date : 1/93 --| References : -------------------------------------------------------------------- --| NOTES : --| : --| Version History : -------------------------------------------------------------------- PACKAGE TileADT IS TYPE Tile IS PRIVATE; TYPE TilePair is record Alpha: Tile; Bravo: Tile; end record; RowBound : Constant INTEGER := 9; ColBound : Constant CHARACTER := 'O'; LayerBound : Constant INTEGER := 5; SUBTYPE Row is INTEGER RANGE 1 .. RowBound; -- Row Positions SUBTYPE Col is CHARACTER RANGE 'A' .. ColBound; -- Column positions SUBTYPE Layer is INTEGER RANGE 1 .. LayerBound; -- Layers high --(1 is bottom, 5 is top) SUBTYPE TileValue is INTEGER RANGE -1 .. 42; -- Legal tile values FUNCTION Create (TheCol: Col; TheRow : Row; TheLayer : Layer) RETURN TILE; -- Assumes : TheCol, TheRow, TheLayer have values. -- Uses : TheRow indicates which row on the board. -- TheCol indicates which column on the board. -- TheLayer indicates which layer on the board. -- Results : A Tile is created and assigned a position TheCol,TheRow,TheLayer. PROCEDURE SetValue (TheTile : IN OUT Tile; Value : TileValue); -- Assumes : nothing (though it makes sense that it have been created). -- Uses : TheTile and Value -- Results : TheTile is assigned Value FUNCTION GetValue (TheTile : Tile) RETURN TileValue; -- Assumes : TheTile has a value -- Uses : TheTile -- Results : Returns the current value of TheTile. FUNCTION GetLayer (TheTile : Tile) RETURN Layer; -- Assumes : TheTile has a value -- Uses : TheTile -- Results : Returns TheTile's layer. FUNCTION GetRow (TheTile : Tile) RETURN Row; -- Assumes : TheTile has a value -- Uses : TheTile -- Results : Returns TheTile's Row. FUNCTION GetCol (TheTile : Tile) RETURN Col; -- Assumes : TheTile has a value -- Uses : TheTile -- Results : Returns TheTile's Col. FUNCTION IsMatch (Tile1, Tile2 : Tile) RETURN BOOLEAN; -- Assumes : Tile1, Tile2 have values. -- Uses : Tile1, Tile2. -- Results : Returns TRUE if Tile1 has the same value as Tile2, FALSE otherwise. -- Notes : TRUE only on exact match. Doesn't deal with seasons or other -- "suit" type tiles. PRIVATE TYPE Tile is RECORD Col_Pos : Col; Row_Pos : Row; Layer_Pos: Layer; Value : TileValue; END RECORD; END TileADT;
package body openGL.Program.textured is overriding procedure set_Uniforms (Self : in Item) is scale_Uniform : constant Variable.uniform.vec3 := Self.uniform_Variable ("uScale"); begin Self.set_mvp_Uniform; scale_Uniform.Value_is (Self.Scale); end set_Uniforms; end openGL.Program.textured;
with STM32_SVD.Interrupts; use STM32_SVD.Interrupts; with STM32_SVD.EXTI; package STM32GD.EXTI.IRQ is protected IRQ_Handler is entry Wait; procedure Cancel; function Status (Line : External_Line_Number) return Boolean; procedure Reset_Status (Line : External_Line_Number); procedure Handler; pragma Attach_Handler (Handler, EXTI0_1); pragma Attach_Handler (Handler, EXTI2_3); pragma Attach_Handler (Handler, EXTI4_15); private EXTI_Status : STM32_SVD.EXTI.PR_Field; Cancelled : Boolean; Triggered : Boolean; end IRQ_Handler; end STM32GD.EXTI.IRQ;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M _ U T I L -- -- -- -- S p e c -- -- -- -- Copyright (C) 1992-2016, Free Software Foundation, Inc. -- -- -- -- 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 Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT 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 GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Package containing utility procedures used throughout the semantics with Einfo; use Einfo; with Exp_Tss; use Exp_Tss; with Namet; use Namet; with Opt; use Opt; with Snames; use Snames; with Types; use Types; with Uintp; use Uintp; with Urealp; use Urealp; package Sem_Util is function Abstract_Interface_List (Typ : Entity_Id) return List_Id; -- Given a type that implements interfaces look for its associated -- definition node and return its list of interfaces. procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id); -- Add A to the list of access types to process when expanding the -- freeze node of E. procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id); -- Given a block statement N, generate an internal E_Block label and make -- it the identifier of the block. Id denotes the generated entity. If the -- block already has an identifier, Id returns the entity of its label. procedure Add_Global_Declaration (N : Node_Id); -- These procedures adds a declaration N at the library level, to be -- elaborated before any other code in the unit. It is used for example -- for the entity that marks whether a unit has been elaborated. The -- declaration is added to the Declarations list of the Aux_Decls_Node -- for the current unit. The declarations are added in the current scope, -- so the caller should push a new scope as required before the call. function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id; -- Returns the name of E adding Suffix function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean; -- Given two types, returns True if we are in Allow_Integer_Address mode -- and one of the types is (a descendant of) System.Address (and this type -- is private), and the other type is any integer type. function Address_Value (N : Node_Id) return Node_Id; -- Return the underlying value of the expression N of an address clause function Addressable (V : Uint) return Boolean; function Addressable (V : Int) return Boolean; pragma Inline (Addressable); -- Returns True if the value of V is the word size or an addressable factor -- of the word size (typically 8, 16, 32 or 64). procedure Aggregate_Constraint_Checks (Exp : Node_Id; Check_Typ : Entity_Id); -- Checks expression Exp against subtype Check_Typ. If Exp is an aggregate -- and Check_Typ a constrained record type with discriminants, we generate -- the appropriate discriminant checks. If Exp is an array aggregate then -- emit the appropriate length checks. If Exp is a scalar type, or a string -- literal, Exp is changed into Check_Typ'(Exp) to ensure that range checks -- are performed at run time. Also used for expressions in the argument of -- 'Update, which shares some of the features of an aggregate. function Alignment_In_Bits (E : Entity_Id) return Uint; -- If the alignment of the type or object E is currently known to the -- compiler, then this function returns the alignment value in bits. -- Otherwise Uint_0 is returned, indicating that the alignment of the -- entity is not yet known to the compiler. function All_Composite_Constraints_Static (Constr : Node_Id) return Boolean; -- Used to implement pragma Restrictions (No_Dynamic_Sized_Objects). -- Given a constraint or subtree of a constraint on a composite -- subtype/object, returns True if there are no nonstatic constraints, -- which might cause objects to be created with dynamic size. -- Called for subtype declarations (including implicit ones created for -- subtype indications in object declarations, as well as discriminated -- record aggregate cases). For record aggregates, only records containing -- discriminant-dependent arrays matter, because the discriminants must be -- static when governing a variant part. Access discriminants are -- irrelevant. Also called for array aggregates, but only named notation, -- because those are the only dynamic cases. procedure Append_Inherited_Subprogram (S : Entity_Id); -- If the parent of the operation is declared in the visible part of -- the current scope, the inherited operation is visible even though the -- derived type that inherits the operation may be completed in the private -- part of the current package. procedure Apply_Compile_Time_Constraint_Error (N : Node_Id; Msg : String; Reason : RT_Exception_Code; Ent : Entity_Id := Empty; Typ : Entity_Id := Empty; Loc : Source_Ptr := No_Location; Rep : Boolean := True; Warn : Boolean := False); -- N is a subexpression which will raise constraint error when evaluated -- at runtime. Msg is a message that explains the reason for raising the -- exception. The last character is ? if the message is always a warning, -- even in Ada 95, and is not a ? if the message represents an illegality -- (because of violation of static expression rules) in Ada 95 (but not -- in Ada 83). Typically this routine posts all messages at the Sloc of -- node N. However, if Loc /= No_Location, Loc is the Sloc used to output -- the message. After posting the appropriate message, and if the flag -- Rep is set, this routine replaces the expression with an appropriate -- N_Raise_Constraint_Error node using the given Reason code. This node -- is then marked as being static if the original node is static, but -- sets the flag Raises_Constraint_Error, preventing further evaluation. -- The error message may contain a } or & insertion character. This -- normally references Etype (N), unless the Ent argument is given -- explicitly, in which case it is used instead. The type of the raise -- node that is built is normally Etype (N), but if the Typ parameter -- is present, this is used instead. Warn is normally False. If it is -- True then the message is treated as a warning even though it does -- not end with a ? (this is used when the caller wants to parameterize -- whether an error or warning is given), or when the message should be -- treated as a warning even when SPARK_Mode is On (which otherwise would -- force an error). function Async_Readers_Enabled (Id : Entity_Id) return Boolean; -- Given the entity of an abstract state or a variable, determine whether -- Id is subject to external property Async_Readers and if it is, the -- related expression evaluates to True. function Async_Writers_Enabled (Id : Entity_Id) return Boolean; -- Given the entity of an abstract state or a variable, determine whether -- Id is subject to external property Async_Writers and if it is, the -- related expression evaluates to True. function Available_Full_View_Of_Component (T : Entity_Id) return Boolean; -- If at the point of declaration an array type has a private or limited -- component, several array operations are not available on the type, and -- the array type is flagged accordingly. If in the immediate scope of -- the array type the component becomes non-private or non-limited, these -- operations become available. This can happen if the scopes of both types -- are open, and the scope of the array is not outside the scope of the -- component. procedure Bad_Attribute (N : Node_Id; Nam : Name_Id; Warn : Boolean := False); -- Called when node N is expected to contain a valid attribute name, and -- Nam is found instead. If Warn is set True this is a warning, else this -- is an error. procedure Bad_Predicated_Subtype_Use (Msg : String; N : Node_Id; Typ : Entity_Id; Suggest_Static : Boolean := False); -- This is called when Typ, a predicated subtype, is used in a context -- which does not allow the use of a predicated subtype. Msg is passed to -- Error_Msg_FE to output an appropriate message using N as the location, -- and Typ as the entity. The caller must set up any insertions other than -- the & for the type itself. Note that if Typ is a generic actual type, -- then the message will be output as a warning, and a raise Program_Error -- is inserted using Insert_Action with node N as the insertion point. Node -- N also supplies the source location for construction of the raise node. -- If Typ does not have any predicates, the call has no effect. Set flag -- Suggest_Static when the context warrants an advice on how to avoid the -- use error. function Bad_Unordered_Enumeration_Reference (N : Node_Id; T : Entity_Id) return Boolean; -- Node N contains a potentially dubious reference to type T, either an -- explicit comparison, or an explicit range. This function returns True -- if the type T is an enumeration type for which No pragma Order has been -- given, and the reference N is not in the same extended source unit as -- the declaration of T. function Build_Actual_Subtype (T : Entity_Id; N : Node_Or_Entity_Id) return Node_Id; -- Build an anonymous subtype for an entity or expression, using the -- bounds of the entity or the discriminants of the enclosing record. -- T is the type for which the actual subtype is required, and N is either -- a defining identifier, or any subexpression. function Build_Actual_Subtype_Of_Component (T : Entity_Id; N : Node_Id) return Node_Id; -- Determine whether a selected component has a type that depends on -- discriminants, and build actual subtype for it if so. function Build_Default_Subtype (T : Entity_Id; N : Node_Id) return Entity_Id; -- If T is an unconstrained type with defaulted discriminants, build a -- subtype constrained by the default values, insert the subtype -- declaration in the tree before N, and return the entity of that -- subtype. Otherwise, simply return T. function Build_Discriminal_Subtype_Of_Component (T : Entity_Id) return Node_Id; -- Determine whether a record component has a type that depends on -- discriminants, and build actual subtype for it if so. procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id); -- Given a compilation unit node N, allocate an elaboration counter for -- the compilation unit, and install it in the Elaboration_Entity field -- of Spec_Id, the entity for the compilation unit. procedure Build_Explicit_Dereference (Expr : Node_Id; Disc : Entity_Id); -- AI05-139: Names with implicit dereference. If the expression N is a -- reference type and the context imposes the corresponding designated -- type, convert N into N.Disc.all. Such expressions are always over- -- loaded with both interpretations, and the dereference interpretation -- carries the name of the reference discriminant. function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean; -- Returns True if the expression cannot possibly raise Constraint_Error. -- The response is conservative in the sense that a result of False does -- not necessarily mean that CE could be raised, but a response of True -- means that for sure CE cannot be raised. procedure Check_Dynamically_Tagged_Expression (Expr : Node_Id; Typ : Entity_Id; Related_Nod : Node_Id); -- Check wrong use of dynamically tagged expression procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id); -- Verify that the full declaration of type T has been seen. If not, place -- error message on node N. Used in object declarations, type conversions -- and qualified expressions. procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id); -- A subprogram that has an Address parameter and is declared in a Pure -- package is not considered Pure, because the parameter may be used as a -- pointer and the referenced data may change even if the address value -- itself does not. -- If the programmer gave an explicit Pure_Function pragma, then we respect -- the pragma and leave the subprogram Pure. procedure Check_Function_Writable_Actuals (N : Node_Id); -- (Ada 2012): If the construct N has two or more direct constituents that -- are names or expressions whose evaluation may occur in an arbitrary -- order, at least one of which contains a function call with an in out or -- out parameter, then the construct is legal only if: for each name that -- is passed as a parameter of mode in out or out to some inner function -- call C2 (not including the construct N itself), there is no other name -- anywhere within a direct constituent of the construct C other than -- the one containing C2, that is known to refer to the same object (RM -- 6.4.1(6.17/3)). procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id); -- AI05-139-2: Accessors and iterators for containers. This procedure -- checks whether T is a reference type, and if so it adds an interprettion -- to N whose type is the designated type of the reference_discriminant. -- If N is a generalized indexing operation, the interpretation is added -- both to the corresponding function call, and to the indexing node. procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id); -- Within a protected function, the current object is a constant, and -- internal calls to a procedure or entry are illegal. Similarly, other -- uses of a protected procedure in a renaming or a generic instantiation -- in the context of a protected function are illegal (AI05-0225). procedure Check_Later_Vs_Basic_Declarations (Decls : List_Id; During_Parsing : Boolean); -- If During_Parsing is True, check for misplacement of later vs basic -- declarations in Ada 83. If During_Parsing is False, and the SPARK -- restriction is set, do the same: although SPARK 95 removes the -- distinction between initial and later declarative items, the distinction -- remains in the Examiner (JB01-005). Note that the Examiner does not -- count package declarations in later declarative items. procedure Check_No_Hidden_State (Id : Entity_Id); -- Determine whether object or state Id introduces a hidden state. If this -- is the case, emit an error. procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id); -- Verify that the profile of nonvolatile function Func_Id does not contain -- effectively volatile parameters or return type. procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id); -- Verify the legality of reference Ref to variable Var_Id when the -- variable is a constituent of a single protected/task type. procedure Check_Potentially_Blocking_Operation (N : Node_Id); -- N is one of the statement forms that is a potentially blocking -- operation. If it appears within a protected action, emit warning. procedure Check_Result_And_Post_State (Subp_Id : Entity_Id); -- Determine whether the contract of subprogram Subp_Id mentions attribute -- 'Result and it contains an expression that evaluates differently in pre- -- and post-state. procedure Check_State_Refinements (Context : Node_Id; Is_Main_Unit : Boolean := False); -- Verify that all abstract states declared in a block statement, entry -- body, package body, protected body, subprogram body, task body, or a -- package declaration denoted by Context have proper refinement. Emit an -- error if this is not the case. Flag Is_Main_Unit should be set when -- Context denotes the main compilation unit. procedure Check_Unused_Body_States (Body_Id : Entity_Id); -- Verify that all abstract states and objects declared in the state space -- of package body Body_Id are used as constituents. Emit an error if this -- is not the case. procedure Check_Unprotected_Access (Context : Node_Id; Expr : Node_Id); -- Check whether the expression is a pointer to a protected component, -- and the context is external to the protected operation, to warn against -- a possible unlocked access to data. function Choice_List (N : Node_Id) return List_Id; -- Utility to retrieve the choices of a Component_Association or the -- Discrete_Choices of an Iterated_Component_Association. For various -- reasons these nodes have a different structure even though they play -- similar roles in array aggregates. function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id; -- Gather the entities of all abstract states and objects declared in the -- body state space of package body Body_Id. procedure Collect_Interfaces (T : Entity_Id; Ifaces_List : out Elist_Id; Exclude_Parents : Boolean := False; Use_Full_View : Boolean := True); -- Ada 2005 (AI-251): Collect whole list of abstract interfaces that are -- directly or indirectly implemented by T. Exclude_Parents is used to -- avoid the addition of inherited interfaces to the generated list. -- Use_Full_View is used to collect the interfaces using the full-view -- (if available). procedure Collect_Interface_Components (Tagged_Type : Entity_Id; Components_List : out Elist_Id); -- Ada 2005 (AI-251): Collect all the tag components associated with the -- secondary dispatch tables of a tagged type. procedure Collect_Interfaces_Info (T : Entity_Id; Ifaces_List : out Elist_Id; Components_List : out Elist_Id; Tags_List : out Elist_Id); -- Ada 2005 (AI-251): Collect all the interfaces associated with T plus -- the record component and tag associated with each of these interfaces. -- On exit Ifaces_List, Components_List and Tags_List have the same number -- of elements, and elements at the same position on these tables provide -- information on the same interface type. procedure Collect_Parents (T : Entity_Id; List : out Elist_Id; Use_Full_View : Boolean := True); -- Collect all the parents of Typ. Use_Full_View is used to collect them -- using the full-view of private parents (if available). function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id; -- Called upon type derivation and extension. We scan the declarative part -- in which the type appears, and collect subprograms that have one -- subsidiary subtype of the type. These subprograms can only appear after -- the type itself. function Compile_Time_Constraint_Error (N : Node_Id; Msg : String; Ent : Entity_Id := Empty; Loc : Source_Ptr := No_Location; Warn : Boolean := False) return Node_Id; -- This is similar to Apply_Compile_Time_Constraint_Error in that it -- generates a warning (or error) message in the same manner, but it does -- not replace any nodes. For convenience, the function always returns its -- first argument. The message is a warning if the message ends with ?, or -- we are operating in Ada 83 mode, or the Warn parameter is set to True. procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id); -- Sets the Has_Delayed_Freeze flag of New if the Delayed_Freeze flag of -- Old is set and Old has no yet been Frozen (i.e. Is_Frozen is false). function Contains_Refined_State (Prag : Node_Id) return Boolean; -- Determine whether pragma Prag contains a reference to the entity of an -- abstract state with a visible refinement. Prag must denote one of the -- following pragmas: -- Depends -- Global function Copy_Component_List (R_Typ : Entity_Id; Loc : Source_Ptr) return List_Id; -- Copy components from record type R_Typ that come from source. Used to -- create a new compatible record type. Loc is the source location assigned -- to the created nodes. function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id; -- Utility to create a parameter profile for a new subprogram spec, when -- the subprogram has a body that acts as spec. This is done for some cases -- of inlining, and for private protected ops. Also used to create bodies -- for stubbed subprograms. procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id); -- Copy the SPARK_Mode aspect if present in the aspect specifications -- of node From to node To. On entry it is assumed that To does not have -- aspect specifications. If From has no aspects, the routine has no -- effect. function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id; -- Replicate a function or a procedure specification denoted by Spec. The -- resulting tree is an exact duplicate of the original tree. New entities -- are created for the unit name and the formal parameters. function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id; -- If a type is a generic actual type, return the corresponding formal in -- the generic parent unit. There is no direct link in the tree for this -- attribute, except in the case of formal private and derived types. -- Possible optimization??? function Current_Entity (N : Node_Id) return Entity_Id; pragma Inline (Current_Entity); -- Find the currently visible definition for a given identifier, that is to -- say the first entry in the visibility chain for the Chars of N. function Current_Entity_In_Scope (N : Node_Id) return Entity_Id; -- Find whether there is a previous definition for identifier N in the -- current scope. Because declarations for a scope are not necessarily -- contiguous (e.g. for packages) the first entry on the visibility chain -- for N is not necessarily in the current scope. function Current_Scope return Entity_Id; -- Get entity representing current scope function Current_Scope_No_Loops return Entity_Id; -- Return the current scope ignoring internally generated loops function Current_Subprogram return Entity_Id; -- Returns current enclosing subprogram. If Current_Scope is a subprogram, -- then that is what is returned, otherwise the Enclosing_Subprogram of the -- Current_Scope is returned. The returned value is Empty if this is called -- from a library package which is not within any subprogram. function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint; -- Same as Type_Access_Level, except that if the type is the type of an Ada -- 2012 stand-alone object of an anonymous access type, then return the -- static accesssibility level of the object. In that case, the dynamic -- accessibility level of the object may take on values in a range. The low -- bound of that range is returned by Type_Access_Level; this function -- yields the high bound of that range. Also differs from Type_Access_Level -- in the case of a descendant of a generic formal type (returns Int'Last -- instead of 0). function Defining_Entity (N : Node_Id; Empty_On_Errors : Boolean := False) return Entity_Id; -- Given a declaration N, returns the associated defining entity. If the -- declaration has a specification, the entity is obtained from the -- specification. If the declaration has a defining unit name, then the -- defining entity is obtained from the defining unit name ignoring any -- child unit prefixes. -- -- Iterator loops also have a defining entity, which holds the list of -- local entities declared during loop expansion. These entities need -- debugging information, generated through Qualify_Entity_Names, and -- the loop declaration must be placed in the table Name_Qualify_Units. -- -- Set flag Empty_On_Error to change the behavior of this routine as -- follows: -- -- * True - A declaration that lacks a defining entity returns Empty. -- A node that does not allow for a defining entity returns Empty. -- -- * False - A declaration that lacks a defining entity is given a new -- internally generated entity which is subsequently returned. A node -- that does not allow for a defining entity raises Program_Error. -- -- The former semantics is appropriate for the back end; the latter -- semantics is appropriate for the front end. function Denotes_Discriminant (N : Node_Id; Check_Concurrent : Boolean := False) return Boolean; -- Returns True if node N is an Entity_Name node for a discriminant. If the -- flag Check_Concurrent is true, function also returns true when N denotes -- the discriminal of the discriminant of a concurrent type. This is needed -- to disable some optimizations on private components of protected types, -- and constraint checks on entry families constrained by discriminants. function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean; -- Detect suspicious overlapping between actuals in a call, when both are -- writable (RM 2012 6.4.1(6.4/3)) function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean; -- Functions to detect suspicious overlapping between actuals in a call, -- when one of them is writable. The predicates are those proposed in -- AI05-0144, to detect dangerous order dependence in complex calls. -- I would add a parameter Warn which enables more extensive testing of -- cases as we find appropriate when we are only warning ??? Or perhaps -- return an indication of (Error, Warn, OK) ??? function Denotes_Variable (N : Node_Id) return Boolean; -- Returns True if node N denotes a single variable without parentheses function Depends_On_Discriminant (N : Node_Id) return Boolean; -- Returns True if N denotes a discriminant or if N is a range, a subtype -- indication or a scalar subtype where one of the bounds is a -- discriminant. function Designate_Same_Unit (Name1 : Node_Id; Name2 : Node_Id) return Boolean; -- Returns True if Name1 and Name2 designate the same unit name; each of -- these names is supposed to be a selected component name, an expanded -- name, a defining program unit name or an identifier. function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id; -- Expr should be an expression of an access type. Builds an integer -- literal except in cases involving anonymous access types where -- accessibility levels are tracked at runtime (access parameters and Ada -- 2012 stand-alone objects). function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id; -- Same as Einfo.Extra_Accessibility except thtat object renames -- are looked through. function Effective_Reads_Enabled (Id : Entity_Id) return Boolean; -- Given the entity of an abstract state or a variable, determine whether -- Id is subject to external property Effective_Reads and if it is, the -- related expression evaluates to True. function Effective_Writes_Enabled (Id : Entity_Id) return Boolean; -- Given the entity of an abstract state or a variable, determine whether -- Id is subject to external property Effective_Writes and if it is, the -- related expression evaluates to True. function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id; -- Returns the enclosing N_Compilation_Unit node that is the root of a -- subtree containing N. function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id; -- Returns the closest ancestor of Typ that is a CPP type. function Enclosing_Declaration (N : Node_Id) return Node_Id; -- Returns the declaration node enclosing N (including possibly N itself), -- if any, or Empty otherwise. function Enclosing_Generic_Body (N : Node_Id) return Node_Id; -- Returns the Node_Id associated with the innermost enclosing generic -- body, if any. If none, then returns Empty. function Enclosing_Generic_Unit (N : Node_Id) return Node_Id; -- Returns the Node_Id associated with the innermost enclosing generic -- unit, if any. If none, then returns Empty. function Enclosing_Lib_Unit_Entity (E : Entity_Id := Current_Scope) return Entity_Id; -- Returns the entity of enclosing library unit node which is the root of -- the current scope (which must not be Standard_Standard, and the caller -- is responsible for ensuring this condition) or other specified entity. function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id; -- Returns the N_Compilation_Unit node of the library unit that is directly -- or indirectly (through a subunit) at the root of a subtree containing -- N. This may be either the same as Enclosing_Comp_Unit_Node, or if -- Enclosing_Comp_Unit_Node returns a subunit, then the corresponding -- library unit. If no such item is found, returns Empty. function Enclosing_Package (E : Entity_Id) return Entity_Id; -- Utility function to return the Ada entity of the package enclosing -- the entity E, if any. Returns Empty if no enclosing package. function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id; -- Returns the entity of the package or subprogram enclosing E, if any. -- Returns Empty if no enclosing package or subprogram. function Enclosing_Subprogram (E : Entity_Id) return Entity_Id; -- Utility function to return the Ada entity of the subprogram enclosing -- the entity E, if any. Returns Empty if no enclosing subprogram. procedure Ensure_Freeze_Node (E : Entity_Id); -- Make sure a freeze node is allocated for entity E. If necessary, build -- and initialize a new freeze node and set Has_Delayed_Freeze True for E. procedure Enter_Name (Def_Id : Entity_Id); -- Insert new name in symbol table of current scope with check for -- duplications (error message is issued if a conflict is found). -- Note: Enter_Name is not used for overloadable entities, instead these -- are entered using Sem_Ch6.Enter_Overloadable_Entity. function Entity_Of (N : Node_Id) return Entity_Id; -- Return the entity of N or Empty. If N is a renaming, return the entity -- of the root renamed object. procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id); -- This procedure is called after issuing a message complaining about an -- inappropriate use of limited type T. If useful, it adds additional -- continuation lines to the message explaining why type T is limited. -- Messages are placed at node N. function Expression_Of_Expression_Function (Subp : Entity_Id) return Node_Id; -- Return the expression of expression function Subp type Extensions_Visible_Mode is (Extensions_Visible_None, -- Extensions_Visible does not yield a mode when SPARK_Mode is off. This -- value acts as a default in a non-SPARK compilation. Extensions_Visible_False, -- A value of "False" signifies that Extensions_Visible is either -- missing or the pragma is present and the value of its Boolean -- expression is False. Extensions_Visible_True); -- A value of "True" signifies that Extensions_Visible is present and -- the value of its Boolean expression is True. function Extensions_Visible_Status (Id : Entity_Id) return Extensions_Visible_Mode; -- Given the entity of a subprogram or formal parameter subject to pragma -- Extensions_Visible, return the Boolean value denoted by the expression -- of the pragma. procedure Find_Actual (N : Node_Id; Formal : out Entity_Id; Call : out Node_Id); -- Determines if the node N is an actual parameter of a function or a -- procedure call. If so, then Formal points to the entity for the formal -- (Ekind is E_In_Parameter, E_Out_Parameter, or E_In_Out_Parameter) and -- Call is set to the node for the corresponding call. If the node N is not -- an actual parameter then Formal and Call are set to Empty. function Find_Specific_Type (CW : Entity_Id) return Entity_Id; -- Find specific type of a class-wide type, and handle the case of an -- incomplete type coming either from a limited_with clause or from an -- incomplete type declaration. If resulting type is private return its -- full view. function Find_Body_Discriminal (Spec_Discriminant : Entity_Id) return Entity_Id; -- Given a discriminant of the record type that implements a task or -- protected type, return the discriminal of the corresponding discriminant -- of the actual concurrent type. function Find_Corresponding_Discriminant (Id : Node_Id; Typ : Entity_Id) return Entity_Id; -- Because discriminants may have different names in a generic unit and in -- an instance, they are resolved positionally when possible. A reference -- to a discriminant carries the discriminant that it denotes when it is -- analyzed. Subsequent uses of this id on a different type denotes the -- discriminant at the same position in this new type. function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id; -- Given an arbitrary entity, try to find the nearest enclosing iterator -- loop. If such a loop is found, return the entity of its identifier (the -- E_Loop scope), otherwise return Empty. function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id; -- Find the nested loop statement in a conditional block. Loops subject to -- attribute 'Loop_Entry are transformed into blocks. Parts of the original -- loop are nested within the block. procedure Find_Overlaid_Entity (N : Node_Id; Ent : out Entity_Id; Off : out Boolean); -- The node N should be an address representation clause. Determines if -- the target expression is the address of an entity with an optional -- offset. If so, set Ent to the entity and, if there is an offset, set -- Off to True, otherwise to False. If N is not an address representation -- clause, or if it is not possible to determine that the address is of -- this form, then set Ent to Empty. function Find_Parameter_Type (Param : Node_Id) return Entity_Id; -- Return the type of formal parameter Param as determined by its -- specification. -- The following type describes the placement of an arbitrary entity with -- respect to SPARK visible / hidden state space. type State_Space_Kind is (Not_In_Package, -- An entity is not in the visible, private or body state space when -- the immediate enclosing construct is not a package. Visible_State_Space, -- An entity is in the visible state space when it appears immediately -- within the visible declarations of a package or when it appears in -- the visible state space of a nested package which in turn is declared -- in the visible declarations of an enclosing package: -- package Pack is -- Visible_Variable : ... -- package Nested -- with Abstract_State => Visible_State -- is -- Visible_Nested_Variable : ... -- end Nested; -- end Pack; -- Entities associated with a package instantiation inherit the state -- space from the instance placement: -- generic -- package Gen is -- Generic_Variable : ... -- end Gen; -- with Gen; -- package Pack is -- package Inst is new Gen; -- -- Generic_Variable is in the visible state space of Pack -- end Pack; Private_State_Space, -- An entity is in the private state space when it appears immediately -- within the private declarations of a package or when it appears in -- the visible state space of a nested package which in turn is declared -- in the private declarations of an enclosing package: -- package Pack is -- private -- Private_Variable : ... -- package Nested -- with Abstract_State => Private_State -- is -- Private_Nested_Variable : ... -- end Nested; -- end Pack; -- The same placement principle applies to package instantiations Body_State_Space); -- An entity is in the body state space when it appears immediately -- within the declarations of a package body or when it appears in the -- visible state space of a nested package which in turn is declared in -- the declarations of an enclosing package body: -- package body Pack is -- Body_Variable : ... -- package Nested -- with Abstract_State => Body_State -- is -- Body_Nested_Variable : ... -- end Nested; -- end Pack; -- The same placement principle applies to package instantiations procedure Find_Placement_In_State_Space (Item_Id : Entity_Id; Placement : out State_Space_Kind; Pack_Id : out Entity_Id); -- Determine the state space placement of an item. Item_Id denotes the -- entity of an abstract state, object or package instantiation. Placement -- captures the precise placement of the item in the enclosing state space. -- If the state space is that of a package, Pack_Id denotes its entity, -- otherwise Pack_Id is Empty. function Find_Static_Alternative (N : Node_Id) return Node_Id; -- N is a case statement whose expression is a compile-time value. -- Determine the alternative chosen, so that the code of non-selected -- alternatives, and the warnings that may apply to them, are removed. function First_Actual (Node : Node_Id) return Node_Id; -- Node is an N_Function_Call, N_Procedure_Call_Statement or -- N_Entry_Call_Statement node. The result returned is the first actual -- parameter in declaration order (not the order of parameters as they -- appeared in the source, which can be quite different as a result of the -- use of named parameters). Empty is returned for a call with no -- parameters. The procedure for iterating through the actuals in -- declaration order is to use this function to find the first actual, and -- then use Next_Actual to obtain the next actual in declaration order. -- Note that the value returned is always the expression (not the -- N_Parameter_Association nodes, even if named association is used). function Fix_Msg (Id : Entity_Id; Msg : String) return String; -- Replace all occurrences of a particular word in string Msg depending on -- the Ekind of Id as follows: -- * Replace "subprogram" with -- - "entry" when Id is an entry [family] -- - "task type" when Id is a single task object, task type or task -- body. -- * Replace "protected" with -- - "task" when Id is a single task object, task type or task body -- All other non-matching words remain as is procedure Gather_Components (Typ : Entity_Id; Comp_List : Node_Id; Governed_By : List_Id; Into : Elist_Id; Report_Errors : out Boolean); -- The purpose of this procedure is to gather the valid components in a -- record type according to the values of its discriminants, in order to -- validate the components of a record aggregate. -- -- Typ is the type of the aggregate when its constrained discriminants -- need to be collected, otherwise it is Empty. -- -- Comp_List is an N_Component_List node. -- -- Governed_By is a list of N_Component_Association nodes, where each -- choice list contains the name of a discriminant and the expression -- field gives its value. The values of the discriminants governing -- the (possibly nested) variant parts in Comp_List are found in this -- Component_Association List. -- -- Into is the list where the valid components are appended. Note that -- Into need not be an Empty list. If it's not, components are attached -- to its tail. -- -- Report_Errors is set to True if the values of the discriminants are -- non-static. -- -- This procedure is also used when building a record subtype. If the -- discriminant constraint of the subtype is static, the components of the -- subtype are only those of the variants selected by the values of the -- discriminants. Otherwise all components of the parent must be included -- in the subtype for semantic analysis. function Get_Actual_Subtype (N : Node_Id) return Entity_Id; -- Given a node for an expression, obtain the actual subtype of the -- expression. In the case of a parameter where the formal is an -- unconstrained array or discriminated type, this will be the previously -- constructed subtype of the actual. Note that this is not quite the -- "Actual Subtype" of the RM, since it is always a constrained type, i.e. -- it is the subtype of the value of the actual. The actual subtype is also -- returned in other cases where it has already been constructed for an -- object. Otherwise the expression type is returned unchanged, except for -- the case of an unconstrained array type, where an actual subtype is -- created, using Insert_Actions if necessary to insert any associated -- actions. function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id; -- This is like Get_Actual_Subtype, except that it never constructs an -- actual subtype. If an actual subtype is already available, i.e. the -- Actual_Subtype field of the corresponding entity is set, then it is -- returned. Otherwise the Etype of the node is returned. function Get_Body_From_Stub (N : Node_Id) return Node_Id; -- Return the body node for a stub function Get_Cursor_Type (Aspect : Node_Id; Typ : Entity_Id) return Entity_Id; -- Find Cursor type in scope of type Typ with Iterable aspect, by locating -- primitive operation First. For use in resolving the other primitive -- operations of an Iterable type and expanding loops and quantified -- expressions over formal containers. function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id; -- Find Cursor type in scope of type Typ with Iterable aspect, by locating -- primitive operation First. For use after resolving the primitive -- operations of an Iterable type. function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id; -- This is used to construct the string literal node representing a -- default external name, i.e. one that is constructed from the name of an -- entity, or (in the case of extended DEC import/export pragmas, an -- identifier provided as the external name. Letters in the name are -- according to the setting of Opt.External_Name_Default_Casing. function Get_Enclosing_Object (N : Node_Id) return Entity_Id; -- If expression N references a part of an object, return this object. -- Otherwise return Empty. Expression N should have been resolved already. function Get_Generic_Entity (N : Node_Id) return Entity_Id; -- Returns the true generic entity in an instantiation. If the name in the -- instantiation is a renaming, the function returns the renamed generic. function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id; -- Implements the notion introduced ever-so briefly in RM 7.3.1 (5.2/3): -- in a child unit a derived type is within the derivation class of an -- ancestor declared in a parent unit, even if there is an intermediate -- derivation that does not see the full view of that ancestor. procedure Get_Index_Bounds (N : Node_Id; L : out Node_Id; H : out Node_Id; Use_Full_View : Boolean := False); -- This procedure assigns to L and H respectively the values of the low and -- high bounds of node N, which must be a range, subtype indication, or the -- name of a scalar subtype. The result in L, H may be set to Error if -- there was an earlier error in the range. -- Use_Full_View is intended for use by clients other than the compiler -- (specifically, gnat2scil) to indicate that we want the full view if -- the index type turns out to be a partial view; this case should not -- arise during normal compilation of semantically correct programs. function Get_Enum_Lit_From_Pos (T : Entity_Id; Pos : Uint; Loc : Source_Ptr) return Node_Id; -- This function returns an identifier denoting the E_Enumeration_Literal -- entity for the specified value from the enumeration type or subtype T. -- The second argument is the Pos value. Constraint_Error is raised if -- argument Pos is not in range. The third argument supplies a source -- location for constructed nodes returned by this function. If No_Location -- is supplied as source location, the location of the returned node is -- copied from the original source location for the enumeration literal, -- when available. function Get_Iterable_Type_Primitive (Typ : Entity_Id; Nam : Name_Id) return Entity_Id; -- Retrieve one of the primitives First, Next, Has_Element, Element from -- the value of the Iterable aspect of a formal type. procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id); -- Retrieve the fully expanded name of the library unit declared by -- Decl_Node into the name buffer. function Get_Max_Queue_Length (Id : Entity_Id) return Uint; -- Return the argument of pragma Max_Queue_Length or zero if the annotation -- is not present. It is assumed that Id denotes an entry. function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id; pragma Inline (Get_Name_Entity_Id); -- An entity value is associated with each name in the name table. The -- Get_Name_Entity_Id function fetches the Entity_Id of this entity, which -- is the innermost visible entity with the given name. See the body of -- Sem_Ch8 for further details on handling of entity visibility. function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id; -- Return the Name component of Test_Case pragma N -- Bad name now that this no longer applies to Contract_Case ??? function Get_Parent_Entity (Unit : Node_Id) return Entity_Id; -- Get defining entity of parent unit of a child unit. In most cases this -- is the defining entity of the unit, but for a child instance whose -- parent needs a body for inlining, the instantiation node of the parent -- has not yet been rewritten as a package declaration, and the entity has -- to be retrieved from the Instance_Spec of the unit. function Get_Pragma_Id (N : Node_Id) return Pragma_Id; pragma Inline (Get_Pragma_Id); -- Obtains the Pragma_Id from Pragma_Name_Unmapped (N) function Get_Qualified_Name (Id : Entity_Id; Suffix : Entity_Id := Empty) return Name_Id; -- Obtain the fully qualified form of entity Id. The format is: -- scope_of_id-1__scope_of_id__chars_of_id__chars_of_suffix function Get_Qualified_Name (Nam : Name_Id; Suffix : Name_Id := No_Name; Scop : Entity_Id := Current_Scope) return Name_Id; -- Obtain the fully qualified form of name Nam assuming it appears in scope -- Scop. The format is: -- scop-1__scop__nam__suffix procedure Get_Reason_String (N : Node_Id); -- Recursive routine to analyze reason argument for pragma Warnings. The -- value of the reason argument is appended to the current string using -- Store_String_Chars. The reason argument is expected to be a string -- literal or concatenation of string literals. An error is given for -- any other form. function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id; -- If Typ has Implicit_Dereference, return discriminant specified in the -- corresponding aspect. function Get_Referenced_Object (N : Node_Id) return Node_Id; -- Given a node, return the renamed object if the node represents a renamed -- object, otherwise return the node unchanged. The node may represent an -- arbitrary expression. function Get_Renamed_Entity (E : Entity_Id) return Entity_Id; -- Given an entity for an exception, package, subprogram or generic unit, -- returns the ultimately renamed entity if this is a renaming. If this is -- not a renamed entity, returns its argument. It is an error to call this -- with any other kind of entity. function Get_Return_Object (N : Node_Id) return Entity_Id; -- Given an extended return statement, return the corresponding return -- object, identified as the one for which Is_Return_Object = True. function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id; -- Nod is either a procedure call statement, or a function call, or an -- accept statement node. This procedure finds the Entity_Id of the related -- subprogram or entry and returns it, or if no subprogram can be found, -- returns Empty. function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id; pragma Inline (Get_Task_Body_Procedure); -- Given an entity for a task type or subtype, retrieves the -- Task_Body_Procedure field from the corresponding task type declaration. function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id; -- For a type entity, return the entity of the primitive equality function -- for the type if it exists, otherwise return Empty. procedure Get_Views (Typ : Entity_Id; Priv_Typ : out Entity_Id; Full_Typ : out Entity_Id; Full_Base : out Entity_Id; CRec_Typ : out Entity_Id); -- Obtain the partial and full view of type Typ and in addition any extra -- types the full view may have. The return entities are as follows: -- -- Priv_Typ - the partial view (a private type) -- Full_Typ - the full view -- Full_Base - the base type of the full view -- CRec_Typ - the corresponding record type of the full view function Has_Access_Values (T : Entity_Id) return Boolean; -- Returns true if type or subtype T is an access type, or has a component -- (at any recursive level) that is an access type. This is a conservative -- predicate, if it is not known whether or not T contains access values -- (happens for generic formals in some cases), then False is returned. -- Note that tagged types return False. Even though the tag is implemented -- as an access type internally, this function tests only for access types -- known to the programmer. See also Has_Tagged_Component. type Alignment_Result is (Known_Compatible, Unknown, Known_Incompatible); -- Result of Has_Compatible_Alignment test, description found below. Note -- that the values are arranged in increasing order of problematicness. function Has_Compatible_Alignment (Obj : Entity_Id; Expr : Node_Id; Layout_Done : Boolean) return Alignment_Result; -- Obj is an object entity, and expr is a node for an object reference. If -- the alignment of the object referenced by Expr is known to be compatible -- with the alignment of Obj (i.e. is larger or the same), then the result -- is Known_Compatible. If the alignment of the object referenced by Expr -- is known to be less than the alignment of Obj, then Known_Incompatible -- is returned. If neither condition can be reliably established at compile -- time, then Unknown is returned. If Layout_Done is True, the function can -- assume that the information on size and alignment of types and objects -- is present in the tree. This is used to determine if alignment checks -- are required for address clauses (Layout_Done is False in this case) as -- well as to issue appropriate warnings for them in the post compilation -- phase (Layout_Done is True in this case). -- -- Note: Known_Incompatible does not mean that at run time the alignment -- of Expr is known to be wrong for Obj, just that it can be determined -- that alignments have been explicitly or implicitly specified which are -- incompatible (whereas Unknown means that even this is not known). The -- appropriate reaction of a caller to Known_Incompatible is to treat it as -- Unknown, but issue a warning that there may be an alignment error. function Has_Declarations (N : Node_Id) return Boolean; -- Determines if the node can have declarations function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean; -- Simple predicate to test for defaulted discriminants function Has_Denormals (E : Entity_Id) return Boolean; -- Determines if the floating-point type E supports denormal numbers. -- Returns False if E is not a floating-point type. function Has_Discriminant_Dependent_Constraint (Comp : Entity_Id) return Boolean; -- Returns True if and only if Comp has a constrained subtype that depends -- on a discriminant. function Has_Effectively_Volatile_Profile (Subp_Id : Entity_Id) return Boolean; -- Determine whether subprogram Subp_Id has an effectively volatile formal -- parameter or returns an effectively volatile value. function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean; -- Determine whether type Typ defines "full default initialization" as -- specified by SPARK RM 3.1. To qualify as such, the type must be -- * A scalar type with specified Default_Value -- * An array-of-scalar type with specified Default_Component_Value -- * An array type whose element type defines full default initialization -- * A protected type, record type or type extension whose components -- either include a default expression or have a type which defines -- full default initialization. In the case of type extensions, the -- parent type defines full default initialization. -- * A task type -- * A private type whose Default_Initial_Condition is non-null function Has_Infinities (E : Entity_Id) return Boolean; -- Determines if the range of the floating-point type E includes -- infinities. Returns False if E is not a floating-point type. function Has_Interfaces (T : Entity_Id; Use_Full_View : Boolean := True) return Boolean; -- Where T is a concurrent type or a record type, returns true if T covers -- any abstract interface types. In case of private types the argument -- Use_Full_View controls if the check is done using its full view (if -- available). function Has_Max_Queue_Length (Id : Entity_Id) return Boolean; -- Determine whether Id is subject to pragma Max_Queue_Length. It is -- assumed that Id denotes an entry. function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean; -- This is a simple minded function for determining whether an expression -- has no obvious side effects. It is used only for determining whether -- warnings are needed in certain situations, and is not guaranteed to -- be accurate in either direction. Exceptions may mean an expression -- does in fact have side effects, but this may be ignored and True is -- returned, or a complex expression may in fact be side effect free -- but we don't recognize it here and return False. The Side_Effect_Free -- routine in Remove_Side_Effects is much more extensive and perhaps could -- be shared, so that this routine would be more accurate. function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean; -- Determine whether abstract state Id has at least one nonnull constituent -- as expressed in pragma Refined_State. This function does not take into -- account the visible refinement region of abstract state Id. function Has_Null_Body (Proc_Id : Entity_Id) return Boolean; -- Determine whether the body of procedure Proc_Id contains a sole -- null statement, possibly followed by an optional return. Used to -- optimize useless calls to assertion checks. function Has_Null_Exclusion (N : Node_Id) return Boolean; -- Determine whether node N has a null exclusion function Has_Null_Refinement (Id : Entity_Id) return Boolean; -- Determine whether abstract state Id has a null refinement as expressed -- in pragma Refined_State. This function does not take into account the -- visible refinement region of abstract state Id. function Has_Overriding_Initialize (T : Entity_Id) return Boolean; -- Predicate to determine whether a controlled type has a user-defined -- Initialize primitive (and, in Ada 2012, whether that primitive is -- non-null), which causes the type to not have preelaborable -- initialization. function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean; -- Return True iff type E has preelaborable initialization as defined in -- Ada 2005 (see AI-161 for details of the definition of this attribute). function Has_Private_Component (Type_Id : Entity_Id) return Boolean; -- Check if a type has a (sub)component of a private type that has not -- yet received a full declaration. function Has_Signed_Zeros (E : Entity_Id) return Boolean; -- Determines if the floating-point type E supports signed zeros. -- Returns False if E is not a floating-point type. function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean; -- Determine whether subprogram [body] Subp_Id has a significant contract. -- All subprograms have a N_Contract node, but this does not mean that the -- contract is useful. function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean; -- Return whether an array type has static bounds function Has_Stream (T : Entity_Id) return Boolean; -- Tests if type T is derived from Ada.Streams.Root_Stream_Type, or in the -- case of a composite type, has a component for which this predicate is -- True, and if so returns True. Otherwise a result of False means that -- there is no Stream type in sight. For a private type, the test is -- applied to the underlying type (or returns False if there is no -- underlying type). function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean; -- Returns true if the last character of E is Suffix. Used in Assertions. function Has_Tagged_Component (Typ : Entity_Id) return Boolean; -- Returns True if Typ is a composite type (array or record) which is -- either itself a tagged type, or has a component (recursively) which is -- a tagged type. Returns False for non-composite type, or if no tagged -- component is present. This function is used to check if "=" has to be -- expanded into a bunch component comparisons. function Has_Undefined_Reference (Expr : Node_Id) return Boolean; -- Given arbitrary expression Expr, determine whether it contains at -- least one name whose entity is Any_Id. function Has_Volatile_Component (Typ : Entity_Id) return Boolean; -- Given arbitrary type Typ, determine whether it contains at least one -- volatile component. function Implementation_Kind (Subp : Entity_Id) return Name_Id; -- Subp is a subprogram marked with pragma Implemented. Return the specific -- implementation requirement which the pragma imposes. The return value is -- either Name_By_Any, Name_By_Entry or Name_By_Protected_Procedure. function Implements_Interface (Typ_Ent : Entity_Id; Iface_Ent : Entity_Id; Exclude_Parents : Boolean := False) return Boolean; -- Returns true if the Typ_Ent implements interface Iface_Ent function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean; -- Returns True if node N appears within a pragma that acts as an assertion -- expression. See Sem_Prag for the list of qualifying pragmas. function In_Generic_Scope (E : Entity_Id) return Boolean; -- Returns True if entity E is inside a generic scope function In_Instance return Boolean; -- Returns True if the current scope is within a generic instance function In_Instance_Body return Boolean; -- Returns True if current scope is within the body of an instance, where -- several semantic checks (e.g. accessibility checks) are relaxed. function In_Instance_Not_Visible return Boolean; -- Returns True if current scope is with the private part or the body of -- an instance. Other semantic checks are suppressed in this context. function In_Instance_Visible_Part return Boolean; -- Returns True if current scope is within the visible part of a package -- instance, where several additional semantic checks apply. function In_Package_Body return Boolean; -- Returns True if current scope is within a package body function In_Parameter_Specification (N : Node_Id) return Boolean; -- Returns True if node N belongs to a parameter specification function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean; -- Returns true if the expression N occurs within a pragma with name Nam function In_Pre_Post_Condition (N : Node_Id) return Boolean; -- Returns True if node N appears within a pre/postcondition pragma. Note -- the pragma Check equivalents are NOT considered. function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean; -- Returns True if N denotes a component or subcomponent in a record or -- array that has Reverse_Storage_Order. function In_Subprogram_Or_Concurrent_Unit return Boolean; -- Determines if the current scope is within a subprogram compilation unit -- (inside a subprogram declaration, subprogram body, or generic subprogram -- declaration) or within a task or protected body. The test is for -- appearing anywhere within such a construct (that is it does not need -- to be directly within). function In_Visible_Part (Scope_Id : Entity_Id) return Boolean; -- Determine whether a declaration occurs within the visible part of a -- package specification. The package must be on the scope stack, and the -- corresponding private part must not. function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id; -- Given the entity of a constant or a type, retrieve the incomplete or -- partial view of the same entity. Note that Id may not have a partial -- view in which case the function returns Empty. function Indexed_Component_Bit_Offset (N : Node_Id) return Uint; -- Given an N_Indexed_Component node, return the first bit position of the -- component if it is known at compile time. A value of No_Uint means that -- either the value is not yet known before back-end processing or it is -- not known at compile time after back-end processing. procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id); -- Inherit the rep item chain of type From_Typ without clobbering any -- existing rep items on Typ's chain. Typ is the destination type. procedure Insert_Explicit_Dereference (N : Node_Id); -- In a context that requires a composite or subprogram type and where a -- prefix is an access type, rewrite the access type node N (which is the -- prefix, e.g. of an indexed component) as an explicit dereference. procedure Inspect_Deferred_Constant_Completion (Decls : List_Id); -- Examine all deferred constants in the declaration list Decls and check -- whether they have been completed by a full constant declaration or an -- Import pragma. Emit the error message if that is not the case. procedure Install_Generic_Formals (Subp_Id : Entity_Id); -- Install both the generic formal parameters and the formal parameters of -- generic subprogram Subp_Id into visibility. function Is_Actual_Out_Parameter (N : Node_Id) return Boolean; -- Determines if N is an actual parameter of out mode in a subprogram call function Is_Actual_Parameter (N : Node_Id) return Boolean; -- Determines if N is an actual parameter in a subprogram call function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean; -- Determines if N is an actual parameter of a formal of tagged type in a -- subprogram call. function Is_Aliased_View (Obj : Node_Id) return Boolean; -- Determine if Obj is an aliased view, i.e. the name of an object to which -- 'Access or 'Unchecked_Access can apply. Note that this routine uses the -- rules of the language, it does not take into account the restriction -- No_Implicit_Aliasing, so it can return True if the restriction is active -- and Obj violates the restriction. The caller is responsible for calling -- Restrict.Check_No_Implicit_Aliasing if True is returned, but there is a -- requirement for obeying the restriction in the call context. function Is_Ancestor_Package (E1 : Entity_Id; E2 : Entity_Id) return Boolean; -- Determine whether package E1 is an ancestor of E2 function Is_Atomic_Object (N : Node_Id) return Boolean; -- Determines if the given node denotes an atomic object in the sense of -- the legality checks described in RM C.6(12). function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean; -- Determines if the given node is an atomic object (Is_Atomic_Object true) -- or else is an object for which VFA is present. function Is_Attribute_Result (N : Node_Id) return Boolean; -- Determine whether node N denotes attribute 'Result function Is_Attribute_Update (N : Node_Id) return Boolean; -- Determine whether node N denotes attribute 'Update function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean; -- Determine whether node N denotes a body or a package declaration function Is_Bounded_String (T : Entity_Id) return Boolean; -- True if T is a bounded string type. Used to make sure "=" composes -- properly for bounded string types. function Is_Constant_Bound (Exp : Node_Id) return Boolean; -- Exp is the expression for an array bound. Determines whether the -- bound is a compile-time known value, or a constant entity, or an -- enumeration literal, or an expression composed of constant-bound -- subexpressions which are evaluated by means of standard operators. function Is_Container_Element (Exp : Node_Id) return Boolean; -- This routine recognizes expressions that denote an element of one of -- the predefined containers, when the source only contains an indexing -- operation and an implicit dereference is inserted by the compiler. -- In the absence of this optimization, the indexing creates a temporary -- controlled cursor that sets the tampering bit of the container, and -- restricts the use of the convenient notation C (X) to contexts that -- do not check the tampering bit (e.g. C.Include (X, C (Y)). Exp is an -- explicit dereference. The transformation applies when it has the form -- F (X).Discr.all. function Is_Contract_Annotation (Item : Node_Id) return Boolean; -- Determine whether aspect specification or pragma Item is a contract -- annotation. function Is_Controlling_Limited_Procedure (Proc_Nam : Entity_Id) return Boolean; -- Ada 2005 (AI-345): Determine whether Proc_Nam is a primitive procedure -- of a limited interface with a controlling first parameter. function Is_CPP_Constructor_Call (N : Node_Id) return Boolean; -- Returns True if N is a call to a CPP constructor function Is_Child_Or_Sibling (Pack_1 : Entity_Id; Pack_2 : Entity_Id) return Boolean; -- Determine the following relations between two arbitrary packages: -- 1) One package is the parent of a child package -- 2) Both packages are siblings and share a common parent function Is_Concurrent_Interface (T : Entity_Id) return Boolean; -- First determine whether type T is an interface and then check whether -- it is of protected, synchronized or task kind. function Is_Current_Instance (N : Node_Id) return Boolean; -- Predicate is true if N legally denotes a type name within its own -- declaration. Prior to Ada 2012 this covered only synchronized type -- declarations. In Ada 2012 it also covers type and subtype declarations -- with aspects: Invariant, Predicate, and Default_Initial_Condition. function Is_Declaration (N : Node_Id) return Boolean; -- Determine whether arbitrary node N denotes a declaration function Is_Declaration_Other_Than_Renaming (N : Node_Id) return Boolean; -- Determine whether arbitrary node N denotes a non-renaming declaration function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean; -- Returns True iff component Comp is declared within a variant part function Is_Dependent_Component_Of_Mutable_Object (Object : Node_Id) return Boolean; -- Returns True if Object is the name of a subcomponent that depends on -- discriminants of a variable whose nominal subtype is unconstrained and -- not indefinite, and the variable is not aliased. Otherwise returns -- False. The nodes passed to this function are assumed to denote objects. function Is_Dereferenced (N : Node_Id) return Boolean; -- N is a subexpression node of an access type. This function returns true -- if N appears as the prefix of a node that does a dereference of the -- access value (selected/indexed component, explicit dereference or a -- slice), and false otherwise. function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean; -- Returns True if type T1 is a descendant of type T2, and false otherwise. -- This is the RM definition, a type is a descendant of another type if it -- is the same type or is derived from a descendant of the other type. function Is_Descendant_Of_Suspension_Object (Typ : Entity_Id) return Boolean; -- Determine whether type Typ is a descendant of type Suspension_Object -- defined in Ada.Synchronous_Task_Control. This version is different from -- Is_Descendant_Of as the detection of Suspension_Object does not involve -- an entity and by extension a call to RTSfind. function Is_Double_Precision_Floating_Point_Type (E : Entity_Id) return Boolean; -- Return whether E is a double precision floating point type, -- characterized by: -- . machine_radix = 2 -- . machine_mantissa = 53 -- . machine_emax = 2**10 -- . machine_emin = 3 - machine_emax function Is_Effectively_Volatile (Id : Entity_Id) return Boolean; -- Determine whether a type or object denoted by entity Id is effectively -- volatile (SPARK RM 7.1.2). To qualify as such, the entity must be either -- * Volatile -- * An array type subject to aspect Volatile_Components -- * An array type whose component type is effectively volatile -- * A protected type -- * Descendant of type Ada.Synchronous_Task_Control.Suspension_Object function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean; -- Determine whether an arbitrary node denotes an effectively volatile -- object (SPARK RM 7.1.2). function Is_Entry_Body (Id : Entity_Id) return Boolean; -- Determine whether entity Id is the body entity of an entry [family] function Is_Entry_Declaration (Id : Entity_Id) return Boolean; -- Determine whether entity Id is the spec entity of an entry [family] function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean; -- Check whether a function in a call is an expanded priority attribute, -- which is transformed into an Rtsfind call to Get_Ceiling. This expansion -- does not take place in a configurable runtime. function Is_Expression_Function (Subp : Entity_Id) return Boolean; -- Determine whether subprogram [body] Subp denotes an expression function function Is_Expression_Function_Or_Completion (Subp : Entity_Id) return Boolean; -- Determine whether subprogram [body] Subp denotes an expression function -- or is completed by an expression function body. function Is_EVF_Expression (N : Node_Id) return Boolean; -- Determine whether node N denotes a reference to a formal parameter of -- a specific tagged type whose related subprogram is subject to pragma -- Extensions_Visible with value "False" (SPARK RM 6.1.7). Several other -- constructs fall under this category: -- 1) A qualified expression whose operand is EVF -- 2) A type conversion whose operand is EVF -- 3) An if expression with at least one EVF dependent_expression -- 4) A case expression with at least one EVF dependent_expression function Is_False (U : Uint) return Boolean; pragma Inline (Is_False); -- The argument is a Uint value which is the Boolean'Pos value of a Boolean -- operand (i.e. is either 0 for False, or 1 for True). This function tests -- if it is False (i.e. zero). function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean; -- Returns True iff the number U is a model number of the fixed-point type -- T, i.e. if it is an exact multiple of Small. function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean; -- Typ is a type entity. This function returns true if this type is fully -- initialized, meaning that an object of the type is fully initialized. -- Note that initialization resulting from use of pragma Normalize_Scalars -- does not count. Note that this is only used for the purpose of issuing -- warnings for objects that are potentially referenced uninitialized. This -- means that the result returned is not crucial, but should err on the -- side of thinking things are fully initialized if it does not know. function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean; -- Determine whether arbitrary declaration Decl denotes a generic package, -- a generic subprogram or a generic body. function Is_Inherited_Operation (E : Entity_Id) return Boolean; -- E is a subprogram. Return True is E is an implicit operation inherited -- by a derived type declaration. function Is_Inherited_Operation_For_Type (E : Entity_Id; Typ : Entity_Id) return Boolean; -- E is a subprogram. Return True is E is an implicit operation inherited -- by the derived type declaration for type Typ. function Is_Inlinable_Expression_Function (Subp : Entity_Id) return Boolean; -- Return True if Subp is an expression function that fulfills all the -- following requirements for inlining: -- 1. pragma/aspect Inline_Always -- 2. No formals -- 3. No contracts -- 4. No dispatching primitive -- 5. Result subtype controlled (or with controlled components) -- 6. Result subtype not subject to type-invariant checks -- 7. Result subtype not a class-wide type -- 8. Return expression naming an object global to the function -- 9. Nominal subtype of the returned object statically compatible -- with the result subtype of the expression function. function Is_Iterator (Typ : Entity_Id) return Boolean; -- AI05-0139-2: Check whether Typ is one of the predefined interfaces in -- Ada.Iterator_Interfaces, or it is derived from one. function Is_Iterator_Over_Array (N : Node_Id) return Boolean; -- N is an iterator specification. Returns True iff N is an iterator over -- an array, either inside a loop of the form 'for X of A' or a quantified -- expression of the form 'for all/some X of A' where A is of array type. type Is_LHS_Result is (Yes, No, Unknown); function Is_LHS (N : Node_Id) return Is_LHS_Result; -- Returns Yes if N is definitely used as Name in an assignment statement. -- Returns No if N is definitely NOT used as a Name in an assignment -- statement. Returns Unknown if we can't tell at this stage (happens in -- the case where we don't know the type of N yet, and we have something -- like N.A := 3, where this counts as N being used on the left side of -- an assignment only if N is not an access type. If it is an access type -- then it is N.all.A that is assigned, not N. function Is_Library_Level_Entity (E : Entity_Id) return Boolean; -- A library-level declaration is one that is accessible from Standard, -- i.e. a library unit or an entity declared in a library package. function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean; -- Determine whether a given type is a limited class-wide type, in which -- case it needs a Master_Id, because extensions of its designated type -- may include task components. A class-wide type that comes from a -- limited view must be treated in the same way. function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean; -- Determines whether Expr is a reference to a variable or IN OUT mode -- parameter of the current enclosing subprogram. -- Why are OUT parameters not considered here ??? function Is_Name_Reference (N : Node_Id) return Boolean; -- Determine whether arbitrary node N is a reference to a name. This is -- similar to Is_Object_Reference but returns True only if N can be renamed -- without the need for a temporary, the typical example of an object not -- in this category being a function call. function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean; -- Determine whether entity Id denotes the procedure that verifies the -- assertion expression of pragma Default_Initial_Condition and if it does, -- the encapsulated expression is nontrivial. function Is_Null_Record_Type (T : Entity_Id) return Boolean; -- Determine whether T is declared with a null record definition or a -- null component list. function Is_Object_Reference (N : Node_Id) return Boolean; -- Determines if the tree referenced by N represents an object. Both -- variable and constant objects return True (compare Is_Variable). function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean; -- Used to test if AV is an acceptable formal for an OUT or IN OUT formal. -- Note that the Is_Variable function is not quite the right test because -- this is a case in which conversions whose expression is a variable (in -- the Is_Variable sense) with an untagged type target are considered view -- conversions and hence variables. function Is_OK_Volatile_Context (Context : Node_Id; Obj_Ref : Node_Id) return Boolean; -- Determine whether node Context denotes a "non-interfering context" (as -- defined in SPARK RM 7.1.3(12)) where volatile reference Obj_Ref can -- safely reside. function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean; -- Determine whether aspect specification or pragma Item is one of the -- following package contract annotations: -- Abstract_State -- Initial_Condition -- Initializes -- Refined_State function Is_Partially_Initialized_Type (Typ : Entity_Id; Include_Implicit : Boolean := True) return Boolean; -- Typ is a type entity. This function returns true if this type is partly -- initialized, meaning that an object of the type is at least partly -- initialized (in particular in the record case, that at least one -- component has an initialization expression). Note that initialization -- resulting from the use of pragma Normalize_Scalars does not count. -- Include_Implicit controls whether implicit initialization of access -- values to null, and of discriminant values, is counted as making the -- type be partially initialized. For the default setting of True, these -- implicit cases do count, and discriminated types or types containing -- access values not explicitly initialized will return True. Otherwise -- if Include_Implicit is False, these cases do not count as making the -- type be partially initialized. function Is_Potentially_Unevaluated (N : Node_Id) return Boolean; -- Predicate to implement definition given in RM 6.1.1 (20/3) function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean; -- Determines if type T is a potentially persistent type. A potentially -- persistent type is defined (recursively) as a scalar type, an untagged -- record whose components are all of a potentially persistent type, or an -- array with all static constraints whose component type is potentially -- persistent. A private type is potentially persistent if the full type -- is potentially persistent. function Is_Protected_Self_Reference (N : Node_Id) return Boolean; -- Return True if node N denotes a protected type name which represents -- the current instance of a protected object according to RM 9.4(21/2). function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean; -- Return True if a compilation unit is the specification or the -- body of a remote call interface package. function Is_Remote_Access_To_Class_Wide_Type (E : Entity_Id) return Boolean; -- Return True if E is a remote access-to-class-wide type function Is_Remote_Access_To_Subprogram_Type (E : Entity_Id) return Boolean; -- Return True if E is a remote access to subprogram type function Is_Remote_Call (N : Node_Id) return Boolean; -- Return True if N denotes a potentially remote call function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean; -- Return True if Proc_Nam is a procedure renaming of an entry function Is_Renaming_Declaration (N : Node_Id) return Boolean; -- Determine whether arbitrary node N denotes a renaming declaration function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean; -- AI05-0139-2: Check whether Typ is derived from the predefined interface -- Ada.Iterator_Interfaces.Reversible_Iterator. function Is_Selector_Name (N : Node_Id) return Boolean; -- Given an N_Identifier node N, determines if it is a Selector_Name. -- As described in Sinfo, Selector_Names are special because they -- represent use of the N_Identifier node for a true identifier, when -- normally such nodes represent a direct name. function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean; -- Determine whether arbitrary entity Id denotes the anonymous object -- created for a single protected or single task type. function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean; -- Determine whether arbitrary entity Id denotes a single protected or -- single task type. function Is_Single_Concurrent_Type_Declaration (N : Node_Id) return Boolean; -- Determine whether arbitrary node N denotes the declaration of a single -- protected type or single task type. function Is_Single_Precision_Floating_Point_Type (E : Entity_Id) return Boolean; -- Return whether E is a single precision floating point type, -- characterized by: -- . machine_radix = 2 -- . machine_mantissa = 24 -- . machine_emax = 2**7 -- . machine_emin = 3 - machine_emax function Is_Single_Protected_Object (Id : Entity_Id) return Boolean; -- Determine whether arbitrary entity Id denotes the anonymous object -- created for a single protected type. function Is_Single_Task_Object (Id : Entity_Id) return Boolean; -- Determine whether arbitrary entity Id denotes the anonymous object -- created for a single task type. function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean; -- Determines if the tree referenced by N represents an initialization -- expression in SPARK 2005, suitable for initializing an object in an -- object declaration. function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean; -- Determines if the tree referenced by N represents an object in SPARK -- 2005. This differs from Is_Object_Reference in that only variables, -- constants, formal parameters, and selected_components of those are -- valid objects in SPARK 2005. function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean; -- Determine whether an arbitrary [private] type is specifically tagged function Is_Statement (N : Node_Id) return Boolean; pragma Inline (Is_Statement); -- Check if the node N is a statement node. Note that this includes -- the case of procedure call statements (unlike the direct use of -- the N_Statement_Other_Than_Procedure_Call subtype from Sinfo). -- Note that a label is *not* a statement, and will return False. function Is_Subprogram_Contract_Annotation (Item : Node_Id) return Boolean; -- Determine whether aspect specification or pragma Item is one of the -- following subprogram contract annotations: -- Contract_Cases -- Depends -- Extensions_Visible -- Global -- Post -- Post_Class -- Postcondition -- Pre -- Pre_Class -- Precondition -- Refined_Depends -- Refined_Global -- Refined_Post -- Test_Case function Is_Subprogram_Stub_Without_Prior_Declaration (N : Node_Id) return Boolean; -- Return True if N is a subprogram stub with no prior subprogram -- declaration. function Is_Suspension_Object (Id : Entity_Id) return Boolean; -- Determine whether arbitrary entity Id denotes Suspension_Object defined -- in Ada.Synchronous_Task_Control. function Is_Synchronized_Object (Id : Entity_Id) return Boolean; -- Determine whether entity Id denotes an object and if it does, whether -- this object is synchronized as specified in SPARK RM 9.1. To qualify as -- such, the object must be -- * Of a type that yields a synchronized object -- * An atomic object with enabled Async_Writers -- * A constant -- * A variable subject to pragma Constant_After_Elaboration function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean; -- Returns True if E is a synchronized tagged type (AARM 3.9.4 (6/2)) function Is_Transfer (N : Node_Id) return Boolean; -- Returns True if the node N is a statement which is known to cause an -- unconditional transfer of control at runtime, i.e. the following -- statement definitely will not be executed. function Is_True (U : Uint) return Boolean; pragma Inline (Is_True); -- The argument is a Uint value which is the Boolean'Pos value of a Boolean -- operand (i.e. is either 0 for False, or 1 for True). This function tests -- if it is True (i.e. non-zero). function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean; -- Determine whether an arbitrary entity denotes an instance of function -- Ada.Unchecked_Conversion. function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean; pragma Inline (Is_Universal_Numeric_Type); -- True if T is Universal_Integer or Universal_Real function Is_Variable_Size_Array (E : Entity_Id) return Boolean; -- Returns true if E has variable size components function Is_Variable_Size_Record (E : Entity_Id) return Boolean; -- Returns true if E has variable size components function Is_Variable (N : Node_Id; Use_Original_Node : Boolean := True) return Boolean; -- Determines if the tree referenced by N represents a variable, i.e. can -- appear on the left side of an assignment. There is one situation (formal -- parameters) in which untagged type conversions are also considered -- variables, but Is_Variable returns False for such cases, since it has -- no knowledge of the context. Note that this is the point at which -- Assignment_OK is checked, and True is returned for any tree thus marked. -- Use_Original_Node is used to perform the test on Original_Node (N). By -- default is True since this routine is commonly invoked as part of the -- semantic analysis and it must not be disturbed by the rewriten nodes. function Is_Verifiable_DIC_Pragma (Prag : Node_Id) return Boolean; -- Determine whether pragma Default_Initial_Condition denoted by Prag has -- an assertion expression which should be verified at runtime. function Is_Visibly_Controlled (T : Entity_Id) return Boolean; -- Check whether T is derived from a visibly controlled type. This is true -- if the root type is declared in Ada.Finalization. If T is derived -- instead from a private type whose full view is controlled, an explicit -- Initialize/Adjust/Finalize subprogram does not override the inherited -- one. function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean; -- Determine whether [generic] function Func_Id is subject to enabled -- pragma Volatile_Function. Protected functions are treated as volatile -- (SPARK RM 7.1.2). function Is_Volatile_Object (N : Node_Id) return Boolean; -- Determines if the given node denotes an volatile object in the sense of -- the legality checks described in RM C.6(12). Note that the test here is -- for something actually declared as volatile, not for an object that gets -- treated as volatile (see Einfo.Treat_As_Volatile). function Itype_Has_Declaration (Id : Entity_Id) return Boolean; -- Applies to Itypes. True if the Itype is attached to a declaration for -- the type through its Parent field, which may or not be present in the -- tree. procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False); -- This procedure is called to clear all constant indications from all -- entities in the current scope and in any parent scopes if the current -- scope is a block or a package (and that recursion continues to the top -- scope that is not a block or a package). This is used when the -- sequential flow-of-control assumption is violated (occurrence of a -- label, head of a loop, or start of an exception handler). The effect of -- the call is to clear the Current_Value field (but we do not need to -- clear the Is_True_Constant flag, since that only gets reset if there -- really is an assignment somewhere in the entity scope). This procedure -- also calls Kill_All_Checks, since this is a special case of needing to -- forget saved values. This procedure also clears the Is_Known_Null and -- Is_Known_Non_Null and Is_Known_Valid flags in variables, constants or -- parameters since these are also not known to be trustable any more. -- -- The Last_Assignment_Only flag is set True to clear only Last_Assignment -- fields and leave other fields unchanged. This is used when we encounter -- an unconditional flow of control change (return, goto, raise). In such -- cases we don't need to clear the current values, since it may be that -- the flow of control change occurs in a conditional context, and if it -- is not taken, then it is just fine to keep the current values. But the -- Last_Assignment field is different, if we have a sequence assign-to-v, -- conditional-return, assign-to-v, we do not want to complain that the -- second assignment clobbers the first. procedure Kill_Current_Values (Ent : Entity_Id; Last_Assignment_Only : Boolean := False); -- This performs the same processing as described above for the form with -- no argument, but for the specific entity given. The call has no effect -- if the entity Ent is not for an object. Last_Assignment_Only has the -- same meaning as for the call with no Ent. procedure Kill_Size_Check_Code (E : Entity_Id); -- Called when an address clause or pragma Import is applied to an entity. -- If the entity is a variable or a constant, and size check code is -- present, this size check code is killed, since the object will not be -- allocated by the program. function Known_To_Be_Assigned (N : Node_Id) return Boolean; -- The node N is an entity reference. This function determines whether the -- reference is for sure an assignment of the entity, returning True if -- so. This differs from May_Be_Lvalue in that it defaults in the other -- direction. Cases which may possibly be assignments but are not known to -- be may return True from May_Be_Lvalue, but False from this function. function Last_Source_Statement (HSS : Node_Id) return Node_Id; -- HSS is a handled statement sequence. This function returns the last -- statement in Statements (HSS) that has Comes_From_Source set. If no -- such statement exists, Empty is returned. function Matching_Static_Array_Bounds (L_Typ : Node_Id; R_Typ : Node_Id) return Boolean; -- L_Typ and R_Typ are two array types. Returns True when they have the -- same number of dimensions, and the same static bounds for each index -- position. procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id); -- Given a node which designates the context of analysis and an origin in -- the tree, traverse from Root_Nod and mark all allocators as either -- dynamic or static depending on Context_Nod. Any incorrect marking is -- cleaned up during resolution. function May_Be_Lvalue (N : Node_Id) return Boolean; -- Determines if N could be an lvalue (e.g. an assignment left hand side). -- An lvalue is defined as any expression which appears in a context where -- a name is required by the syntax, and the identity, rather than merely -- the value of the node is needed (for example, the prefix of an Access -- attribute is in this category). Note that, as implied by the name, this -- test is conservative. If it cannot be sure that N is NOT an lvalue, then -- it returns True. It tries hard to get the answer right, but it is hard -- to guarantee this in all cases. Note that it is more possible to give -- correct answer if the tree is fully analyzed. function Needs_One_Actual (E : Entity_Id) return Boolean; -- Returns True if a function has defaults for all but its first -- formal. Used in Ada 2005 mode to solve the syntactic ambiguity that -- results from an indexing of a function call written in prefix form. function New_Copy_List_Tree (List : List_Id) return List_Id; -- Copy recursively an analyzed list of nodes. Uses New_Copy_Tree defined -- below. As for New_Copy_Tree, it is illegal to attempt to copy extended -- nodes (entities) either directly or indirectly using this function. function New_Copy_Tree (Source : Node_Id; Map : Elist_Id := No_Elist; New_Sloc : Source_Ptr := No_Location; New_Scope : Entity_Id := Empty) return Node_Id; -- Given a node that is the root of a subtree, New_Copy_Tree copies the -- entire syntactic subtree, including recursively any descendants whose -- parent field references a copied node (descendants not linked to a -- copied node by the parent field are not copied, instead the copied tree -- references the same descendant as the original in this case, which is -- appropriate for non-syntactic fields such as Etype). The parent pointers -- in the copy are properly set. New_Copy_Tree (Empty/Error) returns -- Empty/Error. The one exception to the rule of not copying semantic -- fields is that any implicit types attached to the subtree are -- duplicated, so that the copy contains a distinct set of implicit type -- entities. Thus this function is used when it is necessary to duplicate -- an analyzed tree, declared in the same or some other compilation unit. -- This function is declared here rather than in atree because it uses -- semantic information in particular concerning the structure of itypes -- and the generation of public symbols. -- The Map argument, if set to a non-empty Elist, specifies a set of -- mappings to be applied to entities in the tree. The map has the form: -- -- old entity 1 -- new entity to replace references to entity 1 -- old entity 2 -- new entity to replace references to entity 2 -- ... -- -- The call destroys the contents of Map in this case -- -- The parameter New_Sloc, if set to a value other than No_Location, is -- used as the Sloc value for all nodes in the new copy. If New_Sloc is -- set to its default value No_Location, then the Sloc values of the -- nodes in the copy are simply copied from the corresponding original. -- -- The Comes_From_Source indication is unchanged if New_Sloc is set to -- the default No_Location value, but is reset if New_Sloc is given, since -- in this case the result clearly is neither a source node or an exact -- copy of a source node. -- -- The parameter New_Scope, if set to a value other than Empty, is the -- value to use as the Scope for any Itypes that are copied. The most -- typical value for this parameter, if given, is Current_Scope. function New_External_Entity (Kind : Entity_Kind; Scope_Id : Entity_Id; Sloc_Value : Source_Ptr; Related_Id : Entity_Id; Suffix : Character; Suffix_Index : Nat := 0; Prefix : Character := ' ') return Entity_Id; -- This function creates an N_Defining_Identifier node for an internal -- created entity, such as an implicit type or subtype, or a record -- initialization procedure. The entity name is constructed with a call -- to New_External_Name (Related_Id, Suffix, Suffix_Index, Prefix), so -- that the generated name may be referenced as a public entry, and the -- Is_Public flag is set if needed (using Set_Public_Status). If the -- entity is for a type or subtype, the size/align fields are initialized -- to unknown (Uint_0). function New_Internal_Entity (Kind : Entity_Kind; Scope_Id : Entity_Id; Sloc_Value : Source_Ptr; Id_Char : Character) return Entity_Id; -- This function is similar to New_External_Entity, except that the -- name is constructed by New_Internal_Name (Id_Char). This is used -- when the resulting entity does not have to be referenced as a -- public entity (and in this case Is_Public is not set). procedure Next_Actual (Actual_Id : in out Node_Id); pragma Inline (Next_Actual); -- Next_Actual (N) is equivalent to N := Next_Actual (N). Note that we -- inline this procedural form, but not the functional form that follows. function Next_Actual (Actual_Id : Node_Id) return Node_Id; -- Find next actual parameter in declaration order. As described for -- First_Actual, this is the next actual in the declaration order, not -- the call order, so this does not correspond to simply taking the -- next entry of the Parameter_Associations list. The argument is an -- actual previously returned by a call to First_Actual or Next_Actual. -- Note that the result produced is always an expression, not a parameter -- association node, even if named notation was used. procedure Normalize_Actuals (N : Node_Id; S : Entity_Id; Report : Boolean; Success : out Boolean); -- Reorders lists of actuals according to names of formals, value returned -- in Success indicates success of reordering. For more details, see body. -- Errors are reported only if Report is set to True. procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean); -- This routine is called if the sub-expression N maybe the target of -- an assignment (e.g. it is the left side of an assignment, used as -- an out parameters, or used as prefixes of access attributes). It -- sets May_Be_Modified in the associated entity if there is one, -- taking into account the rule that in the case of renamed objects, -- it is the flag in the renamed object that must be set. -- -- The parameter Sure is set True if the modification is sure to occur -- (e.g. target of assignment, or out parameter), and to False if the -- modification is only potential (e.g. address of entity taken). function Null_To_Null_Address_Convert_OK (N : Node_Id; Typ : Entity_Id := Empty) return Boolean; -- Return True if we are compiling in relaxed RM semantics mode and: -- 1) N is a N_Null node and Typ is a descendant of System.Address, or -- 2) N is a comparison operator, one of the operands is null, and the -- type of the other operand is a descendant of System.Address. function Object_Access_Level (Obj : Node_Id) return Uint; -- Return the accessibility level of the view of the object Obj. For -- convenience, qualified expressions applied to object names are also -- allowed as actuals for this function. function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id; -- Retrieve the name of aspect or pragma N taking into account a possible -- rewrite and whether the pragma is generated from an aspect as the names -- may be different. The routine also deals with 'Class in which case it -- returns the following values: -- -- Invariant -> Name_uInvariant -- Post'Class -> Name_uPost -- Pre'Class -> Name_uPre -- Type_Invariant -> Name_uType_Invariant -- Type_Invariant'Class -> Name_uType_Invariant function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id; -- [Ada 2012: AI05-0125-1]: If S is an inherited dispatching primitive S2, -- or overrides an inherited dispatching primitive S2, the original -- corresponding operation of S is the original corresponding operation of -- S2. Otherwise, it is S itself. procedure Output_Entity (Id : Entity_Id); -- Print entity Id to standard output. The name of the entity appears in -- fully qualified form. -- -- WARNING: this routine should be used in debugging scenarios such as -- tracking down undefined symbols as it is fairly low level. procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope); -- Print name Nam to standard output. The name appears in fully qualified -- form assuming it appears in scope Scop. Note that this may not reflect -- the final qualification as the entity which carries the name may be -- relocated to a different scope. -- -- WARNING: this routine should be used in debugging scenarios such as -- tracking down undefined symbols as it is fairly low level. function Policy_In_Effect (Policy : Name_Id) return Name_Id; -- Given a policy, return the policy identifier associated with it. If no -- such policy is in effect, the value returned is No_Name. function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean; -- Subp is the entity for a subprogram call. This function returns True if -- predicate tests are required for the arguments in this call (this is the -- normal case). It returns False for special cases where these predicate -- tests should be skipped (see body for details). function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean; -- Returns True if the names of both entities correspond with matching -- primitives. This routine includes support for the case in which one -- or both entities correspond with entities built by Derive_Subprogram -- with a special name to avoid being overridden (i.e. return true in case -- of entities with names "nameP" and "name" or vice versa). function Private_Component (Type_Id : Entity_Id) return Entity_Id; -- Returns some private component (if any) of the given Type_Id. -- Used to enforce the rules on visibility of operations on composite -- types, that depend on the full view of the component type. For a -- record type there may be several such components, we just return -- the first one. procedure Process_End_Label (N : Node_Id; Typ : Character; Ent : Entity_Id); -- N is a node whose End_Label is to be processed, generating all -- appropriate cross-reference entries, and performing style checks -- for any identifier references in the end label. Typ is either -- 'e' or 't indicating the type of the cross-reference entity -- (e for spec, t for body, see Lib.Xref spec for details). The -- parameter Ent gives the entity to which the End_Label refers, -- and to which cross-references are to be generated. procedure Propagate_Concurrent_Flags (Typ : Entity_Id; Comp_Typ : Entity_Id); -- Set Has_Task, Has_Protected and Has_Timing_Event on Typ when the flags -- are set on Comp_Typ. This follows the definition of these flags which -- are set (recursively) on any composite type which has a component marked -- by one of these flags. This procedure can only set flags for Typ, and -- never clear them. Comp_Typ is the type of a component or a parent. procedure Propagate_DIC_Attributes (Typ : Entity_Id; From_Typ : Entity_Id); -- Inherit all Default_Initial_Condition-related attributes from type -- From_Typ. Typ is the destination type. procedure Propagate_Invariant_Attributes (Typ : Entity_Id; From_Typ : Entity_Id); -- Inherit all invariant-related attributes form type From_Typ. Typ is the -- destination type. procedure Record_Possible_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id); -- Save reference Ref to variable Var_Id when the variable is subject to -- pragma Part_Of. If the variable is known to be a constituent of a single -- protected/task type, the legality of the reference is verified and the -- save does not take place. function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean; -- Determine whether entity Id is referenced within expression Expr function References_Generic_Formal_Type (N : Node_Id) return Boolean; -- Returns True if the expression Expr contains any references to a generic -- type. This can only happen within a generic template. procedure Remove_Homonym (E : Entity_Id); -- Removes E from the homonym chain procedure Remove_Overloaded_Entity (Id : Entity_Id); -- Remove arbitrary entity Id from the homonym chain, the scope chain and -- the primitive operations list of the associated controlling type. NOTE: -- the removal performed by this routine does not affect the visibility of -- existing homonyms. function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id; -- Returns the name of E without Suffix procedure Replace_Null_By_Null_Address (N : Node_Id); -- N is N_Null or a binary comparison operator, we are compiling in relaxed -- RM semantics mode, and one of the operands is null. Replace null with -- System.Null_Address. function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id; -- This is used to construct the second argument in a call to Rep_To_Pos -- which is Standard_True if range checks are enabled (E is an entity to -- which the Range_Checks_Suppressed test is applied), and Standard_False -- if range checks are suppressed. Loc is the location for the node that -- is returned (which is a New_Occurrence of the appropriate entity). -- -- Note: one might think that it would be fine to always use True and -- to ignore the suppress in this case, but it is generally better to -- believe a request to suppress exceptions if possible, and further -- more there is at least one case in the generated code (the code for -- array assignment in a loop) that depends on this suppression. procedure Require_Entity (N : Node_Id); -- N is a node which should have an entity value if it is an entity name. -- If not, then check if there were previous errors. If so, just fill -- in with Any_Id and ignore. Otherwise signal a program error exception. -- This is used as a defense mechanism against ill-formed trees caused by -- previous errors (particularly in -gnatq mode). function Requires_Transient_Scope (Id : Entity_Id) return Boolean; -- Id is a type entity. The result is True when temporaries of this type -- need to be wrapped in a transient scope to be reclaimed properly when a -- secondary stack is in use. Examples of types requiring such wrapping are -- controlled types and variable-sized types including unconstrained -- arrays. procedure Reset_Analyzed_Flags (N : Node_Id); -- Reset the Analyzed flags in all nodes of the tree whose root is N procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type); -- Set the current SPARK_Mode to whatever Mode denotes. This routime must -- be used in tandem with Save_SPARK_Mode_And_Set. function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean; -- Return true if Subp is a function that returns an unconstrained type function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id; -- Similar to attribute Root_Type, but this version always follows the -- Full_View of a private type (if available) while searching for the -- ultimate derivation ancestor. function Safe_To_Capture_Value (N : Node_Id; Ent : Entity_Id; Cond : Boolean := False) return Boolean; -- The caller is interested in capturing a value (either the current value, -- or an indication that the value is non-null) for the given entity Ent. -- This value can only be captured if sequential execution semantics can be -- properly guaranteed so that a subsequent reference will indeed be sure -- that this current value indication is correct. The node N is the -- construct which resulted in the possible capture of the value (this -- is used to check if we are in a conditional). -- -- Cond is used to skip the test for being inside a conditional. It is used -- in the case of capturing values from if/while tests, which already do a -- proper job of handling scoping issues without this help. -- -- The only entities whose values can be captured are OUT and IN OUT formal -- parameters, and variables unless Cond is True, in which case we also -- allow IN formals, loop parameters and constants, where we cannot ever -- capture actual value information, but we can capture conditional tests. function Same_Name (N1, N2 : Node_Id) return Boolean; -- Determine if two (possibly expanded) names are the same name. This is -- a purely syntactic test, and N1 and N2 need not be analyzed. function Same_Object (Node1, Node2 : Node_Id) return Boolean; -- Determine if Node1 and Node2 are known to designate the same object. -- This is a semantic test and both nodes must be fully analyzed. A result -- of True is decisively correct. A result of False does not necessarily -- mean that different objects are designated, just that this could not -- be reliably determined at compile time. function Same_Type (T1, T2 : Entity_Id) return Boolean; -- Determines if T1 and T2 represent exactly the same type. Two types -- are the same if they are identical, or if one is an unconstrained -- subtype of the other, or they are both common subtypes of the same -- type with identical constraints. The result returned is conservative. -- It is True if the types are known to be the same, but a result of -- False is indecisive (e.g. the compiler may not be able to tell that -- two constraints are identical). function Same_Value (Node1, Node2 : Node_Id) return Boolean; -- Determines if Node1 and Node2 are known to be the same value, which is -- true if they are both compile time known values and have the same value, -- or if they are the same object (in the sense of function Same_Object). -- A result of False does not necessarily mean they have different values, -- just that it is not possible to determine they have the same value. procedure Save_SPARK_Mode_And_Set (Context : Entity_Id; Mode : out SPARK_Mode_Type); -- Save the current SPARK_Mode in effect in Mode. Establish the SPARK_Mode -- (if any) of a package or a subprogram denoted by Context. This routine -- must be used in tandem with Restore_SPARK_Mode. function Scalar_Part_Present (T : Entity_Id) return Boolean; -- Tests if type T can be determined at compile time to have at least one -- scalar part in the sense of the Valid_Scalars attribute. Returns True if -- this is the case, and False if no scalar parts are present (meaning that -- the result of Valid_Scalars applied to T is always vacuously True). function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean; -- Determines if the entity Scope1 is the same as Scope2, or if it is -- inside it, where both entities represent scopes. Note that scopes -- are only partially ordered, so Scope_Within_Or_Same (A,B) and -- Scope_Within_Or_Same (B,A) can both be False for a given pair A,B. function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean; -- Like Scope_Within_Or_Same, except that this function returns -- False in the case where Scope1 and Scope2 are the same scope. procedure Set_Convention (E : Entity_Id; Val : Convention_Id); -- Same as Basic_Set_Convention, but with an extra check for access types. -- In particular, if E is an access-to-subprogram type, and Val is a -- foreign convention, then we set Can_Use_Internal_Rep to False on E. -- Also, if the Etype of E is set and is an anonymous access type with -- no convention set, this anonymous type inherits the convention of E. procedure Set_Current_Entity (E : Entity_Id); pragma Inline (Set_Current_Entity); -- Establish the entity E as the currently visible definition of its -- associated name (i.e. the Node_Id associated with its name). procedure Set_Debug_Info_Needed (T : Entity_Id); -- Sets the Debug_Info_Needed flag on entity T , and also on any entities -- that are needed by T (for an object, the type of the object is needed, -- and for a type, various subsidiary types are needed -- see body for -- details). Never has any effect on T if the Debug_Info_Off flag is set. -- This routine should always be used instead of Set_Needs_Debug_Info to -- ensure that subsidiary entities are properly handled. procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id); -- This procedure has the same calling sequence as Set_Entity, but it -- performs additional checks as follows: -- -- If Style_Check is set, then it calls a style checking routine which -- can check identifier spelling style. This procedure also takes care -- of checking the restriction No_Implementation_Identifiers. -- -- If restriction No_Abort_Statements is set, then it checks that the -- entity is not Ada.Task_Identification.Abort_Task. -- -- If restriction No_Dynamic_Attachment is set, then it checks that the -- entity is not one of the restricted names for this restriction. -- -- If restriction No_Long_Long_Integers is set, then it checks that the -- entity is not Standard.Long_Long_Integer. -- -- If restriction No_Implementation_Identifiers is set, then it checks -- that the entity is not implementation defined. procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id); pragma Inline (Set_Name_Entity_Id); -- Sets the Entity_Id value associated with the given name, which is the -- Id of the innermost visible entity with the given name. See the body -- of package Sem_Ch8 for further details on the handling of visibility. procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id); -- The arguments may be parameter associations, whose descendants -- are the optional formal name and the actual parameter. Positional -- parameters are already members of a list, and do not need to be -- chained separately. See also First_Actual and Next_Actual. procedure Set_Optimize_Alignment_Flags (E : Entity_Id); pragma Inline (Set_Optimize_Alignment_Flags); -- Sets Optimize_Alignment_Space/Time flags in E from current settings procedure Set_Public_Status (Id : Entity_Id); -- If an entity (visible or otherwise) is defined in a library -- package, or a package that is itself public, then this subprogram -- labels the entity public as well. procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean); -- N is the node for either a left hand side (Out_Param set to False), -- or an Out or In_Out parameter (Out_Param set to True). If there is -- an assignable entity being referenced, then the appropriate flag -- (Referenced_As_LHS if Out_Param is False, Referenced_As_Out_Parameter -- if Out_Param is True) is set True, and the other flag set False. procedure Set_Rep_Info (T1, T2 : Entity_Id); pragma Inline (Set_Rep_Info); -- Copies the Is_Atomic, Is_Independent and Is_Volatile_Full_Access flags -- from sub(type) entity T2 to (sub)type entity T1, as well as Is_Volatile -- if T1 is a base type. procedure Set_Scope_Is_Transient (V : Boolean := True); -- Set the flag Is_Transient of the current scope procedure Set_Size_Info (T1, T2 : Entity_Id); pragma Inline (Set_Size_Info); -- Copies the Esize field and Has_Biased_Representation flag from sub(type) -- entity T2 to (sub)type entity T1. Also copies the Is_Unsigned_Type flag -- in the fixed-point and discrete cases, and also copies the alignment -- value from T2 to T1. It does NOT copy the RM_Size field, which must be -- separately set if this is required to be copied also. function Scope_Is_Transient return Boolean; -- True if the current scope is transient function Static_Boolean (N : Node_Id) return Uint; -- This function analyzes the given expression node and then resolves it -- as Standard.Boolean. If the result is static, then Uint_1 or Uint_0 is -- returned corresponding to the value, otherwise an error message is -- output and No_Uint is returned. function Static_Integer (N : Node_Id) return Uint; -- This function analyzes the given expression node and then resolves it -- as any integer type. If the result is static, then the value of the -- universal expression is returned, otherwise an error message is output -- and a value of No_Uint is returned. function Statically_Different (E1, E2 : Node_Id) return Boolean; -- Return True if it can be statically determined that the Expressions -- E1 and E2 refer to different objects function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean; -- Determine whether node N is a loop statement subject to at least one -- 'Loop_Entry attribute. function Subprogram_Access_Level (Subp : Entity_Id) return Uint; -- Return the accessibility level of the view denoted by Subp function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean; -- Return True if Typ supports the GCC built-in atomic operations (i.e. if -- Typ is properly sized and aligned). procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String); -- Print debugging information on entry to each unit being analyzed procedure Transfer_Entities (From : Entity_Id; To : Entity_Id); -- Move a list of entities from one scope to another, and recompute -- Is_Public based upon the new scope. function Type_Access_Level (Typ : Entity_Id) return Uint; -- Return the accessibility level of Typ function Type_Without_Stream_Operation (T : Entity_Id; Op : TSS_Name_Type := TSS_Null) return Entity_Id; -- AI05-0161: In Ada 2012, if the restriction No_Default_Stream_Attributes -- is active then we cannot generate stream subprograms for composite types -- with elementary subcomponents that lack user-defined stream subprograms. -- This predicate determines whether a type has such an elementary -- subcomponent. If Op is TSS_Null, a type that lacks either Read or Write -- prevents the construction of a composite stream operation. If Op is -- specified we check only for the given stream operation. function Unique_Defining_Entity (N : Node_Id) return Entity_Id; -- Return the entity which represents declaration N, so that different -- views of the same entity have the same unique defining entity: -- * entry declaration and entry body -- * package spec, package body, and package body stub -- * protected type declaration, protected body, and protected body stub -- * private view and full view of a deferred constant -- * private view and full view of a type -- * subprogram declaration, subprogram, and subprogram body stub -- * task type declaration, task body, and task body stub -- In other cases, return the defining entity for N. function Unique_Entity (E : Entity_Id) return Entity_Id; -- Return the unique entity for entity E, which would be returned by -- Unique_Defining_Entity if applied to the enclosing declaration of E. function Unique_Name (E : Entity_Id) return String; -- Return a unique name for entity E, which could be used to identify E -- across compilation units. function Unit_Is_Visible (U : Entity_Id) return Boolean; -- Determine whether a compilation unit is visible in the current context, -- because there is a with_clause that makes the unit available. Used to -- provide better messages on common visiblity errors on operators. function Universal_Interpretation (Opnd : Node_Id) return Entity_Id; -- Yields Universal_Integer or Universal_Real if this is a candidate function Unqualify (Expr : Node_Id) return Node_Id; pragma Inline (Unqualify); -- Removes any qualifications from Expr. For example, for T1'(T2'(X)), this -- returns X. If Expr is not a qualified expression, returns Expr. function Visible_Ancestors (Typ : Entity_Id) return Elist_Id; -- [Ada 2012:AI-0125-1]: Collect all the visible parents and progenitors -- of a type extension or private extension declaration. If the full-view -- of private parents and progenitors is available then it is used to -- generate the list of visible ancestors; otherwise their partial -- view is added to the resulting list. function Within_Init_Proc return Boolean; -- Determines if Current_Scope is within an init proc function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean; -- Returns True if entity E is declared within scope S procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id); -- Output error message for incorrectly typed expression. Expr is the node -- for the incorrectly typed construct (Etype (Expr) is the type found), -- and Expected_Type is the entity for the expected type. Note that Expr -- does not have to be a subexpression, anything with an Etype field may -- be used. function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean; -- Determine whether type Typ "yields synchronized object" as specified by -- SPARK RM 9.1. To qualify as such, a type must be -- * An array type whose element type yields a synchronized object -- * A descendant of type Ada.Synchronous_Task_Control.Suspension_Object -- * A protected type -- * A record type or type extension without defaulted discriminants -- whose components are of a type that yields a synchronized object. -- * A synchronized interface type -- * A task type function Yields_Universal_Type (N : Node_Id) return Boolean; -- Determine whether unanalyzed node N yields a universal type end Sem_Util;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- O S I N T -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2020, Free Software Foundation, Inc. -- -- -- -- 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 Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT 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 GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Alloc; with Debug; with Fmap; use Fmap; with Gnatvsn; use Gnatvsn; with Hostparm; with Opt; use Opt; with Output; use Output; with Sdefault; use Sdefault; with Table; with Targparm; use Targparm; with Unchecked_Conversion; pragma Warnings (Off); -- This package is used also by gnatcoll with System.Case_Util; use System.Case_Util; with System.CRTL; pragma Warnings (On); with GNAT.HTable; package body Osint is use type CRTL.size_t; Running_Program : Program_Type := Unspecified; -- comment required here ??? Program_Set : Boolean := False; -- comment required here ??? Std_Prefix : String_Ptr; -- Standard prefix, computed dynamically the first time Relocate_Path -- is called, and cached for subsequent calls. Empty : aliased String := ""; No_Dir : constant String_Ptr := Empty'Access; -- Used in Locate_File as a fake directory when Name is already an -- absolute path. ------------------------------------- -- Use of Name_Find and Name_Enter -- ------------------------------------- -- This package creates a number of source, ALI and object file names -- that are used to locate the actual file and for the purpose of message -- construction. These names need not be accessible by Name_Find, and can -- be therefore created by using routine Name_Enter. The files in question -- are file names with a prefix directory (i.e., the files not in the -- current directory). File names without a prefix directory are entered -- with Name_Find because special values might be attached to the various -- Info fields of the corresponding name table entry. ----------------------- -- Local Subprograms -- ----------------------- function Append_Suffix_To_File_Name (Name : File_Name_Type; Suffix : String) return File_Name_Type; -- Appends Suffix to Name and returns the new name function OS_Time_To_GNAT_Time (T : OS_Time) return Time_Stamp_Type; -- Convert OS format time to GNAT format time stamp. If T is Invalid_Time, -- then returns Empty_Time_Stamp. -- Round to even seconds on Windows before conversion. -- Windows ALI files had timestamps rounded to even seconds historically. -- The rounding was originally done in GM_Split. Now that GM_Split no -- longer does it, we are rounding it here only for ALI files. function Executable_Prefix return String_Ptr; -- Returns the name of the root directory where the executable is stored. -- The executable must be located in a directory called "bin", or under -- root/lib/gcc-lib/..., or under root/libexec/gcc/... For example, if -- executable is stored in directory "/foo/bar/bin", this routine returns -- "/foo/bar/". Return "" if location is not recognized as described above. function File_Names_Equal (File1, File2 : String) return Boolean; -- Compare File1 and File2 taking into account the case insensitivity -- of the OS. function Update_Path (Path : String_Ptr) return String_Ptr; -- Update the specified path to replace the prefix with the location where -- GNAT is installed. See the file prefix.c in GCC for details. procedure Locate_File (N : File_Name_Type; T : File_Type; Dir : Natural; Name : String; Found : out File_Name_Type; Attr : access File_Attributes); -- See if the file N whose name is Name exists in directory Dir. Dir is an -- index into the Lib_Search_Directories table if T = Library. Otherwise -- if T = Source, Dir is an index into the Src_Search_Directories table. -- Returns the File_Name_Type of the full file name if file found, or -- No_File if not found. -- -- On exit, Found is set to the file that was found, and Attr to a cache of -- its attributes (at least those that have been computed so far). Reusing -- the cache will save some system calls. -- -- Attr is always reset in this call to Unknown_Attributes, even in case of -- failure procedure Find_File (N : File_Name_Type; T : File_Type; Found : out File_Name_Type; Attr : access File_Attributes; Full_Name : Boolean := False); -- A version of Find_File that also returns a cache of the file attributes -- for later reuse procedure Smart_Find_File (N : File_Name_Type; T : File_Type; Found : out File_Name_Type; Attr : out File_Attributes); -- A version of Smart_Find_File that also returns a cache of the file -- attributes for later reuse function C_String_Length (S : Address) return CRTL.size_t; -- Returns length of a C string (zero for a null address) function To_Path_String_Access (Path_Addr : Address; Path_Len : CRTL.size_t) return String_Access; -- Converts a C String to an Ada String. Are we doing this to avoid withing -- Interfaces.C.Strings ??? -- Caller must free result. function Include_Dir_Default_Prefix return String_Access; -- Same as exported version, except returns a String_Access ------------------------------ -- Other Local Declarations -- ------------------------------ EOL : constant Character := ASCII.LF; -- End of line character Number_File_Names : Nat := 0; -- Number of file names found on command line and placed in File_Names Look_In_Primary_Directory_For_Current_Main : Boolean := False; -- When this variable is True, Find_File only looks in Primary_Directory -- for the Current_Main file. This variable is always set to True for the -- compiler. It is also True for gnatmake, when the source name given on -- the command line has directory information. Current_Full_Source_Name : File_Name_Type := No_File; Current_Full_Source_Stamp : Time_Stamp_Type := Empty_Time_Stamp; Current_Full_Lib_Name : File_Name_Type := No_File; Current_Full_Lib_Stamp : Time_Stamp_Type := Empty_Time_Stamp; Current_Full_Obj_Name : File_Name_Type := No_File; Current_Full_Obj_Stamp : Time_Stamp_Type := Empty_Time_Stamp; -- Respectively full name (with directory info) and time stamp of the -- latest source, library and object files opened by Read_Source_File and -- Read_Library_Info. package File_Name_Chars is new Table.Table ( Table_Component_Type => Character, Table_Index_Type => Int, Table_Low_Bound => 1, Table_Initial => Alloc.File_Name_Chars_Initial, Table_Increment => Alloc.File_Name_Chars_Increment, Table_Name => "File_Name_Chars"); -- Table to store text to be printed by Dump_Source_File_Names The_Include_Dir_Default_Prefix : String_Access := null; -- Value returned by Include_Dir_Default_Prefix. We don't initialize it -- here, because that causes an elaboration cycle with Sdefault; we -- initialize it lazily instead. ------------------ -- Search Paths -- ------------------ Primary_Directory : constant := 0; -- This is index in the tables created below for the first directory to -- search in for source or library information files. This is the directory -- containing the latest main input file (a source file for the compiler or -- a library file for the binder). package Src_Search_Directories is new Table.Table ( Table_Component_Type => String_Ptr, Table_Index_Type => Integer, Table_Low_Bound => Primary_Directory, Table_Initial => 10, Table_Increment => 100, Table_Name => "Osint.Src_Search_Directories"); -- Table of names of directories in which to search for source (Compiler) -- files. This table is filled in the order in which the directories are -- to be searched, and then used in that order. package Lib_Search_Directories is new Table.Table ( Table_Component_Type => String_Ptr, Table_Index_Type => Integer, Table_Low_Bound => Primary_Directory, Table_Initial => 10, Table_Increment => 100, Table_Name => "Osint.Lib_Search_Directories"); -- Table of names of directories in which to search for library (Binder) -- files. This table is filled in the order in which the directories are -- to be searched and then used in that order. The reason for having two -- distinct tables is that we need them both in gnatmake. --------------------- -- File Hash Table -- --------------------- -- The file hash table is provided to free the programmer from any -- efficiency concern when retrieving full file names or time stamps of -- source files. If the programmer calls Source_File_Data (Cache => True) -- he is guaranteed that the price to retrieve the full name (i.e. with -- directory info) or time stamp of the file will be payed only once, the -- first time the full name is actually searched (or the first time the -- time stamp is actually retrieved). This is achieved by employing a hash -- table that stores as a key the File_Name_Type of the file and associates -- to that File_Name_Type the full file name and time stamp of the file. File_Cache_Enabled : Boolean := False; -- Set to true if you want the enable the file data caching mechanism type File_Hash_Num is range 0 .. 1020; function File_Hash (F : File_Name_Type) return File_Hash_Num; -- Compute hash index for use by Simple_HTable type File_Info_Cache is record File : File_Name_Type; Attr : aliased File_Attributes; end record; No_File_Info_Cache : constant File_Info_Cache := (No_File, (others => 0)); package File_Name_Hash_Table is new GNAT.HTable.Simple_HTable ( Header_Num => File_Hash_Num, Element => File_Info_Cache, No_Element => No_File_Info_Cache, Key => File_Name_Type, Hash => File_Hash, Equal => "="); function Smart_Find_File (N : File_Name_Type; T : File_Type) return File_Name_Type; -- Exactly like Find_File except that if File_Cache_Enabled is True this -- routine looks first in the hash table to see if the full name of the -- file is already available. function Smart_File_Stamp (N : File_Name_Type; T : File_Type) return Time_Stamp_Type; -- Takes the same parameter as the routine above (N is a file name without -- any prefix directory information) and behaves like File_Stamp except -- that if File_Cache_Enabled is True this routine looks first in the hash -- table to see if the file stamp of the file is already available. ----------------------------- -- Add_Default_Search_Dirs -- ----------------------------- procedure Add_Default_Search_Dirs is Search_Dir : String_Access; Search_Path : String_Access; Path_File_Name : String_Access; procedure Add_Search_Dir (Search_Dir : String; Additional_Source_Dir : Boolean); procedure Add_Search_Dir (Search_Dir : String_Access; Additional_Source_Dir : Boolean); -- Add a source search dir or a library search dir, depending on the -- value of Additional_Source_Dir. procedure Get_Dirs_From_File (Additional_Source_Dir : Boolean); -- Open a path file and read the directory to search, one per line function Get_Libraries_From_Registry return String_Ptr; -- On Windows systems, get the list of installed standard libraries -- from the registry key: -- -- HKEY_LOCAL_MACHINE\SOFTWARE\Ada Core Technologies\ -- GNAT\Standard Libraries -- Return an empty string on other systems. -- -- Note that this is an undocumented legacy feature, and that it -- works only when using the default runtime library (i.e. no --RTS= -- command line switch). -------------------- -- Add_Search_Dir -- -------------------- procedure Add_Search_Dir (Search_Dir : String; Additional_Source_Dir : Boolean) is begin if Additional_Source_Dir then Add_Src_Search_Dir (Search_Dir); else Add_Lib_Search_Dir (Search_Dir); end if; end Add_Search_Dir; procedure Add_Search_Dir (Search_Dir : String_Access; Additional_Source_Dir : Boolean) is begin if Additional_Source_Dir then Add_Src_Search_Dir (Search_Dir.all); else Add_Lib_Search_Dir (Search_Dir.all); end if; end Add_Search_Dir; ------------------------ -- Get_Dirs_From_File -- ------------------------ procedure Get_Dirs_From_File (Additional_Source_Dir : Boolean) is File_FD : File_Descriptor; Buffer : constant String := Path_File_Name.all & ASCII.NUL; Len : Natural; Actual_Len : Natural; S : String_Access; Curr : Natural; First : Natural; Ch : Character; Status : Boolean; pragma Warnings (Off, Status); -- For the call to Close where status is ignored begin File_FD := Open_Read (Buffer'Address, Binary); -- If we cannot open the file, we ignore it, we don't fail if File_FD = Invalid_FD then return; end if; Len := Integer (File_Length (File_FD)); S := new String (1 .. Len); -- Read the file. Note that the loop is probably not necessary any -- more since the whole file is read in at once on all targets. But -- it is harmless and might be needed in future. Curr := 1; Actual_Len := Len; while Curr <= Len and then Actual_Len /= 0 loop Actual_Len := Read (File_FD, S (Curr)'Address, Len); Curr := Curr + Actual_Len; end loop; -- We are done with the file, so we close it (ignore any error on -- the close, since we have successfully read the file). Close (File_FD, Status); -- Now, we read line by line First := 1; Curr := 0; while Curr < Len loop Ch := S (Curr + 1); if Ch = ASCII.CR or else Ch = ASCII.LF or else Ch = ASCII.FF or else Ch = ASCII.VT then if First <= Curr then Add_Search_Dir (S (First .. Curr), Additional_Source_Dir); end if; First := Curr + 2; end if; Curr := Curr + 1; end loop; -- Last line is a special case, if the file does not end with -- an end of line mark. if First <= S'Last then Add_Search_Dir (S (First .. S'Last), Additional_Source_Dir); end if; end Get_Dirs_From_File; --------------------------------- -- Get_Libraries_From_Registry -- --------------------------------- function Get_Libraries_From_Registry return String_Ptr is function C_Get_Libraries_From_Registry return Address; pragma Import (C, C_Get_Libraries_From_Registry, "__gnat_get_libraries_from_registry"); Result_Ptr : Address; Result_Length : CRTL.size_t; Out_String : String_Ptr; begin Result_Ptr := C_Get_Libraries_From_Registry; Result_Length := CRTL.strlen (Result_Ptr); Out_String := new String (1 .. Integer (Result_Length)); CRTL.strncpy (Out_String.all'Address, Result_Ptr, Result_Length); CRTL.free (Result_Ptr); return Out_String; end Get_Libraries_From_Registry; -- Start of processing for Add_Default_Search_Dirs begin -- If there was a -gnateO switch, add all object directories from the -- file given in argument to the library search list. if Object_Path_File_Name /= null then Path_File_Name := String_Access (Object_Path_File_Name); pragma Assert (Path_File_Name'Length > 0); Get_Dirs_From_File (Additional_Source_Dir => False); end if; -- After the locations specified on the command line, the next places -- to look for files are the directories specified by the appropriate -- environment variable. Get this value, extract the directory names -- and store in the tables. -- Check for eventual project path file env vars Path_File_Name := Getenv (Project_Include_Path_File); if Path_File_Name'Length > 0 then Get_Dirs_From_File (Additional_Source_Dir => True); end if; Path_File_Name := Getenv (Project_Objects_Path_File); if Path_File_Name'Length > 0 then Get_Dirs_From_File (Additional_Source_Dir => False); end if; -- Put path name in canonical form for Additional_Source_Dir in False .. True loop if Additional_Source_Dir then Search_Path := Getenv (Ada_Include_Path); else Search_Path := Getenv (Ada_Objects_Path); end if; Get_Next_Dir_In_Path_Init (Search_Path); loop Search_Dir := Get_Next_Dir_In_Path (Search_Path); exit when Search_Dir = null; Add_Search_Dir (Search_Dir, Additional_Source_Dir); end loop; end loop; -- For the compiler, if --RTS= was specified, add the runtime -- directories. if RTS_Src_Path_Name /= null and then RTS_Lib_Path_Name /= null then Add_Search_Dirs (RTS_Src_Path_Name, Include); Add_Search_Dirs (RTS_Lib_Path_Name, Objects); else if not Opt.No_Stdinc then -- For WIN32 systems, look for any system libraries defined in -- the registry. These are added to both source and object -- directories. Search_Path := String_Access (Get_Libraries_From_Registry); Get_Next_Dir_In_Path_Init (Search_Path); loop Search_Dir := Get_Next_Dir_In_Path (Search_Path); exit when Search_Dir = null; Add_Search_Dir (Search_Dir, False); Add_Search_Dir (Search_Dir, True); end loop; -- The last place to look are the defaults Search_Path := Read_Default_Search_Dirs (String_Access (Update_Path (Search_Dir_Prefix)), Include_Search_File, String_Access (Update_Path (Include_Dir_Default_Name))); Get_Next_Dir_In_Path_Init (Search_Path); loop Search_Dir := Get_Next_Dir_In_Path (Search_Path); exit when Search_Dir = null; Add_Search_Dir (Search_Dir, True); end loop; end if; -- Even when -nostdlib is used, we still want to have visibility on -- the run-time object directory, as it is used by gnatbind to find -- the run-time ALI files in "real" ZFP set up. if not Opt.RTS_Switch then Search_Path := Read_Default_Search_Dirs (String_Access (Update_Path (Search_Dir_Prefix)), Objects_Search_File, String_Access (Update_Path (Object_Dir_Default_Name))); Get_Next_Dir_In_Path_Init (Search_Path); loop Search_Dir := Get_Next_Dir_In_Path (Search_Path); exit when Search_Dir = null; Add_Search_Dir (Search_Dir, False); end loop; end if; end if; end Add_Default_Search_Dirs; -------------- -- Add_File -- -------------- procedure Add_File (File_Name : String; Index : Int := No_Index) is begin Number_File_Names := Number_File_Names + 1; -- As Add_File may be called for mains specified inside a project file, -- File_Names may be too short and needs to be extended. if Number_File_Names > File_Names'Last then File_Names := new File_Name_Array'(File_Names.all & File_Names.all); File_Indexes := new File_Index_Array'(File_Indexes.all & File_Indexes.all); end if; File_Names (Number_File_Names) := new String'(File_Name); File_Indexes (Number_File_Names) := Index; end Add_File; ------------------------ -- Add_Lib_Search_Dir -- ------------------------ procedure Add_Lib_Search_Dir (Dir : String) is begin if Dir'Length = 0 then Fail ("missing library directory name"); end if; declare Norm : String_Ptr := Normalize_Directory_Name (Dir); begin -- Do nothing if the directory is already in the list. This saves -- system calls and avoid unneeded work for D in Lib_Search_Directories.First .. Lib_Search_Directories.Last loop if Lib_Search_Directories.Table (D).all = Norm.all then Free (Norm); return; end if; end loop; Lib_Search_Directories.Increment_Last; Lib_Search_Directories.Table (Lib_Search_Directories.Last) := Norm; end; end Add_Lib_Search_Dir; --------------------- -- Add_Search_Dirs -- --------------------- procedure Add_Search_Dirs (Search_Path : String_Ptr; Path_Type : Search_File_Type) is Current_Search_Path : String_Access; begin Get_Next_Dir_In_Path_Init (String_Access (Search_Path)); loop Current_Search_Path := Get_Next_Dir_In_Path (String_Access (Search_Path)); exit when Current_Search_Path = null; if Path_Type = Include then Add_Src_Search_Dir (Current_Search_Path.all); else Add_Lib_Search_Dir (Current_Search_Path.all); end if; end loop; end Add_Search_Dirs; ------------------------ -- Add_Src_Search_Dir -- ------------------------ procedure Add_Src_Search_Dir (Dir : String) is begin if Dir'Length = 0 then Fail ("missing source directory name"); end if; Src_Search_Directories.Increment_Last; Src_Search_Directories.Table (Src_Search_Directories.Last) := Normalize_Directory_Name (Dir); end Add_Src_Search_Dir; -------------------------------- -- Append_Suffix_To_File_Name -- -------------------------------- function Append_Suffix_To_File_Name (Name : File_Name_Type; Suffix : String) return File_Name_Type is begin Get_Name_String (Name); Name_Buffer (Name_Len + 1 .. Name_Len + Suffix'Length) := Suffix; Name_Len := Name_Len + Suffix'Length; return Name_Find; end Append_Suffix_To_File_Name; --------------------- -- C_String_Length -- --------------------- function C_String_Length (S : Address) return CRTL.size_t is begin if S = Null_Address then return 0; else return CRTL.strlen (S); end if; end C_String_Length; ------------------------------ -- Canonical_Case_File_Name -- ------------------------------ procedure Canonical_Case_File_Name (S : in out String) is begin if not File_Names_Case_Sensitive then To_Lower (S); end if; end Canonical_Case_File_Name; --------------------------------- -- Canonical_Case_Env_Var_Name -- --------------------------------- procedure Canonical_Case_Env_Var_Name (S : in out String) is begin if not Env_Vars_Case_Sensitive then To_Lower (S); end if; end Canonical_Case_Env_Var_Name; --------------------------- -- Create_File_And_Check -- --------------------------- procedure Create_File_And_Check (Fdesc : out File_Descriptor; Fmode : Mode) is begin Output_File_Name := Name_Enter; Fdesc := Create_File (Name_Buffer'Address, Fmode); if Fdesc = Invalid_FD then Fail ("Cannot create: " & Name_Buffer (1 .. Name_Len)); end if; end Create_File_And_Check; ----------------------------------- -- Open_File_To_Append_And_Check -- ----------------------------------- procedure Open_File_To_Append_And_Check (Fdesc : out File_Descriptor; Fmode : Mode) is begin Output_File_Name := Name_Enter; Fdesc := Open_Append (Name_Buffer'Address, Fmode); if Fdesc = Invalid_FD then Fail ("Cannot create: " & Name_Buffer (1 .. Name_Len)); end if; end Open_File_To_Append_And_Check; ------------------------ -- Current_File_Index -- ------------------------ function Current_File_Index return Int is begin return File_Indexes (Current_File_Name_Index); end Current_File_Index; -------------------------------- -- Current_Library_File_Stamp -- -------------------------------- function Current_Library_File_Stamp return Time_Stamp_Type is begin return Current_Full_Lib_Stamp; end Current_Library_File_Stamp; ------------------------------- -- Current_Object_File_Stamp -- ------------------------------- function Current_Object_File_Stamp return Time_Stamp_Type is begin return Current_Full_Obj_Stamp; end Current_Object_File_Stamp; ------------------------------- -- Current_Source_File_Stamp -- ------------------------------- function Current_Source_File_Stamp return Time_Stamp_Type is begin return Current_Full_Source_Stamp; end Current_Source_File_Stamp; ---------------------------- -- Dir_In_Obj_Search_Path -- ---------------------------- function Dir_In_Obj_Search_Path (Position : Natural) return String_Ptr is begin if Opt.Look_In_Primary_Dir then return Lib_Search_Directories.Table (Primary_Directory + Position - 1); else return Lib_Search_Directories.Table (Primary_Directory + Position); end if; end Dir_In_Obj_Search_Path; ---------------------------- -- Dir_In_Src_Search_Path -- ---------------------------- function Dir_In_Src_Search_Path (Position : Natural) return String_Ptr is begin if Opt.Look_In_Primary_Dir then return Src_Search_Directories.Table (Primary_Directory + Position - 1); else return Src_Search_Directories.Table (Primary_Directory + Position); end if; end Dir_In_Src_Search_Path; ----------------------------------------- -- Dump_Command_Line_Source_File_Names -- ----------------------------------------- procedure Dump_Command_Line_Source_File_Names is begin for J in 1 .. Number_Of_Files loop Write_Str (File_Names (J).all & " "); end loop; end Dump_Command_Line_Source_File_Names; ---------------------------- -- Dump_Source_File_Names -- ---------------------------- procedure Dump_Source_File_Names is subtype Rng is Int range File_Name_Chars.First .. File_Name_Chars.Last; begin Write_Str (String (File_Name_Chars.Table (Rng))); end Dump_Source_File_Names; --------------------- -- Executable_Name -- --------------------- function Executable_Name (Name : File_Name_Type; Only_If_No_Suffix : Boolean := False) return File_Name_Type is Exec_Suffix : String_Access; Add_Suffix : Boolean; begin if Name = No_File then return No_File; end if; if Executable_Extension_On_Target = No_Name then Exec_Suffix := Get_Target_Executable_Suffix; else Get_Name_String (Executable_Extension_On_Target); Exec_Suffix := new String'(Name_Buffer (1 .. Name_Len)); end if; if Exec_Suffix'Length /= 0 then Get_Name_String (Name); Add_Suffix := True; if Only_If_No_Suffix then for J in reverse 1 .. Name_Len loop if Name_Buffer (J) = '.' then Add_Suffix := False; exit; elsif Is_Directory_Separator (Name_Buffer (J)) then exit; end if; end loop; end if; if Add_Suffix then -- If Executable doesn't end with the executable suffix, add it if Name_Len <= Exec_Suffix'Length or else not File_Names_Equal (Name_Buffer (Name_Len - Exec_Suffix'Length + 1 .. Name_Len), Exec_Suffix.all) then Name_Buffer (Name_Len + 1 .. Name_Len + Exec_Suffix'Length) := Exec_Suffix.all; Name_Len := Name_Len + Exec_Suffix'Length; Free (Exec_Suffix); return Name_Find; end if; end if; end if; Free (Exec_Suffix); return Name; end Executable_Name; function Executable_Name (Name : String; Only_If_No_Suffix : Boolean := False) return String is Exec_Suffix : String_Access; Add_Suffix : Boolean; begin if Executable_Extension_On_Target = No_Name then Exec_Suffix := Get_Target_Executable_Suffix; else Get_Name_String (Executable_Extension_On_Target); Exec_Suffix := new String'(Name_Buffer (1 .. Name_Len)); end if; if Exec_Suffix'Length = 0 then Free (Exec_Suffix); return Name; else declare Suffix : constant String := Exec_Suffix.all; begin Free (Exec_Suffix); Add_Suffix := True; if Only_If_No_Suffix then for J in reverse Name'Range loop if Name (J) = '.' then Add_Suffix := False; exit; elsif Is_Directory_Separator (Name (J)) then exit; end if; end loop; end if; if Add_Suffix and then (Name'Length <= Suffix'Length or else not File_Names_Equal (Name (Name'Last - Suffix'Length + 1 .. Name'Last), Suffix)) then declare Result : String (1 .. Name'Length + Suffix'Length); begin Result (1 .. Name'Length) := Name; Result (Name'Length + 1 .. Result'Last) := Suffix; return Result; end; else return Name; end if; end; end if; end Executable_Name; ----------------------- -- Executable_Prefix -- ----------------------- function Executable_Prefix return String_Ptr is function Get_Install_Dir (Exec : String) return String_Ptr; -- S is the executable name preceded by the absolute or relative -- path, e.g. "c:\usr\bin\gcc.exe" or "..\bin\gcc". --------------------- -- Get_Install_Dir -- --------------------- function Get_Install_Dir (Exec : String) return String_Ptr is Full_Path : constant String := Normalize_Pathname (Exec); -- Use the full path, so that we find "lib" or "bin", even when -- the tool has been invoked with a relative path, as in -- "./gnatls -v" invoked in the GNAT bin directory. begin for J in reverse Full_Path'Range loop if Is_Directory_Separator (Full_Path (J)) then if J < Full_Path'Last - 5 then if (To_Lower (Full_Path (J + 1)) = 'l' and then To_Lower (Full_Path (J + 2)) = 'i' and then To_Lower (Full_Path (J + 3)) = 'b') or else (To_Lower (Full_Path (J + 1)) = 'b' and then To_Lower (Full_Path (J + 2)) = 'i' and then To_Lower (Full_Path (J + 3)) = 'n') then return new String'(Full_Path (Full_Path'First .. J)); end if; end if; end if; end loop; return new String'(""); end Get_Install_Dir; -- Start of processing for Executable_Prefix begin if Exec_Name = null then Exec_Name := new String (1 .. Len_Arg (0)); Osint.Fill_Arg (Exec_Name (1)'Address, 0); end if; -- First determine if a path prefix was placed in front of the -- executable name. for J in reverse Exec_Name'Range loop if Is_Directory_Separator (Exec_Name (J)) then return Get_Install_Dir (Exec_Name.all); end if; end loop; -- If we come here, the user has typed the executable name with no -- directory prefix. return Get_Install_Dir (Locate_Exec_On_Path (Exec_Name.all).all); end Executable_Prefix; ------------------ -- Exit_Program -- ------------------ procedure Exit_Program (Exit_Code : Exit_Code_Type) is begin -- The program will exit with the following status: -- 0 if the object file has been generated (with or without warnings) -- 1 if recompilation was not needed (smart recompilation) -- 2 if gnat1 has been killed by a signal (detected by GCC) -- 4 for a fatal error -- 5 if there were errors -- 6 if no code has been generated (spec) -- Note that exit code 3 is not used and must not be used as this is -- the code returned by a program aborted via C abort() routine on -- Windows. GCC checks for that case and thinks that the child process -- has been aborted. This code (exit code 3) used to be the code used -- for E_No_Code, but E_No_Code was changed to 6 for this reason. case Exit_Code is when E_Success => OS_Exit (0); when E_Warnings => OS_Exit (0); when E_No_Compile => OS_Exit (1); when E_Fatal => OS_Exit (4); when E_Errors => OS_Exit (5); when E_No_Code => OS_Exit (6); when E_Abort => OS_Abort; end case; end Exit_Program; ---------- -- Fail -- ---------- procedure Fail (S : String) is begin -- We use Output in case there is a special output set up. In this case -- Set_Standard_Error will have no immediate effect. Set_Standard_Error; Osint.Write_Program_Name; Write_Str (": "); Write_Str (S); Write_Eol; Exit_Program (E_Fatal); end Fail; ---------------------- -- File_Names_Equal -- ---------------------- function File_Names_Equal (File1, File2 : String) return Boolean is begin if File_Names_Case_Sensitive then return File1 = File2; else return To_Lower (File1) = To_Lower (File2); end if; end File_Names_Equal; --------------- -- File_Hash -- --------------- function File_Hash (F : File_Name_Type) return File_Hash_Num is begin return File_Hash_Num (Int (F) mod File_Hash_Num'Range_Length); end File_Hash; ----------------- -- File_Length -- ----------------- function File_Length (Name : C_File_Name; Attr : access File_Attributes) return Long_Integer is function Internal (F : Integer; N : C_File_Name; A : System.Address) return CRTL.int64; pragma Import (C, Internal, "__gnat_file_length_attr"); begin -- The conversion from int64 to Long_Integer is ok here as this -- routine is only to be used by the compiler and we do not expect -- a unit to be larger than a 32bit integer. return Long_Integer (Internal (-1, Name, Attr.all'Address)); end File_Length; --------------------- -- File_Time_Stamp -- --------------------- function File_Time_Stamp (Name : C_File_Name; Attr : access File_Attributes) return OS_Time is function Internal (N : C_File_Name; A : System.Address) return OS_Time; pragma Import (C, Internal, "__gnat_file_time_name_attr"); begin return Internal (Name, Attr.all'Address); end File_Time_Stamp; function File_Time_Stamp (Name : Path_Name_Type; Attr : access File_Attributes) return Time_Stamp_Type is begin if Name = No_Path then return Empty_Time_Stamp; end if; Get_Name_String (Name); Name_Buffer (Name_Len + 1) := ASCII.NUL; return OS_Time_To_GNAT_Time (File_Time_Stamp (Name_Buffer'Address, Attr)); end File_Time_Stamp; ---------------- -- File_Stamp -- ---------------- function File_Stamp (Name : File_Name_Type) return Time_Stamp_Type is begin if Name = No_File then return Empty_Time_Stamp; end if; Get_Name_String (Name); -- File_Time_Stamp will always return Invalid_Time if the file does -- not exist, and OS_Time_To_GNAT_Time will convert this value to -- Empty_Time_Stamp. Therefore we do not need to first test whether -- the file actually exists, which saves a system call. return OS_Time_To_GNAT_Time (File_Time_Stamp (Name_Buffer (1 .. Name_Len))); end File_Stamp; function File_Stamp (Name : Path_Name_Type) return Time_Stamp_Type is begin return File_Stamp (File_Name_Type (Name)); end File_Stamp; --------------- -- Find_File -- --------------- function Find_File (N : File_Name_Type; T : File_Type; Full_Name : Boolean := False) return File_Name_Type is Attr : aliased File_Attributes; Found : File_Name_Type; begin Find_File (N, T, Found, Attr'Access, Full_Name); return Found; end Find_File; --------------- -- Find_File -- --------------- procedure Find_File (N : File_Name_Type; T : File_Type; Found : out File_Name_Type; Attr : access File_Attributes; Full_Name : Boolean := False) is begin Get_Name_String (N); declare File_Name : String renames Name_Buffer (1 .. Name_Len); File : File_Name_Type := No_File; Last_Dir : Natural; begin -- If we are looking for a config file, look only in the current -- directory, i.e. return input argument unchanged. Also look only in -- the current directory if we are looking for a .dg file (happens in -- -gnatD mode). if T = Config or else (Debug_Generated_Code and then Name_Len > 3 and then Name_Buffer (Name_Len - 2 .. Name_Len) = ".dg") then Found := N; Attr.all := Unknown_Attributes; if T = Config then if Full_Name then declare Full_Path : constant String := Normalize_Pathname (Get_Name_String (N)); Full_Size : constant Natural := Full_Path'Length; begin Name_Buffer (1 .. Full_Size) := Full_Path; Name_Len := Full_Size; Found := Name_Find; end; end if; -- Check that it is a file, not a directory if not Is_Regular_File (Get_Name_String (Found)) then Found := No_File; end if; end if; return; -- If we are trying to find the current main file just look in the -- directory where the user said it was. elsif Look_In_Primary_Directory_For_Current_Main and then Current_Main = N then Locate_File (N, T, Primary_Directory, File_Name, Found, Attr); return; -- Otherwise do standard search for source file else -- Check the mapping of this file name File := Mapped_Path_Name (N); -- If the file name is mapped to a path name, return the -- corresponding path name if File /= No_File then -- For locally removed file, Error_Name is returned; then -- return No_File, indicating the file is not a source. if File = Error_File_Name then Found := No_File; else Found := File; end if; Attr.all := Unknown_Attributes; return; end if; -- First place to look is in the primary directory (i.e. the same -- directory as the source) unless this has been disabled with -I- if Opt.Look_In_Primary_Dir then Locate_File (N, T, Primary_Directory, File_Name, Found, Attr); if Found /= No_File then return; end if; end if; -- Finally look in directories specified with switches -I/-aI/-aO if T = Library then Last_Dir := Lib_Search_Directories.Last; else Last_Dir := Src_Search_Directories.Last; end if; for D in Primary_Directory + 1 .. Last_Dir loop Locate_File (N, T, D, File_Name, Found, Attr); if Found /= No_File then return; end if; end loop; Attr.all := Unknown_Attributes; Found := No_File; end if; end; end Find_File; ----------------------- -- Find_Program_Name -- ----------------------- procedure Find_Program_Name is Command_Name : String (1 .. Len_Arg (0)); Cindex1 : Integer := Command_Name'First; Cindex2 : Integer := Command_Name'Last; begin Fill_Arg (Command_Name'Address, 0); if Command_Name = "" then Name_Len := 0; return; end if; -- The program name might be specified by a full path name. However, -- we don't want to print that all out in an error message, so the -- path might need to be stripped away. for J in reverse Cindex1 .. Cindex2 loop if Is_Directory_Separator (Command_Name (J)) then Cindex1 := J + 1; exit; end if; end loop; -- Command_Name(Cindex1 .. Cindex2) is now the equivalent of the -- POSIX command "basename argv[0]" -- Strip off any executable extension (usually nothing or .exe) -- but formally reported by autoconf in the variable EXEEXT if Cindex2 - Cindex1 >= 4 then if To_Lower (Command_Name (Cindex2 - 3)) = '.' and then To_Lower (Command_Name (Cindex2 - 2)) = 'e' and then To_Lower (Command_Name (Cindex2 - 1)) = 'x' and then To_Lower (Command_Name (Cindex2)) = 'e' then Cindex2 := Cindex2 - 4; end if; end if; Name_Len := Cindex2 - Cindex1 + 1; Name_Buffer (1 .. Name_Len) := Command_Name (Cindex1 .. Cindex2); end Find_Program_Name; ------------------------ -- Full_Lib_File_Name -- ------------------------ procedure Full_Lib_File_Name (N : File_Name_Type; Lib_File : out File_Name_Type; Attr : out File_Attributes) is A : aliased File_Attributes; begin -- ??? seems we could use Smart_Find_File here Find_File (N, Library, Lib_File, A'Access); Attr := A; end Full_Lib_File_Name; ------------------------ -- Full_Lib_File_Name -- ------------------------ function Full_Lib_File_Name (N : File_Name_Type) return File_Name_Type is Attr : File_Attributes; File : File_Name_Type; begin Full_Lib_File_Name (N, File, Attr); return File; end Full_Lib_File_Name; ---------------------------- -- Full_Library_Info_Name -- ---------------------------- function Full_Library_Info_Name return File_Name_Type is begin return Current_Full_Lib_Name; end Full_Library_Info_Name; --------------------------- -- Full_Object_File_Name -- --------------------------- function Full_Object_File_Name return File_Name_Type is begin return Current_Full_Obj_Name; end Full_Object_File_Name; ---------------------- -- Full_Source_Name -- ---------------------- function Full_Source_Name return File_Name_Type is begin return Current_Full_Source_Name; end Full_Source_Name; ---------------------- -- Full_Source_Name -- ---------------------- function Full_Source_Name (N : File_Name_Type) return File_Name_Type is begin return Smart_Find_File (N, Source); end Full_Source_Name; ---------------------- -- Full_Source_Name -- ---------------------- procedure Full_Source_Name (N : File_Name_Type; Full_File : out File_Name_Type; Attr : access File_Attributes) is begin Smart_Find_File (N, Source, Full_File, Attr.all); end Full_Source_Name; ------------------- -- Get_Directory -- ------------------- function Get_Directory (Name : File_Name_Type) return File_Name_Type is begin Get_Name_String (Name); for J in reverse 1 .. Name_Len loop if Is_Directory_Separator (Name_Buffer (J)) then Name_Len := J; return Name_Find; end if; end loop; Name_Len := Hostparm.Normalized_CWD'Length; Name_Buffer (1 .. Name_Len) := Hostparm.Normalized_CWD; return Name_Find; end Get_Directory; ------------------------------ -- Get_First_Main_File_Name -- ------------------------------ function Get_First_Main_File_Name return String is begin return File_Names (1).all; end Get_First_Main_File_Name; -------------------------- -- Get_Next_Dir_In_Path -- -------------------------- Search_Path_Pos : Integer; -- Keeps track of current position in search path. Initialized by the -- call to Get_Next_Dir_In_Path_Init, updated by Get_Next_Dir_In_Path. function Get_Next_Dir_In_Path (Search_Path : String_Access) return String_Access is Lower_Bound : Positive := Search_Path_Pos; Upper_Bound : Positive; begin loop while Lower_Bound <= Search_Path'Last and then Search_Path.all (Lower_Bound) = Path_Separator loop Lower_Bound := Lower_Bound + 1; end loop; exit when Lower_Bound > Search_Path'Last; Upper_Bound := Lower_Bound; while Upper_Bound <= Search_Path'Last and then Search_Path.all (Upper_Bound) /= Path_Separator loop Upper_Bound := Upper_Bound + 1; end loop; Search_Path_Pos := Upper_Bound; return new String'(Search_Path.all (Lower_Bound .. Upper_Bound - 1)); end loop; return null; end Get_Next_Dir_In_Path; ------------------------------- -- Get_Next_Dir_In_Path_Init -- ------------------------------- procedure Get_Next_Dir_In_Path_Init (Search_Path : String_Access) is begin Search_Path_Pos := Search_Path'First; end Get_Next_Dir_In_Path_Init; -------------------------------------- -- Get_Primary_Src_Search_Directory -- -------------------------------------- function Get_Primary_Src_Search_Directory return String_Ptr is begin return Src_Search_Directories.Table (Primary_Directory); end Get_Primary_Src_Search_Directory; ------------------------ -- Get_RTS_Search_Dir -- ------------------------ function Get_RTS_Search_Dir (Search_Dir : String; File_Type : Search_File_Type) return String_Ptr is procedure Get_Current_Dir (Dir : System.Address; Length : System.Address); pragma Import (C, Get_Current_Dir, "__gnat_get_current_dir"); Max_Path : Integer; pragma Import (C, Max_Path, "__gnat_max_path_len"); -- Maximum length of a path name Current_Dir : String_Ptr; Default_Search_Dir : String_Access; Default_Suffix_Dir : String_Access; Local_Search_Dir : String_Access; Norm_Search_Dir : String_Access; Result_Search_Dir : String_Access; Search_File : String_Access; Temp_String : String_Ptr; begin -- Add a directory separator at the end of the directory if necessary -- so that we can directly append a file to the directory if not Is_Directory_Separator (Search_Dir (Search_Dir'Last)) then Local_Search_Dir := new String'(Search_Dir & String'(1 => Directory_Separator)); else Local_Search_Dir := new String'(Search_Dir); end if; if File_Type = Include then Search_File := Include_Search_File; Default_Suffix_Dir := new String'("adainclude"); else Search_File := Objects_Search_File; Default_Suffix_Dir := new String'("adalib"); end if; Norm_Search_Dir := Local_Search_Dir; if Is_Absolute_Path (Norm_Search_Dir.all) then -- We first verify if there is a directory Include_Search_Dir -- containing default search directories Result_Search_Dir := Read_Default_Search_Dirs (Norm_Search_Dir, Search_File, null); Default_Search_Dir := new String'(Norm_Search_Dir.all & Default_Suffix_Dir.all); Free (Norm_Search_Dir); if Result_Search_Dir /= null then return String_Ptr (Result_Search_Dir); elsif Is_Directory (Default_Search_Dir.all) then return String_Ptr (Default_Search_Dir); else return null; end if; -- Search in the current directory else -- Get the current directory declare Buffer : String (1 .. Max_Path + 2); Path_Len : Natural := Max_Path; begin Get_Current_Dir (Buffer'Address, Path_Len'Address); if Path_Len = 0 then raise Program_Error; end if; if not Is_Directory_Separator (Buffer (Path_Len)) then Path_Len := Path_Len + 1; Buffer (Path_Len) := Directory_Separator; end if; Current_Dir := new String'(Buffer (1 .. Path_Len)); end; Norm_Search_Dir := new String'(Current_Dir.all & Local_Search_Dir.all); Result_Search_Dir := Read_Default_Search_Dirs (Norm_Search_Dir, Search_File, null); Default_Search_Dir := new String'(Norm_Search_Dir.all & Default_Suffix_Dir.all); Free (Norm_Search_Dir); if Result_Search_Dir /= null then return String_Ptr (Result_Search_Dir); elsif Is_Directory (Default_Search_Dir.all) then return String_Ptr (Default_Search_Dir); else -- Search in Search_Dir_Prefix/Search_Dir Norm_Search_Dir := new String' (Update_Path (Search_Dir_Prefix).all & Local_Search_Dir.all); Result_Search_Dir := Read_Default_Search_Dirs (Norm_Search_Dir, Search_File, null); Default_Search_Dir := new String'(Norm_Search_Dir.all & Default_Suffix_Dir.all); Free (Norm_Search_Dir); if Result_Search_Dir /= null then return String_Ptr (Result_Search_Dir); elsif Is_Directory (Default_Search_Dir.all) then return String_Ptr (Default_Search_Dir); else -- We finally search in Search_Dir_Prefix/rts-Search_Dir Temp_String := new String'(Update_Path (Search_Dir_Prefix).all & "rts-"); Norm_Search_Dir := new String'(Temp_String.all & Local_Search_Dir.all); Result_Search_Dir := Read_Default_Search_Dirs (Norm_Search_Dir, Search_File, null); Default_Search_Dir := new String'(Norm_Search_Dir.all & Default_Suffix_Dir.all); Free (Norm_Search_Dir); if Result_Search_Dir /= null then return String_Ptr (Result_Search_Dir); elsif Is_Directory (Default_Search_Dir.all) then return String_Ptr (Default_Search_Dir); else return null; end if; end if; end if; end if; end Get_RTS_Search_Dir; -------------------------------- -- Include_Dir_Default_Prefix -- -------------------------------- function Include_Dir_Default_Prefix return String_Access is begin if The_Include_Dir_Default_Prefix = null then The_Include_Dir_Default_Prefix := String_Access (Update_Path (Include_Dir_Default_Name)); end if; return The_Include_Dir_Default_Prefix; end Include_Dir_Default_Prefix; function Include_Dir_Default_Prefix return String is begin return Include_Dir_Default_Prefix.all; end Include_Dir_Default_Prefix; ---------------- -- Initialize -- ---------------- procedure Initialize is begin Number_File_Names := 0; Current_File_Name_Index := 0; Src_Search_Directories.Init; Lib_Search_Directories.Init; -- Start off by setting all suppress options, to False. The special -- overflow fields are set to Not_Set (they will be set by -gnatp, or -- by -gnato, or, if neither of these appear, in Adjust_Global_Switches -- in Gnat1drv). Suppress_Options := ((others => False), Not_Set, Not_Set); -- Reserve the first slot in the search paths table. This is the -- directory of the main source file or main library file and is filled -- in by each call to Next_Main_Source/Next_Main_Lib_File with the -- directory specified for this main source or library file. This is the -- directory which is searched first by default. This default search is -- inhibited by the option -I- for both source and library files. Src_Search_Directories.Set_Last (Primary_Directory); Src_Search_Directories.Table (Primary_Directory) := new String'(""); Lib_Search_Directories.Set_Last (Primary_Directory); Lib_Search_Directories.Table (Primary_Directory) := new String'(""); end Initialize; ------------------ -- Is_Directory -- ------------------ function Is_Directory (Name : C_File_Name; Attr : access File_Attributes) return Boolean is function Internal (N : C_File_Name; A : System.Address) return Integer; pragma Import (C, Internal, "__gnat_is_directory_attr"); begin return Internal (Name, Attr.all'Address) /= 0; end Is_Directory; ---------------------------- -- Is_Directory_Separator -- ---------------------------- function Is_Directory_Separator (C : Character) return Boolean is begin -- In addition to the default directory_separator allow the '/' to -- act as separator since this is allowed in MS-DOS and Windows. return C = Directory_Separator or else C = '/'; end Is_Directory_Separator; ------------------------- -- Is_Readonly_Library -- ------------------------- function Is_Readonly_Library (File : File_Name_Type) return Boolean is begin Get_Name_String (File); pragma Assert (Name_Buffer (Name_Len - 3 .. Name_Len) = ".ali"); return not Is_Writable_File (Name_Buffer (1 .. Name_Len)); end Is_Readonly_Library; ------------------------ -- Is_Executable_File -- ------------------------ function Is_Executable_File (Name : C_File_Name; Attr : access File_Attributes) return Boolean is function Internal (N : C_File_Name; A : System.Address) return Integer; pragma Import (C, Internal, "__gnat_is_executable_file_attr"); begin return Internal (Name, Attr.all'Address) /= 0; end Is_Executable_File; ---------------------- -- Is_Readable_File -- ---------------------- function Is_Readable_File (Name : C_File_Name; Attr : access File_Attributes) return Boolean is function Internal (N : C_File_Name; A : System.Address) return Integer; pragma Import (C, Internal, "__gnat_is_readable_file_attr"); begin return Internal (Name, Attr.all'Address) /= 0; end Is_Readable_File; --------------------- -- Is_Regular_File -- --------------------- function Is_Regular_File (Name : C_File_Name; Attr : access File_Attributes) return Boolean is function Internal (N : C_File_Name; A : System.Address) return Integer; pragma Import (C, Internal, "__gnat_is_regular_file_attr"); begin return Internal (Name, Attr.all'Address) /= 0; end Is_Regular_File; ---------------------- -- Is_Symbolic_Link -- ---------------------- function Is_Symbolic_Link (Name : C_File_Name; Attr : access File_Attributes) return Boolean is function Internal (N : C_File_Name; A : System.Address) return Integer; pragma Import (C, Internal, "__gnat_is_symbolic_link_attr"); begin return Internal (Name, Attr.all'Address) /= 0; end Is_Symbolic_Link; ---------------------- -- Is_Writable_File -- ---------------------- function Is_Writable_File (Name : C_File_Name; Attr : access File_Attributes) return Boolean is function Internal (N : C_File_Name; A : System.Address) return Integer; pragma Import (C, Internal, "__gnat_is_writable_file_attr"); begin return Internal (Name, Attr.all'Address) /= 0; end Is_Writable_File; ------------------- -- Lib_File_Name -- ------------------- function Lib_File_Name (Source_File : File_Name_Type; Munit_Index : Nat := 0) return File_Name_Type is begin Get_Name_String (Source_File); for J in reverse 2 .. Name_Len loop if Name_Buffer (J) = '.' then Name_Len := J - 1; exit; end if; end loop; if Munit_Index /= 0 then Add_Char_To_Name_Buffer (Multi_Unit_Index_Character); Add_Nat_To_Name_Buffer (Munit_Index); end if; Add_Char_To_Name_Buffer ('.'); Add_Str_To_Name_Buffer (ALI_Suffix.all); return Name_Find; end Lib_File_Name; ----------------- -- Locate_File -- ----------------- procedure Locate_File (N : File_Name_Type; T : File_Type; Dir : Natural; Name : String; Found : out File_Name_Type; Attr : access File_Attributes) is Dir_Name : String_Ptr; begin -- If Name is already an absolute path, do not look for a directory if Is_Absolute_Path (Name) then Dir_Name := No_Dir; elsif T = Library then Dir_Name := Lib_Search_Directories.Table (Dir); else pragma Assert (T /= Config); Dir_Name := Src_Search_Directories.Table (Dir); end if; declare Full_Name : String (1 .. Dir_Name'Length + Name'Length + 1); begin Full_Name (1 .. Dir_Name'Length) := Dir_Name.all; Full_Name (Dir_Name'Length + 1 .. Full_Name'Last - 1) := Name; Full_Name (Full_Name'Last) := ASCII.NUL; Attr.all := Unknown_Attributes; if not Is_Regular_File (Full_Name'Address, Attr) then Found := No_File; else -- If the file is in the current directory then return N itself if Dir_Name'Length = 0 then Found := N; else Name_Len := Full_Name'Length - 1; Name_Buffer (1 .. Name_Len) := Full_Name (1 .. Full_Name'Last - 1); Found := Name_Find; -- ??? Was Name_Enter, no obvious reason end if; end if; end; end Locate_File; ------------------------------- -- Matching_Full_Source_Name -- ------------------------------- function Matching_Full_Source_Name (N : File_Name_Type; T : Time_Stamp_Type) return File_Name_Type is begin Get_Name_String (N); declare File_Name : constant String := Name_Buffer (1 .. Name_Len); File : File_Name_Type := No_File; Attr : aliased File_Attributes; Last_Dir : Natural; begin if Opt.Look_In_Primary_Dir then Locate_File (N, Source, Primary_Directory, File_Name, File, Attr'Access); if File /= No_File and then T = File_Stamp (N) then return File; end if; end if; Last_Dir := Src_Search_Directories.Last; for D in Primary_Directory + 1 .. Last_Dir loop Locate_File (N, Source, D, File_Name, File, Attr'Access); if File /= No_File and then T = File_Stamp (File) then return File; end if; end loop; return No_File; end; end Matching_Full_Source_Name; ---------------- -- More_Files -- ---------------- function More_Files return Boolean is begin return (Current_File_Name_Index < Number_File_Names); end More_Files; ------------------------------- -- Nb_Dir_In_Obj_Search_Path -- ------------------------------- function Nb_Dir_In_Obj_Search_Path return Natural is begin if Opt.Look_In_Primary_Dir then return Lib_Search_Directories.Last - Primary_Directory + 1; else return Lib_Search_Directories.Last - Primary_Directory; end if; end Nb_Dir_In_Obj_Search_Path; ------------------------------- -- Nb_Dir_In_Src_Search_Path -- ------------------------------- function Nb_Dir_In_Src_Search_Path return Natural is begin if Opt.Look_In_Primary_Dir then return Src_Search_Directories.Last - Primary_Directory + 1; else return Src_Search_Directories.Last - Primary_Directory; end if; end Nb_Dir_In_Src_Search_Path; -------------------- -- Next_Main_File -- -------------------- function Next_Main_File return File_Name_Type is File_Name : String_Ptr; Dir_Name : String_Ptr; Fptr : Natural; begin pragma Assert (More_Files); Current_File_Name_Index := Current_File_Name_Index + 1; -- Get the file and directory name File_Name := File_Names (Current_File_Name_Index); Fptr := File_Name'First; for J in reverse File_Name'Range loop if Is_Directory_Separator (File_Name (J)) then if J = File_Name'Last then Fail ("File name missing"); end if; Fptr := J + 1; exit; end if; end loop; -- Save name of directory in which main unit resides for use in -- locating other units Dir_Name := new String'(File_Name (File_Name'First .. Fptr - 1)); case Running_Program is when Compiler => Src_Search_Directories.Table (Primary_Directory) := Dir_Name; Look_In_Primary_Directory_For_Current_Main := True; when Make => Src_Search_Directories.Table (Primary_Directory) := Dir_Name; if Fptr > File_Name'First then Look_In_Primary_Directory_For_Current_Main := True; end if; when Binder | Gnatls => Dir_Name := Normalize_Directory_Name (Dir_Name.all); Lib_Search_Directories.Table (Primary_Directory) := Dir_Name; when Unspecified => null; end case; Name_Len := File_Name'Last - Fptr + 1; Name_Buffer (1 .. Name_Len) := File_Name (Fptr .. File_Name'Last); Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len)); Current_Main := Name_Find; -- In the gnatmake case, the main file may have not have the -- extension. Try ".adb" first then ".ads" if Running_Program = Make then declare Orig_Main : constant File_Name_Type := Current_Main; begin if Strip_Suffix (Orig_Main) = Orig_Main then Current_Main := Append_Suffix_To_File_Name (Orig_Main, ".adb"); if Full_Source_Name (Current_Main) = No_File then Current_Main := Append_Suffix_To_File_Name (Orig_Main, ".ads"); if Full_Source_Name (Current_Main) = No_File then Current_Main := Orig_Main; end if; end if; end if; end; end if; return Current_Main; end Next_Main_File; ------------------------------ -- Normalize_Directory_Name -- ------------------------------ function Normalize_Directory_Name (Directory : String) return String_Ptr is function Is_Quoted (Path : String) return Boolean; pragma Inline (Is_Quoted); -- Returns true if Path is quoted (either double or single quotes) --------------- -- Is_Quoted -- --------------- function Is_Quoted (Path : String) return Boolean is First : constant Character := Path (Path'First); Last : constant Character := Path (Path'Last); begin if (First = ''' and then Last = ''') or else (First = '"' and then Last = '"') then return True; else return False; end if; end Is_Quoted; Result : String_Ptr; -- Start of processing for Normalize_Directory_Name begin if Directory'Length = 0 then Result := new String'(Hostparm.Normalized_CWD); elsif Is_Directory_Separator (Directory (Directory'Last)) then Result := new String'(Directory); elsif Is_Quoted (Directory) then -- This is a quoted string, it certainly means that the directory -- contains some spaces for example. We can safely remove the quotes -- here as the OS_Lib.Normalize_Arguments will be called before any -- spawn routines. This ensure that quotes will be added when needed. Result := new String (1 .. Directory'Length - 1); Result (1 .. Directory'Length - 2) := Directory (Directory'First + 1 .. Directory'Last - 1); Result (Result'Last) := Directory_Separator; else Result := new String (1 .. Directory'Length + 1); Result (1 .. Directory'Length) := Directory; Result (Directory'Length + 1) := Directory_Separator; end if; return Result; end Normalize_Directory_Name; --------------------- -- Number_Of_Files -- --------------------- function Number_Of_Files return Nat is begin return Number_File_Names; end Number_Of_Files; ------------------------------- -- Object_Dir_Default_Prefix -- ------------------------------- function Object_Dir_Default_Prefix return String is Object_Dir : String_Access := String_Access (Update_Path (Object_Dir_Default_Name)); begin if Object_Dir = null then return ""; else declare Result : constant String := Object_Dir.all; begin Free (Object_Dir); return Result; end; end if; end Object_Dir_Default_Prefix; ---------------------- -- Object_File_Name -- ---------------------- function Object_File_Name (N : File_Name_Type) return File_Name_Type is begin if N = No_File then return No_File; end if; Get_Name_String (N); Name_Len := Name_Len - ALI_Suffix'Length - 1; for J in Target_Object_Suffix'Range loop Name_Len := Name_Len + 1; Name_Buffer (Name_Len) := Target_Object_Suffix (J); end loop; return Name_Enter; end Object_File_Name; ------------------------------- -- OS_Exit_Through_Exception -- ------------------------------- procedure OS_Exit_Through_Exception (Status : Integer) is begin Current_Exit_Status := Status; raise Types.Terminate_Program; end OS_Exit_Through_Exception; -------------------------- -- OS_Time_To_GNAT_Time -- -------------------------- function OS_Time_To_GNAT_Time (T : OS_Time) return Time_Stamp_Type is GNAT_Time : Time_Stamp_Type; type Underlying_OS_Time is range -(2 ** (Standard'Address_Size - Integer'(1))) .. +(2 ** (Standard'Address_Size - Integer'(1)) - 1); -- Underlying_OS_Time is a redeclaration of OS_Time to allow integer -- manipulation. Remove this in favor of To_Ada/To_C once newer -- GNAT releases are available with these functions. function To_Int is new Unchecked_Conversion (OS_Time, Underlying_OS_Time); function From_Int is new Unchecked_Conversion (Underlying_OS_Time, OS_Time); TI : Underlying_OS_Time := To_Int (T); Y : Year_Type; Mo : Month_Type; D : Day_Type; H : Hour_Type; Mn : Minute_Type; S : Second_Type; begin if T = Invalid_Time then return Empty_Time_Stamp; end if; if On_Windows and then TI mod 2 > 0 then -- Windows ALI files had timestamps rounded to even seconds -- historically. The rounding was originally done in GM_Split. -- Now that GM_Split no longer does it, we are rounding it here -- only for ALI files. TI := TI + 1; end if; GM_Split (From_Int (TI), Y, Mo, D, H, Mn, S); Make_Time_Stamp (Year => Nat (Y), Month => Nat (Mo), Day => Nat (D), Hour => Nat (H), Minutes => Nat (Mn), Seconds => Nat (S), TS => GNAT_Time); return GNAT_Time; end OS_Time_To_GNAT_Time; ----------------- -- Prep_Suffix -- ----------------- function Prep_Suffix return String is begin return ".prep"; end Prep_Suffix; ------------------ -- Program_Name -- ------------------ function Program_Name (Nam : String; Prog : String) return String_Access is End_Of_Prefix : Natural := 0; Start_Of_Prefix : Positive := 1; Start_Of_Suffix : Positive; begin -- Get the name of the current program being executed Find_Program_Name; Start_Of_Suffix := Name_Len + 1; -- Find the target prefix if any, for the cross compilation case. -- For instance in "powerpc-elf-gcc" the target prefix is -- "powerpc-elf-" -- Ditto for suffix, e.g. in "gcc-4.1", the suffix is "-4.1" for J in reverse 1 .. Name_Len loop if Is_Directory_Separator (Name_Buffer (J)) or else Name_Buffer (J) = ':' then Start_Of_Prefix := J + 1; exit; end if; end loop; -- Find End_Of_Prefix for J in Start_Of_Prefix .. Name_Len - Prog'Length + 1 loop if Name_Buffer (J .. J + Prog'Length - 1) = Prog then End_Of_Prefix := J - 1; exit; end if; end loop; if End_Of_Prefix > 1 then Start_Of_Suffix := End_Of_Prefix + Prog'Length + 1; end if; -- Create the new program name return new String' (Name_Buffer (Start_Of_Prefix .. End_Of_Prefix) & Nam & Name_Buffer (Start_Of_Suffix .. Name_Len)); end Program_Name; ------------------------------ -- Read_Default_Search_Dirs -- ------------------------------ function Read_Default_Search_Dirs (Search_Dir_Prefix : String_Access; Search_File : String_Access; Search_Dir_Default_Name : String_Access) return String_Access is Prefix_Len : constant Integer := Search_Dir_Prefix.all'Length; Buffer : String (1 .. Prefix_Len + Search_File.all'Length + 1); File_FD : File_Descriptor; S, S1 : String_Access; Len : Integer; Curr : Integer; Actual_Len : Integer; J1 : Integer; Prev_Was_Separator : Boolean; Nb_Relative_Dir : Integer; function Is_Relative (S : String; K : Positive) return Boolean; pragma Inline (Is_Relative); -- Returns True if a relative directory specification is found -- in S at position K, False otherwise. ----------------- -- Is_Relative -- ----------------- function Is_Relative (S : String; K : Positive) return Boolean is begin return not Is_Absolute_Path (S (K .. S'Last)); end Is_Relative; -- Start of processing for Read_Default_Search_Dirs begin -- Construct a C compatible character string buffer Buffer (1 .. Search_Dir_Prefix.all'Length) := Search_Dir_Prefix.all; Buffer (Search_Dir_Prefix.all'Length + 1 .. Buffer'Last - 1) := Search_File.all; Buffer (Buffer'Last) := ASCII.NUL; File_FD := Open_Read (Buffer'Address, Binary); if File_FD = Invalid_FD then return Search_Dir_Default_Name; end if; Len := Integer (File_Length (File_FD)); -- An extra character for a trailing Path_Separator is allocated S := new String (1 .. Len + 1); S (Len + 1) := Path_Separator; -- Read the file. Note that the loop is probably not necessary since the -- whole file is read at once but the loop is harmless and that way we -- are sure to accommodate systems where this is not the case. Curr := 1; Actual_Len := Len; while Actual_Len /= 0 loop Actual_Len := Read (File_FD, S (Curr)'Address, Len); Curr := Curr + Actual_Len; end loop; -- Process the file, dealing with path separators Prev_Was_Separator := True; Nb_Relative_Dir := 0; for J in 1 .. Len loop -- Treat any control character as a path separator. Note that we do -- not treat space as a path separator (we used to treat space as a -- path separator in an earlier version). That way space can appear -- as a legitimate character in a path name. -- Why do we treat all control characters as path separators??? if S (J) in ASCII.NUL .. ASCII.US then S (J) := Path_Separator; end if; -- Test for explicit path separator (or control char as above) if S (J) = Path_Separator then Prev_Was_Separator := True; -- If not path separator, register use of relative directory else if Prev_Was_Separator and then Is_Relative (S.all, J) then Nb_Relative_Dir := Nb_Relative_Dir + 1; end if; Prev_Was_Separator := False; end if; end loop; if Nb_Relative_Dir = 0 then return S; end if; -- Add the Search_Dir_Prefix to all relative paths S1 := new String (1 .. S'Length + Nb_Relative_Dir * Prefix_Len); J1 := 1; Prev_Was_Separator := True; for J in 1 .. Len + 1 loop if S (J) = Path_Separator then Prev_Was_Separator := True; else if Prev_Was_Separator and then Is_Relative (S.all, J) then S1 (J1 .. J1 + Prefix_Len - 1) := Search_Dir_Prefix.all; J1 := J1 + Prefix_Len; end if; Prev_Was_Separator := False; end if; S1 (J1) := S (J); J1 := J1 + 1; end loop; Free (S); return S1; end Read_Default_Search_Dirs; ----------------------- -- Read_Library_Info -- ----------------------- function Read_Library_Info (Lib_File : File_Name_Type; Fatal_Err : Boolean := False) return Text_Buffer_Ptr is File : File_Name_Type; Attr : aliased File_Attributes; begin Find_File (Lib_File, Library, File, Attr'Access); return Read_Library_Info_From_Full (Full_Lib_File => File, Lib_File_Attr => Attr'Access, Fatal_Err => Fatal_Err); end Read_Library_Info; --------------------------------- -- Read_Library_Info_From_Full -- --------------------------------- function Read_Library_Info_From_Full (Full_Lib_File : File_Name_Type; Lib_File_Attr : access File_Attributes; Fatal_Err : Boolean := False) return Text_Buffer_Ptr is Lib_FD : File_Descriptor; -- The file descriptor for the current library file. A negative value -- indicates failure to open the specified source file. Len : Integer; -- Length of source file text (ALI). If it doesn't fit in an integer -- we're probably stuck anyway (>2 gigs of source seems a lot, and -- there are other places in the compiler that make this assumption). Text : Text_Buffer_Ptr; -- Allocated text buffer Status : Boolean; pragma Warnings (Off, Status); -- For the calls to Close begin Current_Full_Lib_Name := Full_Lib_File; Current_Full_Obj_Name := Object_File_Name (Current_Full_Lib_Name); if Current_Full_Lib_Name = No_File then if Fatal_Err then Fail ("Cannot find: " & Name_Buffer (1 .. Name_Len)); else Current_Full_Obj_Stamp := Empty_Time_Stamp; return null; end if; end if; Get_Name_String (Current_Full_Lib_Name); Name_Buffer (Name_Len + 1) := ASCII.NUL; -- Open the library FD, note that we open in binary mode, because as -- documented in the spec, the caller is expected to handle either -- DOS or Unix mode files, and there is no point in wasting time on -- text translation when it is not required. Lib_FD := Open_Read (Name_Buffer'Address, Binary); if Lib_FD = Invalid_FD then if Fatal_Err then Fail ("Cannot open: " & Name_Buffer (1 .. Name_Len)); else Current_Full_Obj_Stamp := Empty_Time_Stamp; return null; end if; end if; -- Compute the length of the file (potentially also preparing other data -- like the timestamp and whether the file is read-only, for future use) Len := Integer (File_Length (Name_Buffer'Address, Lib_File_Attr)); -- Check for object file consistency if requested if Opt.Check_Object_Consistency then -- On most systems, this does not result in an extra system call Current_Full_Lib_Stamp := OS_Time_To_GNAT_Time (File_Time_Stamp (Name_Buffer'Address, Lib_File_Attr)); -- ??? One system call here Current_Full_Obj_Stamp := File_Stamp (Current_Full_Obj_Name); if Current_Full_Obj_Stamp (1) = ' ' then -- When the library is readonly always assume object is consistent -- The call to Is_Writable_File only results in a system call on -- some systems, but in most cases it has already been computed as -- part of the call to File_Length above. Get_Name_String (Current_Full_Lib_Name); Name_Buffer (Name_Len + 1) := ASCII.NUL; if not Is_Writable_File (Name_Buffer'Address, Lib_File_Attr) then Current_Full_Obj_Stamp := Current_Full_Lib_Stamp; elsif Fatal_Err then Get_Name_String (Current_Full_Obj_Name); Close (Lib_FD, Status); -- No need to check the status, we fail anyway Fail ("Cannot find: " & Name_Buffer (1 .. Name_Len)); else Current_Full_Obj_Stamp := Empty_Time_Stamp; Close (Lib_FD, Status); -- No need to check the status, we return null anyway return null; end if; elsif Current_Full_Obj_Stamp < Current_Full_Lib_Stamp then Close (Lib_FD, Status); -- No need to check the status, we return null anyway return null; end if; end if; -- Read data from the file declare Actual_Len : Integer := 0; Lo : constant Text_Ptr := 0; -- Low bound for allocated text buffer Hi : Text_Ptr := Text_Ptr (Len); -- High bound for allocated text buffer. Note length is Len + 1 -- which allows for extra EOF character at the end of the buffer. begin -- Allocate text buffer. Note extra character at end for EOF Text := new Text_Buffer (Lo .. Hi); -- Some systems have file types that require one read per line, -- so read until we get the Len bytes or until there are no more -- characters. Hi := Lo; loop Actual_Len := Read (Lib_FD, Text (Hi)'Address, Len); Hi := Hi + Text_Ptr (Actual_Len); exit when Actual_Len = Len or else Actual_Len <= 0; end loop; Text (Hi) := EOF; end; -- Read is complete, close file and we are done Close (Lib_FD, Status); -- The status should never be False. But, if it is, what can we do? -- So, we don't test it. return Text; end Read_Library_Info_From_Full; ---------------------- -- Read_Source_File -- ---------------------- procedure Read_Source_File (N : File_Name_Type; Lo : Source_Ptr; Hi : out Source_Ptr; Src : out Source_Buffer_Ptr; FD : out File_Descriptor; T : File_Type := Source) is Len : Integer; -- Length of file, assume no more than 2 gigabytes of source Actual_Len : Integer; Status : Boolean; pragma Warnings (Off, Status); -- For the call to Close begin Current_Full_Source_Name := Find_File (N, T, Full_Name => True); Current_Full_Source_Stamp := File_Stamp (Current_Full_Source_Name); if Current_Full_Source_Name = No_File then -- If we were trying to access the main file and we could not find -- it, we have an error. if N = Current_Main then Get_Name_String (N); Fail ("Cannot find: " & Name_Buffer (1 .. Name_Len)); end if; FD := Null_FD; Src := null; Hi := No_Location; return; end if; Get_Name_String (Current_Full_Source_Name); Name_Buffer (Name_Len + 1) := ASCII.NUL; -- Open the source FD, note that we open in binary mode, because as -- documented in the spec, the caller is expected to handle either -- DOS or Unix mode files, and there is no point in wasting time on -- text translation when it is not required. FD := Open_Read (Name_Buffer'Address, Binary); if FD = Invalid_FD then Src := null; Hi := No_Location; return; end if; -- If it's a Source file, print out the file name, if requested, and if -- it's not part of the runtimes, store it in File_Name_Chars. We don't -- want to print non-Source files, like GNAT-TEMP-000001.TMP used to -- pass information from gprbuild to gcc. We don't want to save runtime -- file names, because we don't want users to send them in bug reports. if T = Source then declare Name : String renames Name_Buffer (1 .. Name_Len); Inc : String renames Include_Dir_Default_Prefix.all; Part_Of_Runtimes : constant Boolean := Inc /= "" and then Inc'Length < Name_Len and then Name_Buffer (1 .. Inc'Length) = Inc; begin if Debug.Debug_Flag_Dot_N then Write_Line (Name); end if; if not Part_Of_Runtimes then File_Name_Chars.Append_All (File_Name_Chars.Table_Type (Name)); File_Name_Chars.Append (ASCII.LF); end if; end; end if; -- Prepare to read data from the file Len := Integer (File_Length (FD)); -- Set Hi so that length is one more than the physical length, -- allowing for the extra EOF character at the end of the buffer Hi := Lo + Source_Ptr (Len); -- Do the actual read operation declare Var_Ptr : constant Source_Buffer_Ptr_Var := new Source_Buffer (Lo .. Hi); -- Allocate source buffer, allowing extra character at end for EOF begin -- Some systems have file types that require one read per line, -- so read until we get the Len bytes or until there are no more -- characters. Hi := Lo; loop Actual_Len := Read (FD, Var_Ptr (Hi)'Address, Len); Hi := Hi + Source_Ptr (Actual_Len); exit when Actual_Len = Len or else Actual_Len <= 0; end loop; Var_Ptr (Hi) := EOF; Src := Var_Ptr.all'Access; end; -- Read is complete, get time stamp and close file and we are done Close (FD, Status); -- The status should never be False. But, if it is, what can we do? -- So, we don't test it. -- ???We don't really need to return Hi anymore; We could get rid of -- it. We could also make this into a function. pragma Assert (Hi = Src'Last); end Read_Source_File; ------------------- -- Relocate_Path -- ------------------- function Relocate_Path (Prefix : String; Path : String) return String_Ptr is S : String_Ptr; procedure set_std_prefix (S : String; Len : Integer); pragma Import (C, set_std_prefix); begin if Std_Prefix = null then Std_Prefix := Executable_Prefix; if Std_Prefix.all /= "" then -- Remove trailing directory separator when calling set_std_prefix set_std_prefix (Std_Prefix.all, Std_Prefix'Length - 1); end if; end if; if Path'Last >= Prefix'Last and then Path (Prefix'Range) = Prefix then if Std_Prefix.all /= "" then S := new String (1 .. Std_Prefix'Length + Path'Last - Prefix'Last); S (1 .. Std_Prefix'Length) := Std_Prefix.all; S (Std_Prefix'Length + 1 .. S'Last) := Path (Prefix'Last + 1 .. Path'Last); return S; end if; end if; return new String'(Path); end Relocate_Path; ----------------- -- Set_Program -- ----------------- procedure Set_Program (P : Program_Type) is begin if Program_Set then Fail ("Set_Program called twice"); end if; Program_Set := True; Running_Program := P; end Set_Program; ---------------- -- Shared_Lib -- ---------------- function Shared_Lib (Name : String) return String is Library : String (1 .. Name'Length + Library_Version'Length + 3); -- 3 = 2 for "-l" + 1 for "-" before lib version begin Library (1 .. 2) := "-l"; Library (3 .. 2 + Name'Length) := Name; Library (3 + Name'Length) := '-'; Library (4 + Name'Length .. Library'Last) := Library_Version; return Library; end Shared_Lib; ---------------------- -- Smart_File_Stamp -- ---------------------- function Smart_File_Stamp (N : File_Name_Type; T : File_Type) return Time_Stamp_Type is File : File_Name_Type; Attr : aliased File_Attributes; begin if not File_Cache_Enabled then Find_File (N, T, File, Attr'Access); else Smart_Find_File (N, T, File, Attr); end if; if File = No_File then return Empty_Time_Stamp; else Get_Name_String (File); Name_Buffer (Name_Len + 1) := ASCII.NUL; return OS_Time_To_GNAT_Time (File_Time_Stamp (Name_Buffer'Address, Attr'Access)); end if; end Smart_File_Stamp; --------------------- -- Smart_Find_File -- --------------------- function Smart_Find_File (N : File_Name_Type; T : File_Type) return File_Name_Type is File : File_Name_Type; Attr : File_Attributes; begin Smart_Find_File (N, T, File, Attr); return File; end Smart_Find_File; --------------------- -- Smart_Find_File -- --------------------- procedure Smart_Find_File (N : File_Name_Type; T : File_Type; Found : out File_Name_Type; Attr : out File_Attributes) is Info : File_Info_Cache; begin if not File_Cache_Enabled then Find_File (N, T, Info.File, Info.Attr'Access); else Info := File_Name_Hash_Table.Get (N); if Info.File = No_File then Find_File (N, T, Info.File, Info.Attr'Access); File_Name_Hash_Table.Set (N, Info); end if; end if; Found := Info.File; Attr := Info.Attr; end Smart_Find_File; ---------------------- -- Source_File_Data -- ---------------------- procedure Source_File_Data (Cache : Boolean) is begin File_Cache_Enabled := Cache; end Source_File_Data; ----------------------- -- Source_File_Stamp -- ----------------------- function Source_File_Stamp (N : File_Name_Type) return Time_Stamp_Type is begin return Smart_File_Stamp (N, Source); end Source_File_Stamp; --------------------- -- Strip_Directory -- --------------------- function Strip_Directory (Name : File_Name_Type) return File_Name_Type is begin Get_Name_String (Name); for J in reverse 1 .. Name_Len - 1 loop -- If we find the last directory separator if Is_Directory_Separator (Name_Buffer (J)) then -- Return part of Name that follows this last directory separator Name_Buffer (1 .. Name_Len - J) := Name_Buffer (J + 1 .. Name_Len); Name_Len := Name_Len - J; return Name_Find; end if; end loop; -- There were no directory separator, just return Name return Name; end Strip_Directory; ------------------ -- Strip_Suffix -- ------------------ function Strip_Suffix (Name : File_Name_Type) return File_Name_Type is begin Get_Name_String (Name); for J in reverse 2 .. Name_Len loop -- If we found the last '.', return part of Name that precedes it if Name_Buffer (J) = '.' then Name_Len := J - 1; return Name_Enter; end if; end loop; return Name; end Strip_Suffix; --------------------------- -- To_Canonical_File_List -- --------------------------- function To_Canonical_File_List (Wildcard_Host_File : String; Only_Dirs : Boolean) return String_Access_List_Access is function To_Canonical_File_List_Init (Host_File : Address; Only_Dirs : Integer) return Integer; pragma Import (C, To_Canonical_File_List_Init, "__gnat_to_canonical_file_list_init"); function To_Canonical_File_List_Next return Address; pragma Import (C, To_Canonical_File_List_Next, "__gnat_to_canonical_file_list_next"); procedure To_Canonical_File_List_Free; pragma Import (C, To_Canonical_File_List_Free, "__gnat_to_canonical_file_list_free"); Num_Files : Integer; C_Wildcard_Host_File : String (1 .. Wildcard_Host_File'Length + 1); begin C_Wildcard_Host_File (1 .. Wildcard_Host_File'Length) := Wildcard_Host_File; C_Wildcard_Host_File (C_Wildcard_Host_File'Last) := ASCII.NUL; -- Do the expansion and say how many there are Num_Files := To_Canonical_File_List_Init (C_Wildcard_Host_File'Address, Boolean'Pos (Only_Dirs)); declare Canonical_File_List : String_Access_List (1 .. Num_Files); Canonical_File_Addr : Address; Canonical_File_Len : CRTL.size_t; begin -- Retrieve the expanded directory names and build the list for J in 1 .. Num_Files loop Canonical_File_Addr := To_Canonical_File_List_Next; Canonical_File_Len := C_String_Length (Canonical_File_Addr); Canonical_File_List (J) := To_Path_String_Access (Canonical_File_Addr, Canonical_File_Len); end loop; -- Free up the storage To_Canonical_File_List_Free; return new String_Access_List'(Canonical_File_List); end; end To_Canonical_File_List; ---------------------- -- To_Host_Dir_Spec -- ---------------------- function To_Host_Dir_Spec (Canonical_Dir : String; Prefix_Style : Boolean) return String_Access is function To_Host_Dir_Spec (Canonical_Dir : Address; Prefix_Flag : Integer) return Address; pragma Import (C, To_Host_Dir_Spec, "__gnat_to_host_dir_spec"); C_Canonical_Dir : String (1 .. Canonical_Dir'Length + 1); Host_Dir_Addr : Address; Host_Dir_Len : CRTL.size_t; begin C_Canonical_Dir (1 .. Canonical_Dir'Length) := Canonical_Dir; C_Canonical_Dir (C_Canonical_Dir'Last) := ASCII.NUL; if Prefix_Style then Host_Dir_Addr := To_Host_Dir_Spec (C_Canonical_Dir'Address, 1); else Host_Dir_Addr := To_Host_Dir_Spec (C_Canonical_Dir'Address, 0); end if; Host_Dir_Len := C_String_Length (Host_Dir_Addr); if Host_Dir_Len = 0 then return null; else return To_Path_String_Access (Host_Dir_Addr, Host_Dir_Len); end if; end To_Host_Dir_Spec; ----------------------- -- To_Host_File_Spec -- ----------------------- function To_Host_File_Spec (Canonical_File : String) return String_Access is function To_Host_File_Spec (Canonical_File : Address) return Address; pragma Import (C, To_Host_File_Spec, "__gnat_to_host_file_spec"); C_Canonical_File : String (1 .. Canonical_File'Length + 1); Host_File_Addr : Address; Host_File_Len : CRTL.size_t; begin C_Canonical_File (1 .. Canonical_File'Length) := Canonical_File; C_Canonical_File (C_Canonical_File'Last) := ASCII.NUL; Host_File_Addr := To_Host_File_Spec (C_Canonical_File'Address); Host_File_Len := C_String_Length (Host_File_Addr); if Host_File_Len = 0 then return null; else return To_Path_String_Access (Host_File_Addr, Host_File_Len); end if; end To_Host_File_Spec; --------------------------- -- To_Path_String_Access -- --------------------------- function To_Path_String_Access (Path_Addr : Address; Path_Len : CRTL.size_t) return String_Access is subtype Path_String is String (1 .. Integer (Path_Len)); type Path_String_Access is access Path_String; function Address_To_Access is new Unchecked_Conversion (Source => Address, Target => Path_String_Access); Path_Access : constant Path_String_Access := Address_To_Access (Path_Addr); Return_Val : String_Access; begin Return_Val := new String (1 .. Integer (Path_Len)); for J in 1 .. Integer (Path_Len) loop Return_Val (J) := Path_Access (J); end loop; return Return_Val; end To_Path_String_Access; ----------------- -- Update_Path -- ----------------- function Update_Path (Path : String_Ptr) return String_Ptr is function C_Update_Path (Path, Component : Address) return Address; pragma Import (C, C_Update_Path, "update_path"); In_Length : constant Integer := Path'Length; In_String : String (1 .. In_Length + 1); Component_Name : aliased String := "GCC" & ASCII.NUL; Result_Ptr : Address; Result_Length : CRTL.size_t; Out_String : String_Ptr; begin In_String (1 .. In_Length) := Path.all; In_String (In_Length + 1) := ASCII.NUL; Result_Ptr := C_Update_Path (In_String'Address, Component_Name'Address); Result_Length := CRTL.strlen (Result_Ptr); Out_String := new String (1 .. Integer (Result_Length)); CRTL.strncpy (Out_String.all'Address, Result_Ptr, Result_Length); return Out_String; end Update_Path; ---------------- -- Write_Info -- ---------------- procedure Write_Info (Info : String) is begin Write_With_Check (Info'Address, Info'Length); Write_With_Check (EOL'Address, 1); end Write_Info; ------------------------ -- Write_Program_Name -- ------------------------ procedure Write_Program_Name is Save_Buffer : constant String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); begin Find_Program_Name; -- Convert the name to lower case so error messages are the same on -- all systems. for J in 1 .. Name_Len loop if Name_Buffer (J) in 'A' .. 'Z' then Name_Buffer (J) := Character'Val (Character'Pos (Name_Buffer (J)) + 32); end if; end loop; Write_Str (Name_Buffer (1 .. Name_Len)); -- Restore Name_Buffer which was clobbered by the call to -- Find_Program_Name Name_Len := Save_Buffer'Last; Name_Buffer (1 .. Name_Len) := Save_Buffer; end Write_Program_Name; ---------------------- -- Write_With_Check -- ---------------------- procedure Write_With_Check (A : Address; N : Integer) is Ignore : Boolean; begin if N = Write (Output_FD, A, N) then return; else Write_Str ("error: disk full writing "); Write_Name_Decoded (Output_File_Name); Write_Eol; Name_Len := Name_Len + 1; Name_Buffer (Name_Len) := ASCII.NUL; Delete_File (Name_Buffer'Address, Ignore); Exit_Program (E_Fatal); end if; end Write_With_Check; ---------------------------- -- Package Initialization -- ---------------------------- procedure Reset_File_Attributes (Attr : System.Address); pragma Import (C, Reset_File_Attributes, "__gnat_reset_attributes"); begin Initialization : declare function Get_Default_Identifier_Character_Set return Character; pragma Import (C, Get_Default_Identifier_Character_Set, "__gnat_get_default_identifier_character_set"); -- Function to determine the default identifier character set, -- which is system dependent. See Opt package spec for a list of -- the possible character codes and their interpretations. function Get_Maximum_File_Name_Length return Int; pragma Import (C, Get_Maximum_File_Name_Length, "__gnat_get_maximum_file_name_length"); -- Function to get maximum file name length for system Sizeof_File_Attributes : Integer; pragma Import (C, Sizeof_File_Attributes, "__gnat_size_of_file_attributes"); begin pragma Assert (Sizeof_File_Attributes <= File_Attributes_Size); Reset_File_Attributes (Unknown_Attributes'Address); Identifier_Character_Set := Get_Default_Identifier_Character_Set; Maximum_File_Name_Length := Get_Maximum_File_Name_Length; -- Following should be removed by having above function return -- Integer'Last as indication of no maximum instead of -1 ??? if Maximum_File_Name_Length = -1 then Maximum_File_Name_Length := Int'Last; end if; Src_Search_Directories.Set_Last (Primary_Directory); Src_Search_Directories.Table (Primary_Directory) := new String'(""); Lib_Search_Directories.Set_Last (Primary_Directory); Lib_Search_Directories.Table (Primary_Directory) := new String'(""); Osint.Initialize; end Initialization; end Osint;
-- -- Copyright 2021 (C) Jeremy Grosser <jeremy@synack.me> -- -- SPDX-License-Identifier: Apache-2.0 -- with Interfaces.C; package Notcurses.Progress_Bar is type Notcurses_Progress_Bar is private; subtype Progress_Value is Interfaces.C.double range 0.0 .. 1.0; function Create (Plane : Notcurses_Plane; Retrograde : Boolean := False) return Notcurses_Progress_Bar; procedure Set_Progress (This : Notcurses_Progress_Bar; Progress : Progress_Value); function Progress (This : Notcurses_Progress_Bar) return Progress_Value; procedure Destroy (This : in out Notcurses_Progress_Bar); private type Notcurses_Progress_Bar is access all Thin.ncprogbar; end Notcurses.Progress_Bar;
-- CC1224A.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- OBJECTIVE: -- FOR ARRAY TYPES WITH A NONLIMITED COMPONENT TYPE (OF A FORMAL -- AND NONFORMAL GENERIC TYPE), CHECK THAT THE FOLLOWING OPERATIONS -- ARE IMPLICITY DECLARED AND ARE, THEREFORE, AVAILABLE WITHIN THE -- GENERIC UNIT: ASSIGNMENT, THE OPERATION ASSOCIATED WITH -- AGGREGATE NOTATION, MEMBERSHIP TESTS, THE OPERATION ASSOCIATED -- WITH INDEXED COMPONENTS, QUALIFICATION, EXPLICIT CONVERSION, -- 'SIZE, 'ADDRESS, 'FIRST, 'FIRST (N), 'LAST, 'LAST (N), -- 'RANGE, 'RANGE (N), 'LENGTH, 'LENGTH (N). -- HISTORY: -- R.WILLIAMS 10/6/86 -- EDWARD V. BERARD 8/10/90 ADDED CHECKS FOR MULTI-DIMENSIONAL -- ARRAYS -- LDC 10/10/90 CHANGED DECLARATIONS OF AD1 - AD6 TO PROCEDURE -- CALLS OF FA1 - FA6 TO ADDRESS_CHECK AS SUGGESTED -- BY THE CRG. -- PWN 01/31/95 REMOVED INCONSISTENCIES WITH ADA 9X. WITH SYSTEM ; WITH REPORT ; PROCEDURE CC1224A IS SHORT_START : CONSTANT := -10 ; SHORT_END : CONSTANT := 10 ; TYPE SHORT_RANGE IS RANGE SHORT_START .. SHORT_END ; SHORT_LENGTH : CONSTANT NATURAL := (SHORT_END - SHORT_START + 1) ; MEDIUM_START : CONSTANT := 1 ; MEDIUM_END : CONSTANT := 15 ; TYPE MEDIUM_RANGE IS RANGE MEDIUM_START .. MEDIUM_END ; MEDIUM_LENGTH : CONSTANT NATURAL := (MEDIUM_END - MEDIUM_START + 1) ; TYPE MONTH_TYPE IS (JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC) ; TYPE DAY_TYPE IS RANGE 1 .. 31 ; TYPE YEAR_TYPE IS RANGE 1904 .. 2050 ; TYPE DATE IS RECORD MONTH : MONTH_TYPE ; DAY : DAY_TYPE ; YEAR : YEAR_TYPE ; END RECORD ; TODAY : DATE := (AUG, 10, 1990) ; TYPE FIRST_TEMPLATE IS ARRAY (SHORT_RANGE RANGE <>, MEDIUM_RANGE RANGE <>) OF DATE ; TYPE SECOND_TEMPLATE IS ARRAY (SHORT_RANGE, MEDIUM_RANGE) OF DATE ; FIRST_ARRAY : FIRST_TEMPLATE (-10 .. 10, 6 .. 10) ; SECOND_ARRAY : FIRST_TEMPLATE (0 .. 7, 1 .. 15) ; THIRD_ARRAY : SECOND_TEMPLATE ; FOURTH_ARRAY : SECOND_TEMPLATE ; SUBTYPE SUBINT IS INTEGER RANGE REPORT.IDENT_INT (1) .. REPORT.IDENT_INT (6); TYPE ARRA IS ARRAY (SUBINT) OF SUBINT; A1 : ARRA := (REPORT.IDENT_INT (1) .. REPORT.IDENT_INT (6) => 1); A2 : ARRA := (A1'RANGE => 2); TYPE ARRB IS ARRAY (SUBINT RANGE <>) OF DATE ; A3 : ARRB (1 .. 6) := (REPORT.IDENT_INT (1) .. REPORT.IDENT_INT (6) => TODAY); TYPE ARRC IS ARRAY (SUBINT RANGE <>, SUBINT RANGE <>) OF SUBINT; A4 : CONSTANT ARRC := (1 .. 6 => (1 .. 6 => 4)); TYPE ARRD IS ARRAY (SUBINT, SUBINT) OF SUBINT; A5 : ARRD := (A4'RANGE (1) => (A4'RANGE (2) => 5)); TYPE ARRE IS ARRAY (SUBINT) OF DATE ; A6 : ARRE := (A1'RANGE => TODAY); FUNCTION "=" (LEFT : IN SYSTEM.ADDRESS ; RIGHT : IN SYSTEM.ADDRESS ) RETURN BOOLEAN RENAMES SYSTEM."=" ; GENERIC TYPE T1 IS (<>); TYPE T2 IS PRIVATE; X2 : T2; TYPE FARR1 IS ARRAY (SUBINT) OF T1; FA1 : FARR1; TYPE FARR2 IS ARRAY (SUBINT) OF SUBINT; FA2 : FARR2; TYPE FARR3 IS ARRAY (SUBINT RANGE <>) OF T2; FA3 : FARR3; TYPE FARR4 IS ARRAY (SUBINT RANGE <>, SUBINT RANGE <>) OF T1; FA4 : FARR4; TYPE FARR5 IS ARRAY (SUBINT, SUBINT) OF SUBINT; FA5 : FARR5; TYPE FARR6 IS ARRAY (T1) OF T2; FA6 : FARR6; TYPE FARR7 IS ARRAY (T1) OF T2; FA7 : FARR7; PROCEDURE P ; GENERIC TYPE FIRST_INDEX IS (<>) ; TYPE SECOND_INDEX IS (<>) ; TYPE UNCONSTRAINED_ARRAY IS ARRAY (FIRST_INDEX RANGE <>, SECOND_INDEX RANGE <>) OF DATE ; PROCEDURE TEST_PROCEDURE (FIRST : IN UNCONSTRAINED_ARRAY ; FFIFS : IN FIRST_INDEX ; FFILS : IN FIRST_INDEX ; FSIFS : IN SECOND_INDEX ; FSILS : IN SECOND_INDEX ; FFLEN : IN NATURAL ; FSLEN : IN NATURAL ; FFIRT : IN FIRST_INDEX ; FSIRT : IN SECOND_INDEX ; SECOND : IN UNCONSTRAINED_ARRAY ; SFIFS : IN FIRST_INDEX ; SFILS : IN FIRST_INDEX ; SSIFS : IN SECOND_INDEX ; SSILS : IN SECOND_INDEX ; SFLEN : IN NATURAL ; SSLEN : IN NATURAL ; SFIRT : IN FIRST_INDEX ; SSIRT : IN SECOND_INDEX ; REMARKS : IN STRING) ; GENERIC TYPE FIRST_INDEX IS (<>) ; TYPE SECOND_INDEX IS (<>) ; TYPE COMPONENT_TYPE IS PRIVATE ; TYPE CONSTRAINED_ARRAY IS ARRAY (FIRST_INDEX,SECOND_INDEX) OF COMPONENT_TYPE ; PROCEDURE CTEST_PROCEDURE (FIRST : IN CONSTRAINED_ARRAY ; FFIRT : IN FIRST_INDEX ; FSIRT : IN SECOND_INDEX ; SECOND : IN CONSTRAINED_ARRAY ; SFIRT : IN FIRST_INDEX ; SSIRT : IN SECOND_INDEX ; REMARKS : IN STRING) ; PROCEDURE P IS IN1 : INTEGER := FA1'SIZE; IN2 : INTEGER := FA2'SIZE; IN3 : INTEGER := FA3'SIZE; IN4 : INTEGER := FA4'SIZE; IN5 : INTEGER := FA5'SIZE; IN6 : INTEGER := FA6'SIZE; B1 : FARR1; B2 : FARR2; SUBTYPE SARR3 IS FARR3 (FA3'RANGE); B3 : SARR3; SUBTYPE SARR4 IS FARR4 (FA4'RANGE (1), FA4'RANGE (2)); B4 : SARR4; B5 : FARR5; B6 : FARR6 ; PROCEDURE ADDRESS_CHECK(ADDRESS : SYSTEM.ADDRESS) IS BEGIN IF REPORT.EQUAL(1, REPORT.IDENT_INT(2)) THEN REPORT.COMMENT("DON'T OPTIMIZE OUT ADDRESS_CHECK"); END IF; END ADDRESS_CHECK; BEGIN -- P ADDRESS_CHECK(FA1'ADDRESS); ADDRESS_CHECK(FA2'ADDRESS); ADDRESS_CHECK(FA3'ADDRESS); ADDRESS_CHECK(FA4'ADDRESS); ADDRESS_CHECK(FA5'ADDRESS); ADDRESS_CHECK(FA6'ADDRESS); B1 := FA1; IF B1 /= FARR1 (FA1) THEN REPORT.FAILED ("INCORRECT RESULTS - 1" ); END IF; B2 := FA2; IF B2 /= FARR2 (A2) THEN REPORT.FAILED ("INCORRECT RESULTS - 2" ); END IF; B3 := FA3; IF B3 /= FARR3 (FA3) THEN REPORT.FAILED ("INCORRECT RESULTS - 3" ); END IF; B4 := FA4; IF B4 /= FARR4 (FA4) THEN REPORT.FAILED ("INCORRECT RESULTS - 4" ); END IF; B5 := FA5; IF B5 /= FARR5 (A5) THEN REPORT.FAILED ("INCORRECT RESULTS - 5" ); END IF; B6 := FA6; IF B6 /= FARR6 (FA6) THEN REPORT.FAILED ("INCORRECT RESULTS - 6" ); END IF; IF FA7 /= FARR7 (FA6) THEN REPORT.FAILED ("INCORRECT RESULTS - 7" ); END IF; B1 := FARR1'(FA1'RANGE => T1'VAL (1)); IF B1 (1) /= FA1 (1) THEN REPORT.FAILED ("INCORRECT RESULTS - 8" ); END IF; B1 := FARR1'(1 => T1'VAL (1), 2 => T1'VAL (1), 3 .. 6 => T1'VAL (2)); IF B1 (1) /= FA1 (1) THEN REPORT.FAILED ("INCORRECT RESULTS - 9" ); END IF; B2 := FARR2'(FA2'RANGE => 2); IF B2 (2) /= FA2 (2) THEN REPORT.FAILED ("INCORRECT RESULTS - 10" ); END IF; B3 := FARR3'(1|2|3 => X2, 4|5|6 => X2); IF B3 (3) /= FA3 (3) THEN REPORT.FAILED ("INCORRECT RESULTS - 11" ); END IF; B4 := FARR4'(FA5'RANGE (1) => (FA5'RANGE (2) => T1'VAL (4))); IF B4 (4, 4) /= FA4 (4, 4) THEN REPORT.FAILED ("INCORRECT RESULTS - 12" ); END IF; B5 := FARR5'(REPORT.IDENT_INT (1) .. REPORT.IDENT_INT (6) => (1 .. 6 => 5)); IF B5 (5, 5) /= FA5 (5, 5) THEN REPORT.FAILED ("INCORRECT RESULTS - 13" ); END IF; B6 := FARR6'(FA6'RANGE => X2); IF B6 (T1'FIRST) /= FA6 (T1'FIRST) THEN REPORT.FAILED ("INCORRECT RESULTS - 14" ); END IF; IF B1 NOT IN FARR1 THEN REPORT.FAILED ("INCORRECT RESULTS - 15" ); END IF; IF FA2 NOT IN FARR2 THEN REPORT.FAILED ("INCORRECT RESULTS - 16" ); END IF; IF FA3 NOT IN FARR3 THEN REPORT.FAILED ("INCORRECT RESULTS - 17" ); END IF; IF B4 NOT IN FARR4 THEN REPORT.FAILED ("INCORRECT RESULTS - 18" ); END IF; IF B5 NOT IN FARR5 THEN REPORT.FAILED ("INCORRECT RESULTS - 19" ); END IF; IF FA6 NOT IN FARR6 THEN REPORT.FAILED ("INCORRECT RESULTS - 20" ); END IF; IF FA1'LENGTH /= FA1'LAST - FA1'FIRST + 1 THEN REPORT.FAILED ("INCORRECT RESULTS - 27" ); END IF; IF FA2'LENGTH /= FA2'LAST - FA2'FIRST + 1 THEN REPORT.FAILED ("INCORRECT RESULTS - 28" ); END IF; IF FA3'LENGTH /= FA3'LAST - FA3'FIRST + 1 THEN REPORT.FAILED ("INCORRECT RESULTS - 29" ); END IF; IF FA4'LENGTH /= FA4'LAST - FA4'FIRST + 1 THEN REPORT.FAILED ("INCORRECT RESULTS - 30" ); END IF; IF FA4'LENGTH (2) /= FA4'LAST (2) - FA4'FIRST (2) + 1 THEN REPORT.FAILED ("INCORRECT RESULTS - 31" ); END IF; IF FA5'LENGTH /= FA5'LAST - FA5'FIRST + 1 THEN REPORT.FAILED ("INCORRECT RESULTS - 32" ); END IF; IF FA5'LENGTH (2) /= FA5'LAST (2) - FA5'FIRST (2) + 1 THEN REPORT.FAILED ("INCORRECT RESULTS - 33" ); END IF; IF FA6'LENGTH /= T1'POS (FA6'LAST) - T1'POS (FA6'FIRST) + 1 THEN REPORT.FAILED ("INCORRECT RESULTS - 34" ); END IF; END P ; PROCEDURE TEST_PROCEDURE (FIRST : IN UNCONSTRAINED_ARRAY ; FFIFS : IN FIRST_INDEX ; FFILS : IN FIRST_INDEX ; FSIFS : IN SECOND_INDEX ; FSILS : IN SECOND_INDEX ; FFLEN : IN NATURAL ; FSLEN : IN NATURAL ; FFIRT : IN FIRST_INDEX ; FSIRT : IN SECOND_INDEX ; SECOND : IN UNCONSTRAINED_ARRAY ; SFIFS : IN FIRST_INDEX ; SFILS : IN FIRST_INDEX ; SSIFS : IN SECOND_INDEX ; SSILS : IN SECOND_INDEX ; SFLEN : IN NATURAL ; SSLEN : IN NATURAL ; SFIRT : IN FIRST_INDEX ; SSIRT : IN SECOND_INDEX ; REMARKS : IN STRING) IS BEGIN -- TEST_PROCEDURE IF (FIRST'FIRST /= FFIFS) OR (FIRST'FIRST (1) /= FFIFS) OR (FIRST'FIRST (2) /= FSIFS) OR (SECOND'FIRST /= SFIFS) OR (SECOND'FIRST (1) /= SFIFS) OR (SECOND'FIRST (2) /= SSIFS) THEN REPORT.FAILED ("PROBLEMS WITH 'FIRST. " & REMARKS) ; END IF ; IF (FIRST'LAST /= FFILS) OR (FIRST'LAST (1) /= FFILS) OR (FIRST'LAST (2) /= FSILS) OR (SECOND'LAST /= SFILS) OR (SECOND'LAST (1) /= SFILS) OR (SECOND'LAST (2) /= SSILS) THEN REPORT.FAILED ("PROBLEMS WITH 'LAST. " & REMARKS) ; END IF ; IF (FIRST'LENGTH /= FFLEN) OR (FIRST'LENGTH (1) /= FFLEN) OR (FIRST'LENGTH (2) /= FSLEN) OR (SECOND'LENGTH /= SFLEN) OR (SECOND'LENGTH (1) /= SFLEN) OR (SECOND'LENGTH (2) /= SSLEN) THEN REPORT.FAILED ("PROBLEMS WITH 'LENGTH. " & REMARKS) ; END IF ; IF (FFIRT NOT IN FIRST'RANGE (1)) OR (FFIRT NOT IN FIRST'RANGE) OR (SFIRT NOT IN SECOND'RANGE (1)) OR (SFIRT NOT IN SECOND'RANGE) OR (FSIRT NOT IN FIRST'RANGE (2)) OR (SSIRT NOT IN SECOND'RANGE (2)) THEN REPORT.FAILED ("INCORRECT HANDLING OF 'RANGE ATTRIBUE. " & REMARKS) ; END IF ; END TEST_PROCEDURE ; PROCEDURE CTEST_PROCEDURE (FIRST : IN CONSTRAINED_ARRAY ; FFIRT : IN FIRST_INDEX ; FSIRT : IN SECOND_INDEX ; SECOND : IN CONSTRAINED_ARRAY ; SFIRT : IN FIRST_INDEX ; SSIRT : IN SECOND_INDEX ; REMARKS : IN STRING) IS BEGIN -- CTEST_PROCEDURE IF (FIRST'FIRST /= FIRST_INDEX'FIRST) OR (FIRST'FIRST (1) /= FIRST_INDEX'FIRST) OR (FIRST'FIRST (2) /= SECOND_INDEX'FIRST) OR (SECOND'FIRST /= FIRST_INDEX'FIRST) OR (SECOND'FIRST (1) /= FIRST_INDEX'FIRST) OR (SECOND'FIRST (2) /= SECOND_INDEX'FIRST) THEN REPORT.FAILED ("PROBLEMS WITH 'FIRST. " & REMARKS) ; END IF ; IF (FIRST'LAST /= FIRST_INDEX'LAST) OR (FIRST'LAST (1) /= FIRST_INDEX'LAST) OR (FIRST'LAST (2) /= SECOND_INDEX'LAST) OR (SECOND'LAST /= FIRST_INDEX'LAST) OR (SECOND'LAST (1) /= FIRST_INDEX'LAST) OR (SECOND'LAST (2) /= SECOND_INDEX'LAST) THEN REPORT.FAILED ("PROBLEMS WITH 'LAST. " & REMARKS) ; END IF ; IF (FIRST'LENGTH /= FIRST_INDEX'POS (FIRST_INDEX'LAST) - FIRST_INDEX'POS (FIRST_INDEX'FIRST) + 1) OR (FIRST'LENGTH (1) /= FIRST_INDEX'POS (FIRST_INDEX'LAST) - FIRST_INDEX'POS (FIRST_INDEX'FIRST) + 1) OR (FIRST'LENGTH (2) /= SECOND_INDEX'POS (SECOND_INDEX'LAST) - SECOND_INDEX'POS (SECOND_INDEX'FIRST) + 1) OR (SECOND'LENGTH /= FIRST_INDEX'POS (FIRST_INDEX'LAST) - FIRST_INDEX'POS (FIRST_INDEX'FIRST) + 1) OR (SECOND'LENGTH (1) /= FIRST_INDEX'POS (FIRST_INDEX'LAST) - FIRST_INDEX'POS (FIRST_INDEX'FIRST) + 1) OR (SECOND'LENGTH (2) /= SECOND_INDEX'POS (SECOND_INDEX'LAST) - SECOND_INDEX'POS (SECOND_INDEX'FIRST) + 1) THEN REPORT.FAILED ("PROBLEMS WITH 'LENGTH. " & REMARKS) ; END IF ; IF (FFIRT NOT IN FIRST'RANGE (1)) OR (FFIRT NOT IN FIRST'RANGE) OR (SFIRT NOT IN SECOND'RANGE (1)) OR (SFIRT NOT IN SECOND'RANGE) OR (FSIRT NOT IN FIRST'RANGE (2)) OR (SSIRT NOT IN SECOND'RANGE (2)) THEN REPORT.FAILED ("INCORRECT HANDLING OF 'RANGE ATTRIBUE. " & REMARKS) ; END IF ; IF CONSTRAINED_ARRAY'SIZE <= 0 THEN REPORT.FAILED ("PROBLEMS WITH THE 'SIZE ATTRIBUTE. " & REMARKS) ; END IF ; IF FIRST'ADDRESS = SECOND'ADDRESS THEN REPORT.FAILED ("PROBLEMS WITH THE 'ADDRESS ATTRIBUTE. " & REMARKS) ; END IF ; END CTEST_PROCEDURE ; PROCEDURE FIRST_TEST_PROCEDURE IS NEW TEST_PROCEDURE (FIRST_INDEX => SHORT_RANGE, SECOND_INDEX => MEDIUM_RANGE, UNCONSTRAINED_ARRAY => FIRST_TEMPLATE) ; PROCEDURE NEW_CTEST_PROCEDURE IS NEW CTEST_PROCEDURE (FIRST_INDEX => SHORT_RANGE, SECOND_INDEX => MEDIUM_RANGE, COMPONENT_TYPE => DATE, CONSTRAINED_ARRAY => SECOND_TEMPLATE) ; PROCEDURE NP IS NEW P (SUBINT, DATE, TODAY, ARRA, A1, ARRA, A2, ARRB, A3, ARRC, A4, ARRD, A5, ARRE, A6, ARRE, A6); BEGIN -- CC1224A REPORT.TEST ("CC1224A", "FOR ARRAY TYPES WITH A NONLIMITED " & "COMPONENT TYPE (OF A FORMAL AND NONFORMAL GENERIC " & "TYPE), CHECK THAT THE FOLLOWING OPERATIONS " & "ARE IMPLICITY DECLARED AND ARE, THEREFORE, " & "AVAILABLE WITHIN THE GENERIC -- UNIT: " & "ASSIGNMENT, THE OPERATION ASSOCIATED WITH " & "AGGREGATE NOTATION, MEMBERSHIP TESTS, THE " & "OPERATION ASSOCIATED WITH INDEXED " & "COMPONENTS, QUALIFICATION, EXPLICIT " & "CONVERSION, 'SIZE, 'ADDRESS, 'FIRST, " & "'FIRST (N), 'LAST, 'LAST (N), 'RANGE, " & "'RANGE (N), 'LENGTH, 'LENGTH (N)" ) ; NP ; FIRST_TEST_PROCEDURE (FIRST => FIRST_ARRAY, FFIFS => -10, FFILS => 10, FSIFS => 6, FSILS => 10, FFLEN => 21, FSLEN => 5, FFIRT => 0, FSIRT => 8, SECOND => SECOND_ARRAY, SFIFS => 0, SFILS => 7, SSIFS => 1, SSILS => 15, SFLEN => 8, SSLEN => 15, SFIRT => 5, SSIRT => 13, REMARKS => "FIRST_TEST_PROCEDURE") ; NEW_CTEST_PROCEDURE (FIRST => THIRD_ARRAY, FFIRT => -5, FSIRT => 11, SECOND => FOURTH_ARRAY, SFIRT => 0, SSIRT => 14, REMARKS => "NEW_CTEST_PROCEDURE") ; REPORT.RESULT ; END CC1224A;
-- WORDS, a Latin dictionary, by Colonel William Whitaker (USAF, Retired) -- -- Copyright William A. Whitaker (1936–2010) -- -- This is a free program, which means it is proper to copy it and pass -- it on to your friends. Consider it a developmental item for which -- there is no charge. However, just for form, it is Copyrighted -- (c). Permission is hereby freely given for any and all use of program -- and data. You can sell it as your own, but at least tell me. -- -- This version is distributed without obligation, but the developer -- would appreciate comments and suggestions. -- -- All parts of the WORDS system, source code and data files, are made freely -- available to anyone who wishes to use them, for whatever purpose. with Latin_Utils.Strings_Package; use Latin_Utils.Strings_Package; with Support_Utils.Developer_Parameters; use Support_Utils.Developer_Parameters; with Latin_Utils.Preface; package body Support_Utils.Addons_Package is use Ada.Text_IO; use Part_Of_Speech_Type_IO; use Target_Entry_Io; --use KIND_ENTRY_IO; use Stem_Key_Type_IO; function Equ (C, D : Character) return Boolean is begin if (D = 'u') or (D = 'v') then return (C = 'u') or (C = 'v'); else return C = D; end if; end Equ; function Equ (S, T : String) return Boolean is begin if S'Length /= T'Length then return False; end if; for I in 1 .. S'Length loop if not Equ (S (S'First + I - 1), T (T'First + I - 1)) then return False; end if; end loop; return True; end Equ; procedure Load_Addons (File_Name : in String) is use Tackon_Entry_Io; use Prefix_Entry_Io; use Suffix_Entry_Io; --use DICT_IO; S : String (1 .. 100); L, Last, Tic, Pre, Suf, Tac, Pac : Integer := 0; Addons_File : Ada.Text_IO.File_Type; Pofs : Part_Of_Speech_Type; Mean : Meaning_Type := Null_Meaning_Type; M : Integer := 1; --TG : TARGET_ENTRY; Tn : Tackon_Entry; Pm : Prefix_Item; Ts : Stem_Type; procedure Extract_Fix (S : in String; Xfix : out Fix_Type; Xc : out Character) is St : constant String := Trim (S); L : constant Integer := St'Length; J : Integer := 0; begin for I in 1 .. L loop J := I; exit when (I < L) and then (St (I + 1) = ' '); end loop; Xfix := Head (St (1 .. J), Max_Fix_Size); if J = L then -- there is no CONNECT CHARACTER Xc := ' '; return; else for I in J + 1 .. L loop if St (I) /= ' ' then Xc := St (I); exit; end if; end loop; end if; return; end Extract_Fix; begin Open (Addons_File, In_File, File_Name); Preface.Put ("ADDONS"); Preface.Put (" loading "); --FIXME this code looks like it's duplicated somewhere else -- if DICT_IO.IS_OPEN (DICT_FILE (D_K)) then -- DICT_IO.DELETE (DICT_FILE (D_K)); -- end if; -- DICT_IO.CREATE (DICT_FILE (D_K), DICT_IO.INOUT_FILE, ---ADD_FILE_NAME_EXTENSION (DICT_FILE_NAME, DICTIONARY_KIND'IMAGE (D_K))); -- ""); -- while not End_Of_File (Addons_File) loop Get_Non_Comment_Line (Addons_File, S, Last); --TEXT_IO.PUT_LINE (S (1 .. LAST)); Get (S (1 .. Last), Pofs, L); case Pofs is when Tackon => Ts := Head (Trim (S (L + 1 .. Last)), Max_Stem_Size); Get_Line (Addons_File, S, Last); Get (S (1 .. Last), Tn, L); Get_Line (Addons_File, S, Last); Mean := Head (S (1 .. Last), Max_Meaning_Size); if Tn.Base.Pofs = Pack and then (Tn.Base.Pack.Decl.Which = 1 or Tn.Base.Pack.Decl.Which = 2) and then Mean (1 .. 9) = "PACKON w/" then Pac := Pac + 1; Packons (Pac).Pofs := Pofs; Packons (Pac).Tack := Ts; Packons (Pac).Entr := Tn; -- DICT_IO.SET_INDEX (DICT_FILE (D_K), M); -- DE.MEAN := MEAN; -- DICT_IO.WRITE (DICT_FILE (D_K), DE); Packons (Pac).MNPC := M; Means (M) := Mean; M := M + 1; else Tac := Tac + 1; Tackons (Tac).Pofs := Pofs; Tackons (Tac).Tack := Ts; Tackons (Tac).Entr := Tn; -- DICT_IO.SET_INDEX (DICT_FILE (D_K), M); -- DE.MEAN := MEAN; -- DICT_IO.WRITE (DICT_FILE (D_K), DE); -- --DICT_IO.WRITE (DICT_FILE (D_K), MEAN); Tackons (Tac).MNPC := M; Means (M) := Mean; M := M + 1; end if; Number_Of_Packons := Pac; Number_Of_Tackons := Tac; when Prefix => Extract_Fix (S (L + 1 .. Last), Pm.Fix, Pm.Connect); Get_Line (Addons_File, S, Last); Get (S (1 .. Last), Pm.Entr, L); Get_Line (Addons_File, S, Last); Mean := Head (S (1 .. Last), Max_Meaning_Size); if Pm.Entr.Root = Pack then Tic := Tic + 1; Tickons (Tic).Pofs := Pofs; Tickons (Tic).Fix := Pm.Fix; Tickons (Tic).Connect := Pm.Connect; Tickons (Tic).Entr := Pm.Entr; -- DICT_IO.SET_INDEX (DICT_FILE (D_K), M); -- DE.MEAN := MEAN; -- DICT_IO.WRITE (DICT_FILE (D_K), DE); -- --DICT_IO.WRITE (DICT_FILE (D_K), MEAN); Tickons (Tic).MNPC := M; Means (M) := Mean; M := M + 1; else Pre := Pre + 1; Prefixes (Pre).Pofs := Pofs; Prefixes (Pre).Fix := Pm.Fix; Prefixes (Pre).Connect := Pm.Connect; Prefixes (Pre).Entr := Pm.Entr; -- DICT_IO.SET_INDEX (DICT_FILE (D_K), M); -- DICT_IO.WRITE (DICT_FILE (D_K), DE); -- --DICT_IO.WRITE (DICT_FILE (D_K), MEAN); Prefixes (Pre).MNPC := M; Means (M) := Mean; M := M + 1; end if; Number_Of_Tickons := Tic; Number_Of_Prefixes := Pre; when Suffix => Suf := Suf + 1; Suffixes (Suf).Pofs := Pofs; --TEXT_IO.PUT_LINE (S (1 .. LAST)); Extract_Fix (S (L + 1 .. Last), Suffixes (Suf).Fix, Suffixes (Suf).Connect); --TEXT_IO.PUT ("@1"); Get_Line (Addons_File, S, Last); --TEXT_IO.PUT ("@2"); --TEXT_IO.PUT_LINE (S (1 .. LAST) & "<"); --TEXT_IO.PUT ("@2"); Get (S (1 .. Last), Suffixes (Suf).Entr, L); --TEXT_IO.PUT ("@3"); Get_Line (Addons_File, S, Last); --TEXT_IO.PUT ("@4"); Mean := Head (S (1 .. Last), Max_Meaning_Size); --TEXT_IO.PUT ("@5"); -- -- DICT_IO.SET_INDEX (DICT_FILE (D_K), M); -- DE.MEAN := MEAN; -- DICT_IO.WRITE (DICT_FILE (D_K), DE); -- --DICT_IO.WRITE (DICT_FILE (D_K), MEAN); Suffixes (Suf).MNPC := M; Means (M) := Mean; M := M + 1; Number_Of_Suffixes := Suf; when others => Ada.Text_IO.Put_Line ("Bad ADDON !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); Ada.Text_IO.Put_Line (S (1 .. Last)); raise Ada.Text_IO.Data_Error; end case; end loop; Preface.Put (Tac, 1); Preface.Put ("+"); Preface.Put (Pac, 2); Preface.Put (" TACKONS "); Preface.Put (Tic, 1); Preface.Put ("+"); Preface.Put (Pre, 3); Preface.Put (" PREFIXES "); Preface.Put (Suf, 3); Preface.Put (" SUFFIXES "); Preface.Set_Col (60); Preface.Put_Line ("-- Loaded correctly"); Close (Addons_File); exception when Ada.Text_IO.Name_Error => Preface.Put_Line ("No ADDONS file "); null; when Ada.Text_IO.Data_Error => Preface.Put_Line (S (1 .. Last)); Preface.Put_Line ("No further ADDONS read "); Close (Addons_File); when others => Preface.Put_Line ("Exception in LOAD_ADDONS"); Preface.Put_Line (S (1 .. Last)); end Load_Addons; function Subtract_Tackon (W : String; X : Tackon_Item) return String is Wd : constant String := Trim (W); L : constant Integer := Wd'Length; Xf : constant String := Trim (X.Tack); Z : constant Integer := Xf'Length; begin --PUT_LINE ("In SUB TACKON " & INTEGER'IMAGE (L) & INTEGER'IMAGE (Z)); if Words_Mdev (Use_Tackons) and then L > Z and then --WD (L-Z + 1 .. L) = XF (1 .. Z) then Equ (Wd (L - Z + 1 .. L), Xf (1 .. Z)) then --PUT ("In SUBTRACT_TACKON we got a hit "); PUT_LINE (X.TACK); return Wd (1 .. L - Z); else --PUT ("In SUBTRACT_TACKON NO hit "); PUT_LINE (X.TACK); return W; end if; end Subtract_Tackon; function Subtract_Prefix (W : String; X : Prefix_Item) return Stem_Type is Wd : constant String := Trim (W); Xf : constant String := Trim (X.Fix); Z : constant Integer := Xf'Length; St : Stem_Type := Head (Wd, Max_Stem_Size); begin if Words_Mdev (Use_Prefixes) and then X /= Null_Prefix_Item and then Wd'Length > Z and then --WD (1 .. Z) = XF (1 .. Z) and then Equ (Wd (1 .. Z), Xf (1 .. Z)) and then ((X.Connect = ' ') or (Wd (Z + 1) = X.Connect)) then St (1 .. Wd'Length - Z) := Wd (Z + 1 .. Wd'Last); St (Wd'Length - Z + 1 .. Max_Stem_Size) := Null_Stem_Type (Wd'Length - Z + 1 .. Max_Stem_Size); end if; return St; end Subtract_Prefix; function Subtract_Suffix (W : String; X : Suffix_Item) return Stem_Type is Wd : constant String := Trim (W); L : constant Integer := Wd'Length; Xf : constant String := Trim (X.Fix); Z : constant Integer := Xf'Length; St : Stem_Type := Head (Wd, Max_Stem_Size); begin --PUT_LINE ("In SUBTRACT_SUFFIX Z = " & INTEGER'IMAGE (Z) & --" CONNECT >" & X.CONNECT & '<'); if Words_Mdev (Use_Suffixes) and then X /= Null_Suffix_Item and then Wd'Length > Z and then --WD (L-Z + 1 .. L) = XF (1 .. Z) and then Equ (Wd (L - Z + 1 .. L), Xf (1 .. Z)) and then ((X.Connect = ' ') or (Wd (L - Z) = X.Connect)) then --PUT_LINE ("In SUBTRACT_SUFFIX we got a hit"); St (1 .. Wd'Length - Z) := Wd (1 .. Wd'Length - Z); St (Wd'Length - Z + 1 .. Max_Stem_Size) := Null_Stem_Type (Wd'Length - Z + 1 .. Max_Stem_Size); end if; return St; end Subtract_Suffix; function Add_Prefix (Stem : Stem_Type; Prefix : Prefix_Item) return Stem_Type is Fpx : constant String := Trim (Prefix.Fix) & Stem; begin if Words_Mdev (Use_Prefixes) then return Head (Fpx, Max_Stem_Size); else return Stem; end if; end Add_Prefix; function Add_Suffix (Stem : Stem_Type; Suffix : Suffix_Item) return Stem_Type is Fpx : constant String := Trim (Stem) & Suffix.Fix; begin if Words_Mdev (Use_Suffixes) then return Head (Fpx, Max_Stem_Size); else return Stem; end if; end Add_Suffix; -- package body TARGET_ENTRY_IO is separate; -- package body TACKON_ENTRY_IO is separate; -- package body TACKON_LINE_IO is separate; -- package body PREFIX_ENTRY_IO is separate; -- package body PREFIX_LINE_IO is separate; -- package body SUFFIX_ENTRY_IO is separate; -- package body SUFFIX_LINE_IO is separate; package body Target_Entry_Io is use Noun_Entry_IO; use Pronoun_Entry_IO; use Propack_Entry_IO; use Adjective_Entry_IO; use Numeral_Entry_IO; use Adverb_Entry_IO; use Verb_Entry_IO; -- use KIND_ENTRY_IO; -- -- use NOUN_KIND_TYPE_IO; -- use PRONOUN_KIND_TYPE_IO; -- use INFLECTIONS_PACKAGE.INTEGER_IO; -- use VERB_KIND_TYPE_IO; Spacer : Character := ' '; Noun : Noun_Entry; Pronoun : Pronoun_Entry; Propack : Propack_Entry; Adjective : Adjective_Entry; Numeral : Numeral_Entry; Adverb : Adverb_Entry; Verb : Verb_Entry; -- NOUN_KIND : NOUN_KIND_TYPE; -- PRONOUN_KIND : PRONOUN_KIND_TYPE; -- PROPACK_KIND : PRONOUN_KIND_TYPE; -- NUMERAL_VALUE : NUMERAL_VALUE_TYPE; -- VERB_KIND : VERB_KIND_TYPE; --KIND : KIND_ENTRY; procedure Get (F : in File_Type; P : out Target_Entry) is Ps : Target_Pofs_Type := X; begin Get (F, Ps); Get (F, Spacer); case Ps is when N => Get (F, Noun); --GET (F, NOUN_KIND); P := (N, Noun); --, NOUN_KIND); when Pron => Get (F, Pronoun); --GET (F, PRONOUN_KIND); P := (Pron, Pronoun); --, PRONOUN_KIND); when Pack => Get (F, Propack); --GET (F, PROPACK_KIND); P := (Pack, Propack); --, PROPACK_KIND); when Adj => Get (F, Adjective); P := (Adj, Adjective); when Num => Get (F, Numeral); --GET (F, NUMERAL_VALUE); P := (Num, Numeral); --, NUMERAL_VALUE); when Adv => Get (F, Adverb); P := (Adv, Adverb); when V => Get (F, Verb); --GET (F, VERB_KIND); P := (V, Verb); --, VERB_KIND); when X => P := (Pofs => X); end case; return; end Get; procedure Get (P : out Target_Entry) is Ps : Target_Pofs_Type := X; begin Get (Ps); Get (Spacer); case Ps is when N => Get (Noun); --GET (NOUN_KIND); P := (N, Noun); --, NOUN_KIND); when Pron => Get (Pronoun); --GET (PRONOUN_KIND); P := (Pron, Pronoun); --, PRONOUN_KIND); when Pack => Get (Propack); --GET (PROPACK_KIND); P := (Pack, Propack); --, PROPACK_KIND); when Adj => Get (Adjective); P := (Adj, Adjective); when Num => Get (Numeral); --GET (NUMERAL_VALUE); P := (Num, Numeral); --, NUMERAL_VALUE); when Adv => Get (Adverb); P := (Adv, Adverb); when V => Get (Verb); --GET (VERB_KIND); P := (V, Verb); --, VERB_KIND); when X => P := (Pofs => X); end case; return; end Get; procedure Put (F : in File_Type; P : in Target_Entry) is C : constant Positive := Positive (Col (F)); begin Put (F, P.Pofs); Put (F, ' '); case P.Pofs is when N => Put (F, P.N); --PUT (F, P.NOUN_KIND); when Pron => Put (F, P.Pron); --PUT (F, P.PRONOUN_KIND); when Pack => Put (F, P.Pack); --PUT (F, P.PROPACK_KIND); when Adj => Put (F, P.Adj); when Num => Put (F, P.Num); --PUT (F, P.NUMERAL_VALUE); when Adv => Put (F, P.Adv); when V => Put (F, P.V); --PUT (F, P.VERB_KIND); when others => null; end case; Put (F, String'((Integer (Col (F)) .. Target_Entry_Io.Default_Width + C - 1 => ' '))); return; end Put; procedure Put (P : in Target_Entry) is C : constant Positive := Positive (Col); begin Put (P.Pofs); Put (' '); case P.Pofs is when N => Put (P.N); --PUT (P.NOUN_KIND); when Pron => Put (P.Pron); --PUT (P.PRONOUN_KIND); when Pack => Put (P.Pack); --PUT (P.PROPACK_KIND); when Adj => Put (P.Adj); when Num => Put (P.Num); --PUT (P.NUMERAL_VALUE); when Adv => Put (P.Adv); when V => Put (P.V); --PUT (P.VERB_KIND); when others => null; end case; Put (String'( (Integer (Col) .. Target_Entry_Io.Default_Width + C - 1 => ' '))); return; end Put; procedure Get (S : in String; P : out Target_Entry; Last : out Integer) is L : Integer := S'First - 1; Ps : Target_Pofs_Type := X; begin Get (S, Ps, L); L := L + 1; case Ps is when N => Get (S (L + 1 .. S'Last), Noun, Last); --GET (S (L + 1 .. S'LAST), NOUN_KIND, LAST); P := (N, Noun); --, NOUN_KIND); when Pron => Get (S (L + 1 .. S'Last), Pronoun, Last); --GET (S (L + 1 .. S'LAST), PRONOUN_KIND, LAST); P := (Pron, Pronoun); --, PRONOUN_KIND); when Pack => Get (S (L + 1 .. S'Last), Propack, Last); --GET (S (L + 1 .. S'LAST), PROPACK_KIND, LAST); P := (Pack, Propack); --, PROPACK_KIND); when Adj => Get (S (L + 1 .. S'Last), Adjective, Last); P := (Adj, Adjective); when Num => Get (S (L + 1 .. S'Last), Numeral, Last); --GET (S (L + 1 .. S'LAST), NUMERAL_VALUE, LAST); P := (Num, Numeral); --, NUMERAL_VALUE); when Adv => Get (S (L + 1 .. S'Last), Adverb, Last); P := (Adv, Adverb); when V => Get (S (L + 1 .. S'Last), Verb, Last); --GET (S (L + 1 .. S'LAST), VERB_KIND, LAST); P := (V, Verb); --, VERB_KIND); when X => P := (Pofs => X); end case; return; end Get; procedure Put (S : out String; P : in Target_Entry) is L : Integer := S'First - 1; M : Integer := 0; begin M := L + Part_Of_Speech_Type_IO.Default_Width; Put (S (L + 1 .. M), P.Pofs); L := M + 1; S (L) := ' '; case P.Pofs is when N => M := L + Noun_Entry_IO.Default_Width; Put (S (L + 1 .. M), P.N); -- M := L + NOUN_KIND_TYPE_IO.DEFAULT_WIDTH; -- PUT (S (L + 1 .. M), P.NOUN_KIND); when Pron => M := L + Pronoun_Entry_IO.Default_Width; Put (S (L + 1 .. M), P.Pron); -- M := L + PRONOUN_KIND_TYPE_IO.DEFAULT_WIDTH; -- PUT (S (L + 1 .. M), P.PRONOUN_KIND); when Pack => M := L + Propack_Entry_IO.Default_Width; Put (S (L + 1 .. M), P.Pack); -- M := L + PRONOUN_KIND_TYPE_IO.DEFAULT_WIDTH; -- PUT (S (L + 1 .. M), P.PROPACK_KIND); when Adj => M := L + Adjective_Entry_IO.Default_Width; Put (S (L + 1 .. M), P.Adj); when Num => M := L + Numeral_Entry_IO.Default_Width; Put (S (L + 1 .. M), P.Num); -- M := L + NUMERAL_VALUE_TYPE_IO_DEFAULT_WIDTH; -- PUT (S (L + 1 .. M), P.PRONOUN_KIND); when Adv => M := L + Adverb_Entry_IO.Default_Width; Put (S (L + 1 .. M), P.Adv); when V => M := L + Verb_Entry_IO.Default_Width; Put (S (L + 1 .. M), P.V); -- M := L + PRONOUN_KIND_TYPE_IO.DEFAULT_WIDTH; -- PUT (S (L + 1 .. M), P.PRONOUN_KIND); when others => null; end case; S (M + 1 .. S'Last) := (others => ' '); end Put; end Target_Entry_Io; package body Tackon_Entry_Io is procedure Get (F : in File_Type; I : out Tackon_Entry) is begin Get (F, I.Base); end Get; procedure Get (I : out Tackon_Entry) is begin Get (I.Base); end Get; procedure Put (F : in File_Type; I : in Tackon_Entry) is begin Put (F, I.Base); end Put; procedure Put (I : in Tackon_Entry) is begin Put (I.Base); end Put; procedure Get (S : in String; I : out Tackon_Entry; Last : out Integer) is L : constant Integer := S'First - 1; begin Get (S (L + 1 .. S'Last), I.Base, Last); end Get; procedure Put (S : out String; I : in Tackon_Entry) is L : constant Integer := S'First - 1; M : Integer := 0; begin M := L + Target_Entry_Io.Default_Width; Put (S (L + 1 .. M), I.Base); S (S'First .. S'Last) := (others => ' '); end Put; end Tackon_Entry_Io; package body Prefix_Entry_Io is Spacer : Character := ' '; procedure Get (F : in File_Type; P : out Prefix_Entry) is begin Get (F, P.Root); Get (F, Spacer); Get (F, P.Target); end Get; procedure Get (P : out Prefix_Entry) is begin Get (P.Root); Get (Spacer); Get (P.Target); end Get; procedure Put (F : in File_Type; P : in Prefix_Entry) is begin Put (F, P.Root); Put (F, ' '); Put (F, P.Target); end Put; procedure Put (P : in Prefix_Entry) is begin Put (P.Root); Put (' '); Put (P.Target); end Put; procedure Get (S : in String; P : out Prefix_Entry; Last : out Integer) is L : Integer := S'First - 1; begin Get (S (L + 1 .. S'Last), P.Root, L); L := L + 1; Get (S (L + 1 .. S'Last), P.Target, Last); end Get; procedure Put (S : out String; P : in Prefix_Entry) is L : Integer := S'First - 1; M : Integer := 0; begin M := L + Part_Of_Speech_Type_IO.Default_Width; Put (S (L + 1 .. M), P.Root); L := M + 1; S (L) := ' '; M := L + Part_Of_Speech_Type_IO.Default_Width; Put (S (L + 1 .. M), P.Target); S (M + 1 .. S'Last) := (others => ' '); end Put; end Prefix_Entry_Io; package body Suffix_Entry_Io is Spacer : Character := ' '; procedure Get (F : in File_Type; P : out Suffix_Entry) is begin Get (F, P.Root); Get (F, Spacer); Get (F, P.Root_Key); Get (F, Spacer); Get (F, P.Target); Get (F, Spacer); Get (F, P.Target_Key); end Get; procedure Get (P : out Suffix_Entry) is begin Get (P.Root); Get (Spacer); Get (P.Root_Key); Get (Spacer); Get (P.Target); Get (Spacer); Get (P.Target_Key); end Get; procedure Put (F : in File_Type; P : in Suffix_Entry) is begin Put (F, P.Root); Put (F, ' '); Put (F, P.Root_Key, 2); Put (F, ' '); Put (F, P.Target); Put (F, ' '); Put (F, P.Target_Key, 2); end Put; procedure Put (P : in Suffix_Entry) is begin Put (P.Root); Put (' '); Put (P.Root_Key, 2); Put (' '); Put (P.Target); Put (' '); Put (P.Target_Key, 2); end Put; procedure Get (S : in String; P : out Suffix_Entry; Last : out Integer) is L : Integer := S'First - 1; begin --TEXT_IO.PUT ("#1" & INTEGER'IMAGE (L)); Get (S (L + 1 .. S'Last), P.Root, L); --TEXT_IO.PUT ("#2" & INTEGER'IMAGE (L)); L := L + 1; Get (S (L + 1 .. S'Last), P.Root_Key, L); --TEXT_IO.PUT ("#3" & INTEGER'IMAGE (L)); L := L + 1; Get (S (L + 1 .. S'Last), P.Target, L); --TEXT_IO.PUT ("#4" & INTEGER'IMAGE (L)); L := L + 1; Get (S (L + 1 .. S'Last), P.Target_Key, Last); --TEXT_IO.PUT ("#5" & INTEGER'IMAGE (LAST)); end Get; procedure Put (S : out String; P : in Suffix_Entry) is L : Integer := S'First - 1; M : Integer := 0; begin M := L + Part_Of_Speech_Type_IO.Default_Width; Put (S (L + 1 .. M), P.Root); L := M + 1; S (L) := ' '; M := L + 2; Put (S (L + 1 .. M), P.Root_Key); L := M + 1; S (L) := ' '; M := L + Target_Entry_Io.Default_Width; Put (S (L + 1 .. M), P.Target); L := M + 1; S (L) := ' '; M := L + 2; Put (S (L + 1 .. M), P.Target_Key); S (M + 1 .. S'Last) := (others => ' '); end Put; end Suffix_Entry_Io; begin -- Initiate body of ADDONS_PACKAGE --TEXT_IO.PUT_LINE ("Initializing ADDONS_PACKAGE"); Prefix_Entry_Io.Default_Width := Part_Of_Speech_Type_IO.Default_Width + 1 + Part_Of_Speech_Type_IO.Default_Width; Target_Entry_Io.Default_Width := Part_Of_Speech_Type_IO.Default_Width + 1 + Numeral_Entry_IO.Default_Width; -- Largest Suffix_Entry_Io.Default_Width := Part_Of_Speech_Type_IO.Default_Width + 1 + 2 + 1 + Target_Entry_Io.Default_Width + 1 + 2; Tackon_Entry_Io.Default_Width := Target_Entry_Io.Default_Width; end Support_Utils.Addons_Package;
Pragma Ada_2012; Pragma Wide_Character_Encoding( UTF8 ); limited private with Risi_Script.Types.Internals; Package Risi_Script.Types.Implementation is Type Representation is private; Function Create( Data_Type : Enumeration ) return Representation; Function Image( Item : Representation; Sub_Escape : Boolean:= False ) return String; Type Variable_List is Array(Positive Range <>) of Representation; Function Get_Indicator ( Input : Representation ) return Indicator; Function Get_Enumeration( Input : Representation ) return Enumeration; Private Type Internal_Representation(<>); Type Representation is not null access Internal_Representation; Package Internal Renames Risi_Script.Types.Internals; Function Internal_Create ( Item : Internal.Integer_Type ) return Representation; Function Internal_Create ( Item : Internal.Real_Type ) return Representation; Function Internal_Create ( Item : Internal.Pointer_Type ) return Representation; Function Internal_Create ( Item : Internal.Fixed_Type ) return Representation; Function Internal_Create ( Item : Internal.Boolean_Type ) return Representation; Function Internal_Create ( Item : Internal.Func_Type ) return Representation; End Risi_Script.Types.Implementation;
----------------------------------------------------------------------- -- auth_cb -- Authentication callback examples -- Copyright (C) 2013 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Util.Properties; with Util.Log.Loggers; with Util.Http.Clients.Web; with AWS.Config; with AWS.Config.Set; with AWS.Server; with AWS.Services.Dispatchers.URI; with AWS.Services.Page_Server; with AWS.Services.Web_Block.Registry; with AWS.Net.SSL; with Auth_CB; procedure Auth_Demo is Log : Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Auth_Demo"); Dispatcher : AWS.Services.Dispatchers.URI.Handler; WS : AWS.Server.HTTP; Config : AWS.Config.Object; begin if not AWS.Net.SSL.Is_Supported then Log.Error ("SSL is not supported by AWS."); Log.Error ("SSL is required for the OpenID connector to connect to OpenID providers."); Log.Error ("Please, rebuild AWS with SSL support."); return; end if; -- Get the authentication provider configuration. We use the Util.Properties and some -- java like property file. Other configuration implementation are possible. Auth_CB.Config.Load_Properties ("samples.properties"); Util.Log.Loggers.Initialize (Util.Properties.Manager (Auth_CB.Config)); -- Setup the HTTP client implementation to use AWS. Util.Http.Clients.Web.Register; -- Setup AWS dispatchers. AWS.Services.Dispatchers.URI.Register (Dispatcher, "/atlas/auth/auth", Auth_CB.Get_Authorization'Access, Prefix => True); AWS.Services.Dispatchers.URI.Register (Dispatcher, "/verify", Auth_CB.Verify_Authorization'Access); AWS.Services.Dispatchers.URI.Register (Dispatcher, "/atlas", AWS.Services.Page_Server.Callback'Access, Prefix => True); AWS.Services.Dispatchers.URI.Register (Dispatcher, "/success", Auth_CB.User_Info'Access); AWS.Services.Web_Block.Registry.Register ("success", "samples/web/success.thtml", null); -- Configure AWS. Config := AWS.Config.Get_Current; AWS.Config.Set.Session (Config, True); AWS.Config.Set.Session_Name (Config, "AUTH_DEMO"); AWS.Config.Set.Reuse_Address (Config, True); AWS.Config.Set.WWW_Root (Config, "samples/web"); AWS.Server.Start (WS, Dispatcher => Dispatcher, Config => Config); Log.Info ("Connect you browser to: http://localhost:8080/atlas/login.html"); Log.Info ("Press 'q' key to stop the server."); AWS.Server.Wait (AWS.Server.Q_Key_Pressed); Log.Info ("Shutting down server..."); AWS.Server.Shutdown (WS); end Auth_Demo;
-- { dg-do compile } -- { dg-options "-gnatws" } with G_tables; procedure test_tables is package Inst is new G_Tables (Integer); use Inst; It : Inst.Table := Create (15); begin null; end;
with Ada.Text_IO; with Ada.Integer_Text_IO; -- Copyright 2021 Melwyn Francis Carlo procedure A050 is use Ada.Text_IO; use Ada.Integer_Text_IO; -- File Reference: http://www.naturalnumbers.org/primes.html FT : File_Type; Last_Index : Natural; Prime_Num : String (1 .. 10); File_Name : constant String := "problems/003/PrimeNumbers_Upto_1000000"; Primes_Nums : array (Integer range 1 .. 80_000) of Integer; N : Integer := 1; I_Start : Integer := 0; Resultant_Prime : Integer := 0; Count_Val : Integer := 23; Prime_Found : Boolean := False; I, I_By_10, Sum : Integer; begin Open (FT, In_File, File_Name); while not End_Of_File (FT) loop Get_Line (FT, Prime_Num, Last_Index); if Integer'Value (Prime_Num (1 .. Last_Index)) > 1_000_000 then exit; end if; if I_Start = 0 then if Integer'Value (Prime_Num (1 .. Last_Index)) > 1_00_000 then I_Start := N - 1; end if; end if; Primes_Nums (N) := Integer'Value (Prime_Num (1 .. Last_Index)); N := N + 1; end loop; Close (FT); while Count_Val < 1_000 loop I := I_Start; Prime_Found := False; while I < N loop I_By_10 := Integer (Float'Floor (Float (I) / 10.0)); for J in 1 .. I_By_10 loop Sum := 0; for K in J .. (J + Count_Val - 1) loop Sum := Sum + Primes_Nums (K); end loop; if Sum > Primes_Nums (I) then exit; end if; if Sum = Primes_Nums (I) then Resultant_Prime := Primes_Nums (I); Prime_Found := True; Count_Val := Count_Val + 1; exit; end if; end loop; if Prime_Found then exit; end if; I := I + 1; end loop; Count_Val := Count_Val + 1; end loop; Put (Resultant_Prime, Width => 0); end A050;
with agar.core.event; with agar.gui.text; with agar.gui.widget.icon; package agar.gui.widget.socket is use type c.unsigned; type bg_type_t is (SOCKET_PIXMAP, SOCKET_RECT, SOCKET_CIRCLE); for bg_type_t use (SOCKET_PIXMAP => 0, SOCKET_RECT => 1, SOCKET_CIRCLE => 2); for bg_type_t'size use c.unsigned'size; pragma convention (c, bg_type_t); type flags_t is new c.unsigned; SOCKET_HFILL : constant flags_t := 16#01#; SOCKET_VFILL : constant flags_t := 16#02#; SOCKET_EXPAND : constant flags_t := SOCKET_HFILL or SOCKET_VFILL; SOCKET_MOUSEOVER : constant flags_t := 16#04#; STICKY_STATE : constant flags_t := 16#08#; type socket_t is limited private; type socket_access_t is access all socket_t; pragma convention (c, socket_access_t); type insert_callback_t is access function (socket : socket_access_t; icon : agar.gui.widget.icon.icon_access_t) return c.int; pragma convention (c, insert_callback_t); type remove_callback_t is access procedure (socket : socket_access_t; icon : agar.gui.widget.icon.icon_access_t); pragma convention (c, remove_callback_t); -- API function allocate (parent : widget_access_t; flags : flags_t) return socket_access_t; pragma import (c, allocate, "AG_SocketNew"); function from_surface (parent : widget_access_t; flags : flags_t; surface : agar.gui.surface.surface_access_t) return socket_access_t; pragma import (c, from_surface, "AG_SocketFromSurface"); function from_bitmap (parent : widget_access_t; flags : flags_t; file : string) return socket_access_t; pragma inline (from_bitmap); procedure set_insert_callback (socket : socket_access_t; callback : insert_callback_t); pragma import (c, set_insert_callback, "AG_SocketInsertFn"); procedure set_remove_callback (socket : socket_access_t; callback : remove_callback_t); pragma import (c, set_remove_callback, "AG_SocketRemoveFn"); procedure set_padding (socket : socket_access_t; left : natural; right : natural; top : natural; bottom : natural); pragma inline (set_padding); procedure shape_rectangle (socket : socket_access_t; width : natural; height : natural); pragma inline (shape_rectangle); procedure shape_circle (socket : socket_access_t; radius : natural); pragma inline (shape_circle); procedure shape_pixmap (socket : socket_access_t; surface : agar.gui.surface.surface_access_t); pragma import (c, shape_pixmap, "AG_SocketBgPixmap"); procedure shape_pixmap_no_copy (socket : socket_access_t; surface : agar.gui.surface.surface_access_t); pragma import (c, shape_pixmap_no_copy, "AG_SocketBgPixmapNODUP"); function widget (socket : socket_access_t) return widget_access_t; pragma inline (widget); function icon (socket : socket_access_t) return agar.gui.widget.icon.icon_access_t; pragma inline (icon); private type pixmap_t is record s : c.int; end record; pragma convention (c, pixmap_t); type rect_t is record w : c.int; h : c.int; end record; pragma convention (c, rect_t); type circle_t is record r : c.int; end record; pragma convention (c, circle_t); type bg_data_selector_t is (DATA_PIXMAP, DATA_RECT, DATA_CIRCLE); type bg_data_t (member : bg_data_selector_t := DATA_PIXMAP) is record case member is when DATA_PIXMAP => pixmap : pixmap_t; when DATA_RECT => rect : rect_t; when DATA_CIRCLE => circle : circle_t; end case; end record; pragma convention (c, bg_data_t); pragma unchecked_union (bg_data_t); type socket_t is record widget : aliased widget_t; state : c.int; count : c.int; flags : flags_t; bg_type : bg_type_t; bg_data : bg_data_t; justify : agar.gui.text.justify_t; pad_left : c.int; pad_right : c.int; pad_top : c.int; pad_bottom : c.int; icon : agar.gui.widget.icon.icon_access_t; insert_fn : access function (sock : socket_access_t; icon : agar.gui.widget.icon.icon_access_t) return c.int; remove_fn : access procedure (sock : socket_access_t; icon : agar.gui.widget.icon.icon_access_t); overlay_fn : agar.core.event.event_access_t; end record; pragma convention (c, socket_t); end agar.gui.widget.socket;
-- Copyright 2016-2021 Bartek thindil Jasicki -- -- This file is part of Steam Sky. -- -- Steam Sky is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- -- Steam Sky 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 -- along with Steam Sky. If not, see <http://www.gnu.org/licenses/>. with Ada.Containers.Vectors; use Ada.Containers; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Game; use Game; -- ****h* Missions/Missions -- FUNCTION -- Provides code for manipulate missions data -- SOURCE package Missions is -- **** -- ****t* Missions/Missions.Missions_Types -- FUNCTION -- Types of missions -- SOURCE type Missions_Types is (Deliver, Destroy, Patrol, Explore, Passenger) with Default_Value => Deliver; -- **** -- ****t* Missions/Missions.RewardMultiplier -- FUNCTION -- Used for count reward for finished missions -- SOURCE type RewardMultiplier is digits 2 range 0.0 .. 2.0 with Default_Value => 1.0; -- **** -- ****s* Missions/Missions.Mission_Data(MType: -- FUNCTION -- Data structure for missions -- PARAMETERS -- Time - Amount of minutes to finish the mission -- TargetX - Skymap X-axis for the mission target -- TargetY - Skymap Y-axis for the mission target -- Reward - Amount of money reward for the mission -- StartBase - Index of sky base where the mission starts -- Finished - Did the mission is finished -- Multiplier - Bonus to amount of money or reputation rewards for the -- mission -- ItemIndex - Index of proto item to deliver to base -- Data - Minimum quality of cabin needed by passenger (in bases) -- or passenger index (in player ship) -- ShipIndex - Index of proto ship which must be destroyed -- Target - Target for mission (ship, item) -- SOURCE type Mission_Data(MType: Missions_Types := Deliver) is record Time: Positive := 1; TargetX: Natural range 0 .. Map_X_Range'Last; TargetY: Natural range 0 .. Map_Y_Range'Last; Reward: Positive := 1; StartBase: Bases_Range := 1; Finished: Boolean; Multiplier: RewardMultiplier := 1.0; case MType is when Deliver => ItemIndex: Unbounded_String; when Passenger => Data: Positive := 1; when Destroy => ShipIndex: Unbounded_String; when others => Target: Natural := 0; end case; end record; -- **** -- ****t* Missions/Missions.Mission_Container -- FUNCTION -- Used to store data for missions -- SOURCE package Mission_Container is new Vectors(Positive, Mission_Data); -- **** -- ****v* Missions/Missions.AcceptedMissions -- FUNCTION -- List of missions accepted by player -- SOURCE AcceptedMissions: Mission_Container.Vector; -- **** -- ****e* Missions/Missions.Missions_Accepting_Error -- FUNCTION -- Raised when mission can't be accepted -- SOURCE Missions_Accepting_Error: exception; -- **** -- ****e* Missions/Missions.Missions_Finishing_Error -- FUNCTION -- Raised when mission can't be finished -- SOURCE Missions_Finishing_Error: exception; -- **** -- ****f* Missions/Missions.GenerateMissions -- FUNCTION -- Generate if needed new missions in base -- SOURCE procedure GenerateMissions with Test_Case => (Name => "Test_GenerateMissions", Mode => Robustness); -- **** -- ****f* Missions/Missions.AcceptMission -- FUNCTION -- Accept selected mission from base -- PARAMETERS -- MissionIndex - Base list of available missions index of mission to -- accept -- SOURCE procedure AcceptMission(MissionIndex: Positive) with Test_Case => (Name => "Test_AcceptMission", Mode => Nominal); -- **** -- ****f* Missions/Missions.UpdateMissions -- FUNCTION -- Update accepted missions -- PARAMETERS -- Minutes - Amount of passed minutes -- SOURCE procedure UpdateMissions(Minutes: Positive) with Test_Case => (Name => "Test_UpdateMissions", Mode => Robustness); -- **** -- ****f* Missions/Missions.FinishMission -- FUNCTION -- Finish selected mission -- PARAMETERS -- MissionIndex - Player ship list of accepted missions index of mission -- to finish -- SOURCE procedure FinishMission(MissionIndex: Positive) with Pre => MissionIndex <= AcceptedMissions.Last_Index, Test_Case => (Name => "Test_FinishMission", Mode => Nominal); -- **** -- ****f* Missions/Missions.DeleteMission -- FUNCTION -- Delete selected mission -- PARAMETERS -- MissionIndex - Player ship list of accepted missions index of mission -- to delete -- Failed - If true, it is failed mission. Default is true. -- SOURCE procedure DeleteMission (MissionIndex: Positive; Failed: Boolean := True) with Pre => MissionIndex <= AcceptedMissions.Last_Index, Test_Case => (Name => "Test_DeleteMission", Mode => Nominal); -- **** -- ****f* Missions/Missions.UpdateMission -- FUNCTION -- Update status of mission -- PARAMETERS -- MissionIndex - Player ship list of accepted missions index of mission -- to update -- SOURCE procedure UpdateMission(MissionIndex: Positive) with Pre => MissionIndex <= AcceptedMissions.Last_Index, Test_Case => (Name => "Test_UpdateMission", Mode => Nominal); -- **** -- ****f* Missions/Missions.AutoFinishMissions -- FUNCTION -- Finish all possible missions. -- RESULT -- Empty string if everything is ok, otherwise message with information -- what goes wrong -- SOURCE function AutoFinishMissions return String with Test_Case => (Name => "Test_AutoFinishMissions", Mode => Robustness); -- **** -- ****f* Missions/Missions.Get_Mission_Type -- FUNCTION -- Get the name of the type of the selected mission -- PARAMETERS -- MType - The type of mission which name will be get -- RESULT -- Name (as words) of the selected mission's type -- SOURCE function Get_Mission_Type(MType: Missions_Types) return String with Post => Get_Mission_Type'Result'Length > 0, Test_Case => (Name => "Test_Get_Mission_Type", Mode => Nominal); -- **** end Missions;
-- Copyright 2017 Steven Stewart-Gallus -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -- implied. See the License for the specific language governing -- permissions and limitations under the License. with Ada.Dispatching; package body Linted.Sched is High_Contention_Count : constant := 16; procedure Backoff (State : in out Backoff_State) is begin if State < 20 then Pause; else Ada.Dispatching.Yield; end if; if State /= Backoff_State'Last then State := State + 1; end if; end Backoff; procedure Success (C : in out Contention) is begin Contention_Atomics.Saturating_Decrement (Contention_Atomics.Atomic (C)); end Success; procedure Backoff (C : in out Contention) is My_Contention : Contention_T; begin Contention_Atomics.Get (Contention_Atomics.Atomic (C), My_Contention); Contention_Atomics.Saturating_Decrement (Contention_Atomics.Atomic (C)); if My_Contention < High_Contention_Count then Pause; else Ada.Dispatching.Yield; end if; end Backoff; procedure Backoff (C : in out Contention; Highly_Contended : out Boolean) is My_Contention : Contention_T; begin Contention_Atomics.Get (Contention_Atomics.Atomic (C), My_Contention); Contention_Atomics.Saturating_Decrement (Contention_Atomics.Atomic (C)); if My_Contention < High_Contention_Count then Pause; Highly_Contended := False; return; end if; Highly_Contended := True; end Backoff; end Linted.Sched;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with AMF.CMOF.Elements.Collections; package body AMF.Visitors.Generic_CMOF_Containment is procedure Visit_Owned_Elements (Self : in out CMOF_Containment_Iterator'Class; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null access AMF.CMOF.Elements.CMOF_Element'Class; Control : in out Traverse_Control); -- Visit members of ownedElement of the element. ----------------------- -- Visit_Association -- ----------------------- overriding procedure Visit_Association (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Associations.CMOF_Association_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Association; ----------------- -- Visit_Class -- ----------------- overriding procedure Visit_Class (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Classes.CMOF_Class_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Class; ------------------- -- Visit_Comment -- ------------------- overriding procedure Visit_Comment (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Comments.CMOF_Comment_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Comment; ---------------------- -- Visit_Constraint -- ---------------------- overriding procedure Visit_Constraint (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Constraints.CMOF_Constraint_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Constraint; --------------------- -- Visit_Data_Type -- --------------------- overriding procedure Visit_Data_Type (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Data_Types.CMOF_Data_Type_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Data_Type; -------------------------- -- Visit_Element_Import -- -------------------------- overriding procedure Visit_Element_Import (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Element_Imports.CMOF_Element_Import_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Element_Import; ----------------------- -- Visit_Enumeration -- ----------------------- overriding procedure Visit_Enumeration (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Enumerations.CMOF_Enumeration_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Enumeration; ------------------------------- -- Visit_Enumeration_Literal -- ------------------------------- overriding procedure Visit_Enumeration_Literal (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Enumeration_Literals.CMOF_Enumeration_Literal_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Enumeration_Literal; ---------------------- -- Visit_Expression -- ---------------------- overriding procedure Visit_Expression (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Expressions.CMOF_Expression_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Expression; ----------------------------- -- Visit_Opaque_Expression -- ----------------------------- overriding procedure Visit_Opaque_Expression (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Opaque_Expressions.CMOF_Opaque_Expression_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Opaque_Expression; --------------------- -- Visit_Operation -- --------------------- overriding procedure Visit_Operation (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Operations.CMOF_Operation_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Operation; -------------------------- -- Visit_Owned_Elements -- -------------------------- procedure Visit_Owned_Elements (Self : in out CMOF_Containment_Iterator'Class; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null access AMF.CMOF.Elements.CMOF_Element'Class; Control : in out Traverse_Control) is Owned_Element : constant AMF.CMOF.Elements.Collections.Set_Of_CMOF_Element := Element.Get_Owned_Element; begin for J in 1 .. Owned_Element.Length loop AMF.Visitors.Visit (Self, Visitor, AMF.Elements.Element_Access (Owned_Element.Element (J)), Control); case Control is when Continue => null; when Abandon_Children => Control := Continue; when Abandon_Sibling => Control := Continue; exit; when Terminate_Immediately => exit; end case; end loop; end Visit_Owned_Elements; ------------------- -- Visit_Package -- ------------------- overriding procedure Visit_Package (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Packages.CMOF_Package_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Package; -------------------------- -- Visit_Package_Import -- -------------------------- overriding procedure Visit_Package_Import (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Package_Imports.CMOF_Package_Import_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Package_Import; ------------------------- -- Visit_Package_Merge -- ------------------------- overriding procedure Visit_Package_Merge (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Package_Merges.CMOF_Package_Merge_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Package_Merge; --------------------- -- Visit_Parameter -- --------------------- overriding procedure Visit_Parameter (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Parameters.CMOF_Parameter_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Parameter; -------------------------- -- Visit_Primitive_Type -- -------------------------- overriding procedure Visit_Primitive_Type (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Primitive_Types.CMOF_Primitive_Type_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Primitive_Type; -------------------- -- Visit_Property -- -------------------- overriding procedure Visit_Property (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Properties.CMOF_Property_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Property; --------------- -- Visit_Tag -- --------------- overriding procedure Visit_Tag (Self : in out CMOF_Containment_Iterator; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Element : not null AMF.CMOF.Tags.CMOF_Tag_Access; Control : in out AMF.Visitors.Traverse_Control) is begin Self.Visit_Owned_Elements (Visitor, Element, Control); end Visit_Tag; end AMF.Visitors.Generic_CMOF_Containment;
-- -- Copyright (C) 2015-2016 secunet Security Networks AG -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program 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. -- private package HW.GFX.GMA.PLLs with Abstract_State => (State with Part_Of => GMA.State) is -- NOTE: Order of DPLLs is twisted, as DPLL2 (WRPLL1) -- should be selected as last choice. -- XXX: Types should be private (but that triggers a bug in SPARK GPL 2016) type T is (Invalid_PLL, DPLL0, DPLL1, DPLL3, DPLL2); subtype Configurable_DPLLs is T range DPLL1 .. DPLL2; Invalid : constant T := Invalid_PLL; procedure Initialize with Global => (Output => State); procedure Alloc (Port_Cfg : in Port_Config; PLL : out T; Success : out Boolean); procedure Free (PLL : T); procedure All_Off; function Register_Value (PLL : T) return Word32; end HW.GFX.GMA.PLLs;
with Ada.Numerics.Generic_Elementary_Functions; with Ada.Numerics.Float_Random; package body Simulated_Annealing is package Value_Functions is new Ada.Numerics.Generic_Elementary_Functions (Float); use Value_Functions; EPSILON : constant Float := 0.001; Generator : Ada.Numerics.Float_Random.Generator; function Acceptable (E_Diff, Temperature : Float) return Boolean is (E_Diff < 0.0 or else Ada.Numerics.Float_Random.Random (Generator) <= Exp (-E_Diff / Temperature)); function Exponential (N : Positive; T0 : Float) return Scheduler is (T0 => T0, Decay => Log (EPSILON / T0) / Float (N), I => 0); procedure Step (S : in out Scheduler) is begin S.I := S.I + 1; end Step; function Temperature (S : in Scheduler) return Float is TI : Float := S.T0 * Exp (S.Decay * Float (S.I)); begin if TI < EPSILON then TI := 0.0; end if; return TI; end Temperature; package body Optimization is function Minimize (S0 : in State) return Minimization is (S_I => S0, S_Min => S0); function Step (M : in out Minimization; S : in out Scheduler; Improved : out Boolean) return Boolean is T : Float := Temperature (S); begin Improved := False; if T > 0.0 then declare S_J : State := Perturb (M.S_I); E_Diff : Float := Energy (S_J) - Energy (M.S_I); begin if Acceptable (E_Diff, T) then M.S_I := S_J; if Energy (M.S_I) < Energy (M.S_Min) then M.S_Min := M.S_I; Improved := True; end if; end if; Step (S); end; return True; else return False; end if; end Step; function Minimum (M : in Minimization) return State is (M.S_Min); end Optimization; end Simulated_Annealing;