Dataset Viewer (First 5GB)
Auto-converted to Parquet
text
stringlengths
437
491k
meta
dict
package body Bubble with SPARK_Mode is procedure Sort (A : in out Arr) is Tmp : Integer; begin Outer: for I in reverse A'First .. A'Last - 1 loop Inner: for J in A'First .. I loop if A(J) > A(J + 1) then Tmp := A(J); A(J) := A(J + 1); A(J + 1) := Tmp; end if; pragma Loop_Invariant (for all K1 in A'Range => (for some K2 in A'Range => A(K2) = A'Loop_Entry(Inner)(K1))); end loop Inner; pragma Loop_Invariant (for all K1 in A'Range => (for some K2 in A'Range => A(K2) = A'Loop_Entry(Outer)(K1))); end loop Outer; end Sort; end Bubble;
{ "source": "starcoderdata", "programming_language": "ada" }
-- -- ------------------------------------------------------------------------------ with Ada.Unchecked_Conversion; package body ST7735R is --------------------------- -- Register definitions -- --------------------------- type MADCTL is record Reserved1, Reserved2 : Boolean; MH : Horizontal_Refresh_Order; RGB : RGB_BGR_Order; ML : Vertical_Refresh_Order; MV : Boolean; MX : Column_Address_Order; MY : Row_Address_Order; end record with Size => 8, Bit_Order => System.Low_Order_First; for MADCTL use record Reserved1 at 0 range 0 .. 0; Reserved2 at 0 range 1 .. 1; MH at 0 range 2 .. 2; RGB at 0 range 3 .. 3; ML at 0 range 4 .. 4; MV at 0 range 5 .. 5; MX at 0 range 6 .. 6; MY at 0 range 7 .. 7; end record; function To_UInt8 is new Ada.Unchecked_Conversion (MADCTL, UInt8); procedure Write_Command (LCD : ST7735R_Screen'Class; Cmd : UInt8); procedure Write_Command (LCD : ST7735R_Screen'Class; Cmd : UInt8; Data : HAL.UInt8_Array); procedure Write_Pix_Repeat (LCD : ST7735R_Screen'Class; Data : UInt16; Count : Natural); -- Send the same pixel data Count times. This is used to fill an area with -- the same color without allocating a buffer. procedure Write_Data (LCD : ST7735R_Screen'Class; Data : HAL.UInt8_Array); procedure Read_Data (LCD : ST7735R_Screen'Class; Data : out UInt16); procedure Set_Command_Mode (LCD : ST7735R_Screen'Class); procedure Set_Data_Mode (LCD : ST7735R_Screen'Class); procedure Start_Transaction (LCD : ST7735R_Screen'Class); procedure End_Transaction (LCD : ST7735R_Screen'Class); ---------------------- -- Set_Command_Mode -- ---------------------- procedure Set_Command_Mode (LCD : ST7735R_Screen'Class) is begin LCD.RS.Clear; end Set_Command_Mode; ------------------- -- Set_Data_Mode -- ------------------- procedure Set_Data_Mode (LCD : ST7735R_Screen'Class) is begin LCD.RS.Set; end Set_Data_Mode; ----------------------- -- Start_Transaction -- ----------------------- procedure Start_Transaction (LCD : ST7735R_Screen'Class) is begin LCD.CS.Clear; end Start_Transaction; --------------------- -- End_Transaction -- --------------------- procedure End_Transaction (LCD : ST7735R_Screen'Class) is begin LCD.CS.Set; end End_Transaction; ------------------- -- Write_Command -- ------------------- procedure Write_Command (LCD : ST7735R_Screen'Class; Cmd : UInt8) is Status : SPI_Status; begin Start_Transaction (LCD); Set_Command_Mode (LCD); LCD.Port.Transmit (SPI_Data_8b'(1 => Cmd), Status); End_Transaction (LCD); if Status /= Ok then -- No error handling... raise Program_Error; end if; end Write_Command; ------------------- -- Write_Command -- ------------------- procedure Write_Command (LCD : ST7735R_Screen'Class; Cmd : UInt8; Data : HAL.UInt8_Array) is begin Write_Command (LCD, Cmd); Write_Data (LCD, Data); end Write_Command; ---------------- -- Write_Data -- ---------------- procedure Write_Data (LCD : ST7735R_Screen'Class; Data : HAL.UInt8_Array) is Status : SPI_Status; begin Start_Transaction (LCD); Set_Data_Mode (LCD); LCD.Port.Transmit (SPI_Data_8b (Data), Status); if Status /= Ok then -- No error handling... raise Program_Error; end if; End_Transaction (LCD); end Write_Data; ---------------------- -- Write_Pix_Repeat -- ---------------------- procedure Write_Pix_Repeat (LCD : ST7735R_Screen'Class; Data : UInt16; Count : Natural) is Status : SPI_Status; Data8 : constant SPI_Data_8b := SPI_Data_8b'(1 => UInt8 (Shift_Right (Data, 8) and 16#FF#), 2 => UInt8 (Data and 16#FF#)); begin Write_Command (LCD, 16#2C#); Start_Transaction (LCD); Set_Data_Mode (LCD); for X in 1 .. Count loop LCD.Port.Transmit (Data8, Status); if Status /= Ok then -- No error handling... raise Program_Error; end if; end loop; End_Transaction (LCD); end Write_Pix_Repeat; --------------- -- Read_Data -- --------------- procedure Read_Data (LCD : ST7735R_Screen'Class; Data : out UInt16) is SPI_Data : SPI_Data_16b (1 .. 1); Status : SPI_Status; begin Start_Transaction (LCD); Set_Data_Mode (LCD); LCD.Port.Receive (SPI_Data, Status); if Status /= Ok then -- No error handling... raise Program_Error; end if; End_Transaction (LCD); Data := SPI_Data (SPI_Data'First); end Read_Data; ---------------- -- Initialize -- ---------------- procedure Initialize (LCD : in out ST7735R_Screen) is begin LCD.Layer.LCD := LCD'Unchecked_Access; LCD.RST.Clear; LCD.Time.Delay_Milliseconds (100); LCD.RST.Set; LCD.Time.Delay_Milliseconds (100); -- Sleep Exit Write_Command (LCD, 16#11#); LCD.Time.Delay_Milliseconds (100); LCD.Initialized := True; end Initialize; ----------------- -- Initialized -- ----------------- overriding function Initialized (LCD : ST7735R_Screen) return Boolean is (LCD.Initialized); ------------- -- Turn_On -- ------------- procedure Turn_On (LCD : ST7735R_Screen) is begin Write_Command (LCD, 16#29#); end Turn_On; -------------- -- Turn_Off -- -------------- procedure Turn_Off (LCD : ST7735R_Screen) is begin Write_Command (LCD, 16#28#); end Turn_Off; -------------------------- -- Display_Inversion_On -- -------------------------- procedure Display_Inversion_On (LCD : ST7735R_Screen) is begin Write_Command (LCD, 16#21#); end Display_Inversion_On; --------------------------- -- Display_Inversion_Off -- --------------------------- procedure Display_Inversion_Off (LCD : ST7735R_Screen) is begin Write_Command (LCD, 16#20#); end Display_Inversion_Off; --------------- -- Gamma_Set -- --------------- procedure Gamma_Set (LCD : ST7735R_Screen; Gamma_Curve : UInt4) is begin Write_Command (LCD, 16#26#, (0 => UInt8 (Gamma_Curve))); end Gamma_Set; ---------------------- -- Set_Pixel_Format -- ---------------------- procedure Set_Pixel_Format (LCD : ST7735R_Screen; Pix_Fmt : Pixel_Format) is Value : constant UInt8 := (case Pix_Fmt is when Pixel_12bits => 2#011#, when Pixel_16bits => 2#101#, when Pixel_18bits => 2#110#); begin Write_Command (LCD, 16#3A#, (0 => Value)); end Set_Pixel_Format; ---------------------------- -- Set_Memory_Data_Access -- ---------------------------- procedure Set_Memory_Data_Access (LCD : ST7735R_Screen; Color_Order : RGB_BGR_Order; Vertical : Vertical_Refresh_Order; Horizontal : Horizontal_Refresh_Order; Row_Addr_Order : Row_Address_Order; Column_Addr_Order : Column_Address_Order; Row_Column_Exchange : Boolean) is Value : MADCTL; begin Value.MY := Row_Addr_Order; Value.MX := Column_Addr_Order; Value.MV := Row_Column_Exchange; Value.ML := Vertical; Value.RGB := Color_Order; Value.MH := Horizontal; Write_Command (LCD, 16#36#, (0 => To_UInt8 (Value))); end Set_Memory_Data_Access; --------------------------- -- Set_Frame_Rate_Normal -- --------------------------- procedure Set_Frame_Rate_Normal (LCD : ST7735R_Screen; RTN : UInt4; Front_Porch : UInt6; Back_Porch : UInt6) is begin Write_Command (LCD, 16#B1#, (UInt8 (RTN), UInt8 (Front_Porch), UInt8 (Back_Porch))); end Set_Frame_Rate_Normal; ------------------------- -- Set_Frame_Rate_Idle -- ------------------------- procedure Set_Frame_Rate_Idle (LCD : ST7735R_Screen; RTN : UInt4; Front_Porch : UInt6; Back_Porch : UInt6) is begin Write_Command (LCD, 16#B2#, (UInt8 (RTN), UInt8 (Front_Porch), UInt8 (Back_Porch))); end Set_Frame_Rate_Idle; --------------------------------- -- Set_Frame_Rate_Partial_Full -- --------------------------------- procedure Set_Frame_Rate_Partial_Full (LCD : ST7735R_Screen; RTN_Part : UInt4; Front_Porch_Part : UInt6; Back_Porch_Part : UInt6; RTN_Full : UInt4; Front_Porch_Full : UInt6; Back_Porch_Full : UInt6) is begin Write_Command (LCD, 16#B3#, (UInt8 (RTN_Part), UInt8 (Front_Porch_Part), UInt8 (Back_Porch_Part), UInt8 (RTN_Full), UInt8 (Front_Porch_Full), UInt8 (Back_Porch_Full))); end Set_Frame_Rate_Partial_Full; --------------------------- -- Set_Inversion_Control -- --------------------------- procedure Set_Inversion_Control (LCD : ST7735R_Screen; Normal, Idle, Full_Partial : Inversion_Control) is Value : UInt8 := 0; begin if Normal = Line_Inversion then Value := Value or 2#100#; end if; if Idle = Line_Inversion then Value := Value or 2#010#; end if; if Full_Partial = Line_Inversion then Value := Value or 2#001#; end if; Write_Command (LCD, 16#B4#, (0 => Value)); end Set_Inversion_Control; ------------------------- -- Set_Power_Control_1 -- ------------------------- procedure Set_Power_Control_1 (LCD : ST7735R_Screen; AVDD : UInt3; VRHP : UInt5; VRHN : UInt5; MODE : UInt2) is P1, P2, P3 : UInt8; begin P1 := Shift_Left (UInt8 (AVDD), 5) or UInt8 (VRHP); P2 := UInt8 (VRHN); P3 := Shift_Left (UInt8 (MODE), 6) or 2#00_0100#; Write_Command (LCD, 16#C0#, (P1, P2, P3)); end Set_Power_Control_1; ------------------------- -- Set_Power_Control_2 -- ------------------------- procedure Set_Power_Control_2 (LCD : ST7735R_Screen; VGH25 : UInt2; VGSEL : UInt2; VGHBT : UInt2) is P1 : UInt8; begin P1 := Shift_Left (UInt8 (VGH25), 6) or Shift_Left (UInt8 (VGSEL), 2) or UInt8 (VGHBT); Write_Command (LCD, 16#C1#, (0 => P1)); end Set_Power_Control_2; ------------------------- -- Set_Power_Control_3 -- ------------------------- procedure Set_Power_Control_3 (LCD : ST7735R_Screen; P1, P2 : UInt8) is begin Write_Command (LCD, 16#C2#, (P1, P2)); end Set_Power_Control_3; ------------------------- -- Set_Power_Control_4 -- ------------------------- procedure Set_Power_Control_4 (LCD : ST7735R_Screen; P1, P2 : UInt8) is begin Write_Command (LCD, 16#C3#, (P1, P2)); end Set_Power_Control_4; ------------------------- -- Set_Power_Control_5 -- ------------------------- procedure Set_Power_Control_5 (LCD : ST7735R_Screen; P1, P2 : UInt8) is begin Write_Command (LCD, 16#C4#, (P1, P2)); end Set_Power_Control_5; -------------- -- Set_Vcom -- -------------- procedure Set_Vcom (LCD : ST7735R_Screen; VCOMS : UInt6) is begin Write_Command (LCD, 16#C5#, (0 => UInt8 (VCOMS))); end Set_Vcom; ------------------------ -- Set_Column_Address -- ------------------------ procedure Set_Column_Address (LCD : ST7735R_Screen; X_Start, X_End : UInt16) is P1, P2, P3, P4 : UInt8; begin P1 := UInt8 (Shift_Right (X_Start and 16#FF#, 8)); P2 := UInt8 (X_Start and 16#FF#); P3 := UInt8 (Shift_Right (X_End and 16#FF#, 8)); P4 := UInt8 (X_End and 16#FF#); Write_Command (LCD, 16#2A#, (P1, P2, P3, P4)); end Set_Column_Address; --------------------- -- Set_Row_Address -- --------------------- procedure Set_Row_Address (LCD : ST7735R_Screen; Y_Start, Y_End : UInt16) is P1, P2, P3, P4 : UInt8; begin P1 := UInt8 (Shift_Right (Y_Start and 16#FF#, 8)); P2 := UInt8 (Y_Start and 16#FF#); P3 := UInt8 (Shift_Right (Y_End and 16#FF#, 8)); P4 := UInt8 (Y_End and 16#FF#); Write_Command (LCD, 16#2B#, (P1, P2, P3, P4)); end Set_Row_Address; ----------------- -- Set_Address -- ----------------- procedure Set_Address (LCD : ST7735R_Screen; X_Start, X_End, Y_Start, Y_End : UInt16) is begin Set_Column_Address (LCD, X_Start, X_End); Set_Row_Address (LCD, Y_Start, Y_End); end Set_Address; --------------- -- Set_Pixel -- --------------- procedure Set_Pixel (LCD : ST7735R_Screen; X, Y : UInt16; Color : UInt16) is Data : HAL.UInt16_Array (1 .. 1) := (1 => Color); begin Set_Address (LCD, X, X + 1, Y, Y + 1); Write_Raw_Pixels (LCD, Data); end Set_Pixel; ----------- -- Pixel -- ----------- function Pixel (LCD : ST7735R_Screen; X, Y : UInt16) return UInt16 is Ret : UInt16; begin Set_Address (LCD, X, X + 1, Y, Y + 1); Read_Data (LCD, Ret); return Ret; end Pixel; ---------------------- -- Write_Raw_Pixels -- ---------------------- procedure Write_Raw_Pixels (LCD : ST7735R_Screen; Data : in out HAL.UInt8_Array) is Index : Natural := Data'First + 1; Tmp : UInt8; begin -- The ST7735R uses a different endianness than our bitmaps while Index <= Data'Last loop Tmp := Data (Index); Data (Index) := Data (Index - 1); Data (Index - 1) := Tmp; Index := Index + 1; end loop; Write_Command (LCD, 16#2C#); Write_Data (LCD, Data); end Write_Raw_Pixels; ---------------------- -- Write_Raw_Pixels -- ---------------------- procedure Write_Raw_Pixels (LCD : ST7735R_Screen; Data : in out HAL.UInt16_Array) is Data_8b : HAL.UInt8_Array (1 .. Data'Length * 2) with Address => Data'Address; begin Write_Raw_Pixels (LCD, Data_8b); end Write_Raw_Pixels; -------------------- -- Get_Max_Layers -- -------------------- overriding function Max_Layers (Display : ST7735R_Screen) return Positive is (1); ------------------ -- Is_Supported -- ------------------ overriding function Supported (Display : ST7735R_Screen; Mode : FB_Color_Mode) return Boolean is (Mode = HAL.Bitmap.RGB_565); --------------------- -- Set_Orientation -- --------------------- overriding procedure Set_Orientation (Display : in out ST7735R_Screen; Orientation : Display_Orientation) is begin null; end Set_Orientation; -------------- -- Set_Mode -- -------------- overriding procedure Set_Mode (Display : in out ST7735R_Screen; Mode : Wait_Mode) is begin null; end Set_Mode; --------------- -- Get_Width -- --------------- overriding function Width (Display : ST7735R_Screen) return Positive is (Screen_Width); ---------------- -- Get_Height -- ---------------- overriding function Height (Display : ST7735R_Screen) return Positive is (Screen_Height); ---------------- -- Is_Swapped -- ---------------- overriding function Swapped (Display : ST7735R_Screen) return Boolean is (False); -------------------- -- Set_Background -- -------------------- overriding procedure Set_Background (Display : ST7735R_Screen; R, G, B : UInt8) is begin -- Does it make sense when there's no alpha channel... raise Program_Error; end Set_Background; ---------------------- -- Initialize_Layer -- ---------------------- overriding procedure Initialize_Layer (Display : in out ST7735R_Screen; Layer : Positive; Mode : FB_Color_Mode; X : Natural := 0; Y : Natural := 0; Width : Positive := Positive'Last; Height : Positive := Positive'Last) is pragma Unreferenced (X, Y); begin if Layer /= 1 or else Mode /= RGB_565 then raise Program_Error; end if; Display.Layer.Width := Width; Display.Layer.Height := Height; end Initialize_Layer; ----------------- -- Initialized -- ----------------- overriding function Initialized (Display : ST7735R_Screen; Layer : Positive) return Boolean is pragma Unreferenced (Display); begin return Layer = 1; end Initialized; ------------------ -- Update_Layer -- ------------------ overriding procedure Update_Layer (Display : in out ST7735R_Screen; Layer : Positive; Copy_Back : Boolean := False) is pragma Unreferenced (Copy_Back, Display); begin if Layer /= 1 then raise Program_Error; end if; end Update_Layer; ------------------- -- Update_Layers -- ------------------- overriding procedure Update_Layers (Display : in out ST7735R_Screen) is begin Display.Update_Layer (1); end Update_Layers; -------------------- -- Get_Color_Mode -- -------------------- overriding function Color_Mode (Display : ST7735R_Screen; Layer : Positive) return FB_Color_Mode is pragma Unreferenced (Display); begin if Layer /= 1 then raise Program_Error; end if; return RGB_565; end Color_Mode; ----------------------- -- Get_Hidden_Buffer -- ----------------------- overriding function Hidden_Buffer (Display : in out ST7735R_Screen; Layer : Positive) return not null HAL.Bitmap.Any_Bitmap_Buffer is begin if Layer /= 1 then raise Program_Error; end if; return Display.Layer'Unchecked_Access; end Hidden_Buffer; ---------------- -- Pixel_Size -- ---------------- overriding function Pixel_Size (Display : ST7735R_Screen; Layer : Positive) return Positive is (16); ---------------- -- Set_Source -- ---------------- overriding procedure Set_Source (Buffer : in out ST7735R_Bitmap_Buffer; Native : UInt32) is begin Buffer.Native_Source := Native; end Set_Source; ------------ -- Source -- ------------ overriding function Source (Buffer : ST7735R_Bitmap_Buffer) return UInt32 is begin return Buffer.Native_Source; end Source; --------------- -- Set_Pixel -- --------------- overriding procedure Set_Pixel (Buffer : in out ST7735R_Bitmap_Buffer; Pt : Point) is begin Buffer.LCD.Set_Pixel (UInt16 (Pt.X), UInt16 (Pt.Y), UInt16 (Buffer.Native_Source)); end Set_Pixel; --------------------- -- Set_Pixel_Blend -- --------------------- overriding procedure Set_Pixel_Blend (Buffer : in out ST7735R_Bitmap_Buffer; Pt : Point) renames Set_Pixel; ----------- -- Pixel -- ----------- overriding function Pixel (Buffer : ST7735R_Bitmap_Buffer; Pt : Point) return UInt32 is (UInt32 (Buffer.LCD.Pixel (UInt16 (Pt.X), UInt16 (Pt.Y)))); ---------- -- Fill -- ---------- overriding procedure Fill (Buffer : in out ST7735R_Bitmap_Buffer) is begin -- Set the drawing area over the entire layer Set_Address (Buffer.LCD.all, 0, UInt16 (Buffer.Width - 1), 0, UInt16 (Buffer.Height - 1)); -- Fill the drawing area with a single color Write_Pix_Repeat (Buffer.LCD.all, UInt16 (Buffer.Native_Source and 16#FFFF#), Buffer.Width * Buffer.Height); end Fill; --------------- -- Fill_Rect -- --------------- overriding procedure Fill_Rect (Buffer : in out ST7735R_Bitmap_Buffer; Area : Rect) is begin -- Set the drawing area coresponding to the rectangle to draw Set_Address (Buffer.LCD.all, UInt16 (Area.Position.X), UInt16 (Area.Position.X + Area.Width - 1), UInt16 (Area.Position.Y), UInt16 (Area.Position.Y + Area.Height - 1)); -- Fill the drawing area with a single color Write_Pix_Repeat (Buffer.LCD.all, UInt16 (Buffer.Native_Source and 16#FFFF#), Area.Width * Area.Height); end Fill_Rect; ------------------------ -- Draw_Vertical_Line -- ------------------------ overriding procedure Draw_Vertical_Line (Buffer : in out ST7735R_Bitmap_Buffer; Pt : Point; Height : Integer) is begin -- Set the drawing area coresponding to the line to draw Set_Address (Buffer.LCD.all, UInt16 (Pt.X), UInt16 (Pt.X), UInt16 (Pt.Y), UInt16 (Pt.Y + Height - 1)); -- Fill the drawing area with a single color Write_Pix_Repeat (Buffer.LCD.all, UInt16 (Buffer.Native_Source and 16#FFFF#), Height); end Draw_Vertical_Line; -------------------------- -- Draw_Horizontal_Line -- -------------------------- overriding procedure Draw_Horizontal_Line (Buffer : in out ST7735R_Bitmap_Buffer; Pt : Point; Width : Integer) is begin -- Set the drawing area coresponding to the line to draw Set_Address (Buffer.LCD.all, UInt16 (Pt.X), UInt16 (Pt.X + Width), UInt16 (Pt.Y), UInt16 (Pt.Y)); -- Fill the drawing area with a single color Write_Pix_Repeat (Buffer.LCD.all, UInt16 (Buffer.Native_Source and 16#FFFF#), Width); end Draw_Horizontal_Line; end ST7735R;
{ "source": "starcoderdata", "programming_language": "ada" }
--* -- OBJECTIVE: -- CHECK THAT AN UNCONSTRAINED ARRAY TYPE OR A RECORD WITHOUT -- DEFAULT DISCRIMINANTS CAN BE USED IN AN ACCESS_TYPE_DEFINITION -- WITHOUT AN INDEX OR DISCRIMINANT CONSTRAINT. -- -- CHECK THAT (NON-STATIC) INDEX OR DISCRIMINANT CONSTRAINTS CAN -- SUBSEQUENTLY BE IMPOSED WHEN THE TYPE IS USED IN AN OBJECT -- DECLARATION, ARRAY COMPONENT DECLARATION, RECORD COMPONENT -- DECLARATION, ACCESS TYPE DECLARATION, PARAMETER DECLARATION, -- DERIVED TYPE DEFINITION, PRIVATE TYPE. -- -- CHECK FOR UNCONSTRAINED GENERIC FORMAL TYPE. -- HISTORY: -- AH 09/02/86 CREATED ORIGINAL TEST. -- DHH 08/16/88 REVISED HEADER AND ENTERED COMMENTS FOR PRIVATE TYPE -- AND CORRECTED INDENTATION. -- BCB 04/12/90 ADDED CHECKS FOR AN ARRAY AS A SUBPROGRAM RETURN -- TYPE AND AN ARRAY AS A FORMAL PARAMETER. -- LDC 10/01/90 ADDED CODE SO F, FPROC, G, GPROC AREN'T OPTIMIZED -- AWAY WITH REPORT; USE REPORT; PROCEDURE C38002A IS BEGIN TEST ("C38002A", "NON-STATIC CONSTRAINTS CAN BE IMPOSED " & "ON ACCESS TYPES ACCESSING PREVIOUSLY UNCONSTRAINED " & "ARRAY OR RECORD TYPES"); DECLARE C3 : CONSTANT INTEGER := IDENT_INT(3); TYPE ARR IS ARRAY (INTEGER RANGE <>) OF INTEGER; TYPE ARR_NAME IS ACCESS ARR; SUBTYPE ARR_NAME_3 IS ARR_NAME(1..3); TYPE REC(DISC : INTEGER) IS RECORD COMP : ARR_NAME(1..DISC); END RECORD; TYPE REC_NAME IS ACCESS REC; OBJ : REC_NAME(C3); TYPE ARR2 IS ARRAY (1..10) OF REC_NAME(C3); TYPE REC2 IS RECORD COMP2 : REC_NAME(C3); END RECORD; TYPE NAME_REC_NAME IS ACCESS REC_NAME(C3); TYPE DERIV IS NEW REC_NAME(C3); SUBTYPE REC_NAME_3 IS REC_NAME(C3); FUNCTION F (PARM : REC_NAME_3) RETURN REC_NAME_3 IS BEGIN IF NOT EQUAL(IDENT_INT(3), 1 + IDENT_INT(2)) THEN COMMENT("DON'T OPTIMIZE F AWAY"); END IF; RETURN PARM; END; PROCEDURE FPROC (PARM : REC_NAME_3) IS BEGIN IF NOT EQUAL(IDENT_INT(4), 2 + IDENT_INT(2)) THEN COMMENT("DON'T OPTIMIZE FPROC AWAY"); END IF; END FPROC; FUNCTION G (PA : ARR_NAME_3) RETURN ARR_NAME_3 IS BEGIN IF NOT EQUAL(IDENT_INT(5), 3 + IDENT_INT(2)) THEN COMMENT("DON'T OPTIMIZE G AWAY"); END IF; RETURN PA; END G; PROCEDURE GPROC (PA : ARR_NAME_3) IS BEGIN IF NOT EQUAL(IDENT_INT(6), 4 + IDENT_INT(2)) THEN COMMENT("DON'T OPTIMIZE GPROC AWAY"); END IF; END GPROC; BEGIN DECLARE R : REC_NAME; BEGIN R := NEW REC'(DISC => 3, COMP => NEW ARR'(1..3 => 5)); R := F(R); R := NEW REC'(DISC => 4, COMP => NEW ARR'(1..4 => 5)); R := F(R); FAILED ("INCOMPATIBLE CONSTRAINT ON ACCESS VALUE " & "ACCEPTED BY FUNCTION FOR RECORD"); EXCEPTION WHEN CONSTRAINT_ERROR => IF R = NULL OR ELSE R.DISC /= 4 THEN FAILED ("ERROR IN EVALUATION/ASSIGNMENT OF " & "ACCESS VALUE - RECORD,FUNCTION"); END IF; END; DECLARE R : REC_NAME; BEGIN R := NEW REC'(DISC => 3, COMP => NEW ARR'(1..3 => 5)); FPROC(R); R := NEW REC'(DISC => 4, COMP => NEW ARR'(1..4 => 5)); FPROC(R); FAILED ("INCOMPATIBLE CONSTRAINT ON ACCESS VALUE " & "ACCEPTED BY PROCEDURE FOR RECORD"); EXCEPTION WHEN CONSTRAINT_ERROR => IF R = NULL OR ELSE R.DISC /= 4 THEN FAILED ("ERROR IN EVALUATION/ASSIGNMENT OF " & "ACCESS VALUE - RECORD,PROCEDURE"); END IF; END; DECLARE A : ARR_NAME; BEGIN A := NEW ARR'(1..3 => 5); A := G(A); A := NEW ARR'(1..4 => 6); A := G(A); FAILED ("INCOMPATIBLE CONSTRAINT ON ACCESS VALUE " & "ACCEPTED BY FUNCTION FOR ARRAY"); EXCEPTION WHEN CONSTRAINT_ERROR => IF A = NULL OR ELSE A(4) /= 6 THEN FAILED ("ERROR IN EVALUATION/ASSIGNMENT OF " & "ACCESS VALUE - ARRAY,FUNCTION"); END IF; END; DECLARE A : ARR_NAME; BEGIN A := NEW ARR'(1..3 => 5); GPROC(A); A := NEW ARR'(1..4 => 6); GPROC(A); FAILED ("INCOMPATIBLE CONSTRAINT ON ACCESS VALUE " & "ACCEPTED BY PROCEDURE FOR ARRAY"); EXCEPTION WHEN CONSTRAINT_ERROR => IF A = NULL OR ELSE A(4) /= 6 THEN FAILED ("ERROR IN EVALUATION/ASSIGNMENT OF " & "ACCESS VALUE - ARRAY,PROCEDURE"); END IF; END; END; DECLARE C3 : CONSTANT INTEGER := IDENT_INT(3); TYPE REC (DISC : INTEGER) IS RECORD NULL; END RECORD; TYPE P_ARR IS ARRAY (INTEGER RANGE <>) OF INTEGER; TYPE P_ARR_NAME IS ACCESS P_ARR; TYPE P_REC_NAME IS ACCESS REC; GENERIC TYPE UNCON_ARR IS ARRAY (INTEGER RANGE <>) OF INTEGER; PACKAGE P IS TYPE ACC_REC IS ACCESS REC; TYPE ACC_ARR IS ACCESS UNCON_ARR; TYPE ACC_P_ARR IS ACCESS P_ARR; SUBTYPE ACC_P_ARR_3 IS ACC_P_ARR(1..3); OBJ : ACC_REC(C3); TYPE ARR2 IS ARRAY (1..10) OF ACC_REC(C3); TYPE REC1 IS RECORD COMP1 : ACC_REC(C3); END RECORD; TYPE REC2 IS RECORD COMP2 : ACC_ARR(1..C3); END RECORD; SUBTYPE ACC_REC_3 IS ACC_REC(C3); FUNCTION F (PARM : ACC_REC_3) RETURN ACC_REC_3; PROCEDURE FPROC (PARM : ACC_REC_3); FUNCTION G (PA : ACC_P_ARR_3) RETURN ACC_P_ARR_3; PROCEDURE GPROC (PA : ACC_P_ARR_3); TYPE ACC1 IS PRIVATE; TYPE ACC2 IS PRIVATE; TYPE DER1 IS PRIVATE; TYPE DER2 IS PRIVATE; PRIVATE TYPE ACC1 IS ACCESS ACC_REC(C3); TYPE ACC2 IS ACCESS ACC_ARR(1..C3); TYPE DER1 IS NEW ACC_REC(C3); TYPE DER2 IS NEW ACC_ARR(1..C3); END P; PACKAGE BODY P IS FUNCTION F (PARM : ACC_REC_3) RETURN ACC_REC_3 IS BEGIN IF NOT EQUAL(IDENT_INT(3), 1 + IDENT_INT(2)) THEN COMMENT("DON'T OPTIMIZE F AWAY"); END IF; RETURN PARM; END; PROCEDURE FPROC (PARM : ACC_REC_3) IS BEGIN IF NOT EQUAL(IDENT_INT(4), 2 + IDENT_INT(2)) THEN COMMENT("DON'T OPTIMIZE FPROC AWAY"); END IF; END FPROC; FUNCTION G (PA : ACC_P_ARR_3) RETURN ACC_P_ARR_3 IS BEGIN IF NOT EQUAL(IDENT_INT(5), 3 + IDENT_INT(2)) THEN COMMENT("DON'T OPTIMIZE G AWAY"); END IF; RETURN PA; END; PROCEDURE GPROC (PA : ACC_P_ARR_3) IS BEGIN IF NOT EQUAL(IDENT_INT(6), 4 + IDENT_INT(2)) THEN COMMENT("DON'T OPTIMIZE GPROC AWAY"); END IF; END GPROC; END P; PACKAGE NP IS NEW P (UNCON_ARR => P_ARR); USE NP; BEGIN DECLARE R : ACC_REC; BEGIN R := NEW REC(DISC => 3); R := F(R); R := NEW REC(DISC => 4); R := F(R); FAILED ("INCOMPATIBLE CONSTRAINT ON ACCESS VALUE " & "ACCEPTED BY FUNCTION FOR A RECORD -GENERIC"); EXCEPTION WHEN CONSTRAINT_ERROR => IF R = NULL OR ELSE R.DISC /= 4 THEN FAILED ("ERROR IN EVALUATION/ASSIGNMENT " & "OF ACCESS VALUE - RECORD," & "FUNCTION -GENERIC"); END IF; END; DECLARE R : ACC_REC; BEGIN R := NEW REC(DISC => 3); FPROC(R); R := NEW REC(DISC => 4); FPROC(R); FAILED ("INCOMPATIBLE CONSTRAINT ON ACCESS VALUE " & "ACCEPTED BY PROCEDURE FOR A RECORD -GENERIC"); EXCEPTION WHEN CONSTRAINT_ERROR => IF R = NULL OR ELSE R.DISC /= 4 THEN FAILED ("ERROR IN EVALUATION/ASSIGNMENT " & "OF ACCESS VALUE - RECORD," & "PROCEDURE -GENERIC"); END IF; END; DECLARE A : ACC_P_ARR; BEGIN A := NEW P_ARR'(1..3 => 5); A := G(A); A := NEW P_ARR'(1..4 => 6); A := G(A); FAILED ("INCOMPATIBLE CONSTRAINT ON ACCESS VALUE " & "ACCEPTED BY FUNCTION FOR AN ARRAY -GENERIC"); EXCEPTION WHEN CONSTRAINT_ERROR => IF A = NULL OR ELSE A(4) /= 6 THEN FAILED ("ERROR IN EVALUATION/ASSIGNMENT " & "OF ACCESS VALUE - ARRAY," & "FUNCTION -GENERIC"); END IF; END; DECLARE A : ACC_P_ARR; BEGIN A := NEW P_ARR'(1..3 => 5); GPROC(A); A := NEW P_ARR'(1..4 => 6); GPROC(A); FAILED ("INCOMPATIBLE CONSTRAINT ON ACCESS VALUE " & "ACCEPTED BY PROCEDURE FOR AN ARRAY -GENERIC"); EXCEPTION WHEN CONSTRAINT_ERROR => IF A = NULL OR ELSE A(4) /= 6 THEN FAILED ("ERROR IN EVALUATION/ASSIGNMENT " & "OF ACCESS VALUE - ARRAY," & "PROCEDURE -GENERIC"); END IF; END; END; DECLARE TYPE CON_INT IS RANGE 1..10; GENERIC TYPE UNCON_INT IS RANGE <>; PACKAGE P2 IS SUBTYPE NEW_INT IS UNCON_INT RANGE 1..5; FUNCTION FUNC_INT (PARM : NEW_INT) RETURN NEW_INT; PROCEDURE PROC_INT (PARM : NEW_INT); END P2; PACKAGE BODY P2 IS FUNCTION FUNC_INT (PARM : NEW_INT) RETURN NEW_INT IS BEGIN IF NOT EQUAL(IDENT_INT(3), 1 + IDENT_INT(2)) THEN COMMENT("DON'T OPTIMIZE F AWAY"); END IF; RETURN PARM; END FUNC_INT; PROCEDURE PROC_INT (PARM : NEW_INT) IS BEGIN IF NOT EQUAL(IDENT_INT(4), 2 + IDENT_INT(2)) THEN COMMENT("DON'T OPTIMIZE FPROC AWAY"); END IF; END PROC_INT; END P2; PACKAGE NP2 IS NEW P2 (UNCON_INT => CON_INT); USE NP2; BEGIN DECLARE R : CON_INT; BEGIN R := 2; R := FUNC_INT(R); R := 8; R := FUNC_INT(R); FAILED ("INCOMPATIBLE CONSTRAINT ON VALUE " & "ACCEPTED BY FUNCTION -GENERIC"); EXCEPTION WHEN CONSTRAINT_ERROR => IF R /= 8 THEN FAILED ("ERROR IN EVALUATION/ASSIGNMENT " & "OF VALUE -FUNCTION, GENERIC"); END IF; END; DECLARE R : CON_INT; BEGIN R := 2; PROC_INT(R); R := 9; PROC_INT(R); FAILED ("INCOMPATIBLE CONSTRAINT ON ACCESS VALUE " & "ACCEPTED BY PROCEDURE -GENERIC"); EXCEPTION WHEN CONSTRAINT_ERROR => IF R /= 9 THEN FAILED ("ERROR IN EVALUATION/ASSIGNMENT " & "OF ACCESS VALUE - PROCEDURE, " & "GENERIC"); END IF; END; END; RESULT; END C38002A;
{ "source": "starcoderdata", "programming_language": "ada" }
------------------------------------------------------------------------------ with Ada.Containers.Hash_Tables; with Ada.Streams; with Ada.Finalization; generic type Key_Type (<>) is private; type Element_Type (<>) is private; with function Hash (Key : Key_Type) return Hash_Type; with function Equivalent_Keys (Left, Right : Key_Type) return Boolean; with function "=" (Left, Right : Element_Type) return Boolean is <>; package Ada.Containers.Indefinite_Hashed_Maps is pragma Preelaborate; type Map is tagged private; pragma Preelaborable_Initialization (Map); type Cursor is private; pragma Preelaborable_Initialization (Cursor); Empty_Map : constant Map; No_Element : constant Cursor; function "=" (Left, Right : Map) return Boolean; function Capacity (Container : Map) return Count_Type; procedure Reserve_Capacity (Container : in out Map; Capacity : Count_Type); function Length (Container : Map) return Count_Type; function Is_Empty (Container : Map) return Boolean; procedure Clear (Container : in out Map); function Key (Position : Cursor) return Key_Type; function Element (Position : Cursor) return Element_Type; procedure Replace_Element (Container : in out Map; Position : Cursor; New_Item : Element_Type); procedure Query_Element (Position : Cursor; Process : not null access procedure (Key : Key_Type; Element : Element_Type)); procedure Update_Element (Container : in out Map; Position : Cursor; Process : not null access procedure (Key : Key_Type; Element : in out Element_Type)); procedure Move (Target : in out Map; Source : in out Map); procedure Insert (Container : in out Map; Key : Key_Type; New_Item : Element_Type; Position : out Cursor; Inserted : out Boolean); procedure Insert (Container : in out Map; Key : Key_Type; New_Item : Element_Type); procedure Include (Container : in out Map; Key : Key_Type; New_Item : Element_Type); procedure Replace (Container : in out Map; Key : Key_Type; New_Item : Element_Type); procedure Exclude (Container : in out Map; Key : Key_Type); procedure Delete (Container : in out Map; Key : Key_Type); procedure Delete (Container : in out Map; Position : in out Cursor); function First (Container : Map) return Cursor; function Next (Position : Cursor) return Cursor; procedure Next (Position : in out Cursor); function Find (Container : Map; Key : Key_Type) return Cursor; function Contains (Container : Map; Key : Key_Type) return Boolean; function Element (Container : Map; Key : Key_Type) return Element_Type; function Has_Element (Position : Cursor) return Boolean; function Equivalent_Keys (Left, Right : Cursor) return Boolean; function Equivalent_Keys (Left : Cursor; Right : Key_Type) return Boolean; function Equivalent_Keys (Left : Key_Type; Right : Cursor) return Boolean; procedure Iterate (Container : Map; Process : not null access procedure (Position : Cursor)); private pragma Inline ("="); pragma Inline (Length); pragma Inline (Is_Empty); pragma Inline (Clear); pragma Inline (Key); pragma Inline (Element); pragma Inline (Move); pragma Inline (Contains); pragma Inline (Capacity); pragma Inline (Reserve_Capacity); pragma Inline (Has_Element); pragma Inline (Equivalent_Keys); type Node_Type; type Node_Access is access Node_Type; type Key_Access is access Key_Type; type Element_Access is access Element_Type; type Node_Type is limited record Key : Key_Access; Element : Element_Access; Next : Node_Access; end record; package HT_Types is new Hash_Tables.Generic_Hash_Table_Types (Node_Type, Node_Access); type Map is new Ada.Finalization.Controlled with record HT : HT_Types.Hash_Table_Type; end record; use HT_Types; use Ada.Finalization; use Ada.Streams; procedure Adjust (Container : in out Map); procedure Finalize (Container : in out Map); type Map_Access is access constant Map; for Map_Access'Storage_Size use 0; type Cursor is record Container : Map_Access; Node : Node_Access; end record; procedure Write (Stream : access Root_Stream_Type'Class; Item : Cursor); for Cursor'Write use Write; procedure Read (Stream : access Root_Stream_Type'Class; Item : out Cursor); for Cursor'Read use Read; No_Element : constant Cursor := (Container => null, Node => null); procedure Write (Stream : access Root_Stream_Type'Class; Container : Map); for Map'Write use Write; procedure Read (Stream : access Root_Stream_Type'Class; Container : out Map); for Map'Read use Read; Empty_Map : constant Map := (Controlled with HT => (null, 0, 0, 0)); end Ada.Containers.Indefinite_Hashed_Maps;
{ "source": "starcoderdata", "programming_language": "ada" }
----------------------------------------------------------------------- with Util.Log.Loggers; with ASF.Cookies; with AWA.Users.Services; with AWA.Users.Modules; package body AWA.Users.Filters is -- The logger Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("AWA.Users.Filters"); -- ------------------------------ -- Set the user principal on the session associated with the ASF request. -- ------------------------------ procedure Set_Session_Principal (Request : in out ASF.Requests.Request'Class; Principal : in Principals.Principal_Access) is Session : ASF.Sessions.Session := Request.Get_Session (Create => True); begin Session.Set_Principal (Principal.all'Access); end Set_Session_Principal; -- ------------------------------ -- Initialize the filter and configure the redirection URIs. -- ------------------------------ procedure Initialize (Filter : in out Auth_Filter; Context : in ASF.Servlets.Servlet_Registry'Class) is URI : constant String := Context.Get_Init_Parameter (AUTH_FILTER_REDIRECT_PARAM); begin Log.Info ("Using login URI: {0}", URI); if URI = "" then Log.Error ("The login URI is empty. Redirection to the login page will not work."); end if; Filter.Login_URI := To_Unbounded_String (URI); ASF.Security.Filters.Auth_Filter (Filter).Initialize (Context); end Initialize; procedure Authenticate (F : in Auth_Filter; Request : in out ASF.Requests.Request'Class; Response : in out ASF.Responses.Response'Class; Session : in ASF.Sessions.Session; Auth_Id : in String; Principal : out ASF.Principals.Principal_Access) is pragma Unreferenced (F, Session); use AWA.Users.Modules; use AWA.Users.Services; Manager : constant User_Service_Access := AWA.Users.Modules.Get_User_Manager; P : AWA.Users.Principals.Principal_Access; begin Manager.Authenticate (Cookie => Auth_Id, Ip_Addr => "", Principal => P); Principal := P.all'Access; -- Setup a new AID cookie with the new connection session. declare Cookie : constant String := Manager.Get_Authenticate_Cookie (P.Get_Session_Identifier); C : ASF.Cookies.Cookie := ASF.Cookies.Create (ASF.Security.Filters.AID_COOKIE, Cookie); begin ASF.Cookies.Set_Path (C, Request.Get_Context_Path); ASF.Cookies.Set_Max_Age (C, 15 * 86400); Response.Add_Cookie (Cookie => C); end; exception when Not_Found => Principal := null; end Authenticate; -- ------------------------------ -- Display or redirects the user to the login page. This procedure is called when -- the user is not authenticated. -- ------------------------------ overriding procedure Do_Login (Filter : in Auth_Filter; Request : in out ASF.Requests.Request'Class; Response : in out ASF.Responses.Response'Class) is URI : constant String := To_String (Filter.Login_URI); begin Log.Info ("User is not logged, redirecting to {0}", URI); if Request.Get_Header ("X-Requested-With") = "" then Response.Send_Redirect (Location => URI); else Response.Send_Error (ASF.Responses.SC_UNAUTHORIZED); end if; end Do_Login; -- ------------------------------ -- Initialize the filter and configure the redirection URIs. -- ------------------------------ overriding procedure Initialize (Filter : in out Verify_Filter; Context : in ASF.Servlets.Servlet_Registry'Class) is URI : constant String := Context.Get_Init_Parameter (VERIFY_FILTER_REDIRECT_PARAM); begin Filter.Invalid_Key_URI := To_Unbounded_String (URI); end Initialize; -- ------------------------------ -- Filter a request which contains an access key and verify that the -- key is valid and identifies a user. Once the user is known, create -- a session and setup the user principal. -- -- If the access key is missing or invalid, redirect to the -- <b>Invalid_Key_URI</b> associated with the filter. -- ------------------------------ overriding procedure Do_Filter (Filter : in Verify_Filter; Request : in out ASF.Requests.Request'Class; Response : in out ASF.Responses.Response'Class; Chain : in out ASF.Servlets.Filter_Chain) is Key : constant String := Request.Get_Parameter (PARAM_ACCESS_KEY); Manager : constant Users.Services.User_Service_Access := Users.Modules.Get_User_Manager; Principal : AWA.Users.Principals.Principal_Access; begin Log.Info ("Verify access key {0}", Key); Manager.Verify_User (Key => Key, IpAddr => "", Principal => Principal); Set_Session_Principal (Request, Principal); -- Request is authorized, proceed to the next filter. ASF.Servlets.Do_Filter (Chain => Chain, Request => Request, Response => Response); exception when AWA.Users.Services.Not_Found => declare URI : constant String := To_String (Filter.Invalid_Key_URI); begin Log.Info ("Invalid access key {0}, redirecting to {1}", Key, URI); Response.Send_Redirect (Location => URI); end; end Do_Filter; end AWA.Users.Filters;
{ "source": "starcoderdata", "programming_language": "ada" }
-- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Opt; use Opt; with Tree_IO; use Tree_IO; package body Osint.C is Output_Object_File_Name : String_Ptr; -- Argument of -o compiler option, if given. This is needed to verify -- consistency with the ALI file name. procedure Adjust_OS_Resource_Limits; pragma Import (C, Adjust_OS_Resource_Limits, "__gnat_adjust_os_resource_limits"); -- Procedure to make system specific adjustments to make GNAT run better function Create_Auxiliary_File (Src : File_Name_Type; Suffix : String) return File_Name_Type; -- Common processing for Create_List_File, Create_Repinfo_File and -- Create_Debug_File. Src is the file name used to create the required -- output file and Suffix is the desired suffix (dg/rep/xxx for debug/ -- repinfo/list file where xxx is specified extension. ------------------ -- Close_C_File -- ------------------ procedure Close_C_File is Status : Boolean; begin Close (Output_FD, Status); if not Status then Fail ("error while closing file " & Get_Name_String (Output_File_Name)); end if; end Close_C_File; ---------------------- -- Close_Debug_File -- ---------------------- procedure Close_Debug_File is Status : Boolean; begin Close (Output_FD, Status); if not Status then Fail ("error while closing expanded source file " & Get_Name_String (Output_File_Name)); end if; end Close_Debug_File; ------------------ -- Close_H_File -- ------------------ procedure Close_H_File is Status : Boolean; begin Close (Output_FD, Status); if not Status then Fail ("error while closing file " & Get_Name_String (Output_File_Name)); end if; end Close_H_File; --------------------- -- Close_List_File -- --------------------- procedure Close_List_File is Status : Boolean; begin Close (Output_FD, Status); if not Status then Fail ("error while closing list file " & Get_Name_String (Output_File_Name)); end if; end Close_List_File; ------------------------------- -- Close_Output_Library_Info -- ------------------------------- procedure Close_Output_Library_Info is Status : Boolean; begin Close (Output_FD, Status); if not Status then Fail ("error while closing ALI file " & Get_Name_String (Output_File_Name)); end if; end Close_Output_Library_Info; ------------------------ -- Close_Repinfo_File -- ------------------------ procedure Close_Repinfo_File is Status : Boolean; begin Close (Output_FD, Status); if not Status then Fail ("error while closing representation info file " & Get_Name_String (Output_File_Name)); end if; end Close_Repinfo_File; --------------------------- -- Create_Auxiliary_File -- --------------------------- function Create_Auxiliary_File (Src : File_Name_Type; Suffix : String) return File_Name_Type is Result : File_Name_Type; begin Get_Name_String (Src); Name_Buffer (Name_Len + 1) := '.'; Name_Len := Name_Len + 1; Name_Buffer (Name_Len + 1 .. Name_Len + Suffix'Length) := Suffix; Name_Len := Name_Len + Suffix'Length; if Output_Object_File_Name /= null then for Index in reverse Output_Object_File_Name'Range loop if Output_Object_File_Name (Index) = Directory_Separator then declare File_Name : constant String := Name_Buffer (1 .. Name_Len); begin Name_Len := Index - Output_Object_File_Name'First + 1; Name_Buffer (1 .. Name_Len) := Output_Object_File_Name (Output_Object_File_Name'First .. Index); Name_Buffer (Name_Len + 1 .. Name_Len + File_Name'Length) := File_Name; Name_Len := Name_Len + File_Name'Length; end; exit; end if; end loop; end if; Result := Name_Find; Name_Buffer (Name_Len + 1) := ASCII.NUL; Create_File_And_Check (Output_FD, Text); return Result; end Create_Auxiliary_File; ------------------- -- Create_C_File -- ------------------- procedure Create_C_File is Dummy : Boolean; begin Set_File_Name ("c"); Delete_File (Name_Buffer (1 .. Name_Len), Dummy); Create_File_And_Check (Output_FD, Text); end Create_C_File; ----------------------- -- Create_Debug_File -- ----------------------- function Create_Debug_File (Src : File_Name_Type) return File_Name_Type is begin return Create_Auxiliary_File (Src, "dg"); end Create_Debug_File; ------------------- -- Create_H_File -- ------------------- procedure Create_H_File is Dummy : Boolean; begin Set_File_Name ("h"); Delete_File (Name_Buffer (1 .. Name_Len), Dummy); Create_File_And_Check (Output_FD, Text); end Create_H_File; ---------------------- -- Create_List_File -- ---------------------- procedure Create_List_File (S : String) is Dummy : File_Name_Type; begin if S (S'First) = '.' then Dummy := Create_Auxiliary_File (Current_Main, S (S'First + 1 .. S'Last)); else Name_Buffer (1 .. S'Length) := S; Name_Len := S'Length + 1; Name_Buffer (Name_Len) := ASCII.NUL; Create_File_And_Check (Output_FD, Text); end if; end Create_List_File; -------------------------------- -- Create_Output_Library_Info -- -------------------------------- procedure Create_Output_Library_Info is Dummy : Boolean; begin Set_File_Name (ALI_Suffix.all); Delete_File (Name_Buffer (1 .. Name_Len), Dummy); Create_File_And_Check (Output_FD, Text); end Create_Output_Library_Info; ------------------------------ -- Open_Output_Library_Info -- ------------------------------ procedure Open_Output_Library_Info is begin Set_File_Name (ALI_Suffix.all); Open_File_To_Append_And_Check (Output_FD, Text); end Open_Output_Library_Info; ------------------------- -- Create_Repinfo_File -- ------------------------- procedure Create_Repinfo_File (Src : String) is Discard : File_Name_Type; begin Name_Buffer (1 .. Src'Length) := Src; Name_Len := Src'Length; Discard := Create_Auxiliary_File (Name_Find, "rep"); return; end Create_Repinfo_File; --------------------------- -- Debug_File_Eol_Length -- --------------------------- function Debug_File_Eol_Length return Nat is begin -- There has to be a cleaner way to do this ??? if Directory_Separator = '/' then return 1; else return 2; end if; end Debug_File_Eol_Length; ------------------- -- Delete_C_File -- ------------------- procedure Delete_C_File is Dummy : Boolean; begin Set_File_Name ("c"); Delete_File (Name_Buffer (1 .. Name_Len), Dummy); end Delete_C_File; ------------------- -- Delete_H_File -- ------------------- procedure Delete_H_File is Dummy : Boolean; begin Set_File_Name ("h"); Delete_File (Name_Buffer (1 .. Name_Len), Dummy); end Delete_H_File; --------------------------------- -- Get_Output_Object_File_Name -- --------------------------------- function Get_Output_Object_File_Name return String is begin pragma Assert (Output_Object_File_Name /= null); return Output_Object_File_Name.all; end Get_Output_Object_File_Name; ----------------------- -- More_Source_Files -- ----------------------- function More_Source_Files return Boolean renames More_Files; ---------------------- -- Next_Main_Source -- ---------------------- function Next_Main_Source return File_Name_Type renames Next_Main_File; ----------------------- -- Read_Library_Info -- ----------------------- procedure Read_Library_Info (Name : out File_Name_Type; Text : out Text_Buffer_Ptr) is begin Set_File_Name (ALI_Suffix.all); -- Remove trailing NUL that comes from Set_File_Name above. This is -- needed for consistency with names that come from Scan_ALI and thus -- preventing repeated scanning of the same file. pragma Assert (Name_Len > 1 and then Name_Buffer (Name_Len) = ASCII.NUL); Name_Len := Name_Len - 1; Name := Name_Find; Text := Read_Library_Info (Name, Fatal_Err => False); end Read_Library_Info; ------------------- -- Set_File_Name -- ------------------- procedure Set_File_Name (Ext : String) is Dot_Index : Natural; begin Get_Name_String (Current_Main); -- Find last dot since we replace the existing extension by .ali. The -- initialization to Name_Len + 1 provides for simply adding the .ali -- extension if the source file name has no extension. Dot_Index := Name_Len + 1; for J in reverse 1 .. Name_Len loop if Name_Buffer (J) = '.' then Dot_Index := J; exit; end if; end loop; -- Make sure that the output file name matches the source file name. -- To compare them, remove file name directories and extensions. if Output_Object_File_Name /= null then -- Make sure there is a dot at Dot_Index. This may not be the case -- if the source file name has no extension. Name_Buffer (Dot_Index) := '.'; -- If we are in multiple unit per file mode, then add ~nnn -- extension to the name before doing the comparison. if Multiple_Unit_Index /= 0 then declare Exten : constant String := Name_Buffer (Dot_Index .. Name_Len); begin Name_Len := Dot_Index - 1; Add_Char_To_Name_Buffer (Multi_Unit_Index_Character); Add_Nat_To_Name_Buffer (Multiple_Unit_Index); Dot_Index := Name_Len + 1; Add_Str_To_Name_Buffer (Exten); end; end if; -- Remove extension preparing to replace it declare Name : String := Name_Buffer (1 .. Dot_Index); First : Positive; begin Name_Buffer (1 .. Output_Object_File_Name'Length) := Output_Object_File_Name.all; -- Put two names in canonical case, to allow object file names -- with upper-case letters on Windows. Canonical_Case_File_Name (Name); Canonical_Case_File_Name (Name_Buffer (1 .. Output_Object_File_Name'Length)); Dot_Index := 0; for J in reverse Output_Object_File_Name'Range loop if Name_Buffer (J) = '.' then Dot_Index := J; exit; end if; end loop; -- Dot_Index should not be zero now (we check for extension -- elsewhere). pragma Assert (Dot_Index /= 0); -- Look for first character of file name First := Dot_Index; while First > 1 and then Name_Buffer (First - 1) /= Directory_Separator and then Name_Buffer (First - 1) /= '/' loop First := First - 1; end loop; -- Check name of object file is what we expect if Name /= Name_Buffer (First .. Dot_Index) then Fail ("incorrect object file name"); end if; end; end if; Name_Buffer (Dot_Index) := '.'; Name_Buffer (Dot_Index + 1 .. Dot_Index + Ext'Length) := Ext; Name_Buffer (Dot_Index + Ext'Length + 1) := ASCII.NUL; Name_Len := Dot_Index + Ext'Length + 1; end Set_File_Name; --------------------------------- -- Set_Output_Object_File_Name -- --------------------------------- procedure Set_Output_Object_File_Name (Name : String) is Ext : constant String := Target_Object_Suffix; NL : constant Natural := Name'Length; EL : constant Natural := Ext'Length; begin -- Make sure that the object file has the expected extension if NL <= EL or else (Name (NL - EL + Name'First .. Name'Last) /= Ext and then Name (NL - 2 + Name'First .. Name'Last) /= ".o" and then (not Generate_C_Code or else Name (NL - 2 + Name'First .. Name'Last) /= ".c")) then Fail ("incorrect object file extension"); end if; Output_Object_File_Name := new String'(Name); end Set_Output_Object_File_Name; ---------------- -- Tree_Close -- ---------------- procedure Tree_Close is Status : Boolean; begin Tree_Write_Terminate; Close (Output_FD, Status); if not Status then Fail ("error while closing tree file " & Get_Name_String (Output_File_Name)); end if; end Tree_Close; ----------------- -- Tree_Create -- ----------------- procedure Tree_Create is Dot_Index : Natural; begin Get_Name_String (Current_Main); -- If an object file has been specified, then the ALI file -- will be in the same directory as the object file; -- so, we put the tree file in this same directory, -- even though no object file needs to be generated. if Output_Object_File_Name /= null then Name_Len := Output_Object_File_Name'Length; Name_Buffer (1 .. Name_Len) := Output_Object_File_Name.all; end if; Dot_Index := Name_Len + 1; for J in reverse 1 .. Name_Len loop if Name_Buffer (J) = '.' then Dot_Index := J; exit; end if; end loop; -- Should be impossible to not have an extension pragma Assert (Dot_Index /= 0); -- Change extension to adt Name_Buffer (Dot_Index) := '.'; Name_Buffer (Dot_Index + 1) := 'a'; Name_Buffer (Dot_Index + 2) := 'd'; Name_Buffer (Dot_Index + 3) := 't'; Name_Buffer (Dot_Index + 4) := ASCII.NUL; Name_Len := Dot_Index + 3; Create_File_And_Check (Output_FD, Binary); Tree_Write_Initialize (Output_FD); end Tree_Create; ----------------------- -- Write_Debug_Info -- ----------------------- procedure Write_Debug_Info (Info : String) renames Write_Info; ------------------------ -- Write_Library_Info -- ------------------------ procedure Write_Library_Info (Info : String) renames Write_Info; --------------------- -- Write_List_Info -- --------------------- procedure Write_List_Info (S : String) is begin Write_With_Check (S'Address, S'Length); end Write_List_Info; ------------------------ -- Write_Repinfo_Line -- ------------------------ procedure Write_Repinfo_Line (Info : String) renames Write_Info; begin Adjust_OS_Resource_Limits; Opt.Create_Repinfo_File_Access := Create_Repinfo_File'Access; Opt.Write_Repinfo_Line_Access := Write_Repinfo_Line'Access; Opt.Close_Repinfo_File_Access := Close_Repinfo_File'Access; Opt.Create_List_File_Access := Create_List_File'Access; Opt.Write_List_Info_Access := Write_List_Info'Access; Opt.Close_List_File_Access := Close_List_File'Access; Set_Program (Compiler); end Osint.C;
{ "source": "starcoderdata", "programming_language": "ada" }
----------------------------------------------------------------------- with Ada.Strings.Unbounded; with ADO.Objects; with ADO.Schemas; with ADO.Queries; with Util.Beans.Objects; with Util.Beans.Basic; with AWA.Counters.Modules; with AWA.Counters.Models; -- == Counter Bean == -- The <b>Counter_Bean</b> allows to represent a counter associated with some database -- entity and allows its control by the <awa:counter> component. -- package AWA.Counters.Beans is type Counter_Bean (Of_Type : ADO.Objects.Object_Key_Type; Of_Class : ADO.Schemas.Class_Mapping_Access) is new Util.Beans.Basic.Readonly_Bean with record Counter : Counter_Index_Type; Value : Integer := -1; Object : ADO.Objects.Object_Key (Of_Type, Of_Class); end record; type Counter_Bean_Access is access all Counter_Bean'Class; -- Get the value identified by the name. overriding function Get_Value (From : in Counter_Bean; Name : in String) return Util.Beans.Objects.Object; type Counter_Stat_Bean is new AWA.Counters.Models.Stat_List_Bean with record Module : AWA.Counters.Modules.Counter_Module_Access; Stats : aliased AWA.Counters.Models.Stat_Info_List_Bean; Stats_Bean : AWA.Counters.Models.Stat_Info_List_Bean_Access; end record; type Counter_Stat_Bean_Access is access all Counter_Stat_Bean'Class; -- Get the query definition to collect the counter statistics. function Get_Query (From : in Counter_Stat_Bean) return ADO.Queries.Query_Definition_Access; overriding function Get_Value (List : in Counter_Stat_Bean; Name : in String) return Util.Beans.Objects.Object; -- Set the value identified by the name. overriding procedure Set_Value (From : in out Counter_Stat_Bean; Name : in String; Value : in Util.Beans.Objects.Object); -- Load the statistics information. overriding procedure Load (List : in out Counter_Stat_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String); -- Create the Blog_Stat_Bean bean instance. function Create_Counter_Stat_Bean (Module : in AWA.Counters.Modules.Counter_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access; end AWA.Counters.Beans;
{ "source": "starcoderdata", "programming_language": "ada" }
With Ada.Streams, Ada.Strings.Less_Case_Insensitive, Ada.Strings.Equal_Case_Insensitive, Ada.Containers.Indefinite_Ordered_Maps; Package INI with Preelaborate, Elaborate_Body is Type Value_Type is ( vt_String, vt_Float, vt_Integer, vt_Boolean ); Type Instance(Convert : Boolean) is private; Function Exists( Object : in Instance; Key : in String; Section: in String:= "" ) return Boolean; -- Return the type of the associated value. Function Value( Object : in Instance; Key : in String; Section: in String:= "" ) return Value_Type with Pre => Exists(Object, Key, Section); -- Return the value associated with the key in the indicated section. Function Value( Object : in Instance; Key : in String; Section: in String:= "" ) return String with Pre => Exists(Object, Key, Section); Function Value( Object : in Instance; Key : in String; Section: in String:= "" ) return Float with Pre => Exists(Object, Key, Section); Function Value( Object : in Instance; Key : in String; Section: in String:= "" ) return Integer with Pre => Exists(Object, Key, Section); Function Value( Object : in Instance; Key : in String; Section: in String:= "" ) return Boolean with Pre => Exists(Object, Key, Section); -- Associates a value with the given key in the indicated section. Procedure Value( Object : in out Instance; Key : in String; Value : in String; Section: in String:= "" ) with Post => Exists(Object, Key, Section); Procedure Value( Object : in out Instance; Key : in String; Value : in Float; Section: in String:= "" ) with Post => Exists(Object, Key, Section); Procedure Value( Object : in out Instance; Key : in String; Value : in Integer; Section: in String:= "" ) with Post => Exists(Object, Key, Section); Procedure Value( Object : in out Instance; Key : in String; Value : in Boolean; Section: in String:= "" ) with Post => Exists(Object, Key, Section); -- This value sets the Convert discriminant for the object that is generated -- by the 'Input attribute. Default_Conversion : Boolean := False; Empty : Constant Instance; Private Type Value_Object( Kind : Value_Type; Length : Natural ) ; Function "ABS"( Object : Value_Object ) return String; Function "="(Left, Right : Value_Object) return Boolean; Package Object_Package is procedure Value_Output( Stream : not null access Ada.Streams.Root_Stream_Type'Class; Item : in Value_Object ) is null; function Value_Input( Stream : not null access Ada.Streams.Root_Stream_Type'Class ) return Value_Object; End Object_Package; Type Value_Object( Kind : Value_Type; Length : Natural ) is record case Kind is when vt_String => String_Value : String(1..Length):= (Others=>' '); when vt_Float => Float_Value : Float := 0.0; when vt_Integer => Integer_Value: Integer := 0; when vt_Boolean => Boolean_Value: Boolean := False; end case; end record; -- with Input => Object_Package.Value_Input, -- Output => Object_Package.Value_Output; Package KEY_VALUE_MAP is new Ada.Containers.Indefinite_Ordered_Maps( -- "=" => , "<" => Ada.Strings.Less_Case_Insensitive, Key_Type => String, Element_Type => Value_Object ); Function "="(Left, Right : KEY_VALUE_MAP.Map) return Boolean; Package KEY_SECTION_MAP is new Ada.Containers.Indefinite_Ordered_Maps( "=" => "=", "<" => Ada.Strings.Less_Case_Insensitive, Key_Type => String, Element_Type => KEY_VALUE_MAP.Map ); procedure INI_Output( Stream : not null access Ada.Streams.Root_Stream_Type'Class; Item : in Instance ); function INI_Input( Stream : not null access Ada.Streams.Root_Stream_Type'Class ) return Instance; Type Instance(Convert : Boolean) is new KEY_SECTION_MAP.Map with null record with Input => INI_Input, Output => INI_Output; overriding function Copy (Source : Instance) return Instance is ( Source ); Empty : Constant Instance:= (KEY_SECTION_MAP.map with Convert => True, others => <>); End INI;
{ "source": "starcoderdata", "programming_language": "ada" }
----------------------------------------------------------------------- with Util.Properties; with Util.Log.Loggers; with Bbox.API; with Druss.Gateways; with Ada.Strings.Unbounded; package body Druss.Commands.Ping is use Ada.Strings.Unbounded; -- The logger Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Druss.Commands.Ping"); -- ------------------------------ -- Execute the wifi 'status' command to print the Wifi current status. -- ------------------------------ procedure Do_Ping (Command : in Command_Type; Args : in Argument_List'Class; Selector : in Device_Selector_Type; Context : in out Context_Type) is pragma Unreferenced (Command, Args); procedure Do_Ping (Gateway : in out Druss.Gateways.Gateway_Type); procedure Box_Status (Gateway : in out Druss.Gateways.Gateway_Type); Console : constant Druss.Commands.Consoles.Console_Access := Context.Console; procedure Do_Ping (Gateway : in out Druss.Gateways.Gateway_Type) is procedure Ping_Device (Manager : in Util.Properties.Manager; Name : in String); Box : Bbox.API.Client_Type; procedure Ping_Device (Manager : in Util.Properties.Manager; Name : in String) is Id : constant String := Manager.Get (Name & ".id", ""); begin case Selector is when DEVICE_ALL => null; when DEVICE_ACTIVE => if Manager.Get (Name & ".active", "") = "0" then return; end if; when DEVICE_INACTIVE => if Manager.Get (Name & ".active", "") = "1" then return; end if; end case; Log.Info ("Ping command on {0}", Manager.Get (Name & ".ipaddress", "")); Box.Post ("hosts/" & Id, "action=ping"); end Ping_Device; begin if Ada.Strings.Unbounded.Length (Gateway.Passwd) = 0 then return; end if; Gateway.Refresh; Box.Set_Server (To_String (Gateway.Ip)); Box.Login (To_String (Gateway.Passwd)); Bbox.API.Iterate (Gateway.Hosts, "hosts.list", Ping_Device'Access); end Do_Ping; procedure Box_Status (Gateway : in out Druss.Gateways.Gateway_Type) is procedure Print_Device (Manager : in Util.Properties.Manager; Name : in String); procedure Print_Device (Manager : in Util.Properties.Manager; Name : in String) is Link : constant String := Manager.Get (Name & ".link", ""); begin if Manager.Get (Name & ".active", "") = "0" then return; end if; Console.Start_Row; Console.Print_Field (F_BBOX_IP_ADDR, Gateway.Ip); Console.Print_Field (F_IP_ADDR, Manager.Get (Name & ".ipaddress", "")); Console.Print_Field (F_HOSTNAME, Manager.Get (Name & ".hostname", "")); Print_Perf (Console, F_ACTIVE, Manager.Get (Name & ".ping.average", "")); if Link = "Ethernet" then Console.Print_Field (F_LINK, Link & " port " & Manager.Get (Name & ".ethernet.logicalport", "")); else Console.Print_Field (F_LINK, Link & " RSSI " & Manager.Get (Name & ".wireless.rssi0", "")); end if; Console.End_Row; end Print_Device; begin Gateway.Refresh; Bbox.API.Iterate (Gateway.Hosts, "hosts.list", Print_Device'Access); end Box_Status; begin Druss.Gateways.Iterate (Context.Gateways, Gateways.ITER_ENABLE, Do_Ping'Access); delay 5.0; Console.Start_Title; Console.Print_Title (F_BBOX_IP_ADDR, "Bbox IP", 16); Console.Print_Title (F_IP_ADDR, "Device IP", 16); Console.Print_Title (F_HOSTNAME, "Hostname", 28); Console.Print_Title (F_ACTIVE, "Ping", 15); Console.Print_Title (F_LINK, "Link", 18); Console.End_Title; Druss.Gateways.Iterate (Context.Gateways, Gateways.ITER_ENABLE, Box_Status'Access); end Do_Ping; -- ------------------------------ -- Execute a ping from the gateway to each device. -- ------------------------------ overriding procedure Execute (Command : in out Command_Type; Name : in String; Args : in Argument_List'Class; Context : in out Context_Type) is pragma Unreferenced (Name); begin if Args.Get_Count > 1 then Context.Console.Notice (N_USAGE, "Too many arguments to the command"); Druss.Commands.Driver.Usage (Args, Context); elsif Args.Get_Count = 0 then Command.Do_Ping (Args, DEVICE_ALL, Context); elsif Args.Get_Argument (1) = "all" then Command.Do_Ping (Args, DEVICE_ALL, Context); elsif Args.Get_Argument (1) = "active" then Command.Do_Ping (Args, DEVICE_ACTIVE, Context); elsif Args.Get_Argument (1) = "inactive" then Command.Do_Ping (Args, DEVICE_INACTIVE, Context); else Context.Console.Notice (N_USAGE, "Invalid argument: " & Args.Get_Argument (1)); Druss.Commands.Driver.Usage (Args, Context); end if; end Execute; -- ------------------------------ -- Write the help associated with the command. -- ------------------------------ overriding procedure Help (Command : in out Command_Type; Name : in String; Context : in out Context_Type) is pragma Unreferenced (Command); Console : constant Druss.Commands.Consoles.Console_Access := Context.Console; begin Console.Notice (N_HELP, "ping: Ask the Bbox to ping the devices"); Console.Notice (N_HELP, "Usage: ping [all | active | inactive]"); Console.Notice (N_HELP, ""); Console.Notice (N_HELP, " Ask the Bbox to ping the devices. By default it will ping"); Console.Notice (N_HELP, " all the devices that have been discovered by the Bbox."); Console.Notice (N_HELP, " The command will wait 5 seconds and it will list the active"); Console.Notice (N_HELP, " devices with their ping performance."); Console.Notice (N_HELP, ""); Console.Notice (N_HELP, " all Ping all the devices"); Console.Notice (N_HELP, " active Ping the active devices only"); Console.Notice (N_HELP, " inative Ping the inactive devices only"); end Help; end Druss.Commands.Ping;
{ "source": "starcoderdata", "programming_language": "ada" }
-- -- ------------------------------------------------------------------------------ with System.Machine_Code; use System.Machine_Code; with Cortex_M_SVD.SCB; use Cortex_M_SVD.SCB; with AGATE.Traces; with AGATE.Arch.ArmvX_m; use AGATE.Arch.ArmvX_m; package body AGATE.Scheduler.Context_Switch is procedure Context_Switch_Handler; pragma Machine_Attribute (Context_Switch_Handler, "naked"); pragma Export (C, Context_Switch_Handler, "PendSV_Handler"); ------------ -- Switch -- ------------ procedure Switch is begin -- Trigger PendSV SCB_Periph.ICSR.PENDSVSET := True; end Switch; ---------------------------- -- Context_Switch_Handler -- ---------------------------- procedure Context_Switch_Handler is begin Asm (Template => "push {lr}" & ASCII.LF & "bl current_task_context" & ASCII.LF & "stm r0, {r4-r12}", -- Save extra context Volatile => True); SCB_Periph.ICSR.PENDSVCLR := True; Running_Task.Stack_Pointer := PSP; Set_PSP (Ready_Tasks.Stack_Pointer); Traces.Context_Switch (Task_ID (Running_Task), Task_ID (Ready_Tasks)); Running_Task := Ready_Tasks; Running_Task.Status := Running; Traces.Running (Current_Task); Asm (Template => "bl current_task_context" & ASCII.LF & "ldm r0, {r4-r12}" & ASCII.LF & -- Load extra context "pop {pc}", Volatile => True); end Context_Switch_Handler; end AGATE.Scheduler.Context_Switch;
{ "source": "starcoderdata", "programming_language": "ada" }
with Common_Formal_Containers; use Common_Formal_Containers; package afrl.impact.ImpactAutomationRequest.SPARK_Boundary with SPARK_Mode is pragma Annotate (GNATprove, Terminating, SPARK_Boundary); function Get_EntityList_From_TrialRequest (Request : ImpactAutomationRequest) return Int64_Vect with Global => null; function Get_OperatingRegion_From_TrialRequest (Request : ImpactAutomationRequest) return Int64 with Global => null; function Get_TaskList_From_TrialRequest (Request : ImpactAutomationRequest) return Int64_Vect with Global => null; end afrl.impact.ImpactAutomationRequest.SPARK_Boundary;
{ "source": "starcoderdata", "programming_language": "ada" }
-- -- -- GNARL was developed by the GNARL team at Florida State University. It is -- -- now maintained by Ada Core Technologies Inc. in cooperation with Florida -- -- State University (http://www.gnat.com). -- -- -- ------------------------------------------------------------------------------ with Interfaces.C; -- Used for Size_t; with Interfaces.C.Pthreads; -- Used for, size_t, -- pthread_mutex_t, -- pthread_cond_t, -- pthread_t with Interfaces.C.POSIX_RTE; -- Used for, Signal, -- siginfo_ptr, with System.Task_Clock; -- Used for, Stimespec with Unchecked_Conversion; pragma Elaborate_All (Interfaces.C.Pthreads); with System.Task_Info; package System.Task_Primitives is -- Low level Task size and state definition type LL_Task_Procedure_Access is access procedure (Arg : System.Address); type Pre_Call_State is new System.Address; type Task_Storage_Size is new Interfaces.C.size_t; type Machine_Exceptions is new Interfaces.C.POSIX_RTE.Signal; type Error_Information is new Interfaces.C.POSIX_RTE.siginfo_ptr; type Lock is private; type Condition_Variable is private; -- The above types should both be limited. They are not due to a hack in -- ATCB allocation which allocates a block of the correct size and then -- assigns an initialized ATCB to it. This won't work with limited types. -- When allocation is done with new, these can become limited once again. -- ??? type Task_Control_Block is record LL_Entry_Point : LL_Task_Procedure_Access; LL_Arg : System.Address; Thread : aliased Interfaces.C.Pthreads.pthread_t; Stack_Size : Task_Storage_Size; Stack_Limit : System.Address; end record; type TCB_Ptr is access all Task_Control_Block; -- Task ATCB related and variables. function Address_To_TCB_Ptr is new Unchecked_Conversion (System.Address, TCB_Ptr); procedure Initialize_LL_Tasks (T : TCB_Ptr); -- Initialize GNULLI. T points to the Task Control Block that should -- be initialized for use by the environment task. function Self return TCB_Ptr; -- Return a pointer to the Task Control Block of the calling task. procedure Initialize_Lock (Prio : System.Any_Priority; L : in out Lock); -- Initialize a lock object. Prio is the ceiling priority associated -- with the lock. procedure Finalize_Lock (L : in out Lock); -- Finalize a lock object, freeing any resources allocated by the -- corresponding Initialize_Lock. procedure Write_Lock (L : in out Lock; Ceiling_Violation : out Boolean); pragma Inline (Write_Lock); -- Lock a lock object for write access to a critical section. After -- this operation returns, the calling task owns the lock, and -- no other Write_Lock or Read_Lock operation on the same object will -- return the owner executes an Unlock operation on the same object. procedure Read_Lock (L : in out Lock; Ceiling_Violation : out Boolean); pragma Inline (Read_Lock); -- Lock a lock object for read access to a critical section. After -- this operation returns, the calling task owns the lock, and -- no other Write_Lock operation on the same object will return until -- the owner(s) execute Unlock operation(s) on the same object. -- A Read_Lock to an owned lock object may return while the lock is -- still owned, though an implementation may also implement -- Read_Lock to have the same semantics. procedure Unlock (L : in out Lock); pragma Inline (Unlock); -- Unlock a locked lock object. The results are undefined if the -- calling task does not own the lock. Lock/Unlock operations must -- be nested, that is, the argument to Unlock must be the object -- most recently locked. procedure Initialize_Cond (Cond : in out Condition_Variable); -- Initialize a condition variable object. procedure Finalize_Cond (Cond : in out Condition_Variable); -- Finalize a condition variable object, recovering any resources -- allocated for it by Initialize_Cond. procedure Cond_Wait (Cond : in out Condition_Variable; L : in out Lock); pragma Inline (Cond_Wait); -- Wait on a condition variable. The mutex object L is unlocked -- atomically, such that another task that is able to lock the mutex -- can be assured that the wait has actually commenced, and that -- a Cond_Signal operation will cause the waiting task to become -- eligible for execution once again. Before Cond_Wait returns, -- the waiting task will again lock the mutex. The waiting task may become -- eligible for execution at any time, but will become eligible for -- execution when a Cond_Signal operation is performed on the -- same condition variable object. The effect of more than one -- task waiting on the same condition variable is unspecified. procedure Cond_Timed_Wait (Cond : in out Condition_Variable; L : in out Lock; Abs_Time : System.Task_Clock.Stimespec; Timed_Out : out Boolean); pragma Inline (Cond_Timed_Wait); -- Wait on a condition variable, as for Cond_Wait, above. In addition, -- the waiting task will become eligible for execution again -- when the absolute time specified by Timed_Out arrives. procedure Cond_Signal (Cond : in out Condition_Variable); pragma Inline (Cond_Signal); -- Wake up a task waiting on the condition variable object specified -- by Cond, making it eligible for execution once again. procedure Set_Priority (T : TCB_Ptr; Prio : System.Any_Priority); pragma Inline (Set_Priority); -- Set the priority of the task specified by T to P. procedure Set_Own_Priority (Prio : System.Any_Priority); pragma Inline (Set_Own_Priority); -- Set the priority of the calling task to P. function Get_Priority (T : TCB_Ptr) return System.Any_Priority; pragma Inline (Get_Priority); -- Return the priority of the task specified by T. function Get_Own_Priority return System.Any_Priority; pragma Inline (Get_Own_Priority); -- Return the priority of the calling task. procedure Create_LL_Task (Priority : System.Any_Priority; Stack_Size : Task_Storage_Size; Task_Info : System.Task_Info.Task_Info_Type; LL_Entry_Point : LL_Task_Procedure_Access; Arg : System.Address; T : TCB_Ptr); -- Create a new low-level task with priority Priority. A new thread -- of control is created with a stack size of at least Stack_Size, -- and the procedure LL_Entry_Point is called with the argument Arg -- from this new thread of control. The Task Control Block pointed -- to by T is initialized to refer to this new task. procedure Exit_LL_Task; -- Exit a low-level task. The resources allocated for the task -- by Create_LL_Task are recovered. The task no longer executes, and -- the effects of further operations on task are unspecified. procedure Abort_Task (T : TCB_Ptr); -- Abort the task specified by T (the target task). This causes -- the target task to asynchronously execute the handler procedure -- installed by the target task using Install_Abort_Handler. The -- effect of this operation is unspecified if there is no abort -- handler procedure for the target task. procedure Test_Abort; -- ??? Obsolete? This is intended to allow implementation of -- abortion and ATC in the absence of an asynchronous Abort_Task, -- but I think that we decided that GNARL can handle this on -- its own by making sure that there is an Undefer_Abortion at -- every abortion synchronization point. type Abort_Handler_Pointer is access procedure (Context : Pre_Call_State); procedure Install_Abort_Handler (Handler : Abort_Handler_Pointer); -- Install an abort handler procedure. This procedure is called -- asynchronously by the calling task whenever a call to Abort_Task -- specifies the calling task as the target. If the abort handler -- procedure is asynchronously executed during a GNULLI operation -- and then calls some other GNULLI operation, the effect is unspecified. procedure Install_Error_Handler (Handler : System.Address); -- Install an error handler for the calling task. The handler will -- be called synchronously if an error is encountered during the -- execution of the calling task. procedure LL_Assert (B : Boolean; M : String); -- If B is False, print the string M to the console and halt the -- program. Task_Wrapper_Frame : constant Integer := 72; -- This is the size of the frame for the Pthread_Wrapper procedure. type Proc is access procedure (Addr : System.Address); -- Test and Set support type TAS_Cell is private; -- On some systems we can not assume that an arbitrary memory location -- can be used in an atomic test and set instruction (e.g. on some -- multiprocessor machines, only memory regions are cache interlocked). -- TAS_Cell is private to facilitate adaption to a variety of -- implementations. procedure Initialize_TAS_Cell (Cell : out TAS_Cell); pragma Inline (Initialize_TAS_Cell); -- Initialize a Test And Set Cell. On some targets this will allocate -- a system-level lock object from a special pool. For most systems, -- this is a nop. procedure Finalize_TAS_Cell (Cell : in out TAS_Cell); pragma Inline (Finalize_TAS_Cell); -- Finalize a Test and Set cell, freeing any resources allocated by the -- corresponding Initialize_TAS_Cell. procedure Clear (Cell : in out TAS_Cell); pragma Inline (Clear); -- Set the state of the named TAS_Cell such that a subsequent call to -- Is_Set will return False. This operation must be atomic with -- respect to the Is_Set and Test_And_Set operations for the same -- cell. procedure Test_And_Set (Cell : in out TAS_Cell; Result : out Boolean); pragma Inline (Test_And_Set); -- Modify the state of the named TAS_Cell such that a subsequent call -- to Is_Set will return True. Result is set to True if Is_Set -- was False prior to the call, False otherwise. This operation must -- be atomic with respect to the Clear and Is_Set operations for the -- same cell. function Is_Set (Cell : in TAS_Cell) return Boolean; pragma Inline (Is_Set); -- Returns the current value of the named TAS_Cell. This operation -- must be atomic with respect to the Clear and Test_And_Set operations -- for the same cell. private type Lock is record mutex : aliased Interfaces.C.Pthreads.pthread_mutex_t; end record; type Condition_Variable is record CV : aliased Interfaces.C.Pthreads.pthread_cond_t; end record; type TAS_Cell is record Value : aliased Interfaces.C.unsigned := 0; end record; end System.Task_Primitives;
{ "source": "starcoderdata", "programming_language": "ada" }
-- SOFTWARE. -------------------------------------------------------------------------------- with Vulkan.Math.GenFType; with Vulkan.Math.GenDType; with Vulkan.Math.Vec3; with Vulkan.Math.Dvec3; use Vulkan.Math.GenFType; use Vulkan.Math.GenDType; use Vulkan.Math.Vec3; use Vulkan.Math.Dvec3; -------------------------------------------------------------------------------- --< @group Vulkan Math Functions -------------------------------------------------------------------------------- --< @summary --< This package provides GLSL Geometry Built-in functions. --< --< @description --< All geometry functions operate on vectors as objects. -------------------------------------------------------------------------------- package Vulkan.Math.Geometry is pragma Preelaborate; pragma Pure; ---------------------------------------------------------------------------- --< @summary --< Calculate the magnitude of the vector. --< --< @description --< Calculate the magnitude of the GenFType vector, using the formula: --< --< Magnitude = sqrt(sum(x0^2, ..., xn^2)) --< --< @param x --< The vector to determine the magnitude for. --< --< @return --< The magnitude of the vector. ---------------------------------------------------------------------------- function Mag (x : in Vkm_GenFType) return Vkm_Float; ---------------------------------------------------------------------------- --< @summary --< Calculate the magnitude of the vector. --< --< @description --< Calculate the magnitude of the Vkm_GenDType vector, using the formula: --< --< Magnitude = sqrt(sum(x0^2, ..., xn^2)) --< --< @param x --< The vector to determine the magnitude for. --< --< @return --< The magnitude of the vector. ---------------------------------------------------------------------------- function Mag (x : in Vkm_GenDType) return Vkm_Double; ---------------------------------------------------------------------------- --< @summary --< Calculate the distance between two points, p0 and p1. --< --< @description --< Calculate the distance between two GenFType vectors representing points p0 --< and p1, using the formula: --< --< Distance = Magnitude(p0 - p1) --< --< @param p0 --< A vector which represents the first point. --< --< @param p1 --< A vector which represents the seconds point. --< --< @return --< The distance between the two points. ---------------------------------------------------------------------------- function Distance (p0, p1 : in Vkm_GenFType) return Vkm_Float is (Mag(p0 - p1)) with Inline; ---------------------------------------------------------------------------- --< @summary --< Calculate the distance between two points, p0 and p1. --< --< @description --< Calculate the distance between two GenDType vectors representing points p0 --< and p1, using the formula: --< --< Distance = Magnitude(p0 - p1) --< --< @param p0 --< A vector which represents the first point. --< --< @param p1 --< A vector which represents the seconds point. --< --< @return --< The distance between the two points. ---------------------------------------------------------------------------- function Distance (p0, p1 : in Vkm_GenDType) return Vkm_Double is (Mag(p0 - p1)) with Inline; ---------------------------------------------------------------------------- --< @summary --< Calculate the dot product between two vectors. --< --< @description --< Calculate the dot product between two GenFType vectors. --< --< x dot y = --< \ [x1 ... xN] . | y1 | = x1*y1 + ... xN * yN --< \ | ... | --< \ | yN | --< --< @param x --< The left vector in the dot product operation. --< --< @param y --< The right vector in the dot product operation. --< --< --< @return The dot product of the two vectors. ---------------------------------------------------------------------------- function Dot (x, y : in Vkm_GenFType) return Vkm_Float; ---------------------------------------------------------------------------- --< @summary --< Calculate the dot product between two vectors. --< --< @description --< Calculate the dot product between the two GenDType vectors. --< --< x dot y = --< \ [x1 ... xN] . | y1 | = x1*y1 + ... xN * yN --< \ | ... | --< \ | yN | --< --< @param x --< The left vector in the dot product operation. --< --< @param y --< The right vector in the dot product operation. --< --< @return --< The dot product of the two vectors. ---------------------------------------------------------------------------- function Dot (x, y : in Vkm_GenDType) return Vkm_Double; ---------------------------------------------------------------------------- --< @summary --< Calculate the cross product between two 3 dimmensional vectors. --< --< @description --< Calculate the cross product between two 3 dimmensional GenFType vectors. --< --< x cross y = --< \ | i j k | = i | x1 x2 | -j | x0 x2 | +k | x0 x1 | = | +(x1*y2 - x2*y1) | --< \ | x0 x1 x2 | | y1 y2 | | y0 y2 | | y0 y1 | | -(x0*y2 - x2*y1) | --< \ | y0 y1 y2 | | +(x0*y1 - x1*y0) | --< --< @param x --< The left vector in the cross product operation. --< --< @param y --< The right vector in the cross product operation. --< --< @return --< The cross product of the two vectors. ---------------------------------------------------------------------------- function Cross (x, y : in Vkm_Vec3 ) return Vkm_Vec3; ---------------------------------------------------------------------------- --< @summary --< Calculate the cross product between two 3 dimmensional vectors. --< --< @description --< Calculate the cross product between two 3 dimmensional GenDType vectors. --< --< x cross y = --< \ | i j k | = i | x1 x2 | -j | x0 x2 | +k | x0 x1 | = | +(x1*y2 - x2*y1) | --< \ | x0 x1 x2 | | y1 y2 | | y0 y2 | | y0 y1 | | -(x0*y2 - x2*y1) | --< \ | y0 y1 y2 | | +(x0*y1 - x1*y0) | --< --< @param x --< The left vector in the cross product operation. --< --< @param y --< The right vector in the cross product operation. --< --< @return --< The cross product of the two vectors. ---------------------------------------------------------------------------- function Cross (x, y : in Vkm_Dvec3) return Vkm_Dvec3; ---------------------------------------------------------------------------- --< @summary --< Normalize a vector. --< --< @description --< Normalize the GenFType vector so that it has a magnitude of 1. --< --< @param x --< The vector to normalize. --< --< @return --< The normalized vector. ---------------------------------------------------------------------------- function Normalize(x : in Vkm_GenFType) return Vkm_GenFType is (x / Mag(x)) with inline; ---------------------------------------------------------------------------- --< @summary --< Normalize a vector. --< --< @description --< Normalize the GenDType vector so that it has a magnitude of 1. --< --< @param x --< The vector to normalize. --< --< @return --< The normalized vector. ---------------------------------------------------------------------------- function Normalize(x : in Vkm_GenDType) return Vkm_GenDType is (x / Mag(x)) with inline; ---------------------------------------------------------------------------- --< @summary --< Force a normal vector to face an incident vector. --< --< @description --< Return a normal vector N as-is if an incident vector I points in the opposite --< direction of a reference normal vector, Nref. Otherwise, if I is pointing --< in the same direction as the reference normal, flip the normal vector N. --< --< - If Nref dot I is negative, these vectors are not facing the same direction. --< - If Nref dot I is positive, these vectors are facing in the same direction. --< - If Nref dot I is zero, these two vectors are orthogonal to each other. --< --< @param n --< The normal vector N --< --< @param i --< The incident vector I --< --< @param nref --< The reference normal vector Nref --< --< @return --< If I dot Nref < 0, return N. Otherwise return -N. ---------------------------------------------------------------------------- function Face_Forward(n, i, nref : in Vkm_GenFType) return Vkm_GenFType is (if Dot(nref,i) < 0.0 then n else -n) with Inline; ---------------------------------------------------------------------------- --< @summary --< Force a normal vector to face an incident vector. --< --< @description --< Return a normal vector N as-is if an incident vector I points in the opposite --< direction of a reference normal vector, Nref. Otherwise, if I is pointing --< in the same direction as the reference normal, flip the normal vector N. --< --< - If Nref dot I is negative, these vectors are not facing the same direction. --< - If Nref dot I is positive, these vectors are facing in the same direction. --< - If Nref dot I is zero, these two vectors are orthogonal to each other. --< --< @param n --< The normal vector N --< --< @param i --< The incident vector I --< --< @param nref --< The reference normal vector Nref --< --< @return --< If I dot Nref < 0, return N. Otherwise return -N. ---------------------------------------------------------------------------- function Face_Forward(n, i, nref : in Vkm_GenDType) return Vkm_GenDType is (if Dot(nref,i) < 0.0 then n else -n) with Inline; ---------------------------------------------------------------------------- --< @summary --< Calculate the reflection of an incident vector using the normal vector --< for the surface. --< --< @description --< For the incident vector I and surface orientation N, returns the reflection --< direction: --< --< I - 2 * ( N dot I ) * N. --< --< @param i --< The incident vector I. --< --< @param n --< The normal vector N. N should already be normalized. --< --< @return The reflection direction. ---------------------------------------------------------------------------- function Reflect(i, n : in Vkm_GenFType) return Vkm_GenFType is (i - 2.0 * Dot(n, i) * n) with Inline; ---------------------------------------------------------------------------- --< @summary --< Calculate the reflection of an incident vector using the normal vector --< for the surface. --< --< @description --< For the incident vector I and surface orientation N, returns the reflection --< direction: --< --< I - 2 * ( N dot I ) * N. --< --< @param i --< The incident vector I. --< --< @param n --< The normal vector N. N should already be normalized. --< --< @return The reflection direction. ---------------------------------------------------------------------------- function Reflect(i, n : in Vkm_GenDType) return Vkm_GenDType is (i - 2.0 * Dot(n, i) * n) with Inline; ---------------------------------------------------------------------------- --< @summary --< Calculate the refraction vector for the incident vector I travelling --< through the surface with normal N and a ratio of refraction eta. --< --< @description --< For the indident vector I and surface normal N, and the ratio of refraction --< eta, calculate the refraction vector. --< --< k = 1.0 - eta^2 (1.0 - dot(N,I)^2) --< If k < 0, the result is a vector of all zeros. --< Else , the result is: eta*I - (eta*dot(N,I) + sqrt(k))*N --< --< @param i --< The incident vector I. --< --< @param n --< The surface normal vector N. --< --< @param eta --< The indices of refraction. --< --< @return --< The refraction vector. ---------------------------------------------------------------------------- function Refract(i, n : in Vkm_GenFType; eta : in Vkm_Float ) return Vkm_GenFType; ---------------------------------------------------------------------------- --< @summary --< Calculate the refraction vector for the incident vector I travelling --< through the surface with normal N and a ratio of refraction eta. --< --< @description --< For the indident vector I and surface normal N, and the ratio of refraction --< eta, calculate the refraction vector. --< --< k = 1.0 - eta^2 (1.0 - dot(N,I)^2) --< If k < 0, the result is a vector of all zeros. --< Else , the result is: eta*I - (eta*dot(N,I) + sqrt(k))*N --< --< @param i --< The incident vector I. --< --< @param n --< The surface normal vector N. --< --< @param eta --< The indices of refraction. --< --< @return --< The refraction vector. ---------------------------------------------------------------------------- function Refract(i, n : in Vkm_GenDType; eta : in Vkm_Double ) return Vkm_GenDType; end Vulkan.Math.Geometry;
{ "source": "starcoderdata", "programming_language": "ada" }
-- --* -- * A three channel color struct. -- type TCOD_ColorRGB is record r : aliased unsigned_char; -- color.h:47 g : aliased unsigned_char; -- color.h:48 b : aliased unsigned_char; -- color.h:49 end record with Convention => C_Pass_By_Copy; -- color.h:42 subtype TCOD_color_t is TCOD_ColorRGB; -- color.h:51 --* -- * A four channel color struct. -- type TCOD_ColorRGBA is record r : aliased unsigned_char; -- color.h:63 g : aliased unsigned_char; -- color.h:64 b : aliased unsigned_char; -- color.h:65 a : aliased unsigned_char; -- color.h:66 end record with Convention => C_Pass_By_Copy; -- color.h:56 -- constructors function TCOD_color_RGB (r : unsigned_char; g : unsigned_char; b : unsigned_char) return TCOD_color_t -- color.h:73 with Import => True, Convention => C, External_Name => "TCOD_color_RGB"; function TCOD_color_HSV (hue : float; saturation : float; value : float) return TCOD_color_t -- color.h:74 with Import => True, Convention => C, External_Name => "TCOD_color_HSV"; -- basic operations function TCOD_color_equals (c1 : TCOD_color_t; c2 : TCOD_color_t) return Extensions.bool -- color.h:76 with Import => True, Convention => C, External_Name => "TCOD_color_equals"; function TCOD_color_add (c1 : TCOD_color_t; c2 : TCOD_color_t) return TCOD_color_t -- color.h:77 with Import => True, Convention => C, External_Name => "TCOD_color_add"; function TCOD_color_subtract (c1 : TCOD_color_t; c2 : TCOD_color_t) return TCOD_color_t -- color.h:78 with Import => True, Convention => C, External_Name => "TCOD_color_subtract"; function TCOD_color_multiply (c1 : TCOD_color_t; c2 : TCOD_color_t) return TCOD_color_t -- color.h:79 with Import => True, Convention => C, External_Name => "TCOD_color_multiply"; function TCOD_color_multiply_scalar (c1 : TCOD_color_t; value : float) return TCOD_color_t -- color.h:80 with Import => True, Convention => C, External_Name => "TCOD_color_multiply_scalar"; function TCOD_color_lerp (c1 : TCOD_color_t; c2 : TCOD_color_t; coef : float) return TCOD_color_t -- color.h:81 with Import => True, Convention => C, External_Name => "TCOD_color_lerp"; --* -- * Blend `src` into `dst` as an alpha blending operation. -- * \rst -- * .. versionadded:: 1.16 -- * \endrst -- procedure TCOD_color_alpha_blend (dst : access TCOD_ColorRGBA; src : access constant TCOD_ColorRGBA) -- color.h:88 with Import => True, Convention => C, External_Name => "TCOD_color_alpha_blend"; -- HSV transformations procedure TCOD_color_set_HSV (color : access TCOD_color_t; hue : float; saturation : float; value : float) -- color.h:91 with Import => True, Convention => C, External_Name => "TCOD_color_set_HSV"; procedure TCOD_color_get_HSV (color : TCOD_color_t; hue : access float; saturation : access float; value : access float) -- color.h:92 with Import => True, Convention => C, External_Name => "TCOD_color_get_HSV"; function TCOD_color_get_hue (color : TCOD_color_t) return float -- color.h:93 with Import => True, Convention => C, External_Name => "TCOD_color_get_hue"; procedure TCOD_color_set_hue (color : access TCOD_color_t; hue : float) -- color.h:94 with Import => True, Convention => C, External_Name => "TCOD_color_set_hue"; function TCOD_color_get_saturation (color : TCOD_color_t) return float -- color.h:95 with Import => True, Convention => C, External_Name => "TCOD_color_get_saturation"; procedure TCOD_color_set_saturation (color : access TCOD_color_t; saturation : float) -- color.h:96 with Import => True, Convention => C, External_Name => "TCOD_color_set_saturation"; function TCOD_color_get_value (color : TCOD_color_t) return float -- color.h:97 with Import => True, Convention => C, External_Name => "TCOD_color_get_value"; procedure TCOD_color_set_value (color : access TCOD_color_t; value : float) -- color.h:98 with Import => True, Convention => C, External_Name => "TCOD_color_set_value"; procedure TCOD_color_shift_hue (color : access TCOD_color_t; shift : float) -- color.h:99 with Import => True, Convention => C, External_Name => "TCOD_color_shift_hue"; procedure TCOD_color_scale_HSV (color : access TCOD_color_t; saturation_coef : float; value_coef : float) -- color.h:100 with Import => True, Convention => C, External_Name => "TCOD_color_scale_HSV"; -- color map procedure TCOD_color_gen_map (map : access TCOD_color_t; nb_key : int; key_color : access constant TCOD_color_t; key_index : access int) -- color.h:102 with Import => True, Convention => C, External_Name => "TCOD_color_gen_map"; end color_h;
{ "source": "starcoderdata", "programming_language": "ada" }
------------------------------------------------------------- with Program.Elements.Declarations; with Program.Lexical_Elements; with Program.Elements.Defining_Names; with Program.Elements.Parameter_Specifications; with Program.Elements.Expressions; with Program.Elements.Aspect_Specifications; package Program.Elements.Function_Renaming_Declarations is pragma Pure (Program.Elements.Function_Renaming_Declarations); type Function_Renaming_Declaration is limited interface and Program.Elements.Declarations.Declaration; type Function_Renaming_Declaration_Access is access all Function_Renaming_Declaration'Class with Storage_Size => 0; not overriding function Name (Self : Function_Renaming_Declaration) return not null Program.Elements.Defining_Names.Defining_Name_Access is abstract; not overriding function Parameters (Self : Function_Renaming_Declaration) return Program.Elements.Parameter_Specifications .Parameter_Specification_Vector_Access is abstract; not overriding function Result_Subtype (Self : Function_Renaming_Declaration) return not null Program.Elements.Element_Access is abstract; not overriding function Renamed_Function (Self : Function_Renaming_Declaration) return Program.Elements.Expressions.Expression_Access is abstract; not overriding function Aspects (Self : Function_Renaming_Declaration) return Program.Elements.Aspect_Specifications .Aspect_Specification_Vector_Access is abstract; not overriding function Has_Not (Self : Function_Renaming_Declaration) return Boolean is abstract; not overriding function Has_Overriding (Self : Function_Renaming_Declaration) return Boolean is abstract; not overriding function Has_Not_Null (Self : Function_Renaming_Declaration) return Boolean is abstract; type Function_Renaming_Declaration_Text is limited interface; type Function_Renaming_Declaration_Text_Access is access all Function_Renaming_Declaration_Text'Class with Storage_Size => 0; not overriding function To_Function_Renaming_Declaration_Text (Self : aliased in out Function_Renaming_Declaration) return Function_Renaming_Declaration_Text_Access is abstract; not overriding function Not_Token (Self : Function_Renaming_Declaration_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Overriding_Token (Self : Function_Renaming_Declaration_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Function_Token (Self : Function_Renaming_Declaration_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Left_Bracket_Token (Self : Function_Renaming_Declaration_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Right_Bracket_Token (Self : Function_Renaming_Declaration_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Return_Token (Self : Function_Renaming_Declaration_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Not_Token_2 (Self : Function_Renaming_Declaration_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Null_Token (Self : Function_Renaming_Declaration_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Renames_Token (Self : Function_Renaming_Declaration_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function With_Token (Self : Function_Renaming_Declaration_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Semicolon_Token (Self : Function_Renaming_Declaration_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; end Program.Elements.Function_Renaming_Declarations;
{ "source": "starcoderdata", "programming_language": "ada" }
----------------------------------------------------------------------- package body EL.Contexts.TLS is Context : EL.Contexts.ELContext_Access := null; pragma Thread_Local_Storage (Context); -- ------------------------------ -- Get the current EL context associated with the current thread. -- ------------------------------ function Current return EL.Contexts.ELContext_Access is begin return Context; end Current; -- ------------------------------ -- Initialize and setup a new per-thread EL context. -- ------------------------------ overriding procedure Initialize (Obj : in out TLS_Context) is begin Obj.Previous := Context; Context := Obj'Unchecked_Access; EL.Contexts.Default.Default_Context (Obj).Initialize; end Initialize; -- ------------------------------ -- Restore the previouse per-thread EL context. -- ------------------------------ overriding procedure Finalize (Obj : in out TLS_Context) is begin Context := Obj.Previous; EL.Contexts.Default.Default_Context (Obj).Finalize; end Finalize; end EL.Contexts.TLS;
{ "source": "starcoderdata", "programming_language": "ada" }
with Ada.Containers.Functional_Maps; with Ada.Containers.Functional_Vectors; with Common; use Common; with Ada.Containers; use Ada.Containers; generic type Element_Type is private; package Bounded_Stack with SPARK_Mode is Capacity : constant Integer := 200; Empty : constant Integer := 0; subtype Extent is Integer range Empty .. Capacity; subtype Index is Extent range 1 .. Capacity; type Stack is private; function Size (S : Stack) return Extent; function Element (S : Stack; I : Index) return Element_Type with Ghost, Pre => I <= Size (S); procedure Push (S : in out Stack; E : Element_Type) with Pre => Size (S) < Capacity, Post => Size (S) = Size (S'Old) + 1 and then (for all I in 1 .. Size (S'Old) => Element (S, I) = Element (S'Old, I)) and then Element (S, Size (S)) = E; procedure Pop (S : in out Stack; E : out Element_Type) with Pre => Size (S) > Empty, Post => Size (S) = Size (S'Old) - 1 and then (for all I in 1 .. Size (S) => Element (S, I) = Element (S'Old, I)) and then E = Element (S'Old, Size (S'Old)); private type Content_Array is array (Index) of Element_Type with Relaxed_Initialization; type Stack is record Top : Extent := 0; Content : Content_Array; end record with Predicate => (for all I in 1 .. Top => Content (I)'Initialized); function Size (S : Stack) return Extent is (S.Top); function Element (S : Stack; I : Index) return Element_Type is (S.Content (I)); end Bounded_Stack;
{ "source": "starcoderdata", "programming_language": "ada" }
package GBA.Audio is type Sweep_Shift_Type is range 0 .. 7; type Frequency_Direction is ( Increasing , Decreasing ); for Frequency_Direction use ( Increasing => 0 , Decreasing => 1 ); type Sweep_Duration_Type is range 0 .. 7; type Sweep_Control_Info is record Shift : Sweep_Shift_Type; Frequency_Change : Frequency_Direction; Duration : Sweep_Duration_Type; end record with Size => 16; for Sweep_Control_Info use record Shift at 0 range 0 .. 2; Frequency_Change at 0 range 3 .. 3; Duration at 0 range 4 .. 6; end record; type Sound_Duration_Type is range 0 .. 63; type Wave_Pattern_Duty_Type is range 0 .. 3; type Envelope_Step_Type is range 0 .. 7; type Envelope_Direction is ( Increasing , Decreasing ); for Envelope_Direction use ( Increasing => 1 , Decreasing => 0 ); type Initial_Volume_Type is range 0 .. 15; type Duty_Length_Info is record Duration : Sound_Duration_Type; Wave_Pattern_Duty : Wave_Pattern_Duty_Type; Envelope_Step_Time : Envelope_Step_Type; Envelope_Change : Envelope_Direction; Initial_Volume : Initial_Volume_Type; end record with Size => 16; for Duty_Length_Info use record Duration at 0 range 0 .. 5; Wave_Pattern_Duty at 0 range 6 .. 7; Envelope_Step_Time at 0 range 8 .. 10; Envelope_Direction at 0 range 11 .. 11; Initial_Volume at 0 range 12 .. 15; end record; type Frequency_Type is range 0 .. 2047; type Frequency_Control_Info is record Frequency : Frequency_Type; Use_Duration : Boolean; Initial : Boolean; end record with Size => 16; for Frequency_Control_Info use record Frequency at 0 range 0 .. 10; Use_Duration at 0 range 14 .. 14; Initial at 0 range 15 .. 15; end record; end GBA.Audio;
{ "source": "starcoderdata", "programming_language": "ada" }
------------------------------------------------------------- with Program.Elements.Declarations; with Program.Lexical_Elements; with Program.Elements.Defining_Identifiers; with Program.Elements.Parameter_Specifications; with Program.Elements.Aspect_Specifications; package Program.Elements.Procedure_Body_Stubs is pragma Pure (Program.Elements.Procedure_Body_Stubs); type Procedure_Body_Stub is limited interface and Program.Elements.Declarations.Declaration; type Procedure_Body_Stub_Access is access all Procedure_Body_Stub'Class with Storage_Size => 0; not overriding function Name (Self : Procedure_Body_Stub) return not null Program.Elements.Defining_Identifiers .Defining_Identifier_Access is abstract; not overriding function Parameters (Self : Procedure_Body_Stub) return Program.Elements.Parameter_Specifications .Parameter_Specification_Vector_Access is abstract; not overriding function Aspects (Self : Procedure_Body_Stub) return Program.Elements.Aspect_Specifications .Aspect_Specification_Vector_Access is abstract; not overriding function Has_Not (Self : Procedure_Body_Stub) return Boolean is abstract; not overriding function Has_Overriding (Self : Procedure_Body_Stub) return Boolean is abstract; type Procedure_Body_Stub_Text is limited interface; type Procedure_Body_Stub_Text_Access is access all Procedure_Body_Stub_Text'Class with Storage_Size => 0; not overriding function To_Procedure_Body_Stub_Text (Self : aliased in out Procedure_Body_Stub) return Procedure_Body_Stub_Text_Access is abstract; not overriding function Not_Token (Self : Procedure_Body_Stub_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Overriding_Token (Self : Procedure_Body_Stub_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Procedure_Token (Self : Procedure_Body_Stub_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Left_Bracket_Token (Self : Procedure_Body_Stub_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Right_Bracket_Token (Self : Procedure_Body_Stub_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Is_Token (Self : Procedure_Body_Stub_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Separate_Token (Self : Procedure_Body_Stub_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function With_Token (Self : Procedure_Body_Stub_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Semicolon_Token (Self : Procedure_Body_Stub_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; end Program.Elements.Procedure_Body_Stubs;
{ "source": "starcoderdata", "programming_language": "ada" }
--* -- CHECK THAT A CASE_STATEMENT CORRECTLY HANDLES A SMALL RANGE OF -- POTENTIAL VALUES OF TYPE INTEGER, SITUATED FAR FROM 0 AND -- GROUPED INTO A SMALL NUMBER OF ALTERNATIVES. -- (OPTIMIZATION TEST -- BIASED JUMP TABLE.) -- RM 03/26/81 WITH REPORT; PROCEDURE C54A42E IS USE REPORT ; BEGIN TEST( "C54A42E" , "TEST THAT A CASE_STATEMENT HANDLES CORRECTLY" & " A SMALL, FAR RANGE OF POTENTIAL VALUES OF" & " TYPE INTEGER" ); DECLARE NUMBER : CONSTANT := 4001 ; LITEXPR : CONSTANT := NUMBER + 5 ; STATCON : CONSTANT INTEGER RANGE 4000..4010 := 4009 ; DYNVAR : INTEGER RANGE 4000..4010 := IDENT_INT( 4010 ); DYNCON : CONSTANT INTEGER RANGE 4000..4010 := IDENT_INT( 4002 ); BEGIN CASE INTEGER'(4000) IS WHEN 4001 | 4004 => FAILED("WRONG ALTERNATIVE F1"); WHEN 4009 | 4002 => FAILED("WRONG ALTERNATIVE F2"); WHEN 4005 => FAILED("WRONG ALTERNATIVE F3"); WHEN 4003 | 4007..4008 => FAILED("WRONG ALTERNATIVE F4"); WHEN 4006 => FAILED("WRONG ALTERNATIVE F5"); WHEN OTHERS => NULL ; END CASE; CASE IDENT_INT(NUMBER) IS WHEN 4001 | 4004 => NULL ; WHEN 4009 | 4002 => FAILED("WRONG ALTERNATIVE G2"); WHEN 4005 => FAILED("WRONG ALTERNATIVE G3"); WHEN 4003 | 4007..4008 => FAILED("WRONG ALTERNATIVE G4"); WHEN 4006 => FAILED("WRONG ALTERNATIVE G5"); WHEN OTHERS => FAILED("WRONG ALTERNATIVE G6"); END CASE; CASE IDENT_INT(LITEXPR) IS WHEN 4001 | 4004 => FAILED("WRONG ALTERNATIVE H1"); WHEN 4009 | 4002 => FAILED("WRONG ALTERNATIVE H2"); WHEN 4005 => FAILED("WRONG ALTERNATIVE H3"); WHEN 4003 | 4007..4008 => FAILED("WRONG ALTERNATIVE H4"); WHEN 4006 => NULL ; WHEN OTHERS => FAILED("WRONG ALTERNATIVE H6"); END CASE; CASE STATCON IS WHEN 4001 | 4004 => FAILED("WRONG ALTERNATIVE I1"); WHEN 4009 | 4002 => NULL ; WHEN 4005 => FAILED("WRONG ALTERNATIVE I3"); WHEN 4003 | 4007..4008 => FAILED("WRONG ALTERNATIVE I4"); WHEN 4006 => FAILED("WRONG ALTERNATIVE I5"); WHEN OTHERS => FAILED("WRONG ALTERNATIVE I6"); END CASE; CASE DYNVAR IS WHEN 4001 | 4004 => FAILED("WRONG ALTERNATIVE J1"); WHEN 4009 | 4002 => FAILED("WRONG ALTERNATIVE J2"); WHEN 4005 => FAILED("WRONG ALTERNATIVE J3"); WHEN 4003 | 4007..4008 => FAILED("WRONG ALTERNATIVE J4"); WHEN 4006 => FAILED("WRONG ALTERNATIVE J5"); WHEN OTHERS => NULL ; END CASE; CASE DYNCON IS WHEN 4001 | 4004 => FAILED("WRONG ALTERNATIVE K1"); WHEN 4009 | 4002 => NULL ; WHEN 4005 => FAILED("WRONG ALTERNATIVE K3"); WHEN 4003 | 4007..4008 => FAILED("WRONG ALTERNATIVE K4"); WHEN 4006 => FAILED("WRONG ALTERNATIVE K5"); WHEN OTHERS => FAILED("WRONG ALTERNATIVE K6"); END CASE; END ; RESULT ; END C54A42E ;
{ "source": "starcoderdata", "programming_language": "ada" }
with Orka.Futures; with Orka.Jobs.Queues; with Orka.Resources.Locations; with Orka.Resources.Loaders; generic with package Queues is new Orka.Jobs.Queues (<>); Job_Queue : Queues.Queue_Ptr; Maximum_Requests : Positive; -- Maximum number of resources waiting to be read from a file system -- or archive. Resources are read sequentially, but may be processed -- concurrently. This number depends on how fast the hardware can read -- the requested resources. Task_Name : String := "Resource Loader"; package Orka.Resources.Loader is procedure Add_Location (Location : Locations.Location_Ptr; Loader : Loaders.Loader_Ptr); -- Add a location that contains files that can be loaded by the -- given loader. Multiple loaders can be registered for a specific -- location and multiple locations can be registered for a specific -- loader. -- -- A loader can only load resources that have a specific extension. -- The extension can be queried by calling the Loader.Extension function. function Load (Path : String) return Futures.Pointers.Mutable_Pointer; -- Load the given resource from a file system or archive and return -- a handle for querying the processing status of the resource. Calling -- this function may block until there is a free slot available for -- processing the data. procedure Shutdown; private task Loader; end Orka.Resources.Loader;
{ "source": "starcoderdata", "programming_language": "ada" }
-- Zip.Compress -- ------------ -- -- This package facilitates the storage or compression of data. -- -- Note that unlike decompression where the decoding is unique, -- there is a quasi indefinite number of ways of compressing data into -- most Zip-supported formats, including LZW (Shrink), Reduce, Deflate, or LZMA. -- As a result, you may want to use your own way for compressing data. -- This package is a portable one and doesn't claim to be the "best". -- The term "best" is relative to the needs, since there are at least -- two criteria that usually go in opposite directions: speed and -- compression ratio, a bit like risk and return in finance. with DCF.Streams; package DCF.Zip.Compress is pragma Preelaborate; -- Compression_Method is actually reflecting the way of compressing -- data, not only the final compression format called "method" in -- Zip specifications. type Compression_Method is -- No compression: (Store, -- Deflate combines LZ and Huffman encoding; 4 strengths available: Deflate_Fixed, Deflate_1, Deflate_2, Deflate_3); type Method_To_Format_Type is array (Compression_Method) of Pkzip_Method; Method_To_Format : constant Method_To_Format_Type; -- Deflate_Fixed compresses the data into a single block and with predefined -- ("fixed") compression structures. The data are basically LZ-compressed -- only, since the Huffman code sets are flat and not tailored for the data. subtype Deflation_Method is Compression_Method range Deflate_Fixed .. Deflate_3; -- The multi-block Deflate methods use refined techniques to decide when to -- start a new block and what sort of block to put next. subtype Taillaule_Deflation_Method is Compression_Method range Deflate_1 .. Deflate_3; User_Abort : exception; -- Compress data from an input stream to an output stream until -- End_Of_File(input) = True, or number of input bytes = input_size. -- If password /= "", an encryption header is written. procedure Compress_Data (Input, Output : in out DCF.Streams.Root_Zipstream_Type'Class; Input_Size : File_Size_Type; Method : Compression_Method; Feedback : Feedback_Proc; CRC : out Unsigned_32; Output_Size : out File_Size_Type; Zip_Type : out Unsigned_16); -- ^ code corresponding to the compression method actually used private Method_To_Format : constant Method_To_Format_Type := (Store => Store, Deflation_Method => Deflate); end DCF.Zip.Compress;
{ "source": "starcoderdata", "programming_language": "ada" }
package body getter.macros is function get return character is c : character; procedure rem_var (cur : in params_t.cursor) is begin environment.delete(environment_t.key(params_t.element(cur))); end rem_var; begin if current_called.last > unb.length(current_macros.code) then params_t.iterate(current_called.params, rem_var'access); stack.delete_last; if not stack_t.is_empty(stack) then current_called := stack_t.element(stack_t.last(stack)); current_macros := macroses_t.element(current_called.macros_cursor); end if; pop; return ' '; end if; c := unb.element(current_macros.code, current_called.last); inc(current_called.last); return c; end get; procedure define (name, params : string) is eqs : natural := 1; c : character; tmp_macros : macros_t; len_end : constant natural := end_macros_statement'length; start_pos : natural := 1; cur_pos : natural := 1; mustbe_only_default : boolean := false; t_param : param_t; begin loop c := getter.get(false); if c = ascii.nul then raise ERROR_NO_CLOSED; end if; if end_macros_statement(eqs) = c and then unb.element(tmp_macros.code, unb.length(tmp_macros.code) - eqs + 1) in ' '|ascii.lf then inc(eqs); if eqs > len_end then unb.delete(tmp_macros.code, unb.length(tmp_macros.code) - (end_macros_statement'length - 2), unb.length(tmp_macros.code)); exit; end if; else eqs := 1; end if; unb.append(tmp_macros.code, c); end loop; for i in params'range loop c := params(i); if c in ' '|ascii.lf then if start_pos /= cur_pos then declare param : constant string := params(start_pos..(cur_pos - 1)); assignment_pos : natural := fix.index(param, "="); begin if assignment_pos > 0 then mustbe_only_default := true; if assignment_pos = param'last or assignment_pos = param'first or not validate_variable(param(param'first..(assignment_pos - 1))) or not validate_word(param((assignment_pos + 1)..param'last)) then raise ERROR_PARAM with param; end if; t_param.name := unb.to_unbounded_string(param(param'first..(assignment_pos - 1))); t_param.default_val := value(param((assignment_pos + 1)..param'last)); t_param.has_default := true; elsif mustbe_only_default then raise ERROR_NONDEFAULT_AFTER_DEFAULT with param; elsif not validate_variable(param) then raise ERROR_PARAM with param; else inc(tmp_macros.num_required_params); t_param.name := unb.to_unbounded_string(param); end if; end; tmp_macros.param_names.append(t_param); end if; start_pos := cur_pos + 1; end if; inc(cur_pos); end loop; macroses.insert(name, tmp_macros); end define; procedure call (name, params : string) is t_i : positive := 1; param_i : param_names_t.cursor; tmp_env_cur : environment_t.cursor; tb : boolean; num_req : natural; tmp_n : natural; mustbe_only_default : boolean := false; t_param : param_t; begin if not macroses_t.contains(macroses, name) then raise ERROR_NO_DEFINED; end if; if not stack_t.is_empty(stack) then stack.replace_element(stack_t.last(stack), current_called); end if; current_called.last := 1; current_called.cur_line := 1; current_called.params.clear; current_called.macros_cursor := macroses_t.find(macroses, name); current_macros := macroses_t.element(current_called.macros_cursor); num_req := current_macros.num_required_params; stack.append(current_called); param_i := param_names_t.first(current_macros.param_names); for i in params'range loop if params(i) = ' ' then declare param_raw : constant string := params(t_i..i - 1); assignment_pos : natural := fix.index(param_raw, "="); name : constant string := param_raw(param_raw'first..(assignment_pos - 1)); param : constant string := param_raw(natural'max((assignment_pos + 1), param_raw'first)..param_raw'last); begin if assignment_pos > 0 then if assignment_pos = param_raw'first or assignment_pos = param_raw'last then raise ERROR_PARAM with param; end if; mustbe_only_default := true; param_i := param_names_t.first(current_macros.param_names); while param_names_t.has_element(param_i) loop t_param := param_names_t.element(param_i); if t_param.name = name then if not t_param.has_default then if num_req = 0 then raise ERROR_COUNT_PARAMS with params; end if; dec(num_req); end if; exit; end if; param_names_t.next(param_i); end loop; if not param_names_t.has_element(param_i) then raise ERROR_UNEXPECTED_NAME with name; end if; environment.insert(name, value(param), tmp_env_cur, tb); elsif mustbe_only_default then raise ERROR_NONDEFAULT_AFTER_DEFAULT with params; else if num_req > 0 then dec(num_req); end if; environment.insert(unb.to_string(param_names_t.element(param_i).name), value(param), tmp_env_cur, tb); param_names_t.next(param_i); end if; if not tb then raise ERROR_ALREADY_DEFINED; end if; end; current_called.params.append(tmp_env_cur); t_i := i + 1; end if; end loop; if num_req > 0 then raise ERROR_COUNT_PARAMS with params; end if; param_i := param_names_t.first(current_macros.param_names); while param_names_t.has_element(param_i) loop t_param := param_names_t.element(param_i); if t_param.has_default then environment.insert(unb.to_string(param_names_t.element(param_i).name), t_param.default_val, tmp_env_cur, tb); if tb then current_called.params.append(tmp_env_cur); end if; end if; param_names_t.next(param_i); end loop; getter.push(get'access); end call; end getter.macros;
{ "source": "starcoderdata", "programming_language": "ada" }
-- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Ada.IO_Exceptions; with Ada.Unchecked_Conversion; with Ada.Unchecked_Deallocation; with System.Strings; use System.Strings; with System.Mmap.OS_Interface; use System.Mmap.OS_Interface; package body System.Mmap is type Mapped_File_Record is record Current_Region : Mapped_Region; -- The legacy API enables only one region to be mapped, directly -- associated with the mapped file. This references this region. File : System_File; -- Underlying OS-level file end record; type Mapped_Region_Record is record File : Mapped_File; -- The file this region comes from. Be careful: for reading file, it is -- valid to have it closed before one of its regions is free'd. Write : Boolean; -- Whether the file this region comes from is open for writing. Data : Str_Access; -- Unbounded access to the mapped content. System_Offset : File_Size; -- Position in the file of the first byte actually mapped in memory User_Offset : File_Size; -- Position in the file of the first byte requested by the user System_Size : File_Size; -- Size of the region actually mapped in memory User_Size : File_Size; -- Size of the region requested by the user Mapped : Boolean; -- Whether this region is actually memory mapped Mutable : Boolean; -- If the file is opened for reading, wheter this region is writable Buffer : System.Strings.String_Access; -- When this region is not actually memory mapped, contains the -- requested bytes. Mapping : System_Mapping; -- Underlying OS-level data for the mapping, if any end record; Invalid_Mapped_Region_Record : constant Mapped_Region_Record := (null, False, null, 0, 0, 0, 0, False, False, null, Invalid_System_Mapping); Invalid_Mapped_File_Record : constant Mapped_File_Record := (Invalid_Mapped_Region, Invalid_System_File); Empty_String : constant String := ""; -- Used to provide a valid empty Data for empty files, for instanc. procedure Dispose is new Ada.Unchecked_Deallocation (Mapped_File_Record, Mapped_File); procedure Dispose is new Ada.Unchecked_Deallocation (Mapped_Region_Record, Mapped_Region); function Convert is new Ada.Unchecked_Conversion (Standard.System.Address, Str_Access); procedure Compute_Data (Region : Mapped_Region); -- Fill the Data field according to system and user offsets. The region -- must actually be mapped or bufferized. procedure From_Disk (Region : Mapped_Region); -- Read a region of some file from the disk procedure To_Disk (Region : Mapped_Region); -- Write the region of the file back to disk if necessary, and free memory ---------------------------- -- Open_Read_No_Exception -- ---------------------------- function Open_Read_No_Exception (Filename : String; Use_Mmap_If_Available : Boolean := True) return Mapped_File is File : constant System_File := Open_Read (Filename, Use_Mmap_If_Available); begin if File = Invalid_System_File then return Invalid_Mapped_File; end if; return new Mapped_File_Record' (Current_Region => Invalid_Mapped_Region, File => File); end Open_Read_No_Exception; --------------- -- Open_Read -- --------------- function Open_Read (Filename : String; Use_Mmap_If_Available : Boolean := True) return Mapped_File is Res : constant Mapped_File := Open_Read_No_Exception (Filename, Use_Mmap_If_Available); begin if Res = Invalid_Mapped_File then raise Ada.IO_Exceptions.Name_Error with "Cannot open " & Filename; else return Res; end if; end Open_Read; ---------------- -- Open_Write -- ---------------- function Open_Write (Filename : String; Use_Mmap_If_Available : Boolean := True) return Mapped_File is File : constant System_File := Open_Write (Filename, Use_Mmap_If_Available); begin if File = Invalid_System_File then raise Ada.IO_Exceptions.Name_Error with "Cannot open " & Filename; else return new Mapped_File_Record' (Current_Region => Invalid_Mapped_Region, File => File); end if; end Open_Write; ----------- -- Close -- ----------- procedure Close (File : in out Mapped_File) is begin -- Closing a closed file is allowed and should do nothing if File = Invalid_Mapped_File then return; end if; if File.Current_Region /= null then Free (File.Current_Region); end if; if File.File /= Invalid_System_File then Close (File.File); end if; Dispose (File); end Close; ---------- -- Free -- ---------- procedure Free (Region : in out Mapped_Region) is Ignored : Integer; pragma Unreferenced (Ignored); begin -- Freeing an already free'd file is allowed and should do nothing if Region = Invalid_Mapped_Region then return; end if; if Region.Mapping /= Invalid_System_Mapping then Dispose_Mapping (Region.Mapping); end if; To_Disk (Region); Dispose (Region); end Free; ---------- -- Read -- ---------- procedure Read (File : Mapped_File; Region : in out Mapped_Region; Offset : File_Size := 0; Length : File_Size := 0; Mutable : Boolean := False) is File_Length : constant File_Size := Mmap.Length (File); Req_Offset : constant File_Size := Offset; Req_Length : File_Size := Length; -- Offset and Length of the region to map, used to adjust mapping -- bounds, reflecting what the user will see. Region_Allocated : Boolean := False; begin -- If this region comes from another file, or simply if the file is -- writeable, we cannot re-use this mapping: free it first. if Region /= Invalid_Mapped_Region and then (Region.File /= File or else File.File.Write) then Free (Region); end if; if Region = Invalid_Mapped_Region then Region := new Mapped_Region_Record'(Invalid_Mapped_Region_Record); Region_Allocated := True; end if; Region.File := File; if Req_Offset >= File_Length then -- If the requested offset goes beyond file size, map nothing Req_Length := 0; elsif Length = 0 or else Length > File_Length - Req_Offset then -- If Length is 0 or goes beyond file size, map till end of file Req_Length := File_Length - Req_Offset; else Req_Length := Length; end if; -- Past this point, the offset/length the user will see is fixed. On the -- other hand, the system offset/length is either already defined, from -- a previous mapping, or it is set to 0. In the latter case, the next -- step will set them according to the mapping. Region.User_Offset := Req_Offset; Region.User_Size := Req_Length; -- If the requested region is inside an already mapped region, adjust -- user-requested data and do nothing else. if (File.File.Write or else Region.Mutable = Mutable) and then Req_Offset >= Region.System_Offset and then (Req_Offset + Req_Length <= Region.System_Offset + Region.System_Size) then Region.User_Offset := Req_Offset; Compute_Data (Region); return; elsif Region.Buffer /= null then -- Otherwise, as we are not going to re-use the buffer, free it System.Strings.Free (Region.Buffer); Region.Buffer := null; elsif Region.Mapping /= Invalid_System_Mapping then -- Otherwise, there is a memory mapping that we need to unmap. Dispose_Mapping (Region.Mapping); end if; -- mmap() will sometimes return NULL when the file exists but is empty, -- which is not what we want, so in the case of a zero length file we -- fall back to read(2)/write(2)-based mode. if File_Length > 0 and then File.File.Mapped then Region.System_Offset := Req_Offset; Region.System_Size := Req_Length; Create_Mapping (File.File, Region.System_Offset, Region.System_Size, Mutable, Region.Mapping); Region.Mapped := True; Region.Mutable := Mutable; else -- There is no alignment requirement when manually reading the file. Region.System_Offset := Req_Offset; Region.System_Size := Req_Length; Region.Mapped := False; Region.Mutable := True; From_Disk (Region); end if; Region.Write := File.File.Write; Compute_Data (Region); exception when others => -- Before propagating any exception, free any region we allocated -- here. if Region_Allocated then Dispose (Region); end if; raise; end Read; ---------- -- Read -- ---------- procedure Read (File : Mapped_File; Offset : File_Size := 0; Length : File_Size := 0; Mutable : Boolean := False) is begin Read (File, File.Current_Region, Offset, Length, Mutable); end Read; ---------- -- Read -- ---------- function Read (File : Mapped_File; Offset : File_Size := 0; Length : File_Size := 0; Mutable : Boolean := False) return Mapped_Region is Region : Mapped_Region := Invalid_Mapped_Region; begin Read (File, Region, Offset, Length, Mutable); return Region; end Read; ------------ -- Length -- ------------ function Length (File : Mapped_File) return File_Size is begin return File.File.Length; end Length; ------------ -- Offset -- ------------ function Offset (Region : Mapped_Region) return File_Size is begin return Region.User_Offset; end Offset; ------------ -- Offset -- ------------ function Offset (File : Mapped_File) return File_Size is begin return Offset (File.Current_Region); end Offset; ---------- -- Last -- ---------- function Last (Region : Mapped_Region) return Integer is begin return Integer (Region.User_Size); end Last; ---------- -- Last -- ---------- function Last (File : Mapped_File) return Integer is begin return Last (File.Current_Region); end Last; ------------------- -- To_Str_Access -- ------------------- function To_Str_Access (Str : System.Strings.String_Access) return Str_Access is begin if Str = null then return null; else return Convert (Str.all'Address); end if; end To_Str_Access; ---------- -- Data -- ---------- function Data (Region : Mapped_Region) return Str_Access is begin return Region.Data; end Data; ---------- -- Data -- ---------- function Data (File : Mapped_File) return Str_Access is begin return Data (File.Current_Region); end Data; ---------------- -- Is_Mutable -- ---------------- function Is_Mutable (Region : Mapped_Region) return Boolean is begin return Region.Mutable or Region.Write; end Is_Mutable; ---------------- -- Is_Mmapped -- ---------------- function Is_Mmapped (File : Mapped_File) return Boolean is begin return File.File.Mapped; end Is_Mmapped; ------------------- -- Get_Page_Size -- ------------------- function Get_Page_Size return Integer is Result : constant File_Size := Get_Page_Size; begin return Integer (Result); end Get_Page_Size; --------------------- -- Read_Whole_File -- --------------------- function Read_Whole_File (Filename : String; Empty_If_Not_Found : Boolean := False) return System.Strings.String_Access is File : Mapped_File := Open_Read (Filename); Region : Mapped_Region renames File.Current_Region; Result : String_Access; begin Read (File); if Region.Data /= null then Result := new String'(String (Region.Data (1 .. Last (Region)))); elsif Region.Buffer /= null then Result := Region.Buffer; Region.Buffer := null; -- So that it is not deallocated end if; Close (File); return Result; exception when Ada.IO_Exceptions.Name_Error => if Empty_If_Not_Found then return new String'(""); else return null; end if; when others => Close (File); return null; end Read_Whole_File; --------------- -- From_Disk -- --------------- procedure From_Disk (Region : Mapped_Region) is begin pragma Assert (Region.File.all /= Invalid_Mapped_File_Record); pragma Assert (Region.Buffer = null); Region.Buffer := Read_From_Disk (Region.File.File, Region.User_Offset, Region.User_Size); Region.Mapped := False; end From_Disk; ------------- -- To_Disk -- ------------- procedure To_Disk (Region : Mapped_Region) is begin if Region.Write and then Region.Buffer /= null then pragma Assert (Region.File.all /= Invalid_Mapped_File_Record); Write_To_Disk (Region.File.File, Region.User_Offset, Region.User_Size, Region.Buffer); end if; System.Strings.Free (Region.Buffer); Region.Buffer := null; end To_Disk; ------------------ -- Compute_Data -- ------------------ procedure Compute_Data (Region : Mapped_Region) is Base_Data : Str_Access; -- Address of the first byte actually mapped in memory Data_Shift : constant Integer := Integer (Region.User_Offset - Region.System_Offset); begin if Region.User_Size = 0 then Region.Data := Convert (Empty_String'Address); return; elsif Region.Mapped then Base_Data := Convert (Region.Mapping.Address); else Base_Data := Convert (Region.Buffer.all'Address); end if; Region.Data := Convert (Base_Data (Data_Shift + 1)'Address); end Compute_Data; end System.Mmap;
{ "source": "starcoderdata", "programming_language": "ada" }
with Ada.Text_IO; procedure Test_For_Primes is type Pascal_Triangle_Type is array (Natural range <>) of Long_Long_Integer; function Calculate_Pascal_Triangle (N : in Natural) return Pascal_Triangle_Type is Pascal_Triangle : Pascal_Triangle_Type (0 .. N); begin Pascal_Triangle (0) := 1; for I in Pascal_Triangle'First .. Pascal_Triangle'Last - 1 loop Pascal_Triangle (1 + I) := 1; for J in reverse 1 .. I loop Pascal_Triangle (J) := Pascal_Triangle (J - 1) - Pascal_Triangle (J); end loop; Pascal_Triangle (0) := -Pascal_Triangle (0); end loop; return Pascal_Triangle; end Calculate_Pascal_Triangle; function Is_Prime (N : Integer) return Boolean is I : Integer; Result : Boolean := True; Pascal_Triangle : constant Pascal_Triangle_Type := Calculate_Pascal_Triangle (N); begin I := N / 2; while Result and I > 1 loop Result := Result and Pascal_Triangle (I) mod Long_Long_Integer (N) = 0; I := I - 1; end loop; return Result; end Is_Prime; function Image (N : in Long_Long_Integer; Sign : in Boolean := False) return String is Image : constant String := N'Image; begin if N < 0 then return Image; else if Sign then return "+" & Image (Image'First + 1 .. Image'Last); else return Image (Image'First + 1 .. Image'Last); end if; end if; end Image; procedure Show (Triangle : in Pascal_Triangle_Type) is use Ada.Text_IO; Begin for I in reverse Triangle'Range loop Put (Image (Triangle (I), Sign => True)); Put ("x^"); Put (Image (Long_Long_Integer (I))); Put (" "); end loop; end Show; procedure Show_Pascal_Triangles is use Ada.Text_IO; begin for N in 0 .. 9 loop declare Pascal_Triangle : constant Pascal_Triangle_Type := Calculate_Pascal_Triangle (N); begin Put ("(x-1)^" & Image (Long_Long_Integer (N)) & " = "); Show (Pascal_Triangle); New_Line; end; end loop; end Show_Pascal_Triangles; procedure Show_Primes is use Ada.Text_IO; begin for N in 2 .. 63 loop if Is_Prime (N) then Put (N'Image); end if; end loop; New_Line; end Show_Primes; begin Show_Pascal_Triangles; Show_Primes; end Test_For_Primes;
{ "source": "starcoderdata", "programming_language": "ada" }
-- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Package containing the routines to process a list of discrete choices. -- Such lists can occur in two different constructs: case statements and -- record variants. We have factorized what used to be two very similar -- sets of routines in one place. These are not currently used for the -- aggregate case, since issues with nested aggregates make that case -- substantially different. -- The following processing is required for such cases: -- 1. Analysis of names of subtypes, constants, expressions appearing within -- the choices. This must be done when the construct is encountered to get -- proper visibility of names. -- 2. Checking for semantic correctness of the choices. A lot of this could -- be done at the time when the construct is encountered, but not all, since -- in the case of variants, statically predicated subtypes won't be frozen -- (and the choice sets known) till the enclosing record type is frozen. So -- at least the check for no overlaps and covering the range must be delayed -- till the freeze point in this case. -- 3. Set the Others_Discrete_Choices list for an others choice. This is -- used in various ways, e.g. to construct the disriminant checking function -- for the case of a variant with an others choice. -- 4. In the case of static predicates, we need to expand out choices that -- correspond to the predicate for the back end. This expansion destroys -- the list of choices, so it should be delayed to expansion time. -- Step 1 is performed by the generic procedure Analyze_Choices, which is -- called when the variant record or case statement/expression is first -- encountered. -- Step 2 is performed by the generic procedure Check_Choices. We decide to -- do all semantic checking in that step, since as noted above some of this -- has to be deferred to the freeze point in any case for variants. For case -- statements and expressions, this procedure can be called at the time the -- case construct is encountered (after calling Analyze_Choices). -- Step 3 is also performed by Check_Choices, since we need the static ranges -- for predicated subtypes to accurately construct this. -- Step 4 is performed by the procedure Expand_Static_Predicates_In_Choices. -- For case statements, this call only happens during expansion. The reason -- we do the expansion unconditionally for variants is that other processing, -- for example for aggregates, relies on having a complete list of choices. -- Historical note: We used to perform all four of these functions at once in -- a single procedure called Analyze_Choices. This routine was called at the -- time the construct was first encountered. That seemed to work OK up to Ada -- 2005, but the introduction of statically predicated subtypes with delayed -- evaluation of the static ranges made this completely wrong, both because -- the ASIS tree got destroyed by step 4, and steps 2 and 3 were too early -- in the variant record case. with Types; use Types; package Sem_Case is procedure No_OP (C : Node_Id); -- The no-operation routine. Does mostly nothing. Can be used -- in the following generics for the parameters Process_Empty_Choice, -- or Process_Associated_Node. In the case of an empty range choice, -- routine emits a warning when Warn_On_Redundant_Constructs is enabled. generic with procedure Process_Associated_Node (A : Node_Id); -- Associated with each case alternative or record variant A there is -- a node or list of nodes that need additional processing. This routine -- implements that processing. package Generic_Analyze_Choices is procedure Analyze_Choices (Alternatives : List_Id; Subtyp : Entity_Id); -- From a case expression, case statement, or record variant, this -- routine analyzes the corresponding list of discrete choices which -- appear in each element of the list Alternatives (for the variant -- part case, this is the variants, for a case expression or statement, -- this is the Alternatives). -- -- Subtyp is the subtype of the discrete choices. The type against which -- the discrete choices must be resolved is its base type. end Generic_Analyze_Choices; generic with procedure Process_Empty_Choice (Choice : Node_Id); -- Processing to carry out for an empty Choice. Set to No_Op (declared -- above) if no such processing is required. with procedure Process_Non_Static_Choice (Choice : Node_Id); -- Processing to carry out for a non static Choice (gives an error msg) with procedure Process_Associated_Node (A : Node_Id); -- Associated with each case alternative or record variant A there is -- a node or list of nodes that need semantic processing. This routine -- implements that processing. package Generic_Check_Choices is procedure Check_Choices (N : Node_Id; Alternatives : List_Id; Subtyp : Entity_Id; Others_Present : out Boolean); -- From a case expression, case statement, or record variant N, this -- routine analyzes the corresponding list of discrete choices which -- appear in each element of the list Alternatives (for the variant -- part case, this is the variants, for a case expression or statement, -- this is the Alternatives). -- -- Subtyp is the subtype of the discrete choices. The type against which -- the discrete choices must be resolved is its base type. -- -- Others_Present is set to True if an Others choice is present in the -- list of choices, and in this case Others_Discrete_Choices is set in -- the N_Others_Choice node. -- -- If a Discrete_Choice list contains at least one instance of a subtype -- with a static predicate, then the Has_SP_Choice flag is set true in -- the parent node (N_Variant, N_Case_Expression/Statement_Alternative). end Generic_Check_Choices; end Sem_Case;
{ "source": "starcoderdata", "programming_language": "ada" }
with Measure_Units; use Measure_Units; with Ada.Text_IO; use Ada.Text_IO; procedure Aviotest0 is Avg_Speed : Kn := 350.0; Travel_Time : Duration := 2.0 * 3600.0; -- two hours CR : Climb_Rate := 1500.0; Climb_Time : Duration := 60.0 * 20; -- 2 minutes Alt0 : Ft := 50_000.0; -- from here Alt1 : Ft := 20_000.0; -- to here Sink_Time : Duration := 60.0 * 10; -- in 10 minutes begin Put_Line ("avg speed (kt): " & Avg_Speed); Put_Line ("avg speed (m/s): " & To_Mps (Avg_Speed)); Put_Line ("flight duration (s): " & Duration'Image (Travel_Time)); Put_Line ("distance (NM): " & (Avg_Speed * Travel_Time)); Put_Line ("distance (m): " & To_Meters (Avg_Speed * Travel_Time)); Put_Line ("climb rate (ft/min): " & CR); Put_Line ("alt (ft) after " & Duration'Image (Climb_Time) & " s: " & (CR * Climb_Time)); Put_Line ("change alt rate (ft/m): " & ((Alt1 - Alt0) / Sink_Time)); end Aviotest0;
{ "source": "starcoderdata", "programming_language": "ada" }
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
4